@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@600;700;800&family=Nunito:wght@600;700;800&display=swap');


/* ---------------------------------------------------------------------------
   Design tokens — game aesthetic
   --------------------------------------------------------------------------- */
:root {
    /* Background + frame (match provided cheerful puzzle look) */
    --color-bg: #f7efdd;
    --color-border: rgba(130, 91, 48, 0.18);
    --color-text: #3d2b1f;
    --color-text-muted: rgba(61, 43, 31, 0.78);
    --color-text-subtle: rgba(61, 43, 31, 0.66);
    --color-primary: #ff7a1a;
    --color-primary-dim: #ff9a4f;
    --color-primary-glow: rgba(255, 122, 26, 0.35);
    --color-accent: #37c66a;
    --color-accent-glow: rgba(55, 198, 106, 0.28);
    --color-danger: #ff3b5c;

    /* Block colors (closer to screenshot palette) */
    --color-block: #4db3ff;
    --block-blue: #8958ce;
    --block-green: #1dd15f;
    --block-yellow: #eddc27;
    --block-orange: #f174ae; /* pink-ish */
    --block-purple: #ea4a4a;
    --block-cyan: #15e8f4;

    --font-family: 'Nunito', system-ui, -apple-system, Segoe UI, sans-serif;
    --font-display: 'Baloo 2', system-ui, -apple-system, Segoe UI, sans-serif;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 40px;
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 26px;
    --radius-xl: 34px;
    --canvas-width: min(650px, 100vw);
    --canvas-height: min(820px, 100vh);
    --panel-shadow: 0 20px 55px rgba(60, 35, 15, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.65);
    --stack-gap: 18px;
    /* Keep grid cells square (no stretching) by basing sizing on vmin. */
    --cell-size: clamp(37px, 10.8vmin, 64px);
    --piece-cell: calc(var(--cell-size) - 6px);

    /* Board frame — pastel game glow (Block Buddies) */
    --board-neon: rgba(140, 90, 45, 0.38);
    --board-glow-blue: rgba(140, 90, 45, 0.16);
    --board-glow-purple: rgba(240, 225, 197, 0.22);
    --board-glow-pink: rgba(255, 255, 255, 0.14);
}

:root {
    /* Background + frame (match provided cheerful puzzle look) */
    --color-bg: #f7efdd;
    --color-border: rgba(130, 91, 48, 0.18);
    --color-text: #3d2b1f;
    --color-text-muted: rgba(61, 43, 31, 0.78);
    --color-text-subtle: rgba(61, 43, 31, 0.66);
    --color-primary: #ff7a1a;
    --color-primary-dim: #ff9a4f;
    --color-primary-glow: rgba(255, 122, 26, 0.35);
    --color-accent: #37c66a;
    --color-accent-glow: rgba(55, 198, 106, 0.28);
    --color-danger: #ff3b5c;

    /* Block colors (closer to screenshot palette) */
    --color-block: #4db3ff;
    --block-blue: #8958ce;
    --block-green: #1dd15f;
    --block-yellow: #eddc27;
    --block-orange: #f174ae; /* pink-ish */
    --block-purple: #ea4a4a;
    --block-cyan: #15e8f4;

    --font-family: 'Nunito', system-ui, -apple-system, Segoe UI, sans-serif;
    --font-display: 'Baloo 2', system-ui, -apple-system, Segoe UI, sans-serif;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 40px;
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 26px;
    --radius-xl: 34px;
    --canvas-width: min(650px, 100vw);
    --canvas-height: min(820px, 100vh);
    --panel-shadow: 0 20px 55px rgba(60, 35, 15, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.65);
    --stack-gap: 18px;
    /* Keep grid cells square (no stretching) by basing sizing on vmin. */
    --cell-size: clamp(37px, 10.8vmin, 64px);
    --piece-cell: calc(var(--cell-size) - 6px);

    /* Board frame — pastel game glow (Block Buddies) */
    --board-neon: rgba(140, 90, 45, 0.38);
    --board-glow-blue: rgba(140, 90, 45, 0.16);
    --board-glow-purple: rgba(240, 225, 197, 0.22);
    --board-glow-pink: rgba(255, 255, 255, 0.14);
}

/* ---------------------------------------------------------------------------
   Base
   --------------------------------------------------------------------------- */
body {
    font-family: var(--font-family);
    background: url('../img/bg.png') center / cover no-repeat;
    color: var(--color-text);
    overflow: hidden;
    touch-action: none;
    user-select: none;
    margin: 0;
}

/* ---------------------------------------------------------------------------
   Utilities
   --------------------------------------------------------------------------- */
.color-blue { --block-color: var(--block-blue); --highlight-color: var(--block-blue); }
.color-green { --block-color: var(--block-green); --highlight-color: var(--block-green); }
.color-yellow { --block-color: var(--block-yellow); --highlight-color: var(--block-yellow); }
.color-orange { --block-color: var(--block-orange); --highlight-color: var(--block-orange); }
.color-purple { --block-color: var(--block-purple); --highlight-color: var(--block-purple); }
.color-cyan { --block-color: var(--block-cyan); --highlight-color: var(--block-cyan); }

.pos-0-0 { grid-column: 1; grid-row: 1; }
.pos-1-0 { grid-column: 2; grid-row: 1; }
.pos-2-0 { grid-column: 3; grid-row: 1; }
.pos-0-1 { grid-column: 1; grid-row: 2; }
.pos-1-1 { grid-column: 2; grid-row: 2; }
.pos-2-1 { grid-column: 3; grid-row: 2; }
.pos-0-2 { grid-column: 1; grid-row: 3; }
.pos-1-2 { grid-column: 2; grid-row: 3; }
.pos-2-2 { grid-column: 3; grid-row: 3; }

/* ---------------------------------------------------------------------------
   Game wrapper — immersive game frame
   --------------------------------------------------------------------------- */
#game-wrapper {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: transparent;
}

#gameArea {
    width: var(--canvas-width);
    height: var(--canvas-height);
    z-index: 10;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: visible;
    box-sizing: border-box;
    padding: 0 12px 12px;
}

.menu .play-area,
.menu .ui-layer {
    opacity: 0;
    pointer-events: none;
}

.menu .play-area {
    transform: translateY(10px);
}

.play-area {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--stack-gap);
}

.board {
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(8, var(--cell-size, 44px));
    grid-template-rows: repeat(8, var(--cell-size, 44px));
    gap: 0;
    touch-action: none;
    padding: 0;
    border-radius: 22px;
    box-sizing: content-box;
    overflow: hidden;
    background:
        radial-gradient(130% 110% at 16% 10%, rgba(255, 255, 255, 0.76) 0%, rgba(255, 255, 255, 0.3) 34%, rgba(255, 255, 255, 0.06) 58%, transparent 100%),
        linear-gradient(165deg, rgba(255, 255, 255, 0.95) 0%, rgba(247, 244, 236, 0.92) 48%, rgba(232, 224, 208, 0.9) 100%);
    border: 2px solid var(--board-neon);
    box-shadow:
        0 0 12px var(--board-glow-blue),
        0 0 24px var(--board-glow-purple),
        0 0 36px var(--board-glow-pink),
        0 18px 34px rgba(255, 122, 26, 0.18),
        0 8px 0 #8c5a2d,
        inset 0 0 20px rgba(255, 143, 58, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.board::before {
    content: "";
    position: absolute;
    inset: 2px;
    border-radius: 18px;
    pointer-events: none;
    border: 1px solid rgba(255, 255, 255, 0.34);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.46),
        inset 0 -3px 8px rgba(140, 132, 115, 0.1);
}

.board::after {
    display: none;
}

.cell {
    width: var(--cell-size, 44px);
    height: var(--cell-size, 44px);
    box-sizing: border-box;
    border: 1px solid rgba(178, 170, 153, 0.38);
    position: relative;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.56) 0%, rgba(245, 241, 232, 0.58) 100%);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.5),
        inset 0 -1px 0 rgba(168, 160, 143, 0.1);
}

.cell::before {
    content: "";
    position: absolute;
    inset: 2px 2px auto 2px;
    height: 32%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.24) 0%, rgba(255, 255, 255, 0) 100%);
    pointer-events: none;
    opacity: 0.75;
}

.cell::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 3px;
    height: 3px;
    border-radius: 999px;
    background: rgba(162, 153, 136, 0.3);
    transform: translate(-50%, -50%);
}

.cell--filled::before,
.cell--filled::after {
    display: none;
}

.cell--filled {
    border-color: rgba(140, 90, 45, 0.14);
    background:
        linear-gradient(165deg,
            color-mix(in srgb, var(--block-color) 78%, white) 0%,
            var(--block-color) 36%,
            color-mix(in srgb, var(--block-color) 78%, black) 100%);
    border-radius: 0;
    box-shadow:
        inset 0 2px 0 rgba(255, 255, 255, 0.35),
        inset 0 -6px 10px rgba(0, 0, 0, 0.18),
        0 12px 22px rgba(60, 35, 15, 0.18);
}

.cell--filled::before {
    content: "";
    position: absolute;
    inset: 3px 3px auto 3px;
    height: 35%;
    border-radius: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.42) 0%, rgba(255, 255, 255, 0) 100%);
    pointer-events: none;
    opacity: 0.9;
}

.cell--highlight {
    outline: 2px solid rgba(255, 122, 26, 0.35);
    outline-offset: -2px;
    box-shadow:
        inset 0 0 0 2px rgba(255, 255, 255, 0.22),
        inset 0 0 0 999px color-mix(in srgb, var(--highlight-color) 18%, transparent);
}

.cell--clearing {
    animation: clear-pop 260ms cubic-bezier(0.18, 0.8, 0.25, 1) forwards;
    animation-delay: var(--clear-delay, 0ms);
    z-index: 2;
    overflow: visible;
}

.cell--clearing::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(80, 216, 255, 0) 35%,
        rgba(80, 216, 255, 0.95) 46%,
        rgba(255, 149, 238, 1) 50%,
        rgba(255, 245, 176, 0.98) 54%,
        rgba(255, 245, 176, 0) 65%,
        rgba(255, 255, 255, 0) 100%);
    transform-origin: center;
    animation: flash-spread-x 260ms ease-out forwards;
    animation-delay: var(--clear-delay, 0ms);
    pointer-events: none;
    mix-blend-mode: screen;
    filter: drop-shadow(0 0 6px rgba(72, 228, 255, 0.55)) drop-shadow(0 0 14px rgba(255, 110, 224, 0.35));
}

.cell--clearing--col::before {
    animation-name: flash-spread-y;
    background: linear-gradient(180deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(80, 216, 255, 0) 35%,
        rgba(80, 216, 255, 0.95) 46%,
        rgba(255, 149, 238, 1) 50%,
        rgba(255, 245, 176, 0.98) 54%,
        rgba(255, 245, 176, 0) 65%,
        rgba(255, 255, 255, 0) 100%);
}

/* Clearing preset tokens (grid-size fixed at 8 in this game).
   These map dynamic line-clear timing/thickness values to class names
   so JS can avoid setting inline CSS variables. */
.cell--delay-9 { --clear-delay: 9ms; }
.cell--delay-18 { --clear-delay: 18ms; }
.cell--delay-27 { --clear-delay: 27ms; }
.cell--delay-36 { --clear-delay: 36ms; }
.cell--delay-45 { --clear-delay: 45ms; }
.cell--delay-54 { --clear-delay: 54ms; }
.cell--delay-63 { --clear-delay: 63ms; }
.cell--delay-72 { --clear-delay: 72ms; }

.cell--beam-width-0 { --beam-width: 0.4; }
.cell--beam-width-1 { --beam-width: 0.57142857; }
.cell--beam-width-2 { --beam-width: 0.74285714; }
.cell--beam-width-3 { --beam-width: 0.91428571; }

.cell--beam-opacity-0 { --beam-opacity: 0.55; }
.cell--beam-opacity-1 { --beam-opacity: 0.67857143; }
.cell--beam-opacity-2 { --beam-opacity: 0.80714286; }
.cell--beam-opacity-3 { --beam-opacity: 0.93571429; }

.line-clear-star {
    position: absolute;
    left: var(--star-x, 0px);
    top: var(--star-y, 0px);
    z-index: 8;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.35);
    opacity: 0;
    font-size: 1.35rem;
    line-height: 1;
    filter:
        drop-shadow(0 0 4px rgba(255, 252, 177, 0.95))
        drop-shadow(0 0 10px rgba(255, 173, 236, 0.78))
        drop-shadow(0 0 14px rgba(119, 235, 255, 0.62));
    animation: line-star-pop 560ms ease-out forwards;
    animation-delay: var(--star-delay, 0ms);
}

@keyframes clear-pop {
    0% {
        transform: scale(1);
        filter: brightness(1) saturate(1.05);
        opacity: 1;
    }
    50% {
        transform: scale(1.02);
        filter: brightness(1.12) saturate(1.18);
        opacity: 1;
    }
    100% {
        transform: scale(0.92);
        filter: brightness(1) saturate(1.05);
        opacity: 0;
    }
}

@keyframes flash-spread-x {
    0% {
        opacity: 0;
        transform: scaleX(0);
    }
    35% {
        opacity: var(--beam-opacity, 1);
        transform: scaleX(var(--beam-width, 1));
    }
    100% {
        opacity: 0;
        transform: scaleX(var(--beam-width, 1));
    }
}

@keyframes flash-spread-y {
    0% {
        opacity: 0;
        transform: scaleY(0);
    }
    35% {
        opacity: var(--beam-opacity, 1);
        transform: scaleY(var(--beam-width, 1));
    }
    100% {
        opacity: 0;
        transform: scaleY(var(--beam-width, 1));
    }
}

.line-clear-multiplier {
    position: absolute;
    left: var(--mult-x, 0px);
    top: var(--mult-y, 0px);
    transform: translate(-50%, -50%);
    z-index: 10;
    pointer-events: none;
    font-family: var(--font-display);
    font-weight: 900;
    letter-spacing: 0.02em;
    /* Use gradient text + layered glow. */
    color: transparent;
    background: linear-gradient(90deg, #22bcc4 0%, #8958ce 45%, #ffd34d 100%);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    text-shadow:
        0 2px 0 rgba(60, 35, 15, 0.18),
        0 0 16px rgba(34, 188, 196, 0.55),
        0 0 30px rgba(137, 88, 206, 0.40),
        0 0 48px rgba(255, 211, 77, 0.35);
    font-size: 3.1rem; /* default; overridden by modifier classes */
    opacity: 0;
    animation:
        multiplier-pop 780ms ease-out forwards,
        multiplier-gradient-shimmer 820ms ease-out forwards;
}

/* Star-style multiplier label (2x/3x/4x...) */
.line-clear-multiplier--star {
    /* Remove the gradient/background treatment behind the label. */
    background: none;
    -webkit-background-clip: initial;
    background-clip: initial;
    color: rgba(255, 245, 176, 0.98);
    text-shadow: none;

    opacity: 0;
    animation: line-star-pop 560ms ease-out forwards;
    animation-delay: var(--star-delay, 0ms);

    /* Bright, playful pop glow (similar vibe to the ⭐). */
    filter:
        drop-shadow(0 0 6px rgba(255, 252, 177, 0.95))
        drop-shadow(0 0 14px rgba(255, 173, 236, 0.78))
        drop-shadow(0 0 18px rgba(119, 235, 255, 0.62));
}

/* 2x styling */
.line-clear-multiplier--2 {
    background: linear-gradient(90deg, #22bcc4 0%, #8958ce 55%, #ffd34d 100%);
    text-shadow:
        0 2px 0 rgba(60, 35, 15, 0.18),
        0 0 18px rgba(34, 188, 196, 0.70),
        0 0 36px rgba(137, 88, 206, 0.45),
        0 0 56px rgba(255, 211, 77, 0.35);
}

/* 3x styling (stronger and more colorful) */
.line-clear-multiplier--3 {
    font-size: 3.6rem;
    background: linear-gradient(90deg, #ff7a1a 0%, #f174ae 35%, #37c66a 68%, #22bcc4 100%);
    text-shadow:
        0 2px 0 rgba(60, 35, 15, 0.18),
        0 0 20px rgba(255, 122, 26, 0.75),
        0 0 42px rgba(241, 116, 174, 0.50),
        0 0 64px rgba(55, 198, 106, 0.45),
        0 0 82px rgba(34, 188, 196, 0.35);
}

@keyframes multiplier-pop {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.55);
    }
    28% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.05);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1.15);
    }
}

@keyframes multiplier-gradient-shimmer {
    0% {
        background-position: 0% 50%;
    }
    100% {
        background-position: 100% 50%;
    }
}

@keyframes line-star-pop {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(calc(0.2 * var(--star-scale, 1)));
    }
    25% {
        opacity: 1;
        transform: translate(-50%, -66%) scale(calc(1.15 * var(--star-scale, 1)));
    }
    60% {
        opacity: 1;
        transform: translate(-50%, -78%) scale(calc(1 * var(--star-scale, 1)));
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -100%) scale(calc(0.72 * var(--star-scale, 1)));
    }
}


/* ---------------------------------------------------------------------------
   UI layer — proper game HUD layout
   --------------------------------------------------------------------------- */
.ui-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding: 0;
    z-index: 20;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: auto;
    padding: 12px;
    margin: 0;
}

.header__left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.header__right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-sm);
}

.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: 1px solid var(--board-neon);
    background:
        radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.9) 0%, transparent 55%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.78) 0%, rgba(240, 225, 197, 0.85) 100%);
    color: rgba(61, 43, 31, 0.92);
    box-shadow:
        0 0 12px var(--board-glow-blue),
        0 0 24px var(--board-glow-purple),
        0 0 36px var(--board-glow-pink),
        0 12px 24px rgba(60, 35, 15, 0.14),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    margin: 0;
}

.icon-btn:hover {
    transform: translateY(-1px);
    border-color: var(--board-neon);
    box-shadow:
        0 0 14px var(--board-glow-blue),
        0 0 28px var(--board-glow-purple),
        0 0 40px var(--board-glow-pink),
        var(--panel-shadow);
}

.icon-btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.icon-btn i {
    font-size: 1rem;
}

.level-badge {
    display: inline-block;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.04em;
    color: rgba(61, 43, 31, 0.95);
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}

.hud-score-row {
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    width: 100%;
    flex: 0 0 auto;
}

.goal-meter {
    width: min(356px, 92%);
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    margin: 0 auto;
}

.goal-meter__track {
    position: relative;
    min-width: 0;
    padding: 0 1px;
    display: flex;
    align-items: center;
}

.goal-meter__end {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
}

.goal-meter__end--score {
    flex-direction: row;
    justify-content: center;
    gap: 6px;
}

.goal-meter__end--goal {
    position: relative;
    justify-content: center;
}

.goal-meter__goal-icon {
    position: absolute;
    left: 50%;
    bottom: calc(100% - 2px);
    transform: translateX(-50%);
    display: block;
    font-size: 2rem;
    line-height: 1;
    background: none;
    border: 0;
    box-shadow: none;
    filter: drop-shadow(0 1px 1px rgba(60, 30, 10, 0.22));
    z-index: 3;
}

.goal-meter__value {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
    height: 36px;
    padding: 0 10px;
    font-family: var(--font-display);
    font-size: 1.08rem;
    line-height: 1;
    font-weight: 800;
    letter-spacing: 0.02em;
    text-align: center;
    text-shadow: 0 1px 0 rgba(26, 18, 8, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.24);
    box-shadow:
        0 7px 12px rgba(60, 35, 15, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.2),
        inset 0 -1px 2px rgba(0, 0, 0, 0.15);
}

.goal-meter__value--score {
    color: rgba(61, 43, 31, 0.95);
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
    min-width: 0;
    width: auto;
    height: auto;
    padding: 0;
}

.goal-meter__score-icon {
    font-size: 1.25rem;
    line-height: 1;
    filter: drop-shadow(0 1px 1px rgba(60, 30, 10, 0.2));
}

.goal-meter__value--goal {
    color: #ffe9ee;
    border-radius: 999px;
    background:
        radial-gradient(circle at 24% 14%, rgba(255, 137, 158, 0.52) 0%, rgba(255, 137, 158, 0.16) 42%, transparent 62%),
        linear-gradient(180deg, #ff6a7f 0%, #f04861 58%, #cf2f49 100%);
    box-shadow:
        0 7px 13px rgba(124, 24, 43, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.16),
        inset 0 -1px 2px rgba(95, 17, 32, 0.28),
        0 0 8px rgba(240, 72, 97, 0.28);
}

.progress-bar {
    position: relative;
    width: 100%;
    height: 18px;
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid rgba(132, 90, 44, 0.28);
    background:
        linear-gradient(180deg, rgba(255, 245, 228, 0.22) 0%, rgba(255, 245, 228, 0.08) 100%),
        linear-gradient(180deg, rgba(226, 204, 172, 0.7) 0%, rgba(210, 183, 147, 0.7) 100%);
    box-shadow:
        inset 0 1px 2px rgba(255, 255, 255, 0.2),
        inset 0 -1px 2px rgba(90, 57, 22, 0.18),
        0 5px 12px rgba(87, 56, 27, 0.14);
}

.progress-bar::before {
    content: "";
    position: absolute;
    inset: 1px 2px auto 2px;
    height: 42%;
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(255, 233, 196, 0.3) 0%, rgba(255, 233, 196, 0.02) 100%);
    pointer-events: none;
    z-index: 1;
}

.progress-bar__fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    border-radius: inherit;
    transform: scaleX(var(--progress-pct, 0));
    transform-origin: left center;
    background:
        radial-gradient(circle at 24% 14%, rgba(154, 237, 160, 0.4) 0%, transparent 52%),
        linear-gradient(180deg, #68da74 0%, #44c965 52%, #25af56 100%);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.14),
        inset 0 -1px 2px rgba(0, 0, 0, 0.12),
        0 0 6px rgba(73, 201, 101, 0.24);
    transition: transform 0.2s ease, filter 0.2s ease;
    z-index: 0;
}

.progress-bar__fill::after {
    content: "";
    position: absolute;
    inset: 2px auto 2px 4px;
    width: max(20px, 18%);
    border-radius: inherit;
    background: linear-gradient(90deg, rgba(194, 251, 199, 0.25) 0%, rgba(194, 251, 199, 0) 100%);
}

.progress-bar__fill::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 38px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(219, 255, 222, 0.28) 52%, rgba(255, 255, 255, 0) 100%);
    transform: translateX(-42px);
    animation: meter-shimmer 2.2s linear infinite;
}

@keyframes meter-shimmer {
    0% {
        transform: translateX(-42px);
    }
    100% {
        transform: translateX(250px);
    }
}

/* ---------------------------------------------------------------------------
   Responsive breakpoints
   - Keep square cells / aspect ratios intact by only changing square sizing
     (cell-size is always used for both width and height).
   - Layout scale is controlled via CSS variables and a few element overrides.
--------------------------------------------------------------------------- */

/* Desktop (>=1025px) - keep original sizing */
@media (min-width: 1025px) {
    :root {
        --canvas-width: min(600px, 100vw);
        --canvas-height: min(750px, 100vh);
        --cell-size: clamp(37px, min(10.8vw, 10.8vh), 54px);
    }
}

/* Small Mobile (<=480px) */
@media (max-width: 480px) {
    :root {
        --canvas-width: min(420px, 100vw);
        --canvas-height: min(620px, 100vh);
        --cell-size: clamp(30px, 9.6vmin, 46px);

        --stack-gap: 14px;
        --space-xl: 28px;
    }

    #gameArea {
        padding: 0 10px 10px;
    }

    .header {
        padding: 10px;
    }

    .icon-btn {
        width: 38px;
        height: 38px;
    }

    .icon-btn i {
        font-size: 0.95rem;
    }

    .goal-meter {
        width: min(320px, 92%);
        gap: 7px;
        padding: 0;
    }

    .goal-meter__value {
        min-width: 42px;
        height: 30px;
        padding: 0 8px;
        font-size: 0.95rem;
    }

    .goal-meter__goal-icon {
        bottom: calc(100% - 1px);
        font-size: 1.6rem;
    }

    .progress-bar {
        height: 15px;
    }

    .tray-area {
        margin-top: 12px;
    }
}

/* Mobile (481px-640px) */
@media (min-width: 481px) and (max-width: 640px) {
    :root {
        --canvas-width: min(520px, 100vw);
        --canvas-height: min(700px, 100vh);
        --cell-size: clamp(32px, 10.1vmin, 50px);

        --stack-gap: 16px;
        --space-xl: 32px;
    }

    #gameArea {
        padding: 0 12px 12px;
    }

    .header {
        padding: 11px 12px;
    }

    .icon-btn {
        width: 42px;
        height: 42px;
    }

    .goal-meter {
        width: min(340px, 92%);
    }

    .progress-bar {
        height: 16px;
    }

    .tray-area {
        margin-top: 14px;
    }
}

/* Tablet Portrait (641px-768px) */
@media (min-width: 641px) and (max-width: 768px) {
    :root {
        --canvas-width: min(600px, 94vw);
        --canvas-height: min(780px, 100vh);
        --cell-size: clamp(34px, 10.4vmin, 56px);

        --stack-gap: 18px;
    }
}

/* Tablet Landscape (769px-1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    :root {
        --canvas-width: min(680px, 96vw);
        --canvas-height: min(800px, 100vh);
        --cell-size: clamp(34px, 9.8vmin, 60px);

        --stack-gap: 16px;
    }

    .tray-area {
        margin-top: 16px;
    }
}

/* Landscape Mobile (orientation: landscape) */
@media (max-width: 640px) and (orientation: landscape) {
    :root {
        --cell-size: clamp(30px, 10vmin, 44px);
        --stack-gap: 12px;
        --space-xl: 24px;
    }

    .header {
        padding: 10px;
    }

    .goal-meter__goal-icon {
        font-size: 1.45rem;
    }

    .progress-bar {
        height: 14px;
    }

    .tray-area {
        margin-top: 10px;
    }
}

.tray-area {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding: 0;
    min-height: 0;
    margin-top: 18px;
    flex: 0 0 auto;
}

.tray {
    width: auto;
    max-width: 100%;
    display: grid;
    grid-template-columns: repeat(3, max-content);
    column-gap: 18px;
    row-gap: 0;
    align-items: end;
    justify-items: center;
    justify-content: center;
    pointer-events: auto;
    padding: 0;
    border-radius: 0;
    background: transparent;
    border: none;
    box-shadow: none;
}

.piece {
    position: relative;
    width: calc(var(--piece-cell, 44px) * 3);
    height: calc(var(--piece-cell, 44px) * 3);
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    touch-action: none;
    padding: 0;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    display: grid;
    grid-template-columns: repeat(3, var(--piece-cell, 28px));
    grid-template-rows: repeat(3, var(--piece-cell, 28px));
    place-content: center;
}

.piece--empty {
    pointer-events: none;
}

.piece--dragging {
    opacity: 0.15;
    filter: saturate(0.2);
    transform: scale(0.98);
    pointer-events: none;
}

.piece:focus-visible {
    outline: 2px solid rgba(34, 211, 238, 0.65);
    outline-offset: 6px;
}

.piece__cell {
    position: relative;
    width: var(--piece-cell, 28px);
    height: var(--piece-cell, 28px);
    border-radius: 0;
    background:
        linear-gradient(165deg,
            color-mix(in srgb, var(--block-color) 78%, white) 0%,
            var(--block-color) 36%,
            color-mix(in srgb, var(--block-color) 78%, black) 100%);
    box-shadow:
        inset 0 2px 0 rgba(255, 255, 255, 0.35),
        inset 0 -5px 8px rgba(0, 0, 0, 0.18),
        0 12px 22px rgba(60, 35, 15, 0.18);
}

.piece__cell::before {
    content: "";
    position: absolute;
    inset: 2px 2px auto 2px;
    height: 40%;
    border-radius: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.42) 0%, rgba(255, 255, 255, 0) 100%);
    pointer-events: none;
    opacity: 0.9;
}

.drag-ghost {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 50;
    pointer-events: none;
    transform: translate(var(--ghost-x, -9999px), var(--ghost-y, -9999px));
    display: grid;
    grid-template-columns: repeat(var(--ghost-w, 1), var(--cell-size, 44px));
    grid-template-rows: repeat(var(--ghost-h, 1), var(--cell-size, 44px));
    place-content: center;
}

.ghost-w1 { --ghost-w: 1; }
.ghost-w2 { --ghost-w: 2; }
.ghost-w3 { --ghost-w: 3; }
.ghost-h1 { --ghost-h: 1; }
.ghost-h2 { --ghost-h: 2; }
.ghost-h3 { --ghost-h: 3; }

.drag-ghost .piece__cell {
    width: calc(var(--cell-size, 44px) - 4px);
    height: calc(var(--cell-size, 44px) - 4px);
    border-radius: 0;
}

/* ---------------------------------------------------------------------------
   Modals — game overlay style
   --------------------------------------------------------------------------- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(40, 22, 10, 0.18);
    backdrop-filter: blur(10px) saturate(1.1);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
}

/* Only the start modal should show the content without a dim/blur overlay behind it. */
#startModal.modal {
    background: transparent;
    backdrop-filter: none;
}

#howToPlayModal.modal {
    background: rgba(40, 22, 10, 0.1);
    backdrop-filter: none;
}

.modal.modal--active {
    opacity: 1;
    pointer-events: auto;
}

.modal[hidden] {
    display: none;
}

.modal__content {
    border: 1px solid var(--color-border);
    background:
        radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.72) 45%, rgba(255, 255, 255, 0.62) 100%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.86) 0%, rgba(240, 225, 197, 0.76) 100%);
    padding: var(--space-xl);
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow:
        var(--panel-shadow),
        0 0 80px var(--color-primary-glow),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-xl);
}

.modal__logo {
    width: min(320px, 84%);
    height: auto;
    margin: -10px auto 12px;
    display: block;
    filter: drop-shadow(0 20px 22px rgba(60, 35, 15, 0.16));
}

.modal__title {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
    line-height: 1;
    font-family: var(--font-display);
}

.modal__title--danger {
    color: var(--color-danger) !important;
    background: none !important;
    -webkit-text-fill-color: var(--color-danger) !important;
}

.modal__text {
    font-size: 0.875rem;
    color: var(--color-text-subtle);
    margin: 0 0 var(--space-md) 0;
    line-height: 1.5;
}

.modal__score {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: var(--space-lg);
}

.modal__emoji {
    font-size: 4.5rem;
    line-height: 1;
}

.modal__actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: var(--space-md);
}

.modal__actions .btn {
    margin-top: 0;
    min-width: 140px;
    padding: 12px 20px;
}

/* ---------------------------------------------------------------------------
   Tutorial (start modal)
   --------------------------------------------------------------------------- */
.tutorial {
    background: rgba(255, 255, 255, 0.62);
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    margin: var(--space-md) 0;
}

.tutorial__labels {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-bottom: var(--space-sm);
}

.tutorial__visual {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-md);
    margin: var(--space-md) 0;
    font-size: 0.875rem;
    color: var(--color-text-subtle);
}

.tutorial__blocks {
    display: flex;
    gap: 3px;
}

.tutorial__block {
    display: block;
    width: 12px;
    height: 12px;
    background: linear-gradient(135deg, var(--color-block) 0%, #2563eb 100%);
    border-radius: 0;
    box-shadow: 0 6px 12px rgba(60, 35, 15, 0.14);
}

.tutorial__arrow {
    font-size: 0.75rem;
    color: var(--color-primary);
}

.tutorial__icon {
    color: var(--color-accent);
}

#howToPlayModal .modal__content {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: 24px;
}

#howToPlayModal .modal__title,
#howToPlayModal .modal__text,
#howToPlayModal .tutorial,
#howToPlayModal .btn {
    margin: 0;
}

#howToPlayModal .btn {
    align-self: center;
    font-size: 1.2rem;
    padding: 10px 30px;
}

#levelCompleteModal .modal__content {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: 24px;
}

#levelCompleteModal .modal__title,
#levelCompleteModal .modal__actions {
    margin: 0;
}

.level-card {
    width: 136px;
    height: 136px;
    margin: 0 auto;
    border-radius: var(--radius-md);
    border: 2px solid var(--board-neon);
    background:
        radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.92) 0%, transparent 60%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.84) 0%, rgba(240, 225, 197, 0.88) 100%);
    box-shadow:
        0 0 12px var(--board-glow-blue),
        0 0 24px var(--board-glow-purple),
        0 0 36px var(--board-glow-pink),
        0 18px 34px rgba(255, 122, 26, 0.18),
        0 8px 0 #8c5a2d,
        inset 0 0 20px rgba(255, 143, 58, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.22);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.level-card__label {
    font-family: var(--font-family);
    font-size: 0.88rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.level-card__value {
    font-family: var(--font-display);
    font-size: 2.8rem;
    line-height: 1;
    font-weight: 800;
    color: var(--color-text);
}

.level-card__target {
    display: none;
}

#startModal .modal__content {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    padding: 24px;
}

#startModal .modal__logo,
#startModal .level-card,
#startModal .btn {
    margin: 0;
}

#startModal .modal__logo {
    width: min(280px, 80%);
    margin: 0 auto;
}

#startModal .level-card {
    align-self: center;
}

#startModal .btn {
    align-self: center;
    font-size: 1.2rem;
    padding: 10px 30px;
}

/* ---------------------------------------------------------------------------
   Buttons — game CTA style
   --------------------------------------------------------------------------- */
.btn {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    padding: 16px var(--space-xl);
    border: 1px solid rgba(255, 122, 26, 0.38);
    cursor: pointer;
    margin-top: var(--space-lg);
    text-transform: uppercase;
    border-radius: var(--radius-md);
    transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.btn--primary {
    background:
        radial-gradient(circle at 30% 18%, rgba(255, 255, 255, 0.55) 0%, transparent 55%),
        linear-gradient(180deg, var(--color-primary-dim) 0%, var(--color-primary) 60%, #ff5a1a 100%);
    color: rgba(255, 255, 255, 0.96);
    text-shadow: 0 2px 0 rgba(60, 35, 15, 0.22);
}

.btn--primary:hover {
    box-shadow: 0 0 30px var(--color-primary-glow);
    transform: translateY(-2px);
    border-color: var(--color-primary);
}

.btn--primary:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.btn--secondary {
    background:
        radial-gradient(circle at 30% 18%, rgba(255, 255, 255, 0.82) 0%, transparent 55%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.95) 0%, rgba(238, 224, 198, 0.96) 100%);
    color: rgba(61, 43, 31, 0.95);
    text-shadow: none;
    border-color: rgba(140, 90, 45, 0.24);
}

.btn--secondary:hover {
    box-shadow: 0 0 24px rgba(120, 88, 44, 0.16);
    transform: translateY(-2px);
    border-color: rgba(140, 90, 45, 0.42);
}

.btn--secondary:focus-visible {
    outline: 2px solid rgba(140, 90, 45, 0.55);
    outline-offset: 2px;
}
