:root {
  --ink: #2a2440;
  --aqua: #5cc9f5;
  --sun: #ffd25e;
  --rest: #8fe870;
  --bubble: #ff7ad9;
  --grape: #a98bff;
  --coral: #ff5a6e;
  --gold: #ffe45e;
  --paper: #fff7ef;
  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 22px;
  --shadow-toy: 0 5px 0 rgba(42, 36, 64, 0.28);
  --shadow-panel: 0 12px 40px rgba(42, 36, 64, 0.22);
  --font: "Baloo 2", "Nunito", ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --edge: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: linear-gradient(180deg, #7fa8ff 0%, #ffe0c0 100%);
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

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

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

button,
a,
input {
  touch-action: manipulation;
}

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  /* A definite row, so a sheet's max-height: 100% really caps it at the screen. */
  grid-template-rows: minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: calc(var(--safe-top) + var(--edge)) calc(var(--safe-right) + var(--edge))
    calc(var(--safe-bottom) + var(--edge)) calc(var(--safe-left) + var(--edge));
  pointer-events: none;
}

.screen[hidden] {
  display: none;
}

.screen--start,
.screen--join,
.screen--lobby,
.screen--finish,
.screen--error {
  background: radial-gradient(120% 90% at 50% 0%, rgba(127, 168, 255, 0.5), rgba(42, 36, 64, 0.55));
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  pointer-events: auto;
}

/* One card per screen; it never scrolls the page, only its own list if it must. */
.sheet {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(440px, 100%);
  max-height: 100%;
  min-height: 0;
  padding: 16px 18px 18px;
  color: var(--ink);
  border-radius: var(--radius-l);
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-panel), var(--shadow-toy);
  animation: panel-in 260ms cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

.hub-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hub-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 2px 14px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--paper);
  background: var(--ink);
  border-radius: 999px;
}

.eyebrow {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.65;
}

.brand {
  display: grid;
  gap: 2px;
}

.logo {
  margin: 0;
  font-size: clamp(44px, 13vw, 62px);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.02em;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 12px;
}

.logo--small {
  font-size: clamp(34px, 10vw, 44px);
}

.logo__a,
.logo__b {
  display: inline-block;
  text-shadow: 0 4px 0 var(--ink);
  -webkit-text-stroke: 1.5px var(--ink);
}

.logo__a {
  color: var(--coral);
  transform: rotate(-4deg);
}

.logo__b {
  color: var(--aqua);
  transform: rotate(2deg);
}

.tagline {
  margin: 6px 0 0;
  font-size: 16px;
  line-height: 1.3;
  opacity: 0.8;
}

.panel__title {
  margin: 0;
  font-size: 30px;
  line-height: 1.1;
}

.field {
  display: block;
}

.field[hidden] {
  display: none;
}

.field__label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.65;
  margin-bottom: 4px;
}

.field__input {
  width: 100%;
  min-height: 50px;
  padding: 8px 14px;
  font: inherit;
  font-size: 19px;
  font-weight: 700;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: var(--radius-m);
  outline: none;
}

.field__input::placeholder {
  color: rgba(42, 36, 64, 0.35);
}

.field__input:focus-visible {
  box-shadow: 0 0 0 4px rgba(92, 201, 245, 0.55);
}

.field__input--code {
  text-transform: uppercase;
  letter-spacing: 0.4em;
  font-size: 24px;
}

.stack {
  display: grid;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 8px 18px;
  font: inherit;
  font-size: 19px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--ink);
  text-decoration: none;
  border: 3px solid var(--ink);
  border-radius: var(--radius-m);
  cursor: pointer;
  box-shadow: var(--shadow-toy);
  transform: translateY(0);
  transition:
    transform 90ms ease,
    box-shadow 90ms ease,
    background 140ms ease;
  user-select: none;
  -webkit-user-select: none;
}

.btn[hidden] {
  display: none;
}

.btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 1px 0 rgba(42, 36, 64, 0.28);
}

.btn:focus-visible {
  outline: 4px solid rgba(92, 201, 245, 0.7);
  outline-offset: 2px;
}

.btn:disabled {
  cursor: default;
  opacity: 0.55;
}

.btn--big {
  min-height: 58px;
  font-size: 22px;
}

.btn--small {
  min-height: 44px;
  padding: 4px 14px;
  font-size: 16px;
}

.btn--chip {
  min-height: 44px;
  padding: 4px 14px;
  font-size: 15px;
  border-radius: 999px;
  background: var(--paper);
  box-shadow: 0 3px 0 rgba(42, 36, 64, 0.28);
}

.btn--primary {
  background: var(--sun);
}

.btn--secondary {
  background: var(--aqua);
}

.btn--go {
  background: var(--rest);
}

.btn--ghost {
  background: var(--paper);
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
}

.form-message {
  margin: 0;
  padding: 10px 12px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  color: #8a1f2e;
  background: #ffe9ec;
  border: 3px solid var(--coral);
  border-radius: var(--radius-m);
}

.form-message[hidden] {
  display: none;
}

.hint {
  margin: 0;
  font-size: 13px;
  opacity: 0.72;
}

kbd {
  font: inherit;
  font-size: 0.92em;
  background: var(--ink);
  color: var(--paper);
  border-radius: 6px;
  padding: 1px 7px;
}

@media (pointer: coarse) {
  .hint--keys,
  .controls-hint {
    display: none;
  }
}

/* ---------- global overlays ---------- */

.net-banner,
.toast {
  position: fixed;
  left: 50%;
  z-index: 30;
  max-width: calc(100% - 28px);
  padding: 8px 16px;
  font-weight: 800;
  font-size: 15px;
  text-align: center;
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: var(--shadow-toy);
  transform: translateX(-50%);
  pointer-events: none;
}

.net-banner {
  top: calc(var(--safe-top) + 10px);
  background: var(--sun);
  animation: pulse 1.2s ease-in-out infinite;
}

.toast {
  bottom: calc(var(--safe-bottom) + 18px);
  background: var(--paper);
  border-radius: var(--radius-m);
}

.net-banner[hidden],
.toast[hidden] {
  display: none;
}

@keyframes pulse {
  50% {
    opacity: 0.7;
  }
}

.live {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- landing and join ---------- */

.sheet--start .stack .btn--big {
  min-height: 62px;
  font-size: 24px;
}

.join-code {
  display: grid;
  justify-items: center;
  padding: 8px 12px;
  background: #fff;
  border: 3px dashed var(--ink);
  border-radius: var(--radius-m);
}

.join-code[hidden] {
  display: none;
}

.join-code__value {
  font-size: 46px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--coral);
  text-shadow: 0 3px 0 var(--ink);
}

@media (max-height: 600px) {
  .sheet {
    gap: 9px;
    padding: 12px 14px 14px;
  }

  .tagline {
    font-size: 14px;
  }

  .logo {
    font-size: 42px;
  }

  .logo--small {
    font-size: 32px;
  }

  .screen .sheet .btn--big {
    min-height: 52px;
    font-size: 20px;
  }
}

/* ---------- TV screen (/tv/CODE) ---------- */

.screen--tv {
  --tv-unit: min(1vw, 1.8vh);
  place-items: stretch;
  padding: calc(var(--safe-top) + 3vh) calc(var(--safe-right) + 3vw) calc(var(--safe-bottom) + 3vh)
    calc(var(--safe-left) + 3vw);
}

.screen--tv[data-phase="lobby"],
.screen--tv[data-phase="results"] {
  background: radial-gradient(120% 90% at 50% 0%, rgba(127, 168, 255, 0.55), rgba(42, 36, 64, 0.7));
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.tv-lobby,
.tv-race,
.tv-results {
  display: none;
}

.screen--tv[data-phase="lobby"] .tv-lobby,
.screen--tv[data-phase="results"] .tv-results {
  display: grid;
}

.screen--tv[data-phase="race"] .tv-race {
  display: block;
}

.tv-lobby {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 5vw;
}

.tv-invite {
  display: grid;
  justify-items: center;
  gap: 1vh;
  padding: 2.4vh;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-panel), var(--shadow-toy);
}

.tv-invite__qr {
  width: min(56vh, 40vw);
  aspect-ratio: 1;
}

.tv-invite__scan {
  margin: 0;
  font-size: calc(var(--tv-unit) * 4);
  font-weight: 800;
}

.tv-invite__url {
  margin: 0;
  font-size: calc(var(--tv-unit) * 2);
  font-weight: 700;
  opacity: 0.75;
}

.tv-side {
  display: grid;
  gap: 1.6vh;
  align-content: center;
  color: var(--paper);
}

.tv-side .logo {
  font-size: calc(var(--tv-unit) * 8);
}

.tv-code {
  margin: 0;
  font-size: calc(var(--tv-unit) * 3);
  font-weight: 700;
}

.tv-code strong {
  display: block;
  font-size: calc(var(--tv-unit) * 9);
  line-height: 1;
  letter-spacing: 0.14em;
  color: var(--sun);
  text-shadow: 0 6px 0 var(--ink);
}

.tv-status {
  margin: 0;
  font-size: calc(var(--tv-unit) * 2.6);
  font-weight: 700;
}

.tv-roster {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.2vh 1vw;
}

.tv-roster .player {
  min-height: calc(var(--tv-unit) * 6);
  font-size: calc(var(--tv-unit) * 2.4);
  color: var(--ink);
}

.tv-roster .player__name {
  font-size: inherit;
}

.tv-roster .player__state {
  font-size: calc(var(--tv-unit) * 1.8);
}

.tv-roster .player__dot {
  width: calc(var(--tv-unit) * 2.4);
  height: calc(var(--tv-unit) * 2.4);
}

.tv-race {
  justify-self: end;
  align-self: start;
  width: min(28vw, 460px);
  padding: 1.6vh 1.2vw;
  background: rgba(42, 36, 64, 0.72);
  border-radius: var(--radius-l);
  color: #fff;
}

.tv-race__code {
  margin: 0 0 1vh;
  font-size: calc(var(--tv-unit) * 2);
  font-weight: 700;
}

.tv-race__code strong {
  color: var(--sun);
  letter-spacing: 0.1em;
}

.tv-results {
  align-content: center;
  justify-items: center;
  gap: 2vh;
  color: var(--paper);
}

.tv-results__title {
  margin: 0;
  font-size: calc(var(--tv-unit) * 6);
  text-shadow: 0 5px 0 var(--ink);
}

.tv-results__hint {
  margin: 0;
  font-size: calc(var(--tv-unit) * 2.4);
  font-weight: 700;
}

.podium {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: flex-end;
  gap: 1.4vw;
}

.podium__step {
  display: grid;
  justify-items: center;
  gap: 0.6vh;
  width: min(16vw, 280px);
  font-weight: 800;
}

.podium__racer {
  width: calc(var(--tv-unit) * 7);
  aspect-ratio: 1;
  border-radius: 50% 50% 46% 46%;
  background: var(--dot);
  border: 4px solid var(--ink);
  box-shadow: inset 0 -10px 0 rgba(0, 0, 0, 0.12);
}

.podium__name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: calc(var(--tv-unit) * 3);
}

.podium__time {
  font-size: calc(var(--tv-unit) * 2.2);
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

.podium__block {
  display: grid;
  place-items: center;
  width: 100%;
  font-size: calc(var(--tv-unit) * 4);
  color: var(--ink);
  border: 4px solid var(--ink);
  border-radius: var(--radius-m) var(--radius-m) 0 0;
}

.podium__step--1 .podium__block {
  height: 24vh;
  background: var(--gold);
}

.podium__step--2 .podium__block {
  height: 17vh;
  background: #dfe6f2;
}

.podium__step--3 .podium__block {
  height: 12vh;
  background: #f2b98a;
}

.results--tv {
  width: min(60vw, 900px);
  max-height: 22vh;
  font-size: calc(var(--tv-unit) * 2.2);
}

.tv-message {
  position: absolute;
  left: 50%;
  bottom: 6vh;
  transform: translateX(-50%);
  max-width: 80vw;
  margin: 0;
  padding: 1.4vh 2vw;
  font-size: calc(var(--tv-unit) * 2.6);
  font-weight: 800;
  text-align: center;
  background: #ffe9ec;
  border: 4px solid var(--coral);
  border-radius: var(--radius-l);
}

.tv-message[hidden] {
  display: none;
}

/* A TV link opened on a phone still works: stack the QR above the roster. */
@media (max-aspect-ratio: 1 / 1) {
  .screen--tv {
    --tv-unit: 1.6vw;
  }

  .tv-lobby {
    grid-template-columns: 1fr;
    justify-items: center;
    align-content: start;
    gap: 2vh;
  }

  .tv-invite__qr {
    width: min(56vw, 36vh);
  }

  .tv-side {
    justify-items: center;
    text-align: center;
  }

  .tv-race {
    width: min(60vw, 260px);
  }

  .podium__step {
    width: 26vw;
  }
}

/* ---------- phone lobby ---------- */

.sheet--lobby {
  gap: 10px;
}

.invite {
  display: flex;
  align-items: center;
  gap: 14px;
}

.qr svg {
  display: block;
  width: 100%;
  height: 100%;
}

.invite__qr {
  flex: none;
  width: clamp(96px, 30vw, 132px);
  aspect-ratio: 1;
  padding: 4px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: var(--radius-m);
}

.invite__text {
  display: grid;
  gap: 4px;
  justify-items: start;
  min-width: 0;
}

.invite__code {
  font-size: clamp(40px, 12vw, 52px);
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--coral);
  text-shadow: 0 3px 0 var(--ink);
}

.lobby-status {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  opacity: 0.8;
}

.players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  min-height: 0;
  overflow: auto;
  align-content: start;
}

/* Five or more racers fold into two columns so eight still fit a small phone. */
.players:has(> :nth-child(5)) {
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
}

.player {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 4px 10px;
  border: 3px solid var(--ink);
  border-radius: var(--radius-m);
  background: #fff;
  min-width: 0;
}

.player--ready {
  background: #dff8d5;
}

.player--you {
  box-shadow: inset 0 0 0 2px var(--sun);
}

.player--away {
  opacity: 0.55;
}

.player__dot {
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--dot);
  border: 2px solid var(--ink);
}

.player__name {
  flex: 1;
  min-width: 0;
  font-weight: 800;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player__you {
  font-style: normal;
  font-size: 12px;
  font-weight: 800;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--sun);
  vertical-align: 2px;
}

.player__crown {
  flex: none;
  color: #e0a400;
  display: inline-flex;
}

.player__state {
  flex: none;
  font-size: 13px;
  font-weight: 700;
  opacity: 0.7;
}

.player--ready .player__state {
  color: #2f7d16;
  opacity: 1;
}

.players:has(> :nth-child(5)) .player__state {
  font-size: 0;
}

.players:has(> :nth-child(5)) .player--ready .player__state::after {
  content: "✓";
  font-size: 18px;
}

.lobby-actions {
  display: flex;
  gap: 10px;
}

.lobby-actions .btn {
  flex: 1 1 0;
  padding-inline: 10px;
}

#ready-btn[aria-pressed="true"] {
  background: var(--rest);
}

@media (max-height: 600px) {
  .invite__code {
    font-size: 40px;
  }

  .lobby-status {
    font-size: 14px;
  }
}

/* ---------- HUD ---------- */

.screen--hud {
  place-items: start center;
  pointer-events: none;
}

.hud {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  left: calc(var(--safe-left) + 12px);
  right: calc(var(--safe-right) + 12px);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas: "pips timer place";
  align-items: center;
  gap: 8px 12px;
}

.hud__timer {
  grid-area: timer;
  font-size: clamp(28px, 5vw, 46px);
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: #fff;
  padding: 4px 18px;
  background: rgba(42, 36, 64, 0.72);
  border-radius: var(--radius-l);
  border: 3px solid rgba(255, 255, 255, 0.22);
}

.hud__pips {
  grid-area: pips;
  display: flex;
  gap: 5px;
}

.pip {
  width: 24px;
  height: 10px;
  border-radius: 999px;
  background: rgba(42, 36, 64, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.6);
  transition:
    background 220ms ease,
    transform 220ms cubic-bezier(0.2, 0.9, 0.25, 1);
}

.pip--on {
  background: var(--rest);
  transform: scaleX(1.12);
}

.hud__place {
  grid-area: place;
  justify-self: end;
  padding: 4px 14px;
  background: rgba(42, 36, 64, 0.6);
  border-radius: 999px;
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.hud__place:empty {
  display: none;
}

/* Portrait phones: the timer gets its own row, pips and place share the next. */
@media (max-width: 520px) {
  .hud {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "timer timer"
      "pips place";
  }

  .hud__timer {
    justify-self: center;
    font-size: 30px;
  }

  .pip {
    width: 18px;
  }
}

.hud-note {
  position: absolute;
  top: calc(var(--safe-top) + 112px);
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 28px);
  margin: 0;
  padding: 8px 16px;
  font-size: 18px;
  font-weight: 800;
  text-align: center;
  background: var(--gold);
  border: 3px solid var(--ink);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-toy);
}

.hud-note[hidden] {
  display: none;
}

.controls-hint {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 22px);
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  background: rgba(42, 36, 64, 0.6);
  color: #fff;
  border-radius: 999px;
  font-size: 14px;
  white-space: nowrap;
  transition: opacity 600ms ease;
}

.controls-hint--faded {
  opacity: 0;
}

/* ---------- countdown and closing banner (shared by HUD, spectators and TV) ---------- */

.countdown[hidden],
.closing[hidden] {
  display: none;
}

.countdown {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  font-size: clamp(90px, 26vw, 220px);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 10px 0 rgba(42, 36, 64, 0.55);
  -webkit-text-stroke: 3px var(--ink);
  pointer-events: none;
}

.countdown--pop {
  animation: pop 400ms cubic-bezier(0.2, 1.4, 0.3, 1) both;
}

@keyframes pop {
  from {
    transform: scale(1.6);
    opacity: 0;
  }
}

.closing {
  position: fixed;
  z-index: 15;
  top: calc(var(--safe-top) + 112px);
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 28px);
  padding: 8px 18px;
  font-size: 18px;
  font-weight: 800;
  text-align: center;
  color: #fff;
  background: var(--coral);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: var(--shadow-toy);
  pointer-events: none;
}

html[data-screen="hud"] .hud-note:not([hidden]) ~ .closing,
html[data-screen="hud"] .closing {
  top: calc(var(--safe-top) + 160px);
}

html[data-screen="watch"] .closing {
  top: calc(var(--safe-top) + 100px);
}

html[data-screen="tv"] .closing {
  top: auto;
  bottom: 5vh;
  font-size: calc(min(1vw, 1.8vh) * 3);
}

html:not([data-screen="hud"]):not([data-screen="watch"]):not([data-screen="tv"]) .closing,
html:not([data-screen="hud"]):not([data-screen="watch"]):not([data-screen="tv"]) .countdown {
  display: none;
}

/* ---------- spectating on a phone ---------- */

.screen--watch {
  grid-template-rows: none;
  place-items: start stretch;
  align-content: start;
  gap: 10px;
}

.watch-card {
  display: grid;
  gap: 2px;
  justify-self: center;
  max-width: 420px;
  padding: 10px 16px;
  text-align: center;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-toy);
}

.watch-card__title {
  font-size: 20px;
}

.watch-card__text {
  font-size: 15px;
  font-weight: 700;
  opacity: 0.8;
}

.watch-leave {
  position: absolute;
  left: calc(var(--safe-left) + 14px);
  bottom: calc(var(--safe-bottom) + 14px);
  pointer-events: auto;
}

.standings {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.standings--mini {
  justify-self: end;
  width: min(220px, 60vw);
}

.standings__row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 2px 10px;
  color: #fff;
  font-weight: 800;
  background: rgba(42, 36, 64, 0.7);
  border-radius: 999px;
}

.standings__row--done {
  background: rgba(47, 125, 22, 0.85);
}

.standings__place {
  width: 1.4em;
  text-align: center;
}

.standings__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.standings__time {
  font-variant-numeric: tabular-nums;
  font-size: 0.85em;
}

.tv-race .standings__row {
  min-height: calc(min(1vw, 1.8vh) * 5);
  font-size: calc(min(1vw, 1.8vh) * 2.4);
}

.tv-race .player__dot {
  width: 1em;
  height: 1em;
}

/* A phone that is watching this round has no runner, so no thumb stick or buttons.
   Specific enough to beat both "show" rules in touch.css, which loads after this file. */
html[data-spectating="true"][data-screen] .touch,
html[data-spectating="true"][data-screen][data-touch] .touch {
  display: none;
}

/* On-screen phone controls (src/client/touch-controls.ts).
   Shown only on the HUD screen of a touch device: a coarse pointer, or once a
   touch has been seen (html[data-touch], set by touch-controls.ts). */

.touch {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
  z-index: 5;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html[data-screen="hud"][data-touch] .touch {
  display: block;
}

@media (pointer: coarse) {
  html[data-screen="hud"] .touch {
    display: block;
  }
  #controls-hint {
    display: none;
  }
}

html[data-touch] #controls-hint {
  display: none;
}

/* Left thumb area: the stick appears wherever the thumb lands in here. */
.touch__zone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 58%;
  height: 62%;
  pointer-events: auto;
  touch-action: none;
}

.touch__base {
  position: absolute;
  /* Resting spot (a hint of where to put the thumb) until a touch moves it. */
  left: calc(84px + env(safe-area-inset-left));
  top: calc(100% - 112px - env(safe-area-inset-bottom));
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border-radius: 50%;
  background: rgba(42, 36, 64, 0.22);
  border: 3px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 4px 14px rgba(42, 36, 64, 0.25);
  opacity: 0.55;
  transition: opacity 120ms ease;
  pointer-events: none;
}

.touch__base.is-active {
  opacity: 1;
  background: rgba(42, 36, 64, 0.32);
  transition: none;
}

.touch__knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 3px 0 rgba(42, 36, 64, 0.35);
}

.touch__base.is-active .touch__knob {
  background: #fff;
  box-shadow:
    0 3px 0 rgba(42, 36, 64, 0.35),
    0 0 0 4px rgba(255, 210, 90, 0.7);
}

.touch__btn {
  position: absolute;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.85);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 0 rgba(42, 36, 64, 0.55);
  box-shadow: 0 5px 0 rgba(42, 36, 64, 0.4);
  pointer-events: auto;
  touch-action: none;
  transition:
    transform 60ms ease,
    box-shadow 60ms ease;
}

.touch__btn--jump {
  right: calc(18px + env(safe-area-inset-right));
  bottom: calc(28px + env(safe-area-inset-bottom));
  width: 96px;
  height: 96px;
  background: rgba(255, 122, 92, 0.82);
  font-size: 18px;
}

/* Action: context icon over a label, both in fixed boxes so a context change
   never shifts layout. The icon shown is picked by data-action (action-button.ts). */
.touch__btn--action {
  right: calc(122px + env(safe-area-inset-right));
  bottom: calc(52px + env(safe-area-inset-bottom));
  width: 80px;
  height: 80px;
  background: rgba(92, 150, 255, 0.82);
  grid-template-rows: 30px 18px;
  align-content: center;
  justify-items: center;
  gap: 1px;
  font-size: 14px;
}

.touch__icons {
  position: relative;
  width: 30px;
  height: 30px;
}

.touch__icon {
  position: absolute;
  inset: 0;
  width: 30px;
  height: 30px;
  display: none;
  filter: drop-shadow(0 2px 0 rgba(42, 36, 64, 0.55));
}

.touch__label {
  height: 18px;
  line-height: 18px;
}

.touch__btn--action[data-action="dash"] .touch__icon--dash,
.touch__btn--action[data-action="dive"] .touch__icon--dive,
.touch__btn--action[data-action="slide"] .touch__icon--slide,
.touch__btn--action[data-action="grab"] .touch__icon--grab,
.touch__btn--action[data-action="parry"] .touch__icon--parry {
  display: block;
}

.touch__btn--action[data-action="dive"] {
  background: rgba(150, 110, 255, 0.85);
}

.touch__btn--action[data-action="parry"] {
  background: rgba(255, 196, 64, 0.9);
}

/* Parry is a timing window: the shield pulses so it reads as "now!". */
.touch__btn--action[data-action="parry"] .touch__icon--parry {
  animation: parry-pulse 520ms ease-in-out infinite;
}

@keyframes parry-pulse {
  50% {
    transform: scale(1.22);
  }
}

@media (prefers-reduced-motion: reduce) {
  .touch__btn--action[data-action="parry"] .touch__icon--parry {
    animation: none;
  }
}

.touch__btn.is-pressed {
  transform: translateY(4px) scale(0.94);
  box-shadow: 0 1px 0 rgba(42, 36, 64, 0.4);
  border-color: #ffd25a;
  filter: brightness(1.15);
}

/* Small phones (320 px wide): keep the buttons thumb-sized but leave room for the stick. */
@media (max-width: 360px) {
  .touch__btn--jump {
    width: 88px;
    height: 88px;
    right: calc(12px + env(safe-area-inset-right));
  }
  .touch__btn--action {
    width: 76px;
    height: 76px;
    right: calc(108px + env(safe-area-inset-right));
  }
}

/* Right-half look zone (src/client/touch-look.ts): swipe to turn, pinch to zoom.
   First child of .touch, so the stick zone and buttons stack above it. */
.touch__look {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 50%;
  pointer-events: auto;
  touch-action: none;
}

/* Desktop mouse-look hint (src/client/mouse-look.ts): race HUD on a mouse only. */
.look-hint {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 66px);
  left: 50%;
  transform: translateX(-50%);
  display: none;
  padding: 6px 14px;
  background: rgba(42, 36, 64, 0.5);
  color: #fff;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  animation: look-hint-fade 9s ease forwards;
}

.look-hint.is-locked {
  animation-name: look-hint-fade-locked;
}

html[data-screen="hud"] .look-hint {
  display: block;
}

html[data-touch] .look-hint {
  display: none;
}

@media (pointer: coarse) {
  .look-hint {
    display: none !important;
  }
}

@keyframes look-hint-fade {
  0%,
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* Same curve under another name, so entering mouse-look replays the hint. */
@keyframes look-hint-fade-locked {
  0%,
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* ---------- finish and results ---------- */

.sheet--finish {
  gap: 8px;
}

.finish-time {
  margin: 0;
  font-size: clamp(40px, 12vw, 62px);
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--coral);
  text-shadow: 0 4px 0 var(--ink);
}

.finish-time[hidden] {
  display: none;
}

.finish-note {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  opacity: 0.78;
}

.results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 5px;
  min-height: 0;
  overflow: auto;
  align-content: start;
}

.results__row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 2px 12px;
  border: 3px solid var(--ink);
  border-radius: var(--radius-m);
  background: #fff;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.results__row--you {
  background: var(--gold);
}

.results__row--dnf {
  opacity: 0.75;
}

.results__place {
  flex: none;
  width: 2.4em;
  font-weight: 800;
  color: var(--coral);
}

.results__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.results__time {
  flex: none;
}

.results__row--dnf .results__time {
  font-weight: 800;
  color: #8a1f2e;
}

.finish-actions {
  display: flex;
  gap: 10px;
}

.finish-actions .btn {
  flex: 1 1 auto;
}

.finish-actions .btn--ghost {
  min-height: 58px;
}

@media (max-height: 640px) {
  .results__row {
    min-height: 32px;
  }

  .finish-time {
    font-size: 38px;
  }

  .finish-actions .btn {
    min-height: 52px;
    padding-inline: 10px;
    font-size: 18px;
  }

  .panel__title {
    font-size: 26px;
  }
}

/* ---------- error ---------- */

.sheet--error {
  background: #fff2f2;
}

.error-message {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  padding: 12px 14px;
  background: #fff;
  border: 3px solid var(--coral);
  border-radius: var(--radius-m);
  word-break: break-word;
}
