:root {
  color-scheme: light;
  --surface-0: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #ffffff;
  --border: #e2e1dc;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e7e6e1;
  --cell-empty: #eeede9;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-0: #111110;
    --surface-1: #1a1a19;
    --surface-2: #222221;
    --border: #33332f;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #2c2c29;
    --cell-empty: #262624;
  }
}

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

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 14px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--surface-1); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; margin: 0; white-space: nowrap; }
.topbar .sub { font-weight: 400; color: var(--text-muted); font-size: 12px; margin-left: 4px; }
.tabs { display: flex; gap: 4px; background: var(--surface-0); padding: 3px; border-radius: 9px; }
.tabs button {
  border: 0; background: transparent; color: var(--text-secondary); font: inherit;
  padding: 6px 12px; border-radius: 7px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text-primary); box-shadow: 0 1px 2px #0002; }

.layout { flex: 1; display: flex; min-height: 0; }
.map-wrap { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--surface-0); }
.panel {
  width: 400px; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px;
  background: var(--surface-0); border-left: 1px solid var(--border);
}
@media (max-width: 820px) {
  .layout { flex-direction: column; overflow-y: auto; }
  .map-wrap { flex: none; height: 52vh; min-height: 300px; }
  .panel { width: auto; border-left: 0; overflow: visible; }
}

.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; margin: 0; min-width: 0;
}
fieldset.card legend { font-weight: 600; padding: 0 4px; font-size: 13px; }
.card h2 { font-size: 15px; margin: 2px 0 8px; }
.card h3 { font-size: 13px; margin: 14px 0 6px; color: var(--text-secondary); font-weight: 600; }
.row { display: flex; flex-direction: column; gap: 3px; margin: 6px 0; min-width: 0; }
.row > label, .seg-label { font-size: 12px; color: var(--text-secondary); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.inline { display: flex; gap: 6px; align-items: center; }
.inline > input:not([type=checkbox]) { flex: 1; min-width: 0; }
input, select, button {
  font: inherit; color: var(--text-primary); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 7px; padding: 6px 8px; min-width: 0;
}
input[type=range] { padding: 0; accent-color: var(--accent); }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button { cursor: pointer; }
button.small { padding: 5px 9px; font-size: 12px; white-space: nowrap; }
.check { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.seg { flex-direction: row; align-items: center; gap: 12px; }
.seg label { display: inline-flex; gap: 4px; align-items: center; font-size: 13px; }
.hint { font-size: 12px; color: var(--text-muted); }
.bad { color: var(--critical); }

body.mode-map .path-only { display: none; }
body.mode-path .map-only { display: none; }

/* HUD over the map */
.map-hud {
  position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 500; pointer-events: none;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
}
#hud-text {
  background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: 12px; box-shadow: 0 2px 8px #0003; max-width: 100%;
}
.progress { width: 180px; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.legend {
  position: absolute; top: 10px; right: 10px; z-index: 500; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; width: 220px;
  box-shadow: 0 2px 8px #0003;
}
.legend .bar { height: 10px; border-radius: 3px; margin: 6px 0 2px; }
.legend .ticks { position: relative; height: 15px; color: var(--text-secondary); }
.legend .ticks span { position: absolute; transform: translateX(-50%); }
.legend .ticks span.start { transform: none; }
.legend .ticks span.end { transform: translateX(-100%); }
.legend .title { font-weight: 600; }
.legend .swatches { list-style: none; margin: 6px 0 2px; padding: 0; display: grid; gap: 3px 10px; }
.legend .swatches.cols2 { grid-template-columns: 1fr 1fr; }
.legend:has(.cols2) { width: 270px; }
.legend .swatches li { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend .swatches i { flex: 0 0 14px; height: 12px; border-radius: 3px; box-shadow: inset 0 0 0 1px #0003; }
.legend .swatches .sub { color: var(--text-muted); font-size: 10px; margin-left: auto; }

/* Results */
.summary { font-size: 13px; color: var(--text-secondary); }
.summary .hero { font-size: 22px; font-weight: 650; color: var(--text-primary); display: block; margin: 2px 0; }
table.bands { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
table.bands th { text-align: left; font-size: 11px; font-weight: 600; color: var(--text-muted); padding: 4px 4px; border-bottom: 1px solid var(--border); }
table.bands td { padding: 5px 4px; border-bottom: 1px solid var(--grid); font-size: 13px; }
table.bands td.num { text-align: right; }
table.bands tr.best td { font-weight: 650; }
.relbar { display: inline-block; height: 6px; border-radius: 3px; background: var(--accent); vertical-align: middle; margin-right: 6px; }
.status { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.good { color: var(--good); }
.status.fair { color: #b67f00; }
.status.poor { color: var(--serious); }
.status.closed { color: var(--text-muted); }
@media (prefers-color-scheme: dark) { .status.fair { color: var(--warning); } }

.chart-wrap { position: relative; }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
.axis-label { font-size: 11px; fill: var(--text-secondary); }
.axis-label.faint { fill: var(--text-muted); font-size: 10px; }
.grid { stroke: var(--grid); stroke-width: 1; }
.cell { cursor: pointer; }
.hour-sel { fill: none; stroke: var(--text-primary); stroke-width: 1.5; }
.hour-line { stroke: var(--text-muted); stroke-dasharray: 3 3; }
.crosshair { stroke: var(--text-muted); stroke-width: 1; }
.series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.series.s1 { stroke: var(--series-1); }
.series.s2 { stroke: var(--series-2); }
.dot { stroke: var(--surface-1); stroke-width: 2; }
.dot.s1 { fill: var(--series-1); }
.dot.s2 { fill: var(--series-2); }
.direct-label { font-size: 11px; fill: var(--text-primary); font-weight: 600; }
.legend-inline { font-size: 12px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.key { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.key.s1 { background: var(--series-1); }
.key.s2 { background: var(--series-2); margin-left: 8px; }
.tip .key.s2 { margin-left: 0; }
.ramp-legend { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-secondary); margin-top: 4px; }
.ramp-legend i { flex: 0 0 140px; height: 8px; border-radius: 3px; }
.tip {
  position: absolute; display: none; pointer-events: none; z-index: 20;
  background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 7px; padding: 6px 8px; font-size: 12px; box-shadow: 0 3px 10px #0004; white-space: nowrap;
}
.about p { margin: 4px 0 8px; color: var(--text-secondary); }

.leaflet-container { font: inherit; }
.map-dark .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.85) contrast(0.9); }
.station-icon {
  width: 16px; height: 16px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px #0006, 0 2px 6px #0006;
}
.station-icon.tx { background: var(--series-2); }
.station-icon.rx { background: var(--series-1); }
.station-label {
  background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border);
  font-weight: 600; font-size: 11px; padding: 1px 5px; border-radius: 4px; box-shadow: none;
}
.station-label::before { display: none; }
