:root {
  --bg: #070914;
  --ink: #eef8ff;
  --muted: #93a4c4;
  --cyan: #3dfff2;
  --magenta: #ff2d95;
  --gold: #ffd166;
  --panel: rgba(7, 10, 24, 0.72);
  --line: rgba(61, 255, 242, 0.45);
  --danger: #ff5d73;
  font-family: "WenQuanYi Micro Hei", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; }
button, input { font-family: inherit; }
button { cursor: pointer; }
#game { display: block; width: 100%; height: 100%; }

#boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, #14203f, #070914 70%);
  z-index: 20;
  letter-spacing: 0.18em;
}
#boot.hide { display: none; }

.screen {
  position: fixed;
  inset: 0;
  display: none;
  pointer-events: none;
  z-index: 5;
}
.screen.open { display: block; pointer-events: none; }
.screen.open .panel { pointer-events: auto; }

.panel {
  position: absolute;
  top: max(16px, 3vh);
  left: max(20px, 4vw);
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  padding: 22px 24px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(10px);
  clip-path: polygon(0 0, calc(100% - 22px) 0, 100% 22px, 100% 100%, 0 100%);
}
.panel.center {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100vw - 28px));
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--cyan);
  letter-spacing: 0.42em;
  font-size: 12px;
}
.logo {
  margin: 0;
  font-size: clamp(46px, 8vw, 76px);
  line-height: 0.95;
  letter-spacing: 0.08em;
  background: linear-gradient(100deg, var(--cyan), #ffffff 42%, var(--magenta));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 16px rgba(61, 255, 242, 0.25));
}
.tag {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
}
.tracks { display: grid; gap: 8px; margin: 12px 0 4px; }
.track-card {
  text-align: left;
  border: 1px solid rgba(61, 255, 242, 0.28);
  background: rgba(0, 0, 0, 0.2);
  color: var(--ink);
  padding: 10px 12px;
}
.track-card b { display: block; letter-spacing: 0.12em; font-size: 15px; }
.track-card span { color: var(--muted); font-size: 12px; }
.track-card small { display: block; margin-top: 4px; color: var(--gold); font-size: 11px; letter-spacing: 0.04em; }
.track-card.selected {
  border-color: var(--magenta);
  background: linear-gradient(90deg, rgba(255, 45, 149, 0.16), rgba(61, 255, 242, 0.08));
}
.kicker {
  margin: 12px 0 0;
  color: var(--gold);
  letter-spacing: 0.28em;
  font-size: 11px;
}
.cars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 0; }
.car-card {
  text-align: left;
  border: 1px solid rgba(255, 209, 102, 0.28);
  background: rgba(0, 0, 0, 0.22);
  color: var(--ink);
  padding: 8px 8px 9px;
}
.car-card b { display: block; letter-spacing: 0.08em; font-size: 14px; }
.car-card span { color: var(--muted); font-size: 11px; }
.car-card .swatch { display: block; height: 6px; margin-bottom: 7px; }
.car-card[data-car="yan"] .swatch { background: linear-gradient(90deg, #f4f7ff, #3dfff2); }
.car-card[data-car="muhang"] .swatch { background: linear-gradient(90deg, #2a1848, #e8a15a); }
.car-card[data-car="zhiyuan"] .swatch { background: linear-gradient(90deg, #f3d7a1, #b388ff); }
.car-card.selected {
  border-color: var(--gold);
  background: linear-gradient(90deg, rgba(255, 209, 102, 0.16), rgba(61, 255, 242, 0.05));
}
.record-banner {
  margin: 4px 0 0;
  color: var(--gold);
  letter-spacing: 0.18em;
  font-size: 14px;
}
.features {
  display: grid;
  gap: 8px;
  margin: 14px 0;
  padding: 0;
  list-style: none;
}
.features li {
  padding-left: 14px;
  border-left: 2px solid var(--magenta);
  color: var(--ink);
  font-size: 14px;
}
.row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  padding: 12px 18px;
  letter-spacing: 0.12em;
  font-size: 14px;
}
.btn:hover, .btn:focus-visible { background: rgba(61, 255, 242, 0.12); outline: none; }
.btn.primary {
  background: linear-gradient(90deg, rgba(61, 255, 242, 0.2), rgba(255, 45, 149, 0.18));
  border-color: var(--cyan);
}
.btn.wide { width: 100%; margin-top: 8px; text-align: left; }
.fine { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 16px 0 0; }
h2 { margin: 0 0 12px; font-size: 28px; letter-spacing: 0.08em; }
.howto { margin: 0 0 8px; padding-left: 18px; color: var(--ink); line-height: 1.55; }
.howto strong { color: var(--gold); font-weight: 650; }

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: none;
  z-index: 4;
}
#hud.show { display: block; }
#hud button { pointer-events: auto; }

.pos {
  position: absolute;
  top: 18px;
  left: 18px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
}
.pos b { font-size: 64px; line-height: 0.8; letter-spacing: -0.04em; }
.pos span { color: var(--muted); margin-bottom: 6px; }
.pos small { display: block; color: var(--cyan); letter-spacing: 0.2em; font-size: 11px; }

.lapblock, .timeblock {
  position: absolute;
  top: 18px;
  text-align: right;
}
.lapblock { left: 50%; transform: translateX(-50%); text-align: center; }
.timeblock { right: 18px; }
.k { display: block; color: var(--muted); font-size: 11px; letter-spacing: 0.18em; }
.v { font-variant-numeric: tabular-nums; font-size: 22px; }
.lapblock .v { font-size: 28px; }

.speed {
  position: absolute;
  left: 18px;
  bottom: 22px;
}
.speed b {
  font-size: 64px;
  font-style: italic;
  letter-spacing: -0.04em;
  line-height: 0.85;
}
.speed span { color: var(--muted); letter-spacing: 0.14em; font-size: 12px; }

.nitro-wrap {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  width: min(420px, 62vw);
}
.nitro-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  letter-spacing: 0.22em;
  color: var(--gold);
  margin-bottom: 6px;
}
#nitro {
  height: 16px;
  border: 1px solid rgba(255, 209, 102, 0.7);
  background: rgba(0, 0, 0, 0.35);
  position: relative;
  overflow: hidden;
}
#nitro-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff2d95, #ffd166 55%, #3dfff2);
  box-shadow: 0 0 16px rgba(255, 209, 102, 0.45);
}
#nitro.ready { box-shadow: 0 0 18px rgba(61, 255, 242, 0.35); }
#nitro.burning #nitro-fill { filter: brightness(1.35); animation: burn 0.18s linear infinite; }
#nitro::before, #nitro::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(7, 10, 24, 0.85);
}
#nitro::before { left: 33.3%; }
#nitro::after { left: 66.6%; }
@keyframes burn { 50% { filter: brightness(1.8); } }

#minimap {
  position: absolute;
  right: 16px;
  bottom: 16px;
  border: 1px solid var(--line);
  background: rgba(5, 8, 18, 0.45);
  border-radius: 50%;
}

#callout, #hint, #wrong-way, #countdown {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  letter-spacing: 0.24em;
}
#callout {
  bottom: 78px;
  font-size: 28px;
  color: var(--gold);
  text-shadow: 0 0 16px rgba(255, 209, 102, 0.45);
  opacity: 0;
}
#callout.show { opacity: 1; }
#callout.is-drift { color: var(--cyan); text-shadow: 0 0 18px rgba(61, 255, 242, 0.65); }
#callout.is-mini { color: #fff6d0; text-shadow: 0 0 18px rgba(255, 230, 140, 0.7); }
#callout.is-nitro { color: #ffb15a; text-shadow: 0 0 22px rgba(255, 140, 40, 0.8); font-size: 34px; }
#hint {
  top: 28%;
  color: var(--ink);
  background: rgba(7, 10, 24, 0.7);
  border: 1px solid var(--line);
  padding: 10px 16px;
  display: none;
  font-size: 16px;
}
#hint.show { display: block; }
#wrong-way {
  top: 22%;
  color: var(--danger);
  display: none;
  font-size: 22px;
}
#wrong-way.show { display: block; }
#countdown {
  top: 32%;
  font-size: clamp(72px, 14vw, 140px);
  font-weight: 750;
  display: none;
  text-shadow: 0 0 24px rgba(61, 255, 242, 0.55);
}
#countdown.show { display: block; }

#replay-bar {
  position: fixed;
  left: 50%;
  bottom: max(16px, 2vh);
  transform: translateX(-50%);
  z-index: 6;
  width: min(520px, calc(100vw - 24px));
  padding: 12px 14px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  pointer-events: auto;
}
#replay-bar[hidden] { display: none; }
.replay-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  letter-spacing: 0.08em;
}
.replay-head b { color: var(--cyan); }
#replay-clock { font-variant-numeric: tabular-nums; }
#replay-bar .fine { margin: 6px 0 8px; }
body.is-replay #touch { display: none !important; }
body.is-replay #hud { display: none !important; }

.hud-actions {
  position: absolute;
  top: 18px;
  right: 18px;
  display: flex;
  gap: 8px;
}
.delta {
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  font-size: 15px;
}
.delta.ahead { color: var(--cyan); }
.delta.behind { color: var(--magenta); }
.delta.even { color: var(--gold); }
.timeblock { top: 64px; }
.hud-actions .btn { padding: 8px 10px; letter-spacing: 0.08em; font-size: 12px; }
.btn.is-muted { color: var(--muted); border-color: rgba(147, 164, 196, 0.4); }

#result-place {
  margin: 0;
  font-size: clamp(42px, 8vw, 68px);
  background: linear-gradient(90deg, var(--gold), white);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.stats { display: flex; gap: 22px; margin: 8px 0 14px; }
.stats b { font-variant-numeric: tabular-nums; font-size: 20px; }
#result-list { list-style: none; margin: 0 0 16px; padding: 0; }
#result-list li {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-variant-numeric: tabular-nums;
}
#result-list li.me { color: var(--cyan); }

#touch {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 6;
  pointer-events: none;
}
body.show-touch #touch { display: block; }
.pad {
  position: absolute;
  bottom: 18px;
  width: 92px;
  height: 92px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(8, 12, 28, 0.45);
  color: white;
  font-size: 22px;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}
.pad:active { background: rgba(61, 255, 242, 0.22); }
.pad.left { left: 18px; }
.pad.right { left: 122px; }
.pad.gas {
  right: 18px;
  width: 108px;
  height: 108px;
  border-color: var(--cyan);
}
.pad.brake { right: 138px; bottom: 28px; width: 78px; height: 78px; }
.pad.drift { right: 18px; bottom: 140px; width: 86px; }
.pad.nitro {
  right: 116px;
  bottom: 140px;
  width: 86px;
  border-color: var(--gold);
  color: var(--gold);
}
.pad.pause {
  top: 16px;
  right: 16px;
  bottom: auto;
  width: 64px;
  height: 42px;
  font-size: 14px;
}

body.is-nitro::after,
body.is-drift::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}
body.is-nitro::after {
  box-shadow: inset 0 0 160px rgba(255, 140, 40, 0.42);
}
body.is-drift::after {
  box-shadow: inset 0 0 120px rgba(61, 255, 242, 0.24);
}

#debug {
  position: fixed;
  left: 18px;
  top: 110px;
  z-index: 7;
  margin: 0;
  color: #b7ffcf;
  font: 12px/1.45 ui-monospace, monospace;
  white-space: pre;
  text-shadow: 0 1px 2px #000;
}

@media (max-width: 520px) {
  .cars { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .pos b, .speed b { font-size: 46px; }
  .timeblock { top: 58px; }
  .lapblock { top: 14px; }
  .nitro-wrap { bottom: 128px; width: min(420px, 86vw); }
  #minimap { width: 112px !important; height: 112px !important; }
  .speed { bottom: 128px; }
  #callout { bottom: 168px; }
}
