/* ═══════════════════════════════════════════════════════════
   Rečko — Modern UI  (dark-first, Inter font, mobile-ready)
   ═══════════════════════════════════════════════════════════ */

/* ── Reset & touch fix ────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    touch-action: manipulation;   /* prevents double-tap zoom everywhere */
}
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    height: 100%;
}

/* ── CSS Variables — light theme default ──────────────────── */
:root {
    /* Background */
    --bg:         #eeeef8;
    --bg-grad:    linear-gradient(160deg, #ededfb 0%, #e6e6f2 100%);
    /* Surfaces */
    --surface:    #ffffff;
    --surface-2:  #f5f5fc;
    --surface-3:  #eeeef8;
    /* Borders */
    --border:     #d1d1e8;
    --border-2:   #b8b8d4;
    /* Text */
    --text:       #18182e;
    --text-muted: #6b6d8e;
    --text-inv:   #ffffff;
    /* Game tile colors */
    --correct:     #22c55e;
    --correct-dim: #16a34a;
    --present:     #f59e0b;
    --present-dim: #d97706;
    --absent:      #9ca3b8;
    /* UI accent */
    --accent:      #818cf8;
    --accent-2:    #6366f1;
    --error:       #ef4444;
    /* Keyboard */
    --key-bg:     #ddddf0;
    --key-text:   #18182e;
    --key-absent: #b0b0c8;
    /* Misc */
    --header-bg:  rgba(238,238,248,0.94);
    --shadow:     0 8px 32px rgba(100,100,140,0.18);
    --shadow-sm:  0 2px 8px rgba(100,100,140,0.12);
    --radius-lg:   18px;
    --radius-md:   12px;
    --radius-sm:   8px;
    --radius-key:  8px;
    /* Responsive sizing */
    --tile-size:    clamp(50px, 13vw, 62px);
    --key-h:        clamp(48px, 10vw, 58px);
    --key-w:        clamp(28px,  7vw, 43px);
    --key-font:     clamp(0.72rem, 2vw, 0.95rem);
    --hdr-h:        58px;
}
/* ── Dark theme ───────────────────────────────────────────── */
/* html.dark-theme: set by inline pre-init script in <head> before first paint (FOUC fix).
   body.dark-theme: set by game.js after DOMContentLoaded.
   Both selectors needed so dark vars apply from the very first rendered pixel.   */
html.dark-theme,
body.dark-theme {
    --bg:               #0f0f17;
    --bg-grad:          linear-gradient(160deg, #0f0f17 0%, #13131f 100%);
    --surface:          #1c1c30;
    --surface-2:        #23233a;
    --surface-3:        #2a2a45;
    --border:           #2e2e4a;
    --border-2:         #3d3d5c;
    --text:             #e2e4ff;
    --text-muted:       #6b6d8e;
    --text-inv:         #111118;
    --absent:           #2d2d46;
    --header-bg:        rgba(15,15,23,0.94);
    --key-bg:           #252545;
    --key-text:         #c4c6f0;
    --key-absent:       #131325;  /* visibly darker than --key-bg, clearly "used" */
    --key-absent-text:  #45476a;  /* dimmed but readable — more contrast than text-muted */
    --shadow:           0 8px 32px rgba(0,0,0,0.35);
    --shadow-sm:        0 2px 8px rgba(0,0,0,0.25);
}

/* ── Body & layout ────────────────────────────────────────── */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-grad);
    color: var(--text);
    height: 100dvh;
    overflow: hidden;   /* outer page never scrolls; inner .boards-scroll scrolls */
    display: flex;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    transition: background 0.3s, color 0.3s;
}
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 480px;
    height: 100dvh;     /* fixed height — enables internal scrolling */
    position: relative; /* for modals */
}

/* ── Mode bar ──────────────────────────────────────────────── */
.mode-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 5px 0 4px;
    background: var(--header-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 99;
    width: 100%;
}

/* ── Boards scroll — fills remaining space, scrolls internally ── */
.boards-scroll {
    flex: 1;            /* takes all space between mode-bar and keyboard */
    min-height: 0;      /* crucial: lets flex child shrink below content size */
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Thin scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.boards-scroll::-webkit-scrollbar { width: 4px; }
.boards-scroll::-webkit-scrollbar-track { background: transparent; }
.boards-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Keyboard — flex-shrink:0 keeps it always at the bottom ── */
#keyboard-container {
    flex-shrink: 0;
    width: 100%;
    border-top: 1px solid var(--border);
    background: var(--bg-grad);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding-bottom: max(env(safe-area-inset-bottom, 0px), 4px);
}

/* ── Footer bar ─────────────────────────────────────────────── */
.footer-bar {
    flex-shrink: 0;
    width: 100%;
    text-align: center;
    padding: 3px 0 6px;
    pointer-events: none;
    user-select: none;
}

/* ── Header ────────────────────────────────────────────────── */

header {
    width: 100%;
    height: var(--hdr-h);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 14px;
    background: var(--header-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 24px rgba(0,0,0,0.18);
}
.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 4px;
}
.header-left { gap: 10px; }
header h1 {
    font-size: clamp(1.55rem, 5.5vw, 2.1rem);
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--accent) 0%, #c084fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
header button {
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}
header button:hover { background: var(--surface-2); color: var(--text); }
header button:active { background: var(--surface-3); }

/* ── Theme icon animation ─────────────────────────────────── */
.theme-icon-wrap {
    position: relative;
    width: 18px;
    height: 18px;
    display: block;
    overflow: hidden;          /* clips icons as they enter/exit */
}
#icon-moon, #icon-sun {
    position: absolute;
    top: 0; left: 0;
    width: 18px;
    height: 18px;
    display: block;
}
#icon-moon.ti-hidden,
#icon-sun.ti-hidden  { display: none; }

/* Moon falls in from above with bounce */
@keyframes moonFallIn {
    0%   { transform: translateY(-110%); opacity: 0; }
    55%  { transform: translateY(10%);   opacity: 1; }
    75%  { transform: translateY(-5%);              }
    100% { transform: translateY(0);     opacity: 1; }
}
/* Moon drops out downward */
@keyframes moonFallOut {
    0%   { transform: translateY(0);    opacity: 1; }
    100% { transform: translateY(115%); opacity: 0; }
}
/* Sun bounces up from below */
@keyframes sunBounceIn {
    0%   { transform: translateY(110%) scale(0.7); opacity: 0; }
    55%  { transform: translateY(-10%) scale(1.15); opacity: 1; }
    75%  { transform: translateY(4%)   scale(0.95);            }
    100% { transform: translateY(0)    scale(1);    opacity: 1; }
}
/* Sun flies up and out */
@keyframes sunFlyOut {
    0%   { transform: translateY(0)     scale(1);   opacity: 1; }
    100% { transform: translateY(-115%) scale(0.6); opacity: 0; }
}

.ti-moon-in  { animation: moonFallIn  .4s cubic-bezier(.22,.68,0,1.2) forwards; }
.ti-moon-out { animation: moonFallOut .22s ease-in               forwards; }
.ti-sun-in   { animation: sunBounceIn .4s cubic-bezier(.22,.68,0,1.2) forwards; }
.ti-sun-out  { animation: sunFlyOut   .22s ease-in               forwards; }

/* Autofill toggle — active state glows in accent colour */
#autofill-toggle { transition: background 0.2s; }

/* PNG icon color matching — all states via CSS filter
   Target colors match what SVG icons get via currentColor:
   rest  = --text-muted = #6b6d8e
   hover = --text       = #18182e (light) / #e2e4ff (dark)          */

/* Light theme, rest → #6b6d8e */
#autofill-toggle img {
    filter: invert(45%) sepia(11%) saturate(609%) hue-rotate(201deg) brightness(93%) contrast(88%);
    transition: filter .2s;
}
/* Light theme, hover → #18182e */
#autofill-toggle:hover img {
    filter: invert(8%) sepia(14%) saturate(2112%) hue-rotate(206deg) brightness(98%) contrast(92%);
}
/* Active glow background */
#autofill-toggle.active {
    background: color-mix(in srgb, var(--accent) 14%, transparent);
}
#autofill-toggle.active img {
    filter: invert(8%) sepia(14%) saturate(2112%) hue-rotate(206deg) brightness(98%) contrast(92%);
}
#autofill-toggle.active:hover {
    background: color-mix(in srgb, var(--accent) 22%, transparent);
}

/* Dark theme, rest → #6b6d8e */
.dark-theme #autofill-toggle img {
    filter: invert(1) sepia(1) saturate(0.3) hue-rotate(200deg) brightness(0.52);
}
/* Dark theme, hover → #e2e4ff */
.dark-theme #autofill-toggle:hover img {
    filter: invert(97%) sepia(8%) saturate(526%) hue-rotate(200deg) brightness(108%);
}
.dark-theme #autofill-toggle.active img {
    filter: invert(97%) sepia(8%) saturate(526%) hue-rotate(200deg) brightness(108%);
}

/* ── Message bar ──────────────────────────────────────────── */
#message-container {
    min-height: 30px;
    margin: 10px 0 4px;
    font-size: 0.88rem;
    font-weight: 600;
    text-align: center;
    color: var(--error);
    padding: 0 16px;
    transition: opacity 0.3s;
    letter-spacing: 0.01em;
}

/* ── Loading ──────────────────────────────────────────────── */
#loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    min-height: 260px;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.loader {
    width: 34px;
    height: 34px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Already played ───────────────────────────────────────── */
.already-played-message {
    width: 100%;
    padding: 24px 16px;
    display: flex;
    justify-content: center;
}
.already-played-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 28px;
    text-align: center;
    width: 100%;
    max-width: 360px;
    box-shadow: var(--shadow);
}
.already-played-icon { font-size: 2.8rem; margin-bottom: 14px; }
.already-played-card h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 10px;
}
.already-played-card p {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.already-played-card a {
    display: inline-block;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    color: var(--correct);
    text-decoration: none;
    margin: 8px 0 16px;
}
.already-played-card a:hover { text-decoration: underline; }

/* ── Countdown ────────────────────────────────────────────── */
.countdown-box {
    margin-top: 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 20px;
}
.countdown-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 6px;
}
.countdown-timer {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.04em;
}

/* ── Game board ───────────────────────────────────────────── */
#game-board {
    display: grid;
    grid-template-rows: repeat(6, var(--tile-size));
    gap: 6px;
    width: calc(var(--tile-size) * 5 + 6px * 4);
    margin: 8px 0 14px;
    flex-shrink: 0;
}
.row {
    display: grid;
    grid-template-columns: repeat(5, var(--tile-size));
    gap: 6px;
    perspective: 300px;
}

/* ── Tiles ────────────────────────────────────────────────── */
.tile {
    width: var(--tile-size);
    height: var(--tile-size);
    border: 2px solid var(--border);
    border-radius: 5px;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.4rem, 4.5vw, 2rem);
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text);
    transition: border-color 0.1s;
    backface-visibility: hidden;
    will-change: transform;
}
.tile.filled {
    border-color: var(--border-2);
    animation: tilePop 0.09s ease-out;
}
@keyframes tilePop {
    0%   { transform: scale(1.09); }
    100% { transform: scale(1); }
}

/* Hint-filled tiles (auto-filled by Sudoku logic) — lighter shade.
   MUST come BEFORE .correct/.present/.absent so those classes win the cascade. */
.tile.hint-filled {
    background: color-mix(in srgb, var(--correct) 28%, var(--surface));
    border-color: color-mix(in srgb, var(--correct) 55%, var(--border));
    color: var(--text);
    animation: hintPop 0.35s cubic-bezier(.34,1.56,.64,1);
}
body.dark-theme .tile.hint-filled {
    background: color-mix(in srgb, var(--correct) 22%, var(--surface));
    border-color: color-mix(in srgb, var(--correct) 45%, var(--border));
}
@keyframes hintPop {
    0%   { transform: scale(0.82); opacity: 0.4; }
    100% { transform: scale(1);    opacity: 1;   }
}
/* Reverse of hintPop — micro-pop then fast collapse, so motion starts immediately */
@keyframes hintDisappear {
    0%   { transform: scale(1);    opacity: 1;   }
    15%  { transform: scale(1.08); opacity: 1;   }
    100% { transform: scale(0.65); opacity: 0;   }
}
.tile.hint-disappear {
    animation: hintDisappear 0.16s cubic-bezier(.4,0,1,1) forwards;
    pointer-events: none;
}

/* Color states — applied before reveal animation (override hint-filled above) */
.tile.correct { background: var(--correct);  border-color: var(--correct);  color: #fff; }
.tile.present { background: var(--present);  border-color: var(--present);  color: #fff; }
.tile.absent  { background: var(--absent);   border-color: var(--absent);   color: #fff; }

/* Flip reveal */
.tile.reveal {
    animation: flipReveal 0.52s ease-in-out forwards;
}
@keyframes flipReveal {
    0%   { transform: scaleY(1);    }
    42%  { transform: scaleY(0.02); }
    58%  { transform: scaleY(0.02); }
    100% { transform: scaleY(1);    }
}

/* Shake — single-mode row */
.row.shake { animation: rowShake 0.48s ease-in-out; }

/* Shake — multi-mode board */
.multi-board.shake { animation: rowShake 0.48s ease-in-out; }

/* Shake — keyboard (always visible, triggered on invalid word) */
#keyboard-container.shake { animation: rowShake 0.42s ease-in-out; }

@keyframes rowShake {
    0%,100% { transform: translateX(0); }
    15%,45%,75% { transform: translateX(-7px); }
    30%,60%,90% { transform: translateX( 7px); }
}

/* Invalid word tile flash — red briefly then fade back to normal */
.tile.invalid {
    animation: tileInvalid 0.6s ease-in-out;
}
@keyframes tileInvalid {
    0%,20% { background: var(--error); color: #fff; border-color: var(--error); transform: scale(1.06); }
    60%    { background: var(--error); color: #fff; border-color: var(--error); transform: scale(1.02); }
    100%   { background: var(--tile-bg, transparent); color: var(--tile-text, var(--text)); border-color: var(--tile-border, var(--border)); transform: scale(1); }
}

/* ── Keyboard ─────────────────────────────────────────────── */
#keyboard-container {
    width: 100%;
    padding: 4px 6px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 5px;
}
.key {
    height: var(--key-h);
    min-width: var(--key-w);
    flex: 1;
    max-width: calc(var(--key-w) + 5px);
    background: var(--key-bg);
    color: var(--key-text);
    border: none;
    border-radius: var(--radius-key);
    font-family: 'Inter', sans-serif;
    font-size: var(--key-font);
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: filter 0.1s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    box-shadow: 0 2px 0 rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.07);
    letter-spacing: -0.03em;
    touch-action: manipulation;
}
.key:active {
    filter: brightness(0.78);
    transform: scale(0.94);
    box-shadow: none;
}
.key.large {
    max-width: calc(var(--key-w) * 1.65);
    font-size: calc(var(--key-font) * 0.85);
    letter-spacing: -0.04em;
}
.key.correct { background: var(--correct); color: #fff; box-shadow: 0 2px 0 var(--correct-dim); }
.key.present { background: var(--present); color: #fff; box-shadow: 0 2px 0 var(--present-dim); }
.key.absent  { background: var(--key-absent); color: var(--key-absent-text, var(--text-muted)); box-shadow: none; }

/* ── Modals ───────────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0,0,0,0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    align-items: center;
    justify-content: center;
    padding: 20px 16px;
}
.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 30px 24px;
    width: 100%;
    max-width: 420px;
    text-align: center;
    box-shadow: 0 28px 64px rgba(0,0,0,0.45);
    position: relative;
    max-height: 92vh;
    overflow-y: auto;
    animation: modalIn 0.28s cubic-bezier(.34,1.56,.64,1);
}
@keyframes modalIn {
    from { opacity:0; transform: translateY(24px) scale(0.96); }
    to   { opacity:1; transform: translateY(0)    scale(1); }
}
#end-game-message {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 10px;
}
.word-reveal-line {
    font-size: 0.92rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.modal-content #secret-word-reveal {
    font-size: 1.45rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    color: var(--text);
}
.modal-content a { color: var(--correct); text-decoration: none; }
.modal-content a:hover { text-decoration: underline; }

/* Word reveal — clean, no decorations, clearly a link */
.word-reveal-block {
    display: block;
    text-align: center;
    text-decoration: none;
    margin: 10px 0 4px;
}
.word-reveal-block strong {
    display: block;
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    color: var(--correct);
    transition: opacity 0.15s;
}
.word-reveal-block:hover strong { opacity: 0.8; }
.word-reveal-sub {
    display: block;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.06em;
    margin-top: 5px;
    transition: color 0.15s;
}
.word-reveal-block:hover .word-reveal-sub { color: var(--correct); }

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

/* Instructions */
.instructions-content { text-align: left; }
.instructions-content h2 {
    text-align: center;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 22px;
}
.instructions-content p {
    font-size: 0.93rem;
    line-height: 1.65;
    color: var(--text-muted);
    margin-bottom: 12px;
}
.instructions-content p strong { color: var(--text); }
.instructions-content ul { list-style: none; margin-bottom: 18px; }
.instructions-content ul li {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 0.93rem;
    color: var(--text);
    margin-bottom: 12px;
}
.color-example {
    width: 26px; height: 26px;
    border-radius: 5px;
    flex-shrink: 0;
}
.color-example.green  { background: var(--correct); }
.color-example.yellow { background: var(--present); }
.color-example.gray   { background: var(--absent); }

/* Stats modal */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin: 20px 0;
}
.stat-cell {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 12px 6px;
}
.stat-number {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
}
.stat-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 5px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.dist-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 12px;
    text-align: center;
}
.dist-bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.dist-bar-label {
    width: 16px;
    text-align: right;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    flex-shrink: 0;
}
.dist-bar-wrap { flex: 1; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.dist-bar {
    height: 22px;
    background: var(--accent-2, #6366f1);
    border-radius: 4px;
    min-width: 24px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 8px;
}
.dist-bar.highlight { background: var(--correct); }
.dist-bar span { font-size: 0.8rem; font-weight: 700; color: #fff; }

/* ── Buttons ──────────────────────────────────────────────── */
#share-button, #got-it-button, #close-modal-button {
    height: 44px;
    padding: 0 22px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 0.93rem;
    font-weight: 700;
    cursor: pointer;
    transition: filter 0.15s, transform 0.1s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
#share-button {
    background: var(--accent-2, #6366f1);
    color: #fff;
    box-shadow: 0 4px 14px rgba(99,102,241,0.4);
}
#share-button:hover  { filter: brightness(1.1); }
#share-button:active { transform: scale(0.96); }

#got-it-button {
    display: block;
    width: 100%;
    margin-top: 22px;
    justify-content: center;
    background: var(--accent-2, #6366f1);
    color: #fff;
    height: 46px;
    box-shadow: 0 4px 14px rgba(99,102,241,0.35);
}
#got-it-button:hover  { filter: brightness(1.08); }
#got-it-button:active { transform: scale(0.97); }

#close-modal-button {
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
#close-modal-button:hover { background: var(--surface-3); color: var(--text); }

.close-button {
    position: absolute;
    top: 12px; right: 14px;
    width: 32px; height: 32px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1.4rem;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    touch-action: manipulation;
}
.close-button:hover { background: var(--surface-2); color: var(--text); }

/* ── Tooltips ─────────────────────────────────────────────── */
.tooltip {
    position: absolute;
    background: var(--surface-3);
    border: 1px solid var(--border-2);
    color: var(--text);
    padding: 7px 11px;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 500;
    z-index: 300;
    opacity: 0;
    pointer-events: none;
    max-width: 175px;
    text-align: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.35);
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.tooltip.visible { opacity: 1; transform: translateY(0) !important; }
.tooltip.position-top    { transform: translateY(-8px); }
.tooltip.position-bottom { transform: translateY(8px);  }
.tooltip::after {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
}
.tooltip.position-top::after    { top: 100%;    border-top-color:    var(--surface-3); }
.tooltip.position-bottom::after { bottom: 100%; border-bottom-color: var(--surface-3); }

/* ── Responsive tweaks ────────────────────────────────────── */
@media (max-width: 380px) {
    :root {
        --tile-size: 50px;
        --key-h:     45px;
        --key-w:     26px;
        --key-font:  0.68rem;
    }
}
@media (max-width: 320px) {
    :root {
        --tile-size: 44px;
        --key-h:     41px;
        --key-w:     22px;
    }
}
@media (min-height: 700px) {
    #game-board { margin-bottom: 18px; }
}

/* ── Pomoć tooltip bubble ─────────────────────────────── */
.tooltip-pomoc {
    position: absolute;
    z-index: 400;
    background: var(--accent-2, #6366f1);
    color: #fff;
    padding: 10px 12px 10px 14px;
    border-radius: 10px;
    font-size: 0.82rem;
    font-weight: 600;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    white-space: normal;
    max-width: 220px;
    line-height: 1.4;
    box-shadow: 0 6px 20px rgba(99,102,241,0.45);
    pointer-events: auto;
    transform: translate(-50%, 0) translateY(8px);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.tooltip-pomoc.visible {
    opacity: 1;
    transform: translate(-50%, 0) translateY(0);
}
.tooltip-pomoc::before {
    content: '';
    position: absolute;
    top: -7px;
    left: 50%;
    transform: translateX(-50%);
    border: 7px solid transparent;
    border-top: 0;
    border-bottom-color: var(--accent-2, #6366f1);
}
/* Title always on one line */
.tooltip-pomoc strong {
    color: #fff;
    white-space: nowrap;
    display: block;
    margin-bottom: 2px;
}
/* Clean link-style close — no border, no background */
.tt-close {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    color: rgba(255,255,255,0.65);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    align-self: flex-start;
    letter-spacing: .02em;
    transition: color 0.15s;
    font-family: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.tt-close:hover { color: #fff; }

/* ── Instruction modal demo tiles ─────────────────────────── */
.instr-demo-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.instr-tiles {
    display: flex;
    gap: 5px;
    flex-shrink: 0;
}
.instr-tile {
    width: 40px;
    height: 40px;
    border: 2px solid var(--border, #3a3a5c);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text);
    background: var(--surface, #1a1a2e);
    text-transform: uppercase;
    /* 3-D flip perspective */
    perspective: 250px;
    transform-style: preserve-3d;
    transition: background 0.18s, border-color 0.18s, color 0.18s;
}
/* Colored states (same variables as the game) */
.instr-tile.correct { background: var(--correct, #538d4e); border-color: var(--correct, #538d4e); color: #fff; }
.instr-tile.present { background: var(--present, #b59f3b); border-color: var(--present, #b59f3b); color: #fff; }
.instr-tile.absent  { background: var(--absent,  #3a3a3c); border-color: var(--absent,  #3a3a3c); color: #fff; }

/* Flip animation for demo tiles */
.instr-tile.demo-reveal {
    animation: demoFlip 0.5s ease-in-out forwards;
}
@keyframes demoFlip {
    0%   { transform: rotateX(0deg);   }
    45%  { transform: rotateX(-90deg); }
    55%  { transform: rotateX(-90deg); }
    100% { transform: rotateX(0deg);   }
}

.instr-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.84rem;
    color: var(--text);
    line-height: 1.3;
}
.instr-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}
.correct-dot { background: var(--correct, #538d4e); }
.present-dot { background: var(--present, #b59f3b); }
.absent-dot  { background: var(--absent,  #3a3a3c); border: 1.5px solid var(--border, #555); }

/* ── Script switcher (LAT | ЋИР) ──────────────────────────── */
#script-switcher {
    width: auto;
    min-width: 62px;
    padding: 0 6px;
    font-family: 'Inter', sans-serif;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    white-space: nowrap;
    color: var(--text-muted);
}
#script-switcher .script-sep {
    opacity: 0.35;
    font-weight: 400;
    font-size: 0.7rem;
}
#script-switcher .script-active {
    color: var(--accent);
    font-weight: 800;
}
#script-switcher:hover .script-lat,
#script-switcher:hover .script-cyr {
    opacity: 0.75;
}

/* ══ Mod Switcher pill ════════════════════════════════════════════════════════════════ */
.mod-switcher {
    display: flex;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2px;
    gap: 1px;
    flex-shrink: 0;
}
.mod-btn {
    height: 26px;
    min-width: 30px;
    padding: 0 7px;
    background: none;
    border: none;
    border-radius: 17px;
    font-family: 'Inter', sans-serif;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.mod-btn:hover  { color: var(--text); background: var(--surface-3); }
.mod-btn.active {
    background: var(--accent-2, #6366f1);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99,102,241,0.35);
}

/* ══ Multi-mode board layout ══════════════════════════════════════════════════ */
/* Always 2-column CSS grid. Tile sizes are set per-mod via --tile-size-m
   so everything scales automatically without JavaScript.                      */
#game-board.multi-board-container {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;   /* 2-column layout */
    grid-template-rows: auto !important;          /* reset single-mode 'repeat(6,...)' */
    /* Width = exactly 2 boards of 5 tiles each, shared by all modes */
    width: auto !important;
    max-width: 100% !important;
    gap: 10px 10px;
    margin: 2px auto 10px;   /* reduced top margin — brings boards closer to mode-bar */
    padding: 0 10px;
    align-items: start;
    flex-shrink: 0;
}

/* Per-mod tile size — all modes use same tile size so width is identical.
   Container centering keeps 4× and 8× same width as 2×.              */
#game-board.multi-board-container.mod-2                                          { --tile-size-m: clamp(28px, 9.5vw, 42px); --gap-m: 4px; }
#game-board.multi-board-container.mod-4,
#game-board.multi-board-container.mod-8                                          { --tile-size-m: clamp(28px, 9.5vw, 40px); --gap-m: 4px; }

/* 2× mode: exactly 2 boards (grid already handles it).  No extra scroll needed. */
/* 4× mode: 2 boards per row × 2 rows = 2×2 grid. */
/* 8× mode: 2 boards per row × 4 rows = 2×4 grid. */

/* Each wrapper occupies 1 grid cell */
.multi-board-wrap {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.multi-board-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: calc(var(--tile-size-m, var(--tile-size)) * 5 + var(--gap-m, 6px) * 4);
    margin-bottom: 5px;
}
.multi-board-label {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
.multi-board-solved-badge {
    display: none;
    align-items: center;
    gap: 3px;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--correct);
    letter-spacing: 0.04em;
}
.multi-board-solved-badge svg { flex-shrink: 0; }
.multi-board-wrap.solved .multi-board-solved-badge { display: flex; }

/* Inner board grid — dimensions driven by --tile-size-m set on container */
.multi-board {
    display: grid;
    gap: var(--gap-m, 6px);
    flex-shrink: 0;
}
/* Tiles inside multi boards: override the global --tile-size */
.multi-board .tile {
    width:  var(--tile-size-m, var(--tile-size));
    height: var(--tile-size-m, var(--tile-size));
    font-size: clamp(0.7rem, 2.8vw, 1.1rem);
    font-weight: 800;
}

/* Solved board: green left border */
.multi-board-wrap.solved .multi-board {
    border-left: 3px solid var(--correct);
    border-radius: 4px;
    padding-left: 3px;
    animation: boardSolve 0.5s cubic-bezier(.22,.68,0,1.2);
}
@keyframes boardSolve {
    0%   { border-left-color: transparent; }
    60%  { border-left-color: var(--correct); }
    100% { border-left-color: var(--correct); }
}
/* Failed board: red left border */
.multi-board-wrap.failed .multi-board {
    border-left: 3px solid var(--error);
    border-radius: 4px;
    padding-left: 3px;
}

/* Keyboard is NOT fixed in multi mode — it flows naturally after the boards,
   identical to 1× mode. No gap, no overlap. */

/* ══ Already-played multi cards ══════════════════════════════════════════════════ */
.already-played-multi {
    width: 100%;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}
.already-played-multi-header {
    text-align: center;
    margin-bottom: 4px;
}
.already-played-multi-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}
.already-played-multi-header p {
    font-size: 0.85rem;
    color: var(--text-muted);
}
/* Row of N word cards */
.ap-words-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    width: 100%;
    max-width: 440px;
}
.ap-word-card {
    flex: 1;
    min-width: 90px;
    max-width: 140px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 8px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}
.ap-word-card.solved { border-color: var(--correct); }
.ap-word-card.unsolved { border-color: var(--error); opacity: 0.75; }
.ap-word-num {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 6px;
}
.ap-word-text {
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    color: var(--correct);
    text-decoration: none;
    display: block;
    margin-bottom: 2px;
}
.ap-word-card.unsolved .ap-word-text { color: var(--error); }
.ap-word-sub {
    font-size: 0.62rem;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    white-space: nowrap;
}
/* Countdown in already-played multi */
.ap-countdown-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 20px;
    text-align: center;
    width: 100%;
    max-width: 440px;
}
