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

:root {
    color-scheme: dark;
    --bg-1: #06131d;
    --bg-2: #0b2536;
    --bg-3: #113d50;
    --card: rgba(7, 20, 30, 0.74);
    --card-strong: rgba(9, 27, 39, 0.88);
    --line: rgba(141, 225, 255, 0.18);
    --line-strong: rgba(141, 225, 255, 0.34);
    --text: #f6fbff;
    --muted: #a8c0cf;
    --accent: #6cf2d4;
    --accent-2: #ffbf5f;
    --accent-3: #ff7f50;
    --success: #62f7a7;
    --danger: #ff7c7c;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.38);
    --radius: 22px;
}

html,
body {
    width: 100%;
    height: 100%;
}

body {
    overflow: hidden;
    font-family: "Outfit", sans-serif;
    background:
        radial-gradient(circle at top, rgba(108, 242, 212, 0.16), transparent 28%),
        radial-gradient(circle at 80% 16%, rgba(255, 191, 95, 0.12), transparent 24%),
        linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 44%, var(--bg-3) 100%);
    color: var(--text);
}

body::before,
body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
}

body::before {
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
    background-size: 64px 64px;
    mask-image: radial-gradient(circle at center, black 35%, transparent 95%);
    opacity: 0.28;
}

body::after {
    background:
        radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.1) 0 1px, transparent 1px),
        radial-gradient(circle at 75% 18%, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px),
        radial-gradient(circle at 60% 40%, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px),
        radial-gradient(circle at 15% 65%, rgba(255, 255, 255, 0.12) 0 1px, transparent 1px),
        radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px);
}

canvas {
    display: block;
}

.screen,
.overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.screen {
    display: grid;
    place-items: center;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    background: linear-gradient(180deg, rgba(2, 7, 14, 0.68), rgba(2, 8, 14, 0.88));
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

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

.screen-visible,
.overlay-visible {
    opacity: 1;
    visibility: visible;
}

.hero-shell {
    width: min(1100px, 100%);
    max-height: calc(100svh - 24px);
    display: grid;
    gap: 14px;
}

.hero-top,
.start-grid {
    min-width: 0;
}

.hero-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.brand-copy {
    max-width: 640px;
}

.eyebrow {
    font-size: 0.72rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 10px;
}

.hero-title {
    font-family: "Space Grotesk", sans-serif;
    font-size: clamp(2.25rem, 5vw, 4.1rem);
    line-height: 0.95;
    margin-bottom: 10px;
}

.hero-subtitle,
.section-head p,
.microcopy,
.cta-note,
.tip-text,
.modal-subtitle,
#scoreSourceLabel,
#modalScoreSourceLabel,
.stat-name,
.card-label {
    color: var(--muted);
}

.hero-subtitle {
    font-size: clamp(0.98rem, 1.8vw, 1.2rem);
    max-width: 50ch;
}

.language-picker {
    display: grid;
    gap: 6px;
    min-width: 160px;
    font-size: 0.82rem;
    color: var(--muted);
}

.language-picker select,
.name-input {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 14px;
    background: rgba(5, 16, 25, 0.88);
    color: var(--text);
    font: inherit;
    outline: none;
}

.language-picker select {
    padding: 10px 12px;
}

.glass-card,
.ui-card,
.modal-card {
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: var(--shadow);
}

.start-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.8fr);
    gap: 14px;
}

.glass-card,
.ui-card,
.modal-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: linear-gradient(180deg, var(--card-strong), var(--card));
}

.setup-card,
.score-card {
    padding: 18px;
}

.setup-card {
    display: grid;
    gap: 14px;
}

.score-card {
    display: grid;
    gap: 12px;
    align-content: start;
}

.section-head {
    display: grid;
    gap: 4px;
}

.section-head h2,
.modal-scores-head h3,
.modal-title {
    font-family: "Space Grotesk", sans-serif;
}

.section-head h2 {
    font-size: 1.15rem;
}

.field-stack,
.option-block,
.tip-box {
    display: grid;
    gap: 8px;
}

.field-label,
.option-title,
.tip-label {
    font-size: 0.8rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.name-input {
    padding: 12px 14px;
    font-size: 1rem;
}

.option-grid {
    display: grid;
    gap: 8px;
}

.two-col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.chips-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.option-btn {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
    min-width: 0;
}

.option-btn:hover {
    transform: translateY(-1px);
    border-color: var(--line-strong);
}

.option-btn.is-selected {
    background: linear-gradient(135deg, rgba(108, 242, 212, 0.18), rgba(255, 191, 95, 0.14));
    border-color: rgba(108, 242, 212, 0.58);
    box-shadow: inset 0 0 0 1px rgba(108, 242, 212, 0.2);
}

.option-btn strong,
.option-btn span {
    display: block;
    min-width: 0;
}

.option-btn strong {
    font-size: 0.95rem;
}

.option-btn span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.78rem;
}

.option-btn.compact strong {
    font-size: 0.88rem;
}

.option-btn.compact span {
    display: none;
}

.cta-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
    align-items: center;
}

.primary-btn,
.secondary-btn {
    border: none;
    border-radius: 16px;
    padding: 13px 16px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.primary-btn {
    color: #07202d;
    background: linear-gradient(135deg, var(--accent), #9ef1ff 52%, var(--accent-2));
    box-shadow: 0 12px 28px rgba(108, 242, 212, 0.24);
}

.primary-btn:hover,
.secondary-btn:hover {
    transform: translateY(-1px);
}

.secondary-btn {
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.highscore-list {
    list-style: none;
    display: grid;
    gap: 7px;
}

.highscore-list.compact {
    gap: 6px;
}

.highscore-item {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.highscore-item.empty {
    opacity: 0.6;
}

.highscore-rank {
    font-family: "Space Grotesk", sans-serif;
    color: var(--accent-2);
}

.highscore-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.highscore-score {
    font-family: "Space Grotesk", sans-serif;
}

.tip-box {
    padding: 12px 14px;
    border-radius: 18px;
    background: linear-gradient(135deg, rgba(255, 191, 95, 0.08), rgba(108, 242, 212, 0.07));
    border: 1px solid rgba(255, 191, 95, 0.16);
}

.ad-slot:empty {
    display: none;
}

.ad-slot:not(:empty) {
    min-height: 84px;
    padding: 10px;
    border-radius: 18px;
    border: 1px dashed rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.04);
}

.hud {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.hud-visible {
    opacity: 1;
}

.hud-stack {
    display: grid;
    gap: 10px;
    width: min(360px, calc(100vw - 24px));
}

.ui-card {
    padding: 14px 16px;
}

.card-label {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.75rem;
    margin-bottom: 8px;
}

.mission-text {
    font-family: "Space Grotesk", sans-serif;
    font-size: clamp(1rem, 2.4vw, 1.35rem);
    line-height: 1.2;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.stat,
.summary-item {
    display: grid;
    gap: 3px;
}

.stat strong,
.summary-item strong,
.session-metrics strong {
    font-family: "Space Grotesk", sans-serif;
    font-size: 1.05rem;
}

.lives-row,
.timer-block,
.action-row,
.session-metrics,
.modal-actions,
.modal-scores-head {
    display: flex;
    align-items: center;
}

.lives-row,
.timer-block {
    justify-content: space-between;
    gap: 12px;
    margin-top: 12px;
}

.timer-block {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
}

.timer-bar,
.progress-bar {
    overflow: hidden;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 999px;
}

.timer-bar {
    height: 10px;
}

.progress-bar {
    height: 7px;
}

.timer-fill,
.progress-fill {
    height: 100%;
    transition: width 0.12s linear, background 0.2s ease;
}

.timer-fill {
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.timer-fill.warning {
    background: linear-gradient(90deg, #ff6f61, #ffb366);
}

.progress-fill {
    width: 0%;
    background: linear-gradient(90deg, #7dbbff, #6cf2d4);
}

.timer-text {
    font-family: "Space Grotesk", sans-serif;
}

.lives-container {
    display: flex;
    gap: 6px;
    font-size: 1rem;
}

.life {
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.life.lost {
    opacity: 0.2;
    transform: scale(0.9);
}

.session-metrics {
    flex-wrap: wrap;
    gap: 8px 10px;
}

.session-metrics span:nth-of-type(odd) {
    min-width: 72px;
}

.action-row {
    gap: 8px;
    pointer-events: auto;
}

.action-row .secondary-btn {
    flex: 1;
}

.feedback {
    position: fixed;
    left: 50%;
    bottom: max(22px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 25;
    min-width: min(420px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    padding: 14px 18px;
    border-radius: 18px;
    text-align: center;
    font-weight: 700;
    font-size: clamp(0.95rem, 2vw, 1.25rem);
    background: rgba(4, 14, 22, 0.92);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.feedback.show {
    opacity: 1;
    transform: translateX(-50%) translateY(-8px);
}

.overlay {
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(2, 8, 14, 0.78);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

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

.modal-card {
    width: min(700px, 100%);
    padding: 22px;
    display: grid;
    gap: 16px;
}

.modal-title {
    font-size: clamp(2rem, 4vw, 2.8rem);
    line-height: 1;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.summary-item {
    padding: 12px 14px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.04);
}

.rank-message {
    min-height: 1.4em;
    color: var(--accent);
    font-weight: 600;
}

.modal-scores {
    display: grid;
    gap: 10px;
}

.modal-scores-head {
    justify-content: space-between;
    gap: 12px;
}

.modal-actions {
    justify-content: flex-end;
    gap: 10px;
}

.flight-progress {
    display: none;
    margin-top: 10px;
}

.flight-progress.active {
    display: block;
}

.score-popup {
    position: fixed;
    z-index: 30;
    font-family: "Space Grotesk", sans-serif;
    font-size: 1.8rem;
    color: var(--success);
    text-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    pointer-events: none;
    animation: scoreFloat 0.9s ease-out forwards;
}

@keyframes scoreFloat {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-64px) scale(1.3);
    }
}

@media (max-width: 980px) {
    .start-grid {
        grid-template-columns: 1fr;
    }

    .hero-shell {
        max-height: none;
    }
}

@media (max-width: 720px) {
    .screen {
        display: block;
        padding: 8px;
    }

    .hero-shell {
        gap: 10px;
        max-height: none;
    }

    .hero-top {
        gap: 10px;
        flex-direction: column;
    }

    .language-picker {
        min-width: 0;
        width: 100%;
    }

    .setup-card,
    .score-card,
    .modal-card {
        padding: 14px;
    }

    .cta-row {
        grid-template-columns: 1fr;
    }

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

    .score-card {
        max-height: 240px;
        overflow-y: auto;
    }

    .summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .modal-actions {
        flex-direction: column;
    }

    .modal-actions button {
        width: 100%;
    }
}

@media (max-width: 520px) {
    .hero-shell {
        gap: 8px;
    }

    .hero-title {
        font-size: 2rem;
    }

    .hero-subtitle {
        font-size: 0.92rem;
    }

    .two-col {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

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

    .option-btn {
        padding: 8px 9px;
    }

    .option-btn strong {
        font-size: 0.8rem;
    }

    .option-btn span {
        display: none;
    }

    .highscore-item {
        padding: 8px 9px;
        gap: 8px;
        grid-template-columns: 28px minmax(0, 1fr) auto;
        font-size: 0.88rem;
    }

    .tip-box {
        display: none;
    }

    .setup-card,
    .score-card {
        gap: 10px;
    }

    .score-card {
        max-height: 220px;
    }

    .hud {
        right: 12px;
        left: 12px;
    }

    .hud-stack {
        width: auto;
    }
}

@media (max-height: 760px) {
    .hero-shell {
        gap: 8px;
    }

    .hero-title {
        font-size: clamp(1.9rem, 5vw, 3rem);
    }

    .hero-subtitle {
        font-size: 0.9rem;
    }

    .setup-card,
    .score-card {
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .setup-card {
        gap: 10px;
    }

    .option-block {
        gap: 6px;
    }

    .highscore-item {
        padding-top: 7px;
        padding-bottom: 7px;
    }
}
