:root {
  color-scheme: light dark;
  --grass: #eef0f2;
  --asphalt: #d4d6da;
  --curb: #b9bcc2;
  --dash: #ffffff;
  --ink: #0a0a0a;
  --muted: #56585e;
  --surface: #ffffffee;
  --border: #00000018;
  --accent: #0a0a0a;
  --accent-ink: #ffffff;
  --shadow: 0 18px 48px #0000001f;
}

[data-theme='dark'] {
  --grass: #0b0d10;
  --asphalt: #26272b;
  --curb: #3f3f46;
  --dash: #52525b;
  --ink: #fafafa;
  --muted: #a1a1aa;
  --surface: #131417f2;
  --border: #ffffff1f;
  --accent: #fafafa;
  --accent-ink: #0a0a0a;
  --shadow: 0 18px 48px #00000066;
}

* { box-sizing: border-box; }

/* Every panel below sets its own `display`, which would otherwise beat the
   browser's [hidden] { display: none } and leave the HUD, the pads and the
   countdown on screen for the whole session. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--grass);
  color: var(--ink);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.shell { position: fixed; inset: 0; }

#stage { display: block; width: 100%; height: 100%; touch-action: none; }

/* Above the steering thumb on the left: the top corners belong to the order
   list and the map, and the right column is the item/brake/drift cluster. */
.hud {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 104px);
  left: 12px;
  max-width: calc(100% - 150px);
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 54px;
  padding: 2px 8px;
  line-height: 1.15;
}

.pill span { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.pill strong { font-size: 15px; font-variant-numeric: tabular-nums; }

.charge {
  width: 66px;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.charge i { display: block; height: 100%; width: 0%; background: var(--muted); transition: width 90ms linear, background-color 120ms linear; }
.charge i[data-tier='1'] { background: #f59e0b; }
.charge i[data-tier='2'] { background: #ec4899; }
.charge i[data-tier='boost'] { background: #22c55e; }

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: #38bdf8;
  color: #06131c;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Item slots sit in the right-hand cluster and only exist while they hold
   something, so an empty-handed player still sees a clean layout.
   Compound selector on purpose: .pad is defined further down the file and would
   otherwise win on source order. */
.pad.pad-item {
  width: 56px;
  height: 56px;
  min-width: 56px;
  min-height: 56px;
  padding: 0 2px;
  border-radius: 16px;
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  box-shadow: var(--shadow);
}

.badge-devil { background: #ef4444; color: #fff5f5; }

/* The devil does not blind you — it swaps your steering. The overlay only has
   to say "this is why you are turning the wrong way". */
.devil {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  box-shadow: inset 0 0 22vmin 6vmin #dc2626aa;
  animation: pulse 1.1s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { box-shadow: inset 0 0 18vmin 4vmin #dc262699; }
  to { box-shadow: inset 0 0 26vmin 8vmin #dc2626cc; }
}

.countdown {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  font-size: clamp(64px, 22vw, 132px);
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--ink);
  text-shadow: 0 6px 24px #00000040;
  pointer-events: none;
}

.standings {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 4px;
  max-width: 46vw;
}

.standings li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.2;
}

.standings li.me { border-color: var(--ink); font-weight: 600; }
.standings .rank { min-width: 12px; font-variant-numeric: tabular-nums; font-weight: 700; }
.standings .dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.standings .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standings .gap { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

.minimap {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: 10px;
  width: 108px;
  height: 108px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.toast {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 176px);
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 13px;
  max-width: calc(100% - 32px);
  text-align: center;
}

/* Thumbs: steering on the left, everything you tap on the right. */
.pads {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px;
  align-items: flex-end;
}

.pad-left { display: flex; gap: 10px; align-items: flex-end; }
.pad-right { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.slots { display: flex; gap: 10px; }
.pad-row { display: flex; align-items: flex-end; gap: 10px; }

.pad {
  min-height: 72px;
  min-width: 72px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 22px;
  font-weight: 700;
  touch-action: none;
  user-select: none;
  cursor: pointer;
  transition: transform 90ms ease, background-color 120ms ease;
}

.pad:active, .pad[data-held='true'] { transform: scale(0.96); background: var(--accent); color: var(--accent-ink); }
.pad-steer { width: 74px; height: 74px; min-width: 74px; min-height: 74px; border-radius: 50%; font-size: 22px; }
.pad-drift { width: 92px; height: 92px; min-width: 92px; min-height: 92px; border-radius: 50%; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.pad-brake { width: 66px; height: 66px; min-width: 66px; min-height: 66px; border-radius: 50%; font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase; }
.pad:focus-visible, .primary:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: color-mix(in srgb, var(--grass) 82%, transparent);
  backdrop-filter: blur(6px);
  z-index: 5;
}

.modal[hidden] { display: none; }

.card {
  width: min(420px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 22px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.eyebrow { margin: 0 0 4px; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.card h1, .card h2 { margin: 0 0 6px; font-size: 24px; letter-spacing: -0.02em; }
.hint { margin: 0 0 14px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.hint.small { margin: 12px 0 0; font-size: 13px; }

.roster { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }

.roster li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  font-size: 15px;
}

.roster .dot { width: 14px; height: 14px; border-radius: 5px; flex: none; }
.roster .who { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster .meta { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.roster .rank { font-weight: 700; min-width: 22px; }

.primary {
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.primary[disabled] { opacity: 0.42; cursor: default; }

@media (prefers-reduced-motion: reduce) {
  .pad, .charge i { transition: none; }
  .devil { animation: none; }
}
