:root {
  --fg: #f4f7ff;
  --accent: #39e6ff;
  --panel: rgba(8, 10, 30, 0.82);
  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, placed by their progress. */
#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;
}

#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;
}

h1 {
  margin: 0;
  font-size: clamp(40px, 9vw, 84px);
  letter-spacing: 0.04em;
  color: var(--accent);
  text-shadow: 0 0 18px var(--accent);
}

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

.hint { opacity: 0.75; 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 var(--accent);
  border-radius: 10px;
  padding: 12px 22px;
  cursor: pointer;
  min-width: 180px;
}

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

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

.level-btn small { opacity: 0.7; }

#playerTag { margin: -6px 0 0; font-size: 15px; min-height: 1.2em; }

.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); }

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

#menuActions button { flex: 1; min-width: 0; }

#avatarBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

/* 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 .field { width: min(420px, 100%); }

.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; opacity: 0.7; 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 { opacity: 0.7; 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 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; }

#race h3 { margin: 10px 0 0; font-size: 18px; opacity: 0.85; }

#friendList:empty::after { content: 'No friends yet. Ask for their nickname and add it below.'; opacity: 0.6; font-size: 14px; }

.toast {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  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; }

#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); }
