[hidden] { display: none !important; }
:root {
  --bg: #f8fafc; --fg: #0f172a; --muted: #64748b; --card: #ffffff; --line: #e2e8f0; --accent: #2563eb;
  --green: #16a34a; --yellow: #eab308; --red: #dc2626; --free: #22c55e; --nodata: #94a3b8;
  --tabs-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1220; --fg: #e2e8f0; --muted: #94a3b8; --card: #111a2e; --line: #1e293b; --accent: #60a5fa; }
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9); }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); }
.view { position: fixed; inset: 0 0 calc(var(--tabs-h) + env(safe-area-inset-bottom)) 0; overflow: auto; }
.page { padding: 16px; max-width: 760px; margin: 0 auto; position: static; min-height: 100%; }
h1 { font-size: 1.4rem; margin: .2rem 0 .6rem; }
.muted { color: var(--muted); font-size: .9rem; }
.banner { position: fixed; top: 0; left: 0; right: 0; z-index: 2000; background: #7c2d12; color: #fff; padding: 6px 12px; font-size: .85rem; }

/* tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: flex; background: var(--card); border-top: 1px solid var(--line); z-index: 1500; }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem; }
.tabs a .ti { font-size: 1.25rem; line-height: 1; }
.tabs a.on { color: var(--accent); font-weight: 600; }

/* map */
#map { position: absolute; inset: 0; }
.map-tools { position: absolute; top: 12px; right: 12px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.fab { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--fg);
  font-size: 1.2rem; box-shadow: 0 2px 6px rgba(0,0,0,.25); }
.layers { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; font-size: .9rem; }
.legend { position: absolute; left: 8px; top: 8px; z-index: 1000; background: var(--card); border-radius: 8px; padding: 4px 8px;
  font-size: .72rem; display: flex; gap: 4px; align-items: center; opacity: .92; flex-wrap: wrap; max-width: 70%; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--nodata); }
.dot.green { background: var(--green); } .dot.yellow { background: var(--yellow); } .dot.red { background: var(--red); }
.dot.free { background: var(--free); } .dot.nodata { background: var(--nodata); }
.ev-icon { width: 22px; height: 22px; border-radius: 4px; color: #fff; font: 700 13px/22px system-ui; text-align: center; border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.ev-icon.events { background: #dc2626; } .ev-icon.roadworks { background: #ea580c; width: 16px; height: 16px; font-size: 10px; line-height: 13px; border-width: 1.5px; }
.vms-icon { width: 12px; height: 12px; background: #2563eb; border: 2px solid #fff; border-radius: 2px; }
.me-icon { width: 26px; height: 26px; }
.me-icon .arrow { width: 0; height: 0; margin: 0 auto; border-left: 9px solid transparent; border-right: 9px solid transparent;
  border-bottom: 24px solid #2563eb; filter: drop-shadow(0 0 2px #fff); transform-origin: 50% 60%; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; z-index: 1200; max-height: 55%; overflow: auto; background: var(--card);
  border-radius: 16px 16px 0 0; box-shadow: 0 -4px 16px rgba(0,0,0,.3); padding: 12px 16px 16px; }
.sheet .close { float: right; background: none; border: 0; color: var(--muted); font-size: 1.4rem; }
.sheet h2 { font-size: 1.05rem; margin: 0 0 4px; }
.row { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.big { font-size: 1.3rem; font-weight: 700; }
a { color: var(--accent); }

/* cards */
.cards { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.cards li { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.cards li.tap { cursor: pointer; }
.delay-0 { color: var(--green); } .delay-1 { color: var(--yellow); } .delay-2 { color: var(--red); }
.spark { width: 100%; height: 34px; display: block; margin-top: 6px; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.chart { margin: 12px 0; min-height: 220px; }
.back { display: inline-block; margin-bottom: 8px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .78rem; color: #fff; background: var(--nodata); }
.pill.green { background: var(--green); } .pill.yellow { background: var(--yellow); color: #111; } .pill.red { background: var(--red); }
.pill.free { background: var(--free); }
code { font-size: .85em; }

/* drive mode: always dark, large */
.drive { background: #020617; color: #f1f5f9; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.drive-top { display: flex; justify-content: space-between; align-items: baseline; color: #94a3b8; font-size: .85rem; }
.drive-own { color: #f1f5f9; font-size: 1.4rem; font-weight: 700; }
.drive-main { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: center; }
.rec, .ahead { text-align: center; }
.rec-label, .ahead-label { color: #94a3b8; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.rec-sign { margin: 8px auto; width: 128px; height: 128px; border-radius: 50%; border: 10px solid #e2e8f0; display: flex;
  align-items: center; justify-content: center; font-size: 3.2rem; font-weight: 800; }
.rec-sign.jam { border-color: var(--red); font-size: 1.4rem; }
.rec-reason { color: #94a3b8; font-size: .8rem; min-height: 2.2em; }
.ahead-speed { font-size: 3.6rem; font-weight: 800; line-height: 1.1; margin: 8px 0; }
.ahead-speed.green, .ahead-speed.free { color: var(--free); } .ahead-speed.yellow { color: var(--yellow); }
.ahead-speed.red { color: #f87171; } .ahead-speed.nodata { color: #64748b; }
.ahead-where { color: #cbd5e1; font-size: .85rem; }
.drive-event { background: #1e293b; border-radius: 12px; padding: 12px; font-size: 1.05rem; min-height: 3.2em; }
.drive-event .ev-dist { font-size: 1.6rem; font-weight: 800; color: #fb923c; margin-right: 8px; }
.drive-age { color: #64748b; font-size: .8rem; }
.drive-ctl { display: flex; gap: 8px; flex-wrap: wrap; }
.drive-ctl select, .drive-ctl button { background: #1e293b; color: #f1f5f9; border: 1px solid #334155; border-radius: 10px;
  padding: 10px 12px; font-size: 1rem; }
.drive-ctl select { flex: 1; min-width: 150px; }
.drive-ctl button[disabled] { opacity: .45; }
.safety { color: #64748b; font-size: .75rem; margin: 0; }
@media (max-width: 380px) { .rec-sign { width: 104px; height: 104px; font-size: 2.6rem; } .ahead-speed { font-size: 2.8rem; } }
.row.flat { border: 0; padding: 0; }
.chart { overflow: hidden; }
.chart .u-legend { font-size: .75rem; }
.chart .u-legend tr { display: inline-block; margin-right: 8px; }
.drive-match { font-size: .8rem; padding: 4px 10px; border-radius: 8px; background: #0f172a; color: #94a3b8; align-self: flex-start; }
.drive-match.route { color: #86efac; } .drive-match.free { color: #fcd34d; }
