:root {
  --chg-up3: #c8322b;
  --chg-up2: #e8743b;
  --chg-up1: #f2b56b;
  --chg-same: #9aa3ad;
  --chg-down1: #4a8fd6;
  --chg-closed: #3b2fa0;
  --chg-new: #8b2fc9;
  --badge: #1d1f24;
  --badge-text: #ffffff;
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1d1f24;
  --muted: #5d636e;
  --border: #dcd9d0;
  --accent: #2456c9;
  --map: #eeece6;
  --map-road: #d6d2c8;
  --map-road-major: #c4bfb2;
  --flow-free: #2e8b57;
  --flow-slow: #d08a00;
  --flow-jam: #c8322b;
  --flow-idle: #b9c2cf;
  --car: #1d1f24;
  --cycle: #1f9e89;
  --bollard: #c8322b;
  --signal: #c8322b;
  --dev-fill: rgba(214, 120, 30, 0.22);
  --dev-edge: #b85f12;
  --school: #7b3fb5;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171b;
    --surface: #1d2026;
    --text: #e8e8ea;
    --muted: #9aa1ad;
    --border: #2e333b;
    --accent: #7aa2ff;
    --map: #1a1d22;
    --map-road: #2b3038;
    --map-road-major: #3a404a;
    --flow-free: #46b37a;
    --flow-slow: #e3a42a;
    --flow-jam: #ef5b52;
    --flow-idle: #4a5260;
    --car: #f2f2f2;
    --cycle: #34c3ab;
    --bollard: #ef5b52;
    --dev-fill: rgba(240, 150, 60, 0.2);
    --dev-edge: #f0a050;
    --school: #c79bff;
    --chg-up3: #ff6b5e;
    --chg-up2: #ff9a5c;
    --chg-up1: #ffc98a;
    --chg-same: #6b7480;
    --chg-down1: #6eaaf0;
    --chg-closed: #e6e6ff;
    --chg-new: #c79bff;
    --badge: #f2f2f2;
    --badge-text: #15171b;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #15171b;
  --surface: #1d2026;
  --text: #e8e8ea;
  --muted: #9aa1ad;
  --border: #2e333b;
  --accent: #7aa2ff;
  --map: #1a1d22;
  --map-road: #2b3038;
  --map-road-major: #3a404a;
  --flow-free: #46b37a;
  --flow-slow: #e3a42a;
  --flow-jam: #ef5b52;
  --flow-idle: #4a5260;
  --car: #f2f2f2;
  --cycle: #34c3ab;
  --bollard: #ef5b52;
  --dev-fill: rgba(240, 150, 60, 0.2);
  --dev-edge: #f0a050;
  --school: #c79bff;
  --chg-up3: #ff6b5e;
  --chg-up2: #ff9a5c;
  --chg-up1: #ffc98a;
  --chg-same: #6b7480;
  --chg-down1: #6eaaf0;
  --chg-closed: #e6e6ff;
  --chg-new: #c79bff;
  --badge: #f2f2f2;
  --badge-text: #15171b;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font:
    15px/1.5 system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
}

.top,
.controls,
.panels,
.card {
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 16px;
}

.top h1 {
  font-size: 1.45rem;
  margin: 20px 0 4px;
  text-wrap: balance;
}

.lede {
  margin: 0 0 12px;
  color: var(--muted);
  max-width: 75ch;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  padding-block: 10px;
}

.controls label {
  display: flex;
  gap: 6px;
  align-items: center;
  font-weight: 600;
}

select,
button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
}

button {
  cursor: pointer;
}

button:hover,
select:hover {
  border-color: var(--accent);
}

.legend {
  color: var(--muted);
  font-size: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
}

.sw {
  display: inline-block;
  width: 18px;
  height: 4px;
  border-radius: 2px;
  margin-left: 6px;
}

.sw.free {
  background: var(--flow-free);
}
.sw.slow {
  background: var(--flow-slow);
}
.sw.jam {
  background: var(--flow-jam);
}
.sw.cycle {
  background: repeating-linear-gradient(90deg, var(--cycle) 0 5px, transparent 5px 8px);
}

.sw.dev {
  height: 10px;
  background: var(--dev-fill);
  border: 1.5px solid var(--dev-edge);
}

.dot.school {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--school);
  margin-left: 6px;
}

.dot.bollard {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bollard);
  margin-left: 6px;
}

.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 860px) {
  .panels {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel-head,
.panel-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-size: 0.88rem;
}

.panel-head select {
  font-weight: 600;
  max-width: 70%;
}

.panel-foot {
  color: var(--muted);
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
}

.clock {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

canvas {
  width: 100%;
  height: min(62vh, 620px);
  display: block;
  touch-action: none;
  cursor: grab;
}

.card {
  margin-top: 16px;
}

.card > h2 {
  font-size: 1.1rem;
  margin: 18px 0 6px;
}

.muted {
  color: var(--muted);
  font-size: 0.88rem;
}

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.86rem;
}

th,
td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  font-weight: 600;
  background: color-mix(in srgb, var(--surface) 85%, var(--border));
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

td.warn {
  color: var(--flow-slow);
  font-weight: 600;
}

.up {
  color: var(--flow-jam);
}
.down {
  color: var(--flow-free);
}

tr.group td {
  font-weight: 700;
  background: color-mix(in srgb, var(--surface) 92%, var(--accent));
}

.prose p,
.prose > ul,
.prose > ol {
  max-width: 100ch;
}

.prose li {
  margin-bottom: 6px;
}

.verify {
  background: var(--surface);
  border: 1px solid var(--border);
}

code {
  font-size: 0.9em;
}

body > :last-child {
  margin-bottom: 40px;
}

details {
  margin: 10px 0;
}

summary {
  cursor: pointer;
  font-weight: 600;
}

.prose-list li {
  margin-bottom: 6px;
}

.top h1 {
  font-size: 1.6rem;
}

.howto {
  margin: 4px 0 14px;
  padding-left: 22px;
  max-width: 80ch;
  color: var(--muted);
}

.howto li {
  margin-bottom: 2px;
}

.findings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 6px;
}

.finding {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.finding h3 {
  font-size: 0.92rem;
  margin: 0 0 6px;
}

.finding .big {
  font-size: 1.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.finding .big.up {
  color: var(--chg-up3);
}

.finding .big.down {
  color: var(--chg-down1);
}

.finding .vals {
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.finding p {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 6px 0 0;
}

.toggle {
  display: inline-flex;
}

.toggle button {
  border-radius: 0;
}

.toggle button:first-child {
  border-radius: 6px 0 0 6px;
}

.toggle button:last-child {
  border-radius: 0 6px 6px 0;
  border-left: 0;
}

.toggle button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--surface);
}

.legend-bar {
  max-width: 1500px;
  margin: 0 auto 8px;
  padding: 0 16px;
}

.sw.up3 {
  background: var(--chg-up3);
}
.sw.up2 {
  background: var(--chg-up2);
}
.sw.up1 {
  background: var(--chg-up1);
}
.sw.same {
  background: var(--chg-same);
}
.sw.down1 {
  background: var(--chg-down1);
}
.sw.down3 {
  background: repeating-linear-gradient(90deg, var(--chg-closed) 0 3px, transparent 3px 7px);
}
.sw.new {
  background: var(--chg-new);
}

.badge {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--badge);
  color: var(--badge-text);
  font-style: normal;
  font-size: 0.7rem;
  font-weight: 700;
  margin-left: 6px;
}

.places {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 2.2fr;
  gap: 14px;
  align-items: start;
}

@media (max-width: 860px) {
  .places {
    grid-template-columns: 1fr;
  }
}

.place-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.place-list button {
  width: 100%;
  text-align: left;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
}

.place-list button[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.place-list .num {
  display: inline-grid;
  place-items: center;
  flex: 0 0 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--badge);
  color: var(--badge-text);
  font-size: 0.78rem;
  font-weight: 700;
}

.place-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.place-detail h3 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.place-detail .headline {
  font-size: 1.05rem;
  margin: 0 0 10px;
}

.place-detail .headline strong {
  font-variant-numeric: tabular-nums;
}

.place-detail p {
  max-width: 75ch;
}

.section-title {
  max-width: 1500px;
  margin: 28px auto 0;
  padding: 0 16px;
  font-size: 1.2rem;
}

details.fold > summary {
  list-style: none;
  cursor: pointer;
}

details.fold > summary::-webkit-details-marker {
  display: none;
}

details.fold > summary h2 {
  display: inline;
  font-size: 1.05rem;
}

details.fold > summary::before {
  content: "▸ ";
  color: var(--muted);
}

details.fold[open] > summary::before {
  content: "▾ ";
}

details.fold {
  margin-top: 10px;
}

[hidden] {
  display: none !important;
}

.services {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
  margin: 8px 0;
}

.service-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.service-block h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.service-summary p {
  margin: 0 0 6px;
  font-size: 0.88rem;
}

.service-summary .extra {
  font-size: 1rem;
}

.service-summary .extra strong {
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.bars {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 1.1fr) 1.4fr;
  grid-template-areas: "label bar" "label value";
  column-gap: 10px;
  align-items: center;
  font-size: 0.82rem;
}

.bar-label {
  grid-area: label;
}

.bar-value {
  grid-area: value;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
}

.bar {
  grid-area: bar;
  position: relative;
  height: 10px;
  background: var(--border);
  border-radius: 5px;
}

.bar .fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 5px;
}

.bar .fill.ok {
  background: var(--flow-free);
}

.bar .fill.near {
  background: var(--flow-slow);
}

.bar .fill.over {
  background: var(--flow-jam);
}

.bar .mark {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--text, currentColor);
}

.tag {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--muted);
}

/* Until app.js has filled in the findings and panels, keep everything below
   the header invisible so nothing jumps when it appears. Fallback reveal after
   8 s in case the script fails. */
body.loading > :not(header) {
  visibility: hidden;
  animation: reveal 0s 8s forwards;
}

@keyframes reveal {
  to {
    visibility: visible;
  }
}

@media (max-width: 480px) {
  .finding {
    padding: 10px;
  }
  .finding .big {
    font-size: 1.2rem;
  }
  .finding p {
    display: none;
  }
}
