:root {
  --bg: #0b0d10; --panel: #12161b; --ink: #f2f5f8; --muted: #8b95a1;
  --accent: #3b9eff; --ok: #2fd27a; --warn: #ff5a4f; --line: #222a33;
  --map-filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.7);
}
body[data-theme="day"] {
  --bg: #eef1f4; --panel: #ffffff; --ink: #10161c; --muted: #5d6874; --line: #d6dde4;
  --map-filter: none;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
.hidden { display: none !important; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }

#app { display: grid; grid-template-columns: minmax(280px, 34%) 1fr; height: 100dvh; }
#panel { background: var(--panel); padding: 16px 18px; display: flex; flex-direction: column;
  gap: 12px; border-right: 1px solid var(--line); overflow: auto; }
.topline { display: flex; justify-content: space-between; align-items: center; }
#clock { font-size: 28px; font-weight: 600; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.chip { font-size: 13px; padding: 4px 10px; border-radius: 99px; background: var(--line); color: var(--muted); }
.chip.ok { background: rgba(47,210,122,.15); color: var(--ok); }
.chip.bad { background: rgba(255,90,79,.15); color: var(--warn); }

#speedBlock { text-align: center; padding: 6px 0 0; }
#speed { font-size: clamp(96px, 20vh, 190px); line-height: 1; font-weight: 700;
  font-variant-numeric: tabular-nums; transition: color .2s; }
#speed.over { color: var(--warn); }
#speedUnit { color: var(--muted); font-size: 20px; margin-top: -4px; }

.limit { align-self: center; width: 84px; height: 84px; border-radius: 50%; background: #fff;
  border: 8px solid #e3262a; display: grid; place-items: center; color: #111;
  font-size: 34px; font-weight: 800; }
#overspeed { align-self: center; color: var(--warn); font-weight: 600; }

.navcard { display: flex; align-items: center; gap: 12px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
#navArrow { font-size: 40px; width: 56px; text-align: center; color: var(--accent); }
.navtext { flex: 1; min-width: 0; }
#navDist { font-size: 26px; font-weight: 700; }
#navInstr { color: var(--muted); font-size: 15px; overflow: hidden; text-overflow: ellipsis; }
#eta { text-align: center; color: var(--muted); font-size: 15px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: auto; }
.stats div { background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 12px; display: flex; flex-direction: column; font-size: 20px; font-weight: 600; }
.k { color: var(--muted); font-size: 12px; font-weight: 400; text-transform: uppercase; letter-spacing: .06em; }

button.ghost { background: transparent; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; color: var(--muted); }
button.ghost.small { padding: 6px 10px; font-size: 13px; align-self: center; }
button.primary { background: var(--accent); border: 0; border-radius: 12px; padding: 14px 18px;
  color: #fff; font-weight: 600; width: 100%; }

#mapWrap { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #1b2026; }
body[data-theme="night"] .leaflet-tile-pane { filter: var(--map-filter); }
.leaflet-control-attribution { font-size: 10px; }
#mapMsg { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 700;
  background: var(--panel); border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px; }

.carIcon svg { width: 44px; height: 44px; transition: transform .25s linear; filter: drop-shadow(0 2px 6px rgba(0,0,0,.6)); }

#dock { position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 800;
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
#dock button { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; min-height: 52px; box-shadow: 0 6px 18px rgba(0,0,0,.35); }
#dock button.locked { opacity: .45; }

#searchBar { position: absolute; top: 12px; left: 12px; right: 12px; z-index: 900;
  display: flex; flex-wrap: wrap; gap: 8px; max-width: 640px; }
#searchInput { flex: 1; min-width: 0; padding: 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); }
#searchGo { background: var(--accent); border: 0; border-radius: 12px; padding: 0 20px; color: #fff; font-weight: 600; }
#results { list-style: none; margin: 0; padding: 0; width: 100%; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
#results:empty { display: none; }
#results li { padding: 14px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 15px; }
#results li:last-child { border-bottom: 0; }
#results li:active { background: var(--line); }

.sheet { position: fixed; z-index: 1000; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(460px, 92vw); max-height: 90dvh; overflow: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.6);
  display: flex; flex-direction: column; gap: 12px; }
.sheet h3 { margin: 0; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.row select, .row input[type=number] { background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; }
.row input[type=number] { width: 70px; }
.row input[type=checkbox] { width: 26px; height: 26px; }
.btnlink { flex: 1; text-align: center; padding: 14px; border-radius: 12px; background: var(--bg);
  border: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.muted { color: var(--muted); } .small { font-size: 12px; }
hr { border: 0; border-top: 1px solid var(--line); width: 100%; }

.modal { position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,.75); display: grid; place-items: center; padding: 16px; }
.modal .card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: 24px; width: min(520px, 100%); max-height: 96dvh; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
@media (max-height: 520px) { .modal .card { padding: 14px; gap: 8px; } .modal h2 { font-size: 24px; } .modal ul { line-height: 1.35; font-size: 14px; } }
.modal h2 { margin: 0; font-size: 32px; }
.modal ul { margin: 0; padding-left: 20px; color: var(--muted); line-height: 1.5; }

@media (orientation: portrait), (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #panel { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; border-right: 0;
    border-bottom: 1px solid var(--line); padding: 10px 14px; max-height: 42dvh; }
  #speed { font-size: 84px; }
  .stats { display: none; }
  #resetTrip { display: none; }
}
