:root {
  color-scheme: dark;
  --bg: #070b1a;
  --panel: rgba(9, 13, 28, 0.84);
  --card: rgba(255, 255, 255, 0.05);
  --line: rgba(255, 255, 255, 0.1);
  --text: #eef1f6;
  --muted: #a3abbb;
  --accent: #ffb547;
  --on-accent: #1a1204;
  --sans: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --mono: "Cascadia Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

[hidden] { display: none !important; }

button { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  display: block;
  touch-action: none;
}

/* HUD */

.hud {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  pointer-events: none;
}
.hud p { margin: 0; }
.hud-block { text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7); }
.speed { font-size: 0.875rem; color: var(--muted); }
.speed b { font-family: var(--mono); font-size: 1.9rem; color: var(--text); letter-spacing: -0.03em; }
.dist { font-family: var(--mono); font-size: 0.95rem; }
.nitro {
  width: 112px;
  height: 6px;
  margin-top: 8px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}
.nitro i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #5fb4ff, #9fe0ff);
  transform-origin: left center;
  transform: scaleX(0);
}
.hud.radar .speed b { color: #ff5a4a; animation: radar 0.5s steps(2) infinite; }
@keyframes radar { 50% { opacity: 0.45; } }
.hud.boost .nitro i { background: linear-gradient(90deg, #ff9a3d, #ffd36b); }
.hud-center { text-align: center; }
.time {
  font-family: var(--mono);
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  letter-spacing: -0.04em;
}
.time.low { color: #ff6b5b; }
.zone { margin-top: 4px; font-size: 0.8125rem; color: var(--text); opacity: 0.85; font-weight: 600; }
.place { margin-top: 2px; font-family: var(--mono); font-size: 0.8125rem; color: var(--accent); font-weight: 700; }
.hud-right { display: flex; justify-content: flex-end; gap: 8px; pointer-events: auto; }
.hud-btns { display: flex; gap: 8px; }
.icon-btn svg { display: block; margin: 0 auto; }
.icon-btn[aria-pressed="false"] { opacity: 0.45; text-decoration: line-through; }
.icon-btn {
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(9, 13, 28, 0.55);
  font-weight: 700;
  font-size: 0.8125rem;
  cursor: pointer;
}

@media (max-width: 520px) {
  .place, .style-total { font-size: 0.75rem; letter-spacing: -0.02em; }
  .hud-right { flex-direction: column; align-items: flex-end; }
  .speed b { font-size: 1.5rem; }
  .time { font-size: 2.1rem; }
  .dist { font-size: 0.8125rem; }
  .nitro { width: 84px; }
}

/* banner, nitro button */

.banner {
  position: fixed;
  left: 50%;
  top: 26%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
  width: max-content;
  max-width: 92vw;
}
.banner.show { animation: banner 1.6s ease-out forwards; }
.banner b { display: block; font-size: clamp(2rem, 7vw, 3.6rem); font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; }
.banner span { display: block; margin-top: 6px; font-family: var(--mono); font-size: 1.1rem; color: var(--accent); font-weight: 700; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.96); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

.style-total { margin-top: 2px; font-family: var(--mono); font-size: 0.8125rem; color: #9fe0ff; font-weight: 700; }
.style-gain { min-height: 1.1em; font-family: var(--mono); font-size: 0.75rem; font-weight: 700; color: #9fe0ff; opacity: 0.85; }
.style-gain.minus { color: #ff6b5b; }
.time.pen { color: #ff6b5b; }
.ach-toast {
  position: fixed;
  left: 50%;
  top: calc(max(12px, env(safe-area-inset-top)) + 140px);
  transform: translate(-50%, -40px);
  opacity: 0;
  display: grid;
  gap: 2px;
  justify-items: center;
  padding: 10px 18px;
  border: 1px solid var(--accent);
  border-radius: 14px;
  background: rgba(9, 13, 28, 0.9);
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s;
}
.ach-toast.show { transform: translate(-50%, 0); opacity: 1; }
.ach-toast small { font-size: 0.72rem; color: var(--accent); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.ach-toast b { font-size: 1rem; }
.ach-list { width: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.ach { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); opacity: 0.6; }
.ach.done { opacity: 1; border-color: rgba(255, 181, 71, 0.5); }
.ach-mark { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--line); color: var(--on-accent); font-weight: 800; }
.ach.done .ach-mark { background: var(--accent); border-color: var(--accent); }
.ach b { font-size: 0.95rem; }
.ach p { margin: 2px 0 0; font-size: 0.8125rem; color: var(--muted); line-height: 1.35; }
.nitro-btn {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  width: 64px;
  height: 64px;
  border: 2px solid rgba(159, 224, 255, 0.6);
  border-radius: 50%;
  background: rgba(9, 13, 28, 0.5);
  color: #9fe0ff;
  font-weight: 800;
  font-size: 1.2rem;
  touch-action: none;
}
.horn-btn {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(max(22px, env(safe-area-inset-bottom)) + 76px);
  width: 56px;
  height: 56px;
  border: 2px solid rgba(255, 181, 71, 0.6);
  border-radius: 50%;
  background: rgba(9, 13, 28, 0.5);
  color: var(--accent);
  font-weight: 800;
  font-size: 0.85rem;
  touch-action: none;
}
.nitro-btn.on { background: #5fb4ff; color: #04121f; }

/* panels */

#ui:empty { display: none; }

.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  overscroll-behavior: contain;
  display: grid;
  gap: 14px;
  justify-items: start;
  align-content: start;
  padding: 24px 24px 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  user-select: text;
  -webkit-user-select: text;
}
.panel.wide { width: min(760px, calc(100vw - 24px)); }
.panel-top { width: 100%; display: flex; align-items: center; justify-content: space-between; }
.mark { width: 34px; height: 6px; border-radius: 3px; background: var(--accent); }
.panel h1 { margin: 0; font-size: clamp(2.6rem, 11vw, 3.6rem); font-weight: 800; letter-spacing: -0.04em; line-height: 1; }
.panel h2 { margin: 0; font-size: 1.7rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; }
.panel p { margin: 0; }
.tag { color: var(--muted); font-size: 1.0625rem; line-height: 1.45; }
.keys { font-family: var(--mono); font-size: 0.8125rem; color: var(--muted); line-height: 1.5; }
.best { font-family: var(--mono); font-size: 0.9375rem; display: inline-flex; align-items: center; gap: 8px; }
.more { font-size: 0.875rem; color: var(--muted); }
.more:hover { color: var(--text); }
.about { width: 100%; display: grid; gap: 4px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 0.8125rem; color: var(--muted); line-height: 1.45; }
.about p { margin: 0; }
.about a { color: var(--accent); font-weight: 700; }
.over-label { color: var(--muted); font-weight: 600; }
.over-dist { font-family: var(--mono); font-size: 2.8rem; font-weight: 700; letter-spacing: -0.04em; line-height: 1; }
.record { color: var(--accent); font-weight: 800; }
.note { min-height: 1.3em; font-size: 0.9rem; color: var(--accent); font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: 10px; }

.panel-head { width: 100%; display: flex; align-items: center; gap: 12px; }
.panel-head h2 { flex: 1; }
.head-note { font-family: var(--mono); font-size: 0.8125rem; color: var(--muted); }
.back {
  width: 40px;
  height: 40px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
}

.top-right { display: flex; align-items: center; gap: 8px; }
.chip-btn { padding: 4px 11px; border: 1px solid var(--line); border-radius: 999px; background: none; font-size: 0.75rem; font-weight: 700; color: var(--muted); cursor: pointer; }
.chip-btn[aria-pressed="true"] { color: var(--text); background: rgba(255, 255, 255, 0.08); }
.langs { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 999px; }
.langs button { border: 0; background: none; padding: 3px 11px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; color: var(--muted); cursor: pointer; }
.langs button[aria-pressed="true"] { background: rgba(255, 255, 255, 0.12); color: var(--text); }

.btn {
  min-height: 46px;
  padding: 11px 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.15s, background-color 0.15s;
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: #ffc46b; }
.btn.ghost { border-color: transparent; color: var(--muted); }

/* main menu */

.menu { width: 100%; display: grid; gap: 8px; }
.levels { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.levels .menu-item { padding: 12px 14px; }
.levels .menu-item b { font-size: 1rem; }
.levels .menu-item[aria-pressed="true"] { border-color: var(--accent); background: rgba(255, 181, 71, 0.12); }
.opt-head { width: 100%; margin: 14px 0 6px; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.opt-list { width: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); font: inherit; font-size: 0.875rem; font-weight: 600; text-align: left; cursor: pointer; }
.opt i { position: relative; flex: none; width: 34px; height: 20px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); transition: background 0.15s; }
.opt i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.opt[aria-pressed="true"] i { background: var(--accent); }
.opt[aria-pressed="true"] i::after { transform: translateX(14px); }
.level-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-bottom: 14px; }
@media (max-width: 520px) {
  .levels { grid-template-columns: 1fr; }
  .levels .menu-item { padding: 10px 14px; }
}
.menu-item {
  display: grid;
  gap: 2px;
  justify-items: start;
  width: 100%;
  padding: 13px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}
.menu-item:hover { border-color: rgba(255, 255, 255, 0.28); }
.menu-item:active { transform: scale(0.99); }
.menu-item b { font-size: 1.15rem; font-weight: 800; }
.menu-item span { font-size: 0.875rem; color: var(--muted); }
.menu-item.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.menu-item.primary span { color: rgba(26, 18, 4, 0.72); }

/* chapter and map cards */

.cards {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}
.card {
  display: grid;
  align-content: start;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}
.card:hover:not([disabled]) { border-color: rgba(255, 255, 255, 0.3); transform: translateY(-2px); }
.card[disabled] { cursor: default; }
.card[disabled] img { filter: grayscale(0.85) brightness(0.55); }
.card img { width: 100%; aspect-ratio: 16 / 9; display: block; object-fit: cover; }
.card-body { display: grid; gap: 4px; padding: 10px 12px 12px; }
.card-body small { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.card-body b { font-size: 1.02rem; font-weight: 800; }
.card-body .best { font-size: 0.8125rem; color: var(--muted); }
.lock { font-size: 0.8125rem; color: var(--muted); }

.stars { display: inline-flex; gap: 2px; font-size: 1.05rem; line-height: 1; }
.stars i { font-style: normal; color: rgba(255, 255, 255, 0.22); }
.stars i.on { color: var(--accent); }
.panel > .stars { font-size: 2rem; gap: 6px; }

.hero-img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
.story-title { font-size: 1.9rem; }
.goal { font-size: 0.975rem; line-height: 1.45; }
.goal b { color: var(--accent); }
/* a phone on its side or a small game frame: the "Go" button must fit without scrolling */
@media (max-height: 560px) {
  .hero-img { display: none; }
  .story-title { font-size: 1.5rem; }
}

/* leaderboard */

.chips { width: 100%; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: none; font-size: 0.8125rem; font-weight: 700; color: var(--muted); cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chips.boards .chip.on { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.3); color: var(--text); }
.board { width: 100%; margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.row-entry { display: grid; grid-template-columns: 2.2em 12px 1fr auto; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 10px; }
.row-entry:nth-child(odd) { background: var(--card); }
.row-entry.me { background: rgba(255, 181, 71, 0.16); }
.row-entry .pos { font-family: var(--mono); color: var(--muted); text-align: right; }
.row-entry .dot { width: 12px; height: 12px; border-radius: 50%; }
.row-entry .who { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-entry .who small { margin-left: 8px; font-weight: 600; font-size: 0.72rem; color: var(--muted); }
.row-entry.me .who small { color: var(--accent); }
.row-entry .val { font-family: var(--mono); font-weight: 700; }
.row-entry.npc { opacity: 0.8; }
.board .empty { padding: 10px; color: var(--muted); }
.board-note { font-size: 0.875rem; color: var(--muted); min-height: 1.2em; }
.name-box, .send-box { width: 100%; display: grid; gap: 6px; }
.name-box label { font-weight: 700; font-size: 0.9rem; }
.name-box input, .send-box input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
}
.name-box input:focus, .send-box input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.name-box .row, .send-box .row { flex-wrap: nowrap; }
.hint { font-size: 0.78rem; color: var(--muted); }

/* garage */

.showcase { width: 100%; display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; align-items: start; }
.car-big { width: 100%; height: auto; border-radius: 12px; display: block; border: 1px solid var(--line); }
.paint-label { font-size: 0.8125rem; color: var(--muted); font-weight: 600; }
.paints { display: flex; flex-wrap: wrap; gap: 7px; }
.paint { width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.25); cursor: pointer; padding: 0; }
.paint.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255, 181, 71, 0.35); }
.car-grid { width: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.car-tile { display: grid; gap: 4px; padding: 6px 6px 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); cursor: pointer; text-align: center; font-size: 0.8125rem; font-weight: 700; }
.car-tile canvas { width: 100%; height: auto; border-radius: 8px; display: block; }
.car-tile.viewing { border-color: rgba(255, 255, 255, 0.4); }
.car-tile.chosen { border-color: var(--accent); }
.car-tile .lock { font-weight: 600; }
@media (max-width: 600px) { .showcase { grid-template-columns: 1fr; } }

.garage { width: 100%; display: grid; gap: 12px; }
.car {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 14px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
}
.car.selected { border-color: var(--accent); }
.car-pic { width: 100%; height: auto; border-radius: 10px; display: block; }
.car-body { display: grid; gap: 8px; justify-items: start; }
.car-body b { font-size: 1.1rem; }
.car-note { font-size: 0.875rem; color: var(--muted); line-height: 1.4; }
.car-stats { margin: 0; display: grid; grid-template-columns: auto auto; gap: 4px 12px; align-items: center; font-size: 0.8125rem; color: var(--muted); }
.car-stats dd { margin: 0; display: inline-flex; gap: 3px; }
.car-stats i { width: 14px; height: 6px; border-radius: 2px; background: rgba(255, 255, 255, 0.15); }
.car-stats i.on { background: var(--accent); }
.picked { font-weight: 700; color: var(--accent); }

@media (max-width: 520px) {
  .panel { padding: 20px 16px 18px; }
  .car { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card-body { padding: 8px 10px 10px; }
  .card-body b { font-size: 0.9rem; }
}

.noscript { position: fixed; inset: 0; display: grid; place-items: center; font-weight: 700; }

/* link preview frame, see ?og in js/main.js */
.og #ui, .og .hud { display: none !important; }
.og-title {
  position: fixed;
  left: 64px;
  top: 56px;
  display: grid;
  gap: 10px;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.6);
}
.og-title b { font-size: 108px; font-weight: 800; letter-spacing: -0.045em; line-height: 1; }
.og-title span { font-size: 34px; font-weight: 600; color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .banner.show { animation-timing-function: steps(1); }
  .card, .menu-item, .btn { transition: none; }
}
