        *, *::before, *::after { box-sizing: border-box; }

        html, body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow-x: hidden; /* prevent horizontal scrollbars on mobile/desktop */
        }

        :root {
            --header-h: 68px;
            --header-pad-y: 10px;
            --header-pad-x: 12px;
            --header-gap: 10px;

            --btn-size: 44px;
            --btn-radius: 14px;
            --icon-size: 20px;

            --level-font: 20px;
            --score-label-font: 11px;
            --score-value-font: 18px;

            --pill-pad-y: 8px;
            --pill-pad-x: 14px;

            --board-inset: 10px; /* used by JS scale padding */

            --overlay-pad: 18px;

            --card-radius: 24px;
            --level-card-radius: 18px;
            --tile-w: 48px;
            --tile-h: 66px;
            --tile-gap: 4px;
            --tile-radius: 6px;
            --tile-face-pad: 0;
            --tile-emoji-font: 26px;
            --tile-emoji-big-font: 30px;
            --tile-lift-x: -1px;
            --tile-lift-y: -1px;
            --tile-press-x: 5px;
            --tile-press-y: 5px;

            /* Realistic tile palette (reference demo) */
            --tile-top-bg: #f9f7f1;
            --tile-top-highlight: #ffffff;
            --bone-1: #e4ddcd;
            --bone-2: #dfd6c2;
            --bone-3: #d3c8af;
            --bone-4: #c9bc9e;
            --base-1: #2a7a44;
            --base-2: #216336;
            --base-3: #184c28;
            --base-4: #10331b;
            /* Bone (thinner) + green base (deeper) */
            --tile-shadow-rest:
                inset 1px 1px 2px rgba(255, 255, 255, 1),
                inset -1px -1px 2px rgba(0, 0, 0, 0.05),
                1px 1px 0px var(--bone-1),
                2px 2px 0px var(--bone-3),
                3px 3px 0px var(--base-1),
                4px 4px 0px var(--base-1),
                5px 5px 0px var(--base-2),
                6px 6px 0px var(--base-3),
                7px 7px 0px var(--base-4),
                9px 9px 8px rgba(0, 0, 0, 0.45),
                11px 11px 14px rgba(0, 0, 0, 0.35);
            --tile-shadow-hover:
                inset 1px 1px 2px rgba(255, 255, 255, 1),
                inset -1px -1px 2px rgba(0, 0, 0, 0.05),
                1px 1px 0px var(--bone-1),
                2px 2px 0px var(--bone-2),
                3px 3px 0px var(--bone-4),
                4px 4px 0px var(--base-1),
                5px 5px 0px var(--base-1),
                6px 6px 0px var(--base-2),
                7px 7px 0px var(--base-3),
                8px 8px 0px var(--base-3),
                9px 9px 0px var(--base-4),
                11px 11px 10px rgba(0, 0, 0, 0.4),
                13px 13px 16px rgba(0, 0, 0, 0.3);
            --tile-shadow-active:
                inset 1px 1px 2px rgba(255, 255, 255, 1),
                inset -1px -1px 2px rgba(0, 0, 0, 0.05),
                1px 1px 0px var(--bone-1),
                2px 2px 0px var(--base-1),
                3px 3px 0px var(--base-2),
                4px 4px 0px var(--base-3),
                5px 5px 0px var(--base-4),
                7px 7px 8px rgba(0, 0, 0, 0.55);

            --modal-gap: 18px;
            --start-gap: 22px;

            --modal-btn-margin-top: 6px;
            --start-btn-margin-top: 12px;
            --start-logo-margin-bottom: -10px;

            --modal-card-pad: 22px;
            --modal-title-font: 26px;
            --modal-desc-font: 16px;
            --modal-btn-font: 18px;
            --modal-btn-pad-y: 12px;
            --modal-btn-pad-x: 18px;

            --start-level-label-font: 16px;
            --start-level-value-font: 40px;
        }

        body {
            font-family: 'Nunito', sans-serif;
            background-color: #123e25;
            background-image: 
                url("../img/bg.png"),
                radial-gradient(1200px 800px at 50% 45%, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.35) 70%, rgba(0, 0, 0, 0.55) 100%);
            background-size: cover, auto;
            background-position: center, center;
            background-repeat: no-repeat, no-repeat;
            overflow: hidden;
            touch-action: none;
            user-select: none;
            -webkit-user-select: none;
        }

        /* --- APP LAYOUT --- */
        .app {
            width: 100%;
            /* Fallback */
            min-height: 100vh;
            height: 100vh;
            display: grid;
            grid-template-rows: var(--header-h) 1fr;
            position: relative;
            color: #1f2937;
        }

        /* Universal fix for mobile browser UI resizing */
        @supports (height: 100dvh) {
            .app {
                min-height: 100dvh;
                height: 100dvh;
            }
        }

        body.is-start-open .app-header,
        body.is-start-open .board-container,
        body.is-victory-open .app-header,
        body.is-victory-open .board-container {
            visibility: hidden;
        }

        .app-header {
            width: 100%;
            height: var(--header-h);
            padding: var(--header-pad-y) var(--header-pad-x);
            padding-left: calc(var(--header-pad-x) + env(safe-area-inset-left));
            padding-right: calc(var(--header-pad-x) + env(safe-area-inset-right));
            display: grid;
            grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
            align-items: center;
            position: relative;
            z-index: 50;
            pointer-events: none;
            gap: var(--header-gap);
            overflow: hidden;
        }

        .header-left,
        .header-right {
            display: flex;
            align-items: center;
            gap: var(--header-gap);
            pointer-events: none;
            min-width: 0;
        }

        .header-left {
            justify-self: start;
        }

        .header-right {
            justify-self: end;
        }

        .header-actions {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .header-left > *,
        .header-right > * {
            pointer-events: auto;
        }

        .level-pill {
            background: transparent;
            -webkit-backdrop-filter: none;
            backdrop-filter: none;
            border: 0;
            padding: 0 6px;
            border-radius: 0;
            box-shadow: none;
            max-width: 100%;
            overflow: hidden;
        }

        .level-title {
            color: #ffffff;
            font-weight: 900;
            font-size: var(--level-font);
            letter-spacing: 0.12em;
            text-transform: uppercase;
            margin: 0;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
        }

        .score-pill {
            background: rgba(255, 255, 255, 0.08);
            -webkit-backdrop-filter: blur(10px);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.14);
            padding: var(--pill-pad-y) var(--pill-pad-x);
            border-radius: 9999px;
            box-shadow: 0 10px 18px rgba(0, 0, 0, 0.25);
            display: flex;
            align-items: baseline;
            gap: 10px;
            max-width: 100%;
            overflow: hidden;
            white-space: nowrap;
        }

        .score-pill--center {
            justify-self: center;
            pointer-events: auto;
        }

        .header-action-btn {
            pointer-events: auto;
            width: var(--btn-size);
            height: var(--btn-size);
            padding: 0;
            border-radius: var(--btn-radius);
            cursor: pointer;
            color: rgba(255, 244, 214, 0.98);
            background:
                radial-gradient(120% 120% at 30% 25%, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0.04) 28%, rgba(0, 0, 0, 0) 55%),
                linear-gradient(180deg, rgba(22, 33, 34, 0.92), rgba(8, 14, 15, 0.92));
            border: 1px solid rgba(246, 207, 126, 0.8);
            box-shadow:
                0 12px 20px rgba(0, 0, 0, 0.42),
                inset 0 1px 0 rgba(255, 255, 255, 0.08),
                inset 0 -10px 18px rgba(0, 0, 0, 0.45);
            display: grid;
            place-items: center;
            transition: transform 0.15s ease, filter 0.15s ease;
            -webkit-appearance: none;
            appearance: none;
            line-height: 1;
        }

        .header-action-btn:hover { filter: brightness(1.08); }
        .header-action-btn:active { transform: scale(0.96); }

        .header-action-icon { display: grid; place-items: center; }

        .icon {
            width: var(--icon-size);
            height: var(--icon-size);
        }

        .score-label {
            color: rgba(255, 255, 255, 0.75);
            font-weight: 900;
            font-size: var(--score-label-font);
            letter-spacing: 0.18em;
            text-transform: uppercase;
        }

        .score-value {
            color: #fef3c7;
            font-weight: 900;
            font-size: var(--score-value-font);
            letter-spacing: 0.06em;
            font-variant-numeric: tabular-nums;
            white-space: nowrap;
        }

        .score-pill.score-bump {
            animation: scoreBump 0.22s ease-out;
        }

        .board-container {
            width: 100%;
            position: relative;
            overflow: hidden;
            z-index: 10;
            isolation: isolate;
            padding-left: calc(env(safe-area-inset-left));
            padding-right: calc(env(safe-area-inset-right));
        }

        .board-container::after {
            content: "";
            position: absolute;
            inset: 0;
            background:
                radial-gradient(900px 700px at 50% 40%, rgba(255, 255, 255, 0.04), rgba(0, 0, 0, 0.10) 60%, rgba(0, 0, 0, 0.28));
            pointer-events: none;
            z-index: 0;
        }

        .game-board {
            position: absolute;
            left: 50%;
            top: 50%;
            width: var(--board-w, auto);
            height: var(--board-h, auto);
            transform: translate(-50%, -50%) scale(var(--board-scale, 1));
            transform-origin: center center;
            filter: drop-shadow(0px 26px 40px rgba(0, 0, 0, 0.55));
            z-index: 2;
        }

        .shard {
            position: absolute;
            border-radius: 2px;
            transform: translate(-50%, -50%);
            pointer-events: none;
            z-index: 300000;
            opacity: 1;
            animation: shardFly 0.62s ease-out forwards;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
            width: var(--w, 6px);
            height: var(--h, 6px);
            left: var(--x, 0px);
            top: var(--y, 0px);
            animation-duration: var(--dur, 0.5s);
        }

        .shard--c0 { background: #fde68a; }
        .shard--c1 { background: #f59e0b; }
        .shard--c2 { background: #ffffff; }
        .shard--c3 { background: #e5e7eb; }
        .shard--c4 { background: #92400e; }
        .shard--c5 { background: #111827; }
        .shard--c6 { background: #34d399; }
        .shard--c7 { background: #fbbf24; }

        /* --- RESPONSIVE BREAKPOINTS --- */

        /* Small Mobile (≤480px) */
        @media (max-width: 480px) {
            :root {
                --header-h: 56px;
                --header-pad-y: 6px;
                --header-pad-x: 10px;
                --header-gap: 8px;

                --btn-size: 38px;
                --btn-radius: 12px;
                --icon-size: 18px;

                --level-font: 16px;
                --score-label-font: 10px;
                --score-value-font: 15px;

                --pill-pad-y: 6px;
                --pill-pad-x: 10px;

                --overlay-pad: 14px;
                --card-radius: 20px;
                --level-card-radius: 16px;
                --tile-face-pad: 0;
                --tile-emoji-font: 24px;
                --tile-emoji-big-font: 28px;
                --modal-gap: 14px;
                --start-gap: 16px;

                --modal-btn-margin-top: 6px;
                --start-btn-margin-top: 10px;
                --start-logo-margin-bottom: -6px;
                --modal-card-pad: 18px;
                --modal-title-font: 22px;
                --modal-desc-font: 14px;
                --modal-btn-font: 16px;
                --modal-btn-pad-y: 11px;
                --modal-btn-pad-x: 16px;

                --start-level-label-font: 14px;
                --start-level-value-font: 34px;
            }

            .header-actions { gap: 6px; }
            .score-pill { gap: 8px; }

            .app-header {
                row-gap: 6px;
                padding-bottom: 8px;
            }
        }

        /* Mobile (481px–640px) */
        @media (min-width: 481px) and (max-width: 640px) {
            :root {
                --header-h: 60px;
                --header-pad-y: 8px;
                --header-pad-x: 10px;

                --btn-size: 42px;
                --icon-size: 19px;
                --level-font: 18px;
                --score-value-font: 16px;

                --overlay-pad: 16px;
                --card-radius: 22px;
                --modal-gap: 16px;
                --start-gap: 18px;
                --start-level-value-font: 38px;
            }

            .header-actions { gap: 8px; }

            .app-header {
                row-gap: 6px;
                padding-bottom: 8px;
            }
        }

        /* Tablet Portrait (641px–768px) */
        @media (min-width: 641px) and (max-width: 768px) {
            :root {
                --header-h: 68px;
                --header-pad-x: 12px;
                --header-pad-y: 10px;
                --level-font: 19px;
                --score-value-font: 18px;
            }
        }

        /* Mobile & tablet portrait: score on second row */
        @media (max-width: 768px) {
            .app {
                grid-template-rows: auto 1fr;
            }

            .app-header {
                height: auto;
                grid-template-columns: minmax(0, 1fr) auto;
                grid-template-rows: auto auto;
                row-gap: 4px;
                align-content: center;
            }

            .header-left {
                grid-column: 1;
                grid-row: 1;
            }

            .header-right {
                grid-column: 2;
                grid-row: 1;
            }

            .score-pill--center {
                grid-column: 1 / -1;
                grid-row: 2;
                justify-self: center;
            }
        }

        /* Tablet Landscape (769px–1024px) */
        @media (min-width: 769px) and (max-width: 1024px) {
            :root {
                --header-h: 70px;
                --header-pad-x: 12px;
                --level-font: 20px;
            }
        }

        /* Desktop (≥1025px) */
        @media (min-width: 1025px) {
            :root {
                --header-h: 72px;
                --header-pad-x: 14px;
                --btn-size: 46px;
                --icon-size: 21px;
                --level-font: 21px;
                --score-value-font: 19px;
            }
        }

        /* Landscape Mobile (orientation: landscape) */
        @media (max-width: 896px) and (orientation: landscape) {
            :root {
                --header-h: 48px;
                --header-pad-y: 6px;
                --header-pad-x: 10px;
                --btn-size: 36px;
                --icon-size: 18px;
                --level-font: 15px;
                --score-value-font: 14px;
                --pill-pad-y: 6px;
                --pill-pad-x: 10px;

                --overlay-pad: 12px;
                --card-radius: 18px;
                --level-card-radius: 14px;
                --tile-face-pad: 0;
                --tile-emoji-font: 22px;
                --tile-emoji-big-font: 26px;
                --modal-gap: 12px;
                --start-gap: 14px;

                --modal-btn-margin-top: 4px;
                --start-btn-margin-top: 8px;
                --start-logo-margin-bottom: -4px;

                --modal-card-pad: 16px;
                --modal-title-font: 20px;
                --modal-desc-font: 13px;
                --modal-btn-font: 15px;
                --modal-btn-pad-y: 10px;
                --modal-btn-pad-x: 14px;

                --start-level-label-font: 13px;
                --start-level-value-font: 32px;
            }

            .app-header {
                row-gap: 4px;
            }
        }

        @keyframes scoreBump {
            0% { transform: scale(1); }
            55% { transform: scale(1.06); }
            100% { transform: scale(1); }
        }


        .float-score {
            position: absolute;
            left: 50%;
            top: 44%;
            transform: translate3d(-50%, -50%, 0);
            color: #fef3c7;
            font-weight: 900;
            letter-spacing: 0.08em;
            text-shadow: 0 10px 22px rgba(0, 0, 0, 0.55);
            pointer-events: none;
            z-index: 250;
            animation: floatScore 0.75s ease-out forwards;
            -webkit-font-smoothing: antialiased;
        }

        @keyframes floatScore {
            0% { opacity: 0; transform: translate3d(-50%, -40%, 0) scale(0.92); }
            20% { opacity: 1; }
            100% { opacity: 0; transform: translate3d(-50%, -120%, 0) scale(1.05); }
        }

        .modal {
            position: fixed;
            inset: 0;
            z-index: 9999;
            display: grid;
            place-items: center;
            padding: var(--overlay-pad);
            background: transparent;
        }

        .modal--dim {
            z-index: 10020;
            background: rgba(0, 0, 0, 0.48);
            -webkit-backdrop-filter: blur(3px);
            backdrop-filter: blur(3px);
        }

        .settings-panel {
            width: 100%;
            display: flex;
            flex-direction: column;
            gap: 12px;
            text-align: left;
        }

        .settings-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 14px;
            width: 100%;
            padding: 14px 16px;
            border-radius: 14px;
            background:
                linear-gradient(145deg, rgba(255, 255, 255, 0.06) 0%, rgba(0, 0, 0, 0) 50%),
                rgba(0, 0, 0, 0.28);
            border: 1px solid rgba(246, 207, 126, 0.38);
            box-shadow:
                inset 0 1px 0 rgba(255, 255, 255, 0.07),
                0 8px 20px rgba(0, 0, 0, 0.28);
        }

        .settings-row__text {
            min-width: 0;
            display: flex;
            flex-direction: column;
            gap: 3px;
        }

        .settings-row__title {
            font-weight: 900;
            font-size: clamp(14px, 3.6vw, 16px);
            color: rgba(255, 244, 214, 0.98);
            letter-spacing: 0.04em;
        }

        .settings-row__desc {
            font-size: clamp(11px, 3vw, 12px);
            font-weight: 700;
            color: rgba(255, 255, 255, 0.52);
            line-height: 1.3;
        }

        .game-switch {
            position: relative;
            flex-shrink: 0;
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
        }

        .game-switch__input {
            position: absolute;
            opacity: 0;
            width: 1px;
            height: 1px;
            margin: 0;
            padding: 0;
            clip: rect(0 0 0 0);
            clip-path: inset(50%);
            overflow: hidden;
        }

        .game-switch__track {
            display: block;
            width: 3.35rem;
            height: 1.85rem;
            border-radius: 9999px;
            position: relative;
            background: linear-gradient(180deg, rgba(30, 38, 42, 0.98), rgba(12, 18, 20, 0.99));
            border: 2px solid rgba(100, 116, 125, 0.65);
            box-shadow:
                inset 0 2px 6px rgba(0, 0, 0, 0.55),
                0 1px 0 rgba(255, 255, 255, 0.06);
            transition: border-color 0.2s ease, box-shadow 0.2s ease;
        }

        .game-switch__thumb {
            position: absolute;
            top: 3px;
            left: 3px;
            width: calc(1.85rem - 10px);
            height: calc(1.85rem - 10px);
            border-radius: 50%;
            background: linear-gradient(165deg, #9ca3af 0%, #4b5563 45%, #374151 100%);
            box-shadow:
                0 2px 6px rgba(0, 0, 0, 0.45),
                inset 0 1px 0 rgba(255, 255, 255, 0.35);
            transform: translateX(0);
            transition:
                transform 0.22s cubic-bezier(0.34, 1.2, 0.64, 1),
                background 0.2s ease,
                box-shadow 0.2s ease;
        }

        .game-switch__input:checked + .game-switch__track {
            border-color: rgba(252, 211, 77, 0.75);
            box-shadow:
                inset 0 2px 6px rgba(0, 0, 0, 0.35),
                0 0 22px rgba(251, 191, 36, 0.28);
        }

        .game-switch__input:checked + .game-switch__track .game-switch__thumb {
            transform: translateX(calc(3.35rem - 6px - (1.85rem - 10px)));
            background: linear-gradient(165deg, #fef3c7 0%, #fbbf24 40%, #d97706 100%);
            box-shadow:
                0 2px 8px rgba(217, 119, 6, 0.45),
                inset 0 1px 0 rgba(255, 255, 255, 0.55);
        }

        .game-switch__input:focus-visible + .game-switch__track {
            outline: 2px solid #fde68a;
            outline-offset: 3px;
        }

        .modal-prose {
            width: 100%;
            text-align: left;
            font-weight: 700;
            font-size: clamp(13px, 3.5vw, 15px);
            line-height: 1.5;
            color: rgba(255, 250, 235, 0.92);
        }

        .modal-prose p {
            margin: 0 0 0.75rem;
        }

        .modal-prose p:last-child {
            margin-bottom: 0;
        }

        .modal-prose ul {
            margin: 0 0 0.75rem;
            padding-left: 1.15rem;
        }

        .modal-prose ul:last-child {
            margin-bottom: 0;
        }

        .modal-prose li {
            margin-bottom: 0.45rem;
        }

        .modal-prose strong {
            color: #fde68a;
            font-weight: 900;
        }

        p.modal-prose.modal-prose--single {
            margin: 0;
        }

        .modal-prose--center {
            text-align: center;
        }

        .modal__card {
            width: min(420px, 92vw);
            border-radius: var(--card-radius);
            padding: var(--modal-card-pad);
            position: relative;
            color: rgba(255, 244, 214, 0.98);
            border: 1px solid rgba(246, 207, 126, 0.78);
            background:
                radial-gradient(140% 120% at 20% 10%, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0.05) 30%, rgba(0, 0, 0, 0) 55%),
                linear-gradient(180deg, rgba(22, 33, 34, 0.94), rgba(8, 14, 15, 0.94));
            box-shadow:
                0 30px 60px rgba(0, 0, 0, 0.55),
                inset 0 1px 0 rgba(255, 255, 255, 0.08),
                0 0 0 1px rgba(0, 0, 0, 0.25);
            display: grid;
            gap: var(--modal-gap);
            justify-items: center;
            text-align: center;
        }

        .modal__card.modal__card--panel {
            width: min(460px, 94vw);
            justify-items: stretch;
        }

        .modal-heading {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 0.35rem;
            margin: 0;
            width: 100%;
        }

        .modal-heading .modal-icon {
            font-size: clamp(4.25rem, 20vw, 6.75rem);
            line-height: 0.92;
            margin: 0;
            padding: 0;
            font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", system-ui, sans-serif;
            filter: drop-shadow(0 3px 10px rgba(0, 0, 0, 0.35));
        }

        .modal-heading .modal-icon.is-hidden {
            display: none;
        }

        .modal-heading .modal-title {
            margin: 0;
        }

        .modal-title {
            font-size: var(--modal-title-font);
            font-weight: 900;
            margin: 0;
            text-align: center;
            letter-spacing: 0.08em;
            text-transform: uppercase;
            color: #ffffff;
        }

        .modal-title--success { color: #34d399; }

        .modal-actions {
            display: flex;
            flex-direction: row;
            flex-wrap: wrap;
            gap: 10px;
            width: 100%;
            margin-top: var(--modal-btn-margin-top);
            justify-content: stretch;
        }

        .modal-actions .modal-btn {
            flex: 1 1 120px;
            margin-top: 0;
            width: auto;
            min-width: 0;
        }

        .modal-btn {
            width: 100%;
            margin-top: var(--modal-btn-margin-top);
            padding: var(--modal-btn-pad-y) var(--modal-btn-pad-x);
            background: linear-gradient(to bottom, #fde68a, #f59e0b);
            color: #111827;
            font-weight: 900;
            border-radius: 9999px;
            font-size: var(--modal-btn-font);
            letter-spacing: 0.08em;
            text-transform: uppercase;
            border: 2px solid rgba(252, 211, 77, 0.95);
            cursor: pointer;
            transition: transform 0.15s ease, filter 0.15s ease;
            box-shadow: 0 0 34px rgba(251, 191, 36, 0.45);
        }

        .modal-btn:hover { filter: brightness(1.06); transform: scale(1.02); }
        .modal-btn:active { transform: scale(0.98); }

        .modal-btn--secondary {
            background: linear-gradient(180deg, rgba(55, 65, 81, 0.95), rgba(31, 41, 55, 0.98));
            color: rgba(255, 244, 214, 0.98);
            border: 2px solid rgba(156, 163, 175, 0.65);
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.35);
        }

        .modal-btn--secondary:hover { filter: brightness(1.12); }
        .modal-btn--secondary:active { transform: scale(0.98); }

        /* --- START/HOME MODAL --- */
        .start-modal {
            position: fixed;
            inset: 0;
            z-index: 10000;
            display: grid;
            place-items: center;
            padding: var(--overlay-pad);
            padding-top: calc(var(--overlay-pad) + env(safe-area-inset-top));
            padding-bottom: calc(var(--overlay-pad) + env(safe-area-inset-bottom));
            background: transparent;
            overflow: auto;
        }

        .start-modal--dim {
            background: rgba(0, 0, 0, 0.48);
            -webkit-backdrop-filter: blur(3px);
            backdrop-filter: blur(3px);
        }

        .start-modal__card {
            width: min(460px, 94vw);
            border-radius: var(--card-radius);
            padding: var(--modal-card-pad);
            position: relative;
            color: rgba(255, 244, 214, 0.98);
            border: 1px solid rgba(246, 207, 126, 0.78);
            background:
                radial-gradient(140% 120% at 20% 10%, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0.05) 30%, rgba(0, 0, 0, 0) 55%),
                linear-gradient(180deg, rgba(22, 33, 34, 0.94), rgba(8, 14, 15, 0.94));
            box-shadow:
                0 30px 60px rgba(0, 0, 0, 0.55),
                inset 0 1px 0 rgba(255, 255, 255, 0.08),
                0 0 0 1px rgba(0, 0, 0, 0.25);
            display: grid;
            gap: var(--start-gap);
            justify-items: center;
            text-align: center;
            max-height: calc(100dvh - (var(--overlay-pad) * 2) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
            overflow: auto;
            -webkit-overflow-scrolling: touch;
            /* prevent inner content from forcing horizontal overflow */
            max-width: 100%;
        }

        .start-modal__logo {
            /* Never use vw inside a constrained card: it can overflow on some devices */
            width: 100%;
            max-width: 380px;
            max-height: min(38vh, 260px);
            height: auto;
            object-fit: contain;
            display: block;
            margin-bottom: var(--start-logo-margin-bottom);
            filter: drop-shadow(0 18px 26px rgba(0, 0, 0, 0.55));
        }

        /* Short viewports (mobile landscape, devtools, foldables) */
        @media (max-height: 720px) {
            .start-modal__logo { max-height: min(26vh, 200px); }
        }

        .start-modal__level-card {
            width: 132px;
            max-width: 58vw;
            aspect-ratio: 1 / 1;
            border-radius: var(--level-card-radius);
            padding: clamp(6px, 1.6vw, 8px);
            border: 1px solid rgba(255, 255, 255, 0.12);
            background: rgba(0, 0, 0, 0.28);
            -webkit-backdrop-filter: blur(10px);
            backdrop-filter: blur(10px);
            box-shadow: 0 14px 22px rgba(0, 0, 0, 0.35);
            display: grid;
            gap: clamp(4px, 1vw, 6px);
            place-content: center;
            justify-items: center;
        }

        .start-modal__level-label {
            font-weight: 900;
            font-size: var(--start-level-label-font);
            letter-spacing: 0.2em;
            text-transform: uppercase;
            opacity: 0.85;
            text-align: center;
            width: 100%;
            line-height: 1.1;
        }

        .start-modal__level-value {
            font-weight: 900;
            font-size: var(--start-level-value-font);
            letter-spacing: 0.06em;
            color: #fef3c7;
            font-variant-numeric: tabular-nums;
        }

        .start-modal__btn {
            width: 100%;
            margin-top: var(--start-btn-margin-top);
            padding: var(--modal-btn-pad-y) var(--modal-btn-pad-x);
            border-radius: 9999px;
            font-weight: 900;
            font-size: var(--modal-btn-font);
            letter-spacing: 0.08em;
            text-transform: uppercase;
            cursor: pointer;
            color: #111827;
            border: 2px solid rgba(252, 211, 77, 0.95);
            background: linear-gradient(to bottom, #fde68a, #f59e0b);
            box-shadow: 0 0 34px rgba(251, 191, 36, 0.45);
            transition: transform 0.15s ease, filter 0.15s ease;
        }

        .start-modal__btn:hover { filter: brightness(1.06); transform: scale(1.02); }
        .start-modal__btn:active { transform: scale(0.98); }

        .is-hidden {
            display: none !important;
        }

        /* --- TILE & BOARD STYLING (reference: realistic 3D demo) --- */
        .game-tile {
            position: absolute;
            left: var(--tile-left, 0px);
            top: var(--tile-top, 0px);
            z-index: var(--tile-z, 0);
            width: var(--tile-w);
            height: var(--tile-h);
            background: linear-gradient(135deg, var(--tile-top-highlight) 0%, var(--tile-top-bg) 60%);
            border-radius: var(--tile-radius);
            border: none;
            cursor: pointer;
            display: flex;
            justify-content: center;
            align-items: center;
            user-select: none;
            -webkit-user-select: none;
            box-shadow: var(--tile-shadow-rest);
            transition:
                transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1),
                box-shadow 0.15s cubic-bezier(0.2, 0.8, 0.2, 1),
                filter 0.15s ease-out;
        }

        .game-tile::after {
            content: '';
            position: absolute;
            inset: 0;
            border-radius: var(--tile-radius);
            background: linear-gradient(135deg, rgba(255, 255, 255, 0.7) 0%, rgba(255, 255, 255, 0) 30%);
            pointer-events: none;
        }

        .game-tile:not(.tile-air):hover {
            transform: translate(var(--tile-lift-x), var(--tile-lift-y));
            box-shadow: var(--tile-shadow-hover);
        }

        .game-tile.tile-selected {
            transform: translate(var(--tile-lift-x), var(--tile-lift-y));
            box-shadow: var(--tile-shadow-hover);
            filter: drop-shadow(0 0 8px rgba(253, 224, 71, 0.65));
        }

        .game-tile.tile-air {
            transition: none !important;
            will-change: transform;
            filter: brightness(1.05) drop-shadow(0px 12px 18px rgba(0, 0, 0, 0.45));
            backface-visibility: hidden;
            transform: translate3d(var(--air-x, 0px), var(--air-y, 0px), 0);
            z-index: var(--air-z, 200000);
            box-shadow: var(--tile-shadow-hover);
        }

        .game-tile.tile-impact-pop {
            animation: tileImpactPop 0.16s ease-out;
        }

        .game-tile:active:not(.tile-air) {
            transform: translate(var(--tile-press-x), var(--tile-press-y));
            box-shadow: var(--tile-shadow-active);
            filter: brightness(0.95);
        }

        .game-tile.tile-selected:active:not(.tile-air) {
            transform: translate(4px, 4px);
        }

        .game-tile.blocked {
            cursor: pointer;
        }

        /* --- ANIMATION CLASSES --- */
        .tile-denied {
            animation: deniedShake 0.22s ease-out;
        }

        .tile-highlight {
            transform: translate(var(--tile-lift-x), -3px) !important;
            box-shadow: var(--tile-shadow-hover) !important;
            filter: brightness(1.12) drop-shadow(0 0 14px rgba(253, 224, 71, 0.85)) !important;
        }

        .tile-hide {
            transform: scale(0) !important;
            opacity: 0;
        }

        @keyframes deniedShake {
            0% { transform: translate(0, 0); }
            20% { transform: translate(-3px, 0); }
            40% { transform: translate(3px, 0); }
            60% { transform: translate(-2px, 0); }
            80% { transform: translate(2px, 0); }
            100% { transform: translate(0, 0); }
        }

        @keyframes tileImpactPop {
            0% { filter: brightness(1.05) drop-shadow(0px 12px 18px rgba(0, 0, 0, 0.45)); }
            45% { filter: brightness(1.2) drop-shadow(0 0 12px rgba(253, 224, 71, 0.65)); }
            100% { filter: brightness(1.05) drop-shadow(0px 12px 18px rgba(0, 0, 0, 0.45)); }
        }

        @keyframes shardFly {
            0% { transform: translate3d(-50%, -50%, 0) rotate(0deg) scale(1); opacity: 1; }
            100% { transform: translate3d(calc(-50% + var(--dx)), calc(-50% + var(--dy)), 0) rotate(240deg) scale(0.15); opacity: 0; }
        }

        /* --- TILE FACE --- */
        .tile-face-wrap {
            position: relative;
            z-index: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100%;
            padding: var(--tile-face-pad);
            overflow: hidden;
            font-family: 'Kaiti', 'STKaiti', 'KaiTi_GB2312', '楷体', 'Noto Serif TC', serif;
            -webkit-font-smoothing: antialiased;
            text-rendering: geometricPrecision;
            pointer-events: none;
        }

        .tile-emoji {
            font-size: var(--tile-emoji-font);
            line-height: 1;
            font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", system-ui, sans-serif;
        }

        .tile-emoji--big {
            font-size: var(--tile-emoji-big-font);
        }
