/* Daily Driver Racing — UI overlay (DOM, not WebGL). Our own clean look. */
:root {
  --bg: #0b0e12;
  --panel: rgba(16, 20, 26, 0.72);
  --panel-border: rgba(255, 255, 255, 0.10);
  --text: #e8ecf1;
  --text-dim: #9aa7b5;
  --accent: #ffb547;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

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

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); }

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

#ui { position: absolute; inset: 0; pointer-events: none; display: flex; flex-direction: column; }
#ui button, #ui .panel { pointer-events: auto; }

#title { padding: 18px 22px; align-self: flex-start; }
#title h1 { font-size: 22px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
#title .subtitle { font-size: 12px; color: var(--text-dim); letter-spacing: 0.12em; text-transform: uppercase; }

#specs {
  position: absolute; left: 22px; bottom: 86px; width: 300px; max-width: 42vw;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px;
  padding: 14px 16px; backdrop-filter: blur(8px);
}
#specs h2 { font-size: 17px; font-weight: 600; color: var(--accent); margin-bottom: 10px; }
#specs dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; }
#specs dt { color: var(--text-dim); }
#specs dd { text-align: right; font-variant-numeric: tabular-nums; }
.driver-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--panel-border);
  font-size: 13px;
}
.driver-label { color: var(--text-dim); }
.driver-controls { display: flex; align-items: center; gap: 8px; }
#driver-name, #map-name, #sound-name { font-weight: 600; color: var(--text); min-width: 96px; text-align: center; }
#sound-name { cursor: pointer; user-select: none; }
#map-name { max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.driver-btn {
  width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06); color: var(--text); font-size: 10px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.driver-btn:hover { border-color: var(--accent); color: var(--accent); }

#car-nav {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 22px;
  display: flex; align-items: center; gap: 16px; white-space: nowrap;
}
.nav-btn {
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--panel-border);
  background: var(--panel); color: var(--text); font-size: 18px; cursor: pointer;
  backdrop-filter: blur(8px);
}
.nav-btn:hover { border-color: var(--accent); color: var(--accent); }
.drive-btn {
  padding: 12px 22px; border-radius: 24px; border: 1px solid var(--accent);
  background: var(--accent); color: #14181e; font-size: 15px; font-weight: 700;
  letter-spacing: 0.12em; cursor: pointer;
}
.drive-btn:hover { filter: brightness(1.12); }
#app.drive #specs, #app.drive #car-nav, #app.drive #title, #app.drive #help { display: none; }
#car-dots { display: flex; gap: 8px; }
#car-dots .dot { width: 9px; height: 9px; border-radius: 50%; background: rgba(255,255,255,0.25); transition: background 0.2s, transform 0.2s; }
#car-dots .dot.active { background: var(--accent); transform: scale(1.25); }

#help {
  position: absolute; right: 22px; bottom: 24px; font-size: 12px; color: var(--text-dim);
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 8px; padding: 6px 10px;
  max-width: calc(50vw - 220px); line-height: 1.4;
}

#loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 14px; letter-spacing: 0.1em; color: var(--text-dim); background: var(--bg);
  transition: opacity 0.4s;
}
#loading.done { opacity: 0; pointer-events: none; }

/* Driving HUD */
#hud { position: absolute; inset: 0; pointer-events: none; }
.hud-right {
  position: absolute; right: 20px; bottom: 20px; text-align: right;
  background: rgba(14, 18, 24, 0.78); border: 1px solid var(--panel-border); border-radius: 10px;
  padding: 10px 14px; min-width: 150px;
}
.hud-gear { font-size: 15px; color: var(--accent); font-weight: 700; letter-spacing: 0.1em; }
.hud-speed { font-size: 44px; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.hud-unit { font-size: 14px; color: var(--text-dim); margin-left: 6px; font-weight: 400; }
.hud-rpm { height: 6px; border-radius: 3px; background: rgba(255,255,255,0.12); overflow: hidden; margin-top: 6px; }
.hud-rpm-fill { height: 100%; width: 100%; transform: scaleX(0); transform-origin: left center; will-change: transform; background: linear-gradient(90deg, #6fd3a0, var(--accent)); }
.hud-rpm-fill.red { background: #ff5a4e; }
.hud-hint {
  position: absolute; left: 22px; bottom: 24px; font-size: 12px; color: var(--text-dim);
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 8px; padding: 6px 10px;
}

@media (max-width: 1440px) {
  #help {
    top: 62px;
    bottom: auto;
    right: 22px;
    max-width: calc(100vw - 360px);
    text-align: right;
  }
}

@media (max-width: 700px) {
  #specs { width: auto; right: 22px; bottom: 84px; max-width: none; }
  #specs dl { font-size: 12px; }
  #car-nav { gap: 10px; }
  #help { display: none; }
  .hud-hint { display: none; }
}

/* crash: Game Over */
#crash-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(120, 0, 0, 0.25), rgba(0, 0, 0, 0.55));
  z-index: 30; pointer-events: none; animation: crash-in 0.25s ease-out;
}
#crash-overlay .crash-box {
  background: rgba(12, 14, 18, 0.88); border: 1px solid rgba(255, 80, 70, 0.6); border-radius: 12px;
  padding: 22px 34px; text-align: center; color: #fff; max-width: min(90vw, 520px);
}
#crash-overlay h2 { font-size: 34px; letter-spacing: 0.12em; color: #ff5a4e; margin-bottom: 8px; }
#crash-overlay p { font-size: 15px; color: #e8e8e8; }
#crash-overlay .crash-keys { margin-top: 12px; font-size: 13px; color: #aab; }
@keyframes crash-in { from { background: rgba(255, 255, 255, 0.9); } }

/* GTA-style radar, right side above the speedometer */
/* ---- chase mode ---- */
.chase-mode { font-size: 12px; color: #ffb547; letter-spacing: 0.04em; margin-top: 6px; min-height: 14px; text-align: right; }
#race-hud {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 13; pointer-events: none;
  text-align: center; color: #fff; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7); font-family: system-ui, sans-serif;
}
#race-hud .race-main { font-size: 28px; font-weight: 800; letter-spacing: 0.06em; }
#race-hud .race-sub { font-size: 14px; opacity: 0.85; letter-spacing: 0.08em; margin-top: 2px; }
#race-hud .race-pin { width: 240px; height: 10px; margin: 8px auto 0; border-radius: 5px; background: rgba(0, 0, 0, 0.55); overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.4); }
#race-hud .race-pin > div { height: 100%; width: 0; background: linear-gradient(90deg, #3d7bff, #ff3b3b); }
#race-banner {
  position: absolute; top: 96px; left: 50%; transform: translateX(-50%); z-index: 13; pointer-events: none;
  font: 800 22px system-ui, sans-serif; color: #ffcc33; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
  opacity: 0; transition: opacity 0.3s;
}
#race-banner.on { opacity: 1; }
#race-count {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center; z-index: 14; pointer-events: none;
  font: 900 140px system-ui, sans-serif; color: #fff; text-shadow: 0 6px 24px rgba(0, 0, 0, 0.7);
}
#race-count.on { display: flex; }
#race-count.go { color: #4cff7a; }
#race-result { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 20; background: rgba(0, 0, 0, 0.45); }
#race-result .race-box { background: rgba(14, 17, 22, 0.94); border-radius: 12px; padding: 26px 34px; color: #e8ecef; min-width: 420px; font-family: system-ui, sans-serif; }
#race-result .race-box h2 { margin: 0 0 6px; font-size: 38px; letter-spacing: 0.06em; }
#race-result .race-box.win h2 { color: #4cff7a; }
#race-result .race-box.lose h2 { color: #ff4a4a; }
#race-result table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 14px; }
#race-result td { padding: 4px 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
#race-result tr.me td { color: #ffcc33; font-weight: 700; }
#race-result .race-keys { opacity: 0.7; font-size: 13px; }

#minimap {
  position: absolute; right: 22px; bottom: 150px; width: 240px; height: 240px; border-radius: 50%;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45); z-index: 12; pointer-events: none; opacity: 0.95;
}
#minimap canvas { width: 100%; height: 100%; display: block; border-radius: 50%; }
@media (max-width: 700px) { #minimap { width: 150px; height: 150px; bottom: 120px; right: 12px; } }

/* ---- PC / Mobile switch ---- */
#device-switch { position: absolute; top: max(14px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); z-index: 6; pointer-events: auto; }
#app.drive #device-switch { display: none; }
.seg { display: inline-flex; border: 1px solid var(--panel-border); border-radius: 18px; overflow: hidden; background: var(--panel); }
.seg button { padding: 7px 16px; border: 0; background: transparent; color: var(--text-dim); font: 600 13px var(--font); letter-spacing: 0.06em; cursor: pointer; }
.seg button.on { background: var(--accent); color: #14181e; }
/* compact sound on/off for short screens (the Sound row is hidden there) */
.sound-toggle { display: none; position: absolute; top: max(14px, env(safe-area-inset-top)); right: calc(max(14px, env(safe-area-inset-right)) + 140px); z-index: 6;
  padding: 7px 14px; border: 1px solid var(--panel-border); border-radius: 18px; background: var(--panel); color: var(--text); font: 600 13px var(--font); cursor: pointer; pointer-events: auto; }
.sound-toggle.off { color: var(--text-dim); }
#app.drive .sound-toggle { display: none !important; }
#specs { scrollbar-width: thin; scrollbar-color: var(--panel-border) transparent; }

/* ---- mobile touch controls (shown only while driving in Mobile) ---- */
#touch { display: none; position: absolute; inset: 0; z-index: 22; pointer-events: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#app.mobile.drive #touch { display: block; }
#touch button, #touch .t-joy { pointer-events: auto; touch-action: none; -webkit-tap-highlight-color: transparent; }
#touch button {
  border: 1px solid rgba(255, 255, 255, 0.28); background: rgba(14, 18, 24, 0.68); color: #fff;
  font: 700 12px var(--font); letter-spacing: 0.05em;
}
#touch button.on, #touch button:active { background: rgba(255, 181, 71, 0.85); color: #14181e; }
.t-top { position: absolute; top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); display: flex; gap: 6px; }
.t-top button { min-width: 44px; height: 36px; padding: 0 9px; border-radius: 8px; }
.t-joy {
  position: absolute; left: max(14px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom));
  width: min(178px, 46vh); height: min(178px, 46vh); border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.08) 0%, rgba(14, 18, 24, 0.64) 72%);
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  display: flex; align-items: center; justify-content: center;
}
.t-joy.active { border-color: rgba(255, 181, 71, 0.65); }
.t-joy-ring {
  position: absolute; inset: 22%; border-radius: 50%;
  border: 1px dashed rgba(255, 255, 255, 0.16); pointer-events: none;
}
.t-joy-mark {
  position: absolute; font-size: 12px; line-height: 1;
  color: rgba(255, 255, 255, 0.38); pointer-events: none; transition: color 80ms ease;
}
.t-joy-mark.on { color: rgba(255, 181, 71, 0.95); }
.t-joy-mark.up { top: 8px; left: 50%; transform: translateX(-50%); }
.t-joy-mark.down { bottom: 8px; left: 50%; transform: translateX(-50%); }
.t-joy-mark.left { left: 9px; top: 50%; transform: translateY(-50%); }
.t-joy-mark.right { right: 9px; top: 50%; transform: translateY(-50%); }
.t-joy-knob {
  width: 40%; height: 40%; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 35% 32%, rgba(255, 255, 255, 0.42), rgba(220, 228, 238, 0.22) 60%, rgba(16, 20, 26, 0.65));
  border: 2px solid rgba(255, 255, 255, 0.65);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45), inset 0 1px 4px rgba(255, 255, 255, 0.35);
  transition: transform 120ms ease-out, background 90ms ease, border-color 90ms ease;
  will-change: transform;
}
.t-joy.active .t-joy-knob {
  transition: none;
  background: radial-gradient(circle at 35% 32%, #ffd791, rgba(255, 181, 71, 0.92) 62%, rgba(200, 125, 24, 0.95));
  border-color: #fff;
  box-shadow: 0 6px 18px rgba(255, 181, 71, 0.35), 0 4px 12px rgba(0, 0, 0, 0.5);
}
.t-right {
  position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom));
  display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; gap: 10px; align-items: end;
}
.t-small { width: 62px; height: 62px; border-radius: 50%; }
.t-right .t-small:first-child { grid-column: 2; grid-row: 1; }
.t-right .t-small:nth-child(2) { grid-column: 1; grid-row: 2; }
.t-big { grid-column: 2; grid-row: 2; width: 96px; height: 96px; border-radius: 50%; font-size: 13px !important; }
/* driving HUD rearranged around the thumbs */
#app.mobile .hud-hint { display: none; }
#app.mobile .hud-right { right: auto; left: 50%; transform: translateX(-50%); bottom: 8px; min-width: 110px; padding: 6px 12px; text-align: center; }
#app.mobile .hud-speed { font-size: 28px; }
#app.mobile #minimap { top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); bottom: auto; width: 116px; height: 116px; }
#app.mobile #race-hud { top: 8px; }
#app.mobile #race-hud .race-main { font-size: 18px; }
#app.mobile #race-hud .race-sub { font-size: 11px; }
#app.mobile #race-hud .race-pin { width: 160px; }
#app.mobile #race-banner { top: 64px; font-size: 16px; }
#app.mobile #race-count { font-size: 90px; }
#app.mobile #race-result .race-box { min-width: 0; width: min(92vw, 460px); max-height: 84vh; overflow: auto; padding: 14px 18px; }
#app.mobile #race-result .race-box h2 { font-size: 26px; }
#app.mobile #race-result table { font-size: 12px; margin: 8px 0; }
#app.mobile #race-result .race-keys { display: none; }
/* menu on a phone */
#app.mobile #help { display: none; }
#app.mobile #title { padding: 10px 14px; }
#app.mobile #title h1 { font-size: 17px; }
#app.mobile #specs { left: 12px; bottom: 72px; top: auto; width: 290px; max-height: calc(100% - 150px); overflow-y: auto; padding: 10px 12px; }
#app.mobile #specs dl { font-size: 11px; }
#app.mobile .driver-btn { width: 32px; height: 32px; font-size: 13px; }
#app.mobile #car-nav { bottom: 12px; }
@media (max-height: 480px) {
  #app.mobile #specs dl { display: none; }
  /* short screens: compact rows, and the panel scrolls instead of running off the top */
  #specs { max-height: calc(100dvh - 100px); overflow-y: auto; padding: 10px 14px; }
  #specs .driver-row { margin-top: 6px; padding-top: 6px; }
  #sound-select { display: none; }
  .sound-toggle { display: block; }
}
