/* Car Dashboard
   Landscape-first, dark, high contrast. Everything tappable is at least 56px
   because the driver is aiming at it without looking. */

:root {
  --bg: #07090d;
  --bg-panel: #10141c;
  --bg-panel-hi: #171d28;
  --line: #232b3a;
  --text: #eef2f8;
  --text-dim: #8794aa;
  --accent: #35e0c8;
  --accent-warm: #ffb547;
  --danger: #ff5f56;
  --ring-track: #1c2431;

  --pad: clamp(8px, 1.4vw, 16px);
  --radius: 16px;

  /* Kept well clear of Leaflet's internal 400-800 range. */
  --z-map-launch: 500;
  --z-sheet: 1000;
  --z-toast: 1100;
  --z-gate: 2000;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

/* ------------------------------------------------------------- start gate */

.gate {
  position: fixed;
  inset: 0;
  z-index: var(--z-gate);
  display: grid;
  place-items: center;
  background: radial-gradient(120% 90% at 50% 0%, #131a26 0%, var(--bg) 70%);
  text-align: center;
  padding: 24px;
}
.gate.hidden { display: none; }
.gate-mark { font-size: 30px; color: var(--accent); letter-spacing: 6px; }
.gate h1 { margin: 12px 0 6px; font-size: clamp(24px, 5vw, 40px); font-weight: 650; letter-spacing: -0.5px; }
.gate p { margin: 0 0 22px; color: var(--text-dim); max-width: 30ch; line-height: 1.5; }
.gate-inner { display: flex; flex-direction: column; align-items: center; }
.gate-btn {
  padding: 18px 44px;
  border-radius: 999px;
  background: var(--accent);
  color: #04120f;
  font-size: 19px;
  font-weight: 650;
  min-height: 60px;
}
.gate-btn:active { transform: scale(0.97); }
.gate-warn {
  margin-top: 20px;
  max-width: 40ch;
  color: var(--accent-warm);
  font-size: 13px;
  line-height: 1.5;
}

/* ------------------------------------------------------------------ shell */

.dash {
  display: none;
  height: 100%;
  flex-direction: column;
  gap: var(--pad);
  padding: max(var(--pad), env(safe-area-inset-top)) max(var(--pad), env(safe-area-inset-right))
           max(var(--pad), env(safe-area-inset-bottom)) max(var(--pad), env(safe-area-inset-left));
}
.dash.live { display: flex; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: 0 0 auto; }

.clock { display: flex; align-items: baseline; gap: 10px; }
#clockTime { font-size: clamp(22px, 3.6vw, 32px); font-weight: 600; font-variant-numeric: tabular-nums; }
.clock-date { color: var(--text-dim); font-size: clamp(11px, 1.6vw, 14px); }

.status { display: flex; align-items: center; gap: 8px; }

.pill {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: clamp(10px, 1.4vw, 12px);
  font-weight: 600;
  white-space: nowrap;
  max-width: 32vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill-ok { background: rgba(53, 224, 200, 0.14); color: var(--accent); }
.pill-warn { background: rgba(255, 181, 71, 0.14); color: var(--accent-warm); }
.pill-quiet { background: var(--bg-panel-hi); color: var(--text-dim); }

.icon-btn {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--bg-panel-hi);
  color: var(--text-dim);
  font-size: 18px;
  display: grid; place-items: center;
}
.icon-btn:active { background: var(--line); }

/* ------------------------------------------------------------------- grid */

.grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.15fr) minmax(150px, 0.55fr);
  gap: var(--pad);
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
  min-height: 0;
  /* Leaflet puts z-index 400-800 on its own panes. Without a stacking context
     here those values escape into the root context and paint over the sheets. */
  isolation: isolate;
}

/* --------------------------------------------------------------- speedo */

.speedo { display: grid; place-items: center; padding: var(--pad); }
.dial { position: absolute; inset: 8%; width: 84%; height: 84%; }
.dial-track, .dial-value {
  fill: none;
  stroke-width: 14;
  stroke-linecap: round;
  transform: rotate(135deg);
  transform-origin: 130px 130px;
  /* 270 degrees of a r=110 circle: 2*pi*110 = 691.15, three quarters = 518.36 */
  stroke-dasharray: 518.36 691.15;
}
.dial-track { stroke: var(--ring-track); }
.dial-value { stroke: var(--accent); transition: stroke-dasharray 260ms ease-out, stroke 400ms linear; }
.dial-value.fast { stroke: var(--accent-warm); }
.dial-value.veryfast { stroke: var(--danger); }
.tick { stroke: #3a4557; stroke-width: 2; }
.tick.major { stroke: #55637c; stroke-width: 3; }

.speedo-readout { position: relative; text-align: center; z-index: 1; }
.speed-num {
  display: block;
  font-size: clamp(56px, 13vh, 116px);
  font-weight: 700;
  line-height: 0.92;
  font-variant-numeric: tabular-nums;
  letter-spacing: -3px;
}
.unit-btn {
  margin-top: 6px;
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--bg-panel-hi);
  color: var(--text-dim);
  font-size: clamp(11px, 1.6vw, 14px);
  font-weight: 600;
  letter-spacing: 0.5px;
}
.speedo-foot {
  position: absolute;
  bottom: 10px;
  left: 0; right: 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
}

/* ------------------------------------------------------------------ map */

.map-panel { display: flex; }
.map { flex: 1; width: 100%; background: #0d1117; }
.map-fallback {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  color: var(--text-dim);
  font-size: 13px;
  background: var(--bg-panel);
  text-align: center;
  padding: 20px;
}
.map-fallback.show { display: grid; }
.map-launch-row {
  position: absolute;
  left: 10px; bottom: 10px;
  z-index: var(--z-map-launch);
  display: flex;
  gap: 6px;
}
.map-launch {
  padding: 12px 16px;
  min-height: 48px;
  border-radius: 12px;
  background: rgba(16, 20, 28, 0.92);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  backdrop-filter: blur(8px);
}
.map-launch:active { background: var(--line); }

/* Leaflet's own chrome, toned down to match */
.leaflet-container { background: #0d1117; font-family: inherit; }
.leaflet-control-attribution { background: rgba(7,9,13,0.7) !important; color: #6b7789 !important; font-size: 9px !important; }
.leaflet-control-attribution a { color: #8794aa !important; }
.leaflet-control-zoom { display: none; }

.car-marker { display: grid; place-items: center; }
.car-marker svg { filter: drop-shadow(0 0 6px rgba(53, 224, 200, 0.5)); }

/* ------------------------------------------------------------ side tiles */

.side { display: grid; grid-template-rows: 1.2fr 1fr 0.8fr; gap: var(--pad); min-height: 0; }

.tile {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 10px;
  min-height: 0;
  text-align: center;
}

.tile-assist {
  background: linear-gradient(160deg, #17303a, #101a24);
  border-color: #23505a;
  color: inherit;
}
.tile-assist:active { background: linear-gradient(160deg, #1e414f, #142230); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
.tile-icon { font-size: clamp(24px, 4.5vh, 38px); line-height: 1; }
.tile-label { font-size: clamp(12px, 1.7vw, 15px); font-weight: 650; letter-spacing: 0.3px; }
.tile-label-sm { font-size: 11px; color: var(--text-dim); font-weight: 600; letter-spacing: 0.6px; text-transform: uppercase; }

.tile-compass { grid-template-rows: 1fr auto; }
.compass { width: 100%; height: 100%; max-height: 90px; }
.compass-ring { fill: none; stroke: var(--ring-track); stroke-width: 4; }
/* Linear, and roughly the repaint interval - an easing curve restarting 12
   times a second is what makes a compass needle look nervous. */
#compassNeedle { transform-origin: 50px 50px; transition: transform 90ms linear; }
.needle-n { fill: var(--accent); }
.needle-s { fill: #3a4557; }
.tile-readout { font-size: clamp(13px, 2vw, 17px); font-weight: 650; font-variant-numeric: tabular-nums; }

.tile-music { grid-template-rows: auto 1fr; }
.music-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; width: 100%; align-self: stretch; }
.music-btn {
  border-radius: 10px;
  background: var(--bg-panel-hi);
  color: var(--text);
  font-size: clamp(10px, 1.4vw, 13px);
  font-weight: 600;
  min-height: 44px;
  padding: 4px;
}
.music-btn:active { background: var(--line); }

/* ------------------------------------------------------------------ trip */

.trip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: clamp(10px, 3vw, 32px);
  padding: 10px clamp(10px, 2vw, 20px);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.stat { display: flex; align-items: baseline; gap: 5px; }
.stat-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.8px; font-weight: 650; }
.stat-value { font-size: clamp(15px, 2.4vw, 22px); font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-unit { font-size: 10px; color: var(--text-dim); }
.trip-reset {
  margin-left: auto;
  padding: 10px 16px;
  min-height: 44px;
  border-radius: 10px;
  background: var(--bg-panel-hi);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
}
.trip-reset:active { background: var(--line); color: var(--text); }

/* ----------------------------------------------------------- navigation */

.nav-banner {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px clamp(12px, 2vw, 20px);
  background: linear-gradient(120deg, #103a34, #0d2430);
  border: 1px solid #1f5f55;
  border-radius: var(--radius);
}
.nav-banner[hidden] { display: none; }

.nav-maneuver { display: flex; align-items: center; gap: 14px; min-width: 0; }
.nav-icon {
  font-size: clamp(26px, 4.5vh, 40px);
  line-height: 1;
  color: var(--accent);
  flex: 0 0 auto;
}
.nav-text { display: flex; flex-direction: column; min-width: 0; }
.nav-distance {
  font-size: clamp(20px, 3.4vh, 30px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.nav-street {
  font-size: clamp(12px, 1.8vw, 16px);
  color: #a8c4c0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46vw;
}

.nav-summary { display: flex; align-items: center; gap: 14px; flex: 0 0 auto; }
.nav-eta { display: flex; flex-direction: column; align-items: flex-end; }
.nav-eta > span:first-child { font-size: clamp(15px, 2.2vw, 20px); font-weight: 650; font-variant-numeric: tabular-nums; }
.nav-remaining { font-size: 11px; color: #a8c4c0; }
.nav-stop {
  min-height: 48px;
  padding: 0 20px;
  border-radius: 12px;
  background: rgba(255, 95, 86, 0.16);
  color: #ff8b84;
  font-weight: 650;
  font-size: 13px;
}
.nav-stop:active { background: rgba(255, 95, 86, 0.3); }

.map-launch-primary { background: rgba(53, 224, 200, 0.9); color: #04120f; border-color: transparent; }
.map-launch-primary:active { background: var(--accent); }

.nav-results { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.nav-result {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  min-height: 60px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--bg-panel-hi);
  text-align: left;
}
.nav-result:active { background: var(--line); }
.nav-result-name { font-size: 15px; font-weight: 600; }
.nav-result-detail { font-size: 12px; color: var(--text-dim); }
.nav-note { padding: 10px 2px; font-size: 13px; color: var(--text-dim); }

/* The planned route, drawn under the car marker. */
.route-line { stroke: var(--accent); stroke-width: 6; stroke-opacity: 0.85; fill: none; }

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 6vh;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  max-width: min(520px, 88vw);
  padding: 14px 20px;
  border-radius: 12px;
  background: rgba(23, 29, 40, 0.97);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.toast[hidden] { display: none; }

/* --------------------------------------------------------------- sheets */

.sheet {
  position: fixed;
  inset: 0;
  z-index: var(--z-sheet);
  display: grid;
  place-items: end center;
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(6px);
  padding: var(--pad);
}
.sheet[hidden] { display: none; }
.sheet-inner {
  width: min(720px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.assist-state { font-size: 13px; font-weight: 650; color: var(--accent); letter-spacing: 0.4px; }

.assist-form { display: flex; gap: 8px; }
.assist-form input {
  flex: 1;
  min-height: 52px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  -webkit-user-select: text;
  user-select: text;
}
.assist-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.assist-send {
  min-height: 52px;
  padding: 0 22px;
  border-radius: 12px;
  background: var(--accent);
  color: #04120f;
  font-weight: 650;
}

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.setting[hidden] { display: none; }
.setting input[type="password"] {
  width: 140px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  text-align: center;
  letter-spacing: 3px;
  -webkit-user-select: text;
  user-select: text;
}
.setting select {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.setting input[type="checkbox"] { width: 26px; height: 26px; accent-color: var(--accent); }
.setting-btn {
  margin-top: 14px;
  width: 100%;
  min-height: 52px;
  border-radius: 12px;
  background: var(--bg-panel-hi);
  color: var(--text);
  font-weight: 600;
}
.settings-note { margin: 14px 0 0; font-size: 12px; color: var(--text-dim); line-height: 1.5; }

/* -------------------------------------------------- portrait / small screens */

@media (orientation: portrait) {
  .grid {
    grid-template-columns: minmax(0, 1fr) minmax(120px, 0.42fr);
    grid-template-rows: minmax(0, 1.25fr) minmax(0, 1fr);
  }
  .speedo { grid-column: 1; grid-row: 1; }
  .side { grid-column: 2; grid-row: 1 / span 2; grid-template-rows: 1fr 1fr 1fr; }
  .map-panel { grid-column: 1; grid-row: 2; }
  .trip { flex-wrap: wrap; row-gap: 8px; }
  .trip-reset { margin-left: 0; }
}

@media (max-height: 420px) {
  .trip { padding: 6px 12px; }
  .stat-value { font-size: 16px; }
}
