/* Neon Drift — synthwave time trial. Layout is HUD + touch pad over a full-bleed canvas. */

:root {
  --pink: #ff2e97;
  --cyan: #22e9ff;
  --violet: #a855ff;
  --ink: #07041a;
  --ink-2: #0b0620;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --hud-font: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas, "Roboto Mono", monospace;
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: #fff;
  font-family: var(--ui-font);

  /* kill every gesture the browser would otherwise steal from the game */
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* --------------------------------------------------------------- HUD */

#hud {
  position: fixed;
  top: calc(var(--safe-t) + 10px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(10, 5, 30, 0.55);
  border: 1px solid rgba(168, 85, 255, 0.35);
  box-shadow: 0 0 24px rgba(120, 40, 200, 0.35), inset 0 0 20px rgba(80, 20, 160, 0.25);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
  z-index: 10;
}

#hud .stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 84px;
  padding: 2px 10px;
}

#hud .stat + .stat { border-left: 1px solid rgba(168, 85, 255, 0.25); }

#hud .label {
  font-size: 9px;
  letter-spacing: 0.18em;
  font-weight: 700;
  color: rgba(214, 190, 255, 0.75);
  margin-bottom: 2px;
}

#hud .value {
  font-family: var(--hud-font);
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--cyan);
  text-shadow: 0 0 10px rgba(34, 233, 255, 0.75);
}

#hud .primary { min-width: 132px; }
#hud .primary .value { font-size: 30px; }

#hud .stat:last-child .value {
  color: var(--pink);
  text-shadow: 0 0 10px rgba(255, 46, 151, 0.7);
}

/* best-lap celebration pulse */
#hud .stat:last-child.flash .value { animation: bestPulse 1.1s ease-out 1; }
@keyframes bestPulse {
  0%   { transform: scale(1);    filter: brightness(1); }
  25%  { transform: scale(1.22); filter: brightness(2.1); }
  100% { transform: scale(1);    filter: brightness(1); }
}

/* -------------------------------------------------- drift + lap flashes */

#driftFlash {
  position: fixed;
  top: 34%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  font-family: var(--hud-font);
  font-size: clamp(28px, 6vw, 58px);
  font-weight: 800;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  color: #fff;
  text-shadow: 0 0 12px var(--pink), 0 0 34px var(--pink), 0 0 70px rgba(255, 46, 151, 0.6);
  opacity: 0;
  transition: opacity 140ms linear, transform 140ms ease-out;
  pointer-events: none;
  z-index: 9;
}
#driftFlash.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }

#lapSplash {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 250ms ease-out;
  pointer-events: none;
  z-index: 11;
}
#lapSplash.on { opacity: 1; }
#lapSplashLabel {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: var(--violet);
  text-shadow: 0 0 14px rgba(168, 85, 255, 0.9);
}
#lapSplashTime {
  font-family: var(--hud-font);
  font-size: clamp(34px, 7vw, 62px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 0 14px var(--cyan), 0 0 40px rgba(34, 233, 255, 0.7);
}
#lapSplash.best #lapSplashLabel { color: var(--pink); text-shadow: 0 0 14px var(--pink); }
#lapSplash.best #lapSplashTime { text-shadow: 0 0 14px var(--pink), 0 0 44px rgba(255, 46, 151, 0.8); }

/* ------------------------------------------------------- start prompt */

#startPrompt {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: radial-gradient(ellipse at center, rgba(10, 4, 32, 0.35) 0%, rgba(7, 4, 26, 0.8) 100%);
  transition: opacity 400ms ease-out;
  pointer-events: none;
  z-index: 12;
}
#startPrompt.gone { opacity: 0; }

#startPrompt .title {
  font-size: clamp(38px, 9vw, 86px);
  font-weight: 900;
  letter-spacing: 0.14em;
  text-indent: 0.14em;
  background: linear-gradient(180deg, #fff 0%, var(--cyan) 45%, var(--pink) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(255, 46, 151, 0.55)) drop-shadow(0 0 40px rgba(34, 233, 255, 0.35));
}
#startPrompt .sub {
  font-family: var(--hud-font);
  font-size: clamp(11px, 2.4vw, 16px);
  letter-spacing: 0.24em;
  text-indent: 0.24em;
  color: rgba(220, 200, 255, 0.85);
  animation: blink 1.6s ease-in-out infinite;
}

/* car picker — big tap targets, ring lights up in the car's own accent */
#carPick {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 6px 0 2px;
  pointer-events: auto;
}
.carChip {
  --chip-accent: #fff;
  min-height: 46px;
  padding: 10px 20px;
  border-radius: 12px;
  font-family: var(--hud-font);
  font-size: clamp(12px, 2.6vw, 16px);
  font-weight: 800;
  letter-spacing: 0.16em;
  color: rgba(220, 205, 255, 0.7);
  background: rgba(14, 7, 38, 0.6);
  border: 2px solid rgba(168, 85, 255, 0.3);
  cursor: pointer;
  transition: transform 80ms ease-out, border-color 120ms linear,
              color 120ms linear, box-shadow 120ms linear;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.carChip:active { transform: scale(0.94); }
.carChip.sel {
  color: #fff;
  border-color: var(--chip-accent);
  box-shadow: 0 0 20px -2px var(--chip-accent), inset 0 0 16px -6px var(--chip-accent);
  text-shadow: 0 0 10px var(--chip-accent);
}
@keyframes blink { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

/* ------------------------------------------------------ touch controls
   One steering stick (bottom-left) + one DRIFT button (bottom-right).
   The car drives itself forward — kids only steer and drift. */

#touch {
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none;
}
#touch[hidden] { display: none; }

#stick {
  position: absolute;
  left: calc(var(--safe-l) + 22px);
  bottom: calc(var(--safe-b) + 22px);
  width: 148px;
  height: 148px;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;

  background: radial-gradient(circle at 50% 50%, rgba(34, 233, 255, 0.08), rgba(18, 8, 44, 0.55));
  border: 2px solid rgba(34, 233, 255, 0.4);
  box-shadow: 0 0 22px rgba(34, 233, 255, 0.18), inset 0 0 26px rgba(34, 233, 255, 0.08);
}

#stickKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 70px;
  height: 70px;
  margin: -35px 0 0 -35px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, rgba(120, 245, 255, 0.95), rgba(34, 233, 255, 0.55));
  border: 2px solid rgba(180, 250, 255, 0.85);
  box-shadow: 0 0 24px rgba(34, 233, 255, 0.55);
  will-change: transform;
  transition: transform 60ms ease-out;
}
#stick.dragging #stickKnob { transition: none; }

.tbtn {
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;

  position: absolute;
  right: calc(var(--safe-r) + 22px);
  bottom: calc(var(--safe-b) + 30px);

  display: flex;
  align-items: center;
  justify-content: center;

  width: 128px;
  height: 128px;
  border-radius: 50%;

  background: rgba(18, 8, 44, 0.5);
  border: 2px solid rgba(255, 46, 151, 0.55);
  box-shadow: 0 0 18px rgba(255, 46, 151, 0.22), inset 0 0 18px rgba(255, 46, 151, 0.1);
  color: rgba(255, 130, 195, 0.95);

  font-family: var(--hud-font);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.14em;

  transition: transform 70ms ease-out, background 70ms linear, box-shadow 70ms linear;
}

.tbtn.active {
  transform: scale(0.93);
  background: rgba(255, 46, 151, 0.32);
  box-shadow: 0 0 38px rgba(255, 46, 151, 0.7), inset 0 0 26px rgba(255, 46, 151, 0.35);
}

/* small phones / short landscape windows: shrink so the controls never eat the track */
@media (max-height: 460px) {
  #stick { width: 116px; height: 116px; left: calc(var(--safe-l) + 14px); bottom: calc(var(--safe-b) + 14px); }
  #stickKnob { width: 56px; height: 56px; margin: -28px 0 0 -28px; }
  .tbtn { width: 104px; height: 104px; right: calc(var(--safe-r) + 16px); bottom: calc(var(--safe-b) + 18px); font-size: 14px; }
  #hud .primary .value { font-size: 24px; }
  #hud .value { font-size: 17px; }
}
