/* ===== Design tokens ===== */
:root {
    --color-bg: #f6fbff;
    --color-text: #334155;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --transition-fast: 0.1s;
    /* Neon arcade board */
    --board-border: #2E3CBF;
    --board-score: #00F5D4;
    --board-glow: rgba(46, 60, 191, 0.45);
    --board-radius: 24px;
    /* Match background room: neon shelf lighting */
    --neon-blue: #60B8FF;
    --neon-cyan: #60F0FF;
    --neon-pink: #FF6B9D;
    --neon-purple: #B388FF;
    --room-dark: #0d1340;
    --room-mid: #16245E;
    --room-deep: #080b28;
    --border-glow-blue: rgba(96, 184, 255, 0.6);
    --border-glow-pink: rgba(255, 107, 157, 0.4);
    --border-glow-purple: rgba(179, 136, 255, 0.4);
    --top-bar-height: 46px;
    --screen-padding: 28px;
    --ui-inset: 12px;
    --game-gap: 16px;
}

body {
    margin: 0;
    padding: max(var(--screen-padding), env(safe-area-inset-top)) max(var(--screen-padding), env(safe-area-inset-right)) max(var(--screen-padding), env(safe-area-inset-bottom)) max(var(--screen-padding), env(safe-area-inset-left));
    box-sizing: border-box;
    background: var(--color-bg) url('../img/bg.png') no-repeat center center;
    background-size: cover;
    background-attachment: fixed;
    touch-action: none;
    font-family: var(--font-family);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    min-width: 100vw;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    color: var(--color-text);
}

body.in-game {
    gap: var(--game-gap);
}

#top-controls {
    position: fixed;
    top: max(var(--ui-inset), env(safe-area-inset-top));
    left: max(var(--ui-inset), env(safe-area-inset-left));
    z-index: 15;
    pointer-events: none;
}

.btn-icon {
    pointer-events: auto;
}

.btn-icon-svg {
    display: block;
}

body:not(.in-game) #top-controls {
    opacity: 0;
    pointer-events: none;
}

/* Score in themed container (match next-container / overlay style) */
.score-container {
    position: fixed;
    top: max(var(--ui-inset), env(safe-area-inset-top));
    right: max(var(--ui-inset), env(safe-area-inset-right));
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--top-bar-height);
    padding: 0 18px 0 20px;
    box-sizing: border-box;
    background: linear-gradient(145deg, var(--room-mid) 0%, #121a4d 40%, var(--room-dark) 100%);
    border: 2px solid var(--neon-cyan);
    border-radius: 12px;
    box-shadow:
        0 0 20px var(--border-glow-blue),
        0 0 40px var(--border-glow-purple),
        0 12px 32px rgba(0, 0, 0, 0.45),
        inset 0 0 30px rgba(96, 240, 255, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.score-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--board-score);
    text-shadow: 0 0 14px rgba(0, 245, 212, 0.5);
}

body:not(.in-game) .score-container {
    opacity: 0;
    pointer-events: none;
}

/* Start screen: hide game elements */
body.start-screen #next-container,
body.start-screen #gameCanvas {
    display: none;
}

#start-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 10;
    background: transparent;
}

body:not(.start-screen) #start-screen {
    display: none;
}

/* ===== Next preview: width by content, centered ===== */
#next-container {
    flex-shrink: 0;
    width: max-content;
    max-width: min(var(--board-width, 400px), 100%);
    box-sizing: border-box;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 12px 16px 12px 20px;
    background: linear-gradient(145deg, var(--room-mid) 0%, #121a4d 40%, var(--room-dark) 100%);
    border: 2px solid var(--neon-cyan);
    border-radius: var(--board-radius);
    box-shadow:
        0 0 20px var(--border-glow-blue),
        0 0 40px var(--border-glow-purple),
        0 12px 32px rgba(0, 0, 0, 0.45),
        0 6px 0 rgba(0, 0, 0, 0.25),
        inset 0 0 30px rgba(96, 240, 255, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    position: relative;
    overflow: hidden;
}

#next-container::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 60px;
    background: linear-gradient(90deg, rgba(96, 240, 255, 0.08) 0%, transparent 100%);
    pointer-events: none;
}

.next-container-label {
    flex-shrink: 0;
    font-size: 0.7rem;
    font-weight: 800;
    color: var(--neon-cyan);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    text-shadow: 0 0 12px var(--border-glow-blue);
    margin-right: 16px;
    align-self: center;
}

.next-queue {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex: 0 0 auto;
    min-width: 0;
}

.next-preview-canvas {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: block;
    border-radius: 50%;
    background: transparent;
    border: none;
}

.next-preview-canvas:last-child {
    border: 2px solid var(--neon-cyan);
    box-shadow: 0 0 10px var(--border-glow-blue);
}

/* ===== Canvas = play area (height, border, styling directly on canvas, no wrapper) ===== */
#gameCanvas.game-canvas {
    display: block;
    width: var(--board-width, 400px);
    height: var(--board-height, 600px);
    border: 2px solid var(--neon-cyan);
    border-radius: var(--board-radius);
    box-sizing: content-box;
    overflow: hidden;
    background: linear-gradient(165deg, var(--room-mid) 0%, var(--room-dark) 50%, var(--room-deep) 100%);
    box-shadow:
        0 0 24px var(--border-glow-blue),
        0 0 48px var(--border-glow-purple),
        0 0 16px var(--border-glow-pink),
        0 20px 50px rgba(0, 0, 0, 0.5),
        0 10px 0 rgba(0, 0, 0, 0.3),
        inset 0 0 40px rgba(96, 240, 255, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    cursor: none;
}


.overlay-card {
    width: max-content;
    max-width: min(340px, calc(100% - 32px));
    background: linear-gradient(165deg, #121a4d 0%, #0d1340 45%, #080b28 100%);
    border: 3px solid var(--board-border);
    border-radius: var(--board-radius);
    padding: 2rem 2.25rem;
    text-align: center;
    box-shadow:
        0 0 0 1px rgba(96, 240, 255, 0.12) inset,
        0 0 40px rgba(96, 240, 255, 0.08),
        0 0 60px var(--board-glow),
        0 20px 50px rgba(0, 0, 0, 0.5);
}

.overlay-title {
    font-family: 'Luckiest Guy', cursive;
    font-size: 2.5rem;
    font-weight: 400;
    color: #60F0FF;
    text-shadow:
        0 0 20px rgba(96, 240, 255, 0.6),
        0 3px 0 #0F1B4D,
        0 4px 8px rgba(0, 0, 0, 0.4);
    margin: 0 0 0.5rem;
    line-height: 1.1;
    letter-spacing: 0.02em;
}

.overlay-subtitle {
    font-family: 'Nunito', sans-serif;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.85);
    margin: 0 0 1.5rem;
    line-height: 1.5;
    font-size: 1rem;
}

.overlay-card .btn {
    margin-top: 0;
}

/* ===== Buttons ===== */
.btn {
    font-family: 'Nunito', sans-serif;
    background: linear-gradient(180deg, #00F5D4 0%, #0d9488 100%);
    color: #0F1B4D;
    border: none;
    padding: 14px 36px;
    font-size: 1.15rem;
    font-weight: 800;
    border-radius: 99px;
    cursor: pointer;
    box-shadow:
        0 4px 0 #0d9488,
        0 0 20px rgba(0, 245, 212, 0.4);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    margin-top: 10px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow:
        0 6px 0 #0d9488,
        0 0 28px rgba(0, 245, 212, 0.5);
}

.btn:active {
    transform: translateY(2px) scale(0.98);
    box-shadow:
        0 2px 0 #0d9488,
        0 0 16px rgba(0, 245, 212, 0.35);
}

/* Home icon button: square (width = height), same height as score, icon centered */
.btn.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-sizing: border-box;
    width: var(--top-bar-height);
    height: var(--top-bar-height);
    min-width: var(--top-bar-height);
    min-height: var(--top-bar-height);
    max-width: var(--top-bar-height);
    max-height: var(--top-bar-height);
    border-radius: 12px;
    margin-top: 0;
}

.btn.btn-icon .btn-icon-svg {
    width: 22px;
    height: 22px;
    display: block;
    margin: 0 auto;
}

/* ===== Mobile-only: move and drop controls ===== */
.mobile-controls {
    display: none;
    flex-shrink: 0;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px 0;
    width: 100%;
    max-width: var(--board-width, 400px);
    box-sizing: border-box;
}

body.in-game .mobile-controls {
    display: flex;
}

.mobile-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    color: #0F1B4D;
    background: linear-gradient(180deg, #00F5D4 0%, #0d9488 100%);
    box-shadow: 0 4px 0 #0d9488, 0 0 16px rgba(0, 245, 212, 0.35);
    border-radius: 14px;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.mobile-btn:active {
    transform: scale(0.96);
    box-shadow: 0 2px 0 #0d9488, 0 0 12px rgba(0, 245, 212, 0.3);
}

.mobile-btn-left,
.mobile-btn-right {
    width: 52px;
    height: 52px;
    min-width: 52px;
    min-height: 52px;
}

.mobile-btn-left svg,
.mobile-btn-right svg {
    width: 28px;
    height: 28px;
    display: block;
}

.mobile-btn-drop {
    padding: 14px 32px;
    font-size: 1.1rem;
    min-height: 52px;
}

/* Hide mobile controls on desktop (show only on touch/narrow viewports) */
@media (min-width: 769px) {
    .mobile-controls {
        display: none !important;
    }
}

/* ===== Responsive: design tokens overrides per breakpoint ===== */
/* Desktop (≥1025px): base values from :root (no override needed) */

/* Tablet Landscape (769px–1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    :root {
        --screen-padding: 20px;
        --top-bar-height: 42px;
        --ui-inset: 10px;
        --game-gap: 14px;
        --board-radius: 22px;
    }
    .score-container {
        padding: 0 14px 0 16px;
    }
    .score-value {
        font-size: 1.5rem;
    }
    .btn {
        padding: 12px 30px;
        font-size: 1.05rem;
    }
    .btn.btn-icon .btn-icon-svg {
        width: 20px;
        height: 20px;
    }
    #next-container {
        padding: 10px 14px 10px 16px;
    }
    .next-container-label {
        font-size: 0.65rem;
        margin-right: 12px;
    }
    .next-preview-canvas {
        width: 32px;
        height: 32px;
    }
    .overlay-title {
        font-size: 2.25rem;
    }
    .overlay-subtitle {
        font-size: 0.95rem;
    }
    .overlay-card {
        padding: 1.75rem 2rem;
    }
}

/* Tablet Portrait (641px–768px) */
@media (min-width: 641px) and (max-width: 768px) {
    :root {
        --screen-padding: 16px;
        --top-bar-height: 40px;
        --ui-inset: 8px;
        --game-gap: 12px;
        --board-radius: 20px;
    }
    body {
        padding: var(--screen-padding);
    }
    .score-container {
        padding: 0 12px 0 14px;
        border-radius: 10px;
    }
    .score-value {
        font-size: 1.35rem;
    }
    .btn {
        padding: 12px 28px;
        font-size: 1rem;
    }
    .btn.btn-icon .btn-icon-svg {
        width: 18px;
        height: 18px;
    }
    #next-container {
        padding: 8px 12px 8px 14px;
    }
    #next-container::before {
        width: 48px;
    }
    .next-container-label {
        font-size: 0.6rem;
        margin-right: 10px;
    }
    .next-queue {
        gap: 8px;
    }
    .next-preview-canvas {
        width: 30px;
        height: 30px;
    }
    .overlay-card {
        max-width: min(300px, calc(100% - 24px));
        padding: 1.5rem 1.75rem;
    }
    .overlay-title {
        font-size: 2rem;
    }
    .overlay-subtitle {
        font-size: 0.9rem;
        margin-bottom: 1.25rem;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    :root {
        --screen-padding: 12px;
        --top-bar-height: 38px;
        --ui-inset: 8px;
        --game-gap: 10px;
        --board-radius: 18px;
    }
    body {
        padding: var(--screen-padding);
    }
    #start-screen {
        padding: 16px;
    }
    .score-container {
        padding: 0 10px 0 12px;
        border-radius: 10px;
    }
    .score-value {
        font-size: 1.25rem;
    }
    .btn {
        padding: 10px 24px;
        font-size: 0.95rem;
    }
    .btn.btn-icon .btn-icon-svg {
        width: 18px;
        height: 18px;
    }
    #next-container {
        padding: 8px 10px 8px 12px;
    }
    #next-container::before {
        width: 40px;
    }
    .next-container-label {
        font-size: 0.55rem;
        letter-spacing: 0.1em;
        margin-right: 8px;
    }
    .next-queue {
        gap: 6px;
    }
    .next-preview-canvas {
        width: 28px;
        height: 28px;
    }
    .overlay-card {
        max-width: min(280px, calc(100% - 24px));
        padding: 1.25rem 1.5rem;
    }
    .overlay-title {
        font-size: 1.75rem;
    }
    .overlay-subtitle {
        font-size: 0.85rem;
        margin-bottom: 1rem;
    }
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    :root {
        --screen-padding: 8px;
        --top-bar-height: 34px;
        --ui-inset: 6px;
        --game-gap: 8px;
        --board-radius: 14px;
    }
    body {
        padding: var(--screen-padding);
    }
    #start-screen {
        padding: 12px;
    }
    .score-container {
        padding: 0 8px 0 10px;
        border-radius: 8px;
    }
    .score-value {
        font-size: 1.1rem;
    }
    .btn {
        padding: 8px 20px;
        font-size: 0.9rem;
    }
    .btn.btn-icon .btn-icon-svg {
        width: 16px;
        height: 16px;
    }
    #next-container {
        padding: 6px 8px 6px 10px;
    }
    #next-container::before {
        width: 32px;
    }
    .next-container-label {
        font-size: 0.5rem;
        letter-spacing: 0.08em;
        margin-right: 6px;
    }
    .next-queue {
        gap: 4px;
    }
    .next-preview-canvas {
        width: 24px;
        height: 24px;
    }
    .overlay-card {
        max-width: min(260px, calc(100% - 16px));
        padding: 1rem 1.25rem;
    }
    .overlay-title {
        font-size: 1.5rem;
    }
    .overlay-subtitle {
        font-size: 0.8rem;
        margin-bottom: 0.75rem;
    }
}

/* Landscape Mobile: short viewport in landscape */
@media (orientation: landscape) and (max-height: 500px) {
    :root {
        --screen-padding: 6px;
        --top-bar-height: 32px;
        --ui-inset: 4px;
        --game-gap: 6px;
        --board-radius: 12px;
    }
    body {
        padding: var(--screen-padding);
    }
    body.in-game {
        gap: var(--game-gap);
    }
    #start-screen {
        padding: 8px;
    }
    .score-container {
        padding: 0 6px 0 8px;
        border-radius: 8px;
    }
    .score-value {
        font-size: 1rem;
    }
    .btn {
        padding: 6px 16px;
        font-size: 0.85rem;
    }
    .btn.btn-icon .btn-icon-svg {
        width: 14px;
        height: 14px;
    }
    #next-container {
        padding: 4px 6px 4px 8px;
        max-width: 100%;
        min-width: 0;
        width: max-content;
        box-sizing: border-box;
    }
    #next-container::before {
        width: 28px;
    }
    .next-container-label {
        font-size: 0.45rem;
        letter-spacing: 0.06em;
        margin-right: 4px;
    }
    .next-queue {
        gap: 3px;
        min-width: 0;
        flex-shrink: 1;
    }
    .next-preview-canvas {
        width: 20px;
        height: 20px;
        min-width: 20px;
    }
    .overlay-card {
        max-width: min(240px, calc(100% - 16px));
        padding: 0.75rem 1rem;
    }
    .overlay-title {
        font-size: 1.35rem;
    }
    .overlay-subtitle {
        font-size: 0.75rem;
        margin-bottom: 0.5rem;
    }
}
