/* ============================================================================
   NEON VELOCITY — MODERN PERFORMANCE COCKPIT & DIGITAL CLUSTER (src/racer_hud.css)
   Author: Agent 3 — Frontend Specialist (UI/UX)
   Aesthetic: OEM High-Performance Automotive (Porsche / BMW M / Audi Sport Virtual Cockpit)
   Palette: Smoked Glass, Technical Slate, Crisp Polar White, Warning Amber, Crimson Redline
   ============================================================================ */

:root {
  --hud-white: #f8fafc;
  --hud-slate: #94a3b8;
  --hud-slate-dark: #475569;
  --hud-slate-darker: #1e293b;
  --hud-amber: #f59e0b;
  --hud-red: #ef4444;
  --hud-blue: #38bdf8;
  --hud-emerald: #10b981;
  
  --hud-glass-bg: rgba(13, 17, 23, 0.85);
  --hud-glass-bg-subtle: rgba(15, 23, 42, 0.65);
  --hud-glass-border: rgba(255, 255, 255, 0.12);
  --hud-glass-border-focus: rgba(255, 255, 255, 0.28);
  
  --hud-shadow: 0 12px 32px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.4);
  --hud-font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --hud-font-mono: 'DIN Alternate', 'Rajdhani', 'Roboto Mono', monospace;
}

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body, html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #0a0d12;
  font-family: var(--hud-font-sans);
  color: var(--hud-white);
}

/* Subtle Optical Windshield Vignette */
.cockpit-crt-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
  background: radial-gradient(circle at center, transparent 65%, rgba(0, 0, 0, 0.55) 100%);
  opacity: 0.8;
}

/* Master HUD Layer */
#neon-velocity-hud {
  position: absolute;
  top: 44px;
  left: 0;
  width: 100%;
  height: calc(100% - 44px);
  pointer-events: none;
  z-index: 40;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 20px;
  overflow: hidden;
}

/* Interactive elements inside HUD must accept pointer events */
#neon-velocity-hud button,
#neon-velocity-hud .interactive,
.mobile-touch-layer,
.mobile-touch-layer * {
  pointer-events: auto;
}

/* ----------------------------------------------------------------------------
   TOP BAR: REARVIEW MIRROR & PURSUIT / HEAT BANNER
   ---------------------------------------------------------------------------- */
.hud-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: 100%;
  position: relative;
}

/* Top Left: Heat Level & Status */
.hud-heat-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--hud-glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--hud-glass-border);
  border-left: 3px solid var(--hud-amber);
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: var(--hud-shadow);
  min-width: 270px;
  max-width: 320px;
  transition: border-color 0.3s ease;
}

.heat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.heat-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--hud-white);
  text-transform: uppercase;
}

.heat-val-tag {
  font-size: 10px;
  font-family: var(--hud-font-mono);
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid var(--hud-amber);
  padding: 1px 7px;
  border-radius: 4px;
  color: var(--hud-amber);
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* Wanted Stars */
.heat-stars-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.heat-star {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  fill: #334155;
  filter: grayscale(1) opacity(0.3);
  transition: all 0.25s ease;
}

.heat-star.active {
  fill: var(--hud-amber);
  filter: drop-shadow(0 0 6px rgba(245, 158, 11, 0.6)) opacity(1);
  transform: scale(1.1);
}

.heat-star.active.danger {
  fill: var(--hud-red);
  filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.7)) opacity(1);
  transform: scale(1.15);
}

.heat-meter-track {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 3px;
}

.heat-meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--hud-amber), var(--hud-red));
  border-radius: 2px;
  transition: width 0.2s linear;
}

.police-dispatch-feed {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--hud-slate);
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.dispatch-pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--hud-amber);
  animation: radarBlip 1.4s infinite ease-out;
}

@keyframes radarBlip {
  0% { transform: scale(0.9); opacity: 1; }
  50% { transform: scale(1.5); opacity: 0.4; }
  100% { transform: scale(0.9); opacity: 1; }
}

/* ----------------------------------------------------------------------------
   CENTER: AUTO-DIMMING REARVIEW MIRROR RIG
   ---------------------------------------------------------------------------- */
.rearview-mirror-rig {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.rearview-mount-arm {
  width: 12px;
  height: 14px;
  background: linear-gradient(180deg, #1e293b, #0f172a);
  border-radius: 2px 2px 0 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom: none;
}

.rearview-frame {
  position: relative;
  width: 280px;
  height: 74px;
  background: #0b0f15;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.8), inset 0 0 10px rgba(0, 0, 0, 0.85);
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.rearview-frame.siren-strobe-active-red {
  border-color: rgba(239, 68, 68, 0.8);
  box-shadow: 0 0 24px rgba(239, 68, 68, 0.5);
}

.rearview-frame.siren-strobe-active-blue {
  border-color: rgba(56, 189, 248, 0.8);
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.5);
}

#rearview-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.mirror-glass-glare {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.07) 0%, transparent 45%);
}

.mirror-hud-status {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-family: var(--hud-font-mono);
  color: var(--hud-slate);
  letter-spacing: 1px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  white-space: nowrap;
}

/* ----------------------------------------------------------------------------
   TOP RIGHT: STATS & CONTROLS PANEL
   ---------------------------------------------------------------------------- */
.hud-stats-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--hud-glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--hud-glass-border);
  padding: 8px 16px;
  border-radius: 8px;
  box-shadow: var(--hud-shadow);
}

.btn-audio-toggle {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--hud-glass-border);
  color: var(--hud-white);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-audio-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--hud-glass-border-focus);
}

.stat-credits-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.stat-credits-label {
  font-size: 9px;
  color: var(--hud-slate);
  font-weight: 700;
  letter-spacing: 1px;
}

.stat-credits-val {
  font-size: 15px;
  font-family: var(--hud-font-mono);
  color: var(--hud-emerald);
  font-weight: 800;
}

/* ----------------------------------------------------------------------------
   TAKEDOWN / NOTIFICATION BANNER (Burnout / NFS Style)
   ---------------------------------------------------------------------------- */
#hud-takedown-banner {
  position: absolute;
  top: 105px;
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--hud-glass-border);
  border-top: 3px solid var(--hud-amber);
  border-bottom: 3px solid var(--hud-amber);
  padding: 12px 32px;
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.8);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 60;
}

#hud-takedown-banner.active {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.takedown-title {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--hud-white);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.takedown-subtitle {
  font-size: 11px;
  font-family: var(--hud-font-mono);
  color: var(--hud-amber);
  letter-spacing: 1.5px;
  font-weight: 700;
  text-transform: uppercase;
}

/* ----------------------------------------------------------------------------
   BOTTOM CLUSTER: DIGITAL COCKPIT INSTRUMENTATION
   ---------------------------------------------------------------------------- */
.hud-bottom-cluster {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  width: 100%;
}

/* Left Pod: Tactical Radar / Minimap */
.hud-nav-pod {
  background: var(--hud-glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--hud-glass-border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--hud-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.radar-bezel {
  position: relative;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: rgba(11, 15, 22, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.9);
  overflow: hidden;
}

#radar-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.radar-warning-ticker {
  font-size: 9px;
  font-family: var(--hud-font-mono);
  color: var(--hud-slate);
  letter-spacing: 1px;
  margin-top: 6px;
  font-weight: 700;
}

/* Center Pod: Drift Dynamics & Score */
.hud-drift-dynamics {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--hud-glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--hud-glass-border);
  border-radius: 10px;
  padding: 8px 24px;
  box-shadow: var(--hud-shadow);
  opacity: 0.92;
  margin-bottom: 4px;
}

.drift-badge-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.drift-badge {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1.5px;
  color: var(--hud-white);
}

.drift-mult-tag {
  font-size: 10px;
  font-family: var(--hud-font-mono);
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid var(--hud-amber);
  color: var(--hud-amber);
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 700;
}

.drift-score-val {
  font-size: 22px;
  font-family: var(--hud-font-mono);
  color: var(--hud-white);
  font-weight: 900;
  letter-spacing: 1px;
}

.drift-angle-tag {
  font-size: 10px;
  font-family: var(--hud-font-mono);
  color: var(--hud-slate);
  letter-spacing: 0.5px;
}

/* Right Pod: Performance Tachometer & Digital Speedometer */
.hud-telemetry-pod {
  background: var(--hud-glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--hud-glass-border);
  border-radius: 12px;
  padding: 14px 18px;
  box-shadow: var(--hud-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 240px;
}

.dial-pod-container {
  position: relative;
  width: 220px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#gauge-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Center Digital Speedometer Readout */
.dial-digital-readout {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.gear-indicator-pill {
  font-size: 14px;
  font-weight: 900;
  font-family: var(--hud-font-mono);
  color: var(--hud-white);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
}

.digital-speed-val {
  font-size: 46px;
  font-weight: 900;
  font-family: var(--hud-font-mono);
  color: var(--hud-white);
  line-height: 1;
  letter-spacing: -1px;
}

.digital-speed-unit {
  font-size: 10px;
  color: var(--hud-slate);
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-top: 2px;
}

.digital-rpm-val {
  font-size: 10px;
  font-family: var(--hud-font-mono);
  color: var(--hud-slate);
  margin-top: 4px;
}

.redline-flasher {
  position: absolute;
  top: 14px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 1px;
  color: var(--hud-red);
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid var(--hud-red);
  padding: 2px 8px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.1s ease;
}

.redline-flasher.active {
  opacity: 1;
  animation: redlinePulse 0.25s infinite alternate;
}

@keyframes redlinePulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  100% { transform: scale(1.05); opacity: 1; }
}

/* Nitro Boost Charge Bar */
.nitro-cluster-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
}

.nitro-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--hud-slate);
}

.nitro-bar-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.nitro-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #0284c7, #38bdf8);
  border-radius: 3px;
  transition: width 0.1s linear;
}

/* ----------------------------------------------------------------------------
   ALERT STACK: banner (major lane) above toast (minor lane). Flow layout, so
   the two lanes can never overlap and nothing shifts when they appear.
   ---------------------------------------------------------------------------- */
.hud-alert-stack {
  position: absolute;
  top: var(--alert-top, 105px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100% - 24px);
  pointer-events: none;
  z-index: 60;
}

#hud-alert-stack #hud-takedown-banner {
  position: relative;
  top: auto;
  left: auto;
  transform: scale(0.92);
  max-width: 100%;
  text-align: center;
  min-height: 70px;
}

#hud-alert-stack #hud-takedown-banner.active {
  transform: scale(1);
}

.takedown-subtitle[hidden] { display: none; }

#hud-takedown-banner[data-kind="busted"]    { border-top-color: var(--hud-red); border-bottom-color: var(--hud-red); }
#hud-takedown-banner[data-kind="busted"] .takedown-subtitle { color: #fca5a5; }
#hud-takedown-banner[data-kind="takedown"]  { border-top-color: var(--hud-amber); border-bottom-color: var(--hud-amber); }
#hud-takedown-banner[data-kind="heat-up"]   { border-top-color: var(--hud-red); border-bottom-color: var(--hud-amber); }
#hud-takedown-banner[data-kind="heat-down"] { border-top-color: var(--hud-blue); border-bottom-color: var(--hud-blue); }
#hud-takedown-banner[data-kind="heat-down"] .takedown-subtitle { color: var(--hud-blue); }
#hud-takedown-banner[data-kind="evaded"]    { border-top-color: var(--hud-emerald); border-bottom-color: var(--hud-emerald); }
#hud-takedown-banner[data-kind="evaded"] .takedown-subtitle { color: #6ee7b7; }
#hud-takedown-banner[data-kind="chopper"]   { border-top-color: var(--hud-red); border-bottom-color: var(--hud-red); }
#hud-takedown-banner[data-kind="chopper"] .takedown-subtitle { color: #fca5a5; }

.hud-toast {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 34px;
  padding: 0 16px;
  border-radius: 17px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--hud-glass-border);
  border-left: 3px solid var(--hud-blue);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.6);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--hud-white);
  white-space: nowrap;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.hud-toast.active { opacity: 1; transform: translateY(0); }
.hud-toast[data-kind="near-miss"] { border-left-color: var(--hud-emerald); }
.hud-toast[data-kind="spike"]     { border-left-color: var(--hud-red); }
.hud-toast-amt { font-family: var(--hud-font-mono); color: var(--hud-emerald); }
.hud-toast-amt:empty { display: none; }

/* Heat: continuous meter */
.heat-meter-track { height: 6px; border-radius: 3px; }
.heat-meter-fill { border-radius: 3px; }
.heat-val-tag { font-size: 11px; white-space: nowrap; }
.hud-heat-panel[data-heat="4"], .hud-heat-panel[data-heat="5"] { border-left-color: var(--hud-red); }
.dispatch-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mirror-hud-status {
  font-size: 11px;
  letter-spacing: 0.3px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 4px;
  background: rgba(8, 12, 18, 0.7);
}
.radar-warning-ticker { font-size: 10px; }

/* ----------------------------------------------------------------------------
   OVERLAYS: pause menu and run summary
   ---------------------------------------------------------------------------- */
.hud-overlay {
  position: fixed;
  top: 44px;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(5, 8, 12, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
}
.hud-overlay[hidden] { display: none; }

.hud-card {
  width: min(100%, 420px);
  margin: auto;
  padding: 22px 22px 20px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.97);
  border: 1px solid var(--hud-glass-border-focus);
  border-top: 3px solid var(--hud-amber);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.8);
  text-align: center;
}
.hud-summary[data-reason="busted"] .hud-card { border-top-color: var(--hud-red); }
.hud-summary[data-reason="busted"] .hud-card-title { color: #fca5a5; }

.hud-card-title {
  margin: 0 0 4px;
  font-size: clamp(26px, 7vw, 36px);
  font-weight: 900;
  letter-spacing: 3px;
  color: var(--hud-white);
}
.hud-card-sub {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--hud-slate);
  letter-spacing: 0.5px;
}
.hud-card-sub:empty { display: none; }

.hud-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 14px;
}
.hud-summary-row {
  padding: 8px 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--hud-glass-border);
}
.hud-summary-row dt {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--hud-slate);
}
.hud-summary-row dd {
  margin: 2px 0 0;
  font-family: var(--hud-font-mono);
  font-size: 20px;
  font-weight: 900;
  color: var(--hud-white);
}
.hud-summary-row:nth-child(5) dd { color: var(--hud-emerald); }
.hud-summary-newbest {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--hud-amber);
}
.hud-summary-newbest[hidden] { display: none; }

.hud-card-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.hud-btn {
  flex: 1 1 110px;
  min-height: 48px;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--hud-glass-border-focus);
  background: rgba(255, 255, 255, 0.08);
  color: var(--hud-white);
  font: 800 14px/1 var(--hud-font-sans);
  letter-spacing: 1px;
  cursor: pointer;
  touch-action: manipulation;
}
.hud-btn:hover { background: rgba(255, 255, 255, 0.16); }
.hud-btn-primary {
  background: var(--hud-amber);
  border-color: var(--hud-amber);
  color: #111827;
}
.hud-btn-primary:hover { background: #fbbf24; }

/* Visible keyboard focus everywhere in the HUD */
.hud-btn:focus-visible,
.hud-pause-btn:focus-visible,
.btn-audio-toggle:focus-visible,
.mobile-touch-layer button:focus-visible {
  outline: 3px solid var(--hud-blue);
  outline-offset: 2px;
}

/* ----------------------------------------------------------------------------
   MOBILE & TOUCH ON-SCREEN CONTROLS
   Two separate zones (steering bottom-left, 2x2 pedal grid bottom-right).
   Grid layout: every button owns its own cell, nothing is pulled over a
   neighbour with negative margins.
   ---------------------------------------------------------------------------- */
:root {
  --steer: 68px;
  --round: 60px;
  --pedal-w: 72px;
  --gas-h: 120px;
  --brake-h: 96px;
  --tc-gap: 10px;
  --ctl-h: 208px;
}

.mobile-touch-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 60;
  display: none;
}
.mobile-touch-layer.active { display: block; }

#three-canvas { touch-action: none; }

/* Keep the instrument cluster above the controls */
#neon-velocity-hud:has(~ .mobile-touch-layer.active) {
  padding-bottom: calc(var(--ctl-h) + env(safe-area-inset-bottom));
}

.mobile-steering-zone {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  display: flex;
  gap: var(--tc-gap);
  pointer-events: none;
}

.mobile-steer-btn {
  width: var(--steer);
  height: var(--steer);
  flex: 0 0 auto;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 2px solid rgba(255, 255, 255, 0.28);
  color: var(--hud-white);
  font-size: 26px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  transition: transform 0.08s, background-color 0.08s, border-color 0.08s;
}

.mobile-steer-btn:active,
.mobile-steer-btn.pressed {
  background: rgba(255, 255, 255, 0.25);
  border-color: var(--hud-white);
  transform: scale(0.94);
}

.mobile-pedals-zone {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom));
  right: max(12px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: auto auto;
  grid-template-areas:
    "nos ebrake"
    "brake gas";
  gap: var(--tc-gap);
  align-items: end;
  justify-items: center;
  pointer-events: none;
}

.mobile-nitro-btn,
.mobile-ebrake-btn,
.mobile-pedal-brake,
.mobile-pedal-gas {
  margin: 0;
  touch-action: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.mobile-nitro-btn { grid-area: nos; }
.mobile-ebrake-btn { grid-area: ebrake; }
.mobile-pedal-brake { grid-area: brake; }
.mobile-pedal-gas { grid-area: gas; }

.mobile-ebrake-btn,
.mobile-nitro-btn {
  width: var(--round);
  height: var(--round);
  border-radius: 50%;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.08s, background-color 0.08s;
}

.mobile-ebrake-btn {
  background: rgba(40, 20, 20, 0.88);
  border: 2px solid rgba(239, 68, 68, 0.6);
  color: #fca5a5;
}
.mobile-ebrake-btn:active,
.mobile-ebrake-btn.pressed {
  background: rgba(239, 68, 68, 0.4);
  color: #fff;
  border-color: var(--hud-red);
  transform: scale(0.94);
}

.mobile-nitro-btn {
  background: rgba(14, 30, 48, 0.88);
  border: 2px solid rgba(56, 189, 248, 0.65);
  color: var(--hud-blue);
}
.mobile-nitro-btn:active,
.mobile-nitro-btn.pressed {
  background: rgba(56, 189, 248, 0.4);
  color: #fff;
  border-color: var(--hud-blue);
  transform: scale(0.94);
}

.mobile-pedal-brake,
.mobile-pedal-gas {
  width: var(--pedal-w);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 1px;
  position: relative;
  transition: transform 0.08s, background-color 0.08s, border-color 0.08s;
}

.mobile-pedal-brake {
  height: var(--brake-h);
  background: linear-gradient(180deg, #1e2430, #131720);
  border: 2px solid rgba(255, 255, 255, 0.25);
  color: #cbd5e1;
}
.mobile-pedal-brake:active,
.mobile-pedal-brake.pressed {
  background: linear-gradient(180deg, #374151, #1f2937);
  border-color: var(--hud-red);
  color: #fff;
  transform: translateY(4px);
}

.mobile-pedal-gas {
  height: var(--gas-h);
  background: linear-gradient(180deg, #1e293b, #0f172a);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: var(--hud-white);
}
.mobile-pedal-gas:active,
.mobile-pedal-gas.pressed {
  background: linear-gradient(180deg, #334155, #1e293b);
  border-color: var(--hud-white);
  transform: translateY(4px);
}

.pedal-ribs {
  position: absolute;
  top: 8px;
  width: 65%;
  height: 38%;
  border-top: 2px solid rgba(255, 255, 255, 0.18);
  border-bottom: 2px solid rgba(255, 255, 255, 0.18);
  background: repeating-linear-gradient(180deg, transparent, transparent 8px, rgba(255, 255, 255, 0.12) 8px, rgba(255, 255, 255, 0.12) 10px);
  pointer-events: none !important;
}
.mobile-pedal-gas span { position: relative; margin-top: 28px; }

/* Pause: bottom centre, between the two zones */
.hud-pause-btn {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.28);
  color: var(--hud-white);
  font: 900 18px/1 var(--hud-font-sans);
  letter-spacing: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}
.hud-pause-btn:active { background: rgba(255, 255, 255, 0.25); }
.mobile-touch-layer:not(.active) .hud-pause-btn { display: none; }

/* ----------------------------------------------------------------------------
   RESPONSIVE DESIGN RULES
   ---------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .mobile-touch-layer { display: block !important; }
  #neon-velocity-hud { padding-bottom: calc(var(--ctl-h) + env(safe-area-inset-bottom)); }

  /* Header: always a single line */
  body #arcade-bar { flex-wrap: nowrap; padding: 0 10px; gap: 8px; }
  body .arcade-title {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    letter-spacing: 0.8px;
  }
  body .arcade-links { flex: 0 0 auto; gap: 6px; }
  body .arcade-btn { white-space: nowrap; }
  body .arcade-links .arcade-btn:not(.active) { display: none; }

  .dial-pod-container { width: 180px; height: 180px; }
  .digital-speed-val { font-size: 38px; }
  .radar-bezel { width: 125px; height: 125px; }
  .rearview-frame { width: 210px; height: 58px; }
  .hud-heat-panel { min-width: 170px; padding: 6px 10px; }
  .nitro-header span:last-child { display: none; }
  .hud-telemetry-pod { min-width: 0; }
}

@media (max-width: 700px) {
  body .arcade-links { display: none; }
}

@media (max-width: 600px) {
  :root {
    --steer: 58px;
    --round: 56px;
    --pedal-w: 64px;
    --gas-h: 108px;
    --brake-h: 86px;
    --tc-gap: 8px;
    --ctl-h: 188px;
    --alert-top: 172px;
  }

  #neon-velocity-hud { padding: 8px 8px 0; padding-bottom: calc(var(--ctl-h) + env(safe-area-inset-bottom)); }

  /* Top: heat (left) + credits/buttons (right), mirror on its own row below */
  .hud-top-bar { flex-wrap: wrap; gap: 6px; }
  .hud-heat-panel { flex: 1 1 0; min-width: 0; max-width: none; gap: 4px; }
  .hud-stats-panel {
    flex: 0 0 auto;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    width: 156px;
    padding: 6px 8px;
  }
  .stat-credits-box { order: -1; flex: 0 0 100%; flex-direction: row; justify-content: space-between; align-items: baseline; }
  .stat-credits-val { font-size: 16px; }
  .btn-audio-toggle {
    flex: 1 1 0;
    min-height: 44px;
    justify-content: center;
    padding: 4px 6px;
    font-size: 11px;
  }
  .rearview-mirror-rig {
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    order: 3;
    flex: 0 0 100%;
  }
  .rearview-mount-arm { display: none; }
  .rearview-frame { width: min(240px, 100%); height: 50px; }

  /* Bottom: compact drift pill above the radar and gauge */
  .hud-bottom-cluster { flex-wrap: wrap; align-items: flex-end; }
  .hud-drift-dynamics {
    display: flex;
    order: -1;
    flex: 0 0 100%;
    max-width: 300px;
    margin: 0 auto 6px;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 2px 10px;
    padding: 4px 12px;
  }
  .hud-drift-dynamics .drift-badge { font-size: 10px; letter-spacing: 1px; }
  .hud-drift-dynamics .drift-score-val { font-size: 18px; }
  .hud-drift-dynamics .drift-angle-tag { font-size: 11px; }
  #g-force-tag, #chassis-attitude-tag { display: none; }

  .hud-nav-pod { padding: 8px; }
  .radar-bezel { width: 104px; height: 104px; }
  .hud-telemetry-pod { padding: 8px 10px; }
  .dial-pod-container { width: 144px; height: 144px; }
  .digital-speed-val { font-size: 32px; }
  .gear-indicator-pill { width: 22px; height: 22px; font-size: 12px; margin-bottom: 0; }
  .digital-rpm-val { display: none; }
  .redline-flasher { top: 6px; }
  .nitro-cluster-box { margin-top: 6px; }
  .nitro-header { white-space: nowrap; }

  .takedown-title { font-size: 16px; letter-spacing: 1px; }
  .takedown-subtitle { font-size: 11px; letter-spacing: 0.8px; }
  #hud-takedown-banner { padding: 10px 18px; }
  .hud-toast { font-size: 12px; padding: 0 12px; }
  .hud-summary-row dd { font-size: 17px; }
}

/* Short landscape phones: drop the secondary instruments */
@media (max-height: 520px) and (max-width: 950px) {
  :root { --ctl-h: 150px; --steer: 56px; --round: 46px; --pedal-w: 58px; --gas-h: 72px; --brake-h: 60px; --alert-top: 70px; }
  .hud-nav-pod, .hud-drift-dynamics, .dispatch-pulse, .police-dispatch-feed, .mirror-hud-status, .digital-rpm-val { display: none; }
  .rearview-frame { height: 36px; }
  .dial-pod-container { width: 110px; height: 110px; }
  .digital-speed-val { font-size: 24px; }
  .gear-indicator-pill { display: none; }
  .nitro-cluster-box { display: none; }
  .hud-card { padding: 12px 16px; }
  .hud-summary-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}

.mobile-ebrake-btn,
.mobile-ebrake-btn span,
.mobile-nitro-btn { white-space: nowrap; }
.mobile-ebrake-btn { font-size: 10px; letter-spacing: 0; }

/* Short portrait phones (e.g. 360x640): trim secondary info so the drift pill still fits */
@media (max-width: 600px) and (max-height: 700px) {
  :root { --ctl-h: 176px; --alert-top: 140px; --gas-h: 98px; --brake-h: 78px; }
  .police-dispatch-feed, .radar-warning-ticker { display: none; }
  .rearview-frame { height: 40px; }
  .radar-bezel { width: 88px; height: 88px; }
  .dial-pod-container { width: 120px; height: 120px; }
  .digital-speed-val { font-size: 26px; }
  .heat-stars-row .heat-star { width: 16px; height: 16px; }
}
