/* ════════════════════════════════════════════════════
   SELF-HOSTED FONTS
   Files live in /vortmaster/fonts/ (and in fonts/ for itch.io ZIP)
   Download from: https://fonts.google.com/download?family=Quicksand
                  https://fonts.google.com/download?family=Playfair+Display
   ════════════════════════════════════════════════════ */

@font-face {
    font-family: 'Quicksand';
    src: url('fonts/quicksand-v37-latin-regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Quicksand';
    src: url('fonts/quicksand-v37-latin-600.woff2') format('woff2');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Quicksand';
    src: url('fonts/quicksand-v37-latin-700.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Playfair Display';
    src: url('fonts/playfair-display-v40-latin-700.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Playfair Display';
    src: url('fonts/playfair-display-v40-latin-900.woff2') format('woff2');
    font-weight: 900;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Playfair Display';
    src: url('fonts/playfair-display-v40-latin-700italic.woff2') format('woff2');
    font-weight: 700;
    font-style: italic;
    font-display: swap;
}



/* ════════════════════════════════════════════════════
   VIEWPORT LOCK — prevent horizontal scroll at all sizes
   (itch.io iframe, narrow desktop, mobile portrait/landscape)
   ════════════════════════════════════════════════════ */

html, body {
    overflow-x: hidden;
}

/* ════════════════════════════════════════════════════
           THEME SYSTEM — edit per-theme values here freely
           ════════════════════════════════════════════════════ */

        /* ══════════════════════════════════════════════════
           DESIGN SYSTEM — single source of truth
           ══════════════════════════════════════════════════ */

        :root {
            /* ── Typography scale ── */
            --fs-xs:   0.68rem;
            --fs-sm:   0.80rem;
            --fs-base: 0.90rem;
            --fs-lg:   1.05rem;
            --fs-xl:   1.30rem;
            --fs-2xl:  1.70rem;

            /* ── Spacing scale (8px grid) ── */
            --sp-xs:  4px;
            --sp-sm:  8px;
            --sp-md:  12px;
            --sp-lg:  16px;
            --sp-xl:  20px;
            --sp-2xl: 28px;

            /* ── Brand colors ── */
            --brand-primary:      #7ab3a2;
            --brand-primary-dark: #5a9e8e;
            --brand-primary-glow: rgba(122,179,162,0.35);
            --brand-gold:         #c8a96e;
            --brand-gold-light:   #f5e8c0;

            /* ── Semantic colors ── */
            --color-success:      #3e7e57;
            --color-success-bg:   #d5f5e3;
            --color-destructive:  #d84040;
            --color-destructive-bg: #ffebeb;
            --color-destructive-border: #f5c0c0;
            --color-warning:      #b8860b;
            --color-warning-bg:   #fff8e1;

            /* ── Button hierarchy ── */
            --btn-primary-bg:     #7ab3a2;
            --btn-primary-color:  #ffffff;
            --btn-secondary-bg:   transparent;
            --btn-secondary-color: var(--text-muted);
            --btn-secondary-border: var(--tile-border);
            --btn-destructive-bg: #ffebeb;
            --btn-destructive-color: #d84040;
            --btn-destructive-border: #f5c0c0;

            /* ── Line heights ── */
            --lh-tight:  1.3;
            --lh-base:   1.5;
            --lh-loose:  1.7;

            /* ── Border radius scale ── */
            --radius-sm:  8px;
            --radius-md:  12px;
            --radius-lg:  16px;
            --radius-xl:  20px;
            --radius-2xl: 28px;
        }

        /* DEFAULT — Cotton Candy Pastels (original) */
        :root,
        [data-theme="default"] {
            --bg-color: #E8F5E9;
            --page-bg: #D6E8E3;
            --container-bg: #FFFFFF;
            --accent-blue: #E3F2FD;
            --accent-pink: #FFEBEE;
            --text-main: #4a4a4a;
            --text-muted: #888888;
            --tile-bg: #ffffff;
            --tile-border: #cccccc;
            --tile-text: #555555;
            --success-green: #d5f5e3;
            --error-red: #ffcdd2;
            --header-color: #7ab3a2;
            --status-bg: #E3F2FD;
            --status-text: #5c8cae;
            --shadow-outer: 10px 10px 20px rgba(0,0,0,0.05), -10px -10px 20px rgba(255,255,255,0.8);
            --shadow-inner: inset 4px 4px 8px rgba(0,0,0,0.04), inset -4px -4px 8px rgba(255,255,255,0.9);
            --footer-btn-bg: #E8F5E9;
            --input-bg: #fbfbfb;
            --found-bg: #d5f5e3;
            --found-color: #3e7e57;
            --settings-bg: #fdfdfd;
            --iron: #7d7d7d; --copper: #b87333; --bronze: #cd7f32;
            --silver: #C0C0C0; --gold: #FFD700; --platinum: #E5E4E2;
        }

        /* DARK MODE — Deep charcoal with electric accents */
        [data-theme="dark"] {
            --bg-color: #121318;
            --page-bg: #0f1117;
            --container-bg: #1e2028;
            --accent-blue: #1a2a3a;
            --accent-pink: #2a1a22;
            --text-main: #e8e8f0;
            --text-muted: #7a7a9a;
            --tile-bg: #2a2d38;
            --tile-border: #3a3d50;
            --tile-text: #d0d0e8;
            --success-green: #0d2a1a;
            --error-red: #2a0d10;
            --header-color: #6ecfbb;
            --status-bg: #1a2a3a;
            --status-text: #6ecfbb;
            --shadow-outer: 6px 6px 16px rgba(0,0,0,0.5), -4px -4px 12px rgba(255,255,255,0.03);
            --shadow-inner: inset 3px 3px 7px rgba(0,0,0,0.4), inset -3px -3px 7px rgba(255,255,255,0.04);
            --footer-btn-bg: #2a2d38;
            --input-bg: #252830;
            --found-bg: #0d2a1a;
            --found-color: #4ecf80;
            --settings-bg: #252830;
            --iron: #9d9dbd; --copper: #d09050; --bronze: #e09050;
            --silver: #d0d0e8; --gold: #ffd700; --platinum: #a0f0e8;
        }

        /* NIGHT LIGHT — Warm amber tones, blue-light filtered */
        [data-theme="nightlight"] {
            --bg-color: #2d2010;
            --page-bg: #251810;
            --container-bg: #3a2a18;
            --accent-blue: #3a2e1a;
            --accent-pink: #3d2018;
            --text-main: #f0d8a0;
            --text-muted: #a08858;
            --tile-bg: #4a3820;
            --tile-border: #6a5030;
            --tile-text: #f0d0a0;
            --success-green: #1a2a10;
            --error-red: #2a1008;
            --header-color: #e8a050;
            --status-bg: #3a2e1a;
            --status-text: #e8a050;
            --shadow-outer: 6px 6px 16px rgba(0,0,0,0.5), -4px -4px 12px rgba(255,220,150,0.04);
            --shadow-inner: inset 3px 3px 7px rgba(0,0,0,0.35), inset -3px -3px 7px rgba(255,220,150,0.05);
            --footer-btn-bg: #4a3820;
            --input-bg: #3a2e1a;
            --found-bg: #1a3010;
            --found-color: #90d060;
            --settings-bg: #3a2e1a;
            --iron: #c0a080; --copper: #e0a860; --bronze: #d09840;
            --silver: #d8c898; --gold: #f8d050; --platinum: #f0e0b0;
        }

        /* READING MODE — Soft warm cream, maximum comfort */
        [data-theme="reading"] {
            --bg-color: #f5f0e8;
            --page-bg: #ede5db;
            --container-bg: #fdf8f0;
            --accent-blue: #eae4d8;
            --accent-pink: #f5e8e0;
            --text-main: #3a3028;
            --text-muted: #9a8878;
            --tile-bg: #fdf8f0;
            --tile-border: #d8c8b8;
            --tile-text: #3a3028;
            --success-green: #daf0d8;
            --error-red: #f8ddd8;
            --header-color: #8a6a50;
            --status-bg: #eae4d8;
            --status-text: #6a5840;
            --shadow-outer: 8px 8px 18px rgba(160,140,120,0.15), -8px -8px 18px rgba(255,255,250,0.8);
            --shadow-inner: inset 3px 3px 7px rgba(160,140,120,0.1), inset -3px -3px 7px rgba(255,255,250,0.9);
            --footer-btn-bg: #f5f0e8;
            --input-bg: #fdf8f0;
            --found-bg: #daf0d8;
            --found-color: #3a6a30;
            --settings-bg: #faf5ee;
            --iron: #9a8878; --copper: #b87848; --bronze: #c08040;
            --silver: #a8a898; --gold: #c8a030; --platinum: #b8d8d0;
        }

        body {
            font-family: 'Quicksand', sans-serif;
            background-color: var(--page-bg);
            color: var(--text-main);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            margin: 0;
            padding: var(--sp-xl);
            /* Safe-area insets: respect iPhone notches + Android cutouts */
            padding-top:    max(var(--sp-xl), env(safe-area-inset-top));
            padding-bottom: max(var(--sp-xl), env(safe-area-inset-bottom));
            padding-left:   max(var(--sp-xl), env(safe-area-inset-left));
            padding-right:  max(var(--sp-xl), env(safe-area-inset-right));
            box-sizing: border-box;
            line-height: var(--lh-base);
            font-size: var(--fs-base);
        }

        .game-card {
            background: var(--container-bg);
            padding: 30px;
            border-radius: 32px;
            box-shadow: var(--shadow-outer);
            width: 100%;
            max-width: 640px;
            text-align: center;
            position: relative;
            margin-bottom: 20px;
        }

        .header-container {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-bottom: 15px;
        }

        /* ── Title treatment ── */
        h1 {
            font-family: 'Playfair Display', Georgia, serif;
            font-size: 2.4rem;
            font-weight: 900;
            margin: 0;
            letter-spacing: 3px;
            line-height: 1;
            /* Default theme gradient */
            background: linear-gradient(135deg, #5a9e8e 0%, #7ab3a2 40%, #a8d8cc 65%, #c8eae4 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            position: relative;
            display: inline-block;
        }

        /* Decorative rule lines either side of title */
        .title-rule {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 4px;
        }
        .title-rule-line {
            flex: 1;
            height: 1px;
            background: linear-gradient(90deg, transparent, var(--header-color), transparent);
            opacity: 0.4;
        }
        .title-subtitle {
            font-family: 'Quicksand', sans-serif;
            font-size: 0.62rem;
            font-weight: 700;
            letter-spacing: 5px;
            text-transform: uppercase;
            color: var(--text-muted);
            opacity: 0.7;
            margin-top: 2px;
        }

        /* ── Rackup Logo — Concept 4 (Stacked Slab) ──────────────────────── */
        .rackup-logo {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 5px;
            width: 100%;
            padding: 0 28px;
            box-sizing: border-box;
        }
        .rackup-logo h1 {
            margin: 2px 0;
            letter-spacing: 10px;
            white-space: nowrap;
        }
        .rackup-logo__rule {
            width: 100%;
            height: 3px;
            border-radius: 2px;
            background: linear-gradient(90deg,
                transparent 0%,
                var(--header-color, #5a9e8e) 20%,
                var(--header-color, #7ab3a2) 50%,
                var(--header-color, #5a9e8e) 80%,
                transparent 100%);
            opacity: 0.55;
        }
        .rackup-logo .title-subtitle {
            margin-top: 1px;
        }

        /* Mobile: reduce h1 size for single-line fit on Puzzles/Quizzes pages */
        @media (max-width: 450px) {
            h1 {
                font-size: 1.8rem;
                letter-spacing: 2px;
            }
        }

        /* Per-theme title gradients */
        [data-theme="dark"] h1 {
            background: linear-gradient(135deg, #4ecfbb 0%, #6ef0d8 45%, #a0fff0 70%, #c0fff8 100%);
            -webkit-background-clip: text;
            background-clip: text;
        }
        [data-theme="nightlight"] h1 {
            background: linear-gradient(135deg, #c87820 0%, #e8a050 40%, #f8c878 65%, #fde8b0 100%);
            -webkit-background-clip: text;
            background-clip: text;
        }
        [data-theme="reading"] h1 {
            background: linear-gradient(135deg, #6a4a30 0%, #8a6a50 40%, #b08868 65%, #c8a888 100%);
            -webkit-background-clip: text;
            background-clip: text;
        }

        /* ── Tagline ─────────────────────────────────────────────────────── */
        .mm-tagline {
            font-size: 0.82rem;
            font-weight: 600;
            color: var(--text-muted);
            margin-top: 10px;
            letter-spacing: 0.2px;
            padding-top: 10px;
            border-top: 1px solid var(--tile-border);
            width: 100%;
            text-align: center;
            opacity: 0.9;
        }

        /* ── Welcome pill badge ──────────────────────────────────────────── */
        #welcomeMsg {
            margin-top: 10px;
        }

        .welcome-pill {
            display: inline-flex;
            align-items: center;
            gap: 7px;
            background: var(--found-bg);
            border: 1.5px solid rgba(122,179,162,0.35);
            border-radius: 999px;
            padding: 5px 14px 5px 10px;
            font-size: 0.78rem;
            font-weight: 600;
            color: var(--text-muted);
            box-shadow: 0 1px 4px rgba(122,179,162,0.15);
        }

        .welcome-pill__label {
            font-size: 0.9rem;
            line-height: 1;
            opacity: 0.8;
        }

        .welcome-pill__text strong {
            color: var(--header-color);
            font-weight: 800;
        }

        /* Dark theme */
        [data-theme="dark"] .welcome-pill {
            background: rgba(78,207,187,0.1);
            border-color: rgba(78,207,187,0.25);
        }

        /* Nightlight theme */
        [data-theme="nightlight"] .welcome-pill {
            background: rgba(232,160,80,0.12);
            border-color: rgba(232,160,80,0.3);
        }

        /* Reading theme */
        [data-theme="reading"] .welcome-pill {
            background: var(--found-bg);
            border-color: rgba(138,106,80,0.25);
        }

        /* .player-profile removed — name now lives inside #welcomeMsg */

        /* ── Settings Panel ─────────────────────────────────────────────── */
        .settings-panel {
            background: var(--settings-bg);
            border-radius: 16px;
            padding: 14px 16px;
            margin-bottom: 20px;
            box-shadow: var(--shadow-inner);
            display: grid;
            grid-template-columns: 68px 1fr;
            row-gap: 0;
            column-gap: 12px;
            align-items: start;
        }

        /* Each label cell */
        .sp-label {
            font-size: var(--fs-xs);
            font-weight: 700;
            letter-spacing: 0.8px;
            text-transform: uppercase;
            color: var(--text-muted);
            text-align: right;
            padding: var(--sp-md) 0 10px 0;
            align-self: start;
            white-space: normal;
            word-break: break-word;
            line-height: var(--lh-tight);
        }

        /* Divider between rows — spans both columns */
        .sp-divider {
            grid-column: 1 / -1;
            height: 1px;
            background: linear-gradient(90deg, transparent, var(--tile-border), transparent);
            opacity: 0.5;
            margin: 0;
        }

        /* Controls cell */
        .sp-controls {
            display: flex;
            align-items: flex-start;
            flex-wrap: wrap;
            gap: 6px;
            padding: 8px 0;
            min-width: 0;
            overflow: visible;
        }

        /* ── Segmented control (Length) ─────────────────────────────────── */
        .seg-group {
            display: inline-flex;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: var(--shadow-inner);
            border: 1px solid var(--tile-border);
            flex-shrink: 0;
        }

        .seg-group input[type="radio"] { display: none; }

        .seg-group label {
            padding: 5px 10px;
            font-size: 0.85rem;
            font-weight: 700;
            cursor: pointer;
            background: var(--settings-bg);
            color: var(--text-muted);
            transition: background 0.15s, color 0.15s, box-shadow 0.15s;
            border-right: 1px solid var(--tile-border);
            user-select: none;
            line-height: 1.4;
            white-space: nowrap;
        }

        .seg-group label:last-of-type { border-right: none; }

        .seg-group label:hover {
            background: rgba(122,179,162,0.12);
            color: var(--text-main);
            box-shadow: inset 0 -2px 0 #7ab3a2;
        }

        .seg-group input[type="radio"]:checked + label {
            background: #7ab3a2;
            color: #fff;
        }

        /* ── Pill toggle group (Mode, Game, Level, Vocab) ───────────────── */
        .pill-group {
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
            min-width: 0;
            width: 100%;
        }

        .pill-group input[type="radio"] { display: none; }

        .pill-group label {
            display: inline-flex;
            align-items: center;
            gap: 5px;
            padding: 5px 12px;
            border-radius: 20px;
            font-size: 0.82rem;
            font-weight: 700;
            cursor: pointer;
            border: 1.5px solid var(--tile-border);
            background: var(--settings-bg);
            color: var(--text-muted);
            transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
            user-select: none;
            white-space: nowrap;
            flex-shrink: 0;
        }

        .pill-group label:hover {
            border-color: #7ab3a2;
            color: var(--text-main);
        }

        .pill-group input[type="radio"]:checked + label {
            background: #7ab3a2;
            color: #fff;
            border-color: #7ab3a2;
            box-shadow: 0 2px 8px rgba(122,179,162,0.35);
        }

        /* tooltip dotted underline on pill span */
        .pill-group label span[title] {
            cursor: help;
            border-bottom: 1px dotted rgba(255,255,255,0.5);
        }

        .pill-group input[type="radio"]:not(:checked) + label span[title] {
            border-bottom-color: #ccc;
        }

        /* ── Record Stats note ──────────────────────────────────────────── */
        .sp-note {
            font-size: 0.68rem;
            color: var(--text-muted);
            opacity: 0.75;
            margin-top: 2px;
            font-weight: 600;
        }

        /* Hides grid rows without breaking column structure */
        .sp-hidden {
            display: none !important;
        }

        /* ════════════════════════════════════════════════════
           QUIZ SYSTEM
           ════════════════════════════════════════════════════ */

        /* Quiz difficulty row — hidden in non-quiz modes, toggled by JS via sp-hidden */

        /* Quiz status bar override */
        .quiz-status-bar #wordTrackerText {
            background: linear-gradient(135deg, #7ab3a2, #5a9e8e);
            color: #fff;
            font-size: 0.8rem;
            letter-spacing: 0.5px;
        }

        /* Rarity colour coding for found words */
        .found-word.rarity-common   { background: #d5f5e3; color: #2e7d52; }
        .found-word.rarity-uncommon { background: #dce8ff; color: #2952a3; }
        .found-word.rarity-obscure  { background: #f0e6ff; color: #6b21a8; }

        /* Rarity colour coding in solution grid */
        .sol-common   { color: #2e7d52 !important; }
        .sol-uncommon { color: #2952a3 !important; }
        .sol-obscure  { color: #6b21a8 !important; }

        /* Quiz end modal extras */
        .quiz-score-banner {
            background: linear-gradient(135deg, #7ab3a2 0%, #5a9e8e 100%);
            border-radius: 16px;
            padding: 18px;
            margin: 12px 0;
            color: #fff;
        }
        .quiz-score-big {
            font-size: 2.4rem;
            font-weight: 900;
            line-height: 1;
            font-family: 'Playfair Display', serif;
        }
        .quiz-score-sub {
            font-size: 0.78rem;
            font-weight: 700;
            letter-spacing: 1px;
            text-transform: uppercase;
            opacity: 0.85;
            margin-top: 4px;
        }
        .quiz-rarity-breakdown {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 8px;
            margin: 12px 0;
        }
        .qrb-cell {
            border-radius: 12px;
            padding: 10px 6px;
            text-align: center;
        }
        .qrb-cell.common   { background: #d5f5e3; }
        .qrb-cell.uncommon { background: #dce8ff; }
        .qrb-cell.obscure  { background: #f0e6ff; }
        .qrb-num  { font-size: 1.4rem; font-weight: 900; line-height: 1; }
        .qrb-lbl  { font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.75; margin-top: 3px; }
        .qrb-cell.common   .qrb-num { color: #2e7d52; }
        .qrb-cell.uncommon .qrb-num { color: #2952a3; }
        .qrb-cell.obscure  .qrb-num { color: #6b21a8; }

        .btn-quiz-submit {
            width: 100%;
            margin-top: 14px;
            padding: 14px;
            background: linear-gradient(135deg, #7ab3a2, #5a9e8e);
            color: #fff;
            border: none;
            border-radius: 16px;
            font-size: 1rem;
            font-weight: 700;
            cursor: pointer;
            font-family: inherit;
            box-shadow: 0 4px 14px rgba(122,179,162,0.45);
            transition: opacity 0.2s, transform 0.1s;
            letter-spacing: 0.3px;
        }
        .btn-quiz-submit:hover  { opacity: 0.92; }
        .btn-quiz-submit:active { transform: scale(0.98); box-shadow: var(--shadow-inner); }
        .btn-quiz-submit:disabled {
            opacity: 0.5;
            cursor: default;
            background: #ccc;
            box-shadow: none;
        }

        /* Rank reveal pill */
        .rank-pill {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            background: #fff8e1;
            border: 1.5px solid #ffe082;
            border-radius: 20px;
            padding: 6px 16px;
            font-size: 0.9rem;
            font-weight: 700;
            color: #b8860b;
            margin-top: 10px;
        }

        /* Share button */
        .btn-share {
            width: 100%;
            margin-top: 8px;
            padding: 11px;
            background: transparent;
            color: var(--text-muted);
            border: 1.5px solid var(--tile-border);
            border-radius: 14px;
            font-size: 0.88rem;
            font-weight: 700;
            cursor: pointer;
            font-family: inherit;
            transition: border-color 0.15s, color 0.15s;
        }
        .btn-share:hover { border-color: #7ab3a2; color: var(--text-main); }

        /* ── Quiz Selection Screen ──────────────────────────────────────── */
        #quizSelectionPage {
            display: none;
            position: fixed;
            top: 0; left: 0; width: 100%; height: 100%;
            background: var(--page-bg);
            z-index: 200;
            overflow-y: auto;
            box-sizing: border-box;
        }

        .quiz-sel-date {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            font-size: 0.82rem;
            font-weight: 700;
            letter-spacing: 0.3px;
            color: #2a6e58;
            background: linear-gradient(135deg, #d4f5e9 0%, #c0eedd 100%);
            border: 1.5px solid #7ab3a2;
            border-radius: 20px;
            padding: 6px 14px;
            margin: 6px 0 16px 0;
        }
        [data-theme="dark"] .quiz-sel-date {
            color: #90e8cc;
            background: linear-gradient(135deg, #0d2a1e 0%, #0a2018 100%);
            border-color: #2a6e58;
        }
        [data-theme="nightlight"] .quiz-sel-date {
            color: #6a4a20;
            background: linear-gradient(135deg, #f5e8d0 0%, #eedfc0 100%);
            border-color: #b08040;
        }

        .quiz-category {
            margin-bottom: 28px;
        }

        .quiz-category-header {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 12px;
            padding-bottom: 8px;
            border-bottom: 1px solid var(--tile-border);
        }

        .quiz-category-icon { font-size: 1.4rem; }

        .quiz-category-title {
            font-size: 1rem;
            font-weight: 800;
            color: var(--text-main);
            letter-spacing: 0.2px;
        }

        .quiz-category-desc {
            font-size: 0.75rem;
            color: var(--text-muted);
            font-weight: 600;
            margin-left: auto;
        }

        /* Two-column layout: Explorer left, Scholar right */
        .quiz-diff-columns {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 12px;
            margin-top: 4px;
        }

        .quiz-diff-col-header {
            font-size: 0.68rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.8px;
            padding: 6px 10px;
            border-radius: 8px;
            margin-bottom: 8px;
            text-align: center;
        }
        .quiz-diff-col-header.explorer { background: #dce8ff; color: #2952a3; }
        .quiz-diff-col-header.scholar  { background: #f0e6ff; color: #6b21a8; }

        .quiz-diff-col { display: flex; flex-direction: column; gap: 8px; }

        .quiz-card {
            border-radius: 16px;
            padding: 14px;
            cursor: pointer;
            border: 1.5px solid var(--tile-border);
            background: var(--settings-bg);
            transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
            position: relative;
            overflow: hidden;
        }

        .quiz-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 18px rgba(0,0,0,0.1);
            border-color: #7ab3a2;
        }

        .quiz-card:active { transform: scale(0.98); }

        /* Completed state */
        .quiz-card.completed {
            border-color: #7ab3a2;
            background: linear-gradient(135deg, rgba(122,179,162,0.08), rgba(122,179,162,0.03));
        }

        .quiz-card.completed::after {
            content: '✓';
            position: absolute;
            top: 10px; right: 12px;
            font-size: 0.8rem;
            font-weight: 900;
            color: #7ab3a2;
        }

        .qcard-top {
            display: flex;
            align-items: center;
            gap: 8px;
            margin-bottom: 6px;
        }

        .qcard-len {
            font-size: 1.3rem;
            font-weight: 900;
            color: var(--text-main);
            line-height: 1;
            font-family: 'Playfair Display', serif;
        }

        .qcard-diff {
            font-size: 0.65rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.6px;
            padding: 3px 8px;
            border-radius: 20px;
        }

        .qcard-diff.explorer { background: #dce8ff; color: #2952a3; }
        .qcard-diff.scholar  { background: #f0e6ff; color: #6b21a8; }

        .qcard-timer {
            margin-left: auto;
            font-size: 0.7rem;
            font-weight: 700;
            color: var(--text-muted);
        }

        .qcard-status {
            font-size: 0.72rem;
            font-weight: 700;
            color: var(--text-muted);
        }

        .qcard-status.done { color: #7ab3a2; }

        .qcard-score {
            font-size: 1rem;
            font-weight: 800;
            color: #7ab3a2;
        }

        /* Active quiz banner inside game card */
        #quizActiveBanner {
            display: none;
            border-radius: 14px;
            padding: 10px 14px;
            margin-bottom: 12px;
            background: linear-gradient(135deg, #7ab3a2 0%, #5a9e8e 100%);
            color: #fff;
            align-items: center;
            justify-content: space-between;
        }

        .qab-left { display: flex; flex-direction: column; }
        .qab-label {
            font-size: 0.6rem;
            font-weight: 700;
            letter-spacing: 1px;
            text-transform: uppercase;
            opacity: 0.8;
        }
        .qab-detail {
            font-size: 0.9rem;
            font-weight: 800;
            letter-spacing: 0.2px;
        }
        .qab-date {
            font-size: 0.68rem;
            font-weight: 700;
            opacity: 0.75;
        }

        /* Speed quiz countdown */
        #quizCountdown {
            font-size: 1.1rem;
            font-weight: 900;
            font-family: 'Playfair Display', serif;
            letter-spacing: 0.5px;
            padding: 4px 10px;
            background: rgba(255,255,255,0.2);
            border-radius: 8px;
        }
        #quizCountdown.urgent { background: rgba(255,80,80,0.35); }
        #quizHubPage {
            display: none;
            position: fixed;
            top: 0; left: 0; width: 100%; height: 100%;
            background: var(--page-bg);
            z-index: 200;
            overflow-y: auto;
            padding: 20px;
            box-sizing: border-box;
        }

        /* Main tab bar — left-aligned strip */
        .hub-tabs {
            display: flex;
            gap: 0;
            margin: 16px 0 20px 0;
            background: var(--settings-bg);
            border-radius: 12px;
            padding: 4px;
            box-shadow: var(--shadow-inner);
        }
        .hub-tab {
            flex: 1;
            padding: 8px 6px;
            border-radius: 9px;
            border: none;
            background: transparent;
            color: var(--text-muted);
            font-size: 0.78rem;
            font-weight: 700;
            cursor: pointer;
            font-family: inherit;
            transition: all 0.15s;
            text-align: center;
            box-shadow: none;
            white-space: nowrap;
        }
        .hub-tab.active {
            background: #7ab3a2;
            color: #fff;
            box-shadow: 0 2px 8px rgba(122,179,162,0.35);
        }
        .hub-tab:not(.active):hover {
            color: var(--text-main);
            background: var(--tile-border);
        }

        .hub-panel { display: none; }
        .hub-panel.active { display: block; }

        /* Sub-tab row (leaderboard difficulty) — left-aligned, smaller */
        .hub-sub-tabs {
            display: flex;
            gap: 6px;
            margin-bottom: 16px;
        }
        .hub-sub-tab {
            padding: 5px 14px;
            border-radius: 20px;
            border: 1.5px solid var(--tile-border);
            background: transparent;
            color: var(--text-muted);
            font-size: 0.78rem;
            font-weight: 700;
            cursor: pointer;
            font-family: inherit;
            transition: all 0.15s;
            box-shadow: none;
            flex: none;
        }
        .hub-sub-tab.active, .hub-sub-tab:hover {
            background: #7ab3a2;
            color: #fff;
            border-color: #7ab3a2;
        }

        /* Section meta line */
        .hub-meta {
            font-size: 0.75rem;
            color: var(--text-muted);
            font-weight: 600;
            margin: 0 0 14px 0;
            line-height: 1.5;
        }

        /* Leaderboard table */
        .lb-table {
            width: 100%;
            border-collapse: collapse;
            font-size: 0.85rem;
            margin-bottom: 16px;
        }
        .lb-table th {
            text-align: left;
            font-size: 0.65rem;
            text-transform: uppercase;
            letter-spacing: 0.8px;
            color: var(--text-muted);
            padding: 6px 8px;
            border-bottom: 1px solid var(--tile-border);
        }
        .lb-table td {
            padding: 8px 8px;
            border-bottom: 1px solid var(--tile-border);
            font-weight: 600;
            color: var(--text-main);
        }
        .lb-table tr.is-me td { color: #7ab3a2; font-weight: 800; }
        .lb-rank  { font-weight: 900; color: var(--text-muted); width: 28px; }
        .lb-score { font-weight: 800; text-align: right; }

        /* ── Leaderboard Option-A grid ───────────────────────────────────── */
        .lb-grid-wrap {
            margin-bottom: 16px;
        }

        .lb-grid-type-toggle {
            display: flex;
            gap: 6px;
            margin-bottom: 10px;
        }

        .lb-type-btn {
            flex: 1;
            padding: 8px;
            border-radius: 12px;
            border: 1.5px solid var(--tile-border);
            background: var(--settings-bg);
            color: var(--text-muted);
            font-weight: 700;
            font-size: 0.82rem;
            font-family: inherit;
            cursor: pointer;
            transition: all 0.15s;
            text-align: center;
        }
        .lb-type-btn.active {
            background: #7ab3a2;
            border-color: #7ab3a2;
            color: #fff;
        }

        .lb-grid {
            display: grid;
            grid-template-columns: 28px 1fr 1fr;
            gap: 5px;
            align-items: stretch;
        }

        .lb-grid-head {
            font-size: 0.62rem;
            font-weight: 800;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            color: var(--text-muted);
            padding: 4px 6px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .lb-grid-row-label {
            font-size: 0.75rem;
            font-weight: 800;
            color: var(--text-muted);
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 2px 0;
        }

        .lb-grid-cell {
            border-radius: 12px;
            border: 1.5px solid var(--tile-border);
            background: var(--settings-bg);
            padding: 9px 10px;
            cursor: pointer;
            transition: border-color 0.15s, background 0.15s, transform 0.1s;
            min-height: 54px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            gap: 2px;
        }
        .lb-grid-cell:hover {
            border-color: #7ab3a2;
            transform: translateY(-1px);
        }
        .lb-grid-cell:active { transform: scale(0.98); }
        .lb-grid-cell.selected {
            border-color: #7ab3a2;
            background: linear-gradient(135deg, rgba(122,179,162,0.12), rgba(122,179,162,0.04));
        }
        .lb-grid-cell.disabled {
            opacity: 0.35;
            cursor: default;
            pointer-events: none;
        }

        .lb-cell-leader {
            font-size: 0.75rem;
            font-weight: 800;
            color: var(--text-main);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .lb-cell-score {
            font-size: 0.68rem;
            font-weight: 700;
            color: #7ab3a2;
        }
        .lb-cell-empty {
            font-size: 0.68rem;
            color: var(--text-muted);
            font-style: italic;
        }

        /* Detail panel below grid */
        .lb-detail-panel {
            border-radius: 14px;
            border: 1.5px solid #7ab3a2;
            padding: 12px;
            margin-top: 4px;
            background: linear-gradient(135deg, rgba(122,179,162,0.07), transparent);
        }
        .lb-detail-header {
            font-size: 0.72rem;
            font-weight: 800;
            color: #7ab3a2;
            text-transform: uppercase;
            letter-spacing: 0.6px;
            margin-bottom: 10px;
        }

        /* History list */
        .hist-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 10px 14px;
            border-radius: 12px;
            background: var(--settings-bg);
            margin-bottom: 8px;
            font-size: 0.85rem;
            font-weight: 600;
        }
        .hist-date  { color: var(--text-muted); font-size: 0.75rem; margin-top: 2px; }
        .hist-score { font-weight: 800; color: #7ab3a2; font-size: 1rem; flex-shrink: 0; margin-left: 10px; }
        .hist-rank  {
            display: inline-block;
            margin-left: 6px;
            font-size: 0.7rem;
            font-weight: 700;
            color: #7ab3a2;
            background: rgba(122,179,162,0.12);
            padding: 1px 6px;
            border-radius: 6px;
        }

        /* Rarity stats progress bars */
        .rarity-stat-row { margin-bottom: 16px; }
        .rarity-stat-label {
            display: flex;
            justify-content: space-between;
            font-size: 0.78rem;
            font-weight: 700;
            margin-bottom: 6px;
        }
        .rarity-bar-bg {
            height: 10px;
            border-radius: 6px;
            background: var(--tile-border);
            overflow: hidden;
        }
        .rarity-bar-fill {
            height: 100%;
            border-radius: 6px;
            transition: width 0.6s ease;
        }
        .rarity-bar-fill.common   { background: #4ecb8d; }
        .rarity-bar-fill.uncommon { background: #5b8dee; }
        .rarity-bar-fill.obscure  { background: #a855f7; }

        /* ── Quiz Badge Grid ─────────────────────────────────────────────── */
        .qbadge-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 10px;
            margin-top: 4px;
        }

        .qbadge {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: flex-start;
            gap: 5px;
            padding: 10px 6px 8px 6px;
            border-radius: 14px;
            cursor: default;
            transition: transform 0.15s;
            position: relative;
        }
        .qbadge:hover { transform: translateY(-2px); }
        .qbadge:hover .qbadge-tooltip { opacity: 1; pointer-events: auto; transform: translateY(0); }

        .qbadge-icon {
            font-size: 1.6rem;
            width: 48px;
            height: 48px;
            border-radius: 13px;
            display: flex;
            align-items: center;
            justify-content: center;
            line-height: 1;
            /* Earned: replaced per badge via inline style */
        }

        .qbadge-name {
            font-size: 0.6rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.4px;
            text-align: center;
            line-height: 1.2;
        }

        /* Earned state */
        .qbadge.earned .qbadge-icon {
            box-shadow: 0 3px 10px rgba(0,0,0,0.15);
        }
        .qbadge.earned .qbadge-name { color: var(--text-main); }

        /* Locked state */
        .qbadge.locked .qbadge-icon {
            background: var(--settings-bg) !important;
            border: 2px dashed var(--tile-border) !important;
            filter: grayscale(1);
            opacity: 0.4;
        }
        .qbadge.locked .qbadge-name { color: var(--text-muted); opacity: 0.5; }

        /* Tooltip */
        .qbadge-tooltip {
            position: absolute;
            bottom: calc(100% + 8px);
            left: 50%;
            transform: translateX(-50%) translateY(4px);
            white-space: nowrap;
            padding: 6px 10px;
            border-radius: 8px;
            font-size: 0.72rem;
            font-weight: 700;
            color: #fff;
            background: #333;
            pointer-events: none;
            opacity: 0;
            transition: opacity 0.2s, transform 0.2s;
            z-index: 999;
            max-width: 180px;
            white-space: normal;
            text-align: center;
            line-height: 1.3;
        }
        .qbadge-tooltip::after {
            content: '';
            position: absolute;
            top: 100%; left: 50%;
            transform: translateX(-50%);
            border: 5px solid transparent;
            border-top-color: #333;
        }

        /* New-badge flash animation */
        @keyframes badgeEarned {
            0%   { transform: scale(0.6); opacity: 0; }
            60%  { transform: scale(1.15); opacity: 1; }
            100% { transform: scale(1); opacity: 1; }
        }
        .qbadge.just-earned .qbadge-icon {
            animation: badgeEarned 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
        }

        /* ── Quiz history reset modal — must sit above hub page (z:200) ── */
        #quizHubOverlay {
            display: none;
            position: fixed;
            top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0,0,0,0.35);
            backdrop-filter: blur(4px);
            z-index: 290;
        }
        #quizResetConfirmModal {
            z-index: 300;
        }
        /* ── Nickname prompt modal ──────────────────────────────────────── */
        #nicknameModal .nick-input {
            width: 100%;
            padding: 12px 14px;
            border-radius: 14px;
            border: 1.5px solid var(--tile-border);
            font-family: inherit;
            font-weight: 700;
            font-size: 1rem;
            color: var(--text-main);
            background: var(--input-bg);
            box-shadow: var(--shadow-inner);
            outline: none;
            box-sizing: border-box;
            margin: 12px 0 6px 0;
            text-align: center;
            letter-spacing: 0.3px;
            transition: border-color 0.15s;
        }
        #nicknameModal .nick-input:focus { border-color: #7ab3a2; }
        #nicknameModal {
            z-index: 150; /* sits above the quiz modal (101) and its overlay (100) */
        }
        #nicknameModal .nick-note {
            font-size: 0.75rem;
            color: var(--text-muted);
            font-weight: 600;
            margin: 0 0 18px 0;
        }

        #quizSubHeader {
            display: none;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
            background: linear-gradient(135deg, #7ab3a2 0%, #5a9e8e 100%);
            border-radius: 14px;
            padding: 10px 16px;
            margin-bottom: 12px;
        }
        .qsh-left {
            display: flex;
            flex-direction: column;
        }
        .qsh-title {
            font-family: 'Quicksand', sans-serif;
            font-size: 0.65rem;
            font-weight: 700;
            letter-spacing: 1.2px;
            text-transform: uppercase;
            color: rgba(255,255,255,0.8);
        }
        .qsh-detail {
            font-size: 0.88rem;
            font-weight: 800;
            color: #fff;
            margin-top: 1px;
            letter-spacing: 0.2px;
        }
        .qsh-date {
            font-size: 0.7rem;
            font-weight: 700;
            color: rgba(255,255,255,0.75);
            letter-spacing: 0.3px;
        }
        .quiz-locked-msg {
            background: var(--settings-bg);
            border: 1.5px solid var(--tile-border);
            border-radius: 16px;
            padding: 20px;
            text-align: center;
            margin: 12px 0;
        }
        .quiz-locked-icon { font-size: 2rem; margin-bottom: 8px; }
        .quiz-locked-title {
            font-weight: 800;
            font-size: 1rem;
            color: var(--text-main);
            margin-bottom: 6px;
        }
        .quiz-locked-sub {
            font-size: 0.82rem;
            color: var(--text-muted);
            font-weight: 600;
            line-height: 1.5;
        }

        /* ── Status bar ─────────────────────────────────────────────────── */
        .status-bar {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
            margin: 16px 0 12px 0;
            padding: 0;
            background: none;
            border-radius: 0;
        }

        /* Left: word-count pill */
        #wordTrackerText {
            display: inline-flex;
            align-items: center;
            font-size: 0.78rem;
            font-weight: 700;
            letter-spacing: 0.4px;
            color: var(--status-text);
            background: var(--status-bg);
            padding: 5px 14px;
            border-radius: 20px;
        }

        /* Right: badge + timer cluster */
        .status-right {
            display: flex;
            align-items: center;
            gap: 6px;
        }

        /* ── Word-building display area ─────────────────────────────────── */
        .display-area {
            min-height: 72px;
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 8px;
            margin-bottom: 4px;
            background: var(--input-bg);
            border-radius: 18px;
            box-shadow: var(--shadow-inner);
            border: 1.5px solid var(--tile-border);
            transition: all 0.3s ease;
            padding: 12px 16px;
        }

        .display-letter {
            font-size: 1.8rem;
            font-weight: 700;
            color: #555;
            width: 35px;
            text-align: center;
            border-bottom: 2px solid transparent;
        }

        .display-letter.active {
            border-bottom: 2px solid #7ab3a2;
            animation: tr-slot-fill 0.2s cubic-bezier(0.34, 1.56, 0.64, 1) both;
        }

        /* Hook Mode Specific Styles */
        .hook-container {
            display: flex;
            align-items: center;
            gap: 12px;
            justify-content: center;
            width: 100%;
        }

        .slot-hook {
            width: 45px;
            height: 50px;
            border: 2px dashed #b0c4de;
            border-radius: 12px;
            background: transparent;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.5rem;
            font-weight: 700;
            color: #555;
            cursor: pointer;
            transition: all 0.15s ease;
        }

        .slot-hook:hover {
            background: rgba(122,179,162,0.12);
            border-color: #7ab3a2;
            border-style: solid;
            transform: scale(1.08);
            box-shadow: 0 4px 12px rgba(122,179,162,0.25);
        }

        .slot-hook.success {
            background: var(--success-green);
            border-color: #3e7e57;
            border-style: solid;
            color: #3e7e57;
            animation: tr-hook-success 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
        }

        .base-word-display {
            display: flex;
            gap: 4px;
            padding: 8px;
            background: var(--accent-blue);
            border-radius: 16px;
            box-shadow: var(--shadow-inner);
        }

        .base-word-display .tile {
            cursor: default;
            box-shadow: 2px 2px 5px rgba(0,0,0,0.05);
            transform: none !important;
            margin: 0;
            width: 40px;
            height: 45px;
        }

        /* Animations */
        .shake { animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both; background: var(--error-red); }
        @keyframes shake {
            10%, 90% { transform: translate3d(-1px, 0, 0); }
            20%, 80% { transform: translate3d(2px, 0, 0); }
            30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
            40%, 60% { transform: translate3d(4px, 0, 0); }
        }

        .bounce { animation: bounce 0.4s ease; }
        @keyframes bounce {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-10px); }
        }

        @keyframes tileFlip {
            0% { transform: rotateY(0deg); background: #eee; color: transparent; }
            50% { transform: rotateY(90deg); background: #ddd; color: transparent; }
            100% { transform: rotateY(0deg); background: var(--tile-bg); color: var(--text-main); }
        }

        .flipping { animation: tileFlip 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards; }

        /* Reduced motion — fast fade-in instead of flip */
        .reduced-motion .flipping {
            animation: none !important;
            opacity: 1 !important;
            transition: opacity 0.15s ease !important;
        }
        /* No animation — instant appear */
        .no-animation .flipping {
            animation: none !important;
            opacity: 1 !important;
            transition: none !important;
        }
        .no-animation .bounce, .no-animation .shake {
            animation: none !important;
        }
        .reduced-motion .bounce {
            animation: none !important;
        }

        /* ══════════════════════════════════════════════════════
           TRAINING MICRO-INTERACTIONS — Phase A + Phase B
           ══════════════════════════════════════════════════ */

        /* ── #1 Tile selecting lift ── (class applied via JS) */
        /* (rules live on .tile.selecting above) */

        /* ── #2 Display slot drop-in ── */
        @keyframes tr-slot-fill {
            0%   { opacity: 0; transform: translateY(-10px) scale(0.9); }
            100% { opacity: 1; transform: translateY(0)    scale(1); }
        }
        .reduced-motion .display-letter.active,
        .no-animation   .display-letter.active { animation: none; }

        /* ── #3 Word tracker counter pulse ── */
        @keyframes tr-counter-pulse {
            0%   { transform: scale(1); }
            45%  { transform: scale(1.13); }
            70%  { transform: scale(0.97); }
            100% { transform: scale(1); }
        }
        #wordTrackerText.tr-updating {
            animation: tr-counter-pulse 0.38s cubic-bezier(0.34, 1.56, 0.64, 1) both;
        }
        .reduced-motion #wordTrackerText.tr-updating,
        .no-animation   #wordTrackerText.tr-updating { animation: none; }

        /* ── #4 Found word entrance ── */
        @keyframes tr-word-in {
            0%   { opacity: 0; transform: scale(0.7) translateY(6px); }
            65%  { transform: scale(1.08); opacity: 1; }
            100% { transform: scale(1)    translateY(0); opacity: 1; }
        }

        /* ── #5 Hook slot success bounce ── */
        @keyframes tr-hook-success {
            0%   { transform: scale(0.65); opacity: 0; }
            55%  { transform: scale(1.12); opacity: 1; }
            80%  { transform: scale(0.97); }
            100% { transform: scale(1); }
        }
        .reduced-motion .slot-hook.success,
        .no-animation   .slot-hook.success { animation: none; }
        @media (hover: none) {
            .slot-hook:hover { transform: none; box-shadow: none; }
        }

        /* ── #6 Feedback message slide-in ── */
        @keyframes tr-feedback-in {
            0%   { opacity: 0; transform: translateY(-7px); }
            100% { opacity: 1; transform: translateY(0); }
        }
        .feedback-msg.tr-feedback-active {
            animation: tr-feedback-in 0.22s ease-out both;
        }
        .reduced-motion .feedback-msg.tr-feedback-active,
        .no-animation   .feedback-msg.tr-feedback-active { animation: none; }

        /* ── #7 Hand cleared glow on display area ── */
        @keyframes tr-clear-glow {
            0%, 100% { border-color: var(--tile-border);  box-shadow: var(--shadow-inner); }
            40%      { border-color: #3e7e57;             box-shadow: var(--shadow-inner), 0 0 18px 5px rgba(62,126,87,0.28); }
        }
        .display-area.tr-cleared {
            animation: tr-clear-glow 0.65s ease-out 3;
        }
        .reduced-motion .display-area.tr-cleared,
        .no-animation   .display-area.tr-cleared { animation: none; }

        /* ── #9 Rack dimming — rules live on .tile-rack.has-tr-selection above ── */
        
        @keyframes modalWin {
            0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
            50% { transform: translate(-50%, -50%) scale(1.05); opacity: 1; }
            100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
        }
        .win-anim { animation: modalWin 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards !important; }

        .feedback-msg {
            height: 22px;
            font-size: 0.82rem;
            font-weight: 700;
            margin: 6px 0 12px 0;
            text-align: center;
            transition: opacity 0.3s;
            letter-spacing: 0.2px;
        }

        /* ── Rack area ──────────────────────────────────────────────────── */
        .rack-container {
            width: 100%;
            margin-bottom: 12px;
        }

        .btn-shuffle {
            width: 40px;
            height: 40px;
            border-radius: 12px;
            border: 1.5px solid var(--tile-border);
            background: var(--container-bg);
            box-shadow: var(--shadow-outer);
            cursor: pointer;
            font-size: 1rem;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.15s;
            color: #7ab3a2;
            flex-shrink: 0;
        }
        .btn-shuffle:hover { border-color: #7ab3a2; }
        .btn-shuffle:active { box-shadow: var(--shadow-inner); transform: scale(0.95); }

        .tile-rack { display: flex; gap: 6px; flex-wrap: nowrap; justify-content: center; width: 100%; }

        .tile {
            width: 45px;
            height: 50px;
            flex-shrink: 0;
            background: var(--tile-bg);
            box-shadow: 4px 4px 8px rgba(0,0,0,0.05), -4px -4px 8px #ffffff;
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.3rem;
            font-weight: 700;
            cursor: pointer;
            transition: all 0.15s ease;
            user-select: none;
            border: 1px solid var(--tile-border);
        }
        .tile:active { box-shadow: var(--shadow-inner); transform: scale(0.95); }
        /* #1 — selected tile lifts and glows */
        .tile.selecting {
            transform: translateY(-6px) scale(1.09);
            box-shadow: 0 6px 16px rgba(122,179,162,0.45), inset 0 1px 0 rgba(255,255,255,0.8);
            border-color: #7ab3a2;
            border-width: 1.5px;
            color: #3e7e57;
        }
        .tile.used { 
            opacity: 0.3; 
            pointer-events: none; 
            filter: grayscale(1); 
            box-shadow: none;
            border-color: #f0f0f0;
        }
        /* subtle hover glow — pointer devices only */
        .tile:hover:not(.used):not(.selecting) {
            transform: translateY(-2px) scale(1.04);
            box-shadow: 0 4px 12px rgba(122,179,162,0.38),
                        4px 4px 8px rgba(0,0,0,0.05),
                        -4px -4px 8px #ffffff;
            border-color: rgba(122,179,162,0.5);
        }
        @media (hover: none) {
            .tile:hover:not(.used):not(.selecting) { transform: none; box-shadow: 4px 4px 8px rgba(0,0,0,0.05), -4px -4px 8px #ffffff; border-color: var(--tile-border); }
        }
        /* #9 — dim unselected tiles when any is selected */
        .tile-rack.has-tr-selection .tile:not(.selecting):not(.used) {
            opacity: 0.42;
            transform: scale(0.94);
        }

        /* ── Found words section ────────────────────────────────────────── */
        .found-container {
            margin-top: 18px;
            background: var(--settings-bg);
            border-radius: 16px;
            padding: 14px 16px;
            box-shadow: var(--shadow-inner);
            min-height: 70px;
        }
        .found-label {
            font-size: 0.68rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.8px;
            color: var(--text-muted);
            margin-bottom: 10px;
        }

        .found-list { display: flex; flex-wrap: wrap; gap: 6px; }

        .found-word {
            background: var(--found-bg);
            color: var(--found-color);
            padding: 5px 12px;
            border-radius: 20px;
            font-size: 0.88rem;
            font-weight: 700;
            letter-spacing: 0.3px;
        }
        /* #4 — new word entrance animation (added via JS) */
        .found-word.tr-word-in {
            animation: tr-word-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
        }
        .reduced-motion .found-word.tr-word-in,
        .no-animation   .found-word.tr-word-in { animation: none; }

        /* ── Action buttons ─────────────────────────────────────────────── */
        .button-group { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
        .row { display: flex; gap: 8px; justify-content: center; }

        /* ── Base button ── */
        button {
            flex: 1;
            padding: 11px var(--sp-md);
            border: none;
            border-radius: var(--radius-md);
            font-size: var(--fs-base);
            font-weight: 700;
            cursor: pointer;
            box-shadow: 3px 3px 8px rgba(0,0,0,0.05), -3px -3px 8px rgba(255,255,255,0.7);
            transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.15s, background 0.12s;
            font-family: inherit;
            letter-spacing: 0.2px;
            line-height: var(--lh-tight);
        }
        button:not(:disabled):hover  { transform: translateY(-2px); box-shadow: 0 5px 14px rgba(0,0,0,0.1); }
        button:not(:disabled):active { transform: translateY(0) scale(0.97); box-shadow: var(--shadow-inner); }
        @media (hover: none) {
            button:not(:disabled):hover { transform: none; box-shadow: 3px 3px 8px rgba(0,0,0,0.05), -3px -3px 8px rgba(255,255,255,0.7); }
        }
        .reduced-motion button, .no-animation button { transition: box-shadow 0.1s; }

        /* ── PRIMARY: Submit, Confirm — teal, strong ── */
        .btn-submit {
            background: var(--btn-primary-bg);
            color: var(--btn-primary-color);
            border: none;
            box-shadow: 0 3px 10px var(--brand-primary-glow);
        }
        .btn-submit:hover { background: var(--brand-primary-dark); }
        .btn-submit:active { box-shadow: var(--shadow-inner); }

        /* ── SECONDARY: Clear — neutral, outlined ── */
        .btn-clear {
            background: var(--btn-secondary-bg);
            color: var(--btn-secondary-color);
            border: 1.5px solid var(--btn-secondary-border);
            box-shadow: none;
        }
        .btn-clear:hover { border-color: var(--brand-primary); color: var(--text-main); }

        /* ── SECONDARY: Shuffle, Refresh — neutral, outlined ── */
        .btn-action {
            background: var(--btn-secondary-bg);
            color: var(--btn-secondary-color);
            border: 1.5px solid var(--btn-secondary-border);
            box-shadow: none;
        }
        .btn-action:hover { border-color: var(--brand-primary); color: var(--text-main); }

        /* ── DESTRUCTIVE: Give Up! — red, clear warning ── */
        .btn-destructive {
            background: var(--btn-destructive-bg);
            color: var(--btn-destructive-color);
            border: 1.5px solid var(--btn-destructive-border);
            box-shadow: none;
            font-weight: 800;
        }
        .btn-destructive:hover {
            background: #ffd5d5;
            border-color: #d84040;
        }

        /* Stats — warm accent */
        .btn-gold {
            background: #fff8e1;
            color: #b8860b;
            border: 1.5px solid #ffe082;
            box-shadow: none;
        }
        .btn-gold:hover { background: #fff3cd; }

        /* ── Footer ─────────────────────────────────────────────────────── */
        /* ── Free Anagram mode ───────────────────────────────────────────── */
        /* Dynamic display slots — width grows with selection */
        #freeDisplayRow {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 6px;
            min-height: 56px;
            flex-wrap: wrap;
        }
        .free-slot {
            width: 44px;
            height: 52px;
            border-radius: 10px;
            border: 2px solid var(--tile-border);
            background: var(--settings-bg);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.3rem;
            font-weight: 700;
            color: var(--text-main);
            transition: border-color 0.15s, background 0.15s;
        }
        .free-slot.filled {
            border-color: #7ab3a2;
            background: rgba(122,179,162,0.1);
        }
        .free-slot.placeholder {
            opacity: 0.25;
            border-style: dashed;
        }

        /* Found words grouped by length */
        .free-length-group {
            margin-bottom: 10px;
        }
        .free-length-label {
            font-size: 0.6rem;
            font-weight: 800;
            text-transform: uppercase;
            letter-spacing: 0.8px;
            color: var(--text-muted);
            margin-bottom: 4px;
        }
        .free-words-row {
            display: flex;
            flex-wrap: wrap;
            gap: 5px;
        }

        /* Blitz countdown banner modifier */
        #quizActiveBanner.blitz-active {
            background: linear-gradient(135deg, #e67e22 0%, #d35400 100%);
        }
        #quizTopNav {
            display: none !important; /* hidden on all screen sizes — hamburger menu replaces this */
            align-items: center;
            justify-content: space-between;
            margin-bottom: 12px;
            gap: 6px;
        }
        .quiz-top-nav-btn {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 2px;
            padding: 7px 6px;
            border-radius: 12px;
            border: 1.5px solid var(--tile-border);
            background: var(--settings-bg);
            color: var(--text-main);
            font-size: 1rem;
            font-weight: 700;
            cursor: pointer;
            font-family: inherit;
            transition: border-color 0.15s, background 0.15s;
            flex: 1;
            box-shadow: none;
        }
        .quiz-top-nav-btn span {
            font-size: 0.58rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.4px;
            color: var(--text-muted);
        }
        .quiz-top-nav-btn:hover { border-color: #7ab3a2; }
        .quiz-top-nav-btn:active { transform: scale(0.97); }
        .quiz-top-nav-btn.qnav-active {
            background: #7ab3a2;
            border-color: #7ab3a2;
            color: #fff;
        }
        .quiz-top-nav-btn.qnav-active span { color: rgba(255,255,255,0.85); }

        /* ── Global footer nav ──────────────────────────────────────────── */
        .footer-controls {
            display: flex;
            flex-direction: column;
            align-items: stretch;
            gap: 0;
            margin-top: 20px;
            padding-top: 16px;
            border-top: 1px solid var(--tile-border);
        }
        .footer-controls button {
            background: transparent;
            color: var(--text-muted);
            font-size: var(--fs-xs);
            font-weight: 700;
            letter-spacing: 0.2px;
            padding: var(--sp-sm) var(--sp-sm);
            border-radius: var(--radius-xl);
            border: 1.5px solid var(--tile-border);
            box-shadow: none;
            flex: 1;
            transition: border-color 0.15s, color 0.15s;
            font-family: inherit;
            cursor: pointer;
            white-space: nowrap;
        }
        .footer-controls button:hover {
            border-color: #7ab3a2;
            color: var(--text-main);
        }
        .footer-controls button:active { transform: scale(0.97); box-shadow: none; }
        .footer-controls button.footer-active {
            border-color: #7ab3a2;
            color: #7ab3a2;
            font-weight: 800;
        }

        .hidden { display: none !important; }

        .overlay {
            display: none;
            position: fixed;
            top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(232, 245, 233, 0.4); 
            backdrop-filter: blur(10px);
            z-index: 500;
        }

        .modal {
            display: none;
            position: fixed;
            top: 50%; left: 50%;
            transform: translate(-50%, -50%);
            background: var(--container-bg);
            padding: var(--sp-2xl);
            font-size: var(--fs-base);
            line-height: var(--lh-base);
            border-radius: 32px;
            z-index: 501;
            text-align: center;
            width: 92%;
            max-width: 420px;
            box-shadow: 0 20px 50px rgba(0,0,0,0.1);
            max-height: 90vh;
            overflow-y: auto;
        }
        
        .modal-rack-wrap {
            transform: scale(0.75);
            margin-top: -10px;
            margin-bottom: 5px;
            pointer-events: none; 
        }

        .solution-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 8px;
            margin: 15px 0 20px 0;
            max-height: 150px;
            overflow-y: auto;
            font-size: 0.9rem;
            padding-right: 5px;
        }
        
        .solution-grid::-webkit-scrollbar { width: 6px; }
        .solution-grid::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

        /* Achievements Styling */
        .trophy-rack {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 10px;
            margin: 15px 0;
        }
        .trophy-card {
            background: #fafafa;
            border-radius: 12px;
            padding: 10px;
            width: 70px;
            box-shadow: var(--shadow-inner);
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        /* Trophy icon containers — strongly distinct per tier */
        .trophy-icon {
            font-size: 1.5rem; font-weight: 900; font-style: normal;
            margin-bottom: 5px; display: flex; align-items: center; justify-content: center;
            width: 48px; height: 48px; border-radius: 12px; line-height: 1;
            font-family: 'Quicksand', sans-serif; letter-spacing: -1px;
        }
        /* Copper — warm terracotta */
        .trophy-icon.copper {
            background: linear-gradient(135deg, #f5c9a0, #e8935a);
            border: 2px solid #b86a30;
            color: #7a3a10;
            box-shadow: 0 2px 8px #c97c3a55;
        }
        /* Silver — cool blue-grey with metallic feel */
        .trophy-icon.silver {
            background: linear-gradient(135deg, #dce8f5, #a8c4dc);
            border: 2px solid #6a90b0;
            color: #2e5070;
            box-shadow: 0 2px 8px #6a90b055;
        }
        /* Gold — rich amber, warm and bright */
        .trophy-icon.gold {
            background: linear-gradient(135deg, #fff0a0, #f5c800);
            border: 2px solid #c09000;
            color: #7a5800;
            box-shadow: 0 2px 10px #e8b80088;
        }
        /* Platinum — vivid teal/cyan, completely unlike gold */
        .trophy-icon.platinum {
            background: linear-gradient(135deg, #a0f5ea, #00d4be);
            border: 2px solid #00a090;
            color: #003830;
            box-shadow: 0 0 0 3px #00d4be33, 0 2px 14px #00d4be88;
        }
        .trophy-icon.none {
            background: #f0f0f0;
            border: 2px solid #e0e0e0;
            color: #ccc;
            opacity: 0.4;
        }

        .badge-rack {
            display: flex;
            gap: 10px;
            justify-content: center;
            flex-wrap: wrap;
            margin: 10px 0 20px 0;
            align-items: flex-start;
        }

        /* Badge chip */
        .badge-chip {
            position: relative;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            width: 62px;
            height: 62px;
            border-radius: 16px;
            cursor: default;
            transition: transform 0.15s, box-shadow 0.15s;
            user-select: none;
        }
        .badge-chip:hover { transform: translateY(-3px); }
        .badge-chip:hover .badge-tooltip { opacity: 1; pointer-events: auto; transform: translateY(0); }

        .badge-num {
            font-size: 1.2rem;
            font-weight: 900;
            line-height: 1;
            letter-spacing: -0.5px;
        }
        .badge-sub {
            font-size: 0.55rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            opacity: 0.75;
            margin-top: 2px;
        }

        /* Colorful floating tooltip */
        .badge-tooltip {
            position: absolute;
            bottom: calc(100% + 10px);
            left: 50%;
            transform: translateX(-50%) translateY(6px);
            white-space: nowrap;
            padding: 7px 12px;
            border-radius: 10px;
            font-size: 0.75rem;
            font-weight: 700;
            color: #fff;
            pointer-events: none;
            opacity: 0;
            transition: opacity 0.2s, transform 0.2s;
            z-index: 999;
            box-shadow: 0 4px 14px rgba(0,0,0,0.18);
            max-width: 200px;
            white-space: normal;
            text-align: center;
            line-height: 1.35;
        }
        .badge-tooltip::after {
            content: '';
            position: absolute;
            top: 100%;
            left: 50%;
            transform: translateX(-50%);
            border: 6px solid transparent;
        }

        /* Badge notification toast */
        #badgeToast {
            position: fixed;
            bottom: 30px;
            right: 20px;
            max-width: 280px;
            padding: 14px 18px;
            border-radius: 18px;
            display: flex;
            align-items: center;
            gap: 12px;
            z-index: 9999;
            box-shadow: 0 8px 28px rgba(0,0,0,0.18);
            opacity: 0;
            transform: translateY(20px);
            transition: opacity 0.4s ease, transform 0.4s ease;
            pointer-events: none;
            font-family: inherit;
        }
        #badgeToast.show {
            opacity: 1;
            transform: translateY(0);
        }
        .toast-badge-chip {
            flex-shrink: 0;
            width: 46px;
            height: 46px;
            border-radius: 12px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
        }
        .toast-badge-num { font-size: 1rem; font-weight: 900; line-height: 1; }
        .toast-badge-sub { font-size: 0.5rem; font-weight: 700; text-transform: uppercase; opacity: 0.8; margin-top: 1px; }
        .toast-text-wrap { flex: 1; }
        .toast-title { font-size: 0.8rem; font-weight: 700; opacity: 0.85; }
        .toast-msg { font-size: 0.9rem; font-weight: 800; margin-top: 2px; }

        #copyright {
            display: none;
        }

        /* Mobile specific fixes */
        @media (max-width: 450px) {
            .settings-panel { grid-template-columns: 58px 1fr; column-gap: 8px; padding: 10px 12px; }
            .sp-label { font-size: 0.6rem; }
            .seg-group label { padding: 5px 7px; font-size: 0.8rem; }
            .pill-group label { padding: 5px 9px; font-size: 0.78rem; }
            .row { flex-direction: column; width: 100%; }
            .tile { width: 34px !important; height: 40px !important; font-size: 1rem !important; flex-shrink: 0 !important; }
        }

        /* Issue 1 fix: "Length" label wraps at 375px — widen column + shrink font */
        @media (max-width: 375px) {
            .settings-panel {
                grid-template-columns: 52px 1fr !important;
            }
            .sp-label { font-size: 0.55rem !important; }
        }

        /* Difficulty badge in status bar */
        .difficulty-badge {
            font-size: 0.72rem;
            font-weight: 700;
            padding: 2px 8px;
            border-radius: 8px;
            letter-spacing: 0.3px;
        }
        .difficulty-badge.beginner     { background: #e8f5e0; color: #3a7a20; }
        .difficulty-badge.intermediate { background: #fff3e0; color: #b05a00; }
        .difficulty-badge.open         { background: #fdecea; color: #a02020; }

        /* Timer display */
        .timer-display {
            font-size: 0.8rem;
            color: var(--text-muted);
            font-weight: 600;
            text-align: right;
            padding: 4px 8px;
            border-radius: 8px;
            background: #f5f5f5;
            display: inline-block;
            margin-top: 4px;
            letter-spacing: 0.5px;
        }

        /* Stats Page (full page overlay) */
        #statsPage {
            display: none;
            position: fixed;
            top: 0; left: 0;
            width: 100%; height: 100%;
            background: var(--container-bg);
            z-index: 200;
            overflow-y: auto;
            padding: 20px;
            box-sizing: border-box;
        }

        .stats-page-inner {
            max-width: 700px;
            margin: 0 auto;
            padding-bottom: 40px;
        }

        .stats-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 24px;
        }

        .stats-title {
            font-size: 1.6rem;
            font-weight: 700;
            color: #7ab3a2;
            letter-spacing: 2px;
            font-family: 'Playfair Display', Georgia, serif;
        }

        .btn-back {
            background: var(--container-bg);
            border: none;
            border-radius: 12px;
            padding: 10px 16px;
            font-family: inherit;
            font-weight: 700;
            font-size: 0.9rem;
            cursor: pointer;
            color: #666;
            box-shadow: 4px 4px 10px rgba(0,0,0,0.05), -4px -4px 10px #ffffff;
        }
        .btn-back:hover { background: #f5f5f5; }

        .stats-section {
            background: var(--container-bg);
            border-radius: 20px;
            padding: 20px;
            margin-bottom: 16px;
            box-shadow: var(--shadow-outer);
        }

        .stats-section h3 {
            font-size: 0.75rem;
            text-transform: uppercase;
            letter-spacing: 2px;
            color: var(--text-muted);
            margin: 0 0 14px 0;
            font-weight: 700;
        }

        .stat-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 10px;
        }

        .stat-label {
            font-size: 0.9rem;
            color: var(--text-main);
            font-weight: 600;
        }

        .stat-value {
            font-size: 1rem;
            font-weight: 700;
            color: #7ab3a2;
        }

        .progress-bar-wrap {
            margin-bottom: 14px;
        }

        .progress-bar-meta {
            display: flex;
            justify-content: space-between;
            font-size: 0.82rem;
            color: var(--text-muted);
            font-weight: 600;
            margin-bottom: 5px;
        }

        .progress-bar-bg {
            background: #efefef;
            border-radius: 8px;
            height: 12px;
            overflow: hidden;
        }

        .progress-bar-fill {
            height: 100%;
            border-radius: 8px;
            background: linear-gradient(90deg, #7ab3a2, #a8d5c8);
            transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .big-stat-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 12px;
        }

        .big-stat-card {
            background: #f9f9f9;
            border-radius: 14px;
            padding: 14px 8px;
            text-align: center;
            box-shadow: var(--shadow-inner);
        }

        .big-stat-num {
            font-size: 1.6rem;
            font-weight: 700;
            color: #7ab3a2;
            line-height: 1;
        }

        .big-stat-lbl {
            font-size: 0.72rem;
            color: var(--text-muted);
            font-weight: 600;
            margin-top: 4px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .power-pill {
            display: inline-flex;
            align-items: center;
            gap: 5px;
            background: #fff8e1;
            border-radius: 20px;
            padding: 4px 12px;
            font-size: 0.85rem;
            font-weight: 700;
            color: #b8860b;
            margin: 3px;
        }

        /* Mobile responsiveness for settings */
        @media (max-width: 450px) {
            .sp-controls { gap: 5px; }
            .big-stat-grid { grid-template-columns: repeat(2, 1fr); }
        }

        /* ════════════════════════════════════════════════════
           PUZZLE MODE
           ════════════════════════════════════════════════════ */
        #puzzlePage {
            display: none; position: fixed;
            top: 0; left: 0; width: 100%; height: 100%;
            background: var(--page-bg); z-index: 200;
            overflow-y: auto; box-sizing: border-box;
        }
        .puzzle-inner {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 100%;
            padding: var(--sp-xl);
            box-sizing: border-box;
        }
        .puzzle-card {
            text-align: left;
            width: 100%;
            max-width: 640px;
            padding: 24px 24px 20px;
        }
        .puzzle-header {
            display: flex; align-items: center;
            justify-content: space-between; margin-bottom: 10px;
        }
        .puzzle-title { font-size: 1.3rem; font-weight: 700; color: #7ab3a2; letter-spacing: 2px; }
        .puzzle-zone-badge {
            font-size: 0.65rem; font-weight: 800; letter-spacing: 1px;
            text-transform: uppercase; padding: 4px 10px; border-radius: 12px;
            background: var(--accent-blue); color: var(--status-text);
        }
        .puzzle-board-wrap { overflow-x: auto; margin-bottom: 12px; }
        .puzzle-board {
            display: grid;
            grid-template-columns: 16px repeat(8, 1fr);
            grid-template-rows: 16px repeat(8, 1fr);
            gap: 2px;
            background: var(--container-bg);
            padding: 6px; border-radius: 12px;
            box-shadow: var(--shadow-outer);
            width: 100%; box-sizing: border-box;
        }
        .pb-coord {
            display: flex; align-items: center; justify-content: center;
            font-size: 0.5rem; font-weight: 700; color: var(--text-muted); opacity: 0.7;
        }
        .pb-cell {
            aspect-ratio: 1; border-radius: 4px;
            display: flex; align-items: center; justify-content: center;
            font-size: 0.5rem; font-weight: 800; text-transform: uppercase;
            cursor: pointer; position: relative;
            transition: transform 0.1s, box-shadow 0.1s;
            user-select: none; flex-direction: column; gap: 0; min-width: 0;
        }
        .pb-cell:active { transform: scale(0.94); }
        .pb-normal  { background: #f0ede6; color: #aaa; border: 1px solid #ddd8ce; }
        .pb-dl      { background: #A8E6CF; color: #2e7d52; border: 1px solid #7dcca8; }
        .pb-tl      { background: #56C596; color: #fff;    border: 1px solid #3da876; }
        .pb-dw      { background: #A8D8F0; color: #2952a3; border: 1px solid #7cbae6; }
        .pb-tw      { background: #5B9BD5; color: #fff;    border: 1px solid #3a7ab8; }
        .pb-cell.locked {
            background: var(--tile-bg) !important; border: 1.5px solid var(--tile-border) !important;
            color: var(--text-main) !important; cursor: default;
            font-size: 0.95rem; font-weight: 900;
        }
        .pb-cell.locked .tile-val { font-size: 0.38rem; font-weight: 700; opacity: 0.55; line-height: 1; align-self: flex-end; margin-right: 1px; }
        .pb-cell.placed {
            background: #7ab3a2 !important; border: 1.5px solid #5a9e8e !important;
            color: #fff !important; font-size: 0.95rem; font-weight: 900;
            box-shadow: 0 2px 7px rgba(122,179,162,0.5); cursor: pointer;
        }
        .pb-cell.placed .tile-val { font-size: 0.38rem; font-weight: 700; opacity: 0.85; line-height: 1; align-self: flex-end; margin-right: 1px; }
        .pb-cell.valid-target { box-shadow: inset 0 0 0 2px rgba(122,179,162,0.6); }
        .pb-cell.invalid-cross { background: #ffcdd2 !important; border-color: #e57373 !important; }

        .puzzle-rack-wrap {
            background: var(--settings-bg); border-radius: 14px;
            padding: 10px 12px; margin-bottom: 10px; box-shadow: var(--shadow-inner);
        }
        .puzzle-rack-label {
            font-size: 0.6rem; font-weight: 800; text-transform: uppercase;
            letter-spacing: 0.8px; color: var(--text-muted); margin-bottom: 7px;
        }
        .puzzle-rack { display: flex; gap: 6px; flex-wrap: nowrap; justify-content: center; }
        .puzzle-tile {
            width: 42px; height: 48px; background: var(--tile-bg);
            border: 1.5px solid var(--tile-border); border-radius: 10px;
            display: flex; flex-direction: column; align-items: center; justify-content: center;
            font-size: 1.15rem; font-weight: 900; color: var(--text-main);
            cursor: pointer; transition: all 0.1s; user-select: none; position: relative;
            box-shadow: 3px 3px 7px rgba(0,0,0,0.06), -3px -3px 7px rgba(255,255,255,0.7);
        }
        .puzzle-tile .pt-val {
            font-size: 0.45rem; font-weight: 700; color: var(--text-muted);
            position: absolute; bottom: 3px; right: 4px; line-height: 1;
        }
        .puzzle-tile.pt-selected {
            background: #7ab3a2; border-color: #5a9e8e; color: #fff;
            box-shadow: 0 3px 10px rgba(122,179,162,0.5); transform: translateY(-3px);
        }
        .puzzle-tile.pt-selected .pt-val { color: rgba(255,255,255,0.8); }
        .puzzle-tile.pt-used { opacity: 0.22; pointer-events: none; box-shadow: none; }
        .puzzle-tile.pt-dragging { opacity: 0.35; transform: scale(0.95); }
        /* subtle hover glow — pointer devices only */
        .puzzle-tile:hover:not(.pt-used):not(.pt-selected):not(.pt-dragging) {
            transform: translateY(-2px) scale(1.04);
            box-shadow: 0 4px 12px rgba(122,179,162,0.38),
                        3px 3px 7px rgba(0,0,0,0.05),
                        -3px -3px 7px #ffffff;
            border-color: rgba(122,179,162,0.5);
        }
        @media (hover: none) {
            .puzzle-tile:hover:not(.pt-used):not(.pt-selected):not(.pt-dragging) { transform: none; box-shadow: 3px 3px 7px rgba(0,0,0,0.06), -3px -3px 7px rgba(255,255,255,0.7); border-color: var(--tile-border); }
        }
        .pb-cell.drag-over {
            box-shadow: 0 0 0 3px #7ab3a2, 0 0 14px 4px rgba(122,179,162,0.55) !important;
            transform: scale(1.08);
        }
        .puzzle-drag-ghost {
            position: fixed; pointer-events: none; z-index: 9999;
            width: 34px; height: 40px; background: #7ab3a2;
            border: 1.5px solid #5a9e8e; border-radius: 10px;
            display: flex; flex-direction: column; align-items: center; justify-content: center;
            font-size: 1.15rem; font-weight: 900; color: #fff;
            box-shadow: 0 6px 20px rgba(122,179,162,0.55);
            opacity: 0.85; transform: translate(-50%, -50%) scale(1.12);
            transition: none;
        }
        .puzzle-drag-ghost .pt-val {
            font-size: 0.45rem; font-weight: 700; color: rgba(255,255,255,0.8);
            position: absolute; bottom: 3px; right: 4px; line-height: 1;
        }

        .puzzle-score-bar {
            display: flex; align-items: center; justify-content: space-between;
            background: var(--settings-bg); border-radius: 12px;
            padding: 9px 13px; margin-bottom: 9px; box-shadow: var(--shadow-inner);
        }
        .puzzle-live-score { font-size: 1.3rem; font-weight: 900; color: #7ab3a2; font-family: 'Playfair Display', serif; }
        .puzzle-score-label { font-size: 0.65rem; font-weight: 700; color: var(--text-muted); }
        .puzzle-words-formed { font-size: 0.7rem; color: var(--text-muted); font-weight: 600; max-width: 58%; text-align: right; line-height: 1.4; }

        .puzzle-actions { display: flex; gap: 8px; margin-bottom: 10px; }
        .btn-puzzle-confirm {
            flex: 2; padding: 12px; background: linear-gradient(135deg, #7ab3a2, #5a9e8e);
            color: #fff; border: none; border-radius: 13px; font-size: 0.92rem; font-weight: 700;
            cursor: pointer; font-family: inherit; box-shadow: 0 3px 10px rgba(122,179,162,0.4);
            transition: opacity 0.15s;
        }
        .btn-puzzle-confirm:disabled { opacity: 0.38; cursor: default; box-shadow: none; }
        .btn-puzzle-undo {
            flex: 1; padding: 12px; background: var(--accent-pink); color: #a04b4b;
            border: 1.5px solid rgba(160,75,75,0.15); border-radius: 13px;
            font-size: 0.85rem; font-weight: 700; cursor: pointer; font-family: inherit;
        }
        .btn-puzzle-new {
            flex: 1; padding: 12px; background: transparent; color: var(--text-muted);
            border: 1.5px solid var(--tile-border); border-radius: 13px;
            font-size: 0.85rem; font-weight: 700; cursor: pointer; font-family: inherit;
        }
        .btn-puzzle-new:hover { border-color: #7ab3a2; color: var(--text-main); }

        .puzzle-result-overlay {
            display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0,0,0,0.4); backdrop-filter: blur(5px); z-index: 300;
            pointer-events: none; /* header/hamburger must always be tappable above this */
        }

        /* ── Result page — desktop: centered modal floating over board ── */
        #puzzleResultPage {
            display: none;
            position: fixed; top: 50%; left: 50%;
            transform: translate(-50%, -50%);
            background: var(--container-bg);
            border-radius: 26px;
            z-index: 301;
            width: 92%; max-width: 400px;
            max-height: 90vh; overflow-y: auto;
            box-shadow: 0 20px 50px rgba(0,0,0,0.15);
        }

        /* Desktop header: title only */
        .prp-header {
            display: flex;
            align-items: center;
            padding: 20px 24px 0 24px;
        }
        .prp-title {
            margin: 0;
            color: #7ab3a2;
            font-size: 1.1rem;
        }
        .prp-body {
            padding: 12px 24px 24px 24px;
        }
        .pr-score-banner {
            background: linear-gradient(135deg, #7ab3a2 0%, #5a9e8e 100%);
            border-radius: 13px; padding: 15px; margin: 10px 0; color: #fff;
        }
        .pr-score-big { font-size: 2.4rem; font-weight: 900; line-height: 1; font-family: 'Playfair Display', serif; }
        .pr-score-sub { font-size: 0.7rem; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; opacity: 0.85; margin-top: 3px; }
        .pr-vs-bar { margin: 10px 0; }
        .pr-vs-label { display: flex; justify-content: space-between; font-size: 0.7rem; font-weight: 700; color: var(--text-muted); margin-bottom: 4px; }
        .pr-vs-track { height: 9px; background: var(--tile-border); border-radius: 5px; overflow: hidden; }
        .pr-vs-fill { height: 100%; border-radius: 5px; background: linear-gradient(90deg, #7ab3a2, #a8d5c8); transition: width 0.8s cubic-bezier(0.4,0,0.2,1); width: 0%; }
        /* ── Score Breakdown — receipt/ticket card ──────────────────────── */
        .pr-breakdown {
            text-align: left;
            font-size: 0.82rem;
            margin: 10px 0;
            border: 1.5px dashed #b8d8cf;
            border-radius: 13px;
            overflow: hidden;
            background: var(--settings-bg);
        }
        .pr-breakdown-title { display: none; } /* replaced by section headers */

        /* Section header bands */
        .pr-section-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 5px 13px;
            font-size: 0.58rem;
            font-weight: 900;
            text-transform: uppercase;
            letter-spacing: 0.9px;
        }
        .pr-section-header--words {
            background: rgba(122, 179, 162, 0.13);
            color: #4a8e7e;
            border-bottom: 1px solid rgba(122,179,162,0.25);
        }
        .pr-section-header--bonuses {
            background: rgba(200, 169, 110, 0.12);
            color: #a07828;
            border-top: 1.5px dashed #b8d8cf;
            border-bottom: 1px solid rgba(200,169,110,0.22);
        }

        /* Data rows */
        .pr-word-row {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            padding: 6px 13px;
            border-bottom: 1px solid var(--tile-border);
        }
        .pr-word-row:last-child { border-bottom: none; }
        .pr-word-left { flex: 1; }
        .pr-word-name  { color: var(--text-main); font-weight: 800; font-size: 0.86rem; }
        .pr-word-detail { color: var(--text-muted); font-size: 0.67rem; margin-top: 2px; line-height: 1.4; }
        .pr-word-pts {
            color: #4a8e7e;
            font-weight: 900;
            font-size: 0.93rem;
            flex-shrink: 0;
            margin-left: 8px;
            font-family: 'Courier New', Courier, monospace;
            letter-spacing: -0.5px;
        }

        /* Alternating stripe */
        .pr-row-stripe { background: rgba(122, 179, 162, 0.07); }

        /* Dim rows */
        .pr-word-row--dim .pr-word-name,
        .pr-word-row--dim .pr-word-detail { color: var(--text-muted, #aaa); }
        .pr-word-row--dim .pr-word-pts    { color: #ccc; font-weight: 700; }

        /* Total footer band */
        .pr-total-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 8px 13px;
            background: rgba(122, 179, 162, 0.15);
            border-top: 1.5px solid #7ab3a2;
        }
        .pr-total-label-text {
            font-size: 0.68rem;
            font-weight: 900;
            text-transform: uppercase;
            letter-spacing: 0.7px;
            color: #4a8e7e;
        }
        .pr-total-pts {
            color: #2e7a68;
            font-weight: 900;
            font-size: 1.1rem;
            font-family: 'Courier New', Courier, monospace;
            letter-spacing: -0.5px;
        }
        .pr-bingo-banner {
            background: linear-gradient(135deg, #ffd700, #ffb300); border-radius: 11px;
            padding: 9px 13px; margin: 8px 0; font-weight: 800; font-size: 0.88rem; color: #7a5800;
        }
        .pr-expert-section { margin: 10px 0; text-align: left; }
        .pr-expert-label { font-size: 0.6rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); margin-bottom: 5px; }
        .pr-expert-move { background: var(--settings-bg); border-radius: 11px; padding: 9px 13px; font-size: 0.82rem; font-weight: 700; color: var(--text-main); border-left: 3px solid #ffd700; border-right: 3px solid #ffd700; text-align: center; }

        .puzzle-legend { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; justify-content: center; }
        .pl-item { display: flex; align-items: center; gap: 3px; font-size: 0.58rem; font-weight: 700; color: var(--text-muted); }
        .pl-swatch { width: 12px; height: 12px; border-radius: 2px; }
        .puzzle-feedback { min-height: 20px; font-size: 0.8rem; font-weight: 700; text-align: center; margin-bottom: 6px; transition: opacity 0.3s; }

        /* ── Training Filter ─────────────────────────────────────────────── */
        .pf-wrap { margin-bottom: 10px; border-radius: 12px; border: 1.5px solid var(--tile-border); background: var(--card-bg, #fff); overflow: hidden; }
        .pf-toggle { width: 100%; display: flex; align-items: center; justify-content: space-between; padding: 9px 13px; background: none; border: none; cursor: pointer; font-size: 0.78rem; font-weight: 800; color: var(--text-main); letter-spacing: 0.4px; }
        .pf-toggle:hover { background: rgba(122,179,162,0.08); }
        .pf-toggle-label { display: flex; align-items: center; gap: 6px; }
        .pf-toggle-caret { font-size: 0.9rem; color: var(--text-muted); transition: transform 0.25s; }
        .pf-wrap.pf-open .pf-toggle-caret { transform: rotate(180deg); }
        .pf-body { display: none; padding: 0 12px 12px; }
        .pf-wrap.pf-open .pf-body { display: block; }
        .pf-desc { font-size: 0.68rem; color: var(--text-muted); margin-bottom: 9px; line-height: 1.5; }
        .pf-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
        .pf-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 8px 10px; border-radius: 9px; border: 1.5px solid var(--tile-border); background: var(--tile-bg, #f9f9f7); cursor: pointer; text-align: left; transition: border-color 0.15s, background 0.15s; }
        .pf-btn:hover { border-color: #7ab3a2; background: rgba(122,179,162,0.07); }
        .pf-btn.pf-active { border-color: #7ab3a2; background: rgba(122,179,162,0.13); box-shadow: 0 0 0 2px rgba(122,179,162,0.25); }
        .pf-icon { font-size: 1.1rem; line-height: 1; margin-bottom: 2px; }
        .pf-name { font-size: 0.72rem; font-weight: 800; color: var(--text-main); }
        .pf-hint { font-size: 0.58rem; color: var(--text-muted); font-weight: 600; }


        /* ── The Last Vort Logo ── */
        .tlv-logo-wrap {
            text-align: center; margin-bottom: 14px; padding: 14px 0 10px 0;
            border-bottom: 1px solid var(--tile-border);
        }
        .tlv-rule-row {
            display: flex; align-items: center; gap: 8px;
            margin-bottom: 2px;
        }
        .tlv-rule-line {
            flex: 1; height: 1px;
            background: linear-gradient(90deg, transparent, #c8a96e, transparent);
            opacity: 0.6;
        }
        .tlv-diamond {
            font-size: 0.6rem; color: #c8a96e; opacity: 0.8;
        }
        .tlv-subtitle-top {
            font-family: 'Quicksand', sans-serif;
            font-size: 0.65rem; font-weight: 700;
            letter-spacing: 6px; text-transform: uppercase;
            color: #b8956a; opacity: 0.85; margin-bottom: 0px;
        }
        .tlv-title {
            font-family: 'Playfair Display', Georgia, serif;
            font-size: 2rem; font-weight: 900;
            letter-spacing: 4px; line-height: 1.05;
            background: linear-gradient(135deg, #8B6914 0%, #c8a96e 35%, #e8cc8e 60%, #c8a96e 80%, #8B6914 100%);
            -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
            display: inline-block;
        }
        .tlv-subtitle-bot {
            font-family: 'Quicksand', sans-serif;
            font-size: 0.55rem; font-weight: 700;
            letter-spacing: 3px; text-transform: uppercase;
            color: var(--text-muted); opacity: 0.65; margin-top: 2px;
        }
        [data-theme="dark"] .tlv-title {
            background: linear-gradient(135deg, #c8a96e 0%, #f0d090 40%, #ffeaa0 65%, #f0d090 85%, #c8a96e 100%);
            -webkit-background-clip: text; background-clip: text;
        }

/* ── Quiz Mode Picker cards (level 1 of two-level quiz selection) ── */
.quiz-mode-card {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 14px 16px;
    background: var(--tile-bg); border: 1.5px solid var(--tile-border);
    border-radius: 14px; cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.quiz-mode-card:hover { border-color: #7ab3a2; box-shadow: 0 4px 12px rgba(122,179,162,0.18); }
.qmc-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.qmc-icon { font-size: 1.8rem; flex-shrink: 0; line-height: 1; }
.qmc-name { font-size: var(--fs-base); font-weight: 800; color: var(--text-main); margin-bottom: 2px; }
.qmc-desc { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 600; line-height: 1.4; }
.qmc-right { flex-shrink: 0; text-align: right; }
.qmc-cta { font-size: var(--fs-lg); font-weight: 800; color: #7ab3a2; }
.qmc-progress { font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted); margin-bottom: 4px; }
.qmc-bar { width: 60px; height: 5px; background: var(--tile-border); border-radius: 3px; overflow: hidden; }
.qmc-bar-fill { height: 100%; background: #7ab3a2; border-radius: 3px; transition: width 0.3s; }

/* ── Quiz Selection Page — outer wrapper + white card ── */
.qsp-outer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: var(--sp-xl);
    box-sizing: border-box;
}
.qsp-card {
    text-align: left;
    padding: 24px 24px 20px;
}
.qsp-logo {
    margin-bottom: 12px;
}
.qsp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.qsp-title {
    font-size: var(--fs-lg);
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: 0.3px;
}
.qsp-encouragement {
    text-align: center;
    font-size: 0.88rem;
    font-weight: 700;
    color: #7ab3a2;
    font-style: italic;
    margin: 4px 0 6px;
    line-height: 1.4;
}

/* ── Mode page headers — Training & Scenarios (mirrors .qsp-header/.qsp-title) ── */
.vm-mode-header {
    margin-bottom: 10px;
    margin-top: 2px;
    text-align: left;
}
.vm-mode-header .qsp-title {
    text-align: left;
}
/* Inside settings-panel grid — must span both label + control columns */
.settings-panel .vm-mode-header {
    grid-column: 1 / -1;
}
.qsp-mode-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
}
.qsp-footer {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--tile-border);
}

/* ── Help modal tabs (all screen sizes) ── */
.help-tab-bar {
    display: flex; gap: 6px; margin-bottom: 14px;
}
.help-tab-btn {
    flex: 1; padding: 8px 4px;
    font-size: var(--fs-xs); font-weight: 800;
    border: 1.5px solid var(--tile-border); border-radius: 8px;
    background: var(--tile-bg); color: var(--text-muted);
    cursor: pointer; text-align: center; min-height: 44px;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.help-tab-btn.active {
    background: #7ab3a2; border-color: #5a9e8e; color: #fff;
}
.help-tab-panel { display: none; }
.help-tab-panel.active { display: block; }


/* ════════════════════════════════════════════════════
   STEP 6: COHESIVE DESIGN — spacing, legend, card polish
   ════════════════════════════════════════════════════ */

/* Board legend — integrated card instead of tacked-on row */
.puzzle-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-sm) var(--sp-lg);
    justify-content: center;
    background: var(--settings-bg);
    border: 1px solid var(--tile-border);
    border-radius: var(--radius-md);
    padding: var(--sp-sm) var(--sp-md);
    margin-bottom: var(--sp-md);
}
.pl-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: var(--fs-xs);
    font-weight: 700;
    color: var(--text-muted);
    white-space: nowrap;
}
.pl-swatch {
    width: 18px; height: 18px;
    border-radius: 4px;
    flex-shrink: 0;
}

/* game-card — consistent padding using spacing scale */
.game-card {
    padding: var(--sp-2xl);
}

/* header-container — consistent bottom margin */
.header-container {
    margin-bottom: var(--sp-lg);
}

/* button-group — consistent spacing */
.button-group {
    display: flex;
    flex-direction: column;
    gap: var(--sp-sm);
    margin-top: var(--sp-sm);
}

/* .row — consistent gap */
.row {
    display: flex;
    gap: var(--sp-sm);
    justify-content: center;
}

/* found-container — consistent top spacing */
.found-container {
    margin-top: var(--sp-lg);
}

/* ════════════════════════════════════════════════════
   MOBILE-FIRST RESPONSIVE — max-width: 600px
   ════════════════════════════════════════════════════ */

@media (max-width: 600px) {

    /* ── Global button touch targets ── */
    button, .btn-submit, .btn-back, .btn-action, .btn-destructive,
    .btn-puzzle-confirm, .btn-puzzle-undo, .btn-puzzle-new,
    .pf-toggle, .hub-tab, .lb-type-btn {
        min-height: 44px;
    }

    /* ── Modals: centered, full-width, properly anchored on mobile ── */
    .modal {
        width: 94%;
        max-width: 94%;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        max-height: 88vh;
        overflow-y: auto;
        border-radius: 20px;
        padding: 20px 16px;
        box-sizing: border-box;
    }
    /* Ensure all buttons inside modals are tappable */
    .modal button {
        min-height: 44px;
    }

    /* ── Board cells: slightly smaller on narrow screens ── */
    .puzzle-board {
        gap: 1px;
        padding: 4px;
    }
    .pb-cell.locked,
    .pb-cell.placed {
        font-size: 0.78rem;
    }

    /* ── Legend: 2×2 grid on mobile instead of single row ── */
    .puzzle-legend {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 4px 8px;
        justify-items: start;
    }
    .pl-item {
        font-size: var(--fs-xs);
    }

    /* ── Rack: shuffle button moves above rack, full-width row of tiles ── */
    .puzzle-rack-wrap .rack-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 7px;
    }
    .puzzle-rack-row {
        justify-content: center;
    }
    .puzzle-tile {
        width: 34px !important;
        height: 40px !important;
        font-size: 0.95rem;
        border-radius: 7px;
        flex-shrink: 0;
    }
    .puzzle-tile .pt-val {
        font-size: 0.38rem;
    }

    /* ── Action buttons: stack on very small screens ── */
    .puzzle-actions {
        gap: 6px;
    }
    .btn-puzzle-confirm,
    .btn-puzzle-undo,
    .btn-puzzle-new {
        font-size: var(--fs-sm);
        padding: 10px 8px;
    }

    /* ── Training filter grid: single column on mobile ── */
    .pf-grid {
        grid-template-columns: 1fr;
    }

    /* ── Quiz selection cards: larger tap targets ── */
    .quiz-card {
        padding: 12px 10px;
        min-height: 60px;
    }
    .quiz-diff-columns {
        gap: 6px;
    }

    /* ── Stats / result modals ── */
    .pr-expert-move {
        font-size: var(--fs-sm);
    }

    /* ── Main Menu: spacing fixes for mobile ── */
    .mm-section {
        gap: 14px;         /* more breathing room between banner cards */
    }
}

/* ════════════════════════════════════════════════════
   MAIN MENU — "NEW HERE?" BADGE on Help card title
   ════════════════════════════════════════════════════ */

.mm-new-badge {
    display: none;              /* hidden by default; JS shows for new visitors */
    font-size: 0.56rem;
    font-weight: 800;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    background: var(--btn-primary-bg);
    color: #fff;
    border-radius: 6px;
    padding: 2px 6px;
    margin-left: 7px;
    vertical-align: middle;
    line-height: 1.4;
    animation: mmBadgePulse 2.4s ease-in-out infinite;
}

@keyframes mmBadgePulse {
    0%, 100% { opacity: 1;    transform: scale(1); }
    50%       { opacity: 0.72; transform: scale(0.95); }
}

[data-theme="dark"] .mm-new-badge {
    background: var(--header-color);
    color: #121318;
}

/* ════════════════════════════════════════════════════
   MAIN MENU — #mainMenu
   ════════════════════════════════════════════════════ */

#mainMenu {
    width: 100%;
    margin-bottom: 4px;
}

.mm-menu {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    margin-bottom: 20px;
}

/* ── Each mode card ──
   Uses a div wrapper inside the button to escape text-align:center
   inherited from .game-card, which breaks flex in some browsers.      */
.mm-btn {
    display: flex;           /* flex: accent bar + mm-inner side by side */
    align-items: stretch;
    width: 100%;
    padding: 0;
    border-radius: 18px;
    border: 1.5px solid var(--tile-border);
    background: var(--settings-bg);
    color: var(--text-main);
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.18s, box-shadow 0.18s, transform 0.18s;
    box-shadow: var(--shadow-inner);
    overflow: hidden;
}

.mm-btn:hover {
    border-color: var(--brand-primary);
    box-shadow: 0 6px 20px rgba(122,179,162,0.22);
    transform: translateY(-2px);
}

.mm-btn:active {
    transform: scale(0.985);
    box-shadow: var(--shadow-inner);
    transition-duration: 0.06s;
}

/* Inner flex row — this is what actually lays out icon + text + arrow */
.mm-inner {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px 18px 18px 16px;
    text-align: left;
    flex: 1;        /* fill width after accent bar */
    min-width: 0;
}

/* Coloured left accent bar */
.mm-accent {
    width: 5px;
    align-self: stretch;
    border-radius: 0;
    flex-shrink: 0;
}
.mm-training .mm-accent { background: #7ab3a2; }
.mm-puzzles  .mm-accent { background: #c8a96e; }
.mm-quizzes  .mm-accent { background: #7a9eb3; }

/* Emoji icon */
.mm-icon {
    font-size: 2.2rem;
    flex-shrink: 0;
    line-height: 1;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.12));
}

/* Title + description column */
.mm-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.mm-title {
    display: block;
    font-size: 1.08rem;
    font-weight: 800;
    letter-spacing: 0.2px;
    font-family: 'Quicksand', sans-serif;
    line-height: 1.2;
}
.mm-training .mm-title { color: #5a9e8e; }
.mm-puzzles  .mm-title { color: #a07828; }
.mm-quizzes  .mm-title { color: #4a7e9e; }

.mm-desc {
    display: block;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Right chevron */
.mm-arrow {
    font-size: 1.5rem;
    font-weight: 300;
    color: var(--tile-border);
    flex-shrink: 0;
    transition: color 0.15s, transform 0.18s;
    line-height: 1;
    padding-right: 2px;
}

.mm-btn:hover .mm-arrow {
    transform: translateX(4px);
}
.mm-training:hover .mm-arrow { color: #7ab3a2; }
.mm-puzzles:hover  .mm-arrow { color: #c8a96e; }
.mm-quizzes:hover  .mm-arrow { color: #7a9eb3; }

/* Hover tint per card */
.mm-training:hover { border-color: #7ab3a2; background: #f0faf7; }
.mm-puzzles:hover  { border-color: #c8a96e; background: #fdf8ee; }
.mm-quizzes:hover  { border-color: #7a9eb3; background: #eef4f9; }

/* Dark theme */
[data-theme="dark"] .mm-training .mm-title { color: #4ecfbb; }
[data-theme="dark"] .mm-puzzles  .mm-title { color: #e8c878; }
[data-theme="dark"] .mm-quizzes  .mm-title { color: #78b0d0; }
[data-theme="dark"] .mm-training .mm-accent { background: #4ecfbb; }
[data-theme="dark"] .mm-puzzles  .mm-accent { background: #e8c878; }
[data-theme="dark"] .mm-quizzes  .mm-accent { background: #78b0d0; }
[data-theme="dark"] .mm-training:hover { background: #1a2e2a; border-color: #4ecfbb; }
[data-theme="dark"] .mm-puzzles:hover  { background: #2a2518; border-color: #e8c878; }
[data-theme="dark"] .mm-quizzes:hover  { background: #182028; border-color: #78b0d0; }

/* Nightlight theme */
[data-theme="nightlight"] .mm-training:hover { background: #f8f4ee; }
[data-theme="nightlight"] .mm-puzzles:hover  { background: #fdf6e8; }
[data-theme="nightlight"] .mm-quizzes:hover  { background: #eef4f8; }

/* ════════════════════════════════════════════════════
   MAIN MENU — Stats / Settings section + Help footer
   ════════════════════════════════════════════════════ */

/* Section wrapper: same width/gap as .mm-menu, separated by extra top margin */
.mm-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    margin-top: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--tile-border);
}

/* Accent colours for Stats and Settings cards */
.mm-stats    .mm-accent { background: #7ab3a2; }
.mm-settings .mm-accent { background: #9b8ec4; }

/* Title colours */
.mm-stats    .mm-title { color: #5a9e8e; }
.mm-settings .mm-title { color: #6d5fa8; }

/* Hover tints */
.mm-stats:hover    { border-color: #7ab3a2; background: #f0faf7; }
.mm-settings:hover { border-color: #9b8ec4; background: #f4f1fb; }

.mm-stats:hover    .mm-arrow { color: #7ab3a2; }
.mm-settings:hover .mm-arrow { color: #9b8ec4; }

/* Dark theme */
[data-theme="dark"] .mm-stats    .mm-title  { color: #4ecfbb; }
[data-theme="dark"] .mm-settings .mm-title  { color: #b8a8e8; }
[data-theme="dark"] .mm-stats    .mm-accent { background: #4ecfbb; }
[data-theme="dark"] .mm-settings .mm-accent { background: #b8a8e8; }
[data-theme="dark"] .mm-stats:hover    { background: #1a2e2a; border-color: #4ecfbb; }
[data-theme="dark"] .mm-settings:hover { background: #1e1a2e; border-color: #b8a8e8; }

/* Nightlight theme */
[data-theme="nightlight"] .mm-stats:hover    { background: #f8f4ee; }
[data-theme="nightlight"] .mm-settings:hover { background: #f4f0f8; }

/* Help card — accent, title and hover colours matching the banner pattern */
.mm-help-card .mm-accent { background: #e8a050; }
.mm-help-card .mm-title  { color: #b87030; }
.mm-help-card:hover { border-color: #e8a050; background: #fdf6ed; }
.mm-help-card:hover .mm-arrow { color: #e8a050; }

/* Dark theme */
[data-theme="dark"] .mm-help-card .mm-title  { color: #f0c080; }
[data-theme="dark"] .mm-help-card .mm-accent { background: #f0c080; }
[data-theme="dark"] .mm-help-card:hover { background: #2a2010; border-color: #f0c080; }

/* Nightlight theme */
[data-theme="nightlight"] .mm-help-card:hover { background: #fdf0e0; }

/* ════════════════════════════════════════════════════
   SETTINGS PANEL FIXES — responsive label column
   ════════════════════════════════════════════════════ */

.settings-panel {
    grid-template-columns: 52px 1fr;
    column-gap: 8px;
    padding: 12px 12px;
}

/* seg-group fills full width — labels share space equally */
.seg-group {
    display: flex;
    width: 100%;
}

.seg-group label {
    flex: 1;
    text-align: center;
    padding: 6px 4px;
}

/* pill-group: no wrapping, pills share space equally */
.pill-group {
    flex-wrap: nowrap;
}

.pill-group label {
    flex: 1;
    justify-content: center;
    padding: 6px 8px;
    font-size: 0.80rem;
}

/* ── Mobile — beats existing @media (max-width: 450px) in style.css ── */
@media (max-width: 450px) {
    .settings-panel {
        grid-template-columns: 44px 1fr !important;
        column-gap: 6px !important;
        padding: 10px 8px !important;
    }
    .seg-group label {
        padding: 6px 2px !important;
        font-size: 0.78rem !important;
    }
    .pill-group label {
        padding: 6px 5px !important;
        font-size: 0.75rem !important;
    }
    .mm-inner {
        padding: 14px 14px 14px 12px;
        gap: 12px;
    }
    .mm-icon {
        font-size: 1.8rem;
    }
    .mm-title {
        font-size: 0.95rem;
    }
    .mm-desc {
        font-size: 0.72rem;
    }
}

/* ════════════════════════════════════════════════════
   PUZZLE ONBOARDING TUTORIAL
   z-index 250 — sits above puzzle page (200),
   below the result modal (300)
   ════════════════════════════════════════════════════ */

#puzzleTutorial {
    position: fixed;
    inset: 0;
    z-index: 250;
    pointer-events: none; /* callout and backdrop re-enable their own */
}

/* ── Backdrop — semi-dark with a spotlight cutout ── */
.pt-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.52);
    pointer-events: auto;
    opacity: 0;
    transition: opacity 0.25s;
    /* Spotlight: an ellipse of transparency centred on the target element.
       Uses CSS custom properties set by puzzleTutorialSpotlight(). */
    -webkit-mask-image: radial-gradient(
        ellipse var(--pt-rw, 60px) var(--pt-rh, 40px)
        at var(--pt-cx, 50%) var(--pt-cy, 50%),
        transparent 85%,
        black 120%
    );
    mask-image: radial-gradient(
        ellipse var(--pt-rw, 60px) var(--pt-rh, 40px)
        at var(--pt-cx, 50%) var(--pt-cy, 50%),
        transparent 85%,
        black 120%
    );
}

.pt-backdrop.pt-active {
    opacity: 1;
}

/* ── Floating callout card ── */
.pt-callout {
    position: fixed;
    width: 290px;
    background: var(--container-bg);
    border-radius: 18px;
    padding: 18px 18px 14px 18px;
    box-shadow:
        0 8px 32px rgba(0,0,0,0.22),
        0 2px 8px rgba(0,0,0,0.12),
        0 0 0 1.5px rgba(122,179,162,0.30);
    pointer-events: auto;
    z-index: 251;
    box-sizing: border-box;
    animation: pt-callout-in 0.22s cubic-bezier(0.34,1.56,0.64,1) both;
}

@keyframes pt-callout-in {
    from { opacity: 0; transform: scale(0.92) translateY(6px); }
    to   { opacity: 1; transform: scale(1)    translateY(0);   }
}

/* Step progress dots */
.pt-dots {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-bottom: 12px;
}

.pt-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--tile-border);
    transition: background 0.2s, transform 0.2s;
}

.pt-dot.pt-dot-active {
    background: #7ab3a2;
    transform: scale(1.35);
}

/* Step icon */
.pt-step-icon {
    font-size: 1.8rem;
    text-align: center;
    margin-bottom: 6px;
    line-height: 1;
}

/* Step title */
.pt-step-title {
    font-family: 'Quicksand', sans-serif;
    font-size: 1.0rem;
    font-weight: 800;
    color: #7ab3a2;
    text-align: center;
    margin-bottom: 8px;
    letter-spacing: 0.2px;
}

/* Step body */
.pt-step-body {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.5;
    text-align: center;
    margin-bottom: 14px;
}

/* Directional arrow — triangle pointing toward the highlighted element */
.pt-arrow {
    position: absolute;
    left: 50%;
    width: 0;
    height: 0;
    transform: translateX(-50%);
    pointer-events: none;
}

.pt-arrow-up {
    /* Points up — callout is below the target */
    top: -10px;
    border-left:  10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 10px solid var(--container-bg);
    filter: drop-shadow(0 -2px 2px rgba(0,0,0,0.08));
}

.pt-arrow-down {
    /* Points down — callout is above the target */
    bottom: -10px;
    border-left:  10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid var(--container-bg);
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.08));
}

/* Button row */
.pt-btn-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.pt-btn-skip {
    background: none;
    border: none;
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 0;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.pt-btn-skip:hover { color: var(--text-main); }

.pt-btn-next {
    background: linear-gradient(135deg, #7ab3a2, #5a9e8e);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 9px 20px;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(122,179,162,0.4);
    transition: opacity 0.15s, transform 0.1s;
    letter-spacing: 0.2px;
}

.pt-btn-next:hover  { opacity: 0.9; transform: translateY(-1px); }
.pt-btn-next:active { transform: scale(0.96); opacity: 1; }

/* Spotlight ring — glowing border around the highlighted element */
/* Achieved by a pseudo-element on the backdrop positioned over the target */
.pt-backdrop.pt-active::after {
    content: '';
    position: fixed;
    left:   calc(var(--pt-cx, 50%) - var(--pt-rw, 60px));
    top:    calc(var(--pt-cy, 50%) - var(--pt-rh, 40px));
    width:  calc(var(--pt-rw, 60px) * 2);
    height: calc(var(--pt-rh, 40px) * 2);
    border-radius: 14px;
    border: 2.5px solid rgba(122,179,162,0.75);
    box-shadow:
        0 0 0 4px rgba(122,179,162,0.15),
        0 0 18px 4px rgba(122,179,162,0.25);
    pointer-events: none;
    animation: pt-ring-pulse 2s ease-in-out infinite;
}

@keyframes pt-ring-pulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(122,179,162,0.15), 0 0 18px 4px rgba(122,179,162,0.25); }
    50%       { box-shadow: 0 0 0 6px rgba(122,179,162,0.20), 0 0 26px 6px rgba(122,179,162,0.35); }
}

/* Dark theme adjustments */
[data-theme="dark"] .pt-callout {
    box-shadow:
        0 8px 32px rgba(0,0,0,0.55),
        0 2px 8px rgba(0,0,0,0.30),
        0 0 0 1.5px rgba(78,207,187,0.25);
}
[data-theme="dark"] .pt-backdrop.pt-active::after {
    border-color: rgba(78,207,187,0.65);
}

/* ════════════════════════════════════════════════════
   STATS DASHBOARD V2 — REDESIGNED
   ════════════════════════════════════════════════════ */

/* ── Collapsible sections (top-level) ── */
.sd-details {
    cursor: pointer;
}
.sd-details-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    list-style: none;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
    padding: 2px 0;
}
.sd-details-summary::-webkit-details-marker { display: none; }
.sd-details-caret { font-size: 0.9rem; transition: transform 0.2s; }
.sd-details[open] .sd-details-caret { transform: rotate(180deg); }

/* ── Sub-collapsible (inside sections, e.g. Recent Scenarios) ── */
.sd-sub-details { margin-top: 4px; }
.sd-sub-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    list-style: none;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
    padding: 8px 0 4px 0;
    border-top: 1px solid var(--tile-border);
}
.sd-sub-summary::-webkit-details-marker { display: none; }
.sd-sub-caret { font-size: 0.75rem; transition: transform 0.2s; }
.sd-sub-details[open] .sd-sub-caret { transform: rotate(180deg); }
.sd-sub-content { padding-top: 8px; }

/* ── Section divider inside collapsibles ── */
.sd-section-divider {
    height: 1px;
    background: var(--tile-border);
    margin: 16px 0;
    opacity: 0.6;
}

/* ════════════════════════════════════
   GLOBAL STATS CARDS (3 stacked)
   ════════════════════════════════════ */

.sd-gs-card {
    border-radius: 18px;
    padding: 16px 18px;
    margin-bottom: 10px;
    position: relative;
    overflow: hidden;
}
.sd-gs-card:last-child { margin-bottom: 0; }

/* Color tints */
.sd-gs-card--scenarios {
    background: linear-gradient(135deg, rgba(200,169,110,0.15) 0%, rgba(200,169,110,0.05) 100%);
    border: 1.5px solid rgba(200,169,110,0.25);
}
.sd-gs-card--training {
    background: linear-gradient(135deg, rgba(122,179,162,0.15) 0%, rgba(122,179,162,0.05) 100%);
    border: 1.5px solid rgba(122,179,162,0.25);
}
.sd-gs-card--streak {
    background: linear-gradient(135deg, rgba(232,115,74,0.15) 0%, rgba(232,115,74,0.05) 100%);
    border: 1.5px solid rgba(232,115,74,0.25);
}

/* Card header: large icon + title */
.sd-gs-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}
.sd-gs-card-icon {
    font-size: 2rem;
    line-height: 1;
    flex-shrink: 0;
}
.sd-gs-card-title {
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-family: 'Playfair Display', serif;
}
.sd-gs-card--scenarios .sd-gs-card-title { color: #b8901e; }
.sd-gs-card--training  .sd-gs-card-title { color: #4a8e7e; }
.sd-gs-card--streak    .sd-gs-card-title { color: #c85020; }

/* Stats grid inside each card */
.sd-gs-card-grid {
    display: flex;
    align-items: center;
    gap: 0;
}
.sd-gs-card-stat {
    flex: 1;
    text-align: center;
}
.sd-gs-card-divider {
    width: 1px;
    height: 44px;
    background: currentColor;
    opacity: 0.12;
    flex-shrink: 0;
    margin: 0 6px;
}
.sd-gs-card-num {
    font-size: 2rem;
    font-weight: 900;
    line-height: 1;
    font-family: 'Playfair Display', serif;
}
.sd-gs-card-num--gold   { color: #c8a96e; }
.sd-gs-card-num--teal   { color: #7ab3a2; }
.sd-gs-card-num--purple { color: #9b7abf; }
.sd-gs-card-lbl {
    font-size: 0.63rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Streak card content */
.sd-gs-streak-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.sd-gs-cal {
    display: flex;
    gap: 5px;
}
.sd-gs-dot {
    flex: 1;
    height: 32px;
    border-radius: 8px;
    background: rgba(232,115,74,0.10);
    border: 1.5px solid rgba(232,115,74,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.64rem;
    font-weight: 800;
    color: rgba(200,80,32,0.5);
    transition: background 0.2s;
}
.sd-gs-dot--played {
    background: #e8734a;
    border-color: #e8734a;
    color: #fff;
}
.sd-gs-dot--today {
    outline: 2px solid rgba(232,115,74,0.7);
    outline-offset: 2px;
    font-weight: 900;
    color: #c85020;
}
.sd-gs-dot--played.sd-gs-dot--today {
    background: #c85020;
    border-color: #c85020;
    color: #fff;
    outline-color: #c85020;
}
.sd-gs-streak-lbl {
    font-size: 0.82rem;
    font-weight: 700;
    color: #c85020;
}
.sd-gs-streak-lbl--muted { color: var(--text-muted); font-style: italic; }

/* Dark mode cards */
[data-theme="dark"] .sd-gs-card--scenarios {
    background: linear-gradient(135deg, rgba(200,169,110,0.12) 0%, rgba(200,169,110,0.04) 100%);
    border-color: rgba(200,169,110,0.20);
}
[data-theme="dark"] .sd-gs-card--training {
    background: linear-gradient(135deg, rgba(122,179,162,0.12) 0%, rgba(122,179,162,0.04) 100%);
    border-color: rgba(122,179,162,0.20);
}
[data-theme="dark"] .sd-gs-card--streak {
    background: linear-gradient(135deg, rgba(232,115,74,0.12) 0%, rgba(232,115,74,0.04) 100%);
    border-color: rgba(232,115,74,0.20);
}
[data-theme="dark"] .sd-gs-dot {
    background: rgba(232,115,74,0.08);
    border-color: rgba(232,115,74,0.15);
}

/* ════════════════════════════════════
   MILESTONE RING
   ════════════════════════════════════ */
.sd-ms-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.sd-ms-svg { width: 90px; height: 90px; }
.sd-ms-center {
    position: absolute;
    top: 0; left: 50%;
    transform: translateX(-50%);
    width: 90px; height: 90px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.sd-ms-num {
    font-size: 1.4rem;
    font-weight: 900;
    color: #c8a96e;
    line-height: 1;
    font-family: 'Playfair Display', serif;
}
.sd-ms-denom { font-size: 0.65rem; font-weight: 700; color: var(--text-muted); }
.sd-ms-label { font-size: 0.78rem; font-weight: 700; color: var(--text-muted); text-align: center; margin-top: 4px; }

/* ════════════════════════════════════
   SCORE TREND CHART
   ════════════════════════════════════ */
.sd-trend-wrap { display: flex; flex-direction: column; gap: 6px; }
.sd-trend-svg {
    width: 100%; height: auto;
    display: block;
    color: var(--text-muted);
    overflow: visible;
}
.sd-trend-legend {
    display: flex;
    gap: 14px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 2px;
}
.sd-trend-leg-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
}
.sd-trend-swatch {
    width: 10px; height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}
.sd-swatch--teal   { background: #7ab3a2; }
.sd-swatch--gold   { background: #c8a96e; }
.sd-swatch--expert { background: rgba(0,0,0,0.10); }
[data-theme="dark"] .sd-swatch--expert { background: rgba(255,255,255,0.15); }

/* ── Trend stat cards ── */
.sd-trend-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 2px;
}
.sd-trend-card {
    background: var(--settings-bg);
    border-radius: 14px;
    padding: 8px 10px;
    text-align: center;
    box-shadow: var(--shadow-inner);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}
.sd-trend-card-badge { font-size: 1.1rem; line-height: 1; margin-bottom: 1px; }
.sd-trend-card-num {
    font-size: 1.3rem;
    font-weight: 900;
    line-height: 1;
    font-family: 'Playfair Display', serif;
}
.sd-trend-card-unit { font-size: 0.65rem; font-weight: 700; margin-left: 2px; vertical-align: middle; }
.sd-trend-card-lbl {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
}
.sd-trend-card-sub { font-size: 0.6rem; color: var(--text-muted); }
[data-theme="dark"] .sd-trend-card { background: rgba(255,255,255,0.04); }

/* Trend card number colour variants */
.sd-tcn--gold   { color: #c8a96e; }
.sd-tcn--teal   { color: #7ab3a2; }
.sd-tcn--purple { color: #9b7abf; }
.sd-tcn--red    { color: #d84040; }
.sd-tcn--muted  { color: var(--text-muted); font-size: 0.95rem; }
[data-theme="dark"] .sd-tcn--gold { color: #d4a843; }

/* ════════════════════════════════════
   RECENT SCENARIO CARDS
   ════════════════════════════════════ */
.sd-pz-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 8px;
    gap: 10px;
}
.sd-pz-card:last-child { margin-bottom: 0; }
.sd-pz-win  { background: rgba(122,179,162,0.08); border: 1px solid rgba(122,179,162,0.25); }
.sd-pz-loss { background: rgba(216,64,64,0.05);   border: 1px solid rgba(216,64,64,0.15); }
.sd-pz-left { flex: 1; min-width: 0; }
.sd-pz-word {
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sd-pz-expert { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; margin-top: 2px; }
.sd-pz-zone   { font-size: 0.68rem; color: var(--text-muted); font-weight: 600; margin-top: 2px; }
.sd-pz-right  { text-align: right; flex-shrink: 0; }
.sd-pz-score  { font-size: 0.8rem; font-weight: 700; color: var(--text-muted); }
.sd-pz-result { font-size: 0.82rem; font-weight: 800; margin-top: 3px; }
.sd-pz-result--win  { color: #7ab3a2; }
.sd-pz-result--loss { color: #d84040; }
[data-theme="dark"] .sd-pz-win  { background: rgba(122,179,162,0.10); }
[data-theme="dark"] .sd-pz-loss { background: rgba(216,64,64,0.08); }

/* ════════════════════════════════════
   ACHIEVEMENT BADGES (with tooltip)
   ════════════════════════════════════ */
.sd-badge-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.sd-badge-grid--achievements { gap: 10px; }

.sd-badge-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 10px 8px;
    border-radius: 14px;
    border: 1.5px solid;
    min-width: 72px;
    max-width: 90px;
    flex: 1;
    text-align: center;
    cursor: default;
    transition: transform 0.15s;
    position: relative;
}
.sd-badge-chip--tooltip { cursor: pointer; }
.sd-badge-chip:hover { transform: translateY(-2px); }

.sd-badge-earned {
    background: rgba(122,179,162,0.10);
    border-color: rgba(122,179,162,0.40);
}
.sd-badge-locked {
    background: #f5f5f5;
    border-color: #e0e0e0;
    opacity: 0.6;
    filter: grayscale(0.5);
}
[data-theme="dark"] .sd-badge-locked { background: rgba(255,255,255,0.04); }

.sd-badge-icon { font-size: 1.5rem; line-height: 1; }
.sd-badge-name {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    line-height: 1.2;
}
/* sd-badge-status removed — earned/locked communicated by chip styling only */

/* Tooltip bubble */
.sd-badge-tooltip {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30,30,30,0.92);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1.4;
    padding: 6px 9px;
    border-radius: 8px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 10;
    max-width: 180px;
    white-space: normal;
    text-align: center;
}
.sd-badge-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(30,30,30,0.92);
}
.sd-badge-chip--tooltip:hover .sd-badge-tooltip { opacity: 1; }

/* Hide tooltips on touch devices — they render as visible in-flow text */
@media (hover: none) {
    .sd-badge-tooltip { display: none !important; }
}

/* Achievement group labels */
.sd-ach-group-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.sd-ach-group-label--mt { margin-top: 14px; }

/* Divider between achievement groups */
.sd-ach-group {
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--tile-border);
}
.sd-ach-group:last-child {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

/* ════════════════════════════════════
   MISC
   ════════════════════════════════════ */
.sd-no-data {
    color: var(--text-muted);
    font-size: 0.88rem;
    text-align: center;
    padding: 8px 0;
}
.sd-ms-legend {
    text-align: center;
    padding: 12px 0;
    font-weight: 700;
    color: #c8a96e;
    font-size: 1.1rem;
}
[data-theme="dark"] .sd-ms-legend { color: #d4a843; }

/* Misc dark overrides */
[data-theme="dark"] .progress-bar-bg { background: rgba(255,255,255,0.08); }

/* Mobile */
@media (max-width: 450px) {
    .sd-gs-card-num { font-size: 1.65rem; }
    .sd-gs-card-icon { font-size: 1.7rem; }
    .sd-gs-dot { height: 28px; font-size: 0.58rem; }
    .sd-badge-chip { min-width: 62px; }
}

/* Issue 2 fix: Scenario badge ragged right edge at 414px — force 2-column grid */
@media (max-width: 414px) {
    .sd-badge-chip {
        flex: 0 1 calc(50% - 5px);
    }
}

/* ── modal-full: wider modal for Settings, Stats, Quiz Hub ── */
.modal-full {
    width: 96%;
    max-width: 640px;
    max-height: 92vh;
    text-align: left;
    padding: 20px 20px 28px 20px;
    border-radius: 24px;
    overflow-y: auto;
}

/* ════════════════════════════════════════════════════
   MAIN MENU UTILITY BUTTONS (Help / Board / Stats / Settings)
   ════════════════════════════════════════════════════ */

.mm-utils {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    width: 100%;
    margin-top: 4px;
}
/* 3-button footer variant */
.mm-utils--3 {
    grid-template-columns: repeat(3, 1fr);
}
/* 4-button footer variant (Training, Scenarios, Quiz pages) */
.mm-utils--4 {
    grid-template-columns: repeat(4, 1fr);
}

.mm-util-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 12px 6px;
    border-radius: 16px;
    border: 1.5px solid var(--tile-border);
    background: var(--settings-bg);
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.15s, background 0.15s, transform 0.12s, box-shadow 0.15s;
    box-shadow: var(--shadow-inner);
}

.mm-util-btn:hover {
    border-color: var(--brand-primary);
    background: #f0faf7;
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(122,179,162,0.18);
}

.mm-util-btn:active {
    transform: scale(0.96);
    box-shadow: var(--shadow-inner);
}

.mm-util-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.mm-util-lbl {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    line-height: 1;
}

/* Dark theme */
[data-theme="dark"] .mm-util-btn { background: rgba(255,255,255,0.05); }
[data-theme="dark"] .mm-util-btn:hover { background: rgba(122,179,162,0.12); }

/* 3-button footer: taller, more substantial buttons */
.mm-utils--3 .mm-util-btn {
    padding: 14px 6px;
    gap: 6px;
}
.mm-utils--3 .mm-util-icon { font-size: 1.6rem; }
.mm-utils--3 .mm-util-lbl  { font-size: 0.68rem; }

/* 4-button footer: same height as 3-button, slightly smaller icons to fit */
.mm-utils--4 .mm-util-btn {
    padding: 14px 4px;
    gap: 6px;
}
.mm-utils--4 .mm-util-icon { font-size: 1.4rem; }
.mm-utils--4 .mm-util-lbl  { font-size: 0.63rem; }

/* Mobile (≤ 480px): icon-only rows, labels hidden */
@media (max-width: 480px) {
    .mm-utils--3 .mm-util-btn {
        padding: 12px 4px;
        gap: 0;
        border-radius: 12px;
        min-height: 52px;
    }
    .mm-utils--3 .mm-util-icon { font-size: 1.5rem; }
    /* Hide labels on mobile — title= tooltip provides text hint */
    .mm-utils--3 .mm-util-lbl { display: none; }

    .mm-utils--4 .mm-util-btn {
        padding: 12px 2px;
        gap: 0;
        border-radius: 12px;
        min-height: 52px;
    }
    .mm-utils--4 .mm-util-icon { font-size: 1.4rem; }
    .mm-utils--4 .mm-util-lbl { display: none; }
}

/* ════════════════════════════════════════════════════
   COMMON MISTAKES SECTION (Phase 3)
   ════════════════════════════════════════════════════ */

/* Empty state */
.sd-mistakes-empty {
    color: var(--text-muted);
    font-size: 0.88rem;
    text-align: center;
    padding: 8px 0;
}

/* Three-stat summary row */
.sd-mk-summary {
    display: flex;
    justify-content: space-around;
    background: var(--settings-bg);
    border-radius: 14px;
    padding: 12px 8px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-inner);
}
.sd-mk-sum-stat {
    text-align: center;
    flex: 1;
}
.sd-mk-sum-num {
    font-size: 1.5rem;
    font-weight: 900;
    line-height: 1;
    font-family: 'Playfair Display', serif;
}
.sd-mk-sum-lbl {
    font-size: 0.58rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-muted);
    margin-top: 3px;
}

/* Group labels */
.sd-mk-group-label {
    font-size: 0.62rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* Repeat-offender list */
.sd-mk-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 4px;
}
.sd-mk-row {
    display: grid;
    grid-template-columns: 6rem 1fr;
    grid-template-rows: auto auto;
    column-gap: 10px;
    align-items: center;
    background: var(--settings-bg);
    border-radius: 10px;
    padding: 8px 10px;
    box-shadow: var(--shadow-inner);
}
.sd-mk-word {
    font-size: 0.92rem;
    font-weight: 900;
    letter-spacing: 1px;
    color: var(--text-main);
    grid-row: 1;
    grid-column: 1;
    white-space: nowrap;
}
.sd-mk-len {
    font-size: 0.58rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    grid-row: 2;
    grid-column: 1;
    margin-top: 2px;
}
.sd-mk-meta {
    grid-row: 1;
    grid-column: 2;
    display: flex;
    align-items: center;
    gap: 8px;
}
.sd-mk-bar-track {
    flex: 1;
    height: 6px;
    border-radius: 99px;
    background: var(--tile-border);
    overflow: hidden;
}
.sd-mk-bar-fill {
    height: 100%;
    border-radius: 99px;
    background: linear-gradient(90deg, #d84040, #e87070);
    transition: width 0.4s ease;
}
.sd-mk-count {
    font-size: 0.68rem;
    font-weight: 800;
    color: #d84040;
    flex-shrink: 0;
    min-width: 22px;
    text-align: right;
}
.sd-mk-hint {
    grid-row: 2;
    grid-column: 2;
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 2px;
}

/* "More" overflow note */
.sd-mk-more {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: center;
    margin: 4px 0 0 0;
    font-style: italic;
}

/* One-timer tag cloud */
.sd-mk-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 4px;
}
.sd-mk-cloud-tag {
    display: inline-block;
    padding: 4px 9px;
    border-radius: 20px;
    background: rgba(216,64,64,0.07);
    border: 1px solid rgba(216,64,64,0.18);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.8px;
    color: var(--text-main);
    cursor: default;
    transition: background 0.15s;
}
.sd-mk-cloud-tag:hover {
    background: rgba(216,64,64,0.13);
}
.sd-mk-cloud-more {
    display: inline-block;
    padding: 4px 9px;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    font-style: italic;
    align-self: center;
}

/* Footer note */
.sd-mk-note {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    margin: 10px 0 0 0;
    line-height: 1.5;
}

/* Dark theme adjustments */
[data-theme="dark"] .sd-mk-summary,
[data-theme="dark"] .sd-mk-row {
    background: rgba(255,255,255,0.04);
}
[data-theme="dark"] .sd-mk-cloud-tag {
    background: rgba(216,64,64,0.10);
    border-color: rgba(216,64,64,0.25);
}
[data-theme="dark"] .sd-mk-bar-track {
    background: rgba(255,255,255,0.12);
}

/* ════════════════════════════════════════════════════
   PHASE 3 — EXTRACTED INLINE STYLES
   All previously inline styles from index.html and
   stats_dashboard_v2.js now live here.
   ════════════════════════════════════════════════════ */

/* ── Global utility modifiers ── */
.btn--full     { width: 100%; }
.btn--flex     { flex: 1; }
.btn--sm       { font-size: 0.82rem; padding: 8px; }
.btn--mt-sm    { margin-top: 8px; }
.btn--mt-md    { margin-top: 10px; }
.btn--mt-lg    { margin-top: 15px; }
.btn--mt-xl    { margin-top: 20px; }
.btn--destructive-text { color: #c0392b; border-color: #ffcdd2; }
.text--destructive { color: #c0392b; }

/* ── Welcome message ── */
.welcome-msg { margin-top: 8px; }

/* ── Timer limit icon ── */
.timer-limit-icon { font-size: 1rem; }

/* ── Pill group full width ── */
.pill-group--full { width: 100%; }

/* ── Inline give-up confirmation bar ── */
.give-up-inline {
    background: #ffebeb;
    border: 1.5px solid #f5c0c0;
    border-radius: 12px;
    padding: 12px 14px;
    margin-top: 8px;
    text-align: center;
}
.give-up-inline__msg {
    font-size: 0.85rem;
    font-weight: 700;
    color: #d84040;
    margin-bottom: 10px;
}
.give-up-inline__btns {
    display: flex;
    gap: 8px;
    justify-content: center;
}
.give-up-inline__btn-keep,
.give-up-inline__btn-quit {
    flex: 1;
    padding: 10px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    font-family: inherit;
}
.give-up-inline__btn-keep {
    border: 1.5px solid #ccc;
    background: #fff;
}
.give-up-inline__btn-quit {
    border: 1.5px solid #d84040;
    background: #d84040;
    color: #fff;
    font-weight: 800;
}
[data-theme="dark"] .give-up-inline { background: rgba(216,64,64,0.10); border-color: rgba(216,64,64,0.25); }
[data-theme="dark"] .give-up-inline__btn-keep { background: var(--container-bg); border-color: var(--tile-border); color: var(--text-main); }

/* ── Shared modal primitives ── */
.modal-title {
    margin-top: 0;
    color: var(--header-color);
    font-family: 'Playfair Display', Georgia, serif;
    letter-spacing: 1px;
}
.modal-title--playfair {
    margin: 0;
    color: var(--header-color);
    font-family: 'Playfair Display', serif;
    letter-spacing: 1px;
}
.modal-title--teal-sm {
    margin: 0 0 6px 0;
    color: #7ab3a2;
    font-size: 1.15rem;
}
.modal-title--destructive {
    margin: 0 0 8px 0;
    color: #c0392b;
    font-size: 1.2rem;
}
.modal-title--gold {
    margin-top: 0;
    color: #b8860b;
}
.modal-title--main {
    margin: 0 0 var(--sp-sm) 0;
    font-size: var(--fs-lg);
    color: var(--text-main);
}
.modal-subtitle {
    font-size: 0.9rem;
    color: #666;
}
.modal-msg {
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 5px;
    font-size: 0.9rem;
}
.modal-body-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0 0 24px 0;
    line-height: 1.5;
}
.modal-body-text--gap-xl { margin: 0 0 var(--sp-xl) 0; }
.modal-body-text--gap-xs { margin: 0 0 4px 0; }
.modal-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.modal-big-icon {
    font-size: 2.2rem;
    margin-bottom: 10px;
}
.modal-big-icon--sm { font-size: 2rem; margin-bottom: 6px; }
.modal-row--mt  { margin-top: 20px; }
.modal-row--gap { gap: 10px; }
.modal--narrow     { max-width: 340px; }
.modal--narrow-lg  { max-width: 360px; }
.modal--center     { text-align: center; }

/* ── Name modal input ── */
.modal-name-input {
    width: 80%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #ccc;
    margin-bottom: 15px;
    font-family: inherit;
    font-weight: 600;
    text-align: center;
}

/* ── Destructive confirm button (quiz history clear, data reset) ── */
.btn-confirm-destructive {
    background: #ffebee;
    color: #c0392b;
    border: 1.5px solid #ffcdd2;
    border-radius: 16px;
    padding: 12px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    font-size: 0.95rem;
    box-shadow: 4px 4px 10px rgba(0,0,0,0.04);
}
.btn-confirm-destructive:hover { background: #ffcdd2; }

/* ── btn-back size modifier ── */
.btn-back--sm { padding: 6px 14px; font-size: 0.8rem; }

/* ── btn-quiz-submit inline variant (no top margin) ── */
.btn-quiz-submit--inline { margin-top: 0; padding: 12px; }

/* ── btn-quiz-submit margin-top variant ── */
.btn--mt-md { margin-top: 10px; }

/* ── Help modal components ── */
.help-tab-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
}
.help-tab-panel--text {
    text-align: left;
    font-size: 0.88rem;
    color: var(--text-main);
    line-height: 1.55;
}
.help-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--tile-border), transparent);
    margin: 0 0 14px 0;
    opacity: 0.6;
}
.help-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 14px;
}
.help-row__icon {
    font-size: 1.3rem;
    flex-shrink: 0;
    margin-top: 1px;
}
.help-row__flex1 { flex: 1; }
.help-row__label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 3px;
}
.help-row__label--teal { color: #7ab3a2; }
.help-row__label--gold { color: #c8a96e; }
.help-row__body {
    font-weight: 600;
    color: var(--text-main);
}
.help-section-heading {
    font-family: 'Playfair Display', serif;
    font-size: 1rem;
    font-weight: 900;
    letter-spacing: 2px;
    text-align: center;
    margin-bottom: 4px;
}
.help-section-heading--gold { color: #c8a96e; }
.help-section-sub {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--text-muted);
    opacity: 0.7;
    text-align: center;
    margin-bottom: 12px;
}
.help-filter-grid {
    margin-top: 6px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 10px;
    font-size: 0.82rem;
}
.help-keys-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 5px 12px;
    font-size: 0.82rem;
}
.help-key {
    font-family: monospace;
    background: var(--accent-blue);
    color: var(--status-text);
    padding: 2px 7px;
    border-radius: 5px;
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
    align-self: center;
}
.help-key--hook {
    background: var(--accent-pink);
    color: #a04b4b;
}
.help-key-desc {
    font-weight: 600;
    color: var(--text-main);
    align-self: center;
}

/* ── Settings page components ── */
.settings-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0 0 12px 0;
}
.settings-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    display: block;
    margin-bottom: 6px;
}
.settings-name-input {
    flex: 1;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1.5px solid #ddd;
    font-family: inherit;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-main);
    background: #fdfdfd;
    box-shadow: var(--shadow-inner);
    outline: none;
}
.settings-save-btn { flex: none; padding: 12px 20px; }
.settings-options-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.settings-keys-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 16px;
    font-size: 0.85rem;
}
.settings-reset-section {
    border: 1.5px solid #ffcdd2;
    border-radius: 16px;
    background: #fff8f8;
}
.settings-reset-heading { color: #c0392b; }
.settings-reset-btn {
    width: 100%;
    padding: 13px;
    background: #ffebee;
    color: #c0392b;
    border: 1.5px solid #ffcdd2;
    border-radius: 14px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    font-size: 0.95rem;
}
.settings-reset-btn:hover { background: #ffcdd2; }
.settings-back-wrap { margin-top: 16px; }
.settings-back-btn { padding: 14px; }
[data-theme="dark"] .settings-name-input { background: rgba(255,255,255,0.05); border-color: rgba(255,255,255,0.15); }
[data-theme="dark"] .settings-reset-section { background: rgba(216,64,64,0.06); border-color: rgba(216,64,64,0.25); }

.settings-back-wrap { margin-top: 16px; }
.settings-back-btn { padding: 14px; }
[data-theme="dark"] .settings-name-input { background: rgba(255,255,255,0.05); border-color: rgba(255,255,255,0.15); }
[data-theme="dark"] .settings-reset-section { background: rgba(216,64,64,0.06); border-color: rgba(216,64,64,0.25); }

/* ════════════════════════════════════════════════════
   BACKGROUND MUSIC — settings section
   ════════════════════════════════════════════════════ */

.vm-music-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: background 0.15s, border-color 0.15s;
    user-select: none;
}
.vm-music-option:hover {
    background: var(--tile-hover);
}
.vm-music-option input[type="radio"] {
    accent-color: var(--accent);
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    cursor: pointer;
}
.vm-music-option:has(input:checked) {
    background: rgba(var(--accent-rgb, 46,125,82), 0.08);
    border-color: var(--accent);
}
.vm-music-label {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}
.vm-music-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
    width: 26px;
    text-align: center;
}
.vm-music-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.vm-music-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}
.vm-music-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.vm-music-playing {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.5px;
    margin-left: auto;
    flex-shrink: 0;
}

/* Volume row */
.vm-volume-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 10px 12px;
    background: var(--tile-bg);
    border-radius: 10px;
    border: 1px solid var(--tile-border);
}
.vm-volume-icon {
    font-size: 1rem;
    flex-shrink: 0;
}
.vm-volume-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 5px;
    border-radius: 3px;
    background: var(--tile-border);
    outline: none;
    cursor: pointer;
}
.vm-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.vm-volume-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.vm-volume-pct {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 36px;
    text-align: right;
}

/* Credit line */
.vm-music-credit {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 10px;
    font-style: italic;
    opacity: 0.75;
}

/* Dark / nightlight theme overrides */
[data-theme="dark"] .vm-music-option:has(input:checked),
[data-theme="nightlight"] .vm-music-option:has(input:checked) {
    background: rgba(122, 179, 162, 0.10);
    border-color: var(--accent);
}
[data-theme="dark"] .vm-volume-row,
[data-theme="nightlight"] .vm-volume-row {
    background: rgba(255,255,255,0.04);
}
[data-theme="dark"] .vm-volume-slider,
[data-theme="nightlight"] .vm-volume-slider {
    background: rgba(255,255,255,0.15);
}

/* ── Stats page components ── */
.stats-actions-row {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}
.sd-detail-section { margin-top: 14px; }
.sd-detail-section + .sd-detail-section { margin-top: 16px; }
.sd-detail-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.badge-rack--display {
    font-size: 2rem;
    justify-content: center;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.js-targets-hidden { display: none; }

/* ── Quiz modal components ── */
.quiz-modal-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin: 4px 0 10px 0;
}
.quiz-gem-msg {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 700;
    margin: 6px 0 10px 0;
}
.quiz-rank-wrap {
    text-align: center;
    margin-top: 8px;
}
.quiz-submit-status {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-align: center;
    min-height: 18px;
    margin-top: 8px;
}
.lb-last-refresh { opacity: 0.7; }
.hist-reset-wrap { margin-top: 16px; }

/* ── Puzzle page components ── */
.puzzle-zone-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.puzzle-zone-hint {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
}
.header-container--puzzle { margin-bottom: 12px; }
.puzzle-best-move-bar {
    background: linear-gradient(135deg, #fff8e1, #fff3cd);
    border: 1.5px solid #ffe082;
    border-radius: 12px;
    padding: 10px 14px;
    margin-bottom: 8px;
    font-size: 0.82rem;
}
.puzzle-best-move-bar__label {
    font-size: 0.6rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #b8860b;
    margin-bottom: 4px;
}
.puzzle-best-move-bar__text {
    font-weight: 700;
    color: #7a5800;
}
.puzzle-top3-bar {
    background: linear-gradient(135deg, #fff8e1, #fff3cd);
    border: 1.5px solid #ffe082;
    border-radius: 12px;
    padding: 10px 14px;
    margin-bottom: 8px;
    font-size: 0.82rem;
    color: #7a5800;
    font-weight: 700;
    line-height: 1.7;
}
.rack-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 7px;
}
.puzzle-rack-label--no-mb { margin-bottom: 0; }
.btn-shuffle--rack { flex-shrink: 0; margin-left: 8px; }
.puzzle-rack-row {
    display: flex;
    justify-content: center;
}
.pr-title {
    margin: 0 0 4px 0;
    color: #7ab3a2;
    font-size: 1.1rem;
}
[data-theme="dark"] .puzzle-best-move-bar,
[data-theme="dark"] .puzzle-top3-bar {
    background: rgba(255,248,225,0.06);
    border-color: rgba(255,224,130,0.30);
}
[data-theme="dark"] .puzzle-best-move-bar__label { color: #d4a843; }
[data-theme="dark"] .puzzle-best-move-bar__text  { color: #c49a40; }
[data-theme="dark"] .puzzle-top3-bar             { color: #c49a40; }
[data-theme="dark"] .settings-name-input { color: var(--text-main); }

/* ── Stats dashboard v2 — extracted colour classes ── */

/* No-data empty state */
.sd-no-data {
    color: var(--text-muted);
    font-size: 0.88rem;
    text-align: center;
    padding: 8px 0;
}

/* Milestone legend (completed all) */
.sd-ms-legend {
    text-align: center;
    padding: 12px 0;
    font-weight: 700;
    color: #c8a96e;
    font-size: 1.1rem;
}

/* Legacy stale sd- classes removed — all stats colours now live in STATS DASHBOARD V2 section above */

/* Settings name row flex container */
.settings-name-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Prevent legacy .footer-controls button rule from overriding mm-util-btn */
#trainingFooter .mm-util-btn,
.qsp-footer .mm-util-btn {
    font-size: unset;
    padding: 12px 6px;
    min-height: unset;
    border-radius: 16px;
    letter-spacing: unset;
}

/* ── settingsPage and helpModal: full-page base (modal classes removed) ── */
/* These match the same pattern as #statsPage and #quizHubPage.           */
#settingsPage {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--container-bg);
    z-index: 201;
    overflow-y: auto;
    padding: 20px;
    box-sizing: border-box;
}

#helpModal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--container-bg);
    z-index: 201;
    overflow-y: auto;
    padding: 20px;
    box-sizing: border-box;
    text-align: left;
}

#helpModal .help-tab-btn {
    padding: 8px 6px;
    font-size: var(--fs-xs);
    min-height: 44px;
}


/* ════════════════════════════════════════════════════════════════════
   MOBILE PWA — FIXED HEADER & LAYOUT FIXES
   All rules scoped to ≤768px. Desktop is completely untouched.
   ════════════════════════════════════════════════════════════════════ */

/* ── Always hidden on desktop ──────────────────────────────────────── */
.vm-mobile-header {
    display: none;
}

@media (max-width: 768px) {

    /* ── White background on mobile ───────────────────────────────── */
    body {
        background-color: var(--container-bg);
        padding-top: max(58px, calc(env(safe-area-inset-top) + 50px));
        padding-bottom: max(var(--sp-xl), env(safe-area-inset-bottom));
        justify-content: flex-start;
    }

    /* ── Hide original in-card logo — fixed header replaces it ─────── */
    .header-container {
        display: none;
    }

    /* ── Quiz active banner spacing ────────────────────────────────── */
    #quizActiveBanner {
        margin-top: 4px;
    }

    /* ── Consistent background on Quizzes overlay across all themes ─── */
    #quizSelectionPage,
    #quizHubPage,
    .qsp-outer {
        background-color: var(--container-bg) !important;
    }

    /* ── Fixed top header bar — logo-only Home tap target ──────────── */
    .vm-mobile-header {
        display: flex;
        align-items: center;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        padding-top:    max(8px, env(safe-area-inset-top));
        padding-bottom: 8px;
        padding-left:   max(16px, env(safe-area-inset-left));
        padding-right:  max(16px, env(safe-area-inset-right));
        background: var(--btn-primary-bg);
        z-index: 2000;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
        user-select: none;
        -webkit-user-select: none;
    }

    .vm-mobile-header__brand {
        display: flex;
        align-items: center;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        flex: 1;
        min-width: 0;
        min-height: 34px;
    }

    .vm-mobile-header__logo {
        font-family: 'Playfair Display', Georgia, serif;
        font-size: 1.1rem;
        font-weight: 900;
        letter-spacing: 2px;
        color: #ffffff;
        line-height: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .vm-mobile-header__arrow {
        font-size: 0.65rem;
        opacity: 0.75;
        vertical-align: middle;
        margin-left: 2px;
        letter-spacing: 0;
    }

    /* Right-side page context label — "Training", "Scenarios" or "Quizzes" */
    .vm-mobile-header__page-label {
        font-family: 'Quicksand', sans-serif;
        font-size: 0.72rem;
        font-weight: 700;
        letter-spacing: 1.2px;
        text-transform: uppercase;
        color: rgba(255, 255, 255, 0.82);
        white-space: nowrap;
        flex-shrink: 0;
        padding-left: 12px;
        /* Hidden when empty — no layout shift when main menu is active */
        min-width: 0;
    }
    .vm-mobile-header__page-label:empty {
        display: none;
    }

    /* ── Full-page views: clear the fixed header ───────────────────── */
    #statsPage,
    #settingsPage,
    #quizHubPage,
    #helpModal,
    #quizSelectionPage {
        padding-top: max(58px, calc(env(safe-area-inset-top) + 50px)) !important;
    }

    #statsPage .stats-header,
    #settingsPage .stats-header,
    #quizHubPage .stats-header {
        margin-top: 0;
        padding-top: 0;
    }

    /* ── Quiz Hub overlay not needed on mobile — hub is already full-screen.
       Hiding it also prevents z-index 290 from covering the hub at z-index 200. ── */
    #quizHubOverlay {
        display: none !important;
    }

    /* ── Quizzes selection page: remove excess gap ─────────────────── */
    .qsp-outer {
        padding-top: 0;
        justify-content: flex-start;
    }
    .qsp-card {
        padding-top: 16px;
    }

    /* ── Puzzle page: clear the fixed header ───────────────────────── */
    #puzzlePage .puzzle-inner {
        padding-top: max(58px, calc(env(safe-area-inset-top) + 50px));
    }

    /* ── Apple-compliant touch targets ─────────────────────────────── */
    button,
    [role="button"] {
        min-height: 44px;
    }

    /* ── Scenario result: full-page on mobile (no modal, no overlay) ─ */
    #puzzleResultPage {
        top: 0;
        left: 0;
        transform: none;
        width: 100%;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
        box-shadow: none;
        padding-top: max(58px, calc(env(safe-area-inset-top) + 50px));
        overflow-y: auto;
        box-sizing: border-box;
        background: var(--container-bg);
        z-index: 200;
    }
    /* On mobile the overlay dimming is not needed — hide it */
    .puzzle-result-overlay {
        display: none !important;
    }
    /* Restructure the page header for mobile: sticky bar feel */
    .prp-header {
        padding: 0 16px 16px 16px;
        border-bottom: 1px solid var(--tile-border);
        margin-bottom: 4px;
    }
    .prp-title {
        font-size: 1.15rem;
    }
    /* Body padding tighter on mobile */
    .prp-body {
        padding: 16px 16px 32px 16px;
        max-width: 500px;
        margin: 0 auto;
    }

    /* Stats card layout handled via inline styles in stats_dashboard_v2.js
       for full mobile/CSS-variable compatibility. No overrides needed here. */

} /* end @media (max-width: 768px) */


/* ════════════════════════════════════════════════════════════════════
   DESKTOP FULL-PAGE DESTINATIONS — centered card layout
   Applies to ≥769px only. On mobile these are full-screen views
   (handled above). On desktop they render as centered floating cards
   with white background, border-radius, and shadow — consistent
   across Stats, Settings, Quiz Hub, Help, and the Scenario result.
   No JS inline styles needed. CSS is the single source of truth.
   ════════════════════════════════════════════════════════════════════ */

@media (min-width: 769px) {

    /* ── Shared card shell ── */
    #statsPage,
    #settingsPage,
    #quizHubPage,
    #helpModal,
    #puzzleResultPage {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 96%;
        max-width: 700px;
        max-height: 92vh;
        overflow-y: auto;
        background: var(--container-bg);
        border-radius: 24px;
        padding: 24px 24px 32px 24px;
        box-sizing: border-box;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.14);
        z-index: 501;
        height: auto;
    }

    /* ── Quiz Hub overlay suppressed on desktop — hub is an opaque card,
       overlay serves no purpose and bleeds through at z-index 290. ── */
    #quizHubOverlay {
        display: none !important;
    }

    /* Inner content wrapper: no extra centering needed — card is already constrained */
    .stats-page-inner {
        max-width: 100%;
        margin: 0;
        padding-bottom: 20px;
    }

} /* end @media (min-width: 769px) */



/* ════════════════════════════════════════════════════
   LOADING SCREEN  (#vmLoadScreen)
   Visible by default (no JS needed to show it).
   Dismissed by window load event adding .vmls--fading.
   ════════════════════════════════════════════════════ */

#vmLoadScreen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--container-bg, #ffffff);
    opacity: 1;
    transition: opacity 0.55s ease;
    pointer-events: all;
}

#vmLoadScreen.vmls--fading {
    opacity: 0;
    pointer-events: none;
}

.vmls-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
    user-select: none;
}

/* ── Brand block ── */
.vmls-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

/* ── Rackup loading screen — Concept 3 (R↑ monogram badge) ── */
.vmls-monogram {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: 22px;
    background: linear-gradient(145deg, #5a9e8e, #7ab3a2);
    box-shadow: 0 6px 24px rgba(90,158,142,0.35);
    animation: vmls-badge-pulse 2s ease-in-out infinite;
}
.vmls-monogram-r {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 2.8rem;
    font-weight: 900;
    color: #fff;
    line-height: 1;
}
.vmls-monogram-arrow {
    font-size: 1rem;
    font-weight: 800;
    color: rgba(255,255,255,0.8);
    margin-top: -10px;
    line-height: 1;
}
@keyframes vmls-badge-pulse {
    0%, 100% { transform: scale(1);    box-shadow: 0 6px 24px rgba(90,158,142,0.35); }
    50%       { transform: scale(1.04); box-shadow: 0 10px 32px rgba(90,158,142,0.50); }
}

/* ── "RACKUP" wordmark below monogram ── */
.vmls-wordmark {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.28em;
    color: var(--brand-primary, #7ab3a2);
    text-transform: uppercase;
}

/* ── Three-dot spinner ── */
.vmls-spinner {
    display: flex;
    gap: 7px;
    align-items: center;
}

.vmls-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--brand-primary, #7ab3a2);
    opacity: 0.25;
    animation: vmls-dot-pulse 1.1s ease-in-out calc(var(--vmls-d) * 0.22s) infinite;
}

@keyframes vmls-dot-pulse {
    0%, 100% { opacity: 0.25; transform: scale(1);    }
    45%       { opacity: 1;    transform: scale(1.25); }
}

/* ── Status text ── */
.vmls-msg {
    font-family: 'Quicksand', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted, #888);
    letter-spacing: 0.04em;
    margin: 0;
}

/* Dark / nightlight theme adjustments */
[data-theme="dark"] #vmLoadScreen,
[data-theme="nightlight"] #vmLoadScreen {
    background: var(--container-bg);
}

/* ── Puzzle Result — Share Row ─────────────────────────────────────────── */

.pr-share-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 1.4rem 0 0.6rem;
    padding-top: 1rem;
    border-top: 1px solid var(--tile-border, #e0e0e0);
}

.pr-share-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted, #888);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    flex-shrink: 0;
}

.pr-share-buttons {
    display: flex;
    gap: 8px;
}

.pr-share-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1.5px solid var(--tile-border, #ddd);
    border-radius: 8px;
    background: var(--tile-bg, #f9f9f9);
    color: var(--text-primary, #333);
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: background 0.13s, border-color 0.13s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: serif;
}

.pr-share-btn:hover {
    background: var(--tile-hover, #eee);
    border-color: var(--text-muted, #bbb);
    transform: translateY(-2px);
}

.pr-share-btn:active {
    transform: scale(0.94);
}

/* Platform tints on hover */
.pr-share-btn--x:hover       { border-color: #000;    color: #000;    }
.pr-share-btn--fb:hover      { border-color: #1877f2; color: #1877f2; }
.pr-share-btn--wa:hover      { border-color: #25d366; color: #25d366; }
.pr-share-btn--discord:hover { border-color: #5865f2; color: #5865f2; }
.pr-share-btn--linkedin:hover{ border-color: #0a66c2; color: #0a66c2; }
.pr-share-btn--copy:hover    { border-color: #7ab3a2; }

/* Dark/nightlight theme */
[data-theme="dark"] .pr-share-btn,
[data-theme="nightlight"] .pr-share-btn {
    border-color: var(--tile-border);
    background: var(--tile-bg);
    color: var(--text-primary);
}

[data-theme="dark"] .pr-share-btn:hover,
[data-theme="nightlight"] .pr-share-btn:hover {
    background: var(--tile-hover);
}



/* ════════════════════════════════════════════════════
   SPLASH SCREEN — REMOVED (Session 17)
   Dead code deleted Session 19. #vmSplash does not
   exist in index.html. All vmspl-* rules removed.
   ════════════════════════════════════════════════════ */
