:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #61656d;
  --line: #e2e2de;
  --hover: #f0f0ec;
  --ix: #0b7a8a;
  --fac: #7a7f88;
  --carrier: #d93a3a;
  --research: #8c44b0;
  --transit: #2a72c9;
  --content: #d98200;
  --infra: #2b8a3e;
  --canada: #c8102e;
  --province: #b9b4ac;
  --mask: #f7f7f5;
  --mask-opacity: 0.62;
  --chip: #eef0f2;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1d2024;
    --text: #e8e9eb;
    --muted: #9ba0a8;
    --line: #2f3338;
    --hover: #262a2f;
    --ix: #3cc3d4;
    --fac: #8d939c;
    --carrier: #ff6b6b;
    --research: #c084fc;
    --transit: #5aa2f5;
    --content: #ffb340;
    --infra: #51cf66;
    --canada: #ff6b6b;
    --province: #4a4f57;
    --mask: #0d0f11;
    --mask-opacity: 0.6;
    --chip: #2a2e34;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a; --surface: #1d2024; --text: #e8e9eb; --muted: #9ba0a8; --line: #2f3338;
  --hover: #262a2f; --ix: #3cc3d4; --fac: #8d939c; --carrier: #ff6b6b; --research: #c084fc;
  --transit: #5aa2f5; --content: #ffb340; --infra: #51cf66; --chip: #2a2e34;
  --canada: #ff6b6b; --province: #4a4f57; --mask: #0d0f11; --mask-opacity: 0.6;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  color-scheme: dark;
}

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

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.brand p { margin: 0; color: var(--muted); }
.tabs { display: flex; gap: 4px; }
.tabs button {
  border: 0; background: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--chip); color: var(--text); font-weight: 600; }

.layout { flex: 1; display: flex; min-height: 0; }
.panel {
  width: 400px; flex: none; overflow-y: auto; background: var(--surface);
  border-right: 1px solid var(--line); padding: 16px;
}
.mapwrap { flex: 1; position: relative; }
#map { position: absolute; inset: 0; background: var(--bg); }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .mapwrap { flex: none; height: 52vh; order: -1; }
  .panel { width: auto; border-right: 0; border-top: 1px solid var(--line); flex: 1; }
  .brand p { display: none; }
}

h2 { font-size: 18px; margin: 0 0 4px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 0 8px; }
.sub { color: var(--muted); margin: 0 0 12px; }
.lede { margin: 0 0 14px; }
.back { border: 0; background: none; color: var(--muted); padding: 0; margin-bottom: 10px; cursor: pointer; }
.back:hover { color: var(--text); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stat { background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li button, .row {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  border: 0; background: none; padding: 7px 8px; border-radius: 6px; cursor: pointer;
}
.list li button:hover { background: var(--hover); }
.row .name, .list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; white-space: nowrap; }
.bar { height: 4px; background: var(--ix); border-radius: 2px; opacity: .55; margin-top: 3px; }
.list .stack { flex: 1; min-width: 0; }

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 0; cursor: pointer;
  background: var(--chip); border-radius: 999px; padding: 3px 10px 3px 8px; font-size: 13px;
}
.chip:hover { outline: 1px solid var(--line); }
.none { color: var(--muted); font-style: italic; }

input[type="search"] {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; margin-bottom: 8px;
}
.note {
  background: var(--bg); border-left: 3px solid var(--content); padding: 8px 12px; border-radius: 4px; margin: 12px 0;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.rel { display: grid; gap: 4px; }
.rel h4 { margin: 10px 0 6px; font-size: 13px; }
.rel p { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
dl.terms dt { font-weight: 600; margin-top: 12px; }
dl.terms dd { margin: 2px 0 0; color: var(--muted); }

.legend {
  position: absolute; left: 12px; bottom: 28px; z-index: 500; background: var(--surface);
  border-radius: 8px; box-shadow: var(--shadow); padding: 8px 12px; font-size: 12px; line-height: 1.8;
}
.legend div { display: flex; align-items: center; gap: 8px; }
.legend label { display: flex; align-items: center; gap: 6px; cursor: pointer; color: var(--muted); }
.sym-ix { width: 14px; height: 14px; border-radius: 50%; background: var(--ix); opacity: .8; }
.sym-far { width: 14px; height: 14px; border-radius: 50%; border: 2px dashed var(--ix); }
.bar.far { background: none; border-top: 2px dashed var(--ix); height: 0; }
.sym-fac { width: 8px; height: 8px; border-radius: 2px; background: var(--fac); margin: 0 3px; }

.leaflet-container { font: inherit; }
.leaflet-tooltip.ixlabel {
  background: none; border: 0; box-shadow: none; padding: 0; font-weight: 600; font-size: 12px;
  color: var(--text); text-shadow: 0 0 3px var(--bg), 0 0 3px var(--bg), 0 0 3px var(--bg);
}
.leaflet-tooltip.ixlabel::before { display: none; }
.leaflet-tooltip.hover { background: var(--surface); color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow); }
.leaflet-tooltip.hover::before { display: none; }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 85%, transparent) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--muted); }
.leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--line); }

/* route explorer */
.pickers { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: end; margin: 8px 0 4px; }
.picker { position: relative; min-width: 0; }
.picker label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.picker input { margin: 0; }
.picks {
  position: absolute; z-index: 1000; left: 0; right: 0; top: 100%; background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 280px; overflow-y: auto;
}
.swap { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; height: 37px; width: 37px; cursor: pointer; font-size: 16px; }
.swap:hover { background: var(--hover); }
.path { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 4px 0 10px; }
.path.alt { opacity: .85; }
.arrow { color: var(--muted); }
.steps { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 10px; }
.step { display: flex; gap: 10px; align-items: flex-start; }
.step .sub { margin: 2px 0 0; }
.num, .stepnum span {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 20px; height: 20px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 700;
}
.stepnum { background: none; border: 0; }
.stepnum span { width: 18px; height: 18px; font-size: 11px; box-shadow: 0 0 0 2px var(--surface); }
button.link { border: 0; background: none; padding: 0; color: var(--ix); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
@media (max-width: 760px) { .pickers { grid-template-columns: 1fr; } .swap { justify-self: center; } }

/* measured paths */
.measured span {
  display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px;
  border-radius: 4px; background: var(--text); color: var(--surface); font-size: 11px; font-weight: 700;
  box-shadow: 0 0 0 2px var(--surface);
}
.legend .measured span { width: 16px; height: 16px; font-size: 10px; }
details.hops { margin: 8px 0; }
details.hops summary { cursor: pointer; color: var(--muted); }
details.hops table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12.5px; }
details.hops th { text-align: left; color: var(--muted); font-weight: 600; padding: 3px 4px; border-bottom: 1px solid var(--line); }
details.hops td { padding: 3px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
details.hops .num-r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; background: var(--ix); color: var(--surface); border-radius: 4px; padding: 0 5px; font-size: 11px; }

/* organizations */
.members { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.members button {
  width: 100%; text-align: left; border: 0; background: var(--bg); border-radius: 8px; padding: 8px 10px;
  cursor: pointer; display: grid; gap: 2px;
}
.members button:hover { background: var(--hover); }
.members .role { font-size: 13px; }
.members .meta { color: var(--muted); font-size: 12px; font-weight: 400; }
