
        /* ----- Settings bar (difficulty) ----- */
        .settings-bar { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; margin-bottom: 0.6rem; max-width: 460px; }
        .setting-group { display: flex; align-items: center; gap: 0.3rem; background: rgba(255,255,255,0.4); border: 1px solid rgba(255,255,255,0.55); 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: #2d4a5e; 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: #1a2b3a; transition: all 0.18s; }
        .setting-btn.active { background: linear-gradient(135deg, #fcd663, #f59e0b); color: #fff; box-shadow: 0 2px 10px rgba(245,158,11,0.45); }
        .setting-btn:hover:not(.active):not(:disabled) { background: rgba(245,158,11,0.12); }
        .setting-btn:disabled { opacity: 0.4; cursor: not-allowed; }

        /* ----- Desktop layout: board fills height, side rail eats the leftover
           horizontal space (mirrors snake.html). Overlays are confined to the
           board so the rail stays clickable on desktop. ----- */
        .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(255,255,255,0.42);
            border: 1px solid rgba(255,255,255,0.55);
            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: #d97706; 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;
            color: #1a2b3a; border-color: rgba(217,119,6,0.3);
        }
        .game-rail .history-toggle:hover, .game-rail .help-toggle:hover {
            background: rgba(217,119,6,0.1);
        }
        .game-rail .history-panel, .game-rail .help-panel {
            max-width: none; margin: 10px 0 0; background: none;
            border: none; padding: 0;
        }

        /* ----- Canvas container + overlays ----- */
        .game-container {
            position: relative;
            /* Hug the canvas — htFitSize makes this portrait board narrower than
               the old width:100% box on desktop. fit-content wraps it tight.
               backdrop-filter is dropped so the (mobile) position:fixed overlays
               aren't trapped to this container — the blur is invisible behind the
               opaque canvas anyway. */
            width: fit-content;
            max-width: 100%;
            margin: 0;
            border-radius: 18px;
            overflow: hidden;
            backdrop-filter: none; -webkit-backdrop-filter: none;
            box-shadow: 0 20px 60px rgba(0,0,0,0.35), 0 0 0 3px rgba(255,255,255,0.18) inset;
        }
        #canvas3d {
            display: block;
            border-radius: 18px;
            touch-action: none;
            cursor: pointer;
            background: linear-gradient(180deg, #4ec0ca 0%, #7ec9e1 50%, #fcd663 92%, #f59e0b 100%);
        }

        /* Top-right HUD bar: pause + score (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-score-box {
            pointer-events: none;
            background: rgba(13, 10, 20, 0.55);
            backdrop-filter: blur(6px);
            -webkit-backdrop-filter: blur(6px);
            border: 1px solid rgba(255,255,255,0.18);
            color: #fff;
            border-radius: 16px;
            padding: 8px 16px;
            font-family: 'Orbitron', monospace;
            display: flex;
            align-items: baseline;
            gap: 6px;
        }
        .hud-score-label {
            font-size: 0.62rem;
            letter-spacing: 0.18em;
            text-transform: uppercase;
            color: rgba(255,255,255,0.65);
        }
        .hud-score-value {
            font-size: 1.6rem;
            font-weight: 800;
            color: #fff;
            text-shadow: 0 2px 8px rgba(0,0,0,0.4);
        }
        .hud-best {
            margin-left: 8px;
            font-size: 0.7rem;
            color: rgba(252,214,99,0.95);
            letter-spacing: 0.08em;
        }
        .hud-pause-btn {
            pointer-events: auto;
            width: 44px; height: 44px;
            border-radius: 12px;
            background: rgba(13, 10, 20, 0.55);
            backdrop-filter: blur(6px);
            -webkit-backdrop-filter: blur(6px);
            border: 1px solid rgba(255,255,255,0.18);
            color: #fff;
            font-size: 1.2rem;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: transform 0.15s, background 0.15s;
        }
        .hud-pause-btn:hover { background: rgba(13, 10, 20, 0.75); transform: scale(1.05); }
        .hud-pause-btn[hidden] { display: none; }

        /* Start / pause / gameover overlays.
           Confined to the board (position:absolute inside the
           position:relative .game-container) so the side rail stays clickable
           on desktop. Goes full-screen (fixed) on mobile via the media query. */
        .overlay {
            position: absolute;
            inset: 0;
            z-index: 20;
            display: none;
            align-items: center;
            justify-content: center;
            overflow-y: auto;
            border-radius: 18px;
            background: linear-gradient(180deg, rgba(13, 10, 20, 0.15), rgba(13, 10, 20, 0.55));
            text-align: center;
            color: #fff;
            font-family: 'Orbitron', monospace;
            padding: 24px;
            backdrop-filter: blur(2px);
            -webkit-backdrop-filter: blur(2px);
        }
        .overlay.active { display: flex; }
        .overlay-box {
            background: rgba(13, 10, 20, 0.6);
            border: 1px solid rgba(255,255,255,0.18);
            border-radius: 22px;
            padding: 30px 30px 26px;
            min-width: 260px;
            max-width: 360px;
        }
        .overlay-title {
            font-size: 1.5rem;
            font-weight: 900;
            letter-spacing: 0.04em;
            margin: 0 0 6px;
            color: #fcd663;
            text-shadow: 0 2px 10px rgba(0,0,0,0.4);
        }
        .overlay-sub {
            margin: 0 0 18px;
            color: rgba(255,255,255,0.78);
            font-family: -apple-system, sans-serif;
            font-size: 0.92rem;
            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, #fcd663, #f59e0b);
            color: #1a1207;
        }
        .overlay-btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(245,158,11,0.4); }
        .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(3, 1fr);
            gap: 8px;
            margin: 12px 0 18px;
        }
        .stat-cell {
            padding: 10px 6px;
            background: rgba(255,255,255,0.06);
            border: 1px solid rgba(255,255,255,0.12);
            border-radius: 10px;
        }
        .stat-cell-label {
            font-size: 0.55rem;
            letter-spacing: 0.14em;
            color: rgba(255,255,255,0.55);
            margin-bottom: 4px;
        }
        .stat-cell-value {
            font-size: 1.1rem;
            font-weight: 800;
            color: #fcd663;
        }

        /* Countdown big number */
        .countdown {
            font-size: 5rem;
            font-weight: 900;
            color: #fff;
            text-shadow: 0 4px 20px rgba(0,0,0,0.4);
            animation: countdownPulse 1s ease-out;
        }
        @keyframes countdownPulse {
            0% { transform: scale(0.6); opacity: 0; }
            40% { transform: scale(1.2); opacity: 1; }
            100% { transform: scale(1); opacity: 0.95; }
        }

        /* Start CTA (idle pulse) */
        .start-cta {
            background: linear-gradient(135deg, #fcd663, #f59e0b);
            color: #1a1207;
            padding: 16px 38px;
            border-radius: 99px;
            font-family: 'Orbitron', monospace;
            font-weight: 800;
            font-size: 1.05rem;
            letter-spacing: 0.16em;
            text-transform: uppercase;
            box-shadow: 0 14px 36px rgba(245,158,11,0.5);
            animation: startPulse 1.6s ease-in-out infinite;
            cursor: pointer;
        }
        @keyframes startPulse {
            0%, 100% { transform: scale(1); box-shadow: 0 14px 36px rgba(245,158,11,0.5); }
            50% { transform: scale(1.06); box-shadow: 0 18px 44px rgba(245,158,11,0.7); }
        }
        .start-sub {
            display: block;
            margin-top: 14px;
            font-size: 0.84rem;
            color: rgba(255,255,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);
        }

        /* Score popup +1 */
        .score-pop {
            position: absolute;
            font-family: 'Orbitron', monospace;
            font-weight: 900;
            font-size: 1.6rem;
            color: #fcd663;
            text-shadow: 0 2px 12px rgba(0,0,0,0.4);
            pointer-events: none;
            animation: scorePop 0.9s ease-out forwards;
            z-index: 5;
        }
        @keyframes scorePop {
            0% { opacity: 0; transform: scale(0.6) translateY(0); }
            20% { opacity: 1; transform: scale(1.4) translateY(-10px); }
            100% { opacity: 0; transform: scale(0.9) translateY(-50px); }
        }

        /* 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(255,255,255,0.25);
            color: #fff; 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(255,255,255,0.1); }
        .help-panel, .history-panel {
            display: none; max-width: 460px; margin: 0.8rem auto 0; padding: 1rem 1.2rem;
            background: rgba(255,255,255,0.42); border: 1px solid rgba(255,255,255,0.55); border-radius: 14px;
            color: #1a2b3a; 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.85rem; color: #d97706; }
        .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: #d97706; text-align: center; margin-bottom: 8px; }
        .history-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; background: rgba(255,255,255,0.4); border-radius: 8px; font-size: 0.78rem; margin-bottom: 4px; }
        .history-score { font-family: 'Orbitron', monospace; font-weight: 700; color: #b8860b; }
        .history-meta { color: #2d4a5e; font-size: 0.72rem; }
        .history-empty { text-align: center; color: rgba(26,43,58,0.5); font-size: 0.84rem; padding: 12px; }

        /* In-overlay difficulty re-pick — MOBILE only (desktop uses the
           always-visible rail). Lets the start/end screens launch a run at a
           different difficulty without the full-screen overlay hiding it. */
        .overlay-settings { display: none; }

        @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; }
            /* Mobile: overlays go full-screen (no rail beside the board to
               preserve), so the start / end screens get 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;
            }
        }

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

        /* ----- Flappy theme variables (used by shared games.css) ----- */
        body.game-page {
            --t-bg: #4ec0ca;
            --t-bg-grad: linear-gradient(180deg, #70c5ce 0%, #87ceeb 60%, #fcd663 100%);
            --t-text: #1a2b3a;
            --t-text-muted: #2d4a5e;
            --t-primary: #f59e0b;
            --t-primary-mid: #fcd663;
            --t-primary-dark: #d97706;
            --t-card-bg: rgba(255,255,255,0.4);
            --t-card-border: rgba(255,255,255,0.55);
            --t-btn-grad: linear-gradient(135deg, #fcd663, #f59e0b);
        }
        body.game-page .game-name,
        body.game-page .score-value { color: #d97706 !important; -webkit-text-fill-color: #d97706 !important; background: none !important; }
