:root {
  --fg: #f4f7ff;
  --accent: #39e6ff;
  --accent-soft: #8fe9ff; /* links and secondary cyan text */
  --muted: #aab4cd; /* hints, headings, difficulty labels: a solid colour, not opacity */
  --panel: rgba(8, 10, 30, 0.9);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #05060f;
  color: var(--fg);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }

canvas { display: block; width: 100%; height: 100%; }

[hidden] { display: none !important; }

#hud {
  position: absolute;
  top: 12px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}

.progress {
  position: relative;
  flex: 1;
  max-width: 420px;
  margin: 0 auto;
  height: 10px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.15);
}

#progressBar { border-radius: 5px; }

/* One marker per other racer at their live position (it falls back when
   they die), a faint tick at their best, and their attempt count below. */
#racers i {
  position: absolute;
  top: -4px;
  width: 8px;
  height: 18px;
  margin-left: -4px;
  border-radius: 3px;
  border: 1px solid #000;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.6);
  transition: left 0.1s linear;
}

#racers i.best { top: -2px; width: 2px; height: 14px; margin-left: -1px; border: none; box-shadow: none; opacity: 0.6; }

#racers small {
  position: absolute;
  top: 16px;
  transform: translateX(-50%);
  font-size: 11px;
  white-space: nowrap;
  text-shadow: 0 0 3px #000, 0 0 3px #000;
  transition: left 0.1s linear;
}

#racers small.pulse { animation: pulse 0.6s ease-out; }

@keyframes pulse { from { transform: translateX(-50%) scale(1.8); } to { transform: translateX(-50%) scale(1); } }

@media (prefers-reduced-motion: reduce) { #racers small.pulse { animation: none; } }

#progressBar { height: 100%; width: 0; background: var(--accent); }

#progressText { font-variant-numeric: tabular-nums; min-width: 3.5em; }

#pauseBtn { pointer-events: auto; padding: 6px 12px; font-size: 14px; min-width: 0; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center; /* scroll, don't clip, when taller than the screen */
  overflow-y: auto;
  gap: 14px;
  padding: 16px;
  background: var(--panel);
  text-align: center;
}

/* White letters with a thin cyan edge and a soft halo: the neon reads, the
   edges stay crisp. */
h1 {
  margin: 0;
  font-size: clamp(34px, 7vw, 60px);
  letter-spacing: 0.03em;
  color: var(--fg);
  text-shadow: 0 0 2px var(--accent), 0 0 14px rgba(57, 230, 255, 0.55);
}

h2 { margin: 0 0 8px; font-size: 40px; }

.hint { color: var(--muted); max-width: 34em; }

#levelList {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
  width: min(420px, 100%);
}

button {
  font: inherit;
  font-size: 18px;
  color: var(--fg);
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  padding: 12px 22px;
  cursor: pointer;
  min-width: 180px;
}

button:hover, button:focus-visible { background: rgba(57, 230, 255, 0.2); border-color: var(--accent); outline: none; }

/* Buttons are neutral by default; the accent marks the one main action of a
   screen (.primary), the level played last, the selected tab, hover and focus. */
button.primary { border-color: var(--accent); background: rgba(57, 230, 255, 0.14); }

.level-btn.last { border-color: var(--accent); }

.level-btn {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.level-btn small { color: var(--muted); }

#playerTag { margin: -6px 0 0; font-size: 15px; min-height: 1.2em; display: flex; align-items: center; justify-content: center; gap: 4px; }

.top-list {
  margin: 0;
  padding: 0 0 0 1.6em;
  width: min(320px, 100%);
  text-align: left;
  font-size: 16px;
}

.top-list:empty { display: none; }

.top-list li { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }

.top-list li.me { color: var(--accent); }

/* The player tag is a button: tap to change avatar and nickname. */
#avatarBtn.tag { display: inline-flex; align-items: center; gap: 8px; border: none; background: none; padding: 4px 8px; min-width: 0; font-size: 15px; margin: -6px 0 0; }

#avatarBtn.tag small { color: var(--muted); font-size: 13px; }

#avatarBtn.tag .av { filter: none; } /* the menu copy of the swatch stays flat */

#avatarBtn.tag:hover, #avatarBtn.tag:focus-visible { background: rgba(57, 230, 255, 0.15); border-radius: 8px; }

/* The party panel: one box at the top of the only screen. */
.party {
  width: min(420px, 100%);
  border: 1px solid var(--accent);
  border-radius: 14px;
  padding: 12px;
  display: grid;
  gap: 10px;
  justify-items: center;
  background: rgba(57, 230, 255, 0.06);
  box-shadow: 0 0 18px rgba(57, 230, 255, 0.12) inset;
}

.party.idle { border-color: rgba(255, 255, 255, 0.25); background: rgba(255, 255, 255, 0.03); box-shadow: none; }

.party > div { display: grid; gap: 10px; justify-items: center; width: 100%; }

.party h3, .play-heading { margin: 0; font-size: 13px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }

.play-heading { margin-top: 6px; }

.party .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; font-size: 15px; }

.party .head b { color: var(--accent); letter-spacing: 0.15em; font-size: 20px; }

.party .head .actions { display: flex; gap: 6px; }

.party .player-list, .party .race-row, .party .field { width: 100%; }

.party .player-list:empty { display: none; }

.party .more { display: flex; flex-wrap: wrap; gap: 2px 8px; justify-content: center; }

button.link { border: none; background: none; min-width: 0; padding: 2px 6px; font-size: 14px; color: var(--accent-soft); text-decoration: none; }

button.link:hover, button.link:focus-visible { background: none; text-decoration: underline; }

button.suggest { align-self: flex-start; margin: 2px 0 6px; font-size: 15px; }

button.sm { min-width: 0; padding: 4px 10px; font-size: 14px; }

button.ghost { border-color: rgba(255, 255, 255, 0.35); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 6px; border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 999px; font-size: 14px; }

.chip.lead { border-color: var(--accent); }

.chip.away { opacity: 0.6; }

.chip small { opacity: 0.7; font-size: 11px; }

.chip .av { width: 18px; height: 18px; }

.chip button { min-width: 0; padding: 1px 8px; font-size: 12px; }

#levelList button[disabled] { opacity: 0.45; cursor: default; }

/* Race screens */
.field { display: flex; flex-direction: column; align-items: stretch; gap: 4px; font-size: 14px; opacity: 0.9; text-align: left; }

.field input, .field select {
  font: inherit;
  font-size: 16px; /* 16px stops iOS from zooming into the field */
  color: var(--fg);
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 10px;
  padding: 8px 12px;
  min-width: 0;
}

.field input:focus, .field select:focus { border-color: var(--accent); outline: none; }

.field select option { color: #000; }

.race-row { display: flex; align-items: flex-end; gap: 10px; width: min(420px, 100%); }

.race-row .field { flex: 1; }

.race-row button { min-width: 0; white-space: nowrap; }

#raceCodeInput { text-transform: uppercase; letter-spacing: 0.2em; }

.error { margin: 0; min-height: 1.2em; color: #ff8a9a; }

.error:empty { display: none; }

.code {
  margin: 0;
  font-size: clamp(40px, 10vw, 64px);
  font-weight: bold;
  letter-spacing: 0.25em;
  color: var(--accent);
  text-shadow: 0 0 18px var(--accent);
  user-select: text;
  -webkit-user-select: text;
}

.link { margin: 0; font-size: 13px; color: var(--muted); word-break: break-all; user-select: text; -webkit-user-select: text; }

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  width: min(320px, 100%);
}

.player-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
}

.player-list small, .top-list small { color: var(--muted); white-space: nowrap; }

.player-list .badge { color: var(--accent); }

.player-list .who { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; text-align: left; }

.player-list .who .name > span, .top-list .name > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.player-list .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

.player-list .actions { display: flex; gap: 6px; flex-shrink: 0; }

.player-list .actions button { min-width: 0; padding: 4px 10px; font-size: 14px; }

.player-list .online { color: #39ff8a; }

button.secondary { font-size: 15px; padding: 7px 14px; border-color: rgba(255, 255, 255, 0.35); min-width: 0; }

.friends { display: grid; gap: 8px; width: min(420px, 100%); justify-items: center; }

.friends h3 { margin: 6px 0 0; font-size: 14px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }

.friends .player-list, .friends .race-row { width: 100%; }

.friends .top-list { width: 100%; }

#menuFriendList:empty::after { content: 'No friends yet. Add one by nickname.'; color: var(--muted); font-size: 14px; }

#menuFriendList:empty { display: block; }

.hint.small { font-size: 14px; }

.avatar-head { display: flex; align-items: center; gap: 14px; width: min(420px, 100%); }

.avatar-head .field { flex: 1; }

/* Small shape-and-color swatch before a name: the same cube or cat. */
.name { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }

.av { width: 22px; height: 22px; flex-shrink: 0; filter: drop-shadow(0 0 4px currentColor); }

.toast {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  width: max-content; /* an absolute box at left: 50% would otherwise shrink to half the screen */
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: rgba(10, 12, 24, 0.95);
  box-shadow: 0 0 18px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}

.toast button { min-width: 0; padding: 6px 12px; font-size: 14px; }

/* The analytics consent bar: on the menu only, until the player answers. */
.consent {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 14px;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: rgba(10, 12, 24, 0.95);
  box-shadow: 0 0 18px rgba(0, 0, 0, 0.5);
  font-size: 14px;
  text-align: left;
}

.consent p { margin: 0; max-width: 420px; }
.consent a { color: var(--accent); }
.consent div { display: flex; gap: 8px; }
.consent button { min-width: 0; padding: 6px 12px; font-size: 14px; }

#countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#countdownNum {
  font-size: clamp(96px, 30vw, 220px);
  font-weight: bold;
  color: var(--fg);
  text-shadow: 0 0 30px var(--accent), 0 0 4px #000;
}

#results.waiting { background: rgba(8, 10, 30, 0.45); }

.swatch-dot {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 2px solid #000;
  box-shadow: 0 0 0 1px var(--fg);
}

#avatarPreview { width: 96px; height: 96px; }

#swatches {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  max-width: 360px;
}

.swatch {
  min-width: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  font-size: 12px;
  font-weight: bold;
}

.swatch[aria-checked='true'] { border-color: var(--fg); box-shadow: 0 0 0 3px var(--accent); }

.swatch-auto, .swatch-auto:hover, .swatch-auto:focus-visible { background: conic-gradient(#ff3df2, #ffe14d, #39ff8a, #39e6ff, #8a5cff, #ff3df2); color: #000; }

.custom-color { display: flex; align-items: center; gap: 10px; }

.custom-color input { width: 56px; height: 36px; padding: 0; border: none; background: none; cursor: pointer; }

.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; }

.toggle input { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }

#worldTabs, #characters { display: flex; gap: 10px; width: min(420px, 100%); }

.world-tab, .character { flex: 1; min-width: 0; padding: 8px 12px; border-color: rgba(255, 255, 255, 0.35); }

.world-tab[aria-selected='true'], .character[aria-checked='true'] { border-color: var(--accent); background: rgba(57, 230, 255, 0.2); }

/* Legal links under the player line, so they are in view without scrolling (legal/privacy.html, legal/terms.html). */
.legal { margin-top: -8px; font-size: 12px; color: var(--muted); }
.legal a { color: var(--muted); text-decoration: none; padding: 4px 2px; }
.legal a:hover, .legal a:focus-visible { color: var(--accent); text-decoration: underline; }
