:root {
  --bg: #0a0c14;
  --panel: rgba(12, 14, 24, 0.88);
  --text: #f0f4ff;
  --muted: #9aa3b8;
  --accent: #a78bfa;
  --cyan: #22d3ee;
  --warm: #fbbf24;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: "DM Sans", system-ui, sans-serif;
  touch-action: none; user-select: none;
}
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.vignette {
  pointer-events: none; position: fixed; inset: 0; z-index: 4;
  background:
    radial-gradient(ellipse at 50% 40%, transparent 42%, rgba(0,0,0,0.5) 100%),
    linear-gradient(180deg, rgba(20,16,40,0.25) 0%, transparent 30%, transparent 70%, rgba(0,0,0,0.35) 100%);
}
.vignette.night {
  background:
    radial-gradient(ellipse at 50% 40%, transparent 38%, rgba(0,0,8,0.72) 100%),
    linear-gradient(180deg, rgba(10,14,40,0.45) 0%, transparent 35%, transparent 65%, rgba(0,0,0,0.5) 100%);
}

.hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; display: flex; flex-direction: column; }
.top {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(10px + var(--safe-t)) 12px 0; gap: 8px; flex-wrap: wrap;
}
.top-right { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.brand {
  pointer-events: auto; text-decoration: none; color: var(--text);
  font-size: 12px; font-weight: 700; padding: 8px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid rgba(255,255,255,0.1);
  backdrop-filter: blur(10px);
}
.brand span { color: var(--accent); }
.chip {
  padding: 7px 11px; border-radius: 999px; background: var(--panel);
  border: 1px solid rgba(255,255,255,0.1); font-size: 11px; color: var(--muted);
  font-weight: 600; backdrop-filter: blur(10px);
}
.chip strong { color: var(--cyan); }
.chip.btn {
  pointer-events: auto; cursor: pointer; color: var(--text);
  border-color: rgba(167,139,250,0.35); font: inherit; font-size: 11px; font-weight: 700;
}
.chip.btn:hover, .chip.btn.on { background: rgba(167,139,250,0.22); border-color: rgba(167,139,250,0.6); }

.race-bar {
  align-self: center; margin-top: 10px; pointer-events: none;
  display: flex; gap: 14px; align-items: center;
  padding: 8px 16px; border-radius: 14px;
  background: rgba(8,10,20,0.85); border: 1px solid rgba(251,191,36,0.4);
  font-size: 13px; color: var(--muted);
}
.race-bar strong { color: var(--warm); font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.race-bar.hidden { display: none; }

.hint {
  margin-top: auto; text-align: center; padding: 0 12px calc(12px + var(--safe-b));
  font-size: 11px; color: rgba(255,255,255,0.45); pointer-events: none;
}

.touch {
  display: none; pointer-events: none;
  position: fixed; left: 0; right: 0; bottom: calc(16px + var(--safe-b));
  z-index: 12; padding: 0 16px;
  justify-content: space-between; align-items: flex-end;
}
.touch.show { display: flex; pointer-events: none; }
.stick-zone {
  pointer-events: auto; width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12);
  position: relative;
}
.stick {
  width: 48px; height: 48px; border-radius: 50%;
  background: rgba(167,139,250,0.55); border: 2px solid rgba(255,255,255,0.4);
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
}
.pedal {
  pointer-events: auto; width: 72px; height: 72px; border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.15); background: rgba(248,113,113,0.25);
  color: #fff; font: 800 11px/1 "DM Sans", system-ui; margin-left: 8px;
}
.pedal.gas { background: rgba(52,211,153,0.28); }

.overlay {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(6,8,16,0.72); backdrop-filter: blur(10px);
}
.overlay.dim { background: rgba(6,8,16,0.85); }
.overlay.hidden { display: none; }
.card {
  width: min(440px, 100%);
  background: var(--panel); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 22px; padding: 28px 22px; text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}
.eyebrow {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--accent);
  border: 1px solid rgba(167,139,250,0.35); padding: 5px 10px; border-radius: 999px;
  margin-bottom: 12px;
}
h1 {
  font-family: "Instrument Serif", Georgia, serif; font-weight: 400;
  font-size: clamp(2rem, 7vw, 2.8rem); margin-bottom: 10px;
}
h1 em {
  font-style: italic;
  background: linear-gradient(135deg, var(--cyan), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
h2 { font-size: 1.15rem; margin-bottom: 6px; }
.lede { color: var(--muted); font-size: 0.95rem; line-height: 1.5; margin-bottom: 18px; }
.lede strong { color: var(--text); }
.hero-actions { display: flex; flex-direction: column; gap: 8px; }
.fine { margin-top: 14px; font-size: 11px; color: rgba(255,255,255,0.4); line-height: 1.4; }

.btn {
  appearance: none; border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06); color: var(--text);
  font: 700 14px "DM Sans", system-ui; padding: 14px 16px; border-radius: 14px;
  cursor: pointer; min-height: 48px;
}
.btn.primary {
  background: linear-gradient(135deg, #7c3aed, #22d3ee);
  border: none; color: #0a0c14;
  box-shadow: 0 10px 28px rgba(124,58,237,0.3);
}
.btn.sm { min-height: 40px; padding: 8px 12px; font-size: 12px; border-radius: 10px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.map-panel {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column;
  background: #0a0c14;
}
.map-panel.hidden { display: none; }
.map-head {
  flex-shrink: 0; padding: calc(10px + var(--safe-t)) 12px 10px;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.map-head h2 { font-size: 1rem; margin: 0; }
.map-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.map-tools input {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12);
  color: var(--text); border-radius: 10px; padding: 8px 12px; font: inherit; font-size: 13px;
  min-width: min(200px, 50vw);
}
#leaflet { flex: 1; min-height: 0; background: #111; touch-action: pan-x pan-y; }
.map-foot {
  flex-shrink: 0; padding: 10px 12px calc(12px + var(--safe-b));
  border-top: 1px solid rgba(255,255,255,0.08);
  background: rgba(8,10,18,0.95);
}
.mode-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tab {
  flex: 1; padding: 10px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.1);
  background: transparent; color: var(--muted); font: 700 12px "DM Sans", system-ui; cursor: pointer;
}
.tab.on { background: rgba(167,139,250,0.2); color: var(--text); border-color: rgba(167,139,250,0.45); }
.map-help { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.race-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.race-tools.hidden { display: none; }
.status { font-size: 11px; color: var(--cyan); margin-top: 8px; min-height: 16px; }

.spinner {
  width: 48px; height: 48px; margin: 0 auto 16px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--cyan); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: calc(20% + var(--safe-b));
  transform: translateX(-50%) translateY(12px);
  z-index: 60; padding: 10px 16px; border-radius: 12px;
  background: rgba(12,14,24,0.92); border: 1px solid rgba(34,211,238,0.4);
  font-size: 13px; font-weight: 700; opacity: 0; transition: 0.25s; pointer-events: none;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Garage */
.garage-card { width: min(520px, 100%); max-height: min(90vh, 720px); overflow: auto; text-align: left; }
.garage-card h2 { text-align: center; font-family: "Instrument Serif", Georgia, serif; font-weight: 400; font-size: 1.6rem; margin-bottom: 4px; }
.garage-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
@media (max-width: 480px) { .garage-grid { grid-template-columns: 1fr; } }
.car-card {
  pointer-events: auto; cursor: pointer; text-align: left;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  border-radius: 14px; padding: 12px;
  transition: border-color 0.15s, background 0.15s;
  color: var(--text); font: inherit;
}
.car-card:hover { border-color: rgba(167,139,250,0.45); }
.car-card.selected {
  border-color: rgba(34,211,238,0.7);
  background: rgba(34,211,238,0.1);
  box-shadow: 0 0 0 1px rgba(34,211,238,0.25);
}
.car-card .emoji { font-size: 1.5rem; line-height: 1; }
.car-card .name { font-weight: 800; font-size: 0.95rem; margin: 4px 0 2px; }
.car-card .tag { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.car-card .bars { display: flex; flex-direction: column; gap: 4px; }
.car-card .bar-row { display: flex; align-items: center; gap: 6px; font-size: 10px; color: var(--muted); }
.car-card .bar-row span { width: 52px; flex-shrink: 0; }
.car-card .bar {
  flex: 1; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.08); overflow: hidden;
}
.car-card .bar i {
  display: block; height: 100%; border-radius: 3px;
  background: linear-gradient(90deg, #7c3aed, #22d3ee);
}

/* Leaflet dark-ish */
.leaflet-container { background: #1a1f2e; font: inherit; }
.leaflet-control-attribution { font-size: 9px !important; }

/* Circular HUD Minimap (Bottom-Left) */
.minimap-container {
  position: fixed;
  left: 18px;
  bottom: calc(20px + var(--safe-b));
  z-index: 25;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.8), inset 0 0 20px rgba(0, 0, 0, 0.4);
  background: #0f172a;
  overflow: hidden;
  pointer-events: auto;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.minimap-container:hover {
  border-color: rgba(34, 211, 238, 0.7);
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.9), 0 0 15px rgba(34, 211, 238, 0.3);
}

#minimap-leaflet {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  pointer-events: none;
}
#minimap-leaflet .leaflet-control-container {
  display: none;
}

.minimap-badge {
  position: absolute;
  top: 10px;
  left: 8px;
  z-index: 40;
  background: linear-gradient(135deg, #22c55e, #15803d);
  color: #ffffff;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1.5px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.minimap-zoom {
  position: absolute;
  left: 10px;
  top: 42px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mini-btn {
  pointer-events: auto;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(15, 23, 42, 0.82);
  color: #fff;
  font: 700 13px/1 "DM Sans", sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  transition: background 0.15s, border-color 0.15s;
}
.mini-btn:hover {
  background: rgba(34, 211, 238, 0.35);
  border-color: rgba(34, 211, 238, 0.7);
}

.minimap-compass {
  position: absolute;
  left: 10px;
  bottom: 22px;
  z-index: 40;
  padding: 0;
}

.minimap-player-arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 35;
  width: 0;
  height: 0;
  /* Center via transform only (rotation applied in JS) */
  margin: 0;
  transform: translate(-50%, -50%) rotate(0deg);
  transform-origin: center center;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 16px solid #ffffff;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.9)) drop-shadow(0 0 6px rgba(34, 211, 238, 0.8));
  pointer-events: none;
}

.minimap-attrib {
  position: absolute;
  right: 18px;
  bottom: 8px;
  z-index: 40;
  font-size: 8px;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  font-weight: 500;
}

@media (max-width: 640px) {
  .minimap-container {
    width: 150px;
    height: 150px;
    left: 12px;
    bottom: calc(12px + var(--safe-b));
  }
  .minimap-badge {
    font-size: 10px;
    padding: 3px 8px;
    max-width: 110px;
  }
  /* When virtual stick is on, park minimap top-left so it doesn't cover controls */
  .minimap-container.minimap-touch-mode {
    top: calc(58px + var(--safe-t));
    bottom: auto;
    left: 10px;
    width: 118px;
    height: 118px;
    opacity: 0.92;
  }
  .minimap-container.minimap-touch-mode .minimap-zoom {
    top: 36px;
  }
  .minimap-container.minimap-touch-mode .minimap-badge {
    font-size: 9px;
    max-width: 90px;
    padding: 2px 7px;
  }
}

/* ---------------------------------------------------------------- radio -- */
.radio-card { max-width: 560px; width: 100%; }
.radio-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.radio-actions .btn { flex: 0 0 auto; }
.radio-vol { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.radio-vol label { font-size: 12px; opacity: .7; min-width: 54px; }
.radio-vol input[type=range] { flex: 1; accent-color: #22d3ee; }
.radio-list {
  max-height: 220px; overflow-y: auto; border-radius: 12px;
  border: 1px solid rgba(255,255,255,.09); background: rgba(0,0,0,.25);
  padding: 6px; margin-bottom: 12px;
}
.radio-row {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border-radius: 9px; font-size: 13px; cursor: pointer; transition: background .12s;
}
.radio-row:hover { background: rgba(255,255,255,.07); }
.radio-row.on { background: rgba(34,211,238,.16); color: #a5f3fc; font-weight: 600; }
.radio-row .tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: .1em;
  opacity: .5; margin-left: auto; white-space: nowrap;
}
.radio-empty { padding: 16px; text-align: center; font-size: 13px; opacity: .55; }
.radio-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 4px; }
body.radio-drag::after {
  content: 'Drop audio files to add them to the radio';
  position: fixed; inset: 18px; z-index: 90; border-radius: 20px;
  border: 2px dashed rgba(34,211,238,.75); background: rgba(6,10,20,.72);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 600; color: #a5f3fc; pointer-events: none;
}
