
        /* ----- Settings bar (size + theme) ----- */
        .settings-bar { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; margin-bottom: 0.6rem; max-width: 520px; }
        .setting-group { display: flex; align-items: center; gap: 0.3rem; background: rgba(168,85,247,0.12); border: 1px solid rgba(192,132,252,0.45); border-radius: 30px; padding: 0.25rem 0.4rem; }
        .setting-label { font-family: 'Orbitron', monospace; font-size: 0.5rem; text-transform: uppercase; letter-spacing: 0.08em; color: #c4b5fd; padding-left: 0.4rem; }
        .setting-btn { padding: 0.3rem 0.7rem; border: none; border-radius: 20px; font-family: inherit; font-size: 0.7rem; font-weight: 600; cursor: pointer; background: transparent; color: #f5f3ff; transition: all 0.18s; }
        .setting-btn.active { background: linear-gradient(135deg, #c084fc, #a855f7 55%, #7c3aed); color: #fff; box-shadow: 0 2px 10px rgba(168,85,247,0.55); }
        .setting-btn:hover:not(.active):not(:disabled) { background: rgba(168,85,247,0.18); }
        .setting-btn:disabled { opacity: 0.4; cursor: not-allowed; }

        /* ----- Desktop fill-the-screen layout -----
           Board lives in .game-main; the leftover horizontal space is consumed
           by a side rail (settings / live stats / history / how-to-play) so the
           board no longer floats as a small element in a sea of empty space. */
        .game-layout {
            display: flex; gap: 22px; align-items: flex-start;
            justify-content: center; width: 100%;
            max-width: 1400px; margin: 0 auto; padding: 0 18px;
        }
        .game-main {
            position: relative; display: flex; flex-direction: column;
            align-items: center; min-width: 0; max-width: 100%;
        }
        .game-rail {
            width: 340px; flex-shrink: 0;
            display: flex; flex-direction: column; gap: 14px;
        }
        .rail-card {
            background: rgba(168,85,247,0.08);
            border: 1px solid rgba(192,132,252,0.32);
            border-radius: 16px; padding: 14px 16px;
            backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
        }
        .rail-card-title {
            font-family: 'Orbitron', monospace; font-size: 0.6rem;
            text-transform: uppercase; letter-spacing: 0.14em;
            color: #c084fc; margin-bottom: 10px;
        }
        /* Settings stack full-width in the rail */
        .game-rail .settings-bar {
            flex-direction: column; align-items: stretch;
            gap: 10px; margin: 0; max-width: none;
        }
        .game-rail .setting-group { justify-content: space-between; }
        /* Recent games + help live open in the rail */
        .game-rail .history-toggle, .game-rail .help-toggle {
            display: block; width: 100%; margin: 0; text-align: left;
        }
        .game-rail .history-panel, .game-rail .help-panel {
            max-width: none; margin: 10px 0 0; background: none;
            border: none; padding: 0;
        }

        /* ----- Canvas container + overlays ----- */
        /* Board hugs the canvas (no empty strip beside it). backdrop-filter is
           NOT applied here so that `position:fixed` mobile overlays aren't
           trapped to this container as their positioning context. */
        .game-container {
            position: relative;
            width: fit-content;
            max-width: 100%;
            margin: 0;
            border-radius: 18px;
            overflow: hidden;
            box-shadow: 0 20px 60px rgba(0,0,0,0.45), 0 0 0 3px rgba(192,132,252,0.18) inset;
        }
        #canvas3d {
            display: block;
            border-radius: 18px;
            touch-action: manipulation;
            cursor: pointer;
            background: radial-gradient(ellipse at 50% 0%, #312e81 0%, #1e1b4b 60%, #0f0c2e 100%);
        }

        /* HUD overlay on canvas */
        .game-hud {
            position: absolute; inset: 0; pointer-events: none;
        }
        .hud-top {
            position: absolute; top: 10px; left: 10px; right: 10px;
            display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
        }
        .hud-stats-box {
            pointer-events: none;
            background: rgba(13, 10, 30, 0.6);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            border: 1px solid rgba(192,132,252,0.28);
            color: #fff;
            border-radius: 14px;
            padding: 7px 14px;
            font-family: 'Orbitron', monospace;
            display: flex;
            align-items: center;
            gap: 14px;
        }
        .hud-stat { display: flex; flex-direction: column; align-items: center; min-width: 36px; }
        .hud-stat-label {
            font-size: 0.5rem;
            letter-spacing: 0.16em;
            text-transform: uppercase;
            color: rgba(196,181,253,0.7);
            margin-bottom: 1px;
        }
        .hud-stat-value {
            font-size: 0.95rem;
            font-weight: 800;
            color: #fff;
            text-shadow: 0 2px 6px rgba(0,0,0,0.4);
        }
        .hud-stat-value.best { color: #fcd663; }
        .hud-pause-btn {
            pointer-events: auto;
            width: 42px; height: 42px;
            border-radius: 12px;
            background: rgba(13, 10, 30, 0.6);
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
            border: 1px solid rgba(192,132,252,0.28);
            color: #fff;
            font-size: 1.05rem;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: transform 0.15s, background 0.15s;
        }
        .hud-pause-btn:hover { background: rgba(168,85,247,0.45); transform: scale(1.05); }
        .hud-pause-btn[hidden] { display: none; }

        /* Overlays — confined to the board (position:absolute) so the side rail
           (size / faces / stats) stays clickable behind them on desktop. The
           .game-container is position:relative + overflow:hidden, so an overlay
           clips to the rounded board and scrolls internally if needed. */
        .overlay {
            position: absolute;
            inset: 0;
            z-index: 20;
            display: none;
            align-items: center;
            justify-content: center;
            overflow-y: auto;
            background: linear-gradient(180deg, rgba(13, 10, 30, 0.2), rgba(13, 10, 30, 0.7));
            text-align: center;
            color: #fff;
            font-family: 'Orbitron', monospace;
            padding: 24px;
            backdrop-filter: blur(3px);
            -webkit-backdrop-filter: blur(3px);
            border-radius: 18px;
        }
        .overlay.active { display: flex; }
        .overlay .overlay-box { margin: auto; }

        /* In-overlay size re-pick — MOBILE only (desktop uses the always-visible
           rail). Lets the start + end screens launch a new run at a different
           board size without hunting for a panel below. */
        .overlay-settings { display: none; }
        .overlay-box {
            background: rgba(13, 10, 30, 0.7);
            border: 1px solid rgba(192,132,252,0.32);
            border-radius: 22px;
            padding: 28px 28px 24px;
            min-width: 260px;
            max-width: 380px;
        }
        .overlay-title {
            font-size: 1.55rem;
            font-weight: 900;
            letter-spacing: 0.04em;
            margin: 0 0 6px;
            color: #fcd663;
            text-shadow: 0 2px 12px rgba(0,0,0,0.5);
        }
        .overlay-sub {
            margin: 0 0 18px;
            color: rgba(245,243,255,0.8);
            font-family: -apple-system, sans-serif;
            font-size: 0.9rem;
            line-height: 1.5;
        }
        .overlay-btn-row {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
            justify-content: center;
        }
        .overlay-btn {
            padding: 11px 20px;
            border-radius: 99px;
            border: 0;
            cursor: pointer;
            font-family: 'Orbitron', monospace;
            font-size: 0.78rem;
            font-weight: 800;
            letter-spacing: 0.1em;
            text-transform: uppercase;
            transition: transform 0.15s, box-shadow 0.15s;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
        }
        .overlay-btn-primary {
            background: linear-gradient(135deg, #c084fc, #a855f7 55%, #7c3aed);
            color: #fff;
        }
        .overlay-btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(168,85,247,0.5); }
        .overlay-btn-ghost {
            background: rgba(255,255,255,0.08);
            border: 1px solid rgba(255,255,255,0.25);
            color: #fff;
        }
        .overlay-btn-ghost:hover { background: rgba(255,255,255,0.15); }

        /* Game-over stats grid */
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 8px;
            margin: 12px 0 18px;
        }
        .stat-cell {
            padding: 10px 6px;
            background: rgba(255,255,255,0.06);
            border: 1px solid rgba(192,132,252,0.18);
            border-radius: 10px;
        }
        .stat-cell-label {
            font-size: 0.55rem;
            letter-spacing: 0.14em;
            color: rgba(196,181,253,0.7);
            margin-bottom: 4px;
        }
        .stat-cell-value {
            font-size: 1.1rem;
            font-weight: 800;
            color: #fcd663;
        }
        .stat-cell-value.highlight { color: #c084fc; }

        /* Start CTA */
        .start-cta {
            background: linear-gradient(135deg, #c084fc, #a855f7 55%, #7c3aed);
            color: #fff;
            padding: 16px 38px;
            border-radius: 99px;
            font-family: 'Orbitron', monospace;
            font-weight: 800;
            font-size: 1.05rem;
            letter-spacing: 0.16em;
            text-transform: uppercase;
            border: 0;
            box-shadow: 0 14px 36px rgba(168,85,247,0.55);
            animation: startPulse 1.6s ease-in-out infinite;
            cursor: pointer;
        }
        @keyframes startPulse {
            0%, 100% { transform: scale(1); box-shadow: 0 14px 36px rgba(168,85,247,0.5); }
            50% { transform: scale(1.06); box-shadow: 0 18px 44px rgba(168,85,247,0.75); }
        }
        .start-sub {
            display: block;
            margin-top: 14px;
            font-size: 0.84rem;
            color: rgba(245,243,255,0.85);
            font-weight: 500;
            letter-spacing: 0.06em;
            font-family: -apple-system, sans-serif;
            text-shadow: 0 2px 8px rgba(0,0,0,0.5);
        }

        /* Help + history panels */
        .help-toggle, .history-toggle {
            display: block; margin: 0.7rem auto 0; padding: 0.4rem 1.1rem;
            background: none; border: 1px solid rgba(192,132,252,0.32);
            color: #f5f3ff; border-radius: 20px; font-family: 'Orbitron', monospace;
            font-size: 0.66rem; cursor: pointer; letter-spacing: 0.12em; text-transform: uppercase;
        }
        .help-toggle:hover, .history-toggle:hover { background: rgba(168,85,247,0.16); }
        .help-panel, .history-panel {
            display: none; max-width: 520px; margin: 0.8rem auto 0; padding: 1rem 1.2rem;
            background: rgba(168,85,247,0.08); border: 1px solid rgba(192,132,252,0.32);
            border-radius: 14px;
            color: #f5f3ff; font-family: -apple-system, sans-serif; font-size: 0.86rem; line-height: 1.55;
        }
        .help-panel.active, .history-panel.active { display: block; }
        .help-panel h3 { margin: 0 0 6px; font-family: 'Orbitron', monospace; font-size: 0.78rem; color: #c084fc; text-transform: uppercase; letter-spacing: 0.08em; }
        .help-panel ul { margin: 0 0 10px; padding-left: 20px; }
        .help-panel li { margin: 3px 0; }
        .history-title { font-family: 'Orbitron', monospace; font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.1em; color: #c084fc; text-align: center; margin-bottom: 8px; }
        .history-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; background: rgba(168,85,247,0.1); border-radius: 8px; font-size: 0.78rem; margin-bottom: 4px; }
        .history-score { font-family: 'Orbitron', monospace; font-weight: 700; color: #fcd663; }
        .history-meta { color: #c4b5fd; font-size: 0.72rem; }
        .history-empty { text-align: center; color: rgba(245,243,255,0.4); font-size: 0.84rem; padding: 12px; }

        /* Pause / play icon */
        .pause-icon::before { content: '⏸'; }
        .play-icon::before { content: '▶'; }

        /* ----- Mobile: stack rail below board, overlays go full-screen ----- */
        @media (max-width: 899px) {
            .game-layout { flex-direction: column; align-items: center; gap: 14px; padding: 0 12px; }
            .game-rail { width: 100%; max-width: 480px; }
            .game-rail .settings-bar { flex-direction: row; flex-wrap: wrap; justify-content: center; }
            .game-rail .setting-group { justify-content: center; }
            /* No rail beside the board to preserve on mobile — give the start /
               end screens the whole viewport. */
            .overlay { position: fixed; border-radius: 0; z-index: 10000; }
            .overlay-settings {
                display: flex; flex-wrap: wrap; gap: 8px;
                justify-content: center; margin: 4px 0 14px;
            }
        }

        /* ----- Memory jewel-tone theme variables (used by shared games.css) ----- */
        body.game-page {
            --t-bg: #1e1b4b;
            --t-bg-grad: radial-gradient(ellipse at 50% -20%, #312e81 0%, #1e1b4b 70%);
            --t-text: #f5f3ff;
            --t-text-muted: #c4b5fd;
            --t-text-subtle: #a78bfa;
            --t-primary: #a855f7;
            --t-primary-mid: #c084fc;
            --t-primary-dark: #7c3aed;
            --t-card-bg: rgba(168,85,247,0.08);
            --t-card-border: rgba(192,132,252,0.35);
            --t-btn-grad: linear-gradient(135deg, #c084fc, #a855f7 55%, #7c3aed);
            --t-correct: #10b981;
        }
        body.game-page .game-name,
        body.game-page .score-value { color: #c084fc !important; -webkit-text-fill-color: #c084fc !important; background: none !important; }
