:root {
  --paper: #E9EDF0;
  --panel: #F6F8F9;
  --ink: #18212C;
  --muted: #5B6875;
  --rule: #CBD3DA;
  --down: #2457D6;
  --up: #B87500;
  --good: #1F8A5B;
  --warn: #B87500;
  --bad: #C23B2E;
  --focus: #2457D6;
  --grid: rgba(24, 33, 44, 0.07);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #141A21;
    --panel: #1B232C;
    --ink: #E4E9EE;
    --muted: #93A0AD;
    --rule: #2C3743;
    --down: #6E97FF;
    --up: #F0B23A;
    --good: #4CC28E;
    --warn: #F0B23A;
    --bad: #FF7A6B;
    --focus: #6E97FF;
    --grid: rgba(228, 233, 238, 0.06);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #141A21; --panel: #1B232C; --ink: #E4E9EE; --muted: #93A0AD; --rule: #2C3743;
  --down: #6E97FF; --up: #F0B23A; --good: #4CC28E; --warn: #F0B23A; --bad: #FF7A6B;
  --focus: #6E97FF; --grid: rgba(228, 233, 238, 0.06); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Archivo", system-ui, sans-serif;
  font-variation-settings: "wdth" 100;
  font-size: 16px;
  line-height: 1.5;
}
main, .top, footer { max-width: 960px; margin: 0 auto; padding: 0 16px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 2px; }

/* header */
.top { display: flex; align-items: baseline; gap: 12px; padding-top: 24px; padding-bottom: 24px; flex-wrap: wrap; }
.brand { color: var(--ink); font-weight: 750; font-size: 1.125rem; text-decoration: none; font-variation-settings: "wdth" 112; }
.brand-sub { color: var(--muted); }
.ip { margin-left: auto; color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }

/* hero */
.hero {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 6px;
  height: clamp(260px, 42vw, 380px);
  overflow: hidden;
}
#trace { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.readout {
  position: absolute; left: 24px; top: 20px; right: 24px; z-index: 1;
  display: flex; flex-direction: column; gap: 2px; pointer-events: none;
}
.phase { font-weight: 600; color: var(--muted); }
.phase[data-dir="download"] { color: var(--down); }
.phase[data-dir="upload"] { color: var(--up); }
.big {
  font-variation-settings: "wdth" 125;
  font-weight: 780;
  font-size: clamp(3.5rem, 13vw, 7.5rem);
  line-height: 0.95;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.unit { font-size: 0.24em; font-weight: 600; letter-spacing: 0; margin-left: 0.3em; color: var(--muted); font-variation-settings: "wdth" 100; }
.target { color: var(--muted); font-size: 0.9375rem; }

/* controls */
.controls { display: flex; align-items: center; gap: 24px; margin: 20px 0 8px; flex-wrap: wrap; }
.start {
  font: inherit; font-weight: 700; font-size: 1.0625rem;
  background: var(--ink); color: var(--paper);
  border: 0; border-radius: 4px; padding: 14px 28px; cursor: pointer;
  min-width: 160px;
}
@media (hover: hover) {
  .start:hover:not(:disabled) { background: var(--down); color: #fff; }
}
.start:disabled { opacity: 0.45; cursor: progress; }
.start.running, .start.running:hover { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px var(--ink); cursor: pointer; }

.steps { list-style: none; display: flex; gap: 0; margin: 0; padding: 0; counter-reset: s; }
.steps li { counter-increment: s; color: var(--muted); padding: 0 14px; position: relative; font-size: 0.9375rem; }
.steps li + li::before { content: ""; position: absolute; left: -6px; top: 50%; width: 12px; height: 1px; background: var(--rule); }
.steps li::after { content: ""; }
.steps li[data-state="active"] { color: var(--ink); font-weight: 650; }
.steps li[data-state="done"] { color: var(--ink); }
.steps li[data-state="done"]::before { background: var(--ink); }

/* results */
.results {
  display: grid; grid-template-columns: repeat(4, 1fr); margin: 24px 0 48px;
  border-top: 1px solid var(--rule);
}
.r { padding: 14px 16px 0 0; }
.r + .r { padding-left: 16px; border-left: 1px solid var(--rule); }
.r dt { color: var(--muted); font-size: 0.875rem; }
.r dd { margin: 0; font-variation-settings: "wdth" 118; font-weight: 700; font-size: 2rem; font-variant-numeric: tabular-nums; line-height: 1.2; }
.r dd small { font-size: 0.875rem; font-weight: 500; color: var(--muted); margin-left: 6px; font-variation-settings: "wdth" 100; }
.r-down dt { color: var(--down); }
.r-up dt { color: var(--up); }

/* sections */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
h2 { font-size: 1.25rem; font-weight: 700; margin: 0; font-variation-settings: "wdth" 112; }
.link { font: inherit; font-size: 0.875rem; color: var(--down); background: none; border: 0; padding: 4px 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.regions, .history { margin-bottom: 48px; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 0.8125rem; padding: 8px 0; border-bottom: 1px solid var(--rule); }
td { padding: 12px 0; border-bottom: 1px solid var(--rule); vertical-align: middle; }
th.num, td.num { text-align: right; }
.lat-col { width: 45%; }

.node-pick { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.node-pick input { accent-color: var(--down); width: 18px; height: 18px; margin: 0; flex: none; }
.node-name { font-weight: 650; }
.node-loc { color: var(--muted); font-size: 0.875rem; display: block; line-height: 1.3; }
.nearest { font-size: 0.75rem; font-weight: 600; color: var(--good); margin-left: 6px; }

.lat { display: flex; align-items: center; gap: 12px; }
.lat-bar { flex: 1; height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; }
.lat-bar i { display: block; height: 100%; width: 0; background: var(--good); border-radius: 3px; transition: width 400ms ease; }
.lat-bar i.mid { background: var(--warn); }
.lat-bar i.slow { background: var(--bad); }
.lat-val { width: 64px; text-align: right; font-size: 0.9375rem; }
.lat-val.err { color: var(--bad); }

.empty { color: var(--muted); margin: 8px 0 0; }

footer { color: var(--muted); font-size: 0.875rem; padding-bottom: 40px; }
footer p { max-width: 64ch; margin: 0; }

@media (max-width: 640px) {
  .results { grid-template-columns: 1fr 1fr; }
  .r:nth-child(3) { padding-left: 0; border-left: 0; }
  .r:nth-child(n+3) { border-top: 1px solid var(--rule); margin-top: 14px; }
  .hero { height: 340px; }
  .readout { left: 16px; right: 16px; top: 16px; }
  .lat-col { width: 40%; }
  .lat-val { width: 52px; }
  .history th:nth-child(2), .history td:nth-child(2) { display: none; }
  .steps li { padding: 0 10px; }
  .steps li:first-child { padding-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .lat-bar i { transition: none; }
}
