:root {
  --bg: #0a1020;
  --card: #0f1830;
  --surface: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8edf7;
  --muted: #8a96b3;
  --faint: #56627f;
  --grid: rgba(255, 255, 255, 0.07);
  --accent: #22d3ee;         /* brand: logo, start button */
  --dl: #3b8fe0;             /* data: download (validated pair, dark surface) */
  --ul: #cc7a1f;             /* data: upload */
  --idle: #8a96b3;           /* data: idle latency */
  --good: #3fb27f;
  --warn: #d9a03a;
  --bad: #e5534b;
  --star: #e5a03a;
  --track: rgba(255, 255, 255, 0.07);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(59, 143, 224, 0.18), transparent 60%),
    radial-gradient(800px 500px at 100% 100%, rgba(204, 122, 31, 0.07), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px clamp(16px, 4vw, 40px);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand .mark { width: 30px; height: 30px; color: var(--accent); }
.brand .name { font-weight: 700; font-size: 20px; letter-spacing: -0.01em; }
.brand .tag { font-size: 12px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 3px 9px; }
.top-left { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.mode { display: inline-flex; padding: 3px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }
.mode button {
  border: 0; background: transparent; color: var(--muted);
  font: 600 13px var(--font); padding: 6px 14px; border-radius: 999px; cursor: pointer;
}
.mode button[aria-pressed="true"] { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.mode button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 560px) { .top { flex-wrap: wrap; row-gap: 12px; } }
.ip { font-size: 13px; color: var(--muted); text-align: right; }
.ip strong { color: var(--text); font-family: var(--mono); font-weight: 500; margin-left: 6px; }

/* ---------- main ---------- */
main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 16px 32px; }

/* ---------- gauge ---------- */
.dial { position: relative; width: min(100%, 360px); aspect-ratio: 1; margin: 0 auto; }
#gauge { width: 100%; height: 100%; display: block; }
.arc-bg, .arc-val { fill: none; stroke-linecap: round; stroke-width: 16; }
.arc-bg { stroke: var(--track); }
.arc-val { filter: drop-shadow(0 0 8px rgba(59, 143, 224, 0.4)); }
body.phase-ul .arc-val { filter: drop-shadow(0 0 8px rgba(204, 122, 31, 0.4)); }
.ticks text { fill: var(--faint); font: 600 11px var(--font); text-anchor: middle; dominant-baseline: middle; }

.readout { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.readout[hidden] { display: none; }
.readout .phase { font-size: 13px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); margin-bottom: 4px; }
.readout .value { display: flex; flex-direction: column; align-items: center; line-height: 1; font-variant-numeric: tabular-nums; }
#val { font-size: clamp(40px, 12vw, 60px); font-weight: 300; letter-spacing: -0.03em; }
.readout .unit { font-size: 15px; color: var(--muted); margin-top: 8px; }

.start {
  position: absolute; left: 50%; top: 50%; translate: -50% -50%;
  width: 42%; aspect-ratio: 1; border-radius: 50%;
  border: 2px solid rgba(34, 211, 238, 0.6);
  background: radial-gradient(circle at 50% 35%, rgba(34, 211, 238, 0.18), rgba(10, 16, 32, 0.9) 70%);
  color: var(--text);
  font: 600 clamp(22px, 6vw, 30px) var(--font);
  letter-spacing: 0.08em; text-transform: uppercase; cursor: pointer;
  animation: pulse 2.4s ease-out infinite;
  transition: transform 0.15s, border-color 0.2s;
}
.start:hover { transform: scale(1.04); border-color: var(--accent); }
.start:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
.start.again { font-size: clamp(15px, 4vw, 18px); }
.start[hidden] { display: none; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.4); }
  70%  { box-shadow: 0 0 0 22px rgba(34, 211, 238, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0); }
}
@media (prefers-reduced-motion: reduce) { .start { animation: none; } }

/* simple view tiles */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; max-width: 760px; margin: 8px auto 0; }
.stats[hidden] { display: none; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; transition: border-color 0.25s, background 0.25s; }
.stat .label { display: flex; align-items: center; gap: 7px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.stat .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.stat.dl .dot { background: var(--dl); }
.stat.ul .dot { background: var(--ul); }
.stat .num { margin-top: 6px; display: flex; align-items: baseline; gap: 5px; font-variant-numeric: tabular-nums; }
.stat .num span { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.stat .num small { font-size: 12px; color: var(--muted); }
.stat.active { border-color: rgba(255, 255, 255, 0.28); background: rgba(255, 255, 255, 0.07); }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, 1fr); } }

.msg { min-height: 1.4em; text-align: center; color: var(--muted); font-size: 14px; margin: 4px 0 16px; }
.msg.err { color: #fca5a5; }

/* ---------- cards ---------- */
.results[hidden] { display: none; }
.results { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
  min-width: 0;
}
.card h2 {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 10px;
  font-size: 14px; font-weight: 600; color: var(--muted);
}
.card h2 .key { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.dl .key { background: var(--dl); }
.ul .key { background: var(--ul); }

.speed-grid { display: grid; grid-template-columns: 1fr 1fr 260px; gap: 16px; }
.row-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }

@media (max-width: 960px) {
  .speed-grid { grid-template-columns: 1fr 1fr; }
  .speed-grid .lat { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; }
}
@media (max-width: 700px) {
  .speed-grid, .row-2 { grid-template-columns: 1fr; }
  .speed-grid .lat { grid-template-columns: 1fr 1fr; }
  .brand .tag { display: none; }
}

.big { display: flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; }
.big span { font-size: clamp(38px, 6vw, 52px); font-weight: 600; letter-spacing: -0.03em; line-height: 1.05; }
.big small, .mid small { font-size: 15px; color: var(--muted); }

.speed.active { border-color: rgba(255, 255, 255, 0.22); }

/* latency column */
.lat { display: flex; flex-direction: column; gap: 18px; }
.metric h2 { margin-bottom: 4px; }
.mid { display: flex; align-items: baseline; gap: 5px; font-variant-numeric: tabular-nums; }
.mid span { font-size: 34px; font-weight: 600; letter-spacing: -0.02em; }
.loaded { display: flex; gap: 18px; margin-top: 4px; font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.arrow { font-weight: 700; margin-right: 3px; }
.arrow.dl { color: var(--dl); }
.arrow.ul { color: var(--ul); }

/* charts */
.chart { display: block; width: 100%; overflow: visible; touch-action: pan-y; }
.chart.area { height: 170px; margin-top: 12px; }
.chart.box { height: 190px; }
.chart text { fill: var(--muted); font: 11px var(--font); font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .p90 { stroke: rgba(232, 237, 247, 0.55); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .p90-label { fill: var(--text); font-size: 11px; font-weight: 600; }
.chart .ramp { fill: rgba(255, 255, 255, 0.025); }
.chart .ramp-label { fill: var(--faint); font-size: 10px; }
.chart .cross { stroke: rgba(232, 237, 247, 0.5); stroke-width: 1; }
.chart .row-label { fill: var(--text); font-size: 12px; }
.chart .row-n { fill: var(--faint); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + g .boxfill, .chart g.hover .boxfill { opacity: 0.55; }

/* quality */
.quality { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 520px) { .quality { grid-template-columns: 1fr; } }
.q { display: flex; align-items: center; gap: 12px; padding: 8px 4px; }
.q svg { width: 36px; height: 36px; flex: none; fill: none; stroke: var(--text); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.q svg .fill { fill: var(--text); stroke: none; }
.q-name { font-size: 14px; font-weight: 600; }
.stars { font-size: 17px; letter-spacing: 2px; line-height: 1.2; color: var(--star); }
.stars .off { color: rgba(255, 255, 255, 0.14); }
.q-label { font-size: 12px; color: var(--muted); }

/* bufferbloat */
.grade-wrap { display: flex; align-items: center; gap: 16px; }
.grade {
  flex: none; width: 72px; height: 72px; border-radius: 16px;
  display: grid; place-items: center;
  font-size: 34px; font-weight: 700;
  border: 2px solid var(--border); background: var(--surface);
}
.grade.good { border-color: var(--good); color: var(--good); }
.grade.warn { border-color: var(--warn); color: var(--warn); }
.grade.bad  { border-color: var(--bad);  color: var(--bad); }
.grade-wrap p { margin: 0; font-size: 14px; line-height: 1.5; color: var(--muted); }
.grade-wrap p b { color: var(--text); font-weight: 600; }

/* connection */
.conn dl { display: grid; grid-template-columns: auto 1fr; gap: 9px 16px; margin: 0; font-size: 14px; }
.conn dt { color: var(--muted); }
.conn dd { margin: 0; font-variant-numeric: tabular-nums; word-break: break-word; }

/* route / path to you */
.card h2 { flex-wrap: wrap; }
.card h2 .sub { font-weight: 400; color: var(--faint); font-size: 12px; }
@media (max-width: 560px) { .card h2 .sub { flex-basis: 100%; } }
.path { display: flex; align-items: flex-start; gap: 4px; margin: 6px 0 14px; }
.path .node { flex: none; width: 124px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; font-size: 12px; color: var(--text); }
.path .node svg {
  width: 46px; height: 46px; padding: 10px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  fill: none; stroke: var(--text); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.path .node svg .fill { fill: var(--text); stroke: none; }
.path .node small { color: var(--faint); font-family: var(--mono); font-size: 11px; white-space: nowrap; }
.path .seg { flex: 1; min-width: 0; position: relative; padding-top: 4px; text-align: center; }
.path .seg::before {
  content: ""; position: absolute; left: 0; right: 0; top: 23px;
  border-top: 2px dashed rgba(255, 255, 255, 0.18);
}
.path .seg .ms {
  position: relative; display: inline-block; padding: 2px 10px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--border);
  font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 8px;
}
.path .seg .cap { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); }
.path .seg .cap em { color: var(--faint); font-style: normal; }
.path .seg.good::before { border-top-color: rgba(63, 178, 127, 0.6); }
.path .seg.warn::before { border-top-color: rgba(217, 160, 58, 0.75); border-top-style: solid; }
.path .seg.bad::before  { border-top-color: rgba(229, 83, 75, 0.8); border-top-style: solid; }
.path .seg.warn .ms { border-color: var(--warn); }
.path .seg.bad .ms  { border-color: var(--bad); }
@media (max-width: 560px) {
  .path { flex-direction: column; align-items: stretch; }
  .path .node { width: auto; flex-direction: row; gap: 10px; text-align: left; }
  .path .node svg { width: 38px; height: 38px; padding: 8px; }
  .path .seg { padding: 2px 0 2px 19px; text-align: left; }
  .path .seg::before { left: 19px; right: auto; top: 0; bottom: 0; border-top: 0; border-left: 2px dashed rgba(255, 255, 255, 0.18); }
  .path .seg.good::before { border-left-color: rgba(63, 178, 127, 0.6); }
  .path .seg.warn::before { border-left: 2px solid var(--warn); }
  .path .seg.bad::before  { border-left: 2px solid var(--bad); }
  .path .seg .ms { margin: 4px 0 0 20px; }
  .path .seg .cap { display: inline; margin-left: 8px; }
}

.verdicts { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.verdicts li { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.45; }
.verdicts li .ic {
  flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #0a1020; margin-top: 1px;
}
.verdicts li.good .ic { background: var(--good); }
.verdicts li.warn .ic { background: var(--warn); }
.verdicts li.bad .ic  { background: var(--bad); }
.verdicts li.info .ic { background: var(--muted); }

.table-wrap { overflow-x: auto; }
.hops { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; min-width: 620px; }
.hops th, .hops td { text-align: right; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.hops th:nth-child(2), .hops td:nth-child(2) { text-align: left; white-space: normal; }
.hops th { color: var(--faint); font-weight: 600; font-size: 12px; }
.hops td:first-child { color: var(--faint); }
.hops .h-name { display: block; color: var(--text); }
.hops .h-ip { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.hops .noreply { color: var(--faint); font-style: italic; }
.hops .loss-warn { color: var(--warn); font-weight: 600; }
.hops .loss-bad { color: var(--bad); font-weight: 600; }
.hops tr.target td { background: rgba(255, 255, 255, 0.03); }
.note { margin: 10px 0 0; font-size: 12px; color: var(--faint); line-height: 1.5; }

/* tools */
.tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; max-width: 760px; margin: 28px auto 0; }
@media (max-width: 560px) { .tools { grid-template-columns: 1fr; } }
.tool {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface);
  color: var(--text); text-decoration: none; transition: border-color 0.2s, background 0.2s;
}
.tool:hover { border-color: rgba(34, 211, 238, 0.5); background: rgba(255, 255, 255, 0.06); }
.tool:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tool svg { flex: none; width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tool b { display: block; font-size: 14px; }
.tool small { display: block; font-size: 12px; color: var(--muted); }

/* details */
.details summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted); }
.details[open] summary { margin-bottom: 12px; }
.details table, .history table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.details th, .details td, .history th, .history td { text-align: right; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.details th:first-child, .details td:first-child, .history th:first-child, .history td:first-child { text-align: left; }
.details th, .history th { color: var(--faint); font-weight: 600; font-size: 12px; }
.details td:first-child { color: var(--muted); }

/* history */
.history { margin-top: 24px; }
.history h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 600; margin: 0 0 8px; }
.history[hidden] { display: none; }

/* tooltip */
.tip {
  position: fixed; z-index: 10; pointer-events: none;
  background: #1a2440; border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 10px;
  padding: 8px 10px; font-size: 12px; color: var(--muted);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.tip[hidden] { display: none; }
.tip .tv { color: var(--text); font-size: 14px; font-weight: 600; }
.tip .tk { display: inline-block; width: 12px; height: 2px; border-radius: 1px; vertical-align: middle; margin-right: 6px; }

/* ---------- footer ---------- */
footer { text-align: center; color: var(--muted); font-size: 13px; padding: 16px 16px 28px; line-height: 1.6; }
footer p { margin: 4px 0; }
footer code {
  font-family: var(--mono); font-size: 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 6px; color: var(--text); word-break: break-all;
}
footer .ver { color: var(--faint); font-size: 12px; margin-top: 10px; }

/* ---------- plain-language finding + support code ---------- */
.finding[hidden], .code-box[hidden], .wifiman[hidden], .tools[hidden] { display: none; }
.finding {
  max-width: 760px; margin: 0 auto 18px; padding: 16px 18px;
  border: 1px solid var(--border); border-radius: 16px; background: var(--card);
}
.f-main { display: flex; gap: 14px; align-items: flex-start; }
.f-ic {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font-size: 18px; font-weight: 700; color: #0a1020; background: var(--muted);
}
.finding.good .f-ic { background: var(--good); }
.finding.warn .f-ic { background: var(--warn); }
.finding.bad  .f-ic { background: var(--bad); }
.finding.good { border-color: rgba(63, 178, 127, 0.45); }
.finding.warn { border-color: rgba(217, 160, 58, 0.55); }
.finding.bad  { border-color: rgba(229, 83, 75, 0.6); }
.f-title { margin: 4px 0 2px; font-size: 18px; font-weight: 700; }
.f-text { margin: 0; font-size: 15px; line-height: 1.5; color: var(--text); opacity: 0.85; }
.f-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.f-actions:empty { display: none; }

.code-box {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border);
}
.code-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.code { font-family: var(--mono); font-size: 26px; letter-spacing: 0.12em; color: var(--text); }
.code-hint { flex-basis: 100%; font-size: 13px; color: var(--muted); }

/* ---------- WiFiman ---------- */
.wifiman {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  max-width: 760px; margin: 28px auto 0; padding: 14px 16px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface);
}
.wifiman > svg { flex: none; width: 30px; height: 30px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; }
.wifiman > svg .fill { fill: var(--accent); stroke: none; }
.wm-text { flex: 1 1 260px; min-width: 0; }
.wm-text b { display: block; font-size: 15px; }
.wm-text small { display: block; font-size: 13px; color: var(--muted); line-height: 1.45; }
.wm-links { display: flex; flex-wrap: wrap; gap: 8px; }
.store {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: 10px;
  background: var(--text); color: #0a1020; text-decoration: none; font: 600 14px var(--font); white-space: nowrap;
}
.store:hover { background: #fff; }
.store:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.store svg { width: 18px; height: 18px; fill: currentColor; }

footer .privacy { color: var(--faint); font-size: 12px; }
