:root {
  color-scheme: light;
  --page: #f6f5f1;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #5b6b7e;
  --muted: #898781;
  --title: #002868;
  --hair: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #002868;
  --accent-ink: #ffffff;
  --map-bg: #e9eef2;
  --land: #e9e9e7;
  --none: #bdbdbd;
  --line-zip3: rgba(80, 30, 10, 0.22);
  --line-zcta: rgba(80, 30, 10, 0.12);
  --line-state: rgba(11, 11, 11, 0.8);
  --line-state-halo: rgba(255, 255, 255, 0.55);
  --empty: #dfe2e0;            /* land with no ZIP code */
  --empty-line: rgba(11, 11, 11, 0.13);
  --halo: #ffffff;
  /* Delivery-day classes (ColorBrewer GnBu, 7 classes), light = fast, dark blue = slow */
  --d1: #f0f9e8; --d2: #ccebc5; --d3: #a8ddb5; --d4: #7bccc4;
  --d5: #4eb3d3; --d6: #2b8cbe; --d7: #08589e;
  --dest: #c51b7d;  /* warm accents stand apart from the green-blue map */
  --hub: #d95f0e;   /* plant markers, same in both themes */
  /* On-time meters: one blue ramp (validated --ordinal), in its own panel */
  --m0: #184f95; --m1: #3987e5; --m3: #86b6ef; --mtrack: #e6e5df; --mnat: #0b0b0b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0f1215;
    --surface: #171b20;
    --ink: #ffffff;
    --ink-2: #b9c2cc;
    --muted: #8a9198;
    --title: #ffffff;
    --hair: #2c3036;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #6da7ec;
    --accent-ink: #0b0b0b;
    --map-bg: #171b20;
    --land: #2f343b;
    --none: #6b6e73;
    --line-zip3: rgba(23, 27, 32, 0.8);
    --line-zcta: rgba(23, 27, 32, 0.45);
    --line-state: rgba(255, 255, 255, 0.85);
    --line-state-halo: rgba(11, 11, 11, 0.5);
    --empty: #23272d;
    --empty-line: rgba(255, 255, 255, 0.09);
    --dest: #f06aa8;
    --halo: #0b0b0b;
    --m0: #9ec5f4; --m1: #3987e5; --m3: #1c5cab; --mtrack: #2a2e34; --mnat: #ffffff;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f1215; --surface: #171b20; --ink: #ffffff; --ink-2: #b9c2cc; --muted: #8a9198;
  --title: #ffffff; --hair: #2c3036; --border: rgba(255, 255, 255, 0.10);
  --accent: #6da7ec; --accent-ink: #0b0b0b; --map-bg: #171b20; --land: #2f343b; --none: #6b6e73;
  --line-zip3: rgba(23, 27, 32, 0.8); --line-zcta: rgba(23, 27, 32, 0.45);
  --line-state: rgba(255, 255, 255, 0.85); --line-state-halo: rgba(11, 11, 11, 0.5);
  --empty: #23272d; --empty-line: rgba(255, 255, 255, 0.09); --dest: #f06aa8; --halo: #0b0b0b;
  --m0: #9ec5f4; --m1: #3987e5; --m3: #1c5cab; --mtrack: #2a2e34; --mnat: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
button, input { font: inherit; color: inherit; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }

.top {
  display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: end; justify-content: space-between;
  padding: 16px 20px 12px;
}
h1 { margin: 0; font-size: 26px; line-height: 1.1; color: var(--title); letter-spacing: -0.01em; }
.sub { margin: 4px 0 0; color: var(--ink-2); }
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.classes { display: flex; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.classes button {
  border: 0; background: none; padding: 6px 11px; border-radius: 7px; cursor: pointer; color: var(--ink-2);
  white-space: nowrap;
}
.classes button:hover { background: var(--hair); color: var(--ink); }
.classes button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }
.classes button small { opacity: .75; font-size: 12px; }

.mailday {
  display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 3px 4px 3px 10px; color: var(--ink-2); font-size: 14px;
}
.mailday select {
  border: 0; background: none; padding: 5px 4px; border-radius: 7px; cursor: pointer; color: var(--ink);
}
.mailday:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.search { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.search input { border: 0; background: none; padding: 6px 10px; width: 7.5em; outline: none; font-variant-numeric: tabular-nums; }
.search button { border: 0; border-left: 1px solid var(--border); background: none; padding: 6px 12px; cursor: pointer; color: var(--ink-2); }
.search button:hover { color: var(--ink); background: var(--hair); }
.search:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }

.demo {
  margin: 0 20px 10px; padding: 8px 12px; border-radius: 8px;
  background: #fff3cd; color: #5c4400; border: 1px solid #f0d68a;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .demo { background: #3a2f0f; color: #f5dc8f; border-color: #6b5718; } }

.wrap { flex: 1; display: grid; grid-template-columns: 1fr 260px; gap: 16px; padding: 0 20px; min-height: 0; }
.mapbox {
  position: relative; background: var(--map-bg); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; min-height: 420px; height: calc(100vh - 210px);
}
#map { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
#map:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

.tip {
  position: absolute; pointer-events: none; z-index: 2; max-width: 260px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 13px; line-height: 1.35;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .12);
}
.tip b { font-variant-numeric: tabular-nums; }
.tip .days { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-weight: 600; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; box-shadow: inset 0 0 0 1px var(--border); }

.zoombtns { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 4px; }
.zoombtns button {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; font-size: 17px; line-height: 1; color: var(--ink-2);
}
.zoombtns button:hover { color: var(--ink); }

.side { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; align-self: start; }
.origin { border-bottom: 1px solid var(--hair); padding-bottom: 12px; margin-bottom: 12px; position: relative; }
.origin .muted { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.origin-zip { font-size: 30px; font-weight: 650; line-height: 1.15; font-variant-numeric: tabular-nums; color: var(--title); }
.origin-meta { color: var(--ink-2); font-size: 13px; }
.unpin {
  position: absolute; right: 0; top: 0; border: 1px solid var(--border); background: none; border-radius: 7px;
  padding: 2px 9px; font-size: 12px; cursor: pointer; color: var(--ink-2);
}
.legend-title { font-size: 13px; font-weight: 600; margin: 0 0 8px; color: var(--ink-2); }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.legend li {
  display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 6px; font-size: 14px;
}
.legend li .sw { width: 18px; height: 14px; }
.legend li .n { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 13px; }
.legend li.zero { opacity: .45; }
.legend li.hit { background: var(--hair); }
.legend-note { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

.perf { border-top: 1px solid var(--hair); margin-top: 12px; padding-top: 12px; font-size: 13px; }
.perf h3 { font-size: 13px; margin: 0 0 4px; color: var(--ink-2); }
.perf p { margin: 0 0 6px; }
.perf .small { font-size: 12px; margin-top: 6px; }
.perf-t { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.perf-t th, .perf-t td { padding: 3px 4px; text-align: right; border-bottom: 1px solid var(--hair); }
.perf-t th:first-child { text-align: left; font-weight: 500; color: var(--ink-2); }
.perf-t thead th { font-weight: 500; color: var(--muted); font-size: 12px; }
.perf-t td { font-weight: 600; }
.nw { white-space: nowrap; }
.perf-tip { margin-top: 3px; font-size: 12.5px; }
.foot { padding: 10px 20px 18px; color: var(--ink-2); font-size: 13px; }
.foot .status { margin: 0 0 6px; min-height: 1.4em; }
.foot details { max-width: 860px; }
.foot summary { cursor: pointer; color: var(--ink); }
.foot ul { padding-left: 18px; }
.credit { margin: 8px 0 0; color: var(--muted); }

@media (max-width: 820px) {
  .top { padding: 12px 16px 10px; }
  h1 { font-size: 21px; }
  .wrap { grid-template-columns: 1fr; padding: 0 16px; gap: 12px; }
  .mapbox { height: auto; min-height: 0; aspect-ratio: 1000 / 620; }
  .side { padding: 12px; }
  .legend { grid-template-columns: 1fr 1fr; column-gap: 10px; }
  .foot { padding: 10px 16px 16px; }
  .classes { width: 100%; }
  .classes button { flex: 1; padding: 6px 6px; }
}

/* Trip: From / To ZIP boxes */
.trip { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.trip label { padding: 0 2px 0 10px; color: var(--ink-2); font-size: 14px; }
.trip input { border: 0; background: none; padding: 6px 6px; width: 9em; outline: none; font-variant-numeric: tabular-nums; }
.trip input + label { border-left: 1px solid var(--hair); }
.trip button { border: 0; border-left: 1px solid var(--border); background: none; padding: 6px 12px; cursor: pointer; color: var(--ink-2); }
.trip button:hover { color: var(--ink); background: var(--hair); }
.trip:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.tripcard { border-bottom: 1px solid var(--hair); padding-bottom: 12px; margin-bottom: 12px; position: relative; }
.tripcard .route { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--title); }
.tripcard .route .to { color: var(--dest); }
.tripcard .big { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 600; margin: 6px 0 2px; }
.tripcard .big .sw { width: 16px; height: 16px; }
.tripcard .clear { position: absolute; right: 0; top: 0; border: 1px solid var(--border); background: none; border-radius: 7px; padding: 2px 9px; font-size: 12px; cursor: pointer; color: var(--ink-2); }
.tripcard .perf-tip { font-size: 13px; }

/* Side panel, top to bottom: on-time meters, hover/trip readout, origin, legend */
.side > div + div, .side > .readout { margin-top: 0; }
.perf { border-top: 0; margin-top: 0; padding-top: 0; border-bottom: 1px solid var(--hair); padding-bottom: 12px; margin-bottom: 12px; }
.ph { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ph h3 { font-size: 14px; color: var(--ink); margin: 0; }
.msub { font-size: 12px; color: var(--ink-2); margin: 8px 0 2px; font-weight: 600; }
.mrow { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: baseline; margin: 4px 0 8px; }
.mlab { font-size: 13px; color: var(--ink-2); }
.mrow.em .mlab { color: var(--ink); font-weight: 600; }
.mval { font-size: 13px; text-align: right; white-space: nowrap; }
.mval b { font-size: 15px; color: var(--ink); }
.mval .muted { font-variant-numeric: tabular-nums; }
.meter { grid-column: 1 / -1; position: relative; display: flex; height: 8px; border-radius: 4px; background: var(--mtrack); overflow: visible; }
.meter span { height: 100%; }
.meter span + span { box-shadow: inset 2px 0 0 var(--surface); } /* 2px surface gap between segments */
.meter .m0 { background: var(--m0); border-radius: 4px 0 0 4px; }
.meter .m1 { background: var(--m1); }
.meter .m3 { background: var(--m3); }
.meter .nat { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--mnat); border-radius: 1px; }
.mkey { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.mkey i { display: inline-block; width: 10px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: 0; }
.mkey .k0 { background: var(--m0); } .mkey .k1 { background: var(--m1); } .mkey .k3 { background: var(--m3); }
.mkey .kn { width: 2px; height: 12px; background: var(--mnat); vertical-align: -2px; }

.readout { border-bottom: 1px solid var(--hair); padding-bottom: 12px; margin-bottom: 12px; position: relative; min-height: 64px; }
.readout p { margin: 4px 0 0; font-size: 13px; }
.readout .cap { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.readout .route { font-size: 18px; font-weight: 650; color: var(--title); }
.readout .route .to { color: var(--dest); }
.readout .route .city { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.readout .cities { font-size: 13px; color: var(--ink-2); }
.readout .hero { display: flex; align-items: center; gap: 8px; font-size: 26px; font-weight: 650; margin: 6px 0 0; color: var(--ink); line-height: 1.15; }
.readout .hero .sw { width: 18px; height: 18px; border-radius: 4px; }
.readout .clear { position: absolute; right: 0; top: 0; border: 1px solid var(--border); background: none; border-radius: 7px; padding: 2px 9px; font-size: 12px; cursor: pointer; color: var(--ink-2); }

/* Legend: swatch, label, distribution bar, count */
.legend li { grid-template-columns: 18px minmax(70px, auto) 1fr auto; cursor: default; }
.legend li .bar { height: 8px; }
.legend li .bar i { display: block; height: 100%; min-width: 0; background: var(--ink-2); opacity: .35; border-radius: 0 4px 4px 0; }
.legend li.hit .bar i, .legend li.focus .bar i { opacity: .7; }
.legend li.focus { background: var(--hair); }

/* USPS mail plants */
.hubmark { display: inline-block; width: 8px; height: 8px; background: var(--hub); box-shadow: 0 0 0 1.5px #fff; margin-right: 7px; vertical-align: 0; }
.hubmark.dia { width: 8px; height: 8px; transform: rotate(45deg) scale(1.05); }
.origin-hub, .readout .plants { font-size: 13px; color: var(--ink-2); margin-top: 3px; }
.hubkey { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--hair); font-size: 13px; color: var(--ink-2); }
.hubkey label { display: flex; align-items: center; gap: 6px; color: var(--ink); cursor: pointer; }
.hubkinds { display: flex; gap: 14px; margin: 6px 0 0; }

/* Legend: chance in each row; ZIP counts on hover */
.legend li .ct { display: none; }
.legend li:hover .pc { display: none; }
.legend li:hover .ct { display: inline; }
.nozip { display: flex; gap: 8px; align-items: flex-start; font-size: 12px; color: var(--ink-2); margin: 8px 0 0; }
.sw-empty { flex: none; width: 18px; height: 14px; margin-top: 1px; border-radius: 2px; background-color: var(--empty);
  background-image: repeating-linear-gradient(135deg, var(--empty-line) 0 1.5px, transparent 1.5px 5px); }
.legend li .sw { box-shadow: inset 0 0 0 1px var(--border); border-radius: 2px; }

/* Fastest / slowest ZIP prefixes */
.rank { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--hair); font-size: 13px; }
.rank h3 { font-size: 14px; margin: 0 0 6px; color: var(--ink); }
.rank h4 { font-size: 12px; margin: 10px 0 2px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.rank p { margin: 6px 0 0; font-size: 12px; }
.rank .seg { display: inline-flex; margin: 0 4px 4px 0; border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.rank .seg button { border: 0; background: none; padding: 3px 9px; border-radius: 6px; cursor: pointer; color: var(--ink-2); font: inherit; }
.rank .seg button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }
.rank ol { list-style: none; margin: 0; padding: 0; }
.rank li button { width: 100%; display: grid; grid-template-columns: 44px 1fr auto; gap: 6px; align-items: baseline;
  border: 0; background: none; padding: 4px 4px; border-radius: 6px; cursor: pointer; color: var(--ink); font: inherit; text-align: left; }
.rank li button:hover, .rank li button:focus-visible { background: var(--hair); }
.rank .rz { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 600; }
.rank .rn { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .rd { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rank .rd small { display: block; color: var(--muted); font-size: 11px; }
