:root {
  --brand: #e4572e;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1f22;
  --muted: #6b7078;
  --border: #e2e0db;
  --track: #e8e6e1;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
  --err-bg: #fde4e1;
  --err-text: #7a1d12;
  --ok: #2f9e44;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121416;
    --surface: #1b1e21;
    --text: #eceae6;
    --muted: #9aa0a8;
    --border: #2c3035;
    --track: #2c3035;
    --warn-bg: #3a2f12;
    --warn-text: #f3d68a;
    --err-bg: #3d1a16;
    --err-text: #f6b4aa;
    --ok: #51cf66;
  }
}
:root[data-theme="dark"] {
  --bg: #121416;
  --surface: #1b1e21;
  --text: #eceae6;
  --muted: #9aa0a8;
  --border: #2c3035;
  --track: #2c3035;
  --warn-bg: #3a2f12;
  --warn-text: #f3d68a;
  --err-bg: #3d1a16;
  --err-text: #f6b4aa;
  --ok: #51cf66;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  border-top: 3px solid var(--brand);
}
.titles { min-width: 0; }
.topbar h1 { margin: 0; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar p { margin: 0; font-size: 13px; color: var(--muted); }

.live {
  flex: none;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on { color: var(--ok); }
.live.on::before { background: var(--ok); animation: blink 2s infinite; }
@keyframes blink { 50% { opacity: .3; } }

.layout { position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0; }
.map { flex: 1; min-height: 240px; background: var(--track); }

.map-buttons {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 500;
  display: flex;
  gap: 6px;
}
.map-buttons button {
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgb(0 0 0 / .15);
  cursor: pointer;
}
.map-buttons button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

.panel {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

/* Bottom-sheet toggle; phones and tablets only (see the desktop media query). */
.panel-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  min-height: 36px;
  margin: -8px 0 6px;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.panel-toggle .handle { width: 36px; height: 4px; border-radius: 2px; background: var(--border); }
.panel.collapsed #panel-details { display: none; }

.notice { border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; font-size: 13px; }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }
.notice.err { background: var(--err-bg); color: var(--err-text); }

.progress-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; margin-bottom: 6px; }
.bar { height: 10px; border-radius: 5px; background: var(--track); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--brand); border-radius: 5px; transition: width .6s ease; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 12px; margin: 12px 0 0; }
.stats div { min-width: 0; }
.stats .wide { grid-column: span 4; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 0; font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats dd small { font-size: 12px; font-weight: 500; color: var(--muted); }
.stats .wide dd { font-size: 17px; }

.stats dd.cell-note { margin-top: 1px; font-size: 12px; font-weight: 400; white-space: normal; }
.stats dd.low { color: var(--err-text); }
.stats dd.ahead { color: var(--ok); }
.stats dd.behind { color: var(--err-text); }
.stats dd.record-projection { margin-top: 2px; font-size: 13px; font-weight: 400; white-space: normal; }

.muted { color: var(--muted); }
.footnote { font-size: 12px; margin: 10px 0 0; }

@media (max-width: 420px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats .wide { grid-column: span 2; }
  .stats dd { font-size: 18px; }
}

@media (min-width: 900px) {
  .layout { flex-direction: row-reverse; }
  .panel-toggle { display: none; }
  .panel.collapsed #panel-details { display: block; }
  .panel { width: 360px; flex: none; border-top: 0; border-right: 1px solid var(--border); overflow-y: auto; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats .wide { grid-column: span 2; }
  .stats dd { font-size: 26px; }
}

/* Rider marker */
.rider { position: relative; }
.rider .dot {
  position: absolute; inset: 0;
  border-radius: 50%;
  background: var(--brand);
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgb(0 0 0 / .25);
}
.rider .pulse {
  position: absolute; inset: -10px;
  border-radius: 50%;
  background: var(--brand);
  opacity: .35;
  animation: pulse 2s ease-out infinite;
}
.rider.stale .dot { background: #8a8f96; }
.rider.stale .pulse { display: none; }
@keyframes pulse { from { transform: scale(.4); opacity: .5; } to { transform: scale(1.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .rider .pulse, .live.on::before { animation: none; }
}

.leaflet-container { font: inherit; }
.leaflet-tooltip.record-tip { font-size: 11px; padding: 1px 5px; }
