:root {
  --asphalt: #1a1f2e;
  --dash: #0d1118;
  --accent: #ff3b4a;
  --gold: #f5c542;
  --cyan: #3de0ff;
  --ok: #3dff9a;
  --panel: rgba(8, 12, 20, 0.92);
  --text: #f2f5ff;
  --muted: #9aa3b8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--text);
  font-family: "Exo 2", system-ui, sans-serif;
  touch-action: none;
  user-select: none;
}

#app { position: relative; width: 100%; height: 100%; }

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#mirror-canvas {
  position: absolute;
  top: 2.2%;
  left: 50%;
  transform: translateX(-50%);
  width: min(28vw, 320px);
  height: min(12vh, 110px);
  z-index: 20;
  border-radius: 8px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

#app.playing #mirror-canvas { opacity: 1; }

/* ---- Cockpit ---- */
#cockpit {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 15;
  opacity: 0;
  transition: opacity 0.4s;
}
#app.playing #cockpit { opacity: 1; }

.windshield-tint {
  position: absolute;
  inset: 0 0 28% 0;
  background: linear-gradient(
    180deg,
    rgba(120, 180, 255, 0.08) 0%,
    transparent 40%,
    rgba(0, 0, 0, 0.15) 100%
  );
}

.a-pillar {
  position: absolute;
  top: 0;
  bottom: 26%;
  width: 7%;
  background: linear-gradient(90deg, #0a0c10, #1c222c 40%, #0a0c10);
  box-shadow: inset 0 0 30px #000;
}
.a-pillar.left {
  left: 0;
  clip-path: polygon(0 0, 100% 8%, 70% 100%, 0 100%);
}
.a-pillar.right {
  right: 0;
  clip-path: polygon(0 8%, 100% 0, 100% 100%, 30% 100%);
}

#rearview {
  position: absolute;
  top: 1.5%;
  left: 50%;
  transform: translateX(-50%);
  width: min(30vw, 340px);
  z-index: 21;
}

.mirror-frame {
  border: 3px solid #2a303c;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  padding: 4px 8px 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55), inset 0 0 0 1px #555;
}

.mirror-label {
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--muted);
  text-align: center;
}

#police-distance {
  font-family: Orbitron, monospace;
  font-size: clamp(11px, 1.5vw, 14px);
  text-align: center;
  color: var(--cyan);
  margin-top: 2px;
}
#police-distance.far { color: var(--ok); }
#police-distance.close { color: var(--accent); }
#police-distance.gone { color: var(--muted); }

#dashboard {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 28%;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(40, 50, 70, 0.5), transparent 55%),
    linear-gradient(180deg, #151a24 0%, #0a0d12 55%, #05070b 100%);
  border-top: 3px solid #2c3444;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4%;
  padding-bottom: 2.5%;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.6);
}

.dash-glow {
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  opacity: 0.5;
}

.gauge {
  width: 90px;
  text-align: center;
  margin-bottom: 1.5%;
  z-index: 2;
}
.gauge.right { margin-left: 2%; }
.gauge-label {
  font-size: 10px;
  letter-spacing: 0.15em;
  color: var(--muted);
}
#speedo, #level-num {
  font-family: Orbitron, monospace;
  font-size: clamp(22px, 3.5vw, 36px);
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(245, 197, 66, 0.45);
}
#level-num { color: var(--cyan); text-shadow: 0 0 12px rgba(61, 224, 255, 0.4); }

#steering-wheel {
  position: relative;
  width: min(22vw, 180px);
  height: min(22vw, 180px);
  margin-bottom: -2%;
  transform: rotate(0deg);
  transition: transform 0.05s linear;
  z-index: 2;
}
.wheel-rim {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 14px solid #1a1e26;
  box-shadow:
    inset 0 0 0 4px #3a4252,
    0 0 0 3px #0c0e12,
    0 10px 25px rgba(0, 0, 0, 0.5);
  background: radial-gradient(circle at 40% 35%, #2a3140, #12151c 70%);
}
.wheel-hub {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28%;
  height: 28%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff5a3c, #8b1a1a);
  box-shadow: 0 0 12px rgba(255, 60, 40, 0.5);
  border: 3px solid #222;
}
.wheel-spoke {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 42%;
  height: 10px;
  margin-top: -5px;
  background: linear-gradient(90deg, #2a303c, #4a5568);
  border-radius: 4px;
  transform-origin: left center;
}
.wheel-spoke.s1 { transform: rotate(-90deg); }
.wheel-spoke.s2 { transform: rotate(30deg); }
.wheel-spoke.s3 { transform: rotate(150deg); }

/* ---- HUD ---- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 25;
  opacity: 0;
}
#app.playing #hud { opacity: 1; }

#timer-box {
  position: absolute;
  top: 16%;
  left: 2%;
  background: var(--panel);
  border: 1px solid #2a3344;
  border-left: 4px solid var(--gold);
  padding: 10px 14px;
  border-radius: 8px;
  min-width: 140px;
}
.hud-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--muted);
}
#timer {
  font-family: Orbitron, monospace;
  font-size: 28px;
  font-weight: 800;
  color: var(--gold);
}
#timer-goal {
  font-size: 14px;
  color: var(--muted);
  margin-left: 4px;
}

#hits-box {
  position: absolute;
  top: 16%;
  right: 2%;
  background: var(--panel);
  border: 1px solid #2a3344;
  border-right: 4px solid var(--accent);
  padding: 10px 14px;
  border-radius: 8px;
}
#hit-pips {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
#hit-pips i {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #553;
  background: #221;
}
#hit-pips i.on {
  background: var(--accent);
  border-color: #ff8a90;
  box-shadow: 0 0 10px var(--accent);
}

#status-box {
  position: absolute;
  top: 16%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: min(14vh, 120px);
  font-family: Orbitron, monospace;
  font-size: 12px;
  letter-spacing: 0.2em;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 59, 74, 0.2);
  border: 1px solid var(--accent);
  color: #ffb0b6;
}
#status-box.free {
  background: rgba(61, 255, 154, 0.15);
  border-color: var(--ok);
  color: var(--ok);
}
#status-box.advantage {
  background: rgba(245, 197, 66, 0.2);
  border-color: var(--gold);
  color: var(--gold);
}

#street-label {
  position: absolute;
  bottom: 30%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.75);
  text-shadow: 0 2px 8px #000;
  background: rgba(0, 0, 0, 0.35);
  padding: 4px 12px;
  border-radius: 6px;
}

#radar-wrap {
  position: absolute;
  right: 2%;
  bottom: 30%;
  width: 140px;
  height: 140px;
  z-index: 26;
}
#radar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 3px solid #2a3344;
  background: rgba(6, 14, 12, 0.85);
  box-shadow: 0 0 0 2px #1a5, inset 0 0 30px rgba(0, 255, 120, 0.12), 0 8px 24px rgba(0,0,0,0.5);
  display: block;
}
.radar-label {
  display: block;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: #6f9;
  margin-top: 4px;
  font-family: Orbitron, monospace;
}

#status-box.cruise {
  background: rgba(61, 224, 255, 0.15);
  border-color: var(--cyan);
  color: var(--cyan);
}

#turbo-box {
  position: absolute;
  top: 16%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: calc(min(14vh, 120px) + 36px);
  background: var(--panel);
  border: 1px solid #2a3344;
  border-bottom: 3px solid #f0a020;
  padding: 8px 16px;
  border-radius: 8px;
  text-align: center;
  min-width: 110px;
}
#turbo-status {
  font-family: Orbitron, monospace;
  font-size: 16px;
  font-weight: 800;
  color: #f0a020;
}
#turbo-box.active {
  border-bottom-color: #ff3b4a;
  box-shadow: 0 0 16px rgba(255, 59, 74, 0.45);
}
#turbo-box.active #turbo-status { color: #ff6b78; }
#turbo-box.cooldown #turbo-status { color: var(--muted); }

#mp-box {
  position: absolute;
  top: 16%;
  left: 2%;
  margin-top: 88px;
  background: var(--panel);
  border: 1px solid #2a3344;
  border-left: 4px solid #f0c020;
  padding: 8px 12px;
  border-radius: 8px;
  min-width: 120px;
}
#mp-status {
  font-family: Orbitron, monospace;
  font-size: 13px;
  font-weight: 700;
  color: #f0c020;
}

.place-label {
  color: var(--gold) !important;
  font-weight: 700;
}
.login-label {
  display: block;
  text-align: left;
  margin: 12px 0 6px;
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.login-input {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid #3a4558;
  background: #0c1018;
  color: #fff;
  font-size: 18px;
  font-family: "Exo 2", system-ui, sans-serif;
}
.login-input:focus {
  outline: 2px solid var(--cyan);
  border-color: var(--cyan);
}
.login-error {
  min-height: 1.2em;
  color: #ff6b78;
  font-size: 14px;
  margin: 8px 0;
}

.control-mode-fieldset {
  border: 1px solid #2a3344;
  border-radius: 10px;
  padding: 10px 12px 12px;
  margin: 14px 0 8px;
  text-align: left;
}
.control-mode-fieldset legend {
  padding: 0 6px;
  margin-bottom: 0;
}
.control-mode-opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 8px 0;
  font-size: 15px;
  line-height: 1.35;
  cursor: pointer;
  color: var(--text);
}
.control-mode-opt input {
  margin-top: 3px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.hud-gear {
  position: absolute;
  top: calc(16% + 72px);
  right: 2%;
  z-index: 26;
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid #2a3344;
  background: var(--panel);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: none;
}
#app.playing .hud-gear { display: grid; place-items: center; }
.hud-gear:active { border-color: var(--cyan); color: var(--cyan); }

.settings-card {
  max-width: 420px;
}
#settings-panel {
  z-index: 55;
}

@media (pointer: coarse), (max-width: 900px) {
  .hud-gear {
    top: calc(18% + 72px);
    width: 48px;
    height: 48px;
  }
}

#app.control-gyro .touch-steer {
  display: none !important;
}
#app.control-gyro .touch-row {
  justify-content: center;
  gap: 6%;
}

#gyro-debug {
  position: absolute;
  top: 2%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 28;
  pointer-events: none;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.02em;
  color: #9ef0c0;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid #2a5540;
  border-radius: 6px;
  padding: 4px 10px;
  white-space: nowrap;
  max-width: 96vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

#infraction-banner,
#bonus-banner,
#message-banner {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  font-family: Orbitron, monospace;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 14px 28px;
  border-radius: 10px;
  text-align: center;
  pointer-events: none;
  animation: popIn 0.35s ease;
}
#infraction-banner {
  background: rgba(180, 0, 20, 0.92);
  border: 2px solid #ff4d5e;
  color: #fff;
  font-size: clamp(16px, 3vw, 26px);
  box-shadow: 0 0 40px rgba(255, 40, 60, 0.55);
}
#bonus-banner {
  background: linear-gradient(135deg, rgba(20, 80, 60, 0.95), rgba(10, 40, 80, 0.95));
  border: 2px solid var(--ok);
  color: var(--gold);
  font-size: clamp(18px, 3.2vw, 28px);
  box-shadow: 0 0 40px rgba(61, 255, 154, 0.4);
}
#message-banner {
  background: var(--panel);
  border: 1px solid #445;
  font-size: 16px;
}
.hidden { display: none !important; }

#flash-overlay {
  position: absolute;
  inset: 0;
  z-index: 45;
  pointer-events: none;
  background: rgba(220, 0, 30, 0.55);
  opacity: 0;
}
#flash-overlay.flashing {
  animation: infractionFlash 0.9s ease-in-out 1;
}
@keyframes infractionFlash {
  0%, 100% { opacity: 0; }
  10%, 25% { opacity: 1; }
  35% { opacity: 0; }
  45%, 60% { opacity: 1; }
  70% { opacity: 0; }
  80%, 92% { opacity: 1; }
}
@keyframes popIn {
  from { opacity: 0; transform: translateX(-50%) scale(0.85); }
  to { opacity: 1; transform: translateX(-50%) scale(1); }
}

/* ---- Overlays ---- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255, 60, 80, 0.18), transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(40, 120, 255, 0.2), transparent 45%),
    rgba(4, 6, 12, 0.88);
  backdrop-filter: blur(6px);
}

.menu-card {
  width: min(92vw, 440px);
  background: var(--panel);
  border: 1px solid #2e384c;
  border-radius: 18px;
  padding: 28px 26px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  text-align: center;
}
.menu-card.wide { width: min(94vw, 560px); }

.eyebrow {
  font-size: 12px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--cyan);
  margin-bottom: 8px;
}
h1 {
  font-family: Orbitron, monospace;
  font-size: clamp(32px, 8vw, 48px);
  font-weight: 800;
  background: linear-gradient(120deg, #fff 20%, var(--accent) 55%, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 10px;
}
h2 {
  font-family: Orbitron, monospace;
  margin-bottom: 12px;
  font-size: 24px;
}
.tagline {
  color: var(--muted);
  margin-bottom: 16px;
  line-height: 1.45;
}
.tips {
  text-align: left;
  list-style: none;
  margin: 0 0 20px;
  color: #c5cddc;
  font-size: 14px;
}
.tips li {
  padding: 8px 0 8px 14px;
  border-left: 3px solid var(--accent);
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.03);
}
.hint { color: var(--muted); font-size: 13px; margin-bottom: 16px; }

.btn {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 12px 16px;
  border: 1px solid #3a455c;
  border-radius: 10px;
  background: #1a2230;
  color: var(--text);
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s;
}
.btn:hover { transform: translateY(-1px); background: #243044; }
.btn.primary {
  background: linear-gradient(135deg, #e6283a, #ff6b3d);
  border-color: transparent;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger {
  background: #3a1520;
  border-color: var(--accent);
  color: #ffb0b6;
}
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

.binds { text-align: left; margin-bottom: 16px; }
.bind-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  border: 1px solid #2a3344;
}
.bind-row.listening {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold);
}
.bind-name { font-weight: 600; color: #f2f5ff; }
.bind-key {
  font-family: Orbitron, monospace;
  font-size: 12px;
  padding: 6px 10px;
  background: #0c1018;
  border-radius: 6px;
  border: 1px solid #667;
  min-width: 140px;
  text-align: center;
  cursor: pointer;
  color: #ffffff;
}

/* Touch — tablet / smartphone */
#touch {
  position: absolute;
  bottom: 28%;
  left: 0;
  right: 0;
  z-index: 30;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 0 2% 1%;
  pointer-events: none;
  gap: 10px;
}
#touch .touch-row {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: flex-end;
  gap: 2%;
  pointer-events: none;
}
#touch .touch-btn {
  pointer-events: auto;
  width: 20vw;
  max-width: 100px;
  height: 20vw;
  max-height: 100px;
  border-radius: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(10, 14, 22, 0.62);
  color: #fff;
  font-weight: 800;
  font-size: clamp(14px, 4vw, 20px);
  backdrop-filter: blur(4px);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}
#touch .touch-turbo {
  width: min(46vw, 220px);
  max-width: 220px;
  height: auto;
  min-height: 56px;
  padding: 12px 18px;
  border-radius: 16px;
  border: 3px solid #f0a020;
  background: linear-gradient(180deg, rgba(240, 160, 32, 0.55), rgba(180, 80, 20, 0.7));
  color: #fff8e8;
  font-family: Orbitron, monospace;
  font-size: clamp(18px, 5vw, 26px);
  letter-spacing: 0.12em;
  box-shadow: 0 0 18px rgba(240, 160, 32, 0.45);
}
#touch .touch-turbo.ready {
  opacity: 1;
}
#touch .touch-turbo.on-cooldown,
#touch .touch-turbo:disabled {
  opacity: 0.45;
  border-color: #666;
  background: rgba(40, 40, 44, 0.7);
  box-shadow: none;
}
#touch .touch-turbo.firing,
#touch .touch-turbo.active {
  border-color: #ff3b4a;
  background: linear-gradient(180deg, rgba(255, 80, 90, 0.7), rgba(180, 30, 40, 0.85));
  box-shadow: 0 0 22px rgba(255, 59, 74, 0.55);
}
#touch .touch-btn:active,
#touch .touch-btn.active {
  background: rgba(255, 59, 74, 0.5);
  border-color: var(--accent);
}
#touch .touch-turbo:active,
#touch .touch-turbo.active {
  background: linear-gradient(180deg, rgba(255, 80, 90, 0.7), rgba(180, 30, 40, 0.85));
  border-color: #ff3b4a;
}

@media (pointer: fine) {
  #touch { display: none !important; }
}
@media (pointer: coarse), (max-width: 900px) {
  #app.playing #touch:not(.hidden) { display: flex; }
  .gauge { width: 70px; }
  #timer-box, #hits-box { top: 18%; }
  #radar-wrap { width: 120px; height: 120px; }
}

@media (max-height: 500px) {
  #dashboard { height: 32%; }
  #street-label { bottom: 34%; }
  #radar-wrap { width: 110px; height: 110px; bottom: 34%; }
}
