:root {
  --bg: #ffffff;
  --fg: #0f172a;
  --muted: #475569;
  --line: #e2e8f0;
  --panel-shadow: 0 -6px 24px rgb(15 23 42 / 0.18);
  --accent: #7c3aed;
  --accent-fg: #ffffff;
  --banner: #0f172a;
  --banner-fg: #ffffff;
  --unmapped: #e5383b;
  --stale: #f59e0b;
  --recent: #16a34a;
  --capture: #7c3aed;
  --transit: #2563eb;
  --ridden: #94a3b8;
  --danger: #b91c1c;
  --radius: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --fg: #f1f5f9;
    --muted: #94a3b8;
    --line: #1f2937;
    --panel-shadow: 0 -6px 24px rgb(0 0 0 / 0.5);
    --accent: #8b5cf6;
    --danger: #f87171;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#map { position: fixed; inset: 0; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  border-radius: 12px;
  padding: 10px 16px;
  min-height: 44px;
}
button.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; }
button.big { width: 100%; min-height: 58px; font-size: 1.25rem; border-radius: 16px; margin-top: 14px; }
button.small { padding: 8px 14px; min-height: 40px; }
button.danger { color: var(--danger); }
button.link { border: none; background: none; color: var(--muted); text-decoration: underline; padding: 8px 0; }
button:active { transform: scale(0.98); }

/* --- Navigation banner --- */
#nav-banner {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: var(--banner);
  color: var(--banner-fg);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.3);
  z-index: 10;
}
#nav-banner[hidden] { display: none; }
.man-icon { flex: none; width: 64px; height: 64px; }
.man-icon:empty { display: none; }
.man-body { min-width: 0; }
.man-dist { font-size: 2.1rem; font-weight: 800; line-height: 1.05; letter-spacing: -0.01em; }
.man-text { font-size: 1.15rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.chip {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 112px);
  left: 10px;
  z-index: 10;
  padding: 7px 14px 7px 30px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.95rem;
  background: var(--unmapped);
  color: #fff;
  box-shadow: 0 3px 10px rgb(0 0 0 / 0.25);
}
.chip::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  width: 10px;
  height: 10px;
  margin-top: -5px;
  border-radius: 50%;
  background: #fff;
  animation: pulse 1.4s ease-in-out infinite;
}
.chip.transit { background: #334155; }
.chip.transit::before { animation: none; background: #94a3b8; }
@keyframes pulse { 50% { opacity: 0.25; } }

.pill {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 112px);
  right: 10px;
  z-index: 10;
  padding: 7px 14px;
  border-radius: 999px;
  background: #facc15;
  color: #1c1917;
  font-weight: 700;
}

.map-buttons {
  position: fixed;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
}
button.round {
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  box-shadow: 0 3px 12px rgb(0 0 0 / 0.25);
}
button.round[hidden] { display: none; }
#btn-mute .slash { display: none; }
#btn-mute.off .slash { display: inline; }
#btn-mute.off .waves { display: none; }

.sim-controls {
  position: fixed;
  left: 10px;
  top: calc(env(safe-area-inset-top) + 160px);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 6px 14px;
  border-radius: 14px;
  background: var(--bg);
  box-shadow: 0 3px 12px rgb(0 0 0 / 0.2);
  font-size: 0.9rem;
  color: var(--muted);
}
.sim-controls[hidden] { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sheet-h, 200px) + 16px);
  transform: translateX(-50%);
  width: min(92vw, 480px);
  z-index: 20;
  padding: 12px 16px;
  border-radius: 14px;
  background: #1e293b;
  color: #fff;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.3);
}

/* --- Bottom sheet --- */
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  max-height: 72vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--panel-shadow);
  padding: 18px 18px calc(env(safe-area-inset-bottom) + 16px);
}
@media (min-width: 720px) {
  .sheet { left: 16px; right: auto; bottom: 16px; width: 400px; border-radius: 22px; max-height: calc(100vh - 32px); }
}

.title-row { display: flex; align-items: center; gap: 10px; }
h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.02em; }
h2 { margin: 0 0 6px; font-size: 1.3rem; }
.tag { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; padding: 3px 8px; border-radius: 6px; background: var(--accent); color: var(--accent-fg); }
.lede { margin: 6px 0 14px; color: var(--muted); font-size: 0.95rem; }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 0.9rem; }

.field { margin: 12px 0; }
.field label { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 4px; }
.field output { font-weight: 700; color: var(--accent); }
.field.inline { display: flex; align-items: center; justify-content: space-between; }
.field.inline label { margin: 0; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 32px; }
select { font: inherit; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); }

.check { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; font-weight: 500; }
.check input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--accent); }

details { margin: 10px 0; border-top: 1px solid var(--line); padding-top: 8px; }
summary { cursor: pointer; font-weight: 600; color: var(--muted); padding: 6px 0; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: 0.85rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 22px; height: 5px; border-radius: 3px; background: var(--c); }
.legend i.dashed { background: repeating-linear-gradient(90deg, var(--c) 0 6px, transparent 6px 10px); }
.legend-note { flex-basis: 100%; }
.legend.compact { margin: 10px 0 4px; }

.notice { margin: 10px 0; padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--accent) 12%, transparent); font-size: 0.92rem; }
.notice.warn { background: color-mix(in srgb, var(--stale) 22%, transparent); }
.notice .row { margin-top: 8px; }
code { font-size: 0.9em; }

.row { display: flex; gap: 10px; }
.row > button { flex: 1; }

.progress { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin: 12px 0; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 0.4s; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 8px; }
.stats > div { display: flex; flex-direction: column; }
.stats b { font-size: 1.35rem; font-weight: 800; }
.stats span { font-size: 0.8rem; color: var(--muted); }

.me-marker { width: 40px; height: 40px; }
.me-marker.no-heading .me-heading { display: none; }
.home-marker {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: #0f172a; color: #fff; font-size: 18px; line-height: 1;
  border: 3px solid #fff; box-shadow: 0 2px 8px rgb(0 0 0 / 0.35);
}

body[data-mode="nav"] .maplibregl-ctrl-bottom-right,
body[data-mode="nav"] .maplibregl-ctrl-bottom-left { bottom: var(--sheet-h, 0); }

[hidden] { display: none !important; }

/* --- Segmented choice (travel mode, camera) --- */
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  margin: 8px 0;
  border-radius: 14px;
  background: var(--line);
}
.seg label { position: relative; }
.seg input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.seg span {
  display: block;
  padding: 9px 8px;
  border-radius: 10px;
  text-align: center;
  font-weight: 600;
  color: var(--muted);
}
.seg input:checked + span { background: var(--accent); color: var(--accent-fg); box-shadow: 0 1px 4px rgb(0 0 0 / 0.2); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.legend i.later { opacity: 0.35; }
