:root {
  --bg: #f6f4ee;
  --panel: #ffffff;
  --fg: #1b1d1a;
  --muted: #5d625a;
  --grid: #e2dfd5;
  --accent: #1f5f3f;
  --accent-fg: #ffffff;
  --route: #d1495b;
  --route-done: #7a7f86;
  --here: #1c6dd0;
  --pick: #e08a00;
  --warn-bg: #fde7c4;
  --warn-fg: #6b3d00;
  --profile-ahead: rgba(31, 95, 63, 0.22);
  --profile-done: rgba(122, 127, 134, 0.28);
  --radius: 12px;
  --tile-filter: none;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121412; --panel: #1c1f1c; --fg: #ecefe9; --muted: #a3a99f; --grid: #2d322d;
    --accent: #4fb07c; --accent-fg: #0d1a12; --route: #ff6b7d; --route-done: #8d939a;
    --here: #5aa2ff; --pick: #ffb23e; --warn-bg: #4a3209; --warn-fg: #ffdca3;
    --profile-ahead: rgba(79, 176, 124, 0.25); --profile-done: rgba(141, 147, 154, 0.25);
    --tile-filter: brightness(0.72) contrast(1.08) saturate(0.85);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121412; --panel: #1c1f1c; --fg: #ecefe9; --muted: #a3a99f; --grid: #2d322d;
  --accent: #4fb07c; --accent-fg: #0d1a12; --route: #ff6b7d; --route-done: #8d939a;
  --here: #5aa2ff; --pick: #ffb23e; --warn-bg: #4a3209; --warn-fg: #ffdca3;
  --profile-ahead: rgba(79, 176, 124, 0.25); --profile-done: rgba(141, 147, 154, 0.25);
  --tile-filter: brightness(0.72) contrast(1.08) saturate(0.85);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.artifact .pwa-only, :root:not(.artifact) .artifact-only { display: none !important; }
:root:not(.has-server) .server-only, .has-server .no-server-only { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h3 { margin: 20px 0 8px; font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
code { font-size: 12px; }

/* ---- stats header ---- */
#stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px 8px;
  padding: 8px 12px 6px; background: var(--panel); border-bottom: 1px solid var(--grid);
}
.stat { display: flex; flex-direction: column; min-width: 0; }
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stat .value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.statusline { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.pill:empty { display: none; }
.pill.ok { color: var(--accent); }
.pill.bad { color: var(--route); }
.banner { grid-column: 1 / -1; margin-top: 6px; padding: 6px 10px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-fg); font-weight: 600; font-size: 14px; }

/* ---- tabs ---- */
main { flex: 1; min-height: 0; position: relative; }
.tab { display: none; position: absolute; inset: 0; overflow-y: auto; padding: 12px 16px 24px; }
.tab.active { display: block; }
#tab-map { padding: 0; overflow: hidden; }
#map { position: absolute; inset: 0; background: var(--grid); }
.map-buttons { position: absolute; right: 12px; bottom: 44px; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.round { width: 52px; height: 52px; border-radius: 50%; border: 0; font-size: 26px; background: var(--panel); color: var(--here); box-shadow: 0 2px 8px rgba(0,0,0,.3); }

#tabs {
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--panel); border-top: 1px solid var(--grid);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs button {
  border: 0; background: none; color: var(--muted); padding: 6px 0 8px; font-size: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
#tabs button span { font-size: 20px; }
#tabs button.active { color: var(--accent); font-weight: 700; }
#tabs button.gps.on { color: var(--here); font-weight: 700; }

/* ---- controls ---- */
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.btn, select, input[type=url], input[type=text] {
  font: inherit; font-size: 15px; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--grid); background: var(--panel); color: var(--fg); cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; }
.check { display: flex; gap: 10px; align-items: center; padding: 8px 0; }
.check input { width: 20px; height: 20px; }
.field { display: flex; flex-direction: column; gap: 4px; padding: 8px 0; }
.field input[type=range] { width: 100%; }
.seg { display: flex; border: 1px solid var(--grid); border-radius: 10px; overflow: hidden; margin-bottom: 8px; }
.seg button { flex: 1; border: 0; padding: 9px 4px; background: var(--panel); color: var(--fg); font: inherit; font-size: 14px; }
.seg button.active { background: var(--accent); color: var(--accent-fg); font-weight: 600; }

/* ---- ahead tab ---- */
#profile { width: 100%; height: 200px; display: block; background: var(--panel); border-radius: var(--radius); touch-action: none; }
.card { background: var(--panel); border-radius: var(--radius); padding: 12px 14px; margin-top: 10px; }
table.grid { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--grid); font-size: 14px; white-space: nowrap; }
table.grid td:first-child { white-space: normal; }
table.grid th:first-child, table.grid td:first-child { text-align: left; }
table.grid thead th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tr.current td { font-weight: 700; background: var(--profile-ahead); }
.up { color: var(--route); }
.down { color: var(--here); }

/* ---- POI list ---- */
.poi-list { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 8px; }
.poi-list li { background: var(--panel); border-radius: var(--radius); padding: 10px 12px; display: grid; grid-template-columns: 34px 1fr auto; gap: 2px 10px; align-items: center; cursor: pointer; }
.poi-list li.passed { opacity: .5; }
.poi-list .icon { font-size: 24px; grid-row: span 2; text-align: center; }
.poi-list .name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.poi-list .dist { font-weight: 700; font-size: 18px; text-align: right; font-variant-numeric: tabular-nums; }
.poi-list .meta { font-size: 13px; color: var(--muted); grid-column: 2 / 4; }
.poi-list .notes { font-size: 13px; grid-column: 2 / 4; }

/* ---- map icons ---- */
.poi-icon span { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; font-size: 18px; background: rgba(255,255,255,.9); border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.leaflet-container { font: inherit; }
.leaflet-tile-pane { filter: var(--tile-filter); }
#tabs button { font-size: 11px; }

/* ---- group ---- */
.group-card { display: flex; flex-direction: column; gap: 10px; margin-top: 0; }
.mate { display: flex; flex-direction: column; gap: 1px; }
.mate-icon span { display: flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%; color: #fff; font-weight: 700; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }

/* ---- weather ---- */
.weather-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.weather-list .card { margin-top: 0; display: flex; flex-direction: column; gap: 8px; }
.weather-list .card.current { outline: 2px solid var(--accent); }
.whead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.wrow { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.wlabel { font-weight: 600; font-size: 13px; color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--bg); }
.chip.warn { background: var(--warn-bg); color: var(--warn-fg); font-weight: 600; }
.hours { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.hour { flex: 0 0 auto; min-width: 58px; display: flex; flex-direction: column; align-items: center; gap: 1px; background: var(--bg); border-radius: 10px; padding: 6px 4px; font-variant-numeric: tabular-nums; }
.hour .big { font-size: 20px; }
.leaflet-control-attribution { font-size: 9px; max-width: 70vw; }

@media (max-width: 380px) {
  .stat .value { font-size: 17px; }
}
