/* Detour Map. Detour's "graphite" look: dark by default, mono labels and readouts, 1px lines, one blue accent. */
:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #14171c;
  --panel-head: #181c22;
  --line: #262b33;
  --grid: #1c2027;
  --ink: #e6e9ee;
  --ink-2: #a9b0ba;
  --muted: #6e7783;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.15);
  --ooni: #c27c2c; /* OONI layer; validated against --accent on the dark panel */
  --on-accent: #ffffff;
  /* Blocked share, 5 classes (validated ordinal ramp on --panel). */
  --c0: #2e4d7a;
  --c1: #3463ad;
  --c2: #4682e6;
  --c3: #7faeff;
  --c4: #c2daff;
  --nodata: #191d23;
  --hatch: #2a3038;
  --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", "JetBrains Mono", Consolas, ui-monospace, "SF Mono", monospace;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f3f4f6;
    --panel: #ffffff;
    --panel-head: #f7f8fa;
    --line: #dadde2;
    --grid: #eceef1;
    --ink: #14171c;
    --ink-2: #464d57;
    --muted: #6a717c;
    --accent: #2a6ee0;
    --accent-soft: rgba(42, 110, 224, 0.1);
    --ooni: #b8660f;
    --c0: #86b6ef;
    --c1: #5598e7;
    --c2: #2a78d6;
    --c3: #1c5cab;
    --c4: #0d366b;
    --nodata: #f3f4f6;
    --hatch: #d5d9df;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.mono, .label, .hint, .num, .tag { font-family: var(--mono); }
.muted { color: var(--muted); }

/* Header */
.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 600; font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; color: var(--accent); }
.tag { color: var(--muted); font-size: 12px; }
.cta {
  margin-left: auto;
  padding: 6px 12px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  font-size: 13px;
  white-space: nowrap;
}
.cta:hover { background: var(--accent); color: var(--on-accent); text-decoration: none; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  padding: 16px 24px 32px;
  max-width: 1440px;
  margin: 0 auto;
}
.side, .content { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px 16px;
  min-width: 0;
}
.panel-title { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.panel-title .hint { font-weight: 400; }
h1.panel-title { font-size: 18px; margin: 0; }
.hint { color: var(--muted); font-size: 12px; margin-left: 6px; }
.label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }

/* Controls */
.controls { display: flex; flex-direction: column; gap: 12px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.seg button {
  flex: 1;
  padding: 6px 4px;
  background: transparent;
  border: 0;
  border-left: 1px solid var(--line);
  color: var(--ink-2);
  font: 12px var(--mono);
  cursor: pointer;
}
.seg button:first-child { border-left: 0; }
.seg button:hover { background: var(--accent-soft); }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--on-accent); }
button:focus-visible, .target-list li:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Target list */
.targets { padding-bottom: 6px; }
.target-list { list-style: none; margin: 0 -8px; padding: 0; max-height: calc(100vh - 290px); min-height: 200px; overflow-y: auto; }
.target-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px 38px;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.target-list li:hover { background: var(--accent-soft); }
.target-list li[aria-selected="true"] { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.target-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.target-list .val { font: 12px var(--mono); text-align: right; color: var(--ink-2); }
.target-list .group { cursor: default; color: var(--muted); font: 11px var(--mono); text-transform: uppercase; letter-spacing: 0.06em; padding-top: 10px; display: block; }
.target-list .group:hover { background: none; }
.meter { height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 0 3px 3px 0; }
.nodata-dash { color: var(--muted); }

/* Map */
.map-panel { padding-bottom: 10px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.map-wrap { position: relative; }
#map { display: block; width: 100%; height: auto; }
#map path { stroke: var(--panel); stroke-width: 0.8; stroke-linejoin: round; transition: opacity 0.12s; }
#map path.nodata { fill: url(#hatch); }
#map path.c0 { fill: var(--c0); }
#map path.c1 { fill: var(--c1); }
#map path.c2 { fill: var(--c2); }
#map path.c3 { fill: var(--c3); }
#map path.c4 { fill: var(--c4); }
#map path.has-data { cursor: pointer; }
#map path:hover, #map path.active { stroke: var(--ink); stroke-width: 1.4; }
#map.dim path:not(.active) { opacity: 0.45; }
.hatch-bg { fill: var(--nodata); }
.hatch-line { stroke: var(--hatch); stroke-width: 1.5; }
.defs-holder { position: absolute; width: 0; height: 0; }

.map-empty {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: 420px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 13px;
  text-align: center;
}

.legend { display: flex; align-items: center; gap: 2px; font: 11px var(--mono); color: var(--muted); flex-wrap: wrap; }
.legend .sw { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.legend .sw i { display: block; width: 44px; height: 10px; }
.legend .sw:first-of-type i { border-radius: 2px 0 0 2px; }
.legend .sw.last i { border-radius: 0 2px 2px 0; }
.legend .nd { margin-left: 10px; }
.legend .nd i { width: 22px; border-radius: 2px; background: repeating-linear-gradient(45deg, var(--nodata) 0 3px, var(--hatch) 3px 4.5px); border: 1px solid var(--line); }

.region-bar { display: flex; gap: 12px; align-items: center; padding: 6px 0 0; font-size: 13px; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: 12px var(--mono); padding: 0; }

.table-view { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.table-view summary { cursor: pointer; color: var(--ink-2); font: 12px var(--mono); }

/* Tables */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font: 11px var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 400; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.data td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.data .asn { display: block; color: var(--muted); font: 11px var(--mono); }
table.data .bar { display: grid; grid-template-columns: minmax(50px, 1fr) 40px; gap: 8px; align-items: center; font: 12px var(--mono); }
table.data .empty td { color: var(--muted); text-align: center; padding: 18px 8px; }
.method { font: 12px var(--mono); color: var(--ink-2); white-space: nowrap; }

/* History */
.history { display: block; width: 100%; height: 180px; }
.history .gridline { stroke: var(--grid); stroke-width: 1; }
.history .baseline { stroke: var(--line); stroke-width: 1; }
.history .tick { fill: var(--muted); font: 10px var(--mono); }
.history .bar { fill: var(--accent); }
.history .hit { fill: transparent; }
.history .hit:hover + .bar, .history .bar.hover { fill: var(--c3); }
.history .empty { fill: var(--muted); font: 12px var(--sans); }

/* Methods */
.method-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 20px; margin: 0; }
.method-list dt { font: 600 12px var(--mono); color: var(--ink); margin-bottom: 2px; }
.method-list dd { margin: 0; color: var(--ink-2); font-size: 13px; }

.foot { color: var(--ink-2); font-size: 13px; padding: 0 4px; }
.foot p { margin: 0 0 6px; max-width: 900px; }

/* Tooltip */
.tip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  min-width: 180px;
  max-width: 280px;
  padding: 8px 10px;
  background: var(--panel-head);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  font-size: 12px;
}
.tip b { display: block; font-size: 13px; margin-bottom: 4px; }
.tip .row { display: flex; justify-content: space-between; gap: 12px; font-family: var(--mono); color: var(--ink-2); }
.tip .row span:last-child { color: var(--ink); }

/* Narrow screens */
@media (max-width: 1100px) {
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .method-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .top { padding: 10px 16px; flex-wrap: wrap; gap: 8px 12px; }
  .tag { display: none; }
  .cta { margin-left: 0; width: 100%; text-align: center; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 24px; }
  .target-list { max-height: 260px; }
  .method-list { grid-template-columns: minmax(0, 1fr); }
  .legend .sw i { width: 32px; }
  table.data { font-size: 12px; }
  table.data th, table.data td { padding: 6px 4px; }
  table.data .method { white-space: normal; }
  table.data .bar { grid-template-columns: minmax(30px, 1fr) 34px; }
}

/* Other sources */
.ext { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.ext-block { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ext-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ext-head .label { margin: 0; }
.ext-head a { font-size: 12px; }
.ext-line { font-size: 13px; line-height: 1.45; color: var(--ink-2); }
.ext-line.muted { color: var(--muted); font-size: 12px; }
.flag { font: 600 12px var(--mono); padding: 2px 6px; border: 1px solid var(--line); border-radius: 3px; color: var(--ink-2); }
.flag.on { border-color: var(--accent); color: var(--accent); }
.data.compact td, .data.compact th { padding-top: 3px; padding-bottom: 3px; }
.events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; line-height: 1.45; }
.events .mono { font-size: 12px; margin-right: 4px; }

/* OONI layer: its own colour, an "≈" in values and a legend, never mixed into our bars */
.meter.ooni > i { background: var(--ooni); }
.target-list .val.ooni { color: var(--muted); }
table.data tr.src-head td { color: var(--muted); font: 11px var(--mono); text-transform: uppercase; letter-spacing: 0.06em; padding-top: 12px; }
.history .ooni-line { fill: none; stroke: var(--ooni); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.history .ooni-dot { fill: var(--ooni); stroke: var(--panel); stroke-width: 2; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font: 11px var(--mono); color: var(--muted); margin: -4px 0 6px; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; background: var(--accent); }
.chart-legend i.line { height: 2px; width: 14px; vertical-align: 3px; background: var(--ooni); }
.tip .row.ooni span:first-child::before { content: ""; display: inline-block; width: 8px; height: 2px; margin-right: 5px; vertical-align: 3px; background: var(--ooni); }

/* Map layers */
.map-tools { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.map-tools .seg button { padding: 4px 10px; }
.map-note { margin: 0 0 8px; padding: 8px 10px; border-left: 2px solid var(--accent); background: var(--accent-soft); color: var(--ink-2); font-size: 13px; line-height: 1.45; }
.map-note a { white-space: nowrap; }
#map path.zero { fill: var(--grid); }
.legend .zero i { width: 22px; border-radius: 2px; background: var(--grid); border: 1px solid var(--line); }
@media (max-width: 820px) { .map-tools { align-items: flex-start; } }
