/* The menu was a sunset Markus picked out; since the pastel restyle
   (2026-11-25) it is a soft winter morning to match the race and the cards:
   powder-blue sky, a blush of morning low down, snowy hills. These variables
   are left from the sunset; the dialogs and the results card went pastel
   too, so little uses them now. */
:root {
    --night:   #190b38;
    --indigo:  #241a4e;
    --violet:  #3b2d7a;
    --blue:    #6064af;
    --lilac:   #7e7eb7;
    --plum:    #723578;
    --magenta: #af3c74;
    --rose:    #d87380;
    --peach:   #e69981;
    --gold:    #f6ce8f;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
    background: #dde7f2;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Courier New', monospace;
    overflow: hidden;
    user-select: none;
}
button { font-family: inherit; }

/* The whole window, up to 1700x1050. It used to leave a margin (96% by 92%)
   that the near-black page hid; on the pale page it showed as a frame, so the
   game fills the window now (Markus, 2026-11-25). Only a screen bigger than
   1700x1050 leaves a margin round it. */
#game-container {
    position: relative;
    width: min(100vw, 1700px);
    height: min(100vh, 1050px);
    background: var(--night);
    border-radius: 0;
    overflow: hidden;
    box-shadow: 0 0 40px rgba(60, 90, 140, 0.25);
}
#game { position: absolute; top: 0; left: 0; z-index: 1; }

/* ─── Menu ─── */
#menu {
    position: absolute;
    inset: 0;
    z-index: 100;
    background:
        /* Snowy hills along the bottom, nearest last: each a wide ellipse of
           its own colour with a soft top edge. Every stop fades to its own hue
           at zero alpha, never to `transparent`, which goes through black. */
        radial-gradient(70% 22% at 22% 104%, rgba(250, 251, 254, 1) 60%, rgba(250, 251, 254, 0) 62%),
        radial-gradient(64% 20% at 84% 106%, rgba(244, 247, 252, 1) 60%, rgba(244, 247, 252, 0) 62%),
        radial-gradient(80% 26% at 58% 108%, rgba(222, 234, 248, 1) 60%, rgba(222, 234, 248, 0) 62%),
        radial-gradient(60% 24% at 6% 100%, rgba(203, 222, 242, 1) 60%, rgba(203, 222, 242, 0) 62%),
        radial-gradient(70% 28% at 96% 98%, rgba(196, 220, 230, 1) 60%, rgba(196, 220, 230, 0) 62%),
        /* the morning's blush on the horizon behind them, and a pale sun */
        radial-gradient(14% 7% at 64% 80%, rgba(255, 252, 240, 0.95), rgba(255, 252, 240, 0) 70%),
        radial-gradient(70% 20% at 60% 82%, rgba(250, 226, 230, 0.85), rgba(250, 226, 230, 0) 75%),
        /* ...and the sky over it, powder blue overhead */
        radial-gradient(80% 40% at 12% -6%, rgba(176, 204, 238, 0.7), rgba(176, 204, 238, 0) 66%),
        radial-gradient(70% 36% at 92% -6%, rgba(190, 226, 226, 0.55), rgba(190, 226, 226, 0) 64%),
        linear-gradient(180deg, #cadff5 0%, #dbe8f7 40%, #eef1f8 70%, #f6f2f6 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    padding: 28px 18px 40px;
}
#menu h1 {
    font-family: 'Press Start 2P', 'Courier New', monospace;
    color: #fff;
    font-size: clamp(24px, 6vw, 54px);
    letter-spacing: 4px;
    margin: 18px 0 10px;
    text-shadow: 3px 3px 0 #79a6dc, 6px 6px 0 #3f6596, 0 0 30px rgba(255, 255, 255, 0.6);
}
.tagline { color: #5a77a1; font-size: 13px; margin-bottom: 30px; letter-spacing: 1px; }
/* The controls as a line on an old amber terminal: phosphor glow, a prompt,
   a blinking block cursor. One line always — the size follows the width. */
.how {
    margin-top: 24px;
    font-family: 'VT323', monospace;
    /* the line is ~34 characters' width in ems: sized to the space it has */
    font-size: clamp(11px, calc((100vw - 64px) / 34), 27px);
    line-height: 1;
    white-space: pre;
    color: #4f6f9c;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
    letter-spacing: 0.02em;
}
.how b { font-weight: normal; color: #24496f; }
.how .prompt { color: #24496f; }
.how .cursor {
    display: inline-block; width: 0.5em; height: 0.9em; margin-left: 0.25em;
    vertical-align: -0.1em; background: #4f6f9c;
    animation: how-blink 1.1s steps(1) infinite;
}
@keyframes how-blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .how .cursor { animation: none; } }
/* a phone is too narrow for one readable line: let it wrap there */
@media (max-width: 560px) { .how { white-space: normal; line-height: 1.35; } }

/* Ten tracks, two rows of five; fewer columns only where five would be too
   small to read. */
#track-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 14px;
    /* also bounded by the window's height, so both rows fit without scrolling:
       a card is about as tall as it is wide */
    width: min(960px, 100%, calc(230vh - 780px));
    justify-content: center;
}
/* The grid between the level arrows. A hidden arrow keeps its room, so the
   grid is the same size whichever level is shown and whether or not Level 2
   is open. */
#grid-row { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; }
#grid-row #track-grid { flex: 0 1 auto; min-width: 0; }
/* Just the pixel chevron, no box: an SVG on a 7x11 grid, so it sits dead centre. */
.level-arrow {
    flex: none; width: 40px; height: 80px; cursor: pointer; padding: 0;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; color: #5d88c2;
    filter: drop-shadow(2px 2px 0 rgba(255, 255, 255, 0.9));
}
.level-arrow svg { width: 21px; height: 33px; fill: currentColor; shape-rendering: crispEdges; }
/* Locked: dimmed, with a pixel padlock over the chevron. */
.level-arrow { position: relative; }
.level-arrow .level-lock { display: none; position: absolute; left: 50%; top: 50%; width: 15px; height: 17px; transform: translate(-50%, -50%); color: #2f5a93; }
.level-arrow.is-locked > svg:not(.level-lock) { opacity: 0.35; }
.level-arrow.is-locked .level-lock { display: block; }
#gate-modal-body { color: #44597a; font-size: 14px; line-height: 1.55; }
#gate-modal-body p { margin: 0 0 10px; }
#gate-modal-body .gate-total { font-family: 'Press Start 2P', 'Courier New', monospace; font-size: 15px; color: #24395c; margin: 14px 0 6px; }
#gate-modal-body .gate-gap { color: #c98a1e; font-weight: bold; }
.level-arrow:hover { color: #2f5a93; filter: drop-shadow(2px 2px 0 rgba(255, 255, 255, 0.9)) drop-shadow(0 0 8px rgba(255, 255, 255, 0.9)); }
#level-label {
    font-family: 'Press Start 2P', 'Courier New', monospace; font-size: 13px; letter-spacing: 3px;
    color: #3f6596; margin: -14px 0 14px; text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.9);
}
#st-levels { display: flex; justify-content: center; gap: 8px; margin: -4px 0 12px; }
#st-levels[hidden] { display: none; }
.st-level {
    padding: 5px 14px; cursor: pointer; border-radius: 999px; font-size: 12.5px; font-weight: bold;
    background: transparent; border: 1px solid rgba(120, 156, 206, 0.45); color: #5a77a1;
}
.st-level.is-on { background: rgba(111, 159, 216, 0.16); border-color: #6f9fd8; color: #2f5a93; }
@media (max-width: 760px) { #track-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 480px) { #track-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } #grid-row { gap: 6px; } .level-arrow { width: 26px; height: 60px; } .level-arrow svg { width: 14px; height: 22px; } }
.track-card {
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(120, 156, 206, 0.35);
    border-radius: 11px;
    box-shadow: 0 4px 14px rgba(70, 105, 155, 0.12);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: border-color 0.15s, transform 0.15s;
}
.track-card:hover { border-color: #6f9fd8; transform: translateY(-2px); }
/* A track not built yet: the same square, empty and still. */
.track-card.is-soon { background: rgba(255, 255, 255, 0.35); border-style: dashed; border-color: rgba(120, 156, 206, 0.3); box-shadow: none; }
.track-card.is-soon:hover { border-color: rgba(120, 156, 206, 0.3); transform: none; }
.track-card.is-soon .track-play { cursor: default; }
.track-card.is-soon .track-title { color: #9aaecb; font-weight: normal; cursor: default; }
.track-play { display: block; width: 100%; padding: 0; border: none; background: none; cursor: pointer; line-height: 0; }
.track-play svg { width: 100%; height: auto; display: block; }
.track-foot { display: flex; align-items: center; gap: 6px; padding: 8px 8px 9px 10px; border-top: 1px solid rgba(120, 156, 206, 0.22); }
.track-title {
    flex: 1 1 auto; min-width: 0;
    background: none; border: none; padding: 0;
    color: #34507a; font-size: 12px; font-weight: bold; text-align: left;
    cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.track-card:hover .track-title { color: #1d3a63; }
.track-trophy {
    flex: 0 0 auto; background: none; border: none; padding: 2px; cursor: pointer;
    line-height: 0; border-radius: 5px; opacity: 0.62; transition: 0.15s;
}
.track-trophy:hover { opacity: 1; background: rgba(120, 156, 206, 0.16); }
.track-trophy svg { width: 15px; height: 15px; display: block; }

/* ─── Sign-in ─── */
#auth-bar {
    position: absolute; top: 18px; right: 18px; z-index: 120;
    display: flex; flex-direction: column; align-items: flex-end; gap: 7px;
}
#auth-hint { color: #4f6f9c; font-size: 12px; text-align: right; max-width: 210px; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8); display: none; }
#auth-signin { display: flex; align-items: center; gap: 8px; }
.auth-btn {
    display: flex; align-items: center; gap: 8px;
    background: rgba(255, 255, 255, 0.85); border: 2px solid #a9c3e6; color: #2f4f7c;
    padding: 9px 15px; font-size: 13px; font-weight: bold; border-radius: 8px; cursor: pointer; transition: 0.15s;
}
.auth-btn:hover { background: #fff; border-color: #6f9fd8; color: #1d3a63; }
.auth-btn svg { width: 16px; height: 16px; }
#auth-user {
    display: none; align-items: center; gap: 10px;
    background: rgba(255, 255, 255, 0.85); border: 2px solid #a9c3e6; border-radius: 8px; padding: 6px 8px 6px 6px;
}
#auth-avatar { width: 30px; height: 30px; border-radius: 50%; background: #cddcf0; object-fit: cover; flex-shrink: 0; }
#auth-name { color: #2f4f7c; font-size: 13px; font-weight: bold; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#auth-signout { background: none; border: none; color: #c4566a; font-size: 11px; font-weight: bold; cursor: pointer; padding: 4px 6px; }
#auth-signout:hover { color: #a3314a; text-decoration: underline; }
#auth-notice {
    position: absolute; top: 96px; right: 18px; z-index: 120; display: none;
    max-width: 320px; padding: 10px 12px; border-radius: 8px; font-size: 11px; line-height: 1.5;
    background: #fff6ea; border: 1px solid #e0b27a; color: #8a5a1e;
}
#auth-notice.is-error { border-color: #d98a8a; color: #b03a3a; }

/* ─── Scores dialog ─── (pastel since 2026-11-25, like the menu) */
#score-modal, #stats-modal, #gate-modal {
    position: absolute; inset: 0; z-index: 160;
    background: rgba(52, 80, 122, 0.38);
    display: none; justify-content: center; align-items: center; padding: 16px; overflow-y: auto;
}
#score-modal.open, #stats-modal.open, #gate-modal.open { display: flex; }
#score-modal-card, #stats-modal-card, #gate-modal-card {
    position: relative; background: #f8fafd; border: 1px solid #c3d5ec; border-radius: 14px;
    box-shadow: 0 18px 50px rgba(50, 80, 130, 0.28);
    padding: 24px 26px 20px; width: min(460px, 100%); max-height: 88vh; overflow-y: auto; text-align: center;
}
#score-modal-title, #stats-modal-title, #gate-modal-title { font-family: 'Press Start 2P', 'Courier New', monospace; color: #3f6596; text-shadow: 2px 2px 0 #d6e4f5; font-size: 13px; line-height: 1.6; margin: 0 0 18px; padding: 0 22px; }
#score-modal-close, #stats-modal-close, #gate-modal-close { position: absolute; top: 8px; right: 12px; background: none; border: none; color: #8aa0bf; font-size: 26px; line-height: 1; cursor: pointer; padding: 2px 6px; }
#score-modal-close:hover, #stats-modal-close:hover, #gate-modal-close:hover { color: #2f4f7c; }
.lb-subtitle { color: #6f86a8; font-size: 12px; margin: -10px 0 16px; }
/* View all: every car of the top ten on the road at once. */
.lb-all {
    display: block; margin: -6px auto 14px; padding: 6px 14px; cursor: pointer;
    background: rgba(111, 159, 216, 0.12); border: 1px solid rgba(111, 159, 216, 0.6); border-radius: 999px;
    color: #2f5a93; font-size: 12.5px; font-weight: bold; letter-spacing: 0.5px;
}
.lb-all:hover:not(:disabled) { background: rgba(111, 159, 216, 0.22); color: #1d3a63; }
.lb-all:disabled { opacity: 0.6; cursor: default; }
.lb-all[hidden] { display: none; }
#score-modal-body { min-height: 90px; text-align: left; }
#score-modal-local { margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(120, 156, 206, 0.25); color: #5a6f90; font-size: 12.5px; text-align: left; }
#score-modal-local .lb-signin-prompt { color: #2f5a93; margin-top: 5px; }
.lb-row {
    display: grid; grid-template-columns: 34px 30px 1fr auto 14px auto; align-items: center; gap: 10px;
    padding: 8px 10px; border-bottom: 1px solid rgba(120, 156, 206, 0.2); color: #24395c; font-size: 15px; border-radius: 6px;
}
.lb-row:last-child { border-bottom: none; }
.lb-row.is-me { background: rgba(226, 168, 58, 0.14); }
.lb-rank { color: #8aa0bf; font-weight: bold; text-align: right; }
.lb-row:nth-child(1) .lb-rank { color: #d49428; }
.lb-row:nth-child(2) .lb-rank { color: #7d8fab; }
.lb-row:nth-child(3) .lb-rank { color: #c4677c; }
.lb-avatar { width: 26px; height: 26px; border-radius: 50%; background: #d6e2f2; object-fit: cover; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-time { color: #2f5a93; font-weight: bold; font-variant-numeric: tabular-nums; }
.lb-msg { color: #7088aa; font-size: 14px; padding: 34px 10px; line-height: 1.7; }
/* When the run was set — quiet, so the name and the time stay the row. */
.lb-when { color: #7088aa; font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
#score-modal-local .lb-mine { color: #44597a; margin-top: 5px; }

/* ─── Standings ─── */
#standings-btn { margin: 18px auto 0; background: rgba(255, 255, 255, 0.7); border-color: #a9c3e6; color: #2f5a93; }
#standings-btn:hover:not(:disabled) { background: #fff; color: #1d3a63; }
#standings-btn[hidden] { display: none; }
#stats-modal-card { width: min(620px, 100%); }
#stats-modal-body { min-height: 90px; text-align: left; }
.lb-row.st-row { grid-template-columns: 34px 30px 1fr auto auto; }
.st-swatch { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 8px; }
.st-gap { color: #7088aa; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.st-chart-wrap { position: relative; margin-top: 16px; padding-top: 12px; border-top: 1px solid rgba(120, 156, 206, 0.25); }
.st-zoom {
    position: absolute; top: 10px; right: 0; padding: 3px 10px; cursor: pointer; border-radius: 999px;
    font: inherit; font-size: 11.5px; background: #f8fafd; border: 1px solid rgba(120, 156, 206, 0.45); color: #5a77a1;
}
.st-zoom:hover { border-color: #6f9fd8; color: #2f5a93; }
.st-chart { width: 100%; height: auto; display: block; }
.st-chart .st-grid { stroke: rgba(120, 156, 206, 0.2); stroke-width: 1; }
.st-chart .st-axis { stroke: rgba(120, 156, 206, 0.5); stroke-width: 1; }
.st-chart text { fill: #7088aa; font-size: 11px; font-family: inherit; font-variant-numeric: tabular-nums; }
.st-chart .st-ylab { text-anchor: end; dominant-baseline: middle; }
.st-chart .st-xlab { text-anchor: middle; }
.st-rest { margin-top: 12px; color: #7088aa; font-size: 12.5px; line-height: 1.5; }

/* ─── In race ─── */
#ui { position: absolute; inset: 0; z-index: 10; pointer-events: none; display: none; }
.hud { position: absolute; top: 16px; left: 16px; color: #fff; font-size: 14px; line-height: 1.6; text-shadow: 2px 2px 0 #000; }
/* The ghost line is dimmed when the ghost is off, so the key that turns it on
   is still visible without shouting. */
#ghost-line { display: none; }
#fog-line { display: none; }
#fog-line.is-off { opacity: 0.55; }
.lb-ghost { color: #3f86c9; opacity: 0.75; font-size: 11px; text-align: center; }
.lb-play {
    background: none; border: none; cursor: pointer; padding: 0; font: inherit;
    color: #3f86c9; font-size: 12px; line-height: 1; text-align: center;
}
.lb-play:hover:not(:disabled) { color: #1d3a63; transform: scale(1.25); }
.lb-play:disabled { cursor: default; opacity: 0.6; }
#replay-line { display: none; color: #8fd0ff; }
/* Watching a whole top ten: which car colour is which driver. */
#replay-legend { display: none; }
#replay-legend span { margin-right: 14px; white-space: nowrap; }
#controls-watch { display: none; }
#ghost-line.is-off { opacity: 0.45; }
#countdown {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    color: #ffdd00; font-size: 72px; font-weight: 900; text-shadow: 4px 4px 0 #000; display: none;
}
/* The result card, in the menu's colours: the same as the score dialog. */
#results {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: max-content; max-width: min(520px, calc(100% - 32px));
    background: rgba(248, 250, 253, 0.96); padding: 30px 40px 28px; border-radius: 14px;
    border: 1px solid #c3d5ec; box-shadow: 0 18px 50px rgba(50, 80, 130, 0.3);
    text-align: center; display: none; pointer-events: auto;
}
#results h2 {
    margin: 0 0 18px; font-family: 'Press Start 2P', 'Courier New', monospace;
    font-size: clamp(14px, 2.4vw, 20px); line-height: 1.5; font-weight: normal;
    text-shadow: 2px 2px 0 #d6e4f5;
}
#results p { color: #24395c; font-size: 18px; margin: 0 0 22px; }
#result-online { color: #5a6f90; font-size: 15px; margin: -10px 0 22px !important; min-height: 20px; }
#result-online.is-good { color: #c98a1e; }
#result-online.is-muted { color: #7a8fae; font-size: 13.5px; }
#result-online.is-error { color: #c4566a; }
#results button {
    padding: 12px 24px; font-size: 16px; margin: 0 8px; border-radius: 9px; cursor: pointer;
    font-weight: bold; background: #e4edf8; color: #2f4f7c; border: 1px solid #b9cde8;
}
#results button.primary {
    background: linear-gradient(#86b5e8, #5d8fcf); color: #fff; border-color: #5584c2;
}
#results button:hover { filter: brightness(1.06); }
.controls { position: absolute; bottom: 16px; left: 16px; color: rgba(255, 255, 255, 0.7); font-size: 12px; text-shadow: 1px 1px 0 #000; }

.perf {
    position: absolute; right: 8px; top: 8px; z-index: 50; pointer-events: none; white-space: pre;
    font: 11px monospace; color: #cfc; background: rgba(0, 0, 0, 0.6); padding: 6px 8px; border-radius: 4px;
}
.rate-hint {
    position: absolute; left: 50%; bottom: 54px; transform: translateX(-50%); z-index: 40;
    font: 12px monospace; color: #ffdd88; background: rgba(0, 0, 0, 0.72); padding: 7px 12px;
    border-radius: 5px; text-align: center; max-width: min(90%, 460px); line-height: 1.5;
}

@media (max-width: 620px) {
    #auth-bar { position: static; align-items: center; align-self: stretch; margin-bottom: 10px; }
    #auth-hint { text-align: center; max-width: none; }
    #auth-notice { position: static; max-width: none; margin-bottom: 10px; }
    #menu { padding: 16px 12px 30px; }
    #score-modal-card, #stats-modal-card { padding: 20px 16px 16px; }
    .lb-row.st-row { grid-template-columns: 26px 24px 1fr auto auto; }
    .st-gap { font-size: 11px; }
    .st-chart text { font-size: 19px; }
    .lb-row { grid-template-columns: 26px 24px 1fr 12px auto; gap: 7px; padding: 8px 2px; font-size: 14px; }
    .lb-when { display: none; }
}
