/* =============================================================================
   Russian Crossword — styles
   -----------------------------------------------------------------------------
   Reuses the site theme variables (--text, --border, --bg-card, --bg-subtle,
   --primary) from styles.css, with [data-theme="dark"] overrides where a
   colour needs to differ. Board is grid + clue lists; it stacks on mobile and
   sits side-by-side on wider screens. Cell + keyboard styling mirrors the
   other games so the crossword feels part of the same family.
   ========================================================================== */

.hidden { display: none !important; }

/* ── Shell / topbar ─────────────────────────────────────────────────────── */

.crossword-shell {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 12px 6px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-height: calc(100vh - 72px);
    gap: 10px;
}

.crossword-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border, #e2e2e2);
}

.crossword-logo {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0;
    color: var(--text, #1a1a1a);
    letter-spacing: 0.3px;
}

.crossword-topbar-actions { display: flex; gap: 6px; }

.icon-btn {
    background: var(--bg-card, #fff);
    border: 1px solid var(--border, #e2e2e2);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 18px;
    color: var(--text, #1a1a1a);
    line-height: 1;
    transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--bg-subtle, #f4f4f5); border-color: var(--primary, #3b6fd4); }
.icon-btn.active { background: var(--primary, #3b6fd4); color: #fff; border-color: var(--primary, #3b6fd4); }

/* ── Status row ─────────────────────────────────────────────────────────── */

.crossword-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.cx-lives { font-size: 1.05rem; letter-spacing: 1px; }
.cx-lives-hearts { color: #e5484d; }
[data-theme="dark"] .cx-lives-hearts { color: #ff7a6b; }
.cx-lives-label { color: var(--text, #1a1a1a); font-size: 0.9rem; letter-spacing: normal; }
.cx-progress { font-size: 0.9rem; color: var(--text-muted, #6b7280); }

.crossword-message {
    min-height: 1.2em;
    text-align: center;
    color: var(--text-muted, #6b7280);
    font-size: 0.92rem;
}

/* ── Board ──────────────────────────────────────────────────────────────── */

/* Mobile-first: grid on top (full width), clues stacked below. On wider
   screens (see the media query at the bottom) the grid takes ≥68.2% of the
   board width with the clues in a narrow column beside it. */
.crossword-play {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
}
.crossword-right {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 100%;
    min-width: 0;
}

/* Transparent centering container — the visible board (border/bg) lives on the
   grid itself so it hugs the cells exactly instead of forming a big empty box. */
.crossword-grid-wrap {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

/* "Play again" appears under the board after a game ends (the result popup
   only dismisses), so the player can review what they filled first. */
.cx-play-again {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    background: var(--primary, #3b6fd4);
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: filter 0.12s;
}
.cx-play-again:hover { filter: brightness(1.08); }

.crossword-grid {
    /* Cell = the smaller of a width cap and a HEIGHT cap from the row count, so
       the grid always fits on screen. On MOBILE the keyboard sits under the grid,
       so ~340px is reserved for chrome + keyboard. On DESKTOP the keyboard is in
       the right column (not under the grid), so the media override below reserves
       less and allows a bigger grid. Container query scales the letters. */
    --cell: clamp(20px, calc((100vh - 340px) / var(--cx-rows, 10)), 45px);
    container-type: inline-size;
    display: grid;
    grid-template-columns: repeat(var(--cx-cols, 10), 1fr);
    gap: 2px;
    box-sizing: content-box;
    width: calc(var(--cx-cols, 10) * var(--cell));
    max-width: 100%;
    padding: 6px;
    border: 1px solid var(--border, #e2e2e2);
    border-radius: 10px;
    background: var(--bg-subtle, #f4f4f5);
}

/* Square cells that scale to the grid width. */
.cx-cell {
    aspect-ratio: 1 / 1;
    width: 100%;
    box-sizing: border-box;
}
.cx-block { background: transparent; }
.cx-fill {
    position: relative;
    background: var(--bg-card, #fff);
    border: 1px solid var(--border, #cfcfcf);
    border-radius: 3px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}
.cx-num {
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: clamp(7px, calc(26cqw / var(--cx-cols, 10)), 14px);
    line-height: 1;
    color: var(--text-muted, #8a8a8a);
    pointer-events: none;
}
.cx-letter {
    font-size: clamp(10px, calc(52cqw / var(--cx-cols, 10)), 28px);
    font-weight: 700;
    color: var(--text, #1a1a1a);
    text-transform: uppercase;
}
.cx-fill.cx-active { background: #dbe7ff; }
[data-theme="dark"] .cx-fill.cx-active { background: #29354f; }
.cx-fill.cx-focus {
    background: #b9d0ff;
    border-color: var(--primary, #3b6fd4);
    box-shadow: inset 0 0 0 1px var(--primary, #3b6fd4);
}
[data-theme="dark"] .cx-fill.cx-focus { background: #37507d; }
.cx-fill.cx-solved {
    background: #d8f3dd;
    border-color: #46b45f;
}
[data-theme="dark"] .cx-fill.cx-solved { background: #1f3d29; border-color: #3f9c57; }
.cx-fill.cx-solved .cx-letter { color: #1c7a37; }
[data-theme="dark"] .cx-fill.cx-solved .cx-letter { color: #7fe39a; }
.cx-fill.cx-wrong { animation: cxShake 0.4s; background: #ffd9d9; border-color: #e5484d; }
[data-theme="dark"] .cx-fill.cx-wrong { background: #4a2224; }
@keyframes cxShake {
    0%,100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

/* ── Clues ──────────────────────────────────────────────────────────────── */

.crossword-clues {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}
/* Disclosure header for the clue block (collapses the list). */
.crossword-clues-toggle {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border: 1px solid var(--border, #e2e2e2);
    border-radius: 8px;
    background: var(--bg-card, #fff);
    color: var(--text, #1a1a1a);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
}
.crossword-clues-toggle:hover { border-color: var(--primary, #3b6fd4); }
.crossword-clues-chevron {
    font-size: 0.8rem;
    line-height: 1;
    transition: transform 0.15s ease;
}
.crossword-clues.collapsed .crossword-clues-chevron { transform: rotate(-90deg); }
.crossword-clues-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.crossword-clue-heading {
    font-size: 1rem;
    margin: 0 0 6px;
    color: var(--text, #1a1a1a);
    border-bottom: 2px solid var(--primary, #3b6fd4);
    padding-bottom: 4px;
}
.crossword-clue-list { list-style: none; margin: 0; padding: 0; }
.cx-clue {
    display: flex;
    gap: 6px;
    align-items: baseline;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text, #1a1a1a);
    transition: background 0.12s;
}
.cx-clue:hover { background: var(--bg-subtle, #f0f0f2); }
.cx-clue-num { font-weight: 700; min-width: 1.4em; color: var(--primary, #3b6fd4); }
.cx-clue-text { flex: 1; }
.cx-clue-len { color: var(--text-muted, #8a8a8a); font-size: 0.82rem; }
.cx-clue.solved { opacity: 0.55; text-decoration: line-through; }
.cx-clue.solved .cx-clue-num { color: #46b45f; }

/* Lingering selection highlight on the active clue (mirrors the grid row). */
.cx-clue.cx-clue-active {
    background: #dbe7ff;
    box-shadow: inset 0 0 0 2px var(--primary, #3b6fd4);
}
[data-theme="dark"] .cx-clue.cx-clue-active { background: #29354f; }

/* Collapsed: hide the Across/Down headings and every clue except the selected
   one, so the whole block shrinks to a single line and the keyboard moves up
   right under the grid. */
.crossword-clues.collapsed .crossword-clue-heading { display: none; }
.crossword-clues.collapsed .cx-clue { display: none; }
.crossword-clues.collapsed .cx-clue.cx-clue-active { display: flex; }
.crossword-clues.collapsed .crossword-clues-body { gap: 0; }

/* ── Keyboard ───────────────────────────────────────────────────────────── */

.crossword-keyboard {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    margin-top: 6px;
    padding-bottom: 8px;
}
.cx-kb-row { display: flex; gap: 4px; justify-content: center; width: 100%; max-width: 100%; }
.cx-key {
    /* flex-basis 0 → every key divides the row width, so a full row always fits
       the screen and never overflows on the right. max-width just caps how big
       a key gets when there is spare room. */
    flex: 1 1 0;
    max-width: 40px;
    min-width: 0;
    height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    border: 1px solid var(--border, #d0d0d0);
    border-radius: 6px;
    background: var(--bg-card, #fff);
    color: var(--text, #1a1a1a);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-transform: uppercase;
    transition: background 0.12s;
}
.cx-key:hover { background: var(--bg-subtle, #eee); }
.cx-key:active { background: #cddafc; }
.cx-key-wide { flex-grow: 1.5; max-width: 60px; }
.cx-key-enter { background: var(--primary, #3b6fd4); color: #fff; border-color: var(--primary, #3b6fd4); }
.cx-key-back { font-size: 18px; }

/* ── Modals ─────────────────────────────────────────────────────────────── */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}
.modal.hidden { display: none; }
.cx-modal-card {
    background: var(--bg-card, #fff);
    color: var(--text, #1a1a1a);
    border-radius: 12px;
    padding: 22px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.cx-modal-title { margin: 0 0 14px; font-size: 1.25rem; text-align: center; }
.cx-modal-label { font-weight: 600; margin-bottom: 8px; }
.cx-modal-note { color: var(--text-muted, #6b7280); font-size: 0.85rem; text-align: center; margin: 12px 0 0; }

.cx-diff-group { display: flex; flex-direction: column; gap: 8px; }
.cx-diff-btn {
    padding: 12px;
    border: 2px solid var(--border, #d8d8d8);
    border-radius: 8px;
    background: var(--bg-subtle, #f6f6f7);
    color: var(--text, #1a1a1a);
    cursor: pointer;
    font-size: 0.95rem;
    text-align: center;
}
.cx-diff-btn.selected { border-color: var(--primary, #3b6fd4); background: #dbe7ff; font-weight: 700; }
[data-theme="dark"] .cx-diff-btn.selected { background: #29354f; }

.cx-modal-actions { display: flex; gap: 8px; margin-top: 18px; }
.cx-btn {
    flex: 1;
    padding: 11px;
    border: 1px solid var(--border, #d0d0d0);
    border-radius: 8px;
    background: var(--bg-subtle, #f2f2f3);
    color: var(--text, #1a1a1a);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
}
.cx-btn-primary { background: var(--primary, #3b6fd4); color: #fff; border-color: var(--primary, #3b6fd4); }

.cx-stats-grid { display: flex; justify-content: space-around; gap: 10px; margin: 8px 0; }
.cx-stat { text-align: center; }
.cx-stat-val { font-size: 1.6rem; font-weight: 700; }
.cx-stat-lab { font-size: 0.78rem; color: var(--text-muted, #6b7280); }
.cx-result-emoji { font-size: 2.6rem; text-align: center; margin-bottom: 4px; }

/* ── Toast ──────────────────────────────────────────────────────────────── */

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%) translateY(20px);
    background: #222;
    color: #fff;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 0.9rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 1100;
    max-width: 90vw;
    text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Wider screens: grid fills the left, right column = clues + keyboard ──── */
@media (min-width: 820px) {
    .crossword-play {
        flex-direction: row;
        align-items: flex-start;
        gap: 20px;
    }
    /* Grid takes the whole left side (centered within it). */
    .crossword-grid-wrap {
        flex: 1 1 0;
        min-width: 0;
    }
    /* Right column: clues on top, keyboard beneath, capped to the viewport so
       the keyboard stays visible; the clue list scrolls inside it if long. */
    .crossword-right {
        flex: 0 0 auto;
        width: clamp(320px, 36%, 440px);
        max-height: calc(100vh - 160px);
    }
    .crossword-clues { flex: 1 1 auto; min-height: 0; }
    .crossword-clues-body { overflow-y: auto; min-height: 0; }
    .crossword-keyboard { flex: 0 0 auto; margin-top: 4px; }
    /* Keyboard is NOT under the grid on desktop, so the grid only needs to clear
       the navbar + topbar + status (~180px) and can be bigger (up to 56px). */
    .crossword-grid {
        --cell: clamp(24px, calc((100vh - 180px) / var(--cx-rows, 10)), 56px);
    }
}
