:root {
  color-scheme: dark;
  --ink: #f7f4e9;
  --night: #08142a;
  --cyan: #55efff;
  --gold: #ffc85a;
  --coral: #ff657a;
  --glass: rgba(6, 17, 38, .76);
  --line: rgba(224, 245, 255, .24);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--night); }
body { color: var(--ink); font: 14px/1.25 Inter, ui-sans-serif, system-ui, sans-serif; user-select: none; }
button { color: inherit; font: inherit; }
#app { position: relative; width: 100%; height: 100%; overflow: hidden; isolation: isolate; }
#viewport { display: block; width: 100%; height: 100%; touch-action: none; }

.hud {
  position: absolute;
  inset: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  padding: 20px 24px;
  pointer-events: none;
  text-shadow: 0 3px 18px #001;
}
.identity { display: grid; gap: 2px; }
.identity span, .kicker, .coach span, .echo span, .delta span {
  color: var(--cyan);
  font: 800 9px/1 ui-monospace, SFMono-Regular, monospace;
  letter-spacing: .22em;
}
.identity b { font-size: 16px; line-height: .82; letter-spacing: .14em; }
.race { display: grid; grid-template-columns: auto auto; align-items: baseline; gap: 3px 15px; text-align: center; }
.race span { color: var(--gold); font: 900 20px ui-monospace, monospace; }
.race b { letter-spacing: .14em; }
.race i { grid-column: 1 / 3; font: 700 11px ui-monospace, monospace; font-style: normal; color: #bfd3e3; }
#pauseButton {
  pointer-events: auto;
  justify-self: end;
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--glass);
  font-weight: 900;
  cursor: pointer;
}

.telemetry {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 25px;
  display: grid;
  grid-template-columns: 1fr minmax(200px, 360px) 1fr;
  align-items: end;
  gap: 20px;
  pointer-events: none;
  text-shadow: 0 3px 18px #001;
}
.speed { display: flex; align-items: end; gap: 7px; }
.speed b { font: 300 clamp(42px, 7vw, 78px)/.75 ui-monospace, monospace; letter-spacing: -.11em; }
.speed span { color: var(--cyan); font: 800 9px ui-monospace, monospace; }
.echo { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.echo > div { grid-column: 1 / 3; height: 5px; overflow: hidden; background: #e7faff20; }
.echo i { display: block; width: 8%; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--gold)); transform-origin: left; }
.echo b { color: var(--gold); font: 900 16px ui-monospace, monospace; }
.delta { justify-self: end; display: grid; text-align: right; gap: 3px; }
.delta b { color: var(--coral); font: 900 17px ui-monospace, monospace; }

.coach {
  position: absolute;
  top: 95px;
  left: 50%;
  width: min(540px, calc(100vw - 40px));
  transform: translateX(-50%);
  padding: 12px 20px;
  border: 1px solid var(--line);
  border-top-color: var(--gold);
  border-radius: 4px 4px 15px 15px;
  background: linear-gradient(180deg, rgba(6, 17, 38, .92), rgba(6, 17, 38, .55));
  text-align: center;
  box-shadow: 0 12px 40px #0018;
  pointer-events: none;
  transition: opacity .4s, transform .4s;
}
.coach b { display: block; margin: 4px; font-size: 15px; letter-spacing: .11em; }
.coach p { margin: 0; color: #b9cad8; font-size: 11px; }
.coach.away { opacity: 0; transform: translate(-50%, -15px); }

.apexCallout {
  position: absolute;
  left: 50%;
  top: 35%;
  opacity: 0;
  transform: translate(-50%, 20px) scale(.85);
  color: var(--gold);
  font: 900 clamp(28px, 5vw, 56px)/1 ui-sans-serif, system-ui;
  letter-spacing: -.05em;
  text-shadow: 0 5px 30px #ffb60088;
  pointer-events: none;
}
.apexCallout.show { animation: apex 1s ease-out; }
.modeBadge, .help {
  position: absolute;
  color: #8ba0b4;
  font: 700 8px ui-monospace, monospace;
  letter-spacing: .12em;
  pointer-events: none;
}
.modeBadge { right: 24px; bottom: 103px; }
.help { left: 50%; bottom: 103px; transform: translateX(-50%); }

.touch { display: none; }
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(115deg, rgba(5, 14, 33, .96), rgba(5, 14, 33, .54)),
    radial-gradient(circle at 70% 30%, #ff6e6e66, transparent 40%);
  backdrop-filter: blur(8px);
}
.card {
  width: min(570px, 100%);
  padding: 38px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--cyan);
  border-radius: 4px 28px 4px 28px;
  background: linear-gradient(145deg, rgba(15, 37, 65, .92), rgba(5, 16, 35, .96));
  box-shadow: 0 45px 120px #001d;
}
.card h1 {
  margin: 10px 0 18px;
  font-size: clamp(68px, 14vw, 112px);
  line-height: .66;
  letter-spacing: -.08em;
}
.card h1 i { color: transparent; -webkit-text-stroke: 1px var(--gold); font-style: normal; }
.card p { max-width: 470px; color: #bdceda; font-size: 15px; }
.card ul { display: flex; gap: 20px; padding: 0; list-style: none; color: #9aafbe; font: 700 9px ui-monospace, monospace; }
.card li b { display: block; margin-bottom: 3px; color: var(--ink); }
.card button {
  min-width: 230px;
  min-height: 52px;
  margin-top: 15px;
  border: 0;
  border-radius: 3px 14px 3px 14px;
  background: var(--cyan);
  color: #061126;
  font-weight: 900;
  letter-spacing: .08em;
  cursor: pointer;
  box-shadow: 0 12px 35px #55efff33;
}
.card small { display: block; margin-top: 13px; color: #748ca0; font: 700 9px ui-monospace, monospace; }
.compact, .result { text-align: center; }
.compact h2, .result h2 { margin: 8px; font-size: clamp(48px, 10vw, 82px); line-height: .8; letter-spacing: -.07em; }
.result dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin: 24px 0 5px; }
.result dl div { padding: 12px; border: 1px solid var(--line); background: #fff5; }
.result dt { color: #91a6b7; font: 700 8px ui-monospace, monospace; }
.result dd { margin: 4px 0 0; color: var(--gold); font: 900 20px ui-monospace, monospace; }

@keyframes apex {
  0% { opacity: 0; transform: translate(-50%, 20px) scale(.85); }
  20%, 65% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -20px) scale(1.06); }
}

@media (pointer: coarse), (max-width: 760px) {
  .hud { padding: 12px; }
  .identity b { font-size: 12px; }
  .race span { font-size: 15px; }
  .coach { top: 72px; }
  .telemetry { left: 12px; right: 12px; bottom: 95px; grid-template-columns: 1fr 1.3fr; }
  .delta { display: none; }
  .speed b { font-size: 42px; }
  .touch {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 10px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
  }
  .touch div { display: flex; gap: 8px; }
  .touch button {
    pointer-events: auto;
    min-width: 64px;
    height: 64px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--glass);
    font-size: 30px;
    font-weight: 900;
    touch-action: none;
  }
  .touch .brake, .touch .throttle { min-width: 76px; font-size: 10px; }
  .touch .brake { color: var(--cyan); border-color: var(--cyan); }
  .touch .throttle { color: #061126; border-color: var(--gold); background: var(--gold); }
  .help, .modeBadge { display: none; }
  .card { padding: 25px; }
  .card h1 { font-size: 72px; }
  .card ul { gap: 10px; }
}

@media (max-height: 520px) {
  .coach { display: none; }
  .card { padding: 20px 26px; }
  .card h1 { margin: 5px 0 10px; font-size: 60px; }
  .card p { margin: 7px 0; font-size: 11px; }
  .card ul { margin: 8px 0; }
  .card button { min-height: 44px; margin-top: 5px; }
}
