/* TAKAA-AJO */

:root {
    --neon-blue: #38bdf8;
    --neon-cyan: #22d3ee;
    --neon-green: #22c55e;
    --neon-red: #ef4444;
    --ink: #e2e8f0;
    --muted: #94a3b8;
    --panel: rgba(8, 14, 28, 0.78);
    --line: rgba(255, 255, 255, 0.1);
}

html, body {
    margin: 0;
    padding: 0;
    background: #020617;
    color: var(--ink);
    font-family: "Rajdhani", sans-serif;
}

/* =====================================================
   CANVAS (PELIKENTTÄ)
   ===================================================== */

canvas {
    display: block;
    margin: 0 auto;
    background: #020617;
    border: 3px solid var(--neon-cyan);
    border-radius: 12px;
    box-shadow:
        0 0 20px rgba(34, 211, 238, 0.2),
        inset 0 0 10px rgba(34, 211, 238, 0.1);
    image-rendering: auto;
}

/* =====================================================
   PÄÄVALIKKO
   ===================================================== */

.menu-page {
    height: 100dvh;
    overflow: hidden;
    color: var(--ink);
    background: #020617;
    font-family: "Rajdhani", sans-serif;
}

.menu-page *,
.menu-page *::before,
.menu-page *::after {
    box-sizing: border-box;
}

.scene {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse 80% 50% at 50% -10%, rgba(56, 189, 248, 0.16), transparent 55%),
        radial-gradient(ellipse 40% 40% at 100% 100%, rgba(239, 68, 68, 0.1), transparent 50%),
        #020617;
}

.scene-glow {
    position: absolute;
    width: 42vw;
    height: 42vw;
    border-radius: 50%;
    filter: blur(40px);
    opacity: 0.55;
    animation: glow-breathe 4.8s ease-in-out infinite;
}

.scene-glow-blue {
    top: -8vw;
    left: -6vw;
    background: rgba(56, 189, 248, 0.22);
}

.scene-glow-red {
    right: -8vw;
    bottom: -10vw;
    background: rgba(239, 68, 68, 0.16);
    animation-delay: -2.4s;
}

.scene-road {
    position: absolute;
    left: 50%;
    bottom: -8%;
    width: 160%;
    height: 48%;
    transform: translateX(-50%) perspective(520px) rotateX(72deg);
    background-image: repeating-linear-gradient(
        to bottom,
        transparent 0 28px,
        rgba(250, 204, 21, 0.55) 28px 36px,
        transparent 36px 72px
    );
    background-size: 14px 100%;
    background-position: center top;
    mask-image: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent 78%);
    opacity: 0.28;
    animation: road-scroll 1.1s linear infinite;
}

.scene-vignette {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 40%, rgba(2, 6, 23, 0.72) 100%);
}

.menu {
    position: relative;
    z-index: 1;
    width: min(1180px, calc(100vw - 36px));
    height: min(820px, calc(100dvh - 28px));
    margin: 14px auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.hero {
    text-align: center;
    flex: 0 0 auto;
}

.siren-bar {
    display: flex;
    width: 148px;
    height: 5px;
    margin: 0 auto 10px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(15, 23, 42, 0.9);
    box-shadow: 0 0 18px rgba(56, 189, 248, 0.25);
}

.siren-bar span {
    flex: 1;
    animation: siren 1.05s ease-in-out infinite;
}

.siren-bar span:first-child {
    background: #38bdf8;
}

.siren-bar span:last-child {
    background: #ef4444;
    animation-delay: 0.52s;
}

.kicker {
    margin: 0 0 4px;
    font-family: "Orbitron", sans-serif;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.42em;
    text-transform: uppercase;
    color: var(--neon-cyan);
}

.menu-page h1 {
    margin: 0;
    font-family: "Orbitron", sans-serif;
    font-weight: 900;
    font-size: clamp(46px, 6vw, 78px);
    line-height: 0.92;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: linear-gradient(180deg, #ffffff 10%, #bae6fd 46%, #38bdf8 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 10px 18px rgba(56, 189, 248, 0.28));
}

.lede {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 18px;
    letter-spacing: 0.04em;
}

.menu-grid {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 0.92fr) minmax(280px, 1.12fr);
    gap: 14px;
}

.menu-page .panel {
    min-height: 0;
    overflow: auto;
    padding: 18px 18px 16px;
    border-radius: 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow:
        0 18px 40px rgba(0, 0, 0, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(16px);
    scrollbar-width: thin;
    scrollbar-color: rgba(56, 189, 248, 0.35) transparent;
}

.menu-page .panel::-webkit-scrollbar {
    width: 8px;
}

.menu-page .panel::-webkit-scrollbar-thumb {
    background: rgba(56, 189, 248, 0.35);
    border-radius: 99px;
}

.panel-accent {
    --accent: var(--neon-cyan);
}

.panel-gold {
    --accent: #facc15;
    display: flex;
    flex-direction: column;
}

.panel-play {
    --accent: var(--neon-blue);
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: auto;
}

.menu-page .panel::before {
    content: "";
    display: block;
    height: 2px;
    margin: -6px 8px 12px;
    border-radius: 99px;
    background: linear-gradient(90deg, transparent, var(--accent, var(--neon-cyan)), transparent);
}

.section-title {
    font-family: "Orbitron", sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: var(--neon-cyan);
    letter-spacing: 0.22em;
    text-transform: uppercase;
    margin: 0 0 12px;
    text-align: center;
}

.rule {
    margin: 0 0 12px;
    text-align: left;
}

.rule strong {
    display: block;
    margin-bottom: 2px;
    font-family: "Orbitron", sans-serif;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.14em;
}

.rule p {
    margin: 0;
    color: #cbd5e1;
    font-size: 16px;
    line-height: 1.35;
}

.rule-danger strong {
    color: #fb7185;
}

.rule-safe strong {
    color: var(--neon-cyan);
}

.controls {
    display: grid;
    gap: 8px;
    margin-top: 4px;
}

.control-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.05);
    text-align: left;
}

.control-row b {
    display: block;
    font-size: 15px;
    letter-spacing: 0.04em;
}

.control-row span {
    color: var(--muted);
    font-size: 13px;
}

.keys {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
}

kbd {
    min-width: 18px;
    padding: 3px 6px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-bottom-width: 3px;
    background: #0b1222;
    color: #f8fafc;
    font-family: "Orbitron", sans-serif;
    font-size: 10px;
    line-height: 1.2;
    text-align: center;
}

.hint {
    margin: 10px 0 0;
    color: #7dd3fc;
    font-size: 14px;
    line-height: 1.35;
    text-align: left;
}

.hof-note {
    margin: 12px 0 0;
    color: #64748b;
    font-size: 14px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-align: center;
    line-height: 1.45;
}

#highscore-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.score-empty {
    margin: auto;
    padding: 12px;
    color: #64748b;
    font-size: 16px;
    font-style: italic;
    text-align: center;
}

.gp-slot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.gp-slot + .gp-slot {
    margin-top: 8px;
}

.gp-who {
    color: var(--muted);
    font-size: 13px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.gp-state {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: "Orbitron", sans-serif;
    font-size: 12px;
    letter-spacing: 0.06em;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #475569;
    box-shadow: 0 0 0 4px rgba(71, 85, 105, 0.2);
}

.gp-slot.connected {
    border-color: rgba(34, 197, 94, 0.35);
}

.gp-slot.connected .status-dot {
    background: var(--neon-green);
    box-shadow: 0 0 10px var(--neon-green);
}

.stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 132px;
    border-radius: 14px;
    overflow: hidden;
    background: #070d18;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.stage-img,
.map-card img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transform: scale(1.045);
    transition: opacity 0.55s ease, transform 0.8s ease, filter 0.3s ease;
}

.stage-img {
    position: absolute;
    inset: 0;
}

.stage-img.is-ready.is-active {
    opacity: 1;
    transform: scale(1);
}

.shot::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background: linear-gradient(105deg, transparent 20%, rgba(255, 255, 255, 0.07) 42%, transparent 64%);
    background-size: 220% 100%;
    animation: shimmer 1.25s ease-in-out infinite;
}

.shot.is-shown::before {
    opacity: 0;
    animation: none;
    transition: opacity 0.35s ease;
}

.stage-caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 28px 12px 10px;
    background: linear-gradient(to top, rgba(2, 6, 23, 0.92), transparent);
    text-align: left;
}

.stage-caption strong {
    font-family: "Orbitron", sans-serif;
    font-size: 14px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.stage-caption span {
    color: #cbd5e1;
    font-size: 15px;
}

.map-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.map-card {
    position: relative;
    padding: 0;
    border: 1px solid #1e293b;
    border-radius: 12px;
    overflow: hidden;
    background: #05080f;
    color: inherit;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}

.map-card .shot {
    display: block;
    height: 64px;
    position: relative;
    overflow: hidden;
    background: #070d18;
}

.map-card img.is-ready {
    opacity: 1;
    transform: none;
    filter: saturate(0.75) brightness(0.78);
}

.map-card:hover {
    transform: translateY(-2px);
    border-color: rgba(56, 189, 248, 0.45);
}

.map-card.active {
    border-color: var(--neon-blue);
    box-shadow: 0 0 0 1px var(--neon-blue), 0 8px 24px rgba(56, 189, 248, 0.22);
}

.map-card.active img.is-ready {
    filter: none;
}

.map-card:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.map-label {
    display: block;
    padding: 6px 8px 7px;
    font-family: "Orbitron", sans-serif;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.play-btn {
    flex: 0 0 auto;
    width: 100%;
    margin: 0;
    padding: 15px 18px 13px;
    border: 0;
    border-radius: 12px;
    cursor: pointer;
    color: #f8fafc;
    font-family: "Orbitron", sans-serif;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    background: linear-gradient(180deg, #38bdf8 0%, #0369a1 100%);
    box-shadow: 0 10px 24px rgba(3, 105, 161, 0.35);
    transition: transform 0.2s ease, filter 0.2s ease;
}

.play-btn small {
    display: block;
    margin-top: 3px;
    font-family: "Rajdhani", sans-serif;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.08em;
    opacity: 0.85;
}

.play-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.06);
}

.play-btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 3px;
}

.play-btn.is-ready {
    box-shadow:
        0 10px 24px rgba(3, 105, 161, 0.35),
        0 0 0 0 rgba(56, 189, 248, 0.45);
    animation: engine-pulse 2.2s ease-out infinite;
}

/* =====================================================
   KÄYNNISTYS
   ===================================================== */

.game-boot {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-align: center;
    background:
        radial-gradient(circle at 18% 20%, rgba(56, 189, 248, 0.2), transparent 36%),
        radial-gradient(circle at 82% 24%, rgba(239, 68, 68, 0.16), transparent 34%),
        #020617;
    transition: opacity 0.45s ease, visibility 0.45s ease;
}

.game-boot[hidden] {
    display: none;
}

.game-boot.is-done {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.game-boot h2 {
    margin: 6px 0 0;
    font-family: "Orbitron", sans-serif;
    font-size: clamp(28px, 4vw, 44px);
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.boot-sub {
    margin: 0;
    color: var(--muted);
    font-size: 18px;
    letter-spacing: 0.08em;
}

.boot-track {
    width: min(260px, 68vw);
    height: 3px;
    margin-top: 18px;
    overflow: hidden;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.08);
}

.boot-bar {
    width: 38%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #38bdf8, #ffffff, #ef4444);
    animation: boot-slide 1s ease-in-out infinite;
}

/* =====================================================
   PAINIKKEET (PELIRUUTU)
   ===================================================== */

.btn {
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    padding: 12px 24px;
    border-radius: 8px;
    font-family: "Orbitron", sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn:hover {
    background: rgba(56, 189, 248, 0.1);
    border-color: var(--neon-blue);
    color: #fff;
    transform: translateY(-2px);
}

.btn.active {
    background: var(--neon-blue);
    border-color: #fff;
    color: #020617;
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.4);
}

/* =====================================================
   HIGH SCORES
   ===================================================== */

.score-entry {
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 9px 12px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 700;
}

.score-entry:nth-child(1) {
    border-left: 4px solid #ffd700;
    background: rgba(255, 215, 0, 0.07);
}

.score-entry:nth-child(2) {
    border-left: 4px solid #c0c0c0;
}

.score-entry:nth-child(3) {
    border-left: 4px solid #cd7f32;
}

.score-name {
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.score-time {
    color: var(--neon-blue);
    font-family: "Orbitron", sans-serif;
    font-size: 14px;
}

/* =====================================================
   MESSAGES & OVERLAYS
   ===================================================== */

#nameEntryOverlay {
    background: radial-gradient(circle, rgba(15, 23, 42, 0.98) 0%, rgba(2, 6, 23, 0.99) 100%);
}

#nameDisplay {
    font-family: "Orbitron", sans-serif;
    color: var(--neon-cyan);
    text-shadow: 0 0 20px var(--neon-cyan);
    animation: blink 0.8s step-end infinite;
}

@keyframes siren {
    0%, 100% { opacity: 0.28; }
    50% { opacity: 1; }
}

@keyframes glow-breathe {
    0%, 100% { opacity: 0.4; transform: scale(1); }
    50% { opacity: 0.75; transform: scale(1.06); }
}

@keyframes road-scroll {
    to { background-position: center 72px; }
}

@keyframes shimmer {
    from { background-position: 120% 0; }
    to { background-position: -40% 0; }
}

@keyframes engine-pulse {
    0% { box-shadow: 0 10px 24px rgba(3, 105, 161, 0.35), 0 0 0 0 rgba(56, 189, 248, 0.45); }
    70% { box-shadow: 0 10px 24px rgba(3, 105, 161, 0.35), 0 0 0 12px rgba(56, 189, 248, 0); }
    100% { box-shadow: 0 10px 24px rgba(3, 105, 161, 0.35), 0 0 0 0 rgba(56, 189, 248, 0); }
}

@keyframes boot-slide {
    from { transform: translateX(-130%); }
    to { transform: translateX(340%); }
}

@keyframes blink {
    50% { opacity: 0.7; }
}

@media (max-width: 980px), (max-height: 760px) {
    .menu {
        height: calc(100dvh - 16px);
        margin: 8px auto;
        gap: 8px;
    }

    .lede {
        display: none;
    }

    .menu-page h1 {
        font-size: 42px;
    }

    .menu-grid {
        gap: 10px;
    }

    .menu-page .panel {
        padding: 12px;
    }

    .rule p,
    .hint,
    .hof-note {
        font-size: 14px;
    }
}

.game-page {
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #020617;
}

.game-header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 15px;
    pointer-events: none;
    z-index: 60;
}

#exitBtn {
    pointer-events: auto;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid var(--neon-blue);
    color: var(--neon-blue);
    font-family: "Orbitron", "Segoe UI", sans-serif;
    font-size: 12px;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
}

#exitBtn:hover {
    background: var(--neon-blue);
    color: #020617;
}

.game-page canvas {
    max-width: 100vw;
    max-height: calc(100vh - 120px);
}

.end-panel {
    width: min(350px, calc(100vw - 32px));
    background: rgba(0, 0, 0, 0.4);
    padding: 20px;
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 30px;
}

.screen-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 100;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: rgba(2, 6, 23, 0.98);
    color: #fff;
    font-family: "Orbitron", "Segoe UI", sans-serif;
}

.screen-overlay.is-open {
    display: flex;
}

#gameEndOverlay {
    z-index: 110;
}

.record-title {
    margin: 0;
    font-size: 48px;
    background: linear-gradient(to bottom, #fff, var(--neon-blue));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

#nameDisplay {
    font-size: 72px;
    letter-spacing: 12px;
    border: 2px solid var(--neon-blue);
    padding: 20px 40px;
    border-radius: 20px;
    margin: 30px 0;
}

.name-cursor {
    color: #facc15;
    text-decoration: underline;
}

.overlay-hint {
    color: #64748b;
}

.end-title {
    margin: 0;
    font-size: 50px;
    color: var(--neon-blue);
}

.end-time {
    margin: 12px 0 20px;
    font-size: 24px;
}

.end-actions {
    display: flex;
    gap: 20px;
}

@media (max-width: 900px) {
    .menu-page {
        height: auto;
        min-height: 100dvh;
        overflow: auto;
    }

    .menu {
        height: auto;
        width: min(1180px, calc(100vw - 20px));
    }

    .menu-grid {
        grid-template-columns: 1fr;
    }

    .stage {
        height: 190px;
        flex: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .scene-glow,
    .scene-road,
    .siren-bar span,
    .play-btn.is-ready,
    .shot::before,
    .boot-bar {
        animation: none;
    }

    .stage-img,
    .map-card img,
    .game-boot,
    .play-btn,
    .map-card {
        transition: none;
    }
}
