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

/* One deliberate type scale + colour roles for the whole UI. Don't introduce new
   font sizes — reuse a token so the eye only moves between a handful of steps.
   Sizes: display/h2 (headings) · lg (primary action) · md (buttons, inputs, body) ·
   sm (labels, chips, hints, status) · xs (the quiet stuff: foot / legal / build). */
:root {
  --fs-display: clamp(34px, 8vw, 64px);
  --fs-h2: clamp(26px, 6vw, 46px);
  --fs-lg: 20px;
  --fs-md: 16px;
  --fs-sm: 13px;
  --fs-xs: 12px;
  --ink: #e6eefc;    /* primary text */
  --muted: #9fb0d0;  /* secondary text — labels, hints, status */
  --dim: #74829e;    /* unimportant — kept subtle + out of the main area */
  --accent: #ffd54d; /* gold highlight */
  --ok: #7dffb0;     /* success / hover */
}

html, body {
  height: 100vh;
  height: 100dvh; /* dynamic viewport: tracks the mobile URL bar so nothing shifts/clips */
  background: #0a0f1c;
  overflow: hidden;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#game, #hud { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; }
#hud { pointer-events: none; }
.hidden { display: none !important; }

/* ---------- start menu / lobby ---------- */
#menu {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px;
  /* lightly darker at the centre for legibility, but let the live 3D flyaround show through */
  background: radial-gradient(120% 90% at 50% 42%, rgba(4, 7, 16, 0.58), rgba(4, 7, 16, 0.32));
  overflow-y: auto;
}
#menu h1 {
  font-size: var(--fs-display); color: var(--accent); letter-spacing: 2px;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.5);
}
#menu .names { display: flex; gap: 24px; flex-wrap: wrap; justify-content: center; }
/* field label ("Your name" / "Player 2") sits inline, to the LEFT of the input */
#menu label { display: flex; flex-direction: row; align-items: center; gap: 10px; font: bold var(--fs-sm) "Trebuchet MS"; letter-spacing: 0.04em; }
#menu .p1 { color: #ff5a4d; } #menu .p2 { color: #37d0ff; }
#menu input {
  width: 160px; padding: 10px; text-align: center; font: bold var(--fs-md) "Trebuchet MS";
  color: #fff; background: rgba(8, 12, 24, 0.9); border: 2px solid currentColor; border-radius: 10px; outline: none;
}
#menu .nameRow { display: flex; gap: 6px; align-items: stretch; }
/* subtle "🎲 name me" button — borders in the player's colour (currentColor), quiet until hover */
.dice {
  width: 42px; flex: none; padding: 0; font-size: var(--fs-md); line-height: 1; color: inherit;
  background: rgba(8, 12, 24, 0.9); border: 2px solid currentColor; border-radius: 10px;
  opacity: 0.72; transition: opacity 0.12s, transform 0.06s;
}
.dice:hover, .dice:focus-visible { opacity: 1; }
.dice:active { transform: scale(0.93); }
#modeButtons, #onlineChoose, #onlinePanel, #lobby { display: flex; flex-direction: column; gap: 10px; align-items: center; width: min(420px, 92vw); }
/* Quick Race + its setup line stay tight together (setup configures Quick Race), then a
   clear gap separates them from the other modes. */
/* Quick Race takes the row; its Setup sits to the right as a small 2-line button. */
.primaryGroup { display: flex; flex-direction: row; align-items: stretch; gap: 8px; width: 100%; margin-bottom: 20px; }
.primaryGroup .play { flex: 1; }
#quickBox { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.optLinks { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 2px; }
.start:disabled { opacity: 0.4; cursor: not-allowed; filter: grayscale(0.5); }
button { cursor: pointer; font-family: inherit; }
.big {
  width: 100%; padding: 15px 18px; font: bold var(--fs-md) "Trebuchet MS"; color: var(--ink);
  background: linear-gradient(180deg, #2a3a66, #1a2742); border: 2px solid #4a6bb0; border-radius: 14px;
}
.big:hover, .big:active { border-color: var(--ok); }
/* the one primary action — a green hero so the eye always has an anchor */
.big.play {
  padding: 18px; font-size: var(--fs-lg); letter-spacing: 0.5px; color: #08210f;
  background: linear-gradient(180deg, #9dffb0, #46cf74); border-color: #bfffce;
  box-shadow: 0 6px 22px rgba(79, 208, 122, 0.28);
}
.big.play:hover, .big.play:active { border-color: #fff; }
/* small 2-line Setup button beside Quick Race (it configures Quick Race) — secondary + muted */
.setupbtn {
  flex: none; width: 120px; padding: 6px 10px; border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; line-height: 1.15;
  font: bold var(--fs-sm) "Trebuchet MS"; color: var(--muted);
  background: rgba(16, 22, 40, 0.6); border: 1.5px solid #34507e;
}
.setupbtn:hover { border-color: var(--ok); color: #fff; }
.setupbtn .setupsub { font-size: var(--fs-xs); color: var(--dim); font-weight: normal; }
#settingsRow { display: flex; justify-content: center; gap: 8px; margin-top: 28px; flex-wrap: wrap; }
/* utility buttons (leaderboard / options / what's new) — secondary, muted until hover */
.toggle {
  padding: 9px 14px; font: bold var(--fs-sm) "Trebuchet MS"; letter-spacing: 0.02em; color: var(--muted);
  background: rgba(16,22,40,0.6); border: 1.5px solid #34507e; border-radius: 10px;
}
.toggle:hover { border-color: var(--ok); color: #fff; }
.toggle[aria-pressed="true"] { color: var(--ok); border-color: var(--ok); background: rgba(20,46,30,0.55); }
.newsList { list-style: none; padding: 0; margin: 10px 0 16px; max-width: 440px; text-align: left; }
.newsList li { font: var(--fs-md)/1.5 "Trebuchet MS"; color: var(--ink); padding: 7px 0; border-bottom: 1px solid rgba(255,255,255,0.08); }
#arenaPick { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 460px; margin: 0 auto; }
#arenaPick .arena { padding: 8px 12px; font: bold var(--fs-sm) "Trebuchet MS"; color: var(--muted); background: rgba(16,22,40,0.7); border: 1.5px solid #34507e; border-radius: 10px; cursor: pointer; }
#arenaPick .arena:hover { border-color: var(--ok); }
#arenaPick .arena.sel { color: #0b1020; background: var(--accent); border-color: var(--accent); }
#diffPick { display: flex; gap: 8px; justify-content: center; }
#diffPick .diff { padding: 8px 16px; font: bold var(--fs-sm) "Trebuchet MS"; color: var(--muted); background: rgba(16,22,40,0.7); border: 1.5px solid #34507e; border-radius: 10px; cursor: pointer; }
#diffPick .diff:hover { border-color: var(--ok); }
#diffPick .diff.sel { color: #0b1020; background: var(--accent); border-color: var(--accent); }
.overlay .sub { color: var(--muted); font: var(--fs-sm) "Trebuchet MS"; margin: -4px 0 10px; }
#lbBody { max-width: 460px; margin: 6px auto 14px; text-align: left; max-height: 52vh; overflow-y: auto; width: min(460px, 88vw); }
#lbBody .row { display: flex; gap: 10px; padding: 8px 12px; border-bottom: 1px solid rgba(255,255,255,0.08); font: var(--fs-md) "Trebuchet MS"; color: var(--ink); }
#lbBody .row .rk { color: var(--accent); font-weight: bold; width: 30px; }
#lbBody .row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lbBody .row .tm { font-variant-numeric: tabular-nums; color: #fff; }
#lbBody .row.me { background: rgba(255,213,77,0.14); border-radius: 8px; }
#optBody { display: flex; flex-direction: column; align-items: center; gap: 18px; }
/* Options is grouped into labelled sections so it reads at a glance, not as one dense stack */
.optSection { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
.optHead { font: bold var(--fs-xs) "Trebuchet MS"; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }
#statsBox { display: grid; grid-template-columns: auto auto; gap: 6px 22px; text-align: left; font: var(--fs-md) "Trebuchet MS"; }
#statsBox span { color: var(--muted); }
#statsBox b { color: var(--accent); text-align: right; font-variant-numeric: tabular-nums; }
/* legal links pinned to the very bottom-right of the screen, above overlays, out of the flow */
.legalLinks { position: fixed; right: 18px; bottom: 12px; margin: 0; text-align: right; z-index: 33; }
.foot a { color: #7fb0e0; text-decoration: none; }
.foot a:hover { color: var(--ok); text-decoration: underline; }
.start {
  width: min(420px, 92vw); padding: 16px; margin-top: 4px; font: bold var(--fs-lg) "Trebuchet MS"; color: #08210f;
  background: linear-gradient(180deg, #9dffb0, #4fd07a); border: none; border-radius: 16px;
}
.small { padding: 8px 14px; font: bold var(--fs-sm) "Trebuchet MS"; color: var(--muted); background: rgba(8, 12, 24, 0.85); border: 2px solid #5a6b85; border-radius: 10px; }
.small:hover { border-color: var(--ok); color: var(--ink); }
#joinBox { display: flex; gap: 8px; }
#joinBox input { width: 120px; text-transform: uppercase; letter-spacing: 4px; }
#joinBox button { padding: 0 18px; background: #37d0ff; border: none; border-radius: 10px; font: bold var(--fs-md) "Trebuchet MS"; }
#codeBox { text-align: center; font: var(--fs-md) "Trebuchet MS"; color: var(--muted); background: rgba(16, 22, 40, 0.5); border: 1.5px solid #34507e; border-radius: 14px; padding: 14px 20px; }
#codeBox b { font-size: 38px; letter-spacing: 8px; color: var(--accent); display: block; margin: 4px 0 8px; }
#codeBox #btnCopyInvite { margin-top: 10px; }
.hint, .foot { font-size: var(--fs-xs); color: var(--dim); text-align: center; }
#startHint:empty { display: none; }
#startHint { font-size: var(--fs-sm); color: #ffcf6a; font-weight: bold; margin-bottom: 2px; }
#netStatus { font: bold var(--fs-sm) "Trebuchet MS"; color: var(--ok); text-align: center; min-height: 18px; }

#dailyNote { font: bold var(--fs-md) "Trebuchet MS"; color: var(--accent); text-align: center; max-width: 360px; line-height: 1.4; margin-bottom: 6px; }
#lobbyBack { margin-top: 12px; }              /* breathing room under START / the primary action */
#onlineChoose #btnQuick { margin-bottom: 14px; } /* separate Quick Match from the invite/join pair */

/* ---------- vs-CPU rival picker ---------- */
#cpuPanel { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.cpuLabel { font: bold var(--fs-sm) "Trebuchet MS"; color: var(--muted); letter-spacing: 0.05em; text-align: center; }
#cpuCount { display: flex; gap: 10px; }
#cpuCount .cpu {
  width: 50px; height: 50px; font: bold var(--fs-lg) "Trebuchet MS"; color: var(--ink);
  background: rgba(8, 12, 24, 0.85); border: 2px solid #5a6b85; border-radius: 12px;
}
#cpuCount .cpu.sel { color: #08210f; background: linear-gradient(180deg, #9dffb0, #4fd07a); border-color: #9dffb0; }

/* ---------- results / pause overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 25;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 24px; background: rgba(4, 7, 16, 0.94);
  -webkit-backdrop-filter: blur(7px); backdrop-filter: blur(7px); overflow-y: auto;
}
/* What's-new can be opened from inside Options, so it must stack ABOVE other overlays
   (same z-index + later in the DOM would paint it behind Options). */
#whatsnew { z-index: 32; }
.overlay h2 { font: 800 var(--fs-h2) "Trebuchet MS"; color: var(--accent); letter-spacing: 1px; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.5); text-align: center; }
.overlayBtns { display: flex; flex-direction: column; gap: 10px; width: min(360px, 90vw); }
#finishBody { width: min(440px, 92vw); display: flex; flex-direction: column; gap: 5px; }
#finishBody .sub { text-align: center; font: bold var(--fs-md) "Trebuchet MS"; color: var(--ok); }
#finishBody .lbhead { text-align: center; font: bold var(--fs-xs) "Trebuchet MS"; color: var(--dim); letter-spacing: 0.1em; margin-top: 8px; }
#finishBody .row { display: flex; align-items: center; gap: 10px; font: bold var(--fs-md) "Trebuchet MS"; color: var(--ink); padding: 5px 12px; border-radius: 9px; background: rgba(255, 255, 255, 0.05); }
#finishBody .row .pos { color: var(--muted); min-width: 30px; }
#finishBody .row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#finishBody .row .tm { color: var(--muted); font-variant-numeric: tabular-nums; }
#finishBody .row.me { background: rgba(255, 210, 80, 0.18); color: #ffe27a; }
#finishBody .row.me .pos, #finishBody .row.me .tm { color: #ffe27a; }

/* ---------- touch controls ---------- */
/* left thumb = steer (two big arrows) + FIRE just above · right thumb = BRAKE / BOOST
   (BOOST biggest, at the bottom where the thumb rests). The kart auto-accelerates, so
   there is no gas pedal. */
#touch { position: fixed; inset: 0; z-index: 15; pointer-events: none; }
#touch .pad { position: fixed; bottom: max(22px, env(safe-area-inset-bottom)); display: flex; }
#touch .left { left: 16px; flex-direction: column; align-items: flex-start; gap: 14px; }
#touch .left .steerrow { display: flex; gap: 14px; align-items: flex-end; }
#touch .left .fire { margin-left: 8px; } /* sit the fire button over the steering arrows */
#touch .right { right: 16px; flex-direction: column; align-items: center; gap: 14px; }

.tbtn {
  pointer-events: auto; border-radius: 50%; display: grid; place-items: center;
  color: #fff; background: rgba(18, 26, 48, 0.5);
  border: 3px solid rgba(255, 255, 255, 0.5); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  touch-action: none; -webkit-user-select: none; user-select: none;
  transition: transform 0.05s, filter 0.05s;
}
.tbtn span { font-size: 30px; line-height: 1; }
.tbtn i { margin-top: 2px; font: 800 10px/1 "Trebuchet MS"; font-style: normal; letter-spacing: 0.06em; opacity: 0.9; }
.tbtn.active { filter: brightness(1.5); transform: scale(0.92); }

/* steering */
.tbtn.steer { width: 92px; height: 92px; font-size: 42px; }
/* actions, smallest (top) → biggest (bottom, under the thumb) */
.tbtn.dodge { width: 64px; height: 64px; background: rgba(120, 92, 200, 0.5); border-color: #c3acff; }
.tbtn.brake { width: 70px; height: 70px; background: rgba(40, 60, 92, 0.5); border-color: #9fc0ff; }
.tbtn.fire  { width: 80px; height: 80px; background: rgba(180, 55, 45, 0.5); border-color: #ff8a7a; }
.tbtn.boost { width: 98px; height: 98px; background: rgba(200, 130, 24, 0.52); border-color: #ffd54d; }
.tbtn.boost span { font-size: 36px; }
