:root { --red:#b91c1c; --ink:#111827; --muted:#4b5563; --line:#d1d5db; --bg:#ffffff; --soft:#f3f4f6; --blue:#1d4ed8; --btn:#111827; --btnInk:#fff; --hi:#fee2e2; --med:#fef3c7; }
body.night { --ink:#e5e7eb; --muted:#9ca3af; --line:#374151; --bg:#111827; --soft:#1f2937; --btn:#e5e7eb; --btnInk:#111827; --hi:#4c1010; --med:#422006; color-scheme:dark; }
* { box-sizing: border-box; }
[hidden] { display:none !important; }   /* the hidden attribute always wins over display rules */
html, body { margin:0; height:100%; font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color:var(--ink); }
#map { position:absolute; inset:0; }
#panel { position:absolute; top:12px; left:12px; width:380px; max-height:calc(100% - 24px); display:flex; flex-direction:column;
  background:var(--bg); border-radius:14px; box-shadow:0 6px 24px rgba(0,0,0,.25); overflow:hidden; z-index:2; }
#panel .bar { display:flex; align-items:center; gap:10px; padding:12px 14px; background:var(--red); color:#fff; }
#panel .bar strong { font-size:18px; flex:1; }
.health { font-size:12px; padding:2px 8px; border-radius:999px; background:rgba(255,255,255,.2); }
.health.ok { background:#16a34a; } .health.bad { background:#111; }
.icon { background:none; border:0; color:#fff; font-size:22px; cursor:pointer; min-width:44px; min-height:44px; }
#panel .body { padding:12px 14px 16px; overflow:auto; }
#panel.collapsed .body { display:none; }
.field { margin-bottom:12px; position:relative; }
.field label, .label { display:block; font-size:13px; font-weight:600; color:var(--muted); margin-bottom:4px; text-transform:uppercase; letter-spacing:.04em; }
.row { display:flex; gap:8px; }
input, select, textarea { font:inherit; padding:10px 12px; border:1px solid var(--line); border-radius:10px; width:100%; min-height:44px; background:var(--bg); color:var(--ink); }
input:focus, select:focus { outline:3px solid #93c5fd; border-color:var(--blue); }
.chip { white-space:nowrap; border:1px solid var(--line); background:var(--soft); color:var(--ink); border-radius:10px; padding:0 12px; min-height:44px; font:inherit; font-size:14px; cursor:pointer; }
.results { list-style:none; margin:4px 0 0; padding:0; border:1px solid var(--line); border-radius:10px; max-height:240px; overflow:auto; background:var(--bg); }
.results:empty { display:none; }
.results li { padding:10px 12px; border-bottom:1px solid var(--soft); cursor:pointer; }
.results li:hover, .results li:focus { background:var(--soft); }
.results small { color:var(--muted); }
.seg { display:flex; border:1px solid var(--line); border-radius:10px; overflow:hidden; }
.seg button { flex:1; min-height:48px; border:0; background:var(--bg); color:var(--ink); font:inherit; font-weight:600; cursor:pointer; }
.seg button.on[data-mode=emergency] { background:var(--red); color:#fff; }
.seg button.on[data-mode=normal] { background:var(--blue); color:#fff; }
.primary { width:100%; min-height:52px; border:0; border-radius:12px; background:var(--btn); color:var(--btnInk); font:inherit; font-size:18px; font-weight:700; cursor:pointer; }
.primary:disabled { opacity:.5; }
.secondary { display:block; text-align:center; margin-top:12px; padding:12px; border:1px solid var(--line); border-radius:12px; color:var(--ink); text-decoration:none; background:var(--bg); font:inherit; cursor:pointer; }
.msg { min-height:1.2em; margin:8px 0 0; color:var(--muted); } .msg.err { color:var(--red); font-weight:600; }
.note { font-size:13px; color:var(--muted); margin:4px 0 0; }
.summary { font-size:20px; font-weight:700; margin:14px 0 6px; }
.summary small { display:block; font-size:14px; font-weight:400; color:var(--muted); }
.avoid { background:var(--hi); border:1px solid var(--line); border-radius:10px; padding:8px 10px; margin:6px 0; font-size:14px; }
.forced { background:#7f1d1d; color:#fff; border-radius:10px; padding:10px; margin:6px 0; font-weight:700; }
h3 { font-size:15px; margin:14px 0 6px; }
.alerts { list-style:none; padding:0; margin:0; }
.alerts li { display:flex; gap:10px; padding:10px; border-radius:10px; margin-bottom:6px; background:var(--soft); cursor:pointer; }
.alerts li.high { background:var(--hi); } .alerts li.medium { background:var(--med); }
.alerts .at { font-weight:700; min-width:58px; font-variant-numeric:tabular-nums; }
.alerts .t { font-weight:600; } .alerts .d { font-size:13px; color:var(--muted); }
.turns { padding-left:20px; font-size:14px; } .turns li { margin:6px 0; }
.layers { display:flex; gap:16px; margin-top:14px; font-size:14px; } .layers label { display:flex; gap:6px; align-items:center; text-transform:none; font-weight:400; }
.layers input { width:auto; min-height:auto; }
dialog { border:0; border-radius:16px; padding:0; width:min(520px, 96vw); max-height:92vh; background:var(--bg); color:var(--ink); }
dialog form { padding:16px 18px; overflow:auto; max-height:92vh; }
dialog h2 { margin:0 0 12px; } dialog label { display:block; margin-bottom:10px; font-size:14px; font-weight:600; }
dialog fieldset { border:1px solid var(--line); border-radius:12px; margin:0 0 12px; padding:10px 12px; }
.grid2 { display:grid; grid-template-columns:2fr 1fr; gap:0 10px; }
.thumbs { display:flex; gap:8px; } .thumbs img { width:96px; height:72px; object-fit:cover; border-radius:8px; border:1px solid var(--line); }
.actions { display:flex; gap:10px; } .actions button { flex:1; margin-top:0; }
.maplibregl-popup-content { font-size:14px; max-width:280px; }
@media (max-width: 700px) {
  #panel { top:auto; bottom:0; left:0; right:0; width:auto; max-height:70%; border-radius:16px 16px 0 0; }
}

/* ---------- start buttons */
.gorow { display:flex; gap:8px; } .gorow .primary { flex:2; } .gorow .secondary { flex:1; margin-top:0; }
#startNav { margin:8px 0 4px; background:#15803d; }
/* ---------- driving mode */
body.navigating #panel, body.navigating .maplibregl-ctrl-top-right { display:none; }
#nav { position:absolute; inset:0; pointer-events:none; z-index:5; }
#nav > * { pointer-events:auto; }
#navTop { position:absolute; top:calc(env(safe-area-inset-top) + 10px); left:10px; right:10px; display:flex; gap:14px; align-items:center;
  background:#0f5132; color:#fff; border-radius:16px; padding:12px 16px; box-shadow:0 6px 20px rgba(0,0,0,.35); }
#navIcon { font-size:54px; line-height:1; min-width:56px; text-align:center; font-weight:700; }
#navDist { font-size:32px; font-weight:800; line-height:1.1; }
#navStreet { font-size:20px; font-weight:600; line-height:1.2; }
#navThen { font-size:15px; opacity:.85; margin-top:2px; } #navThen:empty { display:none; }
.navAlert { position:absolute; top:calc(env(safe-area-inset-top) + 130px); left:10px; right:10px; border-radius:14px; padding:12px 16px;
  font-size:22px; font-weight:800; box-shadow:0 6px 20px rgba(0,0,0,.35); }
.navAlert small { display:block; font-size:15px; font-weight:600; opacity:.9; }
.navAlert.high { background:#b91c1c; color:#fff; } .navAlert.medium { background:#f59e0b; color:#111; } .navAlert.low { background:#e5e7eb; color:#111; }
.navAlert.over { background:#b91c1c; color:#fff; animation:flash .6s steps(2) infinite; }
@keyframes flash { 50% { background:#7f1d1d; } }
.navGps { position:absolute; top:calc(env(safe-area-inset-top) + 130px); left:10px; right:10px; background:#111; color:#fff; border-radius:12px; padding:10px 14px; font-size:15px; }
.navRecenter { position:absolute; right:14px; bottom:120px; min-height:48px; padding:0 18px; border-radius:24px; border:0; background:var(--bg); color:var(--ink); font:inherit; font-weight:700; box-shadow:0 4px 14px rgba(0,0,0,.3); }
#navBottom { position:absolute; left:0; right:0; bottom:0; background:var(--bg); color:var(--ink); padding:10px 14px calc(env(safe-area-inset-bottom) + 10px); display:flex; flex-wrap:wrap; gap:10px 14px; align-items:center; box-shadow:0 -4px 16px rgba(0,0,0,.2); }
.nb b { font-size:24px; display:block; line-height:1.1; } .nb small { color:var(--muted); font-size:13px; }
.nb.spd { text-align:center; min-width:56px; }
.badge { font-size:12px; font-weight:800; padding:4px 8px; border-radius:6px; color:#fff; } .badge.emergency { background:var(--red); } .badge.normal { background:var(--blue); }
.nbtns { display:flex; gap:8px; margin-left:auto; }
.nbtn { min-height:48px; padding:0 14px; border-radius:12px; border:1px solid var(--line); background:var(--soft); color:var(--ink); font:inherit; font-weight:600; }
.nbtn.end { background:#b91c1c; color:#fff; border:0; }
.carMarker { width:0; height:0; border-left:14px solid transparent; border-right:14px solid transparent; border-bottom:34px solid #2563eb; filter:drop-shadow(0 0 3px #fff) drop-shadow(0 2px 4px rgba(0,0,0,.5)); }
@media (max-width:700px) { .nbtns { width:100%; margin-left:0; } .nbtns .nbtn { flex:1; } }

/* ---------- sign-in */
.login { position:fixed; inset:0; z-index:50; background:#7f1d1d; display:flex; align-items:center; justify-content:center; padding:20px; }
.loginCard { background:#fff; border-radius:18px; padding:24px 22px; width:min(380px, 100%); text-align:center; box-shadow:0 10px 40px rgba(0,0,0,.4); }
.loginCard h1 { font-size:22px; margin:10px 0 18px; }
.loginCard label { display:block; text-align:left; font-size:13px; font-weight:600; color:var(--muted); margin-bottom:4px; text-transform:uppercase; }
.loginCard input { font-size:22px; letter-spacing:.2em; text-align:center; margin-bottom:12px; }
.loginCard img { border-radius:16px; }

/* ---------- v0.3: themes, signs, units, AI, crash */
body.night #panel .bar { background:#7f1d1d; }
body.night #navTop { background:#064e3b; }
.maplibregl-popup-content { color:#111; }
.maplibregl-popup-content .chip { background:#f3f4f6; color:#111; border-color:#d1d5db; min-height:40px; }
.maplibregl-popup-content .note { color:#4b5563; }
.popimg { width:100%; max-height:160px; object-fit:cover; border-radius:8px; margin-top:6px; }
.row.wrap { flex-wrap:wrap; }
.chip.wide { width:100%; margin-top:12px; }
.seg.small button { min-height:40px; font-size:14px; }
#lookSeg button.on { background:#374151; color:#fff; }
.lookrow { margin-top:12px; }
.layers { flex-wrap:wrap; gap:10px 16px; }
input.ai, select.ai { background:#fef9c3; color:#111; border-color:#ca8a04; }
.spin { display:inline-block; width:14px; height:14px; border:2px solid var(--line); border-top-color:var(--red); border-radius:50%; animation:spin .8s linear infinite; vertical-align:-2px; }
@keyframes spin { to { transform:rotate(360deg); } }
.units { list-style:none; padding:0; margin:0; } .units li { padding:8px 10px; border-radius:10px; background:var(--soft); margin-bottom:6px; cursor:pointer; }
.units .badge { font-size:10px; padding:2px 6px; }
.who { margin:4px 0 0; padding-left:18px; font-size:14px; }
label.check { display:flex; gap:10px; align-items:flex-start; font-weight:400; } label.check input { width:auto; min-height:auto; margin-top:4px; }
dialog textarea { min-height:140px; margin-bottom:12px; }
dialog fieldset .chip { margin-top:6px; }
.crashBanners { position:absolute; top:calc(env(safe-area-inset-top) + 8px); left:50%; transform:translateX(-50%); width:min(560px, 94vw); z-index:20; display:flex; flex-direction:column; gap:8px; pointer-events:none; }
.crashBanner { pointer-events:auto; background:#b91c1c; color:#fff; border-radius:14px; padding:10px 14px; box-shadow:0 6px 24px rgba(0,0,0,.4); animation:flash 1s steps(2) 6; }
.crashBanner strong { display:block; font-size:17px; } .crashBanner small { display:block; opacity:.9; }
.crashBanner .row { margin-top:8px; } .crashBanner .chip { background:#fff; color:#111; border:0; }
.crash { position:fixed; inset:0; z-index:100; background:#7f1d1d; color:#fff; display:flex; align-items:center; justify-content:center; padding:20px; }
.crash.test { background:#1e3a8a; }
.crashCard { width:min(420px, 100%); text-align:center; }
.crashCard h1 { font-size:30px; margin:0 0 8px; }
.crashCount { font-size:96px; font-weight:800; line-height:1; margin:8px 0; font-variant-numeric:tabular-nums; }
.crashCard p { font-size:17px; }
.bigok { width:100%; min-height:88px; font:inherit; font-size:28px; font-weight:800; border:0; border-radius:18px; background:#fff; color:#111; margin-top:12px; }
.bigsend { width:100%; min-height:56px; font:inherit; font-size:18px; font-weight:700; border:2px solid #fff; border-radius:14px; background:transparent; color:#fff; margin-top:14px; }
@media (max-width: 700px) { .crashBanners { top:calc(env(safe-area-inset-top) + 60px); } }
