:root {
  --ink: #f2f5f3;
  --muted: #9fb3a6;
  --panel: rgba(12, 18, 14, 0.62);
  --line: rgba(255, 255, 255, 0.08);
  --accent: #7dfba1;
  --warn: #ffd166;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #101812;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
}

#game::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 90% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.45) 100%);
}

/* ---------------------------------------------------------------- HUD */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.panel {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.panel .label {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel .value {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.05;
}

.panel .value i {
  font-size: 12px;
  font-style: normal;
  font-weight: 600;
  color: var(--muted);
}

.panel .sub {
  font-size: 11px;
  color: var(--muted);
}

.panel .sub b { color: var(--ink); font-weight: 600; }

.mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.panel-lap { top: clamp(12px, 2vw, 24px); left: clamp(12px, 2vw, 24px); }
.panel-time {
  top: clamp(12px, 2vw, 24px);
  right: clamp(12px, 2vw, 24px);
  align-items: flex-end;
  text-align: right;
}
.panel-speed { left: clamp(12px, 2vw, 24px); bottom: clamp(12px, 2vw, 24px); }
.panel-speed .value b { font-size: 34px; }

.panel-speed .bar {
  width: 122px;
  height: 5px;
  margin-top: 7px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

#speedBar {
  width: 0%;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #5ee08a, var(--warn) 66%, #ff5d5d);
}

#minimap {
  position: absolute;
  right: clamp(12px, 2vw, 24px);
  bottom: clamp(12px, 2vw, 24px);
  width: 170px;
  height: 150px;
  background: rgba(12, 18, 14, 0.55);
  border: 1px solid var(--line);
  border-radius: 14px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

/* --------------------------------------------------------- countdown */
.center-message {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(80px, 17vw, 190px);
  font-weight: 900;
  letter-spacing: -0.05em;
  color: #fff;
  text-shadow: 0 16px 50px rgba(0, 0, 0, 0.65);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.16s ease;
}

.center-message.show { opacity: 1; }
.center-message.go { color: var(--accent); }

@keyframes pop {
  0% { transform: scale(0.72); opacity: 0.2; }
  55% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  font-size: 11px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  white-space: nowrap;
  transition: opacity 0.8s ease;
}

.hint.hide { opacity: 0; }

/* ------------------------------------------------------------ result */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 10, 8, 0.62);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.overlay.hidden { display: none; }

.card {
  width: min(440px, 100%);
  padding: 26px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(24, 34, 28, 0.97), rgba(14, 20, 16, 0.97));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

.card h1 {
  margin: 0 0 6px;
  font-size: 34px;
  letter-spacing: 0.05em;
}

.card p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13px;
}

.rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
}

.row {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 14px;
  text-align: left;
}

.row.you {
  background: rgba(255, 209, 102, 0.16);
  border: 1px solid rgba(255, 209, 102, 0.35);
}

.row .rank { color: var(--muted); font-weight: 700; }
.row .who { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.row .dot { width: 9px; height: 9px; border-radius: 99px; display: inline-block; }
.row .tm {
  color: #c8d6cd;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
}

#restartBtn {
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #0c1a10;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.08s ease;
}

#restartBtn span {
  margin-left: 6px;
  font-size: 11px;
  opacity: 0.5;
}

#restartBtn:hover { background: #a4ffbd; }
#restartBtn:active { transform: scale(0.99); }

/* ------------------------------------------------------------- touch */
.touch {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
}

.touch-group {
  position: absolute;
  bottom: clamp(16px, 4vw, 40px);
  display: flex;
  gap: 12px;
  pointer-events: auto;
}

.touch-group:first-child { left: clamp(16px, 4vw, 40px); }
.touch-group:last-child { right: clamp(16px, 4vw, 40px); }

.tbtn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  touch-action: none;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.06s ease;
}

.tbtn:active { transform: scale(0.94); background: rgba(255, 255, 255, 0.26); }

.tbtn-gas {
  background: rgba(94, 224, 138, 0.22);
  border-color: rgba(94, 224, 138, 0.5);
}

@media (hover: none), (pointer: coarse) {
  .touch { display: block; }
  .hint { display: none; }
  #minimap { display: none; }
  .panel-speed { bottom: 108px; }
}

@media (max-width: 720px) {
  .panel { padding: 8px 10px; border-radius: 12px; }
  .panel .value { font-size: 19px; }
  .panel .sub { font-size: 10px; }
  .panel-speed .value b { font-size: 26px; }
  .panel-speed .bar { width: 84px; }
  .card { padding: 20px; }
  .card h1 { font-size: 27px; }
  .tbtn { width: 60px; height: 60px; }
}
