:root {
  --ink: #e8eef2;
  --dim: #9aa8b2;
  --accent: #ff6b4a;
  --accent2: #f2c14e;
  --panel: rgba(10, 14, 18, 0.62);
  --edge: rgba(255, 255, 255, 0.10);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0a0e12;
  color: var(--ink);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ------------------------------------------------------------------ HUD */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  font-size: 13px;
  user-select: none;
}

.panel {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 12px;
  padding: 10px 13px;
  backdrop-filter: blur(9px) saturate(1.2);
  -webkit-backdrop-filter: blur(9px) saturate(1.2);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.tl { top: 16px; left: 16px; min-width: 178px; }
.tr { top: 16px; right: 16px; padding: 9px; }
.br { right: 16px; bottom: 16px; padding: 6px; }

.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  line-height: 1.65;
}

.k {
  color: var(--dim);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  font-weight: 600;
}

.v { font-weight: 650; font-size: 14px; }
.mono { font-family: var(--mono); font-size: 13.5px; letter-spacing: -0.01em; }

#gatebar {
  margin-top: 8px;
  height: 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.10);
  overflow: hidden;
}
#gatebar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  transition: width 0.18s ease-out;
}

#minimap {
  width: 168px;
  height: 168px;
  display: block;
  border-radius: 8px;
  background:
    radial-gradient(120% 120% at 30% 20%, rgba(80, 96, 70, 0.30), rgba(8, 12, 14, 0.55));
}

#backend {
  margin-top: 7px;
  text-align: center;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  color: #7ee0a8;
  font-weight: 700;
}
#backend.warn { color: var(--accent2); }

.cluster { position: relative; width: 230px; height: 150px; }
#gauge { width: 230px; height: 150px; display: block; }

.readout {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 16px;
  text-align: center;
  pointer-events: none;
}
.speed {
  font-size: 40px;
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.02em;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.6);
}
.speed small {
  font-size: 12px;
  color: var(--dim);
  margin-left: 3px;
  font-weight: 600;
}
.gear {
  margin-top: 2px;
  font-family: var(--mono);
  font-size: 15px;
  color: var(--accent2);
  font-weight: 700;
}

/* -------------------------------------------------------------- messages */
#toast {
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translate(-50%, -8px);
  padding: 10px 22px;
  border-radius: 999px;
  background: rgba(10, 14, 18, 0.72);
  border: 1px solid var(--edge);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.02em;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  backdrop-filter: blur(8px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#wrongway, #offroad {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.16em;
  opacity: 0;
  transition: opacity 0.18s;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
}
#wrongway { color: #ff4d4d; }
#offroad { top: 36%; font-size: 15px; color: var(--accent2); letter-spacing: 0.22em; }
#wrongway.on, #offroad.on { opacity: 1; }

.keys {
  position: absolute;
  left: 16px;
  bottom: 16px;
  max-width: 46vw;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(10, 14, 18, 0.5);
  border: 1px solid var(--edge);
  color: var(--dim);
  font-size: 11.5px;
  line-height: 1.9;
  transition: opacity 0.3s;
}
.keys b {
  display: inline-block;
  min-width: 17px;
  padding: 1px 4px;
  margin: 0 1px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid var(--edge);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 10.5px;
  text-align: center;
}
.keys.boost { color: var(--accent2); }
.keys.paused { color: var(--accent); }

/* --------------------------------------------------------------- results */
#result {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -46%) scale(0.97);
  width: min(420px, 90vw);
  padding: 22px 24px;
  border-radius: 16px;
  background: rgba(9, 13, 17, 0.92);
  border: 1px solid var(--edge);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
#result.show { opacity: 1; transform: translate(-50%, -50%) scale(1); pointer-events: auto; }
#result h2 { margin: 0 0 14px; font-size: 22px; letter-spacing: 0.01em; }
#result table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 13px; }
#result td { padding: 5px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
#result td:first-child { color: var(--dim); font-family: inherit; }
#result td:last-child { text-align: right; font-weight: 600; }

button {
  margin-top: 16px;
  width: 100%;
  padding: 11px 18px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: linear-gradient(180deg, #ff7a58, #e04a2c);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }

/* --------------------------------------------------------------- loading */
#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(90% 90% at 50% 15%, #1d2a33 0%, #0a0e12 60%, #070a0d 100%);
  z-index: 10;
  transition: opacity 0.5s;
}
#loading.done { opacity: 0; pointer-events: none; }

.loadbox { text-align: center; width: min(440px, 86vw); }
.loadbox h1 {
  margin: 0;
  font-size: clamp(38px, 8vw, 64px);
  letter-spacing: 0.12em;
  font-weight: 800;
  background: linear-gradient(180deg, #fff, #ffb08e);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.loadbox .sub {
  margin: 6px 0 22px;
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.track {
  height: 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.10);
  overflow: hidden;
}
#loading-bar {
  height: 100%;
  width: 2%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  transition: width 0.35s ease-out;
}
#loading-status {
  margin: 12px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--dim);
  min-height: 16px;
}
#loading-status.error { color: #ff6b6b; }

#start {
  margin-top: 22px;
  display: none;
}
#start.show { display: block; }

@media (max-width: 720px) {
  .keys { display: none; }
  .br { transform: scale(0.82); transform-origin: bottom right; }
  .tr { transform: scale(0.82); transform-origin: top right; }
}
