:root {
  --bg: #ffffff;
  --fg: #1d232b;
  --muted: #5b6672;
  --line: #dde2e7;
  --hover: #f1f4f7;
  --link: #1f62b5;
  --nad: #3478d4;
  --mixed: #8e5cc4;
  --other: #e2782f;
  --point: #c2185b;
  --osm: #2f9e6b;
  /* OSM addresses per 100 NAD+ points, fewest to most: light to dark, and the hue turns from
     gold through green and teal to blue and purple so neighbouring classes stay apart. */
  --ratio-1: #debb19;
  --ratio-2: #46b250;
  --ratio-3: #008d9c;
  --ratio-4: #2552aa;
  --ratio-5: #52187e;
  --shadow: 0 2px 12px rgba(16, 24, 32, 0.18);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b2027;
    --fg: #e6eaef;
    --muted: #9aa5b1;
    --line: #313944;
    --hover: #252c35;
    --link: #7fb2f5;
    --nad: #5b9bf0;
    --mixed: #b28ae0;
    --other: #f2994f;
    --point: #ff6fa8;
    --osm: #3aad79;
    /* The same hues run the other way for the dark surface, so most is brightest. */
    --ratio-1: #733ea4;
    --ratio-2: #3f75ce;
    --ratio-3: #00a6b5;
    --ratio-4: #4ecf6b;
    --ratio-5: #f9d544;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#map { position: absolute; inset: 0; }

a { color: var(--link); }

.panel {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 340px;
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 2;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px 10px;
}

h1 { font-size: 17px; margin: 0; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 18px 0 6px; }

.fold summary {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 18px 0 6px;
  cursor: pointer;
  list-style: none;
  border-radius: 4px;
}
.fold summary::-webkit-details-marker { display: none; }
.fold summary h2 { margin: 0; }
.fold summary::before {
  content: "";
  width: 6px;
  height: 6px;
  margin: 0 2px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s;
}
.fold[open] summary::before { transform: rotate(45deg); }
.fold summary:hover h2 { color: var(--fg); }
.fold summary:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

.meta { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }

.toggle {
  flex: none;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.toggle svg { transition: transform 0.15s; }
.panel.collapsed .toggle svg { transform: rotate(180deg); }
.panel.collapsed .panel-body { display: none; }

.panel-body { overflow-y: auto; padding: 0 16px 14px; }

.intro { margin: 0 0 10px; }

.legend ul { list-style: none; margin: 0; padding: 0; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.swatch {
  width: 16px;
  height: 12px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--c) 45%, transparent);
  border: 1.5px solid var(--c);
}
.swatch.sparse { background: none; border-style: dashed; }
#legend-ratio .swatch { background: color-mix(in srgb, var(--c) 75%, transparent); }
.legend-title { margin: 0 0 2px; font-size: 12.5px; color: var(--muted); }
.legend .note { margin: 4px 0 6px; font-size: 12px; }

/* Two radios drawn as a segmented switch. */
.color-by { display: flex; margin: 0 0 8px; padding: 0; border: 0; }
.color-by legend { float: left; margin-right: 8px; padding: 0; font-size: 12.5px; color: var(--muted); line-height: 26px; }
.color-by label { position: relative; }
.color-by input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.color-by span {
  display: block;
  padding: 3px 10px;
  border: 1px solid var(--line);
  font-size: 12.5px;
  line-height: 18px;
  white-space: nowrap;
}
.color-by label:first-of-type span { border-radius: 999px 0 0 999px; }
.color-by label:last-of-type span { border-radius: 0 999px 999px 0; border-left: 0; }
.color-by input:hover + span { background: var(--hover); }
.color-by input:checked + span { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.color-by input:focus-visible + span { outline: 2px solid var(--link); outline-offset: 1px; }
.dot { width: 8px; height: 8px; margin: 0 4px; border-radius: 50%; background: var(--point); }

.note { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }

.states { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.states th { text-align: left; white-space: nowrap; font-weight: 600; color: var(--muted); padding: 4px 6px; border-bottom: 1px solid var(--line); }
.states td { padding: 3px 6px; border-bottom: 1px solid var(--line); }
.states .num { text-align: right; }
.states tbody tr.go { cursor: pointer; }
.states tbody tr.go:hover, .states tbody tr.go:focus { background: var(--hover); outline: none; }
.states tbody tr[aria-expanded="true"] { background: var(--hover); }
.states tr.detail td { padding: 6px 6px 10px; }

/* OSM history chart: one series, a 2px line over a 10% wash, hairline grid. */
.trend-title { font-size: 12px; color: var(--muted); }
.trend { position: relative; margin-top: 4px; font-size: 12px; color: var(--muted); }
.trend svg { display: block; overflow: visible; }
.trend svg:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 2px; }
.trend .grid { stroke: var(--line); stroke-width: 1; }
.trend .axis { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.trend .area { fill: var(--osm); fill-opacity: 0.1; }
.trend .line { fill: none; stroke: var(--osm); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.trend .cross { stroke: var(--muted); stroke-width: 1; }
.trend .end, .trend .focus { fill: var(--osm); stroke: var(--bg); stroke-width: 2; }
.trend .hit { fill: transparent; }
.trend .tip {
  position: absolute;
  transform: translate(-50%, -100%);
  pointer-events: none;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 3px 8px;
  white-space: nowrap;
  line-height: 1.3;
}
.trend .tip strong { display: block; color: var(--fg); font-variant-numeric: tabular-nums; }
.trend .tip span { color: var(--muted); font-size: 11px; }
.trend-note { margin: 2px 0 0; font-size: 11px; color: var(--muted); }

.sources { list-style: none; margin: 0; padding: 0; }
.sources li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.sources .sub { display: block; color: var(--muted); font-size: 12px; }

.foot { margin-top: 16px; color: var(--muted); font-size: 12px; }
.foot p { margin: 4px 0; }

/* Popups */
.maplibregl-popup-content {
  background: var(--bg);
  color: var(--fg);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  max-height: 50vh;
  overflow-y: auto;
}
.maplibregl-popup-close-button { color: var(--muted); font-size: 18px; padding: 0 6px; }
.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--bg); }
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--bg); }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--bg); }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--bg); }

.pop h3 { margin: 0 18px 2px 0; font-size: 14px; }
.pop .sub { color: var(--muted); font-size: 12px; }
.pop .bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; margin: 8px 0 4px; background: var(--line); }
.pop .bar span { display: block; height: 100%; }
.pop ul { list-style: none; margin: 6px 0 0; padding: 0; }
.pop li { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; font-variant-numeric: tabular-nums; }
.pop .osm { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 6px; }
.pop .trend-fold { width: 272px; max-width: 100%; margin-top: 4px; }
.pop .trend-fold summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.pop .trend-fold summary:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
.pop .osm .row { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.pop .osm .ratio { margin-top: 2px; }
.pop li .kind, .pop .ratio .kind { width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; display: inline-block; }
.pop .addr + .addr { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }
.pop .tagbox { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-top: 4px; }
.pop .tags { margin: 0; font: 12px/1.4 ui-monospace, Consolas, monospace; color: var(--muted); word-break: break-word; }
.pop .zoom {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 5px 12px 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg);
  font: 12.5px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  cursor: pointer;
}
.pop .zoom:hover { background: var(--hover); }
.pop .zoom:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
.pop .zoom svg { color: var(--muted); }
.pop .copy {
  flex: none;
  width: 28px;
  height: 28px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
}
.pop .copy:hover { background: var(--hover); color: var(--fg); }
.pop .copy:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
.pop .copy .icon-done { display: none; }
.pop .copy.done { border-color: var(--nad); color: var(--nad); }
.pop .copy.done .icon-copy { display: none; }
.pop .copy.done .icon-done { display: block; }
.pop .copy.failed { border-color: #d64545; color: #d64545; }

@media (max-width: 640px) {
  .panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-height: 55%;
    border-radius: 12px 12px 0 0;
  }
  .panel-body { padding: 0 16px 16px; }
  /* The panel is a bottom sheet here, so the chevron points down to close and up to open. */
  .toggle svg { transform: rotate(180deg); }
  .panel.collapsed .toggle svg { transform: none; }
  .maplibregl-ctrl-bottom-right { bottom: 64px; }
}
