:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #16181d;
  --muted: #646b78;
  --accent: #2f6fed;
  --accent-soft: #e6eefe;
  --yes: #137a3e;
  --yes-soft: #e3f4e9;
  --no: #8a3a2a;
  --no-soft: #f7e7e3;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --border: #2a2f39;
    --text: #e8eaee;
    --muted: #949bab;
    --accent: #6e9bff;
    --accent-soft: #1d2a47;
    --yes: #5fd18e;
    --yes-soft: #15301f;
    --no: #f0907a;
    --no-soft: #3a1f19;
    --warn: #f2c25b;
    --warn-soft: #3a2e12;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--sans);
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- header + tabs ---------- */
.top {
  position: sticky; top: 0; z-index: 1000;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.top-inner {
  max-width: 1080px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px 4px;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 650; letter-spacing: -.01em; }
.brand svg { width: 22px; height: 22px; color: var(--accent); }
.dim { color: var(--muted); font-weight: 500; }
.actions { display: flex; gap: 6px; }
.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }

.tabs {
  max-width: 1080px; margin: 0 auto;
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  padding: 6px 12px 8px; scroll-snap-type: x proximity;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: 0 0 auto; scroll-snap-align: start;
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 13px; border-radius: 999px; cursor: pointer; font-weight: 550; font-size: 14px;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }

/* ---------- layout ---------- */
main { max-width: 1080px; margin: 0 auto; padding: 16px; }
.panel { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 760px) {
  .panel { grid-template-columns: 1fr 1fr; }
  .panel > .wide { grid-column: 1 / -1; }
}

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; min-width: 0;
}
.card h2 { margin: 0 0 8px; font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.card .note { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.muted { color: var(--muted); }

/* key/value rows */
.kv { margin: 0; }
.kv > div {
  display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 12px;
  padding: 8px 0; border-top: 1px solid var(--border);
}
.kv > div:first-child { border-top: 0; }
.kv dt { color: var(--muted); font-size: 14px; }
.kv dd { margin: 0; font-family: var(--mono); font-size: 13.5px; overflow-wrap: anywhere; min-width: 0; white-space: pre-line; }
.kv dd.long { font-size: 12.5px; }
@media (max-width: 420px) {
  .kv > div { grid-template-columns: 1fr; gap: 2px; }
}

.na { color: var(--muted); font-family: var(--sans); font-style: italic; }
.pending { color: var(--muted); font-family: var(--sans); }
.pending::after { content: "…"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .2; } }

.pill {
  display: inline-block; padding: 1px 9px; border-radius: 999px; font-family: var(--sans);
  font-size: 12.5px; font-weight: 600; line-height: 1.6;
}
.pill.yes { background: var(--yes-soft); color: var(--yes); }
.pill.no { background: var(--no-soft); color: var(--no); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--accent-soft); color: var(--accent); }

/* ---------- overview ---------- */
.hero { display: grid; gap: 14px; }
@media (min-width: 760px) { .hero { grid-template-columns: 1.1fr 1fr; align-items: stretch; } }
.hero .label { font-size: 13px; color: var(--muted); }
.ip-big {
  font-family: var(--mono); font-weight: 650; letter-spacing: -.02em;
  font-size: clamp(24px, 7vw, 40px); line-height: 1.1; overflow-wrap: anywhere; margin: 2px 0 6px;
}
.ip-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.loc-line { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 550; }
.loc-line img { width: 24px; height: 18px; border-radius: 3px; box-shadow: 0 0 0 1px var(--border); }
.sub { color: var(--muted); font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.map { height: 240px; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.map.tall { height: 320px; }
.map-empty { display: grid; place-items: center; color: var(--muted); font-size: 14px; height: 100%; text-align: center; padding: 16px; }
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }
}
.leaflet-container { font: inherit; background: var(--surface-2); }

.tiles { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px;
  min-width: 0; cursor: pointer; text-align: left;
}
.tile:hover { border-color: var(--accent); }
.tile .t-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.tile .t-value { font-size: 16px; font-weight: 620; margin-top: 4px; overflow-wrap: anywhere; }
.tile .t-sub { font-size: 13px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }

/* ---------- features grid ---------- */
.feat { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; }
.feat span {
  display: flex; align-items: center; gap: 7px; font-size: 13.5px; padding: 6px 8px;
  border-radius: 8px; background: var(--surface-2); min-width: 0;
}
.feat span::before {
  content: ""; flex: 0 0 8px; height: 8px; border-radius: 50%; background: var(--no);
}
.feat span.on::before { background: var(--yes); }
.feat span.off { color: var(--muted); }
.feat-summary { font-size: 14px; color: var(--muted); margin: 0 0 10px; }
.filter { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.filter input {
  flex: 1 1 200px; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 14px;
}

/* ---------- headers / code ---------- */
pre.code {
  margin: 0; padding: 12px; border-radius: 10px; background: var(--surface-2);
  font: 12.5px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 420px; overflow: auto;
}

.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s; }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.foot { max-width: 1080px; margin: 8px auto 24px; padding: 0 16px; color: var(--muted); font-size: 12.5px; }

.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 2000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 480px) {
  #btn-download { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- charts ---------- */
:root { --s1: #2a78d6; --s2: #eb6834; --s-warn: #eda100; --grid: #e7e9ee; }
@media (prefers-color-scheme: dark) { :root { --s1: #3987e5; --s2: #d95926; --s-warn: #c98500; --grid: #262b34; } }
.chart-box { width: 100%; min-height: 120px; }
.chart { display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .tick { fill: var(--muted); font: 11px var(--sans); }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.line.s1 { stroke: var(--s1); } .line.s2 { stroke: var(--s2); }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.dot.s1 { fill: var(--s1); } .dot.s2 { fill: var(--s2); }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .bar { fill: var(--s1); }
.chart .bar.s-warn { fill: var(--s-warn); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.sw.s1 { background: var(--s1); } .sw.s2 { background: var(--s2); }
.tip {
  position: fixed; left: 0; top: 0; z-index: 3000; pointer-events: none; opacity: 0;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 9px; font-size: 12.5px; line-height: 1.45; box-shadow: 0 6px 20px rgba(0,0,0,.18); max-width: 300px;
}
.tip.show { opacity: 1; }
.tip .tip-h { font-weight: 650; }

.tile.static { cursor: default; }
.tile.static:hover { border-color: var(--border); }
.text-input {
  flex: 1 1 200px; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 14px;
}

/* ---------- latency ---------- */
.lat-list { display: grid; }
.lat-row {
  display: grid; gap: 4px 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border);
  grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name med" "bar bar" "spark meta";
}
.lat-row:first-child { border-top: 0; }
.lat-name { grid-area: name; display: flex; flex-direction: column; min-width: 0; }
.lat-name b { font-weight: 600; font-size: 14.5px; }
.lat-name span { font: 12px var(--mono); overflow-wrap: anywhere; }
.lat-med { grid-area: med; font: 650 17px var(--mono); text-align: right; }
.lat-bar { grid-area: bar; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.lat-bar i { display: block; height: 100%; width: 0; background: var(--s1); border-radius: 999px; transition: width .3s; }
.lat-spark { grid-area: spark; height: 30px; min-width: 0; }
.lat-meta { grid-area: meta; font-size: 12.5px; color: var(--muted); text-align: right; }
.spark { width: 100%; height: 30px; display: block; }
.spark .line { fill: none; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
@media (min-width: 760px) {
  .lat-row { grid-template-columns: minmax(150px, 1.1fr) 90px minmax(0, 1.4fr) 130px minmax(140px, auto); grid-template-areas: "name med bar spark meta"; }
}

/* ---------- route ---------- */
.hop-list { display: grid; }
.hop { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--border); }
.hop:first-child { border-top: 0; }
.hop-n { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font: 600 12px var(--mono); }
.hop.you .hop-n { background: #e5484d; color: #fff; }
.hop-mid { min-width: 0; font-size: 13px; }
.hop-ip { font: 13px var(--mono); overflow-wrap: anywhere; }
.hop-ms { text-align: right; font: 600 14px var(--mono); display: grid; gap: 3px; justify-items: end; }

/* ---------- privacy links ---------- */
.links { display: grid; gap: 16px; }
@media (min-width: 760px) { .links { grid-template-columns: 1fr 1fr; } }
.link-group h3 { margin: 0 0 6px; font-size: 14px; }
.link-card {
  display: grid; gap: 1px; padding: 9px 11px; margin-bottom: 6px; border-radius: 10px; background: var(--surface-2);
  text-decoration: none; color: var(--text); border: 1px solid transparent;
}
.link-card:hover { border-color: var(--accent); }
.link-card b { color: var(--accent); font-weight: 600; }
.link-card span { font-size: 13px; }
.link-host { font: 11.5px var(--mono); color: var(--muted); }
