        /* Cinzel - bundled locally for native app (no network dependency) */
        @font-face { font-family: 'Cinzel'; font-style: normal; font-weight: 700; font-display: swap;
            src: url('fonts/cinzel-700.woff2') format('woff2');
            unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
        @font-face { font-family: 'Cinzel'; font-style: normal; font-weight: 700; font-display: swap;
            src: url('fonts/cinzel-700-ext.woff2') format('woff2');
            unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
        @font-face { font-family: 'Cinzel'; font-style: normal; font-weight: 900; font-display: swap;
            src: url('fonts/cinzel-900.woff2') format('woff2');
            unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
        @font-face { font-family: 'Cinzel'; font-style: normal; font-weight: 900; font-display: swap;
            src: url('fonts/cinzel-900-ext.woff2') format('woff2');
            unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
        @font-face { font-family: 'Cinzel Decorative'; font-style: normal; font-weight: 700; font-display: swap;
            src: url('fonts/cinzel-dec-700.woff2') format('woff2');
            unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
        @font-face { font-family: 'Cinzel Decorative'; font-style: normal; font-weight: 700; font-display: swap;
            src: url('fonts/cinzel-dec-700-ext.woff2') format('woff2');
            unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
        @font-face { font-family: 'Cinzel Decorative'; font-style: normal; font-weight: 900; font-display: swap;
            src: url('fonts/cinzel-dec-900.woff2') format('woff2');
            unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
        @font-face { font-family: 'Cinzel Decorative'; font-style: normal; font-weight: 900; font-display: swap;
            src: url('fonts/cinzel-dec-900-ext.woff2') format('woff2');
            unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }

        :root {
            --bg-green: #0a3d1d;
            --card-w: 84px;
            --card-h: calc(var(--card-w) * 1.42);
            --card-rank-scale: 1;
            --card-suit-scale: 1;
            --max-w: var(--card-w);
            --max-h: var(--card-h);
            --gold: #ffd700;
            --fixed-gap: -60px;
            --anim-scale: 1;
            --board-max-width: 860px;
            --board-gap: 8px;
            --cardback-image: url('../cardback/classic.webp');
            --mii-glow-color: rgba(255, 215, 0, 0.9);
            --mii-text-color: #fff;
            --mii-text-border: rgba(255, 255, 255, 0.4);
            --mii-text-bg: rgba(16, 18, 20, 0.88);
        }

        body, button, input, select, textarea {
            font-family: 'Cinzel', system-ui, -apple-system, 'PingFang TC', 'Noto Sans CJK TC', sans-serif;
            margin: 0;
            color: white;
            touch-action: manipulation;
        }

        body {
            background: radial-gradient(ellipse at 20% 30%, #0f4a24 0%, #051d0e 50%, #020e07 100%);
            display: flex;
            flex-direction: column;
            height: 100vh;
            padding-top: env(safe-area-inset-top);
            padding-bottom: env(safe-area-inset-bottom);
            overflow: hidden;
            position: relative;
        }

        body::before {
            content: '';
            position: fixed;
            inset: 0;
            background:
                radial-gradient(ellipse at 70% 20%, rgba(255,215,0,0.04) 0%, transparent 50%),
                radial-gradient(ellipse at 30% 80%, rgba(0,180,80,0.05) 0%, transparent 45%);
            pointer-events: none;
            z-index: 0;
            animation: felt-ambient calc(12s * var(--anim-scale)) ease-in-out infinite alternate;
            transition: opacity 0.25s ease-out;
        }

        @keyframes felt-ambient {
            0%   { opacity: 0.6; transform: scale(1); }
            50%  { opacity: 1; }
            100% { opacity: 0.7; transform: scale(1.04); }
        }

        @media (prefers-reduced-motion: reduce) {
            body::before { animation: none; }
        }

        #header {
            padding: 10px 10px;
            background: rgba(0, 0, 0, 0.62);
            border-bottom: 2px solid var(--gold);
        }

        .header-main {
            display: grid;
            grid-template-columns: auto 1fr auto auto;
            align-items: center;
            gap: 8px;
            min-height: 42px;
        }

        .header-stat {
            font-size: 11px;
            line-height: 1.2;
            min-width: 64px;
            display: flex;
            flex-direction: column;
        }

        .header-title {
            color: var(--gold);
            letter-spacing: 1.6px;
            font-size: 1.02rem;
            font-weight: 900;
            text-align: center;
            line-height: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 2px;
            font-family: 'Cinzel Decorative', 'Georgia', serif;
        }

        .header-title-main {
            line-height: 1;
        }

        .header-mode-tag {
            display: none;
            font-size: 0.56rem;
            letter-spacing: 0.5px;
            color: #d3ecff;
            background: rgba(124, 190, 255, 0.22);
            border: 1px solid rgba(124, 190, 255, 0.55);
            border-radius: 999px;
            padding: 2px 6px;
            line-height: 1.1;
            white-space: nowrap;
        }

        .header-mode-tag.show {
            display: inline-block;
        }

        .header-controls {
            display: flex;
            align-items: center;
            justify-content: flex-end;
        }

        .timer-pill {
            font-size: 13px;
            font-weight: 700;
            font-variant-numeric: tabular-nums;
            padding: 7px 14px;
            border-radius: 999px;
            background: rgba(255, 255, 255, 0.08);
            border: 1px solid rgba(255, 215, 0, 0.35);
            min-width: 84px;
            text-align: center;
        }
        .timer-pill.rewinding {
            color: #ffe7a8;
            border-color: rgba(255, 208, 88, 0.72);
            box-shadow: 0 0 0 2px rgba(255, 208, 88, 0.2), 0 0 14px rgba(255, 192, 91, 0.35);
            animation: timer-rewind-pulse calc(0.24s * var(--anim-scale)) ease-in-out infinite alternate;
        }
        @keyframes timer-rewind-pulse {
            from { transform: translateX(0); filter: brightness(0.94); }
            to { transform: translateX(-1px); filter: brightness(1.14); }
        }

        .header-settings {
            font-size: 19px;
            line-height: 1;
            background: #263238;
            color: white;
            padding: 8px 12px;
            border-radius: 8px;
            border: none;
            cursor: pointer;
            font-weight: 700;
            min-height: 42px;
            min-width: 48px;
            touch-action: manipulation;
            transition: transform calc(0.3s * var(--anim-scale)) ease;
        }
        .header-settings:hover  { transform: scale(1.03); }
        .header-settings:active { transform: scale(0.93); }

        @media (max-width: 520px) {
            #header {
                padding: 9px 8px;
            }

            .header-stat {
                font-size: 13px;
                min-width: 72px;
            }

            .header-title {
                font-size: 1.03rem;
                letter-spacing: 1px;
            }

            .header-mode-tag {
                font-size: 0.54rem;
                padding: 2px 5px;
            }

            .timer-pill {
                font-size: 13px;
                min-width: 80px;
                padding: 7px 10px;
            }

            .header-settings {
                font-size: 20px;
                min-height: 42px;
                min-width: 42px;
                padding: 8px 10px;
            }
        }

        #board {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: flex-start;
            gap: var(--board-gap);
            padding: 20px 5px;
            width: min(100%, var(--board-max-width));
            margin-inline: auto;
            box-sizing: border-box;
            /* no transition — prevents layout flash when columns are added/removed */
        }

        .column {
            display: flex;
            flex-direction: column;
            width: var(--card-w);
            max-width: var(--card-w);
            min-height: 120px;
            position: relative;
            background: rgba(255, 255, 255, 0.03);
            border-radius: 6px;
            transition: box-shadow 0.4s ease-out;
        }

        .card {
            width: var(--card-w);
            height: var(--card-h);
            max-width: var(--card-w);
            max-height: var(--card-h);
            background: linear-gradient(160deg, #fffef7 0%, #f8f4e8 100%);
            border-radius: 6px;
            color: black;
            position: relative;
            box-shadow: 0 3px 8px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.8);
            transition: transform calc(0.25s * var(--anim-scale)) cubic-bezier(0.18, 0.89, 0.32, 1.28);
            display: flex;
            flex-direction: column;
            padding: 6px;
            box-sizing: border-box;
            border: 1px solid #d4c9a8;
            margin-bottom: var(--fixed-gap);
        }

        .card::before {
            content: '';
            position: absolute;
            inset: 3px;
            border: 1px solid rgba(0,0,0,0.07);
            border-radius: 4px;
            pointer-events: none;
            z-index: 0;
        }

        .card-corner {
            position: absolute;
            display: flex;
            flex-direction: column;
            align-items: center;
            line-height: 1;
            font-size: 0.72rem;
            font-weight: 900;
        }

        .card-tl {
            top: 4px;
            left: 5px;
        }

        .card-br {
            bottom: 4px;
            right: 5px;
            transform: rotate(180deg);
        }
        .card-br { display: none; }

        .card-rank {
            font-family: 'Cinzel', 'Noto Sans Symbols2', 'Segoe UI Symbol', serif;
            font-size: calc(0.85rem * var(--card-rank-scale));
            font-weight: 900;
            line-height: 1;
        }

        .card-suit-small {
            font-family: 'Cinzel', 'Noto Sans Symbols2', 'Segoe UI Symbol', serif;
            font-size: calc(0.65rem * var(--card-suit-scale));
            line-height: 1.1;
        }

        .card-suit-tr {
            position: absolute;
            top: 8px;
            right: 7.5px;
            font-family: 'Cinzel', 'Noto Sans Symbols2', 'Segoe UI Symbol', serif;
            font-size: calc(0.65rem * var(--card-suit-scale));
            line-height: 1.1;
            font-weight: 900;
        }

        /* Tablet readability: make corner rank/suit easier to read */
        @media (min-width: 700px) {
            .card-rank { font-size: calc(1.2rem * var(--card-rank-scale)); }
            .card-suit-small { font-size: calc(0.95rem * var(--card-suit-scale)); }
            .card-suit-tr { font-size: calc(0.95rem * var(--card-suit-scale)); }
        }

        @media (min-width: 1000px) {
            .card-rank { font-size: calc(1.35rem * var(--card-rank-scale)); }
            .card-suit-small { font-size: calc(1.05rem * var(--card-suit-scale)); }
            .card-suit-tr { font-size: calc(1.05rem * var(--card-suit-scale)); }
        }

        .card-center-suit {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            font-family: 'Cinzel', 'Noto Sans Symbols2', 'Segoe UI Symbol', serif;
            font-size: calc(2.8rem * var(--card-suit-scale));
            line-height: 1;
            z-index: 1;
        }

        @media (min-width: 450px) {
            .card {
                margin-bottom: var(--fixed-gap);
            }
        }

        @media (min-width: 900px) {
            :root {
                --board-max-width: 1040px;
                --board-gap: 14px;
            }

            #header {
                padding: 12px 14px;
            }

            .header-main {
                gap: 12px;
            }

            .header-stat {
                font-size: 17px;
                min-width: 112px;
            }

            .header-title {
                font-size: 1.8rem;
            }

            .timer-pill {
                font-size: 28px;
                min-width: 176px;
                padding: 10px 18px;
            }

            .header-settings {
                font-size: 30px;
                min-height: 56px;
                min-width: 64px;
            }

            #board {
                gap: 14px;
                padding: 24px 10px;
            }

            #footer {
                padding: 18px 12px calc(18px + env(safe-area-inset-bottom));
            }

            .pile {
                width: 68px;
                height: 93px;
            }

            #deck-pile {
                font-size: 30px;
            }

            .btn-main {
                font-size: 1.35rem;
                padding: 16px 36px;
            }

            #btn-undo {
                width: 62px;
                height: 62px;
            }

            #btn-undo svg {
                width: 30px;
                height: 30px;
            }
        }

        @media (min-width: 1200px) {
            :root {
                --board-max-width: 1240px;
                --board-gap: 18px;
            }

            #board {
                gap: 18px;
            }
        }

        /* --- Landscape Tablet (iPad, Samsung Tab, etc.) --- */
        /* ═══════════════════════════════════════════════════════════════════
           UNIFIED LANDSCAPE LAYOUT — 3-column sidebar for ALL landscape devices
           [Left: Title/Deck/Timer/Settings] | [Board: full height] | [Right: Deal/Undo/Recycle]
           Three sizing tiers based on screen height:
             • < 500px  → phone landscape (compact)
             • ≥ 500px  → tablet landscape (medium)
             • ≥ 800px  → large tablet / desktop (spacious)
           ═══════════════════════════════════════════════════════════════════ */

        /* ── Base: Phone Landscape (height < 500px) ── */
        @media (orientation: landscape) {
            body {
                display: grid;
                grid-template-columns: 96px 1fr 108px;
                grid-template-rows: 1fr;
                padding: 0;
                padding-left: env(safe-area-inset-left);
                padding-right: env(safe-area-inset-right);
                overflow: hidden;
            }

            /* Left Sidebar: Info Panel */
            #header {
                grid-column: 1;
                grid-row: 1;
                width: auto;
                border-bottom: none;
                border-right: 1px solid var(--gold);
                padding: 8px 5px;
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                box-sizing: border-box;
            }

            .header-main {
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: space-around;
                width: 100%;
                height: 100%;
                gap: 4px;
                min-height: 0;
                min-width: 0;
            }

            .header-title {
                font-size: 0.62rem;
                letter-spacing: 0.3px;
                text-align: center;
                gap: 2px;
            }

            .header-title-main { font-size: 0.62rem; }

            .header-mode-tag {
                font-size: 0.38rem;
                padding: 1px 4px;
            }

            .header-stat {
                font-size: 9px;
                min-width: 0;
                text-align: center;
                align-items: center;
            }

            .header-controls {
                gap: 0;
                justify-content: center;
            }

            .timer-pill {
                font-size: 10px;
                min-width: 58px;
                padding: 4px 6px;
                text-align: center;
                border-radius: 6px;
            }

            .header-settings {
                font-size: 15px;
                min-height: 32px;
                min-width: 34px;
                padding: 5px 6px;
                border-radius: 6px;
            }

            /* Center: Game Board (full viewport height) */
            #board {
                grid-column: 2;
                grid-row: 1;
                min-width: 0;
                width: 100%;
                justify-content: space-evenly;
                align-items: flex-start;
                gap: 4px;
                padding: 6px 4px;
                overflow: hidden;
            }

            /* Right Sidebar: Controls */
            #footer {
                grid-column: 3;
                grid-row: 1;
                position: static;
                right: auto; top: auto; bottom: auto;
                width: auto;
                display: flex;
                flex-direction: column;
                justify-content: space-around;
                align-items: center;
                border-top: none;
                border-left: 1px solid var(--gold);
                padding: 8px 7px;
                z-index: 1;
                box-sizing: border-box;
            }

            #footer .pile { width: 52px; height: 72px; }
            #footer #deck-pile { font-size: 24px; }
            #footer #btn-undo { width: 50px; height: 50px; }
            #footer #btn-undo svg { width: 22px; height: 22px; }

            #deal-label, #recycle-label { font-size: 9px; margin-top: 4px; }

            /* Sum bar centered over board: offset = (right - left) / 2 = (108-96)/2 = 6px */
            #sum-bar { left: calc(50% - 6px); bottom: 12px; }

            /* Tip tooltip: no bottom footer, float near board bottom */
            .need-three-tip { bottom: 16px; }

            #ad-banner { display: none; }
        }

        /* ── Tablet Landscape (height ≥ 500px: iPad, Samsung Tab, etc.) ── */
        @media (orientation: landscape) and (min-height: 500px) {
            body {
                grid-template-columns: 145px 1fr 160px;
            }

            .header-title { font-size: 1.1rem; letter-spacing: 0.8px; }
            .header-title-main { font-size: 1.1rem; }
            .header-stat { font-size: 14px; }

            .timer-pill {
                font-size: 17px;
                min-width: 98px;
                padding: 7px 12px;
            }

            .header-settings {
                font-size: 22px;
                min-height: 46px;
                min-width: 50px;
                padding: 8px 9px;
            }

            #board { gap: 10px; padding: 12px 8px; }

            #footer .pile { width: 64px; height: 88px; }
            #footer #deck-pile { font-size: 30px; }
            #footer #btn-undo { width: 58px; height: 58px; }
            #footer #btn-undo svg { width: 28px; height: 28px; }
            #deal-label, #recycle-label { font-size: 11px; }

            /* offset = (160-145)/2 = 7.5px */
            #sum-bar { left: calc(50% - 7.5px); }
        }

        /* ── Large Landscape (height ≥ 800px: iPad Pro, Desktop) ── */
        @media (orientation: landscape) and (min-height: 800px) {
            body {
                grid-template-columns: 190px 1fr 205px;
            }

            .header-title { font-size: 1.6rem; letter-spacing: 1.2px; }
            .header-title-main { font-size: 1.6rem; }
            .header-stat { font-size: 17px; }

            .timer-pill {
                font-size: 22px;
                min-width: 130px;
                padding: 9px 14px;
            }

            .header-settings {
                font-size: 28px;
                min-height: 54px;
                min-width: 58px;
                padding: 10px 11px;
            }

            #board { gap: 14px; padding: 16px 10px; }

            #footer { padding: 16px 12px; }
            #footer .pile { width: 76px; height: 104px; }
            #footer #deck-pile { font-size: 36px; }
            #footer #btn-undo { width: 68px; height: 68px; }
            #footer #btn-undo svg { width: 32px; height: 32px; }
            #deal-label, #recycle-label { font-size: 13px; }

            /* offset = (205-190)/2 = 7.5px */
            #sum-bar { left: calc(50% - 7.5px); }
        }

        .card:last-child {
            margin-bottom: 0;
        }

        .card.red {
            color: #c0392b;
        }

        .card.is-fading {
            opacity: 0 !important;
            visibility: hidden;
        }

        /* ── Long-stack compression ── */
        .card.stack-middle {
            display: none;
        }

        @keyframes card-compress {
            0%   { height: var(--card-h); margin-bottom: var(--fixed-gap); opacity: 0.85; transform: scaleX(1); }
            60%  { opacity: 0.2; transform: scaleX(0.92); }
            100% { height: 0; margin-bottom: 0; opacity: 0; transform: scaleX(0.88); }
        }

        .card.stack-middle-animating {
            animation: card-compress calc(0.32s * var(--anim-scale)) ease-in forwards;
            overflow: hidden;
            pointer-events: none;
        }

        @keyframes badge-appear {
            0%   { opacity: 0; transform: scale(0.6); }
            65%  { transform: scale(1.18); }
            100% { opacity: 1; transform: scale(1); }
        }

        .stack-count-badge.appear {
            animation: badge-appear calc(0.3s * var(--anim-scale)) ease-out forwards;
            animation-delay: calc(0.18s * var(--anim-scale));
            opacity: 0;
        }

        .stack-count-badge {
            align-self: center;
            background: rgba(0, 0, 0, 0.62);
            color: #ffd700;
            border: 1px solid rgba(255, 215, 0, 0.4);
            border-radius: 10px;
            padding: 2px 9px;
            font-size: 10px;
            font-weight: 700;
            letter-spacing: 0.5px;
            z-index: 200;
            pointer-events: none;
            white-space: nowrap;
            /* Negative margin to overlap the compressed cards beneath */
            margin-top: -6px;
            margin-bottom: -6px;
            position: relative;
            box-shadow: 0 1px 4px rgba(0,0,0,0.5);
        }

        .card.selected {
            transform: translateX(40%) rotate(3deg);
            outline: 2px solid var(--gold);
            filter: brightness(1.05);
            animation: selected-pulse 2s ease-in-out infinite;
        }

        @keyframes selected-pulse {
            0%, 100% { box-shadow: 0 3px 6px rgba(0,0,0,0.5), 0 0 6px rgba(255,215,0,0.2); }
            50% { box-shadow: 0 3px 6px rgba(0,0,0,0.5), 0 0 12px rgba(255,215,0,0.35); }
        }

        .card.selected-ready {
            filter: brightness(1.15) !important;
            animation: auto-clear-charge 0.6s cubic-bezier(0.4, 0, 0.8, 1) forwards !important;
        }

        .card.candidate-soft {
            outline: 1px solid rgba(255, 215, 0, 0.24);
            outline-offset: 1px;
            box-shadow: 0 3px 8px rgba(0,0,0,0.42), 0 0 0 1px rgba(255, 215, 0, 0.08), 0 0 10px rgba(255, 215, 0, 0.12);
            filter: brightness(1.03) saturate(1.02);
            transition: transform calc(0.18s * var(--anim-scale)) ease, box-shadow calc(0.18s * var(--anim-scale)) ease, filter calc(0.18s * var(--anim-scale)) ease;
            z-index: 2;
            will-change: transform, box-shadow, filter;
        }

        .card.candidate-soft:not(.selected):not(.selected-ready):not(.selected-invalid-pending) {
            transform: translateX(6%) rotate(1deg);
            opacity: 0.98;
        }

        .card.selected-invalid-pending {
            outline: 2px solid rgba(255, 118, 96, 0.82);
            outline-offset: 1px;
            box-shadow: 0 3px 8px rgba(0,0,0,0.48), 0 0 0 1px rgba(255, 118, 96, 0.18), 0 0 12px rgba(255, 118, 96, 0.16);
            filter: brightness(1.04) saturate(0.98);
            animation: selected-invalid-pending-pulse calc(0.9s * var(--anim-scale)) ease-in-out infinite;
            will-change: transform, box-shadow, filter;
        }

        @keyframes selected-invalid-pending-pulse {
            0%, 100% {
                transform: translateX(40%) rotate(3deg) scale(1);
                box-shadow: 0 3px 8px rgba(0,0,0,0.48), 0 0 0 1px rgba(255, 118, 96, 0.18), 0 0 12px rgba(255, 118, 96, 0.16);
            }

            50% {
                transform: translateX(40%) rotate(3deg) scale(1.015);
                box-shadow: 0 3px 8px rgba(0,0,0,0.48), 0 0 0 1px rgba(255, 118, 96, 0.28), 0 0 16px rgba(255, 118, 96, 0.22);
            }
        }

        .card.selection-magnetic,
        .card.selected-magnetic {
            animation: selection-magnetic-pulse calc(0.24s * var(--anim-scale)) cubic-bezier(0.22, 1, 0.36, 1) both;
            will-change: transform, box-shadow;
        }

        @keyframes selection-magnetic-pulse {
            0% {
                transform: translateX(40%) rotate(3deg) scale(1);
                box-shadow: 0 3px 8px rgba(0,0,0,0.45), 0 0 0 1px rgba(255, 215, 0, 0.18), 0 0 8px rgba(255, 215, 0, 0.14);
            }

            50% {
                transform: translateX(40%) rotate(3deg) scale(1.045);
                box-shadow: 0 3px 8px rgba(0,0,0,0.45), 0 0 0 1px rgba(255, 215, 0, 0.28), 0 0 16px rgba(255, 215, 0, 0.28);
            }

            100% {
                transform: translateX(40%) rotate(3deg) scale(1);
                box-shadow: 0 3px 8px rgba(0,0,0,0.45), 0 0 0 1px rgba(255, 215, 0, 0.2), 0 0 10px rgba(255, 215, 0, 0.16);
            }
        }

        @keyframes auto-clear-charge {
            0%   { outline-color: rgba(255,255,255,0.8); box-shadow: 0 3px 8px rgba(0,0,0,0.45), 0 0 0px rgba(255,215,0,0); }
            50%  { outline-color: rgba(255,215,0,0.9);  box-shadow: 0 3px 8px rgba(0,0,0,0.45), 0 0 10px rgba(255,215,0,0.5); }
            100% { outline-color: rgba(255,215,0,1);    box-shadow: 0 3px 8px rgba(0,0,0,0.45), 0 0 20px rgba(255,215,0,0.9); }
        }

        .card.invalid-flash {
            animation: invalid-shake calc(0.36s * var(--anim-scale)) ease-in-out 2;
            outline: 3px solid #ff3b30 !important;
            box-shadow: 0 0 0 2px rgba(255, 59, 48, 0.28), 0 0 16px rgba(255, 59, 48, 0.5);
        }

        @keyframes invalid-shake {

            0%,
            100% {
                transform: translateX(0);
            }

            25% {
                transform: translateX(-4px);
            }

            50% {
                transform: translateX(4px);
            }

            75% {
                transform: translateX(-3px);
            }
        }

        /* --- 特效層 --- */
        #fx-layer {
            position: fixed;
            inset: 0;
            pointer-events: none;
            z-index: 9999;
        }

        .column-beam {
            position: absolute;
            width: 100%;
            height: 200vh;
            top: -50vh;
            --cb-beam-color: rgba(255, 255, 255, 0.8);
            background: linear-gradient(to right, transparent, var(--cb-beam-color), transparent);
            box-shadow: 0 0 30px var(--cb-beam-color);
            animation: beam-out calc(0.8s * var(--anim-scale)) ease-out forwards;
        }

        @keyframes beam-out {
            0% {
                transform: scaleX(0);
                opacity: 0;
            }

            20% {
                transform: scaleX(1.5);
                opacity: 1;
            }

            100% {
                transform: scaleX(0);
                opacity: 0;
            }
        }

        .column-clear-text {
            position: absolute;
            top: 20%;
            left: 50%;
            transform: translateX(-50%);
            white-space: nowrap;
            font-family: 'Cinzel', Georgia, serif;
            font-weight: 700;
            font-size: 1.4rem;
            letter-spacing: 0.12em;
            color: #fff;
            text-shadow: 0 0 14px rgba(255, 215, 0, 0.95), 0 0 28px rgba(255, 165, 0, 0.5), 0 2px 4px rgba(0, 0, 0, 0.9);
            animation: text-float-up calc(1.2s * var(--anim-scale)) ease-out forwards;
        }

        @keyframes text-float-up {
            0% {
                transform: translate(-50%, 0);
                opacity: 0;
            }

            20% {
                opacity: 1;
            }

            100% {
                transform: translate(-50%, -120px);
                opacity: 0;
            }
        }

        .combo-text {
            position: fixed;
            top: 45%;
            left: 50%;
            transform: translate(-50%, -50%);
            font-family: 'Cinzel Decorative', 'Cinzel', Georgia, serif;
            font-weight: 900;
            font-size: 3.2rem;
            letter-spacing: 0.04em;
            color: #fff;
            text-align: center;
            text-shadow: 0 0 10px rgba(255, 215, 0, 0.8), 0 0 20px rgba(255, 165, 0, 0.6);
            z-index: 10000;
            animation: combo-slam calc(1.6s * var(--anim-scale)) cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
        }

        .combo-text.combo-lite {
            font-family: 'Cinzel', Georgia, serif;
            font-size: clamp(1.4rem, 4.2vw, 2.35rem);
            letter-spacing: 0.06em;
            color: #fff7d8;
            -webkit-text-stroke: 0;
            -webkit-text-fill-color: currentColor;
            background: none;
            text-shadow: 0 0 8px rgba(255, 215, 0, 0.32), 0 1px 2px rgba(0, 0, 0, 0.86);
            filter: none;
            animation: combo-lite-fade calc(0.9s * var(--anim-scale)) ease-out forwards;
        }

        @keyframes combo-lite-fade {
            0% {
                transform: translate(-50%, -46%) scale(0.98);
                opacity: 0;
            }

            14% {
                transform: translate(-50%, -50%) scale(1);
                opacity: 1;
            }

            100% {
                transform: translate(-50%, -56%) scale(1);
                opacity: 0;
            }
        }

        body.major-combo-active::before {
            opacity: 0.42;
        }

        body.major-combo-active #particle-canvas,
        body.major-combo-active #pixi-canvas {
            opacity: 0.6;
        }

        body.major-combo-active .column-beam,
        body.major-combo-active .column.column-cleared-glow,
        body.major-combo-active .column-clear-text,
        body.major-combo-active .clear-flash,
        body.major-combo-active .clear-flash.orange,
        body.major-combo-active .warm-flash,
        body.major-combo-active .golden-vignette,
        body.major-combo-active .combo-border-flash,
        body.major-combo-active .lucky-three-win {
            opacity: 0.72;
            filter: saturate(0.9) brightness(0.95);
        }

        body.magic-moment-active::before {
            opacity: 0.52;
        }

        body.magic-moment-active #particle-canvas,
        body.magic-moment-active #pixi-canvas {
            opacity: 0.48;
        }

        @keyframes combo-slam {
            0%   { opacity: 0; transform: translate(-50%, -64%) scale(1.14); }
            22%  { opacity: 1; transform: translate(-50%, -50%) scale(1.0); }
            55%  { opacity: 1; transform: translate(-50%, -53%) scale(0.99); }
            100% { opacity: 0; transform: translate(-50%, -110%) scale(0.97); }
        }

        /* Border flash on combo ≥ 2 */
        .combo-border-flash {
            position: fixed;
            inset: 0;
            border: 3px solid rgba(255, 215, 0, 0);
            pointer-events: none;
            z-index: 9999;
            border-radius: 2px;
            animation: combo-border-pulse calc(0.45s * var(--anim-scale)) ease-out forwards;
        }
        @keyframes combo-border-pulse {
            0%   { border-color: rgba(255, 215, 0, 0.9); box-shadow: inset 0 0 28px rgba(255, 215, 0, 0.25); }
            60%  { border-color: rgba(255, 215, 0, 0.4); box-shadow: inset 0 0 10px rgba(255, 215, 0, 0.1); }
            100% { border-color: rgba(255, 215, 0, 0); box-shadow: none; }
        }

        .lucky-three-win {
            animation: win-glow 1s infinite alternate;
            z-index: 1000 !important;
        }

        @keyframes win-glow {
            from {
                transform: scale(1.2);
                box-shadow: 0 0 20px var(--gold);
            }

            to {
                transform: scale(1.4) rotate(10deg);
                box-shadow: 0 0 50px white, 0 0 100px var(--gold);
            }
        }

        /* --- Canvas Particle Layer --- */
        #particle-canvas {
            position: fixed;
            inset: 0;
            pointer-events: none;
            z-index: 9998;
        }

        /* --- PIXI.js WebGL Ambient Layer --- */
        #pixi-canvas {
            position: fixed;
            inset: 0;
            pointer-events: none;
            z-index: 9996;
        }

        /* --- Clear Flash Overlay (radial glow) --- */
        .clear-flash {
            position: fixed;
            inset: 0;
            background: radial-gradient(circle at 50% 45%, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0) 65%);
            pointer-events: none;
            z-index: 9997;
            animation: clear-flash-anim calc(0.3s * var(--anim-scale)) ease-out forwards;
        }

        .clear-flash.orange {
            background: radial-gradient(circle at 50% 45%, rgba(255,200,80,0.8) 0%, rgba(255,160,40,0) 60%);
        }

        .card.clear-phase-windup,
        .card.clear-phase-impact,
        .card.clear-phase-settle,
        #board.clear-phase-windup .card,
        #board.clear-phase-impact .card,
        #board.clear-phase-settle .card,
        #fx-layer.clear-phase-windup .card,
        #fx-layer.clear-phase-impact .card,
        #fx-layer.clear-phase-settle .card {
            will-change: transform, opacity, box-shadow, filter;
        }

        .card.clear-phase-windup,
        #board.clear-phase-windup .card,
        #fx-layer.clear-phase-windup .card {
            animation: clear-phase-windup calc(0.16s * var(--anim-scale)) ease-out both;
        }

        .card.clear-phase-impact,
        #board.clear-phase-impact .card,
        #fx-layer.clear-phase-impact .card {
            animation: clear-phase-impact calc(0.14s * var(--anim-scale)) cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
        }

        .card.clear-phase-settle,
        #board.clear-phase-settle .card,
        #fx-layer.clear-phase-settle .card {
            animation: clear-phase-settle calc(0.22s * var(--anim-scale)) ease-out both;
        }

        @keyframes clear-phase-windup {
            0% {
                opacity: 1;
                transform: translateY(0) scale(1);
                box-shadow: 0 3px 8px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.8);
                filter: brightness(1);
            }

            100% {
                opacity: 0.96;
                transform: translateY(-1px) scale(1.012);
                box-shadow: 0 3px 8px rgba(0,0,0,0.45), 0 0 0 1px rgba(255,215,0,0.12), 0 0 12px rgba(255,215,0,0.16);
                filter: brightness(1.04);
            }
        }

        @keyframes clear-phase-impact {
            0% {
                opacity: 1;
                transform: translateY(-1px) scale(1.012);
                box-shadow: 0 3px 8px rgba(0,0,0,0.45), 0 0 0 1px rgba(255,215,0,0.14), 0 0 12px rgba(255,215,0,0.18);
            }

            55% {
                opacity: 0.98;
                transform: translateY(0) scale(0.988);
                box-shadow: 0 3px 8px rgba(0,0,0,0.45), 0 0 0 1px rgba(255,215,0,0.22), 0 0 18px rgba(255,215,0,0.28);
            }

            100% {
                opacity: 0.94;
                transform: translateY(0) scale(1);
                box-shadow: 0 3px 8px rgba(0,0,0,0.45), 0 0 0 1px rgba(255,215,0,0.12), 0 0 10px rgba(255,215,0,0.12);
            }
        }

        @keyframes clear-phase-settle {
            0% {
                opacity: 0.94;
                transform: translateY(0) scale(1);
                filter: brightness(1.06);
            }

            100% {
                opacity: 1;
                transform: translateY(0) scale(1);
                filter: brightness(1);
            }
        }

        .clear-energy-trail {
            position: absolute;
            height: 2px;
            border-radius: 999px;
            background: linear-gradient(90deg, rgba(255,255,255,0), rgba(255,215,0,0.92), rgba(255,255,255,0));
            box-shadow: 0 0 8px rgba(255,215,0,0.45);
            transform-origin: left center;
            pointer-events: none;
            animation: clear-energy-trail-fade calc(0.32s * var(--anim-scale)) ease-out forwards;
            will-change: transform, opacity;
        }

        @keyframes clear-energy-trail-fade {
            0% {
                opacity: 0;
                transform: scaleX(0.32);
            }

            20% {
                opacity: 1;
                transform: scaleX(1);
            }

            100% {
                opacity: 0;
                transform: scaleX(1.18);
            }
        }

        @keyframes clear-flash-anim {
            0% { opacity: 0; transform: scale(0.8); }
            25% { opacity: var(--flash-intensity, 0.15); transform: scale(1); }
            100% { opacity: 0; transform: scale(1.1); }
        }

        /* --- Number Flyout (elegant) --- */
        .number-flyout {
            position: fixed;
            font-size: 1.6rem;
            font-weight: 900;
            color: rgba(255,215,0,0.9);
            text-shadow: 0 0 8px rgba(255,215,0,0.4);
            pointer-events: none;
            z-index: 10000;
        }

        .number-result {
            position: fixed;
            font-size: 2rem;
            font-weight: 900;
            color: rgba(255,255,255,0.95);
            text-shadow: 0 0 12px rgba(255,215,0,0.5);
            pointer-events: none;
            z-index: 10000;
            animation: number-result-pop calc(0.9s * var(--anim-scale)) cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
        }

        @keyframes number-result-pop {
            0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
            25% { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
            55% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
            100% { transform: translate(-50%, -50%) scale(0.95); opacity: 0; }
        }

        .number-flyout.error { color: rgba(255,80,80,0.9); text-shadow: 0 0 8px rgba(255,60,60,0.4); }
        .number-result.error {
            color: rgba(255,100,100,0.95);
            text-shadow: 0 0 12px rgba(255,60,60,0.4);
        }

        /* --- Win Ring (soft glow) --- */
        .win-ring {
            position: fixed;
            border: 2px solid rgba(255,215,0,0.6);
            border-radius: 50%;
            pointer-events: none;
            z-index: 9999;
            box-shadow: 0 0 15px rgba(255,215,0,0.3), inset 0 0 15px rgba(255,215,0,0.15);
            animation: win-ring-expand calc(0.9s * var(--anim-scale)) cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
        }

        @keyframes win-ring-expand {
            0% { width: 20px; height: 20px; opacity: 0.8; transform: translate(-50%, -50%); }
            60% { opacity: 0.5; }
            100% { width: 280px; height: 280px; opacity: 0; transform: translate(-50%, -50%); }
        }

        /* --- Combo Tiers (gold/white premium palette) --- */
        .combo-text.tier-1 { font-size: 3.2rem; color: var(--gold); }
        .combo-text.tier-2 {
            font-size: 3.6rem;
            background: linear-gradient(135deg, #ffd700, #ffe066);
            -webkit-background-clip: text; -webkit-text-fill-color: transparent;
            background-clip: text;
            filter: drop-shadow(0 0 8px rgba(255,215,0,0.3));
        }
        .combo-text.tier-3 {
            font-size: 4.2rem;
            background: linear-gradient(135deg, #ffd700, #fff4cc, #ffd700);
            background-size: 200% 100%;
            -webkit-background-clip: text; -webkit-text-fill-color: transparent;
            background-clip: text;
            filter: drop-shadow(0 0 12px rgba(255,215,0,0.4));
            animation: combo-slam calc(1.6s * var(--anim-scale)) cubic-bezier(0.2, 0.8, 0.2, 1) forwards, combo-shimmer 2s ease-in-out infinite;
        }
        .combo-text.tier-4 {
            font-size: 4.6rem;
            color: #fff;
            -webkit-text-stroke: 1px rgba(255,215,0,0.6);
            filter: drop-shadow(0 0 16px rgba(255,215,0,0.5)) drop-shadow(0 0 4px rgba(255,255,255,0.3));
            animation: combo-slam calc(1.6s * var(--anim-scale)) cubic-bezier(0.2, 0.8, 0.2, 1) forwards,
                       combo-pulse-4 0.85s ease-in-out 0.36s infinite;
        }
        .combo-text.tier-5 {
            font-size: 5rem;
            color: #fff;
            -webkit-text-stroke: 1.5px rgba(255,215,0,0.7);
            filter: drop-shadow(0 0 20px rgba(255,215,0,0.6)) drop-shadow(0 0 40px rgba(255,200,0,0.25)) drop-shadow(0 0 4px rgba(255,255,255,0.5));
            animation: combo-slam calc(1.6s * var(--anim-scale)) cubic-bezier(0.2, 0.8, 0.2, 1) forwards,
                       combo-pulse-5 0.65s ease-in-out 0.36s infinite;
        }

        .combo-text.tier-3.combo-lite,
        .combo-text.tier-4.combo-lite,
        .combo-text.tier-5.combo-lite {
            font-size: clamp(1.4rem, 4.2vw, 2.35rem);
            -webkit-text-stroke: 0;
            -webkit-text-fill-color: currentColor;
            background: none;
            filter: none;
            animation: combo-lite-fade calc(0.9s * var(--anim-scale)) ease-out forwards;
        }

        @keyframes combo-shimmer {
            0% { background-position: 0% 50%; }
            100% { background-position: 200% 50%; }
        }

        @keyframes combo-pulse-4 {
            0%, 100% { filter: drop-shadow(0 0 8px rgba(255,215,0,0.35)) drop-shadow(0 0 2px rgba(255,255,255,0.25)); }
            50%       { filter: drop-shadow(0 0 22px rgba(255,215,0,0.65)) drop-shadow(0 0 10px rgba(255,255,255,0.45)); }
        }
        @keyframes combo-pulse-5 {
            0%, 100% { filter: drop-shadow(0 0 12px rgba(255,215,0,0.45)) drop-shadow(0 0 4px rgba(255,255,255,0.35)); }
            40%       { filter: drop-shadow(0 0 32px rgba(255,215,0,0.85)) drop-shadow(0 0 16px rgba(255,255,255,0.65)); }
        }

        /* --- Column Cleared Glow --- */
        .column.column-cleared-glow {
            --cb-glow-color: rgba(255,215,0,0.3);
            box-shadow: 0 0 20px var(--cb-glow-color), 0 0 40px var(--cb-glow-color);
            transition: box-shadow 0.6s ease-out;
        }

        /* --- Column Mii Tension (咪牌欄位背光) --- */
        .column.mii-tension {
            box-shadow: 0 0 18px var(--mii-glow-color), inset 0 0 12px color-mix(in srgb, var(--mii-glow-color) 12%, transparent);
            transition: box-shadow 0.3s ease-in;
        }

        /* --- Warm Flash / Golden Vignette (subtle) --- */
        .warm-flash {
            position: fixed;
            inset: 0;
            background: radial-gradient(ellipse at 50% 45%, rgba(255,200,80,0.08) 0%, transparent 58%);
            pointer-events: none;
            z-index: 9996;
            animation: warm-glow calc(0.56s * var(--anim-scale)) ease-out forwards;
        }

        @keyframes warm-glow {
            0% { opacity: 0; transform: scale(0.9); }
            25% { opacity: 1; transform: scale(1); }
            100% { opacity: 0; transform: scale(1.05); }
        }

        .golden-vignette {
            position: fixed;
            inset: 0;
            pointer-events: none;
            z-index: 9996;
            background: radial-gradient(ellipse at center, transparent 38%, rgba(255,200,60,0.11) 100%);
            animation: vignette-fade calc(1.4s * var(--anim-scale)) ease-out forwards;
        }

        @keyframes vignette-fade {
            0% { opacity: 0; }
            15% { opacity: 1; }
            100% { opacity: 0; }
        }

        /* --- Panel Entrance Animations --- */
        @keyframes panel-spring-in {
            0% { transform: scale(0.8); opacity: 0; }
            60% { transform: scale(1.05); opacity: 1; }
            100% { transform: scale(1); opacity: 1; }
        }

        @keyframes panel-shake-in {
            0% { transform: scale(0.9) translateX(0); opacity: 0; }
            20% { transform: scale(1.02) translateX(-8px); opacity: 1; }
            40% { transform: scale(1) translateX(6px); }
            60% { transform: scale(1) translateX(-4px); }
            80% { transform: scale(1) translateX(2px); }
            100% { transform: scale(1) translateX(0); }
        }

        @keyframes settings-slide-in {
            from { transform: translateX(100%); }
            to { transform: translateX(0); }
        }

        @keyframes overlay-fade-in {
            0% { opacity: 0; }
            100% { opacity: 1; }
        }

        .win-panel { animation: panel-spring-in calc(0.6s * var(--anim-scale)) cubic-bezier(0.34, 1.56, 0.64, 1) both; }
        .void-win-panel { animation: panel-spring-in calc(0.6s * var(--anim-scale)) cubic-bezier(0.34, 1.56, 0.64, 1) both; }
        .deadlock-panel { animation: panel-shake-in calc(0.5s * var(--anim-scale)) ease-out both; }
        #settings-overlay.show .settings-panel { animation: settings-slide-in 0.28s cubic-bezier(0.4, 0, 0.2, 1) both; }
        .win-overlay { animation: overlay-fade-in calc(0.3s * var(--anim-scale)) ease-out both; }

        /* Item 2/3: Achievement + Leaderboard overlay 開場動畫 */
        .achievement-overlay.show,
        .leaderboard-overlay.show { animation: overlay-fade-in calc(0.22s * var(--anim-scale)) ease-out; }
        .achievement-overlay.show .achievement-panel,
        .leaderboard-overlay.show .leaderboard-panel {
            animation: panel-spring-in calc(0.38s * var(--anim-scale)) cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
        }

        /* Item 2/3: 關閉動畫 */
        @keyframes overlay-fade-out {
            from { opacity: 1; }
            to   { opacity: 0; }
        }
        @keyframes panel-scale-out {
            from { transform: scale(1);   opacity: 1; }
            to   { transform: scale(0.88); opacity: 0; }
        }
        .achievement-overlay.closing,
        .leaderboard-overlay.closing {
            display: flex !important;
            animation: overlay-fade-out calc(0.18s * var(--anim-scale)) ease-in forwards;
        }
        .achievement-overlay.closing .achievement-panel,
        .leaderboard-overlay.closing .leaderboard-panel {
            animation: panel-scale-out calc(0.16s * var(--anim-scale)) ease-in forwards;
        }

        /* Item 4: Settings 關閉動畫 */
        @keyframes settings-slide-out {
            from { transform: translateX(0); }
            to { transform: translateX(100%); }
        }
        #settings-overlay.closing { display: flex !important; }
        #settings-overlay.closing .settings-panel {
            animation: settings-slide-out 0.22s cubic-bezier(0.4, 0, 0.8, 1) forwards;
        }

        /* Item 6: 棄牌堆落入動畫 */
        @keyframes discard-drop-in {
            0%   { transform: translateY(-10px) rotate(-6deg) scale(0.93); opacity: 0.6; }
            60%  { transform: translateY(2px)   rotate(1deg)  scale(1.03); }
            100% { transform: translateY(0)     rotate(0deg)  scale(1);    opacity: 1; }
        }
        .pile.discard-drop-in {
            animation: discard-drop-in calc(0.22s * var(--anim-scale)) ease-out;
        }

        /* Item 7: 取消選牌彈回動畫 */
        @keyframes card-deselect-snap {
            0%   { transform: translateX(40%) rotate(3deg); }
            55%  { transform: translateX(-4%) rotate(-0.5deg); }
            100% { transform: translateX(0)   rotate(0deg); }
        }
        .card.deselecting {
            animation: card-deselect-snap calc(0.13s * var(--anim-scale)) ease-out forwards;
            pointer-events: none;
        }

        /* Item 8: Undo 禁用動畫 */
        @keyframes undo-disable-anim {
            0%   { transform: scale(1.04); }
            55%  { transform: scale(0.86); }
            100% { transform: scale(1); }
        }
        .btn-undo-disabling {
            animation: undo-disable-anim calc(0.18s * var(--anim-scale)) ease-out;
        }

        /* Item 9: 遊戲初始欄位 stagger 出現 */
        @keyframes col-appear {
            from { opacity: 0; transform: translateY(-14px); }
            to   { opacity: 1; transform: translateY(0); }
        }
        .board-init .column {
            opacity: 0;
            animation: col-appear calc(0.28s * var(--anim-scale)) ease-out forwards;
        }
        .board-init .column:nth-child(1) { animation-delay: calc(0s   * var(--anim-scale)); }
        .board-init .column:nth-child(2) { animation-delay: calc(0.06s * var(--anim-scale)); }
        .board-init .column:nth-child(3) { animation-delay: calc(0.12s * var(--anim-scale)); }
        .board-init .column:nth-child(4) { animation-delay: calc(0.18s * var(--anim-scale)); }

        /* Item 10: Checkbox 勾選彈跳 */
        @keyframes check-pop-anim {
            0%   { transform: scale(1); }
            45%  { transform: scale(1.38); }
            100% { transform: scale(1); }
        }
        .setting-check.check-pop {
            animation: check-pop-anim calc(0.22s * var(--anim-scale)) cubic-bezier(0.18, 0.89, 0.32, 1.28);
        }

        /* --- Deck Animations --- */
        @keyframes deck-shuffle {
            0%, 100% { transform: rotate(0deg); }
            25% { transform: rotate(-3deg); }
            75% { transform: rotate(3deg); }
        }

        .deck-shuffle { animation: deck-shuffle calc(0.4s * var(--anim-scale)) ease-in-out; }

        @keyframes deck-num-pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.3); color: var(--gold); }
            100% { transform: scale(1); }
        }

        .deck-num-pulse { display: inline-block; animation: deck-num-pulse calc(0.4s * var(--anim-scale)) ease-out; }

        /* Footer */
        #footer {
            background: rgba(0, 0, 0, 0.95);
            padding: 15px 10px calc(15px + env(safe-area-inset-bottom));
            display: flex;
            justify-content: space-around;
            align-items: center;
            border-top: 1px solid var(--gold);
        }

        .pile {
            width: 55px;
            height: 75px;
            border-radius: 5px;
            border: 1px solid white;
            display: flex;
            justify-content: center;
            align-items: center;
            position: relative;
        }

        #deck-pile {
            background-image: var(--cardback-image, url('../cardback/classic.webp'));
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            box-shadow: 3px 3px 0 #0d47a1;
            cursor: pointer;
            overflow: hidden;
            border: none;
        }
        /* Classic asset has a thin light edge; scale up slightly to hide it. */
        #deck-pile[data-cardback="classic"] {
            background-size: 104% 104%;
        }
        #deck-pile::before,
        #deck-pile::after,
        .cb-preview::before,
        .cb-preview::after {
            content: none;
        }

        /* ── Card Back Variants (Image Assets) ─────────────────────────────── */
        .cb-preview {
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
        }
        .cb-preview-classic { background-image: url('../cardback/classic.webp'); }
        #deck-pile.cb-retro_gold,
        .cb-preview-retro_gold { background-image: url('../cardback/lucky3_retro_classic_gold.webp'); }
        #deck-pile.cb-retro_gold { box-shadow: 3px 3px 0 #171d2a, 0 0 10px rgba(218,165,32,0.2); }

        #deck-pile.cb-nightgold,
        .cb-preview-nightgold { background-image: url('../cardback/nightgold.webp'); }
        #deck-pile.cb-nightgold { box-shadow: 3px 3px 0 #000, 0 0 10px rgba(218,165,32,0.25); }

        #deck-pile.cb-forest,
        .cb-preview-forest { background-image: url('../cardback/forest.webp'); }
        #deck-pile.cb-forest { box-shadow: 3px 3px 0 #020802; }

        #deck-pile.cb-crimson,
        .cb-preview-crimson { background-image: url('../cardback/crimson.webp'); }
        #deck-pile.cb-crimson { box-shadow: 3px 3px 0 #180202; }

        #deck-pile.cb-void,
        .cb-preview-void {
            background-image: url('../cardback/void.webp');
        }
        #deck-pile.cb-void { box-shadow: 3px 3px 0 #000; }

        #deck-pile.cb-lucky,
        .cb-preview-lucky { background-image: url('../cardback/lucky.webp'); }
        #deck-pile.cb-lucky { box-shadow: 3px 3px 0 #020210, 0 0 10px rgba(218,165,32,0.18); }

        #deck-pile.cb-combo5,
        .cb-preview-combo5 { background-image: url('../cardback/combo5.webp'); }
        #deck-pile.cb-combo5 { box-shadow: 3px 3px 0 #0b2a36, 0 0 10px rgba(64,220,255,0.28); }

        #deck-pile.cb-speed18,
        .cb-preview-speed18 { background-image: url('../cardback/speed18.webp'); }
        #deck-pile.cb-speed18 { box-shadow: 3px 3px 0 #0f2d47, 0 0 10px rgba(120,190,255,0.22); }

        #deck-pile.cb-ironwill,
        .cb-preview-ironwill { background-image: url('../cardback/ironwill.webp'); }
        #deck-pile.cb-ironwill { box-shadow: 3px 3px 0 #1b1e2a; }

        #deck-pile.cb-suitcollector,
        .cb-preview-suitcollector { background-image: url('../cardback/suitcollector.webp'); }
        #deck-pile.cb-suitcollector { box-shadow: 3px 3px 0 #1b2a33, 0 0 10px rgba(218,165,32,0.2); }

        #deck-pile.cb-luckydraw,
        .cb-preview-luckydraw { background-image: url('../cardback/luckydraw.webp'); }
        #deck-pile.cb-luckydraw { box-shadow: 3px 3px 0 #121d3a, 0 0 10px rgba(218,165,32,0.25); }

        #deck-pile.cb-fullsweep,
        .cb-preview-fullsweep { background-image: url('../cardback/fullsweep.webp'); }
        #deck-pile.cb-fullsweep { box-shadow: 3px 3px 0 #143020; }

        #deck-pile.cb-dailyregular,
        .cb-preview-dailyregular { background-image: url('../cardback/dailyregular.webp'); }
        #deck-pile.cb-dailyregular { box-shadow: 3px 3px 0 #16314a, 0 0 10px rgba(218,165,32,0.16); }

        #deck-pile.cb-chainreaction,
        .cb-preview-chainreaction { background-image: url('../cardback/chainreaction.webp'); }
        #deck-pile.cb-chainreaction { box-shadow: 3px 3px 0 #1a1938, 0 0 10px rgba(120,190,255,0.2); }

        /* ── Extreme Challenge cardbacks ──────────────────────────────────── */
        #deck-pile.cb-shilian,
        .cb-preview-shilian { background-image: url('../cardback/shilian.webp'); }
        #deck-pile.cb-shilian { box-shadow: 3px 3px 0 #0a0a0a, 0 0 10px rgba(192,192,192,0.18); }

        #deck-pile.cb-tianzhu,
        .cb-preview-tianzhu { background-image: url('../cardback/tianzhu.webp'); }
        #deck-pile.cb-tianzhu { box-shadow: 3px 3px 0 #0a1a2a, 0 0 10px rgba(128,180,220,0.22); }

        #deck-pile.cb-xingbao,
        .cb-preview-xingbao { background-image: url('../cardback/xingbao.webp'); }
        #deck-pile.cb-xingbao { box-shadow: 3px 3px 0 #1a0530, 0 0 10px rgba(255,170,68,0.32); }

        #deck-pile.cb-lunhui,
        .cb-preview-lunhui { background-image: url('../cardback/lunhui.webp'); }
        #deck-pile.cb-lunhui { box-shadow: 3px 3px 0 #050f08, 0 0 10px rgba(136,221,170,0.22); }

        #deck-pile.cb-jufeng,
        .cb-preview-jufeng { background-image: url('../cardback/jufeng.webp'); }
        #deck-pile.cb-jufeng { box-shadow: 3px 3px 0 #050f15, 0 0 10px rgba(170,238,221,0.22); }

        #deck-pile.cb-yongheng,
        .cb-preview-yongheng { background-image: url('../cardback/yongheng.webp'); }
        #deck-pile.cb-yongheng { box-shadow: 3px 3px 0 #1a1005, 0 0 10px rgba(255,215,0,0.32); }

        /* ── Card Back Collection Grid UI ─── */
        .cb-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 14px 8px;
            padding: 12px 4px 4px;
        }
        .cb-loading {
            grid-column: 1 / -1;
            text-align: center;
            font-size: 0.74rem;
            color: rgba(255,255,255,0.72);
            padding: 12px 0;
        }
        .cb-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 5px;
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
        }
        .cb-item.cb-locked { cursor: default; }
        .cb-preview {
            width: 44px;
            height: 60px;
            border-radius: 5px;
            position: relative;
            overflow: hidden;
            border: 2px solid transparent;
            box-sizing: border-box;
            transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
        }
        .cb-item:not(.cb-locked) .cb-preview:active { transform: scale(0.92); }
        .cb-item.cb-selected .cb-preview {
            border-color: var(--gold);
            box-shadow: 0 0 8px rgba(218,165,32,0.55);
        }
        .cb-lock-icon {
            position: absolute;
            inset: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            background: rgba(0,0,0,0.55);
            color: rgba(255,255,255,0.65);
            z-index: 1;
        }
        .cb-selected-mark {
            position: absolute;
            top: 2px;
            right: 4px;
            color: var(--gold);
            font-size: 11px;
            font-weight: bold;
            z-index: 1;
        }
        .cb-name {
            font-size: 0.72rem;
            color: rgba(255,255,255,0.85);
            text-align: center;
        }
        .cb-hint {
            font-size: 0.6rem;
            color: rgba(255,255,255,0.38);
            text-align: center;
            line-height: 1.3;
            font-family: system-ui, -apple-system, sans-serif;
        }

        #discard-pile {
            background: rgba(255, 255, 255, 0.05);
            border: 1px dashed var(--gold);
        }

        @keyframes discard-receive {
            0%   { transform: scale(1); }
            38%  { transform: scale(1.13); box-shadow: 3px 3px 0 rgba(255,215,0,0.5), 0 0 12px rgba(255,215,0,0.25); }
            100% { transform: scale(1);   box-shadow: 3px 3px 0 rgba(255,215,0,0.4); }
        }
        #discard-pile.discard-receive {
            animation: discard-receive 0.28s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
        }

        .has-cards {
            background: white !important;
            color: black;
            border: 1px solid #999 !important;
        }

        .btn-main {
            background: #2e7d32;
            color: white;
            border: none;
            padding: 14px 28px;
            border-radius: 50px;
            font-weight: bold;
            box-shadow: 0 4px #000;
            cursor: pointer;
        }

        #btn-undo {
            background: #455a64;
            width: 50px;
            height: 50px;
            padding: 0;
            border-radius: 50%;
            box-shadow: 0 4px #263238;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        #btn-undo svg {
            width: 24px;
            height: 24px;
            fill: white;
        }

        #btn-undo:disabled {
            opacity: 0.2;
            box-shadow: none;
            cursor: not-allowed;
        }

        #btn-undo.undo-ready {
            animation: undo-ready-pop 0.45s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
        }

        @keyframes undo-ready-pop {
            0%   { transform: scale(0.85); }
            60%  { transform: scale(1.18); box-shadow: 0 0 0 5px rgba(255,215,0,0.3); }
            100% { transform: scale(1);   box-shadow: none; }
        }

        /* ── Undo 按下動畫 ── */
        #btn-undo.undo-spinning {
            animation: undo-btn-squish 0.38s cubic-bezier(0.4, 0, 0.2, 1) forwards;
        }
        #btn-undo.undo-spinning svg {
            animation: undo-arrow-rewind 0.38s cubic-bezier(0.4, 0, 0.2, 1) forwards;
        }
        @keyframes undo-btn-squish {
            0%   { transform: scale(1); }
            28%  { transform: scale(0.80); }
            65%  { transform: scale(1.07); }
            100% { transform: scale(1); }
        }
        @keyframes undo-arrow-rewind {
            0%   { transform: rotate(0deg); }
            100% { transform: rotate(-360deg); }
        }

        /* ── Undo 後牌落回動畫 ── */
        @keyframes undo-card-return {
            0%   { opacity: 0; transform: translateY(-14px) scale(0.86); }
            60%  { transform: translateY(3px) scale(1.05); opacity: 1; }
            100% { transform: translateY(0) scale(1); opacity: 1; }
        }
        .undo-card-return {
            animation: undo-card-return 0.32s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
        }

        /* ── Deal undo：牌堆數字 bump ── */
        @keyframes deck-num-bump {
            0%   { transform: scale(1);    color: inherit; }
            40%  { transform: scale(1.5);  color: var(--gold); }
            100% { transform: scale(1);    color: inherit; }
        }
        #deck-num.undo-bump {
            animation: deck-num-bump 0.32s ease-out forwards;
            display: inline-block;
        }

        .btn-main:active {
            transform: translateY(2px);
            box-shadow: 0 2px #1b5e20;
        }

        .flying {
            position: fixed;
            z-index: 9999;
            pointer-events: none;
            /* 只 transition 位置屬性，把 transform/filter 留給 mii-peek 等 animation 控制 */
            transition:
                left calc(0.5s * var(--anim-scale)) cubic-bezier(0.4, 0, 0.2, 1),
                top  calc(0.5s * var(--anim-scale)) cubic-bezier(0.4, 0, 0.2, 1);
        }

        .card.face-down {
            background: linear-gradient(135deg, #0d47a1 0%, #1565c0 45%, #1e88e5 100%);
            border: none;
            color: transparent;
            overflow: hidden;
        }

        .card.face-down::before {
            content: '';
            position: absolute;
            inset: 6px;
            border-radius: 4px;
            border: 2px solid rgba(255, 255, 255, 0.75);
            background:
                radial-gradient(circle at 25% 25%, rgba(255, 255, 255, 0.35) 0 2px, transparent 3px),
                radial-gradient(circle at 75% 75%, rgba(255, 255, 255, 0.35) 0 2px, transparent 3px),
                repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.16) 0 6px, rgba(255, 255, 255, 0.05) 6px 12px);
        }

        .card.face-down::after {
            content: 'LUCKY 3';
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            font-size: 0.62rem;
            font-weight: 900;
            letter-spacing: 1px;
            color: rgba(255, 255, 255, 0.9);
        }

        .card.face-down.use-cardback {
            background-image: var(--cardback-image, url('../cardback/classic.webp'));
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            border: none;
        }

        .card.face-down.use-cardback::before,
        .card.face-down.use-cardback::after {
            content: none;
        }

        .card.flipping {
            animation: card-flip calc(0.32s * var(--anim-scale)) ease-in-out;
            transform-style: preserve-3d;
        }

        @keyframes card-flip {
            0%   { transform: perspective(700px) rotateY(0deg); }
            48%  { transform: perspective(700px) rotateY(88deg); }
            52%  { transform: perspective(700px) rotateY(92deg); }
            100% { transform: perspective(700px) rotateY(0deg); }
        }

        @keyframes card-deal-land {
            0%   { transform: scale(1) translateY(0); filter: brightness(1.1); }
            30%  { transform: scaleY(0.94) translateY(3px); }
            65%  { transform: scaleY(1.02) translateY(-1px); }
            100% { transform: scale(1) translateY(0); filter: brightness(1); }
        }

        .flying.mii-peek {
            animation:
                mii-peek-rise    calc(0.22s * var(--anim-scale)) ease-out forwards,
                mii-peek-breathe calc(0.9s  * var(--anim-scale)) ease-in-out calc(0.24s * var(--anim-scale)) infinite,
                mii-glow-pulse   calc(1.1s  * var(--anim-scale)) ease-in-out calc(0.24s * var(--anim-scale)) infinite;
        }

        .magic-moment-fly {
            filter: drop-shadow(0 0 10px rgba(255, 216, 107, 0.55));
        }

        .magic-moment-banner {
            position: fixed;
            transform: translate(-50%, -8px);
            padding: 10px 14px;
            border-radius: 10px;
            background: rgba(8, 10, 16, 0.88);
            border: 1px solid rgba(255, 215, 0, 0.45);
            color: #f6e7ba;
            text-align: center;
            z-index: 10019;
            opacity: 0;
            transition-property: opacity, transform;
            transition-timing-function: ease;
            pointer-events: none;
            box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
            font-weight: 700;
            letter-spacing: 0;
            max-width: min(86vw, 330px);
            line-height: 1.2;
        }

        .magic-moment-banner.show {
            opacity: 1;
            transform: translate(-50%, 0);
        }

        .magic-moment-kicker {
            font-size: 12px;
            opacity: 0.92;
        }

        .magic-moment-text {
            font-size: 16px;
            margin-top: 4px;
        }

        .magic-moment-text strong {
            color: #ffd86b;
        }

        .card.mii-land-pop {
            animation: mii-land-pop calc(0.50s * var(--anim-scale)) cubic-bezier(0.2, 0.8, 0.25, 1.15);
            transform-origin: 50% 85%;
        }

        @keyframes mii-land-pop {
            0%   { transform: translateY(-18px) scale(1.14); filter: brightness(1.4); }
            40%  { transform: translateY(5px)   scale(0.94); filter: brightness(1.0); }
            65%  { transform: translateY(-4px)  scale(1.03); }
            82%  { transform: translateY(2px)   scale(0.99); }
            100% { transform: translateY(0)     scale(1);    filter: brightness(1); }
        }

        @keyframes mii-peek-rise {
            from { transform: translateY(0) scale(1); }
            to   { transform: translateY(-14px) scale(1.08) rotate(-2.5deg); }
        }

        @keyframes mii-peek-breathe {
            0%   { transform: translateY(-14px) scale(1.08) rotate(-2.5deg); }
            30%  { transform: translateY(-18px) scale(1.11) rotate(2deg); }
            60%  { transform: translateY(-11px) scale(1.07) rotate(-1.5deg); }
            80%  { transform: translateY(-16px) scale(1.10) rotate(1deg); }
            100% { transform: translateY(-14px) scale(1.08) rotate(-2.5deg); }
        }

        @keyframes mii-glow-pulse {
            0%   { filter: drop-shadow(0 0 10px var(--mii-glow-color)); }
            40%  { filter: drop-shadow(0 0 28px var(--mii-glow-color)) drop-shadow(0 0 8px rgba(255, 255, 255, 0.25)); }
            100% { filter: drop-shadow(0 0 10px var(--mii-glow-color)); }
        }

        .mii-text {
            position: absolute;
            top: -28px;
            left: 50%;
            transform: translateX(-50%);
            white-space: nowrap;
            font-size: 0.82rem;
            font-weight: 900;
            letter-spacing: 0.5px;
            color: var(--mii-text-color, #fff);
            background: var(--mii-text-bg, rgba(16, 18, 20, 0.88));
            border: 1px solid var(--mii-text-border, rgba(255, 255, 255, 0.4));
            border-radius: 999px;
            padding: 4px 10px;
            box-shadow: 0 0 10px var(--mii-text-border, rgba(255, 255, 255, 0.3));
            animation: mii-text-pop calc(1.4s * var(--anim-scale)) ease-out forwards;
            z-index: 1003;
        }

        @keyframes mii-text-pop {
            0% {
                transform: translate(-50%, 8px) scale(0.9);
                opacity: 0;
            }

            18% {
                transform: translate(-50%, 0) scale(1.05);
                opacity: 1;
            }

            70% {
                transform: translate(-50%, -2px) scale(1.02);
                opacity: 1;
            }

            100% {
                transform: translate(-50%, -14px) scale(1);
                opacity: 0;
            }
        }

        .big-msg {
            position: fixed;
            top: 40%;
            left: 50%;
            transform: translate(-50%, -50%);
            font-size: 3rem;
            color: var(--gold);
            text-align: center;
            z-index: 10001;
        }

        .win-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.72);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 10002;
            padding: 20px;
        }

        .win-panel {
            width: min(420px, 92vw);
            background: linear-gradient(180deg, #123a1f, #0a2414);
            border: 2px solid var(--gold);
            border-radius: 14px;
            box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
            padding: 20px 18px;
            text-align: center;
        }

        .shimmer-text {
            background: linear-gradient(90deg, #ffd700 0%, #fff8cc 40%, #ffd700 60%, #ffaa00 100%);
            background-size: 200% 100%;
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            animation: shimmer-sweep 2.4s linear infinite;
        }

        @keyframes shimmer-sweep {
            0%   { background-position: 200% center; }
            100% { background-position: -200% center; }
        }

        .win-title {
            margin: 0;
            color: var(--gold);
            font-size: 1.8rem;
            letter-spacing: 1px;
        }

        .win-subtitle {
            margin: 8px 0 14px;
            font-size: 0.95rem;
            opacity: 0.9;
        }

        .win-stats {
            text-align: left;
            background: rgba(255, 255, 255, 0.07);
            border-radius: 10px;
            padding: 12px;
            margin-bottom: 14px;
        }

        .win-stat-row {
            display: flex;
            justify-content: space-between;
            font-size: 1rem;
            padding: 6px 0;
            border-bottom: 1px solid rgba(255, 255, 255, 0.14);
        }

        .win-stat-row:last-child {
            border-bottom: none;
        }

        .win-play-again {
            width: 100%;
            border: none;
            border-radius: 12px;
            background: var(--gold);
            color: #1b1b1b;
            font-weight: 900;
            font-size: 1.05rem;
            padding: 12px 14px;
            cursor: pointer;
            min-height: 46px;
        }

        .win-best {
            margin: 0 0 12px;
            padding: 10px;
            border-radius: 10px;
            font-size: 0.95rem;
            background: rgba(255, 215, 0, 0.18);
            border: 1px solid rgba(255, 215, 0, 0.45);
            color: #fff8cc;
        }

        .win-fortune {
            margin: 0 0 12px;
            padding: 10px;
            border-radius: 10px;
            font-size: 0.93rem;
            line-height: 1.45;
            background: rgba(129, 199, 132, 0.18);
            border: 1px solid rgba(165, 214, 167, 0.65);
            color: #e8ffe8;
        }

        .win-mystery {
            margin: 4px 0 10px;
            border-radius: 8px;
            background: rgba(255,255,255,0.05);
            border: 1px solid rgba(255,215,0,0.15);
        }
        .win-mystery-toggle {
            display: block;
            cursor: pointer;
            padding: 8px 12px;
            font-size: 0.78rem;
            color: rgba(255,215,0,0.55);
            text-align: left;
            user-select: none;
            list-style: none;
            transition: color 0.15s;
        }
        .win-mystery-toggle::-webkit-details-marker { display: none; }
        .win-mystery[open] .win-mystery-toggle { color: rgba(255,215,0,0.85); }
        .win-mystery-body {
            padding: 0 12px 10px;
            font-size: 0.78rem;
            line-height: 1.65;
            color: rgba(255,255,255,0.7);
            text-align: left;
            margin: 0;
        }

        .about-section {
            margin-bottom: 20px;
        }
        .about-section-title {
            font-size: 0.82rem;
            font-weight: 700;
            color: var(--gold);
            margin-bottom: 7px;
            letter-spacing: 0.4px;
            text-transform: uppercase;
        }
        .about-section-body {
            font-size: 0.83rem;
            line-height: 1.7;
            color: rgba(255,255,255,0.78);
            margin: 0;
        }
        .about-version {
            font-size: 0.72rem;
            color: rgba(255,255,255,0.28);
            margin-top: 24px;
            text-align: center;
        }

        .void-win-panel {
            width: min(430px, 92vw);
            background: radial-gradient(circle at top, #1f2a56 0%, #0d1433 55%, #070c21 100%);
            border: 2px solid #8ec7ff;
            border-radius: 16px;
            box-shadow: 0 20px 42px rgba(0, 0, 0, 0.6);
            padding: 20px 18px;
            text-align: center;
        }

        .void-win-title {
            margin: 0;
            color: #9dd3ff;
            font-size: 1.76rem;
            letter-spacing: 1px;
        }

        .void-win-subtitle {
            margin: 8px 0 14px;
            font-size: 0.95rem;
            line-height: 1.4;
            color: #d7ecff;
        }

        .void-win-badge {
            margin: 0 0 12px;
            padding: 10px;
            border-radius: 10px;
            border: 1px solid rgba(142, 199, 255, 0.7);
            background: rgba(142, 199, 255, 0.18);
            color: #eaf6ff;
            font-weight: 800;
        }

        .deadlock-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.78);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 10003;
            padding: 20px;
        }

        .deadlock-panel {
            width: min(430px, 92vw);
            background: linear-gradient(180deg, #3a1111, #240a0a);
            border: 2px solid #ff6b6b;
            border-radius: 14px;
            box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
            padding: 18px;
            text-align: center;
        }

        .deadlock-title {
            margin: 0;
            color: #ffd2d2;
            font-size: 1.35rem;
            letter-spacing: 0.5px;
        }

        .deadlock-text {
            margin: 10px 0 14px;
            font-size: 0.96rem;
            line-height: 1.5;
            color: #ffe6e6;
        }

        .deadlock-actions {
            display: flex;
            gap: 10px;
        }

        .deadlock-btn {
            flex: 1;
            border: none;
            border-radius: 10px;
            min-height: 44px;
            font-weight: 800;
            cursor: pointer;
            font-size: 0.95rem;
        }

        .deadlock-btn.undo {
            background: #78909c;
            color: #102027;
        }

        .deadlock-btn.new {
            background: #ffd54f;
            color: #3e2723;
        }

        .deadlock-btn:disabled {
            opacity: 0.45;
            cursor: not-allowed;
        }

        .rewind-overlay {
            position: fixed;
            inset: 0;
            z-index: 10002;
            pointer-events: none;
            opacity: 0;
            background:
                radial-gradient(120% 90% at 50% 20%, rgba(255, 218, 121, 0.16), rgba(0, 0, 0, 0.66)),
                linear-gradient(180deg, rgba(12, 14, 19, 0.2), rgba(6, 7, 10, 0.78));
            backdrop-filter: blur(2px);
            transition: opacity calc(0.22s * var(--anim-scale)) ease;
        }
        .rewind-overlay::before,
        .rewind-overlay::after {
            content: '';
            position: absolute;
            inset: 0;
            pointer-events: none;
        }
        .rewind-overlay::before {
            background:
                repeating-linear-gradient(
                    0deg,
                    rgba(255, 246, 210, 0.065) 0px,
                    rgba(255, 246, 210, 0.065) 1px,
                    transparent 1px,
                    transparent 4px
                );
            opacity: 0.35;
            animation: rewind-scanline calc(0.56s * var(--anim-scale)) linear infinite;
        }
        .rewind-overlay::after {
            background:
                radial-gradient(circle at 15% 22%, rgba(255, 224, 145, 0.2) 0 1.5px, transparent 2px),
                radial-gradient(circle at 72% 40%, rgba(255, 224, 145, 0.18) 0 1.4px, transparent 2px),
                radial-gradient(circle at 43% 74%, rgba(255, 224, 145, 0.15) 0 1.3px, transparent 2px);
            animation: rewind-noise-drift calc(0.85s * var(--anim-scale)) steps(2) infinite;
            mix-blend-mode: screen;
            opacity: 0.24;
        }

        .rewind-overlay.show {
            opacity: 1;
            animation: rewind-overlay-breath calc(1.2s * var(--anim-scale)) ease-in-out infinite;
        }

        @keyframes rewind-overlay-breath {
            0%, 100% { filter: saturate(1); }
            50% { filter: saturate(1.18); }
        }
        @keyframes rewind-scanline {
            from { transform: translateY(0); }
            to { transform: translateY(4px); }
        }
        @keyframes rewind-noise-drift {
            0% { transform: translate(0, 0); }
            50% { transform: translate(1px, -1px); }
            100% { transform: translate(-1px, 1px); }
        }
        .rewind-trail {
            position: fixed;
            height: 2px;
            border-radius: 999px;
            transform-origin: left center;
            background: linear-gradient(90deg, rgba(255, 230, 165, 0.65) 0%, rgba(255, 230, 165, 0.05) 100%);
            box-shadow: 0 0 10px rgba(255, 222, 145, 0.38);
            z-index: 10003;
            pointer-events: none;
            animation: rewind-trail-fade calc(0.18s * var(--anim-scale)) ease-out forwards;
        }
        @keyframes rewind-trail-fade {
            from { opacity: 0.78; }
            to { opacity: 0; }
        }
        .rewind-lock-tag {
            position: fixed;
            transform: translate(-50%, -100%);
            z-index: 10004;
            pointer-events: none;
            font-size: 0.68rem;
            font-weight: 800;
            letter-spacing: 0.3px;
            color: #f9ffec;
            background: linear-gradient(180deg, rgba(30, 124, 88, 0.92), rgba(19, 88, 64, 0.9));
            border: 1px solid rgba(179, 255, 221, 0.74);
            border-radius: 999px;
            padding: 4px 10px;
            box-shadow: 0 0 0 2px rgba(83, 221, 160, 0.25), 0 0 18px rgba(76, 210, 150, 0.38);
            animation: rewind-lock-in calc(0.24s * var(--anim-scale)) ease-out;
        }
        @keyframes rewind-lock-in {
            from { opacity: 0; transform: translate(-50%, -80%) scale(0.86); }
            to { opacity: 1; transform: translate(-50%, -100%) scale(1); }
        }

        /* ── 選牌加總顯示 ── */
        #sum-bar {
            position: fixed;
            left: 50%;
            bottom: calc(90px + env(safe-area-inset-bottom));
            transform: translateX(-50%);
            background: rgba(20, 20, 20, 0.88);
            border: 1px solid rgba(255, 215, 0, 0.45);
            border-radius: 999px;
            padding: 5px 18px;
            font-size: 1rem;
            font-weight: 700;
            color: #fff9d0;
            letter-spacing: 0.04em;
            z-index: 500;
            pointer-events: none;
            white-space: nowrap;
            transition: opacity 0.15s ease, transform 0.15s ease;
        }
        #sum-bar.hidden {
            opacity: 0;
            transform: translateX(-50%) translateY(6px);
        }
        #sum-bar .sum-total {
            color: #ffd700;
        }
        #sum-bar .sum-ok {
            color: #7eff9a;
        }
        #sum-bar .sum-fail {
            color: #ff7e7e;
        }

        .need-three-tip {
            position: fixed;
            left: 50%;
            bottom: calc(96px + env(safe-area-inset-bottom));
            transform: translateX(-50%);
            background: rgba(20, 20, 20, 0.9);
            color: #fff9d0;
            border: 1px solid rgba(255, 215, 0, 0.55);
            border-radius: 999px;
            padding: 8px 14px;
            font-size: 0.9rem;
            font-weight: 800;
            z-index: 10004;
            animation: need-three-fade calc(1s * var(--anim-scale)) ease-out forwards;
            pointer-events: none;
        }

        .need-three-tip.rule-hint {
            max-width: min(360px, calc(100vw - 24px));
            white-space: pre-line;
            text-align: left;
            line-height: 1.45;
            border-color: rgba(255, 183, 77, 0.9);
            color: #fff6dd;
        }

        .settings-overlay {
            position: fixed;
            inset: 0;
            background: #0c1e13;
            z-index: 10005;
            display: none;
            overflow: hidden;
        }

        .settings-overlay.show {
            display: flex;
        }

        .settings-panel {
            width: 100%;
            height: 100%;
            max-height: none;
            background: #0c1e13;
            border: none;
            border-radius: 0;
            padding: 0;
            box-shadow: none;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            flex-shrink: 0;
        }

        .settings-title {
            margin: 0 0 12px;
            font-size: 1.2rem;
            color: var(--gold);
        }

        .settings-topbar {
            display: flex;
            align-items: center;
            gap: 12px;
            height: 56px;
            padding: 0 16px;
            padding-top: env(safe-area-inset-top, 0);
            flex-shrink: 0;
            background: #0f2318;
            border-bottom: 1px solid rgba(255, 215, 0, 0.18);
        }

        .settings-back-btn {
            width: 44px;
            height: 44px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: none;
            border: none;
            color: var(--gold, #ffd54f);
            cursor: pointer;
            flex-shrink: 0;
            border-radius: 50%;
            margin-left: -8px;
        }

        .settings-topbar-title {
            font-size: 1.1rem;
            font-weight: 800;
            color: #fff;
            letter-spacing: 0.3px;
        }

        .settings-body {
            flex: 1;
            overflow-y: auto;
            padding: 16px;
            -webkit-overflow-scrolling: touch;
            padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
        }

        .setting-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 12px;
            padding: 10px 0;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .setting-row:last-of-type {
            border-bottom: none;
        }

        .setting-label {
            font-size: 0.95rem;
            font-weight: 700;
        }

        .setting-value {
            font-size: 0.88rem;
            opacity: 0.8;
        }

        .setting-control {
            font-size: 0.92rem;
            padding: 6px 8px;
            border-radius: 8px;
            border: 1px solid rgba(255, 255, 255, 0.35);
            background: rgba(255, 255, 255, 0.08);
            color: #fff;
        }

        .setting-check {
            width: 20px;
            height: 20px;
            accent-color: #ffd54f;
        }
        .setting-row.range-row {
            flex-direction: column;
            align-items: stretch;
            gap: 8px;
        }
        .setting-label-row {
            display: flex;
            align-items: baseline;
            justify-content: space-between;
            gap: 12px;
            width: 100%;
        }
        .setting-inline-value {
            font-size: 0.82rem;
            color: rgba(255, 255, 255, 0.7);
            font-variant-numeric: tabular-nums;
        }
        .setting-control-range {
            width: 100%;
            padding: 0;
            border: none;
            background: transparent;
            accent-color: #ffd54f;
        }
        .visual-preview-title {
            font-size: 0.78rem;
            letter-spacing: 0.5px;
            color: rgba(255, 215, 0, 0.75);
            margin-bottom: 10px;
            text-transform: uppercase;
            font-weight: 700;
        }
        .visual-preview-grid {
            display: flex;
            justify-content: center;
            gap: 16px;
            margin-bottom: 10px;
        }
        .visual-preview-card {
            width: 70px;
            height: calc(70px * 1.42);
            max-width: 70px;
            max-height: calc(70px * 1.42);
            margin-bottom: 0;
            flex-shrink: 0;
            box-shadow: 0 3px 8px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.8);
        }

        .settings-close {
            margin-top: 14px;
            width: 100%;
            min-height: 44px;
            border: none;
            border-radius: 10px;
            background: #ffd54f;
            color: #1b1b1b;
            font-weight: 900;
            cursor: pointer;
        }
        /* pause-overlay 專屬：恢復半透明 backdrop + 置中浮動 panel */
        #pause-overlay.settings-overlay {
            background: rgba(0, 0, 0, 0.72);
            align-items: center;
            justify-content: center;
            padding: 18px;
            overflow-y: auto;
        }
        .pause-panel {
            width: min(360px, calc(100vw - 40px));
            height: auto;
            max-height: 80dvh;
            flex-shrink: 0;
            border: 2px solid var(--gold);
            border-radius: 14px;
            padding: 16px;
            box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
            background: linear-gradient(180deg, #143021, #0d2217);
        }
        .pause-actions {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .settings-achievement {
            margin-top: 10px;
            width: 100%;
            min-height: 42px;
            border: 1px solid rgba(255, 255, 255, 0.35);
            border-radius: 10px;
            background: rgba(255, 255, 255, 0.08);
            color: #fff;
            font-weight: 800;
            cursor: pointer;
        }

        .settings-daily {
            margin-top: 10px;
            width: 100%;
            min-height: 42px;
            border: 1px solid rgba(147, 214, 255, 0.55);
            border-radius: 10px;
            background: rgba(42, 102, 166, 0.35);
            color: #d8eeff;
            font-weight: 900;
            cursor: pointer;
        }

        .win-daily {
            margin: 0 0 12px;
            padding: 9px 10px;
            border-radius: 10px;
            font-size: 0.9rem;
            line-height: 1.35;
            background: rgba(103, 58, 183, 0.2);
            border: 1px solid rgba(179, 136, 255, 0.55);
            color: #efe2ff;
        }

        .settings-restart {
            margin-top: 10px;
            width: 100%;
            min-height: 44px;
            border: none;
            border-radius: 10px;
            background: #c62828;
            color: #fff;
            font-weight: 900;
            cursor: pointer;
        }

        .settings-secondary {
            margin-top: 10px;
            width: 100%;
            min-height: 42px;
            border: 1px solid rgba(255, 255, 255, 0.35);
            border-radius: 10px;
            background: rgba(255, 255, 255, 0.08);
            color: #fff;
            font-weight: 800;
            cursor: pointer;
        }

        /* ── 設定分區 ── */
        .settings-section {
            display: flex;
            align-items: center;
            gap: 8px;
            margin: 12px 0 4px;
        }
        .settings-section-label {
            font-size: 0.7rem;
            font-weight: 700;
            letter-spacing: 1px;
            color: rgba(255,215,0,0.55);
            text-transform: uppercase;
            white-space: nowrap;
        }
        .settings-section-line {
            flex: 1;
            height: 1px;
            background: rgba(255,215,0,0.18);
        }

        /* ── 音效橫排 ── */
        .settings-audio-row {
            display: flex;
            justify-content: space-around;
            align-items: center;
            padding: 8px 0 4px;
            border-bottom: 1px solid rgba(255,255,255,0.1);
        }
        .settings-audio-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 5px;
            flex: 1;
        }
        .settings-audio-icon { font-size: 20px; line-height: 1; }
        .settings-audio-label {
            font-size: 0.68rem;
            color: rgba(255,255,255,0.6);
            text-align: center;
        }

        /* ── 並排按鈕 ── */
        .settings-btn-row {
            display: flex;
            gap: 8px;
            margin-top: 8px;
        }
        .settings-btn-row .settings-achievement {
            margin-top: 0;
            flex: 1;
            font-size: 0.82rem;
        }

        /* ── 教學+版本同行 ── */
        .settings-footer-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-top: 8px;
            padding-top: 8px;
            border-top: 1px solid rgba(255,255,255,0.08);
        }
        .settings-footer-row .settings-secondary {
            margin-top: 0;
            width: auto;
            flex: 1;
            font-size: 0.8rem;
            min-height: 36px;
            padding: 0 10px;
        }
        .settings-version-inline {
            font-size: 0.72rem;
            color: rgba(255,255,255,0.3);
            padding-left: 10px;
            white-space: nowrap;
        }

        .restart-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.72);
            z-index: 10006;
            display: none;
            align-items: center;
            justify-content: center;
            padding: 18px;
        }

        .restart-overlay.show {
            display: flex;
        }

        .restart-panel {
            width: min(390px, 90vw);
            background: linear-gradient(180deg, #2e1111, #1c0909);
            border: 2px solid #ff6b6b;
            border-radius: 14px;
            padding: 16px;
            box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
            text-align: center;
        }

        .restart-title {
            margin: 0;
            color: #ffd4d4;
            font-size: 1.12rem;
        }

        .restart-text {
            margin: 10px 0 14px;
            color: #ffeaea;
            font-size: 0.94rem;
            line-height: 1.45;
        }

        .restart-actions {
            display: flex;
            gap: 10px;
        }

        .restart-btn {
            flex: 1;
            min-height: 42px;
            border: none;
            border-radius: 10px;
            font-weight: 900;
            cursor: pointer;
        }

        .restart-btn.cancel {
            background: #607d8b;
            color: #fff;
        }

        .restart-btn.confirm {
            background: #d32f2f;
            color: #fff;
        }

        .tutorial-overlay {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: min(440px, calc(100vw - 22px));
            z-index: 10007;
            display: none;
            pointer-events: none;
        }

        .tutorial-overlay.show {
            display: block;
        }

        .tutorial-panel {
            pointer-events: auto;
            background: linear-gradient(180deg, rgba(12, 35, 25, 0.96), rgba(7, 21, 15, 0.97));
            border: 2px solid var(--gold);
            border-radius: 12px;
            box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
            padding: 12px;
        }

        .tutorial-title {
            margin: 0;
            font-size: 1.02rem;
            color: #ffe066;
            letter-spacing: 0.3px;
        }

        .tutorial-body {
            margin: 8px 0 10px;
            font-size: 0.92rem;
            line-height: 1.45;
            color: #f6fff8;
        }

        .tutorial-status {
            margin: 0 0 10px;
            font-size: 0.85rem;
            color: #d8f5de;
            opacity: 0.92;
        }

        .tutorial-actions {
            display: flex;
            gap: 8px;
        }

        .tutorial-btn {
            flex: 1;
            min-height: 38px;
            border: none;
            font-family: system-ui, -apple-system, "PingFang TC", sans-serif;
            border-radius: 9px;
            font-weight: 800;
            cursor: pointer;
            font-size: 0.9rem;
        }

        .tutorial-btn.primary {
            background: #ffd54f;
            color: #1f1f1f;
        }

        .tutorial-btn.secondary {
            background: #546e7a;
            color: #fff;
        }

        .achievement-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.78);
            z-index: 10008;
            display: none;
            align-items: center;
            justify-content: center;
            padding: 18px;
        }

        .achievement-overlay.show {
            display: flex;
        }

        .achievement-panel {
            width: min(440px, 92vw);
            max-height: 78vh;
            overflow: auto;
            background: linear-gradient(180deg, #112c1d, #0a1f14);
            border: 2px solid #fdd835;
            border-radius: 14px;
            padding: 14px;
            box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
        }

        .achievement-title {
            margin: 0 0 10px;
            color: #ffe066;
            font-size: 1.2rem;
        }

        .achievement-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 8px;
            margin-bottom: 12px;
        }

        .achievement-stat {
            background: rgba(255, 255, 255, 0.08);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 10px;
            padding: 8px;
        }

        .achievement-stat-label {
            font-size: 0.78rem;
            opacity: 0.9;
        }

        .achievement-stat-value {
            margin-top: 2px;
            font-size: 1.05rem;
            font-weight: 900;
        }

        .achievement-badges {
            display: grid;
            grid-template-columns: 1fr;
            gap: 8px;
            margin-bottom: 12px;
        }

        .achievement-badge {
            border-radius: 10px;
            padding: 9px 10px;
            border: 1px dashed rgba(255, 255, 255, 0.35);
            background: rgba(255, 255, 255, 0.06);
            font-size: 0.88rem;
        }

        .badge-header {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 2px;
        }

        .badge-icon {
            font-size: 1.8rem;
            line-height: 1;
            flex-shrink: 0;
            filter: grayscale(0.4);
        }

        .achievement-badge.unlocked .badge-icon {
            filter: grayscale(0) drop-shadow(0 0 6px rgba(255, 215, 64, 0.7));
        }

        .badge-info {
            display: flex;
            flex-direction: column;
            gap: 2px;
        }

        .badge-title {
            font-size: 0.9rem;
        }

        .badge-text {
            font-size: 0.8rem;
            opacity: 0.8;
        }

        .achievement-badge.unlocked {
            border-style: solid;
            border-color: rgba(255, 215, 64, 0.8);
            background: rgba(255, 215, 64, 0.18);
            color: #fff6c2;
        }

        .achievement-progress {
            margin-top: 7px;
            width: 100%;
            height: 7px;
            border-radius: 999px;
            background: rgba(255, 255, 255, 0.18);
            overflow: hidden;
        }

        .achievement-progress-fill {
            height: 100%;
            border-radius: 999px;
            background: linear-gradient(90deg, #8bc34a, #ffeb3b);
            transition: width 260ms ease;
        }

        .achievement-toast-wrap {
            position: fixed;
            top: calc(env(safe-area-inset-top) + 12px);
            left: 50%;
            transform: translateX(-50%);
            z-index: 10020;
            width: min(420px, 92vw);
            pointer-events: none;
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .achievement-toast {
            padding: 10px 12px;
            border-radius: 12px;
            background: rgba(20, 34, 20, 0.92);
            border: 1px solid rgba(255, 215, 64, 0.62);
            box-shadow: 0 10px 22px rgba(0, 0, 0, 0.45);
            animation: achievement-toast-in calc(2.6s * var(--anim-scale)) ease forwards;
        }

        .achievement-toast-title {
            font-size: 0.95rem;
            font-weight: 900;
            color: #ffe082;
        }

        .achievement-toast-body {
            margin-top: 3px;
            font-size: 0.82rem;
            color: #e9fce8;
        }

        .achievement-burst {
            position: fixed;
            left: 50%;
            top: 28%;
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background: #ffd54f;
            pointer-events: none;
            z-index: 10019;
            transform: translate(-50%, -50%);
            animation: achievement-burst calc(0.8s * var(--anim-scale)) ease-out forwards;
        }

        @keyframes achievement-burst {
            0% {
                opacity: 0.95;
                transform: translate(-50%, -50%) scale(0.8);
            }

            100% {
                opacity: 0;
                transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(0.05);
            }
        }

        @keyframes achievement-toast-in {
            0% {
                opacity: 0;
                transform: translateY(-12px) scale(0.96);
            }

            10% {
                opacity: 1;
                transform: translateY(0) scale(1);
            }

            85% {
                opacity: 1;
                transform: translateY(0) scale(1);
            }

            100% {
                opacity: 0;
                transform: translateY(-8px) scale(0.98);
            }
        }

        /* Update Prompt */
        .update-prompt {
            position: fixed;
            bottom: max(24px, env(safe-area-inset-bottom) + 16px);
            left: 50%;
            transform: translateX(-50%) translateY(120px);
            width: min(440px, 92vw);
            background: rgba(12, 36, 18, 0.94);
            border: 2px solid #ffd54f;
            border-radius: 16px;
            padding: 14px 18px;
            display: flex;
            align-items: center;
            gap: 14px;
            z-index: 10030;
            box-shadow: 0 12px 40px rgba(0, 0, 0, 0.65);
            backdrop-filter: blur(10px);
            transition: transform 0.45s cubic-bezier(0.18, 0.89, 0.32, 1.28);
        }

        .update-prompt.show {
            transform: translateX(-50%) translateY(0);
        }

        .update-prompt-info {
            flex: 1;
        }

        .update-prompt-title {
            font-size: 1rem;
            font-weight: 900;
            color: #ffd54f;
            line-height: 1.2;
        }

        .update-prompt-body {
            font-size: 0.82rem;
            color: #e8f5e9;
            margin-top: 3px;
            opacity: 0.9;
        }

        .update-prompt-btn {
            background: #ffd54f;
            color: #1b1b1b;
            border: none;
            padding: 10px 18px;
            border-radius: 10px;
            font-weight: 900;
            font-size: 0.95rem;
            cursor: pointer;
            white-space: nowrap;
            box-shadow: 0 4px #c6a700;
            flex-shrink: 0;
        }

        .update-prompt-btn:active {
            transform: translateY(2px);
            box-shadow: 0 2px #c6a700;
        }

        .achievement-close {
            width: 100%;
            min-height: 42px;
            border: none;
            border-radius: 10px;
            background: #ffd54f;
            color: #1b1b1b;
            font-weight: 900;
            cursor: pointer;
        }

        /* ── 規則說明 Overlay ── */
        .rules-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.82);
            z-index: 10010;
            display: none;
            align-items: center;
            justify-content: center;
            padding: 18px;
        }
        .rules-overlay.show {
            display: flex;
        }
        .rules-panel {
            width: min(440px, 92vw);
            max-height: 82vh;
            overflow-y: auto;
            background: linear-gradient(180deg, #112c1d, #0a1f14);
            border: 2px solid #fdd835;
            border-radius: 14px;
            padding: 18px 16px 14px;
            box-shadow: 0 14px 36px rgba(0, 0, 0, 0.6);
        }
        .rules-title {
            margin: 0 0 14px;
            color: #ffe066;
            font-size: 1.2rem;
            text-align: center;
        }
        .rules-section {
            margin-bottom: 16px;
        }
        .rules-section-title {
            font-size: 0.72rem;
            font-weight: 700;
            letter-spacing: 1px;
            color: rgba(255, 215, 0, 0.65);
            text-transform: uppercase;
            margin-bottom: 6px;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .rules-section-title::after {
            content: '';
            flex: 1;
            height: 1px;
            background: rgba(255, 215, 0, 0.2);
        }
        .rules-text {
            font-size: 0.9rem;
            color: rgba(255, 255, 255, 0.88);
            line-height: 1.55;
            margin: 0;
        }
        .rules-sums {
            display: flex;
            gap: 10px;
            margin-top: 8px;
        }
        .rules-sum-pill {
            flex: 1;
            text-align: center;
            background: rgba(255, 215, 0, 0.12);
            border: 1px solid rgba(255, 215, 0, 0.35);
            border-radius: 8px;
            padding: 8px 4px;
            font-size: 1.3rem;
            font-weight: 900;
            color: #ffe066;
        }
        .rules-sum-pill small {
            display: block;
            font-size: 0.65rem;
            font-weight: 400;
            color: rgba(255, 255, 255, 0.5);
            margin-top: 2px;
        }
        /* ── 迷你牌組示意圖 ── */
        .rules-patterns {
            display: flex;
            gap: 12px;
            justify-content: center;
            margin-top: 8px;
        }
        .rules-pattern {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 4px;
        }
        .rules-pattern-label {
            font-size: 0.65rem;
            color: rgba(255, 255, 255, 0.45);
            margin-bottom: 2px;
        }
        .rules-mini-col {
            display: flex;
            flex-direction: column;
            gap: 3px;
        }
        .rules-mini-card {
            width: 28px;
            height: 18px;
            border-radius: 3px;
            background: rgba(255, 255, 255, 0.12);
            border: 1px solid rgba(255, 255, 255, 0.25);
        }
        .rules-mini-card.gold {
            background: rgba(255, 215, 0, 0.55);
            border-color: #fdd835;
        }
        .rules-hint-row {
            display: flex;
            align-items: flex-start;
            gap: 8px;
            margin-top: 6px;
            font-size: 0.82rem;
            color: rgba(255, 255, 255, 0.75);
            line-height: 1.45;
        }
        .rules-hint-icon {
            font-size: 1rem;
            flex-shrink: 0;
            margin-top: 1px;
        }
        .rules-close {
            width: 100%;
            min-height: 42px;
            border: none;
            border-radius: 10px;
            background: #ffd54f;
            color: #1b1b1b;
            font-weight: 900;
            cursor: pointer;
            margin-top: 4px;
        }

        .leaderboard-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.78);
            z-index: 10009;
            display: none;
            align-items: center;
            justify-content: center;
            padding: 18px;
        }

        .leaderboard-overlay.show {
            display: flex;
        }

        .leaderboard-panel {
            width: min(460px, 94vw);
            max-height: 80vh;
            overflow: auto;
            background: linear-gradient(180deg, #0f2135, #0a1523);
            border: 2px solid #7ec8ff;
            border-radius: 14px;
            padding: 14px;
            box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
        }

        .leaderboard-title {
            margin: 0 0 8px;
            color: #bfe6ff;
            font-size: 1.2rem;
        }

        .leaderboard-subtitle {
            margin: 0 0 10px;
            font-size: 0.86rem;
            color: #d7ebff;
            opacity: 0.92;
        }

        .leaderboard-list {
            display: grid;
            grid-template-columns: 1fr;
            gap: 6px;
            margin-bottom: 12px;
        }

        .leaderboard-row {
            display: grid;
            grid-template-columns: 48px 1fr auto auto;
            align-items: center;
            gap: 8px;
            border-radius: 10px;
            padding: 8px 10px;
            background: rgba(255, 255, 255, 0.08);
            border: 1px solid rgba(255, 255, 255, 0.18);
            font-size: 0.88rem;
        }

        .leaderboard-row.mine {
            border-color: rgba(255, 215, 64, 0.7);
            background: rgba(255, 215, 64, 0.17);
        }

        .leaderboard-rank {
            font-weight: 900;
            color: #ffe082;
        }

        .leaderboard-user {
            color: #fff;
            font-weight: 700;
        }

        .leaderboard-time {
            color: #b9f6ca;
            font-weight: 900;
            font-variant-numeric: tabular-nums;
        }

        .leaderboard-moves {
            color: #d4edff;
            font-weight: 700;
        }

        .leaderboard-empty {
            padding: 12px;
            border-radius: 10px;
            text-align: center;
            font-size: 0.9rem;
            background: rgba(255, 255, 255, 0.08);
            color: #e3f2fd;
        }

        .leaderboard-close {
            width: 100%;
            min-height: 42px;
            border: none;
            border-radius: 10px;
            background: #7ec8ff;
            color: #0a1b2d;
            font-weight: 900;
            cursor: pointer;
        }

        body.high-contrast {
            background: #021409;
            color: #fff;
        }

        body.high-contrast .column {
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.28);
        }

        body.high-contrast .card {
            border-width: 2px;
            border-color: #111;
            box-shadow: 0 3px 8px rgba(0, 0, 0, 0.65);
        }

        body.high-contrast .card.selected {
            outline-color: #ffec3d;
            filter: brightness(1.14);
        }

        @media (prefers-reduced-motion: reduce) {
            .card.candidate-soft,
            .card.selected-invalid-pending,
            .card.selection-magnetic,
            .card.selected-magnetic,
            .card.clear-phase-windup,
            .card.clear-phase-impact,
            .card.clear-phase-settle,
            #board.clear-phase-windup .card,
            #board.clear-phase-impact .card,
            #board.clear-phase-settle .card,
            #fx-layer.clear-phase-windup .card,
            #fx-layer.clear-phase-impact .card,
            #fx-layer.clear-phase-settle .card,
            .clear-energy-trail,
            .combo-text.combo-lite,
            body.major-combo-active .column-beam,
            body.major-combo-active .column.column-cleared-glow,
            body.major-combo-active .column-clear-text,
            body.major-combo-active .clear-flash,
            body.major-combo-active .clear-flash.orange,
            body.major-combo-active .warm-flash,
            body.major-combo-active .golden-vignette,
            body.major-combo-active .combo-border-flash,
            body.major-combo-active .lucky-three-win {
                animation: none !important;
                transition: none !important;
            }

            .card.candidate-soft {
                transform: none;
            }

            .card.selected-invalid-pending {
                transform: translateX(40%) rotate(3deg);
            }

            .card.selection-magnetic {
                transform: translateX(40%) rotate(3deg);
            }

            .card.selected-magnetic {
                transform: translateX(40%) rotate(3deg);
            }

            .clear-energy-trail {
                opacity: 0.45;
                transform: none;
            }

            .combo-text.combo-lite {
                opacity: 1;
                transform: translate(-50%, -50%);
            }

            body.major-combo-active::before,
            body.major-combo-active #particle-canvas,
            body.major-combo-active #pixi-canvas {
                opacity: 0.45;
            }
        }

        /* Colorblind-friendly suits in high-contrast mode */
        body.high-contrast .card.suit-heart   { color: #1565C0; }
        body.high-contrast .card.suit-diamond { color: #E65100; }
        body.high-contrast .card.suit-spade,
        body.high-contrast .card.suit-club    { color: #1a1a1a; }

        @keyframes need-three-fade {
            0% {
                transform: translate(-50%, 10px);
                opacity: 0;
            }

            20% {
                transform: translate(-50%, 0);
                opacity: 1;
            }

            100% {
                transform: translate(-50%, -10px);
                opacity: 0;
            }
        }

        #deck-pile.deck-warn {
            border: 2px solid rgba(255, 100, 30, 0.9) !important;
            animation: deck-warn-pulse 1.1s ease-in-out infinite;
        }

        @keyframes deck-warn-pulse {
            0%, 100% { box-shadow: 0 0 0 0 rgba(255, 100, 30, 0); }
            50%       { box-shadow: 0 0 0 6px rgba(255, 100, 30, 0.45); }
        }

        .hint-highlight {
            outline: 3px solid #00e676 !important;
            outline-offset: 2px;
            animation: hint-card-pulse 0.6s ease-in-out 3;
            z-index: 10;
            position: relative;
        }

        .rewind-focus {
            outline: 3px solid #ffd54a !important;
            outline-offset: 2px;
            z-index: 11;
            position: relative;
            animation: rewind-focus-pulse calc(0.72s * var(--anim-scale)) ease-in-out 5;
            box-shadow: 0 0 0 2px rgba(255, 213, 74, 0.16), 0 0 18px rgba(255, 214, 87, 0.52);
        }

        @keyframes rewind-focus-pulse {
            0%, 100% { transform: translateY(0) scale(1); filter: brightness(1); }
            45% { transform: translateY(-1px) scale(1.035); filter: brightness(1.28) drop-shadow(0 0 7px rgba(255, 229, 145, 0.85)); }
        }

        @keyframes hint-card-pulse {
            0%, 100% { filter: brightness(1); }
            50%       { filter: brightness(1.35) drop-shadow(0 0 6px #00e676); }
        }

        #deck-pile.hint-press {
            transform: scale(0.94);
            transition: transform 0.15s ease;
        }
        .win-share-btn {
            margin-top: 8px;
            width: 100%;
            min-height: 40px;
            border: 1px solid rgba(255,215,0,0.45);
            border-radius: 10px;
            background: rgba(255,215,0,0.1);
            color: var(--gold);
            font-family: inherit;
            font-size: 0.88rem;
            font-weight: 700;
            cursor: pointer;
            transition: background 0.2s;
        }
        .win-share-btn:active { background: rgba(255,215,0,0.22); }

        .streak-calendar {
            margin: 12px 0 4px;
            width: 100%;
        }
        .streak-calendar-title {
            font-size: 0.78rem;
            color: rgba(255,215,0,0.75);
            letter-spacing: 0.8px;
            margin-bottom: 6px;
            text-transform: uppercase;
        }
        .streak-cal-grid {
            display: grid;
            grid-template-columns: repeat(7, 1fr);
            gap: 3px;
        }
        .streak-cal-day {
            aspect-ratio: 1;
            border-radius: 5px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            font-size: 0.62rem;
            background: rgba(255,255,255,0.05);
            border: 1px solid rgba(255,255,255,0.08);
            line-height: 1.1;
            gap: 1px;
            min-height: 30px;
        }
        .streak-cal-day.today {
            border-color: rgba(255,215,0,0.6);
            background: rgba(255,215,0,0.08);
        }
        .streak-cal-day.has-win {
            background: rgba(0,200,100,0.18);
            border-color: rgba(0,200,100,0.5);
        }
        .streak-cal-day.has-win.today {
            background: rgba(0,200,100,0.28);
            border-color: #00e676;
        }
        .streak-cal-day .cal-suit {
            font-size: 0.75rem;
            line-height: 1;
        }
        .streak-cal-day .cal-num {
            font-size: 0.55rem;
            opacity: 0.7;
        }
        .streak-cal-weekday {
            font-size: 0.55rem;
            color: rgba(255,255,255,0.4);
            text-align: center;
            padding-bottom: 2px;
        }

        /* ── Non-Latin locale font fallback ─────────────────────── */
        body.locale-th  { font-family: 'Noto Sans Thai', 'Sarabun', system-ui, sans-serif; }
        body.locale-vi  { font-family: 'Be Vietnam Pro', 'Noto Sans', system-ui, sans-serif; }
        body.locale-ru,
        body.locale-pl  { font-family: 'PT Sans', 'Arial', system-ui, sans-serif; }
        body.locale-ar  { font-family: 'Noto Sans Arabic', system-ui, sans-serif; }
        body.locale-zh-CN,
        body.locale-zh-Hant { font-family: 'Noto Sans CJK TC', 'PingFang TC', 'Microsoft YaHei', system-ui, sans-serif; }
        body.locale-ja  { font-family: 'Noto Sans JP', 'Hiragino Sans', 'Yu Gothic', system-ui, sans-serif; }
        body.locale-ko  { font-family: 'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif; }
        .win-prev-stats {
            font-size: 0.72rem;
            color: rgba(255,215,0,0.55);
            letter-spacing: 0.5px;
            margin-bottom: 6px;
            text-align: center;
        }
        /* ===== AD BANNER =====
           Default visible (Capacitor app always shows it for non-premium players).
           Body class toggles override visibility — same pattern as root index.html. */
        .ad-banner {
            width: 100%;
            background: rgba(0,0,0,0.7);
            border-top: 1px solid rgba(255,215,0,0.2);
            padding: 6px 10px;
            display: flex;
            align-items: center;
            flex-shrink: 0;
            min-height: 50px;
            z-index: 10;
        }
        body.is-tutorial-active .ad-banner { display: none; }
        .ad-banner-inner {
            display: flex;
            align-items: center;
            width: 100%;
            gap: 8px;
        }
        .ad-label {
            font-size: 9px;
            color: rgba(255,255,255,0.4);
            border: 1px solid rgba(255,255,255,0.2);
            border-radius: 2px;
            padding: 1px 3px;
            flex-shrink: 0;
        }
        .ad-placeholder { flex: 1; text-align: center; }
        .ad-placeholder-text { font-size: 11px; color: rgba(255,255,255,0.5); }
        .ad-upgrade-btn {
            background: linear-gradient(135deg, #ffd700, #ffaa00);
            color: #000;
            border: none;
            border-radius: 6px;
            padding: 6px 10px;
            font-size: 11px;
            font-weight: 700;
            cursor: pointer;
            flex-shrink: 0;
            white-space: nowrap;
        }
        /* ===== INTERSTITIAL ===== */
        .interstitial-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.92);
            z-index: 9000;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .interstitial-panel {
            width: min(360px, 92vw);
            background: #0a2a14;
            border: 1px solid rgba(255,215,0,0.3);
            border-radius: 16px;
            overflow: hidden;
            display: flex;
            flex-direction: column;
        }
        .interstitial-ad-area { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
        .interstitial-ad-content {
            min-height: 180px;
            background: rgba(255,255,255,0.04);
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .interstitial-ad-mock { text-align: center; padding: 20px; }
        .interstitial-ad-icon { font-size: 40px; margin-bottom: 8px; }
        .interstitial-ad-headline { font-size: 18px; font-weight: 700; color: var(--gold); margin-bottom: 6px; }
        .interstitial-ad-body { font-size: 13px; color: rgba(255,255,255,0.7); }
        .interstitial-actions { padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 8px; }
        .interstitial-upgrade-btn {
            width: 100%;
            background: linear-gradient(135deg, #ffd700, #ffaa00);
            color: #000;
            border: none;
            border-radius: 10px;
            padding: 13px;
            font-size: 15px;
            font-weight: 700;
            cursor: pointer;
        }
        .interstitial-close-btn {
            width: 100%;
            background: rgba(255,255,255,0.08);
            color: rgba(255,255,255,0.5);
            border: 1px solid rgba(255,255,255,0.12);
            border-radius: 10px;
            padding: 10px;
            font-size: 13px;
            cursor: not-allowed;
            opacity: 0.6;
        }
        .interstitial-close-btn.ready {
            color: rgba(255,255,255,0.8);
            cursor: pointer;
            opacity: 1;
        }
        /* ===== PREMIUM MODAL ===== */
        .premium-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.85);
            z-index: 9500;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .premium-panel {
            width: min(340px, 90vw);
            background: linear-gradient(160deg, #0f3d1e 0%, #051d0e 100%);
            border: 1px solid rgba(255,215,0,0.5);
            border-radius: 20px;
            padding: 28px 24px 24px;
            text-align: center;
            display: flex;
            flex-direction: column;
            gap: 10px;
            box-shadow: 0 0 40px rgba(255,215,0,0.15);
            max-height: 90vh;
            overflow-y: auto;
        }
        .premium-icon { font-size: 36px; }
        .premium-title {
            font-family: 'Cinzel Decorative', Georgia, serif;
            font-size: 1.1rem;
            color: var(--gold);
            font-weight: 900;
            margin: 0;
            line-height: 1.3;
        }
        .premium-subtitle { font-size: 13px; color: rgba(255,255,255,0.75); margin: 0; }
        .premium-price {
            font-size: 15px;
            font-weight: 700;
            color: #fff;
            background: rgba(255,215,0,0.12);
            border: 1px solid rgba(255,215,0,0.3);
            border-radius: 8px;
            padding: 8px 12px;
            margin: 0;
        }
        .premium-benefits { list-style: none; padding: 0; margin: 0; text-align: left; display: flex; flex-direction: column; gap: 6px; }
        .premium-benefits li { font-size: 13px; color: rgba(255,255,255,0.85); padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.07); }
        .premium-buy-btn {
            width: 100%;
            background: linear-gradient(135deg, #ffd700, #ffaa00);
            color: #000;
            border: none;
            border-radius: 12px;
            padding: 15px;
            font-size: 16px;
            font-weight: 700;
            cursor: pointer;
            box-shadow: 0 4px 16px rgba(255,215,0,0.4);
            margin-top: 4px;
        }
        .premium-buy-btn:active { transform: scale(0.97); }
        .premium-restore-btn {
            width: 100%;
            background: transparent;
            color: rgba(255,255,255,0.5);
            border: 1px solid rgba(255,255,255,0.15);
            border-radius: 10px;
            padding: 10px;
            font-size: 13px;
            cursor: pointer;
        }
        .premium-close-btn {
            background: none;
            border: none;
            color: rgba(255,255,255,0.35);
            font-size: 12px;
            cursor: pointer;
            padding: 4px;
        }
        /* ── 設定 tab 列 ── */
        .settings-tabs {
            display: flex;
            flex-shrink: 0;
            border-bottom: 1px solid rgba(255, 215, 0, 0.15);
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
            scrollbar-width: none;
            background: #0c1e13;
        }
        .settings-tabs::-webkit-scrollbar { display: none; }
        .settings-tab-btn {
            flex: 1;
            min-width: 64px;
            padding: 10px 6px;
            background: transparent;
            border: none;
            border-bottom: 2px solid transparent;
            color: rgba(255,255,255,0.45);
            font-size: 0.72rem;
            font-weight: 700;
            cursor: pointer;
            transition: color 0.15s, border-color 0.15s;
            font-family: inherit;
            white-space: nowrap;
            line-height: 1.35;
        }
        .settings-tab-btn.active {
            color: var(--gold, #ffd54f);
            border-bottom-color: var(--gold, #ffd54f);
            background: transparent;
        }
        .settings-tab-pane { display: none; }
        .settings-tab-pane.active { display: block; }

        .settings-premium-btn {
            width: 100%;
            background: linear-gradient(135deg, #ffd700, #ffaa00);
            color: #000;
            border: none;
            border-radius: 10px;
            padding: 13px;
            font-size: 14px;
            font-weight: 700;
            cursor: pointer;
            margin-bottom: 4px;
        }

        /* ═══════════════════════════════════════════════
           NATIVE APP SOUL ELEMENTS
           (www/ only — PWA root/index.html untouched)
           ═══════════════════════════════════════════════ */

        /* --- 1. 開局靈牌儀式 --- */
        .omen-card-wrap {
            position: fixed;
            inset: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 9800;
            pointer-events: none;
            animation: omen-fadein 0.4s ease forwards;
        }
        @keyframes omen-fadein { from { opacity: 0; } to { opacity: 1; } }

        .omen-scene {
            width: 84px;
            height: calc(84px * 1.42);
            perspective: 600px;
        }
        .omen-inner {
            width: 100%;
            height: 100%;
            transform-style: preserve-3d;
            animation: omen-flip 0.6s ease 0.9s forwards;
        }
        @keyframes omen-flip {
            0%   { transform: rotateY(0deg); }
            100% { transform: rotateY(180deg); }
        }
        .omen-face {
            position: absolute;
            inset: 0;
            border-radius: 8px;
            backface-visibility: hidden;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 2.6rem;
            box-shadow: 0 0 32px rgba(255,215,0,0.5), 0 4px 24px rgba(0,0,0,0.5);
        }
        .omen-back {
            background: linear-gradient(135deg, #0f3d1d 0%, #1a6b35 50%, #0f3d1d 100%);
            border: 2px solid var(--gold);
        }
        .omen-back::before {
            content: '';
            position: absolute;
            inset: 6px;
            background-image:
                repeating-linear-gradient(45deg, rgba(255,215,0,0.15) 0px, rgba(255,215,0,0.15) 1px, transparent 1px, transparent 9px),
                repeating-linear-gradient(-45deg, rgba(255,215,0,0.15) 0px, rgba(255,215,0,0.15) 1px, transparent 1px, transparent 9px);
            border: 1px solid rgba(255,215,0,0.3);
            border-radius: 2px;
        }
        .omen-front {
            background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%);
            border: 2px solid var(--gold);
            transform: rotateY(180deg);
            flex-direction: column;
            gap: 4px;
        }
        .omen-label {
            font-family: 'Cinzel', Georgia, serif;
            font-size: 0.52rem;
            color: var(--gold);
            letter-spacing: 0.12em;
            text-transform: uppercase;
            opacity: 0.85;
        }
        .omen-suit-char {
            font-size: 3rem;
            line-height: 1;
            filter: drop-shadow(0 0 8px currentColor);
        }
        .omen-wrap-out {
            animation: omen-fadeout 0.45s ease forwards;
        }
        @keyframes omen-fadeout { from { opacity: 1; } to { opacity: 0; } }

        /* --- 2. 連擊靈獸（雕刻徽章版） --- */
        .spirit-beast {
            position: fixed;
            left: 50%;
            top: 38%;
            width: clamp(64px, 15vw, 84px);
            height: clamp(64px, 15vw, 84px);
            pointer-events: none;
            z-index: 9998;
            transform: translate(-50%, -50%) translateY(8px) scale(0.9);
            border-radius: 50%;
            border: 1px solid rgba(255, 215, 120, 0.55);
            background: radial-gradient(circle at 50% 50%, rgba(255, 225, 160, 0.2) 0%, rgba(255, 225, 160, 0.04) 58%, transparent 80%);
            box-shadow: 0 0 16px rgba(255, 215, 120, 0.25), inset 0 0 14px rgba(255, 225, 170, 0.14);
            animation: spirit-mark-rise calc(1.1s * var(--anim-scale)) cubic-bezier(0.24, 0.82, 0.31, 1) forwards;
            will-change: transform, opacity;
        }
        .spirit-beast::before,
        .spirit-beast::after {
            content: '';
            position: absolute;
            inset: 10px;
            border-radius: 50%;
            border: 1px solid rgba(255, 215, 120, 0.28);
        }
        .spirit-beast::after {
            inset: 18px;
            border-color: rgba(255, 235, 180, 0.22);
        }
        .spirit-beast-core {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .spirit-beast-icon {
            width: 100%;
            height: 100%;
            object-fit: contain;
            filter: drop-shadow(0 0 12px rgba(255, 220, 145, 0.3));
        }
        .spirit-beast.tier-4 { border-color: rgba(198, 228, 255, 0.58); }
        .spirit-beast.tier-4 .spirit-beast-icon {
            filter: drop-shadow(0 0 13px rgba(170, 220, 255, 0.35));
        }
        .spirit-beast.tier-5 { border-color: rgba(255, 230, 156, 0.65); }
        .spirit-beast.tier-5 {
            box-shadow: 0 0 21px rgba(255, 224, 130, 0.36), inset 0 0 16px rgba(255, 235, 165, 0.18);
        }
        .spirit-beast.tier-5::after {
            animation: spirit-mark-pulse calc(0.42s * var(--anim-scale)) ease-out 1;
        }
        .spirit-beast.tier-5 .spirit-beast-icon {
            filter: drop-shadow(0 0 16px rgba(255, 232, 164, 0.45));
        }
        @keyframes spirit-mark-rise {
            0%   { opacity: 0; transform: translate(-50%, -50%) translateY(8px) scale(0.9); }
            18%  { opacity: 1; transform: translate(-50%, -50%) translateY(-2px) scale(1.04); }
            65%  { opacity: 0.94; transform: translate(-50%, -50%) translateY(-14px) scale(1); }
            100% { opacity: 0; transform: translate(-50%, -50%) translateY(-28px) scale(0.96); }
        }
        @keyframes spirit-mark-pulse {
            from { transform: scale(0.9); opacity: 0.45; }
            to   { transform: scale(1.18); opacity: 0; }
        }

@keyframes spirit-fox-traverse {
    0%   { transform: translateX(calc(-100% - 24px)) translateY(12px); opacity: 0; }
    7%   { opacity: 1; }
    30%  { transform: translateX(18vw) translateY(-10px); }
    55%  { transform: translateX(42vw) translateY(-14px); }
    78%  { transform: translateX(68vw) translateY(-4px); }
    93%  { opacity: 1; }
    100% { transform: translateX(calc(100vw + 24px)) translateY(8px); opacity: 0; }
}

@keyframes spirit-eagle-ascent {
    0%   { transform: translate(-50%, calc(50vh + 120px)) scale(0.88); opacity: 0; }
    9%   { transform: translate(-50%, calc(50vh - 20px)) scale(0.94); opacity: 1; }
    25%  { transform: translate(-50%, 12vh) scale(1.0); }
    38%  { transform: translate(-50%, -2vh) scale(0.97); }
    52%  { transform: translate(-50%, -16vh) scale(1.02); }
    65%  { transform: translate(-50%, -30vh) scale(0.98); }
    80%  { transform: translate(-50%, -44vh) scale(1.01); opacity: 1; }
    100% { transform: translate(-50%, calc(-50vh - 160px)) scale(0.9); opacity: 0; }
}

@keyframes spirit-lion-manifest {
    0%   { transform: translate(-50%, -50%) scale(1.3);  opacity: 0;    filter: blur(12px); }
    20%  { transform: translate(-50%, -50%) scale(1.0);  opacity: 0.78; filter: blur(0px); }
    28%  { transform: translate(-50%, -50%) scale(1.05); opacity: 0.85; }
    38%  { transform: translate(-50%, -50%) scale(0.98); opacity: 0.76; }
    68%  { transform: translate(-50%, -50%) scale(1.0);  opacity: 0.72; filter: blur(0px); }
    100% { transform: translate(-50%, -50%) scale(1.1);  opacity: 0;    filter: blur(6px); }
}

@keyframes lion-shockwave {
    0%   { transform: translate(-50%, -50%) scale(0.4); opacity: 0.6; }
    100% { transform: translate(-50%, -50%) scale(4.0); opacity: 0; }
}

@keyframes spirit-phoenix-ascend {
    0%   { transform: translate(-50%, 56vh) scale(0.72) rotate(-4deg); opacity: 0; filter: blur(10px) saturate(0.85); }
    14%  { transform: translate(-50%, 28vh) scale(0.9) rotate(-1deg); opacity: 0.92; filter: blur(0px) saturate(1.05); }
    34%  { transform: translate(-50%, 8vh) scale(1.04) rotate(1deg); opacity: 1; }
    52%  { transform: translate(-50%, -8vh) scale(1.1) rotate(-1deg); opacity: 0.97; }
    72%  { transform: translate(-50%, -22vh) scale(1.05) rotate(0deg); opacity: 0.88; }
    100% { transform: translate(-50%, -40vh) scale(0.9) rotate(2deg); opacity: 0; filter: blur(4px) saturate(1.2); }
}

@keyframes phoenix-solar-flare {
    0%   { transform: translate(-50%, -50%) scale(0.35); opacity: 0.78; }
    55%  { opacity: 0.42; }
    100% { transform: translate(-50%, -50%) scale(5.1); opacity: 0; }
}

/* ── 狐靈橫穿 ── */
.spirit-beast.spirit-fox {
    width: clamp(260px, 48vw, 420px);
    height: auto;
    left: 0;
    top: auto;
    bottom: 38%;
    border-radius: 0;
    border: none;
    background: none;
    box-shadow: none;
    z-index: 9500;
    transform: none;
    animation: spirit-fox-traverse 1.8s cubic-bezier(0.4, 0, 0.6, 1) forwards;
}
.spirit-beast.spirit-fox .spirit-beast-icon {
    width: 100%;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 0 18px rgba(255, 200, 80, 0.55));
}

/* ── 鷹靈飛升 ── */
.spirit-beast.spirit-eagle {
    width: clamp(200px, 40vw, 340px);
    height: auto;
    left: 50%;
    top: 50%;
    border-radius: 0;
    border: none;
    background: none;
    box-shadow: none;
    z-index: 9600;
    transform: translate(-50%, calc(50vh + 120px)) scale(0.88);
    animation: spirit-eagle-ascent 2.0s cubic-bezier(0.3, 0.1, 0.3, 1) forwards;
}
.spirit-beast.spirit-eagle .spirit-beast-icon {
    width: 100%;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 0 22px rgba(255, 200, 80, 0.6));
}

/* ── 獅靈顯現 ── */
.spirit-beast.spirit-lion {
    width: clamp(300px, 62vw, 520px);
    height: clamp(300px, 62vw, 520px);
    left: 50%;
    top: 50%;
    border-radius: 0;
    border: none;
    background: none;
    box-shadow: none;
    z-index: 50;
    -webkit-mask-image: radial-gradient(circle, black 35%, transparent 72%);
    mask-image: radial-gradient(circle, black 35%, transparent 72%);
    animation: spirit-lion-manifest 3.0s cubic-bezier(0.2, 0.6, 0.3, 1) forwards;
}
.spirit-beast.spirit-lion .spirit-beast-icon {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: drop-shadow(0 0 28px rgba(255, 200, 60, 0.7));
}

/* ── 鳳凰升華 ── */
.spirit-beast.spirit-phoenix {
    width: clamp(280px, 58vw, 500px);
    height: clamp(180px, 36vw, 320px);
    left: 50%;
    top: 50%;
    border-radius: 0;
    border: none;
    background: none;
    box-shadow: none;
    z-index: 9700;
    transform: translate(-50%, 56vh) scale(0.72);
    animation: spirit-phoenix-ascend 3.0s cubic-bezier(0.2, 0.72, 0.22, 1) forwards;
}
.spirit-beast.spirit-phoenix .spirit-beast-icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: hue-rotate(-24deg) saturate(1.42) brightness(1.12) drop-shadow(0 0 26px rgba(255, 138, 48, 0.62));
}
.spirit-beast.spirit-phoenix::before {
    inset: 6% 16%;
    border-radius: 48%;
    border: 1px solid rgba(255, 168, 72, 0.58);
}
.spirit-beast.spirit-phoenix::after {
    inset: 14% 26%;
    border-radius: 50%;
    border: 1px solid rgba(255, 218, 120, 0.42);
}

/* ── 鳳凰日冕 ── */
.phoenix-solar-flare {
    position: fixed;
    left: 50%;
    top: 50%;
    width: clamp(320px, 66vw, 560px);
    height: clamp(320px, 66vw, 560px);
    border-radius: 50%;
    border: 2px solid rgba(255, 176, 76, 0.58);
    box-shadow: 0 0 26px rgba(255, 125, 38, 0.34), inset 0 0 34px rgba(255, 210, 102, 0.24);
    pointer-events: none;
    z-index: 9710;
    animation: phoenix-solar-flare 0.9s ease-out forwards;
}

/* ── 吼叫衝擊波 ── */
.lion-shockwave {
    position: fixed;
    left: 50%;
    top: 50%;
    width: clamp(300px, 62vw, 520px);
    height: clamp(300px, 62vw, 520px);
    border-radius: 50%;
    border: 3px solid rgba(255, 215, 0, 0.5);
    pointer-events: none;
    z-index: 51;
    animation: lion-shockwave 0.85s ease-out forwards;
}

        /* --- 3. 深夜星空 --- */
        body.night-sky::after {
            content: '';
            position: fixed;
            inset: 0;
            pointer-events: none;
            z-index: 0;
            background-image:
                radial-gradient(1px 1px at 12% 8%,  rgba(255,255,255,0.55) 0%, transparent 100%),
                radial-gradient(1px 1px at 35% 15%, rgba(255,255,255,0.4)  0%, transparent 100%),
                radial-gradient(1px 1px at 58% 5%,  rgba(255,255,255,0.6)  0%, transparent 100%),
                radial-gradient(1px 1px at 75% 22%, rgba(255,255,255,0.35) 0%, transparent 100%),
                radial-gradient(1px 1px at 88% 10%, rgba(255,255,255,0.5)  0%, transparent 100%),
                radial-gradient(1.5px 1.5px at 22% 30%, rgba(255,215,0,0.3) 0%, transparent 100%),
                radial-gradient(1px 1px at 48% 35%, rgba(255,255,255,0.45) 0%, transparent 100%),
                radial-gradient(1px 1px at 65% 28%, rgba(255,255,255,0.3)  0%, transparent 100%),
                radial-gradient(1px 1px at 8%  40%, rgba(255,255,255,0.4)  0%, transparent 100%),
                radial-gradient(1.5px 1.5px at 90% 38%, rgba(255,215,0,0.25) 0%, transparent 100%);
            animation: night-drift 18s ease-in-out infinite alternate;
        }
        @keyframes night-drift {
            0%   { opacity: 0.4; transform: translateY(0); }
            100% { opacity: 0.8; transform: translateY(-6px); }
        }

        /* --- 4. 選牌光圈脈衝 --- */
        @keyframes card-select-pulse {
            0%   { box-shadow: 0 0 0 0 rgba(255,215,0,0.7), var(--card-shadow); }
            60%  { box-shadow: 0 0 0 8px rgba(255,215,0,0), var(--card-shadow); }
            100% { box-shadow: 0 0 0 0 rgba(255,215,0,0), var(--card-shadow); }
        }
        .card.select-pulse {
            animation: card-select-pulse calc(0.4s * var(--anim-scale)) ease-out;
        }

        /* ── Gallery ── */
        #gallery-overlay, #gallery-detail-overlay {
            position: fixed; inset: 0; z-index: 19000;
            background: #040f08;
            display: none; flex-direction: column;
            padding-top: env(safe-area-inset-top);
            padding-bottom: env(safe-area-inset-bottom);
        }
        #gallery-overlay.show, #gallery-detail-overlay.show { display: flex; }

        .gallery-header {
            display: flex; align-items: center; gap: 12px;
            padding: 14px 18px 10px;
            border-bottom: 1px solid rgba(255,215,0,0.15);
            flex-shrink: 0;
        }
        .gallery-back {
            background: none; border: none; color: rgba(255,215,0,0.8);
            font-size: 1.4rem; cursor: pointer; padding: 4px 8px;
            font-family: inherit;
        }
        .gallery-header-title {
            font-family: 'Cinzel', Georgia, serif;
            font-size: 1rem; font-weight: 700;
            color: #ffd700; letter-spacing: 1px;
            flex: 1;
        }

        /* 列表 */
        .gallery-list {
            flex: 1; overflow-y: auto;
            padding: 16px;
            display: flex; flex-direction: column; gap: 14px;
        }
        .gallery-hall-row {
            display: grid;
            grid-template-columns: repeat(3, minmax(0, 1fr));
            gap: 8px;
        }
        .gallery-series-section {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }
        .gallery-series-header {
            display: flex;
            align-items: baseline;
            justify-content: space-between;
            padding: 0 4px;
        }
        .gallery-series-title {
            font-family: 'Cinzel', Georgia, serif;
            color: #ffd98f;
            font-size: 0.86rem;
            letter-spacing: 0.8px;
        }
        .gallery-series-stat {
            color: rgba(255, 255, 255, 0.5);
            font-size: 0.7rem;
        }
        .gallery-series-list {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }
        .gallery-hall-tile {
            border: 1px solid rgba(255, 215, 0, 0.28);
            border-radius: 10px;
            background: rgba(255, 255, 255, 0.04);
            color: #ffeaa0;
            padding: 6px;
            display: flex;
            flex-direction: column;
            gap: 6px;
            text-align: left;
            cursor: pointer;
        }
        .gallery-hall-tile img {
            width: 100%;
            aspect-ratio: 4 / 3;
            object-fit: cover;
            border-radius: 8px;
            border: 1px solid rgba(255, 215, 0, 0.2);
        }
        .gallery-hall-tile span {
            font-size: 0.72rem;
            line-height: 1.25;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .gallery-card {
            border-radius: 12px;
            border: 1px solid rgba(255,215,0,0.18);
            background: rgba(255,255,255,0.04);
            overflow: hidden; cursor: pointer;
            display: flex; align-items: center; gap: 14px;
            padding: 12px;
            transition: background 0.15s;
        }
        .gallery-card:active { background: rgba(255,215,0,0.08); }
        .gallery-card-thumb {
            flex-shrink: 0; border-radius: 6px; overflow: hidden;
            border: 2px solid rgba(255,215,0,0.3);
            position: relative;
        }
        .gallery-card-thumb img {
            display: block; width: 100%; height: 100%; object-fit: cover;
        }
        .gallery-card-thumb-mask {
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(165deg, rgba(24,24,24,0.95), rgba(48,48,48,0.9));
            color: rgba(255, 215, 0, 0.72);
            font-size: 0.75rem;
            letter-spacing: 1px;
        }
        .gallery-card-thumb.portrait  { width: 54px; height: 72px; }
        .gallery-card-thumb.landscape { width: 88px; height: 58px; }
        .gallery-card-thumb.square    { width: 66px; height: 66px; }
        .gallery-card-info { flex: 1; min-width: 0; }
        .gallery-card-title {
            font-family: 'Cinzel', Georgia, serif;
            font-size: 0.95rem; font-weight: 700; color: #ffd700;
            margin: 0 0 6px;
        }
        .gallery-progress-bar {
            height: 4px; border-radius: 2px;
            background: rgba(255,255,255,0.1);
            margin-bottom: 5px; overflow: hidden;
        }
        .gallery-progress-fill {
            height: 100%; border-radius: 2px;
            background: linear-gradient(90deg, #ffd700, #ff9500);
            transition: width 0.4s ease;
        }
        .gallery-progress-text {
            font-size: 0.72rem; color: rgba(255,255,255,0.45);
        }
        .gallery-card-lock {
            font-size: 1.2rem; color: rgba(255,255,255,0.2);
        }
        .gallery-card.locked {
            cursor: default;
            opacity: 0.9;
        }
        .gallery-card.completed .gallery-card-thumb {
            border-color: #ffd700;
            box-shadow: 0 0 12px rgba(255,215,0,0.35);
        }
        .gallery-detail-nav {
            margin-left: auto;
            display: inline-flex;
            gap: 6px;
        }
        .gallery-nav-btn {
            width: 28px;
            height: 28px;
            border-radius: 8px;
            border: 1px solid rgba(255, 215, 0, 0.45);
            background: rgba(255, 255, 255, 0.04);
            color: #ffd700;
            cursor: pointer;
        }
        .gallery-nav-btn:disabled {
            opacity: 0.35;
            cursor: default;
        }

        /* 詳情 — 拼圖畫面 */
        .gallery-puzzle-wrap {
            flex: 1; display: flex; align-items: center;
            justify-content: center; padding: 16px; overflow: hidden;
        }
        .gallery-puzzle {
            display: grid; gap: 2px;
            max-width: min(90vw, 420px);
        }
        .gallery-piece {
            border-radius: 3px; overflow: hidden;
            position: relative; background: rgba(255,255,255,0.06);
            border: 1px solid rgba(255,255,255,0.08);
        }
        .gallery-piece img {
            display: block; width: 100%; height: 100%; object-fit: cover;
        }
.gallery-piece.locked::after {
            content: '✦'; position: absolute; inset: 0;
            display: flex; align-items: center; justify-content: center;
            color: rgba(255,215,0,0.18); font-size: 1.1rem;
        }
        .gallery-piece.new-unlock {
            animation: piece-unlock 0.6s cubic-bezier(0.18,0.89,0.32,1.28) both;
        }
        @keyframes piece-unlock {
            0%   { transform: scale(0.5); opacity: 0; filter: brightness(2); }
            60%  { transform: scale(1.08); }
            100% { transform: scale(1); opacity: 1; filter: brightness(1); }
        }

        /* 完整畫作展示 */
        .gallery-full-wrap {
            flex: 1; display: flex; align-items: center;
            justify-content: center; padding: 24px;
        }
        .gallery-frame {
            position: relative; display: inline-block;
            border-radius: 3px;
            /* default fallback frame */
            box-shadow:
                0 0 0 4px #b8860b,
                0 0 0 8px #8B6914,
                0 0 0 12px #DAA520,
                0 0 32px rgba(0,0,0,0.8);
        }
        /* ── per-painting frame styles ── */
        .gallery-frame.frame-cherry-gold-spring {
            border: 6px solid #c9a84c; border-radius: 2px;
            box-shadow:
                inset 0 0 0 3px #f5e6a3,
                inset 0 0 0 6px #b8892a,
                0 0 0 10px #c9a84c,
                0 0 0 14px #8a5e1a,
                0 6px 18px 14px rgba(100,60,10,0.45),
                0 12px 36px 14px rgba(60,30,5,0.25);
        }
        .gallery-frame.frame-iron-cliff-rust {
            border: 8px solid #7a3b1e; border-radius: 1px;
            box-shadow:
                inset 0 0 0 3px #4a1e0a,
                inset 0 0 0 6px #a05030,
                0 0 0 12px #6b3018,
                0 0 0 18px #2e1208,
                0 8px 24px 18px rgba(40,15,5,0.55),
                0 16px 40px 18px rgba(20,8,2,0.3);
        }
        .gallery-frame.frame-mediterranean-vermillion {
            border: 7px solid #c0392b; border-radius: 2px;
            box-shadow:
                inset 0 0 0 2px #f4d03f,
                inset 0 0 0 5px #922b21,
                0 0 0 8px #c0392b,
                0 0 0 13px #922b21,
                0 0 0 16px #f4d03f,
                0 8px 28px 16px rgba(100,20,10,0.5),
                0 0 50px 10px rgba(192,57,43,0.2);
        }
        .gallery-frame.frame-taiwan-temple-lacquer {
            border: 8px solid #9b1b1b; border-radius: 1px;
            box-shadow:
                inset 0 0 0 2px #d4a017,
                inset 0 0 0 5px #5a0e0e,
                inset 0 0 0 8px #1a0a0a,
                0 0 0 12px #7a1515,
                0 0 0 16px #1a0a0a,
                0 0 0 20px #d4a017,
                0 10px 30px 20px rgba(30,5,5,0.6),
                0 0 40px 8px rgba(155,27,27,0.25);
        }
        .gallery-frame.frame-oak-grove-timber {
            border: 7px solid #5c3317; border-radius: 2px;
            box-shadow:
                inset 0 0 0 3px #8b5a2b,
                inset 0 0 0 6px #3e2009,
                0 0 0 10px #6b4020,
                0 0 0 16px #2e1508,
                0 8px 20px 16px rgba(40,20,5,0.5),
                0 16px 40px 16px rgba(20,10,2,0.3);
        }
        .gallery-frame.frame-bronze-green-botanical {
            border: 6px solid #4a6741; border-radius: 2px;
            box-shadow:
                inset 0 0 0 2px #c8a84b,
                inset 0 0 0 5px #2e4a28,
                0 0 0 9px #4a6741,
                0 0 0 14px #8a7530,
                0 0 0 18px #2e4a28,
                0 8px 24px 18px rgba(20,35,15,0.5),
                0 0 35px 6px rgba(74,103,65,0.2);
        }
        .gallery-frame.frame-matte-black-contemporary {
            border: 5px solid #0d0d0d; border-radius: 0px;
            box-shadow:
                inset 0 0 0 2px #2a2a2a,
                inset 0 0 0 4px #c0c0c0,
                0 0 0 8px #111111,
                0 0 0 14px #1e1e1e,
                0 10px 30px 14px rgba(0,0,0,0.7),
                0 20px 50px 14px rgba(0,0,0,0.4);
        }
        .gallery-frame.frame-exhibit-walnut-mat {
            border: 10px solid #3a1f0d; border-radius: 1px;
            box-shadow:
                inset 0 0 0 4px #f0e8d8,
                inset 0 0 0 8px #d4c9b0,
                inset 0 0 0 12px #3a1f0d,
                0 0 0 16px #2a1508,
                0 10px 28px 16px rgba(30,15,5,0.55),
                0 20px 50px 16px rgba(15,8,2,0.35);
        }
        .gallery-frame.frame-provence-sky-blue {
            border: 5px solid #5b8fa8; border-radius: 3px;
            box-shadow:
                inset 0 0 0 3px #d6eaf8,
                inset 0 0 0 6px #85b8d0,
                0 0 0 10px #5b8fa8,
                0 0 0 15px #2e6e8a,
                0 8px 24px 15px rgba(30,80,110,0.4),
                0 0 45px 8px rgba(91,143,168,0.3);
        }
        .gallery-frame.frame-cosmic-black-yellow {
            border: 6px solid #1a1a1a; border-radius: 0px;
            box-shadow:
                inset 0 0 0 2px #f0c010,
                inset 0 0 0 5px #1a1a1a,
                0 0 0 9px #1a1a1a,
                0 0 0 12px #f0c010,
                0 0 0 16px #1a1a1a,
                0 10px 30px 16px rgba(0,0,0,0.65),
                0 0 50px 10px rgba(240,192,16,0.2);
        }
        .gallery-frame.frame-cosmic-violet-gold {
            border: 6px solid #3d1a6b; border-radius: 0px;
            box-shadow:
                inset 0 0 0 2px #d4a017,
                inset 0 0 0 5px #2a0e50,
                0 0 0 9px #4b2080,
                0 0 0 13px #1a0a30,
                0 0 0 17px #d4a017,
                0 10px 32px 17px rgba(40,10,80,0.65),
                0 0 55px 12px rgba(100,40,180,0.25);
        }
        .gallery-frame.frame-pop-art-neon-pink {
            border: 7px solid #e91e8c; border-radius: 3px;
            box-shadow:
                inset 0 0 0 2px #ffe066,
                inset 0 0 0 5px #c2185b,
                0 0 0 9px #e91e8c,
                0 0 0 13px #7b1fa2,
                0 0 0 17px #ffe066,
                0 8px 28px 17px rgba(150,20,100,0.5),
                0 0 55px 12px rgba(233,30,140,0.35),
                0 0 90px 20px rgba(123,31,162,0.2);
        }
        .gallery-frame img {
            display: block; max-width: min(80vw, 400px);
            max-height: 60vh; object-fit: contain; border-radius: 2px;
        }
        .gallery-frame::after {
            content: '';
            position: absolute;
            left: 18%;
            right: 18%;
            bottom: -10px;
            height: 4px;
            border-radius: 999px;
            background: rgba(0,0,0,0.55);
            opacity: 0.7;
            transform-origin: center;
            transform: scaleX(0.75);
            transition: transform calc(0.28s * var(--anim-scale)) ease;
        }
        .gallery-frame.just-completed {
            animation:
                gallery-frame-listing calc(0.86s * var(--anim-scale)) cubic-bezier(0.18,0.89,0.32,1.28) both,
                gallery-frame-shine calc(1.5s * var(--anim-scale)) ease-out calc(0.12s * var(--anim-scale)) both;
        }
        .gallery-frame.just-completed::after {
            animation: gallery-frame-shadow-settle calc(0.86s * var(--anim-scale)) cubic-bezier(0.18,0.89,0.32,1.1) both;
        }
        @keyframes gallery-frame-listing {
            0% {
                opacity: 0;
                transform: translateY(28px) scale(0.82);
                filter: brightness(1.4) saturate(1.2);
            }
            65% {
                opacity: 1;
                transform: translateY(-4px) scale(1.04);
                filter: brightness(1.12);
            }
            100% {
                opacity: 1;
                transform: translateY(0) scale(1);
                filter: brightness(1);
            }
        }
        @keyframes gallery-frame-shine {
            0% { box-shadow: 0 0 0 4px #b8860b, 0 0 0 8px #8B6914, 0 0 0 12px #DAA520, 0 0 32px rgba(0,0,0,0.8); }
            45% { box-shadow: 0 0 0 4px #f5d470, 0 0 0 8px #ba8c1d, 0 0 0 12px #ffd35e, 0 0 48px rgba(255,215,0,0.35); }
            100% { box-shadow: 0 0 0 4px #b8860b, 0 0 0 8px #8B6914, 0 0 0 12px #DAA520, 0 0 32px rgba(0,0,0,0.8); }
        }
        @keyframes gallery-frame-shadow-settle {
            0% { opacity: 0; transform: scaleX(0.45); }
            70% { opacity: 0.95; transform: scaleX(1.04); }
            100% { opacity: 0.7; transform: scaleX(0.75); }
        }
        .gallery-detail-footer {
            padding: 14px 18px; flex-shrink: 0; text-align: center;
        }
        .gallery-completed-label {
            font-size: 0.8rem; color: rgba(255,215,0,0.7);
            letter-spacing: 1px; margin-bottom: 10px;
        }
        @media (prefers-reduced-motion: reduce) {
            .gallery-frame.just-completed,
            .gallery-frame.just-completed::after {
                animation: none;
            }
        }

        /* 碎片掉落通知 */
        .fragment-toast {
            position: fixed; bottom: 90px; left: 50%;
            transform: translateX(-50%);
            background: rgba(10,30,15,0.95);
            border: 1px solid rgba(255,215,0,0.5);
            border-radius: 12px; padding: 10px 18px;
            display: flex; align-items: center; gap: 10px;
            z-index: 25000; pointer-events: none;
            animation: fragment-toast-anim 3s ease forwards;
        }
        @keyframes fragment-toast-anim {
            0%   { opacity: 0; transform: translateX(-50%) translateY(10px); }
            15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
            75%  { opacity: 1; }
            100% { opacity: 0; transform: translateX(-50%) translateY(-6px); }
        }
        .fragment-toast-thumb {
            width: 36px; height: 36px; border-radius: 4px;
            overflow: hidden; border: 1px solid rgba(255,215,0,0.4);
            flex-shrink: 0;
        }
        .fragment-toast-thumb img { width: 100%; height: 100%; object-fit: cover; }
        .fragment-toast-text { font-size: 0.82rem; color: rgba(255,255,255,0.9); }
        .fragment-toast-text strong { color: #ffd700; display: block; font-size: 0.88rem; }

        /* ── Home Screen ── */
        #home-screen {
            position: fixed;
            top: 0; right: 0; bottom: 0; left: 0;
            background: radial-gradient(ellipse at 25% 35%, #0f4a24 0%, #051d0e 65%);
            z-index: 20000;
            display: none;
            flex-direction: column;
            align-items: center;
            overflow-y: auto;
        }
        #home-screen.hiding {
            animation: home-fade-out 0.38s ease-out forwards;
            pointer-events: none;
        }
        @keyframes home-fade-out {
            to { opacity: 0; transform: scale(0.96); }
        }
        .home-content {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 14px;
            width: 280px;
            padding: 24px 20px;
            box-sizing: border-box;
            flex-shrink: 0;
            margin: auto;
        }
        .home-suits {
            font-size: 1.05rem;
            letter-spacing: 14px;
            color: rgba(255, 215, 0, 0.4);
            margin-bottom: -4px;
        }
        .home-title {
            font-family: 'Cinzel Decorative', 'Cinzel', Georgia, serif;
            font-size: 2.8rem;
            font-weight: 900;
            color: #ffd700;
            text-shadow: 0 0 32px rgba(255, 215, 0, 0.55), 0 4px 14px rgba(0, 0, 0, 0.8);
            margin: 0;
            line-height: 1;
        }
        .home-subtitle {
            font-size: 0.72rem;
            color: rgba(255, 255, 255, 0.4);
            letter-spacing: 4px;
            text-transform: uppercase;
            margin: 2px 0 0;
        }
        .home-divider {
            width: 48px;
            height: 1px;
            background: rgba(255, 215, 0, 0.35);
            margin: 4px 0 8px;
        }
        .home-actions {
            width: 100%;
            display: flex;
            flex-direction: column;
            gap: 10px;
        }
        .home-btn {
            display: block;
            width: 100%;
            min-height: 50px;
            padding: 12px 16px;
            border-radius: 14px;
            border: none;
            font-family: inherit;
            font-weight: 700;
            font-size: 1rem;
            cursor: pointer;
            letter-spacing: 0.3px;
            text-align: center;
            transition: transform 0.1s, opacity 0.1s;
        }
        .home-btn:active { transform: scale(0.97); opacity: 0.88; }
        .home-btn-primary {
            background: linear-gradient(135deg, #ffd700 0%, #ff9500 100%);
            color: #1a0800;
            font-size: 1.1rem;
        }
        .home-btn-continue {
            background: rgba(255, 215, 0, 0.13);
            border: 1px solid rgba(255, 215, 0, 0.45);
            color: #ffd700;
        }
        .home-btn-daily {
            background: rgba(255, 255, 255, 0.07);
            border: 1px solid rgba(255, 255, 255, 0.14);
            color: rgba(255, 255, 255, 0.82);
        }
        .home-text-links {
            width: 100%;
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 8px;
            margin-top: 8px;
        }
        .home-text-link {
            min-height: 34px;
            border-radius: 10px;
            border: 1px solid rgba(255, 255, 255, 0.2);
            background: rgba(255, 255, 255, 0.05);
            color: rgba(255, 255, 255, 0.72);
            font-family: inherit;
            font-size: 0.74rem;
            font-weight: 700;
            letter-spacing: 0.3px;
            cursor: pointer;
            padding: 6px 8px;
            text-align: center;
            transition: border-color 0.14s ease, background-color 0.14s ease, color 0.14s ease, transform 0.1s ease;
        }
        .home-text-link:hover {
            border-color: rgba(255, 215, 0, 0.33);
            color: rgba(255, 255, 255, 0.88);
            background: rgba(255, 255, 255, 0.08);
        }
        .home-text-link:active {
            transform: translateY(1px);
            color: #ffd700;
            background: rgba(255, 215, 0, 0.12);
            border-color: rgba(255, 215, 0, 0.45);
        }
        .home-text-link:focus-visible {
            outline: none;
            box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.28);
        }
        .home-ver {
            font-size: 0.62rem;
            color: rgba(255, 255, 255, 0.18);
            margin-top: 4px;
            letter-spacing: 1px;
        }
        /* landscape 縮排 */
        @media (orientation: landscape) and (max-height: 499px) {
            .home-content { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 10px 24px; max-width: 560px; }
            .home-title { font-size: 2rem; }
            .home-actions { max-width: 220px; gap: 8px; }
            .home-btn { min-height: 42px; font-size: 0.9rem; }
        }

/* ── Fragment fly-in animation ── */
.fragment-fly {
    position: fixed; z-index: 9999; pointer-events: none;
    transform-origin: center;
}
.fragment-fly img {
    width: 80px; height: 80px; object-fit: cover;
    border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
@keyframes fragment-appear {
    0%   { transform: scale(0); }
    80%  { transform: scale(1.2); }
    100% { transform: scale(1); }
}
.fragment-fly.appear { animation: fragment-appear 0.3s ease-out forwards; }
@keyframes widget-pulse {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.08); }
    100% { transform: scale(1); }
}
.widget-pulse { animation: widget-pulse 0.4s ease-out; }

/* ── Focus Widget ── */
.focus-widget {
    display: flex; align-items: center; gap: 10px;
    margin: 6px 12px; padding: 8px 12px;
    background: rgba(255,255,255,0.06);
    border-radius: 12px; cursor: pointer;
    border: 1px solid rgba(255,255,255,0.1);
}
.focus-widget-thumb {
    width: 40px; height: 40px; object-fit: cover;
    border-radius: 6px; flex-shrink: 0;
}
.focus-widget-info { flex: 1; min-width: 0; }
.focus-widget-title {
    font-size: 0.75rem; color: #e0d4b0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-bottom: 4px;
}
.focus-widget-bar-wrap {
    height: 4px; background: rgba(255,255,255,0.15); border-radius: 2px;
}
.focus-widget-bar-fill {
    height: 100%; background: #ffd700; border-radius: 2px;
    transition: width 0.4s ease;
}
.focus-widget-count { font-size: 0.7rem; color: #a0e0ff; flex-shrink: 0; }

/* ── Painting reveal ceremony ── */
.painting-reveal-overlay {
    position: fixed; inset: 0; z-index: 10000;
    display: flex; align-items: center; justify-content: center;
}
.reveal-backdrop {
    position: absolute; inset: 0; background: rgba(0,0,0,0.88);
}
.reveal-content {
    position: relative; z-index: 1;
    text-align: center; color: #fff; padding: 2rem 1.5rem;
    max-width: 360px; width: 90%;
}
.reveal-frame { max-width: 280px; margin: 0 auto 1rem; }
.reveal-frame img {
    width: 100%; border-radius: 12px;
    box-shadow: 0 8px 40px rgba(255,215,0,0.4);
    animation: reveal-zoom 1s ease-out both;
}
@keyframes reveal-zoom {
    from { transform: scale(0.3); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}
.reveal-title {
    font-size: 1.4rem; font-weight: bold; margin-bottom: 0.5rem;
    animation: fade-in-up 0.6s 0.5s both;
}
.reveal-badge {
    font-size: 1rem; color: #ffd700;
    animation: fade-in-up 0.6s 0.7s both;
}
@keyframes fade-in-up {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
.reveal-continue-btn {
    margin-top: 2rem; padding: 0.7rem 2.5rem;
    background: #ffd700; color: #1a1a1a;
    border: none; border-radius: 30px;
    font-size: 1rem; cursor: pointer;
    animation: fade-in-up 0.6s 1s both;
    -webkit-tap-highlight-color: transparent;
}

/* ── Streak flame ── */
.streak-flame {
    display: flex; align-items: center; gap: 2px;
    font-size: 0.75rem; margin-top: 2px;
}
.streak-flame.cool .flame-icon { filter: grayscale(0.7); opacity: 0.6; }
.streak-flame.warm .flame-icon { filter: none; }
.streak-flame.hot .flame-icon {
    animation: flame-blink 0.8s ease-in-out infinite alternate;
}
@keyframes flame-blink {
    from { filter: none; }
    to   { filter: drop-shadow(0 0 6px #ffd700) brightness(1.3); }
}
.flame-count { font-weight: bold; color: #ffa500; font-size: 0.7rem; }
.streak-flame.hot .flame-count { color: #ffd700; }

/* ── Win today progress band ── */
.win-today-progress {
    display: flex; flex-direction: column; align-items: center;
    gap: 6px; margin: 0.6rem 0;
}
.win-today-dots { display: flex; gap: 8px; }
.today-dot {
    width: 12px; height: 12px; border-radius: 50%;
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.4);
    transition: all 0.3s ease;
}
.today-dot.filled {
    background: #ffd700;
    border-color: #ffd700;
    box-shadow: 0 0 8px rgba(255,215,0,0.6);
}
.win-today-hint {
    font-size: 0.8rem; color: #a0e0ff;
    text-align: center; opacity: 0.9;
}

/* ── Win panel extras ── */
.win-streak-line { font-size: 0.85rem; color: #ffa500; margin: 0.3rem 0; }
.win-task-hint { font-size: 0.82rem; color: #a0e0ff; margin-top: 0.25rem; font-style: italic; }

/* ── Extreme Challenge ──────────────────────────────────────────── */
.home-btn-challenge {
    background: linear-gradient(135deg, #1a0a2e 0%, #3d1a6e 100%);
    border: 1px solid rgba(160, 80, 255, 0.6);
    color: #d4a8ff;
    font-size: 0.95rem;
    letter-spacing: 0.05em;
}
.home-btn-challenge:hover, .home-btn-challenge:active {
    background: linear-gradient(135deg, #2a0a4e 0%, #5d2a9e 100%);
    border-color: rgba(180, 100, 255, 0.9);
    color: #e8c8ff;
}

/* HUD bar */
.challenge-hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 12px;
    background: rgba(20, 5, 40, 0.92);
    border-bottom: 1px solid rgba(160, 80, 255, 0.4);
    font-size: 0.78rem;
    color: #d4a8ff;
    min-height: 28px;
    z-index: 10;
    position: relative;
}
.challenge-hud-name {
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #c084fc;
}
.challenge-hud-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
.challenge-hud-status {
    font-size: 0.78rem;
    color: #e2b8ff;
}
.challenge-hud-bar-wrap {
    width: 80px;
    height: 6px;
    background: rgba(255,255,255,0.12);
    border-radius: 3px;
    overflow: hidden;
}
.challenge-hud-bar {
    height: 100%;
    background: linear-gradient(90deg, #a855f7, #ec4899);
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0%;
}

/* Challenge Select Overlay */
.challenge-select-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 0, 15, 0.92);
    z-index: 3000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 0;
    overflow-y: auto;
}
.challenge-select-panel {
    width: 100%;
    max-width: 480px;
    min-height: 100%;
    background: linear-gradient(160deg, #0d0520 0%, #100a28 100%);
    padding: 0 0 32px;
}
.challenge-select-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 20px 12px;
    border-bottom: 1px solid rgba(160, 80, 255, 0.25);
}
.challenge-select-title {
    font-size: 1.25rem;
    color: #d4a8ff;
    margin: 0;
    letter-spacing: 0.06em;
}
.challenge-select-close {
    background: none;
    border: none;
    color: rgba(210,160,255,0.7);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}
.challenge-card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 16px 16px 0;
}
.challenge-card {
    background: linear-gradient(145deg, rgba(30,10,60,0.95) 0%, rgba(20,5,40,0.95) 100%);
    border: 1px solid rgba(120, 50, 200, 0.4);
    border-radius: 12px;
    padding: 14px 12px 12px;
    cursor: pointer;
    transition: border-color 0.18s, transform 0.15s;
    position: relative;
    min-height: 100px;
}
.challenge-card:active { transform: scale(0.97); }
.challenge-card.locked {
    opacity: 0.45;
    cursor: default;
    filter: grayscale(0.4);
}
.challenge-card.locked:active { transform: none; }
.challenge-card-hint {
    margin-top: 6px;
    font-size: 0.68rem;
    color: rgba(160,120,200,0.7);
    font-style: italic;
}
.challenge-card.completed {
    border-color: rgba(180, 120, 255, 0.7);
}
.challenge-card-name {
    font-size: 1.05rem;
    font-weight: 700;
    color: #e2b8ff;
    margin-bottom: 4px;
}
.challenge-card-cond {
    font-size: 0.72rem;
    color: rgba(200,150,255,0.75);
    line-height: 1.4;
}
.challenge-card-badge {
    display: inline-block;
    margin-top: 8px;
    background: linear-gradient(90deg, #7c3aed, #a855f7);
    color: #fff;
    font-size: 0.65rem;
    padding: 2px 7px;
    border-radius: 20px;
    letter-spacing: 0.04em;
}
.challenge-card-lock-icon {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 0.9rem;
    opacity: 0.6;
}
.challenge-card-done-icon {
    position: absolute;
    top: 10px;
    right: 10px;
    color: #a855f7;
    font-size: 0.9rem;
}
.challenge-card-num {
    font-size: 0.65rem;
    color: rgba(180,130,255,0.5);
    margin-bottom: 2px;
    letter-spacing: 0.06em;
}

/* Challenge Entry Overlay */
.challenge-entry-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 0, 15, 0.88);
    z-index: 3100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.challenge-entry-panel {
    background: linear-gradient(160deg, #0d0520 0%, #100a28 100%);
    border: 1px solid rgba(160, 80, 255, 0.5);
    border-radius: 18px;
    padding: 28px 24px 24px;
    max-width: 380px;
    width: 100%;
    text-align: center;
}
.challenge-entry-name {
    font-size: 1.6rem;
    font-weight: 700;
    color: #e2b8ff;
    letter-spacing: 0.08em;
    margin-bottom: 14px;
}
.challenge-entry-text {
    font-size: 0.88rem;
    color: rgba(220,185,255,0.85);
    line-height: 1.65;
    margin: 0 0 16px;
}
.challenge-entry-cond {
    background: rgba(120, 40, 200, 0.22);
    border: 1px solid rgba(160, 80, 255, 0.45);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.85rem;
    color: #c084fc;
    margin-bottom: 22px;
    font-weight: 600;
    letter-spacing: 0.04em;
}
.challenge-entry-actions {
    display: flex;
    gap: 10px;
}
.challenge-entry-start {
    flex: 1;
    background: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    padding: 12px 0;
    cursor: pointer;
    letter-spacing: 0.04em;
}
.challenge-entry-cancel {
    flex: 0 0 72px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 10px;
    color: rgba(220,185,255,0.7);
    font-size: 0.88rem;
    padding: 12px 0;
    cursor: pointer;
}

/* Challenge Fail Overlay */
.challenge-fail-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 0, 15, 0.88);
    z-index: 4000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.challenge-fail-panel {
    background: linear-gradient(160deg, #1a0505 0%, #200808 100%);
    border: 1px solid rgba(220, 60, 60, 0.5);
    border-radius: 18px;
    padding: 28px 24px 24px;
    max-width: 320px;
    width: 100%;
    text-align: center;
}
.challenge-fail-icon {
    font-size: 2.8rem;
    color: #f87171;
    margin-bottom: 8px;
}
.challenge-fail-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: #fca5a5;
    margin-bottom: 8px;
    letter-spacing: 0.06em;
}
.challenge-fail-msg {
    font-size: 0.85rem;
    color: rgba(255,160,160,0.75);
    margin-bottom: 22px;
    line-height: 1.5;
}
.challenge-fail-retry {
    width: 100%;
    background: linear-gradient(135deg, #7f1d1d 0%, #dc2626 100%);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    padding: 12px 0;
    cursor: pointer;
    margin-bottom: 10px;
    letter-spacing: 0.04em;
}
.challenge-fail-quit {
    width: 100%;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 10px;
    color: rgba(255,160,160,0.65);
    font-size: 0.88rem;
    padding: 10px 0;
    cursor: pointer;
}

/* Challenge Complete Overlay */
.challenge-complete-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 0, 15, 0.88);
    z-index: 4000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.challenge-complete-panel {
    background: linear-gradient(160deg, #0d0520 0%, #100a28 100%);
    border: 1px solid rgba(180, 100, 255, 0.7);
    border-radius: 18px;
    padding: 32px 24px 26px;
    max-width: 320px;
    width: 100%;
    text-align: center;
    box-shadow: 0 0 40px rgba(160, 80, 255, 0.25);
}
.challenge-complete-icon {
    font-size: 3rem;
    color: #c084fc;
    margin-bottom: 10px;
    animation: challenge-complete-pulse 1.2s ease infinite;
}
@keyframes challenge-complete-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.85; }
}
.challenge-complete-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: #e2b8ff;
    letter-spacing: 0.08em;
    margin-bottom: 6px;
}
.challenge-complete-sub {
    font-size: 1rem;
    color: #c084fc;
    margin-bottom: 16px;
    letter-spacing: 0.04em;
}
.challenge-complete-cardback {
    background: rgba(120, 40, 200, 0.18);
    border: 1px solid rgba(160, 80, 255, 0.35);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.82rem;
    color: rgba(210,165,255,0.8);
    margin-bottom: 22px;
    line-height: 1.4;
}
.challenge-complete-ok {
    width: 100%;
    background: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    padding: 12px 0;
    cursor: pointer;
    letter-spacing: 0.04em;
}

/* Undo-blocked toast */
.challenge-undo-blocked {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(40, 5, 80, 0.95);
    border: 1px solid rgba(160, 80, 255, 0.6);
    color: #d4a8ff;
    font-size: 0.85rem;
    padding: 8px 18px;
    border-radius: 20px;
    z-index: 5000;
    pointer-events: none;
    animation: challenge-undo-block-in 0.2s ease;
}
@keyframes challenge-undo-block-in {
    from { opacity: 0; transform: translateX(-50%) translateY(8px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Tablet portrait layout: keep the phone flow, but size it like a native tablet table. */
@media (orientation: portrait) and (min-width: 600px) {
    :root {
        --board-max-width: 620px;
        --board-gap: 18px;
    }

    #header {
        padding: 12px 16px;
    }

    .header-main {
        min-height: 54px;
        gap: 14px;
    }

    .header-stat {
        min-width: 104px;
        font-size: 15px;
    }

    .header-title {
        font-size: 1.55rem;
        letter-spacing: 1.2px;
    }

    .timer-pill {
        min-width: 124px;
        padding: 9px 14px;
        font-size: 19px;
    }

    .header-settings {
        min-width: 54px;
        min-height: 52px;
        padding: 10px 12px;
    }

    #board {
        width: min(100%, var(--board-max-width));
        gap: var(--board-gap);
        padding: 26px 12px 20px;
        align-items: flex-start;
    }

    .card {
        border-radius: 7px;
        padding: 7px;
    }

    .card::before {
        inset: 4px;
    }

    .card-corner {
        font-size: 0.9rem;
    }

    .card-tl {
        top: 6px;
        left: 7px;
    }

    .card-suit-tr {
        top: 8px;
        right: 7.5px;
    }

    .card-br {
        bottom: 6px;
        right: 7px;
    }
    .card-br { display: none; }

    .card-center-suit {
        font-size: calc(3.8rem * var(--card-suit-scale));
    }

    #footer {
        justify-content: center;
        gap: 56px;
        padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
    }

    #footer > div {
        flex: 0 0 96px;
        justify-content: center;
    }

    .pile {
        width: 68px;
        height: 94px;
    }

    #deck-pile {
        font-size: 30px;
    }

    #btn-undo {
        width: 60px;
        height: 60px;
    }

    #btn-undo svg {
        width: 28px;
        height: 28px;
    }

    #deal-label,
    #recycle-label {
        font-size: 11px;
    }

    .need-three-tip {
        bottom: calc(118px + env(safe-area-inset-bottom));
    }

    .home-content {
        width: 360px;
        gap: 16px;
        padding: 30px 24px;
    }

    .home-title {
        font-size: 3.4rem;
    }

    .home-btn {
        min-height: 56px;
        font-size: 1.05rem;
    }

    .achievement-panel,
    .rules-panel,
    .leaderboard-panel {
        width: min(560px, calc(100vw - 48px));
        max-height: 84dvh;
        padding: 20px;
    }

    .restart-panel {
        width: min(460px, calc(100vw - 48px));
        padding: 20px;
    }

    .tutorial-overlay {
        width: min(520px, calc(100vw - 48px));
    }

    .premium-panel {
        width: min(440px, calc(100vw - 48px));
    }

    .challenge-select-overlay {
        align-items: flex-start;
        padding: 24px 0;
    }

    .challenge-select-panel {
        width: min(560px, calc(100vw - 48px));
        min-height: auto;
        border: 1px solid rgba(160, 80, 255, 0.25);
        border-radius: 14px;
        overflow: hidden;
    }
}

@media (orientation: portrait) and (min-width: 800px) {
    :root {
        --board-max-width: 760px;
        --board-gap: 22px;
    }

    #header {
        padding: 14px 20px;
    }

    .header-main {
        min-height: 60px;
        gap: 18px;
    }

    .header-stat {
        min-width: 124px;
        font-size: 17px;
    }

    .header-title {
        font-size: 1.9rem;
    }

    .timer-pill {
        min-width: 148px;
        font-size: 22px;
    }

    #board {
        padding: 30px 16px 24px;
    }

    #footer {
        gap: 78px;
        padding: 20px 22px calc(20px + env(safe-area-inset-bottom));
    }

    #footer > div {
        flex-basis: 112px;
    }

    .pile {
        width: 76px;
        height: 105px;
    }

    #deck-pile {
        font-size: 34px;
    }

    #btn-undo {
        width: 68px;
        height: 68px;
    }

    #btn-undo svg {
        width: 32px;
        height: 32px;
    }

    #deal-label,
    #recycle-label {
        font-size: 12px;
    }

    .need-three-tip {
        bottom: calc(132px + env(safe-area-inset-bottom));
    }

    .home-content {
        width: 420px;
        gap: 18px;
        padding: 36px 28px;
    }

    .home-title {
        font-size: 4rem;
    }

    .home-btn {
        min-height: 60px;
        font-size: 1.1rem;
    }

    .achievement-panel,
    .rules-panel,
    .leaderboard-panel {
        width: min(680px, calc(100vw - 64px));
        max-height: 86dvh;
        padding: 22px;
    }

    .settings-title,
    .achievement-title,
    .rules-title,
    .leaderboard-title {
        font-size: 1.35rem;
    }

    .restart-panel {
        width: min(520px, calc(100vw - 64px));
    }

    .tutorial-overlay {
        width: min(600px, calc(100vw - 64px));
    }

    .premium-panel {
        width: min(500px, calc(100vw - 64px));
    }

    .challenge-select-panel {
        width: min(680px, calc(100vw - 64px));
    }
}

@media (orientation: portrait) and (min-width: 1024px) {
    :root {
        --board-max-width: 820px;
        --board-gap: 24px;
    }

    #board {
        padding-top: 34px;
    }
}
