:root {
  --bg: #10182e;
  --green: #2bff88;
  --green-dim: #18c46a;
  --green-glow: rgba(43, 255, 136, 0.55);
  --ink: #001a0f;
  --font: "SF Mono", "Roboto Mono", ui-monospace, "Courier New", monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--green);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  cursor: default;
}

.webgl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  outline: none;
  display: block;
}

/* ---------- Loader ---------- */
.loader {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 60%, #1c2b50 0%, var(--bg) 70%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  z-index: 40;
  transition: opacity 0.8s ease;
}
.loader.hidden { opacity: 0; pointer-events: none; }
.loader__logo { font-size: 34px; letter-spacing: 8px; font-weight: 700; text-shadow: 0 0 18px var(--green-glow); }
.loader__logo span { color: #eafff3; }
.loader__bar { width: 240px; height: 3px; background: rgba(43,255,136,0.15); border-radius: 4px; overflow: hidden; }
.loader__fill { height: 100%; width: 0%; background: var(--green); box-shadow: 0 0 14px var(--green-glow); transition: width 0.25s ease; }
.loader__hint { font-size: 11px; letter-spacing: 3px; opacity: 0.6; text-transform: uppercase; }

/* ---------- Intro ---------- */
.intro {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 30;
  text-align: center;
  background: radial-gradient(circle at 50% 50%, rgba(40,55,100,0.35) 0%, rgba(16,24,46,0.85) 80%);
  backdrop-filter: blur(2px);
}
.intro.show { display: flex; animation: fade 0.6s ease; }
.intro h1 { font-size: clamp(40px, 9vw, 96px); letter-spacing: 10px; text-shadow: 0 0 30px var(--green-glow); }
.intro h1 span { color: #eafff3; }
.intro p { font-size: 13px; letter-spacing: 3px; opacity: 0.75; }
.intro button {
  margin-top: 14px;
  padding: 14px 34px;
  background: transparent;
  border: 1px solid var(--green);
  color: var(--green);
  font-family: var(--font);
  font-size: 13px;
  letter-spacing: 4px;
  cursor: pointer;
  border-radius: 2px;
  box-shadow: 0 0 18px rgba(43,255,136,0.25), inset 0 0 18px rgba(43,255,136,0.08);
  transition: all 0.25s ease;
}
.intro button:hover { background: var(--green); color: var(--ink); box-shadow: 0 0 32px var(--green-glow); }

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  top: 22px;
  left: 22px;
  z-index: 20;
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}
.hud.show { opacity: 1; }
.hud__speed { font-size: 40px; font-weight: 700; line-height: 1; text-shadow: 0 0 16px var(--green-glow); }
.hud__speed small { font-size: 12px; margin-left: 6px; opacity: 0.6; letter-spacing: 2px; }
.hud__places { margin-top: 8px; font-size: 11px; letter-spacing: 3px; opacity: 0.75; }
.hud__places b { color: #eafff3; }
.hud__coords {
  margin-top: 6px; font-size: 10px; letter-spacing: 2px; opacity: 0.6;
  font-variant-numeric: tabular-nums;
}
.hud__coords b { color: var(--green); }

/* ---------- Lap timer ---------- */
.laptimer {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  text-align: center;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.laptimer.show { opacity: 1; }
.laptimer__label { font-size: 11px; letter-spacing: 4px; color: var(--green-dim); }
.laptimer__cur {
  font-size: 38px; font-weight: 700; line-height: 1.1; color: #eafff3;
  text-shadow: 0 0 18px var(--green-glow);
}
.laptimer__rows {
  display: flex; gap: 22px; justify-content: center;
  font-size: 12px; letter-spacing: 2px; opacity: 0.85; margin-top: 4px;
}
.laptimer__rows b { color: var(--green); margin-left: 4px; }

.lap-hint {
  position: fixed;
  top: 34px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  font-size: 13px; letter-spacing: 2px; color: var(--green);
  background: rgba(14,22,42,0.6);
  border: 1px solid var(--green);
  border-radius: 6px;
  padding: 8px 14px;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.lap-hint.show { opacity: 0.9; }
.lap-hint kbd {
  border: 1px solid var(--green); border-radius: 3px; padding: 0 5px; color: #eafff3;
}

/* ---------- Controls hint ---------- */
.controls-hint {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  font-size: 11px;
  letter-spacing: 2px;
  opacity: 0;
  transition: opacity 0.6s ease;
  color: rgba(234,255,243,0.7);
}
.controls-hint.show { opacity: 0.85; }
.controls-hint kbd {
  display: inline-block;
  border: 1px solid rgba(43,255,136,0.4);
  border-radius: 3px;
  padding: 1px 7px;
  margin: 0 1px;
  color: var(--green);
  box-shadow: 0 0 8px rgba(43,255,136,0.15);
}

/* ---------- Minimap ---------- */
.minimap {
  position: fixed;
  top: 22px;
  right: 22px;
  z-index: 20;
  width: 160px;
  height: 160px;
  border: 1px solid rgba(43,255,136,0.35);
  border-radius: 6px;
  background: rgba(10,16,34,0.55);
  box-shadow: 0 0 22px rgba(43,255,136,0.12), inset 0 0 22px rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity 0.6s ease;
}
.minimap.show { opacity: 0.92; }

/* ---------- Pit-stop panel (dashboard "race replay" card — every stop).
   Layout from the ideas/ reference; palette tuned to the site's dusk-navy +
   neon-green theme (no heavy glow). Left border is tinted per-stop in JS. */
.stop-panel {
  position: fixed;
  bottom: 26px;
  right: 26px;
  z-index: 25;
  width: min(430px, 92vw);
  padding-bottom: 14px;
  font-family: "Avenir Next", "Segoe UI", -apple-system, system-ui, sans-serif;
  background: linear-gradient(180deg, rgba(26, 38, 70, 0.96), rgba(14, 22, 42, 0.96));
  border: 1px solid rgba(120, 160, 255, 0.28);
  border-left: 3px solid var(--green);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(4, 8, 18, 0.55);
  color: #eef3fa;
  overflow: hidden;
  transform: translateY(140%);
  opacity: 0;
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.45s ease;
}
.stop-panel.show { transform: translateY(0); opacity: 1; }
.stop-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 12px 10px 18px;
  background: rgba(34, 50, 88, 0.85);
  border-bottom: 1px solid rgba(120, 160, 255, 0.18);
  font-size: 16px;
  font-weight: 800;
  font-style: italic;
  letter-spacing: 1.5px;
  color: #f4f8ff;
}
.stop-panel__close {
  flex: none;
  width: 24px;
  height: 24px;
  padding: 0;
  background: none;
  border: 1px solid rgba(120, 160, 255, 0.35);
  border-radius: 6px;
  color: rgba(238, 243, 250, 0.75);
  font-family: var(--font);
  font-style: normal;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.stop-panel__close:hover { color: var(--green); border-color: var(--green); }
.stop-panel__grid {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 10px;
  padding: 12px 14px 0;
}
.stop-panel__card { border-radius: 10px; padding: 12px; }
.stop-panel__card--name { background: rgba(16, 26, 50, 0.9); border: 1px solid rgba(130, 160, 210, 0.3); }
.stop-panel__tag {
  font-family: var(--font);
  font-size: 9px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #8fb7d9;
}
.stop-panel__name {
  margin: 3px 0 0;
  font-size: 17px;
  line-height: 1.15;
  font-weight: 800;
  font-style: italic;
  color: #ffffff;
}
.stop-panel__sub {
  margin-top: 4px;
  font-family: var(--font);
  font-size: 9.5px;
  color: rgba(238, 243, 250, 0.6);
}
.stop-panel__image { margin-top: 10px; }
.stop-panel__image svg,
.stop-panel__image img { display: block; width: 100%; height: auto; border-radius: 6px; }
.stop-panel__card--points {
  background: rgba(30, 44, 78, 0.75);
  border: 1px solid rgba(130, 160, 210, 0.22);
}
.stop-panel__card-title { margin-bottom: 8px; font-size: 12.5px; font-weight: 800; font-style: italic; color: #f4f8ff; }
.stop-panel__points {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 11px;
  line-height: 1.45;
  font-weight: 500;
  color: rgba(226, 236, 248, 0.9);
}
.stop-panel__points li { position: relative; padding-left: 16px; }
.stop-panel__points li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}
.stop-panel__card--tech {
  margin: 10px 14px 0;
  background: rgba(22, 34, 62, 0.85);
  border: 1px solid rgba(130, 160, 210, 0.25);
}
.stop-panel__card--tech.hidden { display: none; }
.stop-panel__techrow { display: flex; flex-wrap: wrap; gap: 14px; }
.tech-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tech-item__logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  color: #ffffff;
}
.tech-item__label { font-family: var(--font); font-size: 9px; color: rgba(238, 243, 250, 0.78); }
.stop-panel__link {
  display: inline-block;
  margin: 12px 18px 0;
  font-family: var(--font);
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--green);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}
.stop-panel__link:hover { border-color: var(--green); }
.stop-panel__link.hidden { display: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ── On-screen touch controls ── */
.touchpad {
  position: fixed;
  inset: auto 0 0 0;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: none;                 /* shown on touch / small screens below */
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 22px;
  pointer-events: none;          /* only the buttons capture input */
  z-index: 22;                   /* above canvas, below intro(30)/loader(40) */
}
.touchpad.show { display: flex; }

/* analog joystick */
.joystick {
  position: relative;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  border: 1px solid var(--green);
  background: rgba(14, 22, 42, 0.45);
  backdrop-filter: blur(4px);
  box-shadow: 0 0 18px rgba(43, 255, 136, 0.2), inset 0 0 22px rgba(43, 255, 136, 0.08);
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: grid;
  place-items: center;
}
.joystick__ring {
  position: absolute;
  width: 60%;
  height: 60%;
  border-radius: 50%;
  border: 1px dashed rgba(43, 255, 136, 0.3);
  pointer-events: none;
}
.joystick__thumb {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: rgba(43, 255, 136, 0.18);
  border: 1px solid var(--green);
  box-shadow: 0 0 20px var(--green-glow), inset 0 0 12px rgba(43, 255, 136, 0.25);
  pointer-events: none;
  will-change: transform;
  transition: transform 0.06s ease-out;
}
.joystick.active .joystick__thumb { background: rgba(43, 255, 136, 0.32); transition: none; }

.tbtn {
  border: 1px solid var(--green);
  background: rgba(14, 22, 42, 0.55);
  color: var(--green);
  line-height: 1;
  display: grid;
  place-items: center;
  backdrop-filter: blur(4px);
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  transition: background 0.08s ease, box-shadow 0.08s ease;
}
.tbtn--brake {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  font-size: 15px;
  letter-spacing: 1px;
  font-weight: 700;
  border-color: #ff3b3b;
  color: #ff7a7a;
  box-shadow: 0 0 16px rgba(255, 59, 59, 0.3);
}
.tbtn--brake.active { background: #ff3b3b; color: #190303; box-shadow: 0 0 30px rgba(255, 59, 59, 0.6); }

/* brake + lap stack on the right of the pad */
.tbtn-cluster {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  pointer-events: none;          /* buttons re-enable their own input */
}
.tbtn--lap {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  font-size: 12px;
  letter-spacing: 1px;
  font-weight: 700;
  border-color: var(--green);
  color: var(--green);
  box-shadow: 0 0 14px rgba(43, 255, 136, 0.25);
  /* only appears while the car is at the start/finish line */
  opacity: 0;
  transform: scale(0.5);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.tbtn--lap.show { opacity: 1; transform: none; pointer-events: auto; }
.tbtn--lap.armed { animation: lap-pulse 1.2s ease-in-out infinite; }
.tbtn--lap.active { background: var(--green); color: var(--ink); box-shadow: 0 0 26px var(--green-glow); }
@keyframes lap-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(43, 255, 136, 0.25); }
  50% { box-shadow: 0 0 26px var(--green-glow); }
}

/* Show the pad on touch-primary devices regardless of width… */
@media (hover: none) and (pointer: coarse) {
  .touchpad { display: flex; }
  .stop-panel {
    top: 144px;
    right: 12px;
    bottom: auto;
    width: min(300px, 72vw);
    max-height: 56vh;
    overflow: auto;
    transform: translateX(125%);
  }
  .stop-panel.show { transform: translateX(0); }
  .stop-panel__grid { grid-template-columns: 1fr; }
  .stop-panel__header { font-size: 14px; padding: 10px 10px 9px 14px; }
  .stop-panel__name { font-size: 15px; }
}

@media (max-width: 600px) {
  .minimap { width: 110px; height: 110px; }
  .hud__speed { font-size: 30px; }
  .controls-hint { display: none; }
  .touchpad { display: flex; }
  .stop-panel {
    top: 132px;
    right: 10px;
    bottom: auto;
    width: min(280px, 76vw);
    max-height: 52vh;
    overflow: auto;
    transform: translateX(125%);
  }
  .stop-panel.show { transform: translateX(0); }
  .stop-panel__grid { grid-template-columns: 1fr; }
  .stop-panel__header { font-size: 13px; padding: 9px 9px 8px 12px; }
  .stop-panel__name { font-size: 14px; }
}
