* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* read by game.js to keep HUD/controls clear of OS chrome */
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --bg: #0b0e1a;
    --panel: rgba(15, 20, 40, 0.92);
    --cyan: #2de2e6;
    --pink: #ff3864;
    --yellow: #f9c80e;
    --text: #eaf6ff;
    --dim: #7a8bb5;
}

html,
body {
    height: 100%;
    overflow: hidden;
    /* outside-the-game region: darker, with a faint grid so the playfield pops */
    background:
        linear-gradient(rgba(45, 226, 230, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(45, 226, 230, 0.025) 1px, transparent 1px),
        #06080f;
    background-size: 28px 28px, 28px 28px, auto;
    font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    overscroll-behavior: none;
}

#game-wrap {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

canvas {
    display: block;
    background: radial-gradient(ellipse at 50% 0%, #141a33 0%, #0b0e1a 70%);
    touch-action: none;
    box-shadow:
        0 0 0 1px rgba(45, 226, 230, 0.25),
        0 0 60px rgba(45, 226, 230, 0.12),
        0 0 120px rgba(0, 0, 0, 0.8);
}

/* ---------- overlays ---------- */
.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    background: rgba(7, 9, 18, 0.82);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 10;
    padding: 24px;
}

.overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.title {
    font-size: clamp(2.4rem, 11vw, 4rem);
    line-height: 1.05;
    text-align: center;
    font-weight: 800;
    letter-spacing: 0.06em;
    color: var(--text);
    text-shadow:
        0 0 12px var(--cyan),
        0 0 48px rgba(45, 226, 230, 0.45);
}

h2 {
    font-size: clamp(1.6rem, 7vw, 2.4rem);
    letter-spacing: 0.12em;
    color: var(--text);
    text-shadow: 0 0 16px rgba(45, 226, 230, 0.6);
}

.subtitle {
    color: var(--dim);
    font-size: 0.95rem;
    letter-spacing: 0.04em;
    text-align: center;
}

.btn {
    font: inherit;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.14em;
    padding: 14px 44px;
    min-width: 230px;
    border-radius: 999px;
    border: 2px solid var(--cyan);
    background: transparent;
    color: var(--cyan);
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: var(--cyan);
    color: #04222a;
    box-shadow: 0 0 24px rgba(45, 226, 230, 0.55);
}

.final-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.final-score .label {
    color: var(--dim);
    letter-spacing: 0.3em;
    font-size: 0.8rem;
}

#final-score {
    font-size: clamp(2.6rem, 12vw, 4rem);
    font-weight: 800;
    color: var(--yellow);
    text-shadow: 0 0 22px rgba(249, 200, 14, 0.55);
}

#highscore-entry {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

#highscore-entry.hidden {
    display: none;
}

#name-input {
    font: inherit;
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: 0.18em;
    text-align: center;
    text-transform: uppercase;
    width: 240px;
    padding: 12px;
    border-radius: 12px;
    border: 2px solid var(--pink);
    background: rgba(255, 56, 100, 0.08);
    color: var(--text);
    outline: none;
}

#name-input::placeholder {
    color: var(--dim);
}

/* ---------- leaderboard ---------- */
#lb-list {
    list-style: none;
    width: min(340px, 86vw);
    max-height: 46vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#lb-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-radius: 10px;
    background: var(--panel);
    border: 1px solid rgba(45, 226, 230, 0.18);
    color: var(--text);
    font-weight: 600;
}

#lb-list li .rank {
    color: var(--dim);
    width: 1.8em;
    font-variant-numeric: tabular-nums;
}

#lb-list li .name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: 0.06em;
}

#lb-list li .pts {
    color: var(--yellow);
    font-variant-numeric: tabular-nums;
}

#lb-list li:nth-child(1) {
    border-color: var(--yellow);
    box-shadow: 0 0 14px rgba(249, 200, 14, 0.25);
}

#lb-list li.empty {
    justify-content: center;
    color: var(--dim);
    font-weight: 400;
}

/* ---------- in-game chrome ---------- */
#btn-pause {
    position: absolute;
    top: calc(10px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    z-index: 5;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid rgba(122, 139, 181, 0.5);
    background: rgba(15, 20, 40, 0.6);
    color: var(--dim);
    font-size: 0.85rem;
    cursor: pointer;
    display: none;
}

#btn-pause.visible {
    display: block;
}

#level-banner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 4;
    font-size: clamp(2rem, 9vw, 3.2rem);
    font-weight: 800;
    letter-spacing: 0.2em;
    color: var(--cyan);
    text-shadow: 0 0 24px rgba(45, 226, 230, 0.8);
    opacity: 0;
}

#level-banner.show {
    animation: banner 1.6s ease forwards;
}

@keyframes banner {
    0% {
        opacity: 0;
        transform: scale(0.7);
    }

    20% {
        opacity: 1;
        transform: scale(1.05);
    }

    35% {
        transform: scale(1);
    }

    75% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: scale(1.1);
    }
}
