:root {
    --bg-deep: #031424;
    --bg-mid: #0b2b44;
    --panel: rgba(4, 27, 44, 0.8);
    --panel-border: rgba(122, 233, 255, 0.22);
    --text-main: #ecfbff;
    --text-muted: #9dd3e0;
    --aqua: #74e6ff;
    --foam: #bff7ff;
    --reef: #1bbfb7;
    --warning: #ff8f6b;
    --boat: #ffd6a3;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: "Sora", "Segoe UI", sans-serif;
    color: var(--text-main);
    background:
        radial-gradient(circle at top left, rgba(27, 191, 183, 0.16), transparent 30%),
        radial-gradient(circle at right 20%, rgba(116, 230, 255, 0.18), transparent 28%),
        linear-gradient(160deg, #03101d 0%, #0b2842 45%, #051a2d 100%);
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
    background-size: 34px 34px;
    mask-image: radial-gradient(circle at center, black 60%, transparent 92%);
}

.app-shell {
    width: min(1240px, calc(100vw - 32px));
    margin: 0 auto;
    padding: 28px 0 36px;
    display: grid;
    grid-template-columns: minmax(320px, 420px) minmax(320px, 1fr);
    gap: 28px;
    align-items: start;
}

.hero-panel,
.game-panel {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 28px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}

.hero-panel {
    padding: 28px;
    overflow: hidden;
}

.hero-panel::after {
    content: '';
    position: absolute;
    right: -90px;
    bottom: -90px;
    width: 240px;
    height: 240px;
    border-radius: 999px;
    background: radial-gradient(circle, rgba(116, 230, 255, 0.18), rgba(116, 230, 255, 0));
}

.eyebrow {
    margin: 0 0 10px;
    font-family: "Space Mono", monospace;
    font-size: 0.82rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--aqua);
}

.eyebrow--small {
    margin-bottom: 6px;
    font-size: 0.72rem;
}

h1,
h2 {
    margin: 0;
    line-height: 1.04;
}

h1 {
    font-size: clamp(2.8rem, 4vw, 4.3rem);
    max-width: 12ch;
}

.tagline {
    margin: 18px 0 24px;
    max-width: 38ch;
    color: var(--text-muted);
    font-size: 1.02rem;
    line-height: 1.6;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-card,
.leaderboard,
.legend-chip {
    background: rgba(8, 43, 68, 0.72);
    border: 1px solid rgba(191, 247, 255, 0.1);
}

.stat-card {
    padding: 16px;
    border-radius: 20px;
    min-height: 106px;
}

.accent-card {
    background: linear-gradient(180deg, rgba(12, 74, 106, 0.92), rgba(8, 43, 68, 0.8));
}

.label {
    display: block;
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-bottom: 12px;
}

.stat-card strong,
.run-score strong {
    font-size: clamp(1.5rem, 3vw, 2.4rem);
}

.exit-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2ch;
}

.exit-status__icon {
    line-height: 1;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.legend-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 18px;
}

.legend-chip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 999px;
    color: var(--text-muted);
}

.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.legend-swatch--timmy {
    background: linear-gradient(135deg, #89edff, #1c7ccf);
}

.legend-swatch--net {
    background: linear-gradient(135deg, #ffb493, #ff6b57);
}

.legend-swatch--boat {
    background: linear-gradient(135deg, #ffd6a3, #ef534f);
}

.leaderboard {
    position: relative;
    z-index: 1;
    padding: 20px;
    border-radius: 24px;
}

.leaderboard__header,
.run-score {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.leaderboard__list {
    margin: 18px 0 14px;
    padding: 0;
    list-style: none;
}

.leaderboard__list li {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 14px 16px;
    border-radius: 18px;
    background: rgba(2, 19, 33, 0.56);
    font-weight: 700;
}

.status-pill {
    border-radius: 999px;
    padding: 8px 12px;
    background: rgba(116, 230, 255, 0.12);
    border: 1px solid rgba(116, 230, 255, 0.2);
    color: var(--foam);
    font-family: "Space Mono", monospace;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.run-score {
    margin-bottom: 8px;
    padding-top: 12px;
    border-top: 1px solid rgba(191, 247, 255, 0.1);
}

.leaderboard__hint {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.game-panel {
    padding: 22px;
}

.game-frame {
    position: relative;
    border-radius: 28px;
    overflow: hidden;
    background: linear-gradient(180deg, rgba(3, 20, 36, 0.8), rgba(6, 38, 58, 0.7));
    border: 1px solid rgba(191, 247, 255, 0.12);
}

.game-frame.is-playing {
    touch-action: none;
}

canvas {
    display: block;
    width: 100%;
    height: auto;
}

.overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(180deg, rgba(0, 10, 20, 0.18), rgba(0, 9, 18, 0.72));
    transition: opacity 220ms ease, visibility 220ms ease;
}

.overlay.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.overlay__card {
    width: min(460px, 100%);
    padding: 24px;
    border-radius: 26px;
    background: rgba(4, 27, 44, 0.84);
    border: 1px solid rgba(122, 233, 255, 0.16);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.36);
    text-align: center;
}

.overlay__kicker,
.overlay__controls {
    margin: 0;
    color: var(--text-muted);
}

.overlay__kicker {
    font-family: 'Space Mono', monospace;
    color: var(--aqua);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    font-size: 0.78rem;
}

.overlay__card h2 {
    margin: 12px 0 10px;
    font-size: clamp(2rem, 5vw, 2.8rem);
}

.overlay__card p + p {
    margin-top: 14px;
}

.primary-button {
    width: 100%;
    border: 0;
    border-radius: 18px;
    margin-top: 18px;
    padding: 15px 18px;
    background: linear-gradient(135deg, #89edff, #3dd0c4 60%, #0f8992);
    color: #022538;
    font-weight: 900;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 160ms ease, box-shadow 160ms ease;
    box-shadow: 0 12px 22px rgba(61, 208, 196, 0.22);
}

.primary-button:hover,
.primary-button:focus-visible {
    transform: translateY(-1px);
    box-shadow: 0 16px 26px rgba(61, 208, 196, 0.3);
}

.touch-controls {
    margin-top: 18px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 92px));
    grid-template-areas:
        '. up .'
        'left . right'
        '. down .';
    justify-content: center;
    gap: 10px;
}

.touch-button {
    min-height: 72px;
    border-radius: 22px;
    border: 1px solid rgba(191, 247, 255, 0.14);
    background: rgba(8, 43, 68, 0.84);
    color: var(--foam);
    font-size: 1.45rem;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 140ms ease, background 140ms ease;
}

.touch-button:active,
.touch-button:focus-visible {
    transform: scale(0.98);
    background: rgba(14, 67, 94, 0.94);
}

.touch-up {
    grid-area: up;
}

.touch-left {
    grid-area: left;
}

.touch-right {
    grid-area: right;
}

.touch-down {
    grid-area: down;
}

@media (max-width: 1080px) {
    .app-shell {
        grid-template-columns: 1fr;
        width: min(920px, calc(100vw - 24px));
        padding-top: 20px;
    }

    .game-panel {
        order: -1;
    }

    h1 {
        max-width: 14ch;
    }
}

@media (max-width: 720px) {
    .app-shell {
        width: min(100vw - 16px, 100%);
        gap: 16px;
    }

    .hero-panel,
    .game-panel {
        border-radius: 22px;
    }

    .hero-panel,
    .game-panel {
        padding: 18px;
    }

    .status-grid {
        grid-template-columns: 1fr;
    }

    .overlay {
        place-items: start center;
        padding: 12px;
        overflow-y: auto;
    }

    .overlay__card {
        margin: 8px 0;
        padding: 18px;
        border-radius: 22px;
    }

    .overlay__card h2 {
        font-size: clamp(1.7rem, 8vw, 2.2rem);
    }

    .overlay__controls {
        font-size: 0.94rem;
    }

    .primary-button {
        padding: 13px 16px;
    }

    .touch-controls {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}