/* ═══════════════════════════════════════════════════════════════
   SPOS Net — design system (v5)
   Deep-space canvas with living aurora depth, a cyan→indigo brand
   gradient for the hero, and ONE deliberate hue per metric —
   download cyan · upload violet · ping amber · jitter rose.
   Colorful and organized, never rainbow-cheap.
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg: #060913;
  --bg-lift: #0c1019;
  --panel: rgba(17, 22, 33, .72);
  --panel-2: rgba(22, 28, 42, .85);
  --panel-3: #1c2436;
  --line: rgba(148, 163, 194, .12);
  --line-2: rgba(148, 163, 194, .22);
  --txt: #eef2fa;
  --txt-2: #a5b1c8;
  --txt-3: #66738e;

  --acc: #22d3ee;                 /* brand cyan — actions, download */
  --acc-2: #818cf8;               /* brand indigo — secondary accent */
  --acc-ink: #07131f;              /* dark ink on accent surfaces */
  --acc-grad: linear-gradient(135deg, #22d3ee 0%, #3b82f6 52%, #818cf8 100%);
  --dl: #22d3ee;                   /* download — cyan */
  --ul: #a78bfa;                   /* upload — violet */
  --pg: #fbbf24;                   /* ping — amber */
  --jt: #fb7185;                   /* jitter — rose */
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;

  --gauge-track: rgba(148, 163, 194, .13);
  --tick: rgba(148, 163, 194, .38);
  --tick-minor: rgba(148, 163, 194, .16);
  --tick-label: #8b97b0;

  --sans: "IBM Plex Sans Arabic", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Sans Arabic", ui-monospace, "Cascadia Mono", monospace;   /* display numerals */
  --disp: "IBM Plex Sans Arabic", system-ui, sans-serif;                       /* wordmark & hero digits */

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --shadow-pop: 0 18px 60px rgba(0, 0, 0, .55), 0 2px 10px rgba(0, 0, 0, .4);
  --ease: cubic-bezier(.33, 1, .68, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* the hidden attribute must always win over class display rules */
[hidden] { display: none !important; }

html { background: var(--bg); -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--sans);
  color: var(--txt);
  background: transparent;   /* the aurora layers live between the html canvas and the content */
  min-height: 100vh;
  min-height: 100svh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* ── aurora: two slow-drifting glows give the canvas life and depth ── */
body::before,
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  pointer-events: none;
  will-change: transform;
}
body::before {
  top: -34vmax;
  inset-inline-end: -20vmax;
  width: 90vmax;
  height: 90vmax;
  background: radial-gradient(closest-side, rgba(34, 211, 238, .13), rgba(34, 211, 238, 0) 70%);
  animation: drift-a 26s ease-in-out infinite alternate;
}
body::after {
  bottom: -38vmax;
  inset-inline-start: -24vmax;
  width: 96vmax;
  height: 96vmax;
  background: radial-gradient(closest-side, rgba(129, 140, 248, .12), rgba(129, 140, 248, 0) 70%);
  animation: drift-b 32s ease-in-out infinite alternate;
}
@keyframes drift-a {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(-6vmax, 5vmax, 0) scale(1.08); }
}
@keyframes drift-b {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(7vmax, -4vmax, 0) scale(1.1); }
}
@media (prefers-reduced-motion: reduce) {
  body::before, body::after { animation: none; }
}

::selection { background: rgba(34, 211, 238, .32); }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ═══ layout shell ═══ */
.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  min-height: 100svh;
  max-width: 1060px;
  margin: 0 auto;
  padding: 0 clamp(16px, 3vw, 32px);
  position: relative;
}

/* ═══ header ═══ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 27px; height: 27px;
  display: block;
}
.brand-name {
  font-family: var(--disp);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .01em;
  user-select: none;
  color: var(--txt);
}

.topbar-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  color: var(--txt-2);
  transition: color .15s var(--ease), background-color .15s var(--ease);
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { color: var(--txt); background: var(--panel-2); }
.icon-btn:focus-visible { outline: 2px solid rgba(34, 211, 238, .55); outline-offset: 1px; }

.chip-btn {
  height: 32px; padding: 0 12px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  font-size: 12.5px; font-weight: 600;
  color: var(--txt-2);
  transition: color .15s var(--ease), border-color .15s var(--ease), box-shadow .2s var(--ease);
  min-width: 44px;
}
.chip-btn:hover { color: var(--txt); border-color: var(--acc); }
.chip-btn:focus-visible { outline: 2px solid rgba(34, 211, 238, .55); outline-offset: 1px; }
.chip-btn svg { width: 13px; height: 13px; }
.chip-btn.has-icon { display: inline-flex; align-items: center; gap: 6px; }

/* ═══ stage ═══ */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 2.6vh, 26px);
  padding: clamp(12px, 2.6vh, 24px) 0;
  position: relative;
}

/* ── connection line ── */
.conn-line {
  position: absolute;
  top: 4px;
  inset-inline: 0;
  min-height: 18px;
  font-size: 12.5px;
  color: var(--txt-3);
  text-align: center;
  max-width: 100%;
  padding: 0 12px;
}
#conn-text b { color: var(--txt-2); font-weight: 500; }
#conn-text bdi { unicode-bidi: isolate; }
#conn-text .sep { margin: 0 7px; opacity: .55; }

.skel {
  display: inline-block;
  width: min(340px, 60vw);
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--panel-2) 25%, var(--panel-3) 45%, var(--panel-2) 65%);
  background-size: 220% 100%;
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer {
  0% { background-position: 130% 0; }
  100% { background-position: -90% 0; }
}
html[dir="rtl"] .skel { animation-direction: reverse; }

/* ── gauge ── */
.gauge-zone { display: flex; flex-direction: column; align-items: center; gap: 4px; }

.gauge {
  position: relative;
  width: clamp(240px, 40svh, 384px);
  aspect-ratio: 1;
}
.gauge-halo {
  position: absolute; inset: 6%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(34, 211, 238, .14), rgba(129, 140, 248, .07) 55%, transparent 74%);
  transition: background 1s var(--ease);
  pointer-events: none;
}

#gauge-svg { position: absolute; inset: 0; width: 100%; height: 100%; }

/* the dial rests dimmed before the test and wakes up with the first byte */
.g-ticks { transition: opacity .5s var(--ease); }
html[data-state="idle"] .g-ticks { opacity: .6; }
html[data-state="idle"] .g-track { animation: track-breathe 3.8s ease-in-out infinite; }
@keyframes track-breathe { 50% { opacity: .45; } }

.gauge-center {
  position: absolute; inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding-top: 12px; /* optical center: dial center sits slightly high */
}

/* phase pill (during a run) */
.g-phase {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line-2);
  font-size: 11.5px; font-weight: 600;
  color: var(--txt-2);
  margin-bottom: 8px;
  letter-spacing: .01em;
}
.g-phase-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--acc);
  animation: pulse 1.3s ease-in-out infinite;
}

/* readout: number centered, unit beneath it — the big number carries
   the brand gradient so the hero feels alive the moment a byte lands */
.g-readout { display: flex; flex-direction: column; align-items: center; gap: 1px; direction: ltr; }
.g-num {
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(40px, 7.6svh, 56px);
  letter-spacing: -.01em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #ffffff 25%, #a5f3fc 75%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
html[data-state="idle"] .g-num {
  background: none;
  -webkit-text-fill-color: currentColor;
  color: var(--txt-2);
}
.g-unit {
  font-size: 12px;
  color: var(--txt-3);
  font-weight: 600;
  letter-spacing: .14em;
  line-height: 1;
  margin-top: 4px;
}

.g-grade {
  font-size: 12.5px; font-weight: 600;
  margin-top: 8px;
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px solid;
}
.g-grade.good { color: var(--ok); border-color: rgba(52, 211, 153, .35); background: rgba(52, 211, 153, .08); }
.g-grade.mid { color: var(--warn); border-color: rgba(251, 191, 36, .35); background: rgba(251, 191, 36, .08); }
.g-grade.low { color: var(--bad); border-color: rgba(248, 113, 113, .35); background: rgba(248, 113, 113, .08); }

.scale-hint {
  font-size: 10.5px;
  color: var(--txt-3);
  margin-top: 7px;
  direction: rtl;
}
html[lang="en"] .scale-hint { letter-spacing: .04em; }

/* start button — the hero of the pre-start screen: brand gradient,
   dark ink, soft glow; it must feel like THE call-to-action */
.start-btn {
  position: relative;
  width: 118px; height: 118px;
  border-radius: 50%;
  background: var(--acc-grad);
  border: 0;
  font-size: 19px;
  font-weight: 700;
  color: var(--acc-ink);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 14px 44px rgba(34, 211, 238, .34), 0 6px 22px rgba(99, 102, 241, .25);
  transition: box-shadow .2s var(--ease), transform .14s var(--ease), filter .2s var(--ease);
}
.start-btn:hover {
  filter: brightness(1.08);
  transform: translateY(-2px);
  box-shadow: 0 20px 60px rgba(34, 211, 238, .45), 0 8px 28px rgba(99, 102, 241, .32);
}
.start-btn:active { transform: scale(.96); }
.start-btn:focus-visible { outline: 2px solid rgba(165, 243, 252, .8); outline-offset: 5px; }
.start-ring {
  position: absolute; inset: -7px;
  border-radius: 50%;
  border: 2px solid rgba(34, 211, 238, .45);
  animation: start-pulse 2.8s cubic-bezier(.2, .6, .35, 1) infinite;
  pointer-events: none;
}
@keyframes start-pulse {
  0%   { transform: scale(.94); opacity: .75; }
  70%  { transform: scale(1.14); opacity: 0; }
  100% { transform: scale(1.14); opacity: 0; }
}

.start-hint {
  font-size: 12.5px;
  color: var(--txt-3);
  margin-top: 14px;
}

.stop-btn {
  display: inline-flex; align-items: center; gap: 7px;
  margin-top: 2px;
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  color: var(--txt-3);
  font-size: 12.5px;
  transition: color .15s, border-color .15s;
}
.stop-btn svg { width: 13px; height: 13px; }
.stop-btn:hover { color: var(--bad); border-color: rgba(248, 113, 113, .4); }

/* ── live speed graph ── */
.spark {
  display: block;
  width: min(880px, 100%);
  height: 56px;
}

/* ── phase chips ── */
.phases {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  flex-wrap: wrap;
  justify-content: center;
}
.ph {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--txt-3);
  font-size: 12.5px;
  transition: color .25s, border-color .25s, background-color .25s, box-shadow .25s;
}
.ph-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--txt-3);
  opacity: .5;
  transition: background-color .25s;
}
.ph-check { width: 13px; height: 13px; display: none; color: var(--ok); }
.ph-sep { color: var(--txt-3); opacity: .5; display: flex; }
.ph-sep svg { width: 14px; height: 14px; }
html[dir="rtl"] .ph-sep svg { transform: scaleX(-1); }

.ph.active {
  color: var(--txt);
  border-color: rgba(34, 211, 238, .45);
  background: rgba(34, 211, 238, .08);
}
.ph.active .ph-dot { background: var(--acc); opacity: 1; animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.ph.done { color: var(--txt-2); }
.ph.done .ph-dot { display: none; }
.ph.done .ph-check { display: block; }

/* ── metrics ── */
.metrics {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  width: min(880px, 100%);
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 2px;
}

.metric { padding: 2px 14px; text-align: center; }
.metric + .metric { border-inline-start: 1px solid var(--line); }

.m-head {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 11.5px;
  color: var(--txt-3);
  margin-bottom: 7px;
  white-space: nowrap;
}
html[lang="en"] .m-head { letter-spacing: .07em; text-transform: uppercase; font-size: 10.5px; }
.m-head svg { width: 14px; height: 14px; opacity: .8; flex: none; }

.m-val { display: flex; align-items: baseline; justify-content: center; gap: 5px; direction: ltr; }
.m-val .num {
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(19px, 3.4svh, 24px);
  font-variant-numeric: tabular-nums;
  color: var(--txt-2);
  transition: color .3s;
  min-width: 2.2ch;
}
.m-val .unit { font-size: 11px; color: var(--txt-3); }

.metric.on .m-head { color: var(--txt-2); }
.metric.on .m-head svg { opacity: 1; }
.metric.on .num { color: var(--txt); }

#m-download.on .m-head, #m-download.on .m-head svg { color: var(--dl); }
#m-download.on .num { color: #67e8f9; }
#m-upload.on .m-head, #m-upload.on .m-head svg { color: var(--ul); }
#m-upload.on .num { color: #c4b5fd; }
#m-ping.on .m-head, #m-ping.on .m-head svg { color: var(--pg); }
#m-ping.on .num { color: #fcd34d; }
#m-jitter.on .m-head, #m-jitter.on .m-head svg { color: var(--jt); }
#m-jitter.on .num { color: #fda4af; }
#m-loss.on .m-head, #m-loss.on .m-head svg { color: var(--ok); }
#m-loss.on .num { color: #6ee7b7; }
#m-loss.on .num.bad { color: var(--bad); }

/* ── actions (space always reserved — layout stays locked) ── */
.actions {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; flex-wrap: wrap;
  min-height: 46px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s var(--ease);
}
html[data-state="done"] .actions { opacity: 1; pointer-events: auto; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 18px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-2);
  color: var(--txt-2);
  font-size: 13.5px; font-weight: 500;
  transition: color .15s var(--ease), border-color .15s var(--ease), background-color .15s var(--ease), box-shadow .2s var(--ease);
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { color: var(--txt); background: var(--panel-2); border-color: var(--txt-3); }
.btn:focus-visible { outline: 2px solid rgba(34, 211, 238, .55); outline-offset: 1px; }

.btn-accent {
  background: var(--acc-grad);
  border-color: transparent;
  color: var(--acc-ink);
  font-weight: 600;
  box-shadow: 0 6px 22px rgba(34, 211, 238, .25), 0 3px 12px rgba(99, 102, 241, .18);
}
.btn-accent:hover {
  background: var(--acc-grad);
  color: var(--acc-ink);
  filter: brightness(1.08);
  border-color: transparent;
  box-shadow: 0 8px 28px rgba(34, 211, 238, .35), 0 4px 16px rgba(99, 102, 241, .25);
}

.btn-ghost { border-color: transparent; color: var(--txt-3); height: 36px; }
.btn-ghost:hover { border-color: var(--line-2); }

/* ═══ footer ═══ */
.foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 52px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: #8b97ad;
  flex-wrap: wrap;
  padding: 8px 12px;
}
.foot-side { display: flex; align-items: center; gap: 8px; }
.foot-mark { width: 20px; height: 20px; display: block; opacity: .9; }
.foot-sep { width: 1px; height: 16px; background: var(--line-2); }
/* the active webfont is named in the footer — instant visual proof the
   custom font really is the one rendering the page */
.foot-font {
  font-size: 10.5px;
  color: var(--txt-3);
  letter-spacing: .02em;
  transition: color .3s;
}
.foot-font.ok { color: rgba(110, 231, 183, .85); }
.foot-font.bad { color: var(--bad); }
.foot-credit {
  display: flex; align-items: center; gap: 7px;
  color: #9aa4b8;
  text-decoration: none;
  transition: color .15s;
}
.foot-credit b { color: var(--txt-2); font-weight: 600; }
.foot-credit:hover, .foot-credit:hover b { color: var(--acc-2); }
.foot-logo {
  width: 20px; height: 20px;
  border-radius: 6px;
  display: block;
  box-shadow: 0 0 0 1px var(--line-2);
}

/* ═══ drawers ═══ */
.scrim {
  position: fixed; inset: 0;
  background: rgba(3, 5, 10, .6);
  backdrop-filter: blur(3px);
  z-index: 50;
  animation: fade .2s var(--ease);
}
@keyframes fade { from { opacity: 0; } }

.drawer {
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  width: min(420px, calc(100vw - 20px));
  background: rgba(12, 16, 25, .96);
  backdrop-filter: blur(18px);
  border-inline-start: 1px solid var(--line);
  z-index: 60;
  display: flex; flex-direction: column;
  transform: translateX(calc(var(--dir, 1) * 105%));
  transition: transform .3s var(--ease);
}
html[dir="rtl"] .drawer { --dir: -1; }
.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 22px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.drawer-head h2 { font-size: 15px; font-weight: 600; }

.drawer-body {
  overflow-y: auto;
  padding: 20px 22px 44px;
  display: flex; flex-direction: column; gap: 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--panel-3) transparent;
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 calc(100% - 26px), transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 calc(100% - 26px), transparent 100%);
}
.drawer-body::-webkit-scrollbar { width: 8px; }
.drawer-body::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 4px; }

/* ── share sheet: centered dialog on wide screens, bottom sheet on phones ── */
.drawer.sheet {
  inset-block: auto;
  inset-inline: auto;
  top: 50%; left: 50%;
  width: min(500px, calc(100vw - 28px));
  max-height: min(88dvh, 820px);
  border: 1px solid var(--line-2);
  border-radius: 22px;
  border-inline-start: 1px solid var(--line-2);
  box-shadow: var(--shadow-pop);
  transform: translate(-50%, -47%) scale(.96);
  opacity: 0;
  visibility: hidden;          /* a closed sheet must never intercept clicks */
  pointer-events: none;
  transition: transform .28s var(--ease), opacity .2s var(--ease), visibility 0s linear .28s;
}
.drawer.sheet.open {
  visibility: visible;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  transition: transform .28s var(--ease), opacity .2s var(--ease), visibility 0s;
}

.share-body { gap: 13px; padding: 16px 18px calc(22px + env(safe-area-inset-bottom, 0px)); }
.sheet .drawer-body {
  -webkit-mask-image: none;   /* keep the last row fully visible in the bottom sheet */
  mask-image: none;
}

.fmt-seg button { flex-direction: column; gap: 3px; padding: 10px 6px; }
.fmt-seg button svg { width: 17px; height: 17px; margin-bottom: 2px; color: var(--txt-3); }
.fmt-seg button.on svg { color: var(--acc); }

.share-preview {
  flex: none;                 /* the full card must always be visible — never shrink-clip it */
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
  background: rgba(0, 0, 0, .28);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
}
.share-preview canvas {
  display: block;             /* kill the inline baseline gap */
  border-radius: 12px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .5);
  max-width: 100%;
}

.share-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}
.share-tile {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 12px 6px 10px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  color: var(--txt-2);
  font-size: 12px; font-weight: 500;
  text-align: center;
  transition: color .15s, border-color .15s, background-color .15s, box-shadow .2s;
}
.share-tile svg { width: 21px; height: 21px; }
.share-tile:hover {
  color: var(--txt);
  border-color: var(--acc);
  background: var(--panel-2);
}
.share-tile:focus-visible { outline: 2px solid rgba(34, 211, 238, .55); outline-offset: 1px; }
.share-tile.st-accent {
  background: var(--acc-grad);
  border-color: transparent;
  color: var(--acc-ink);
  font-weight: 600;
  box-shadow: 0 6px 22px rgba(34, 211, 238, .25), 0 3px 12px rgba(99, 102, 241, .18);
}
.share-tile.st-accent:hover { filter: brightness(1.08); color: var(--acc-ink); border-color: transparent; }

/* settings */
.set-group { display: flex; flex-direction: column; gap: 9px; }
.set-label { font-size: 13px; font-weight: 600; color: var(--txt-2); }
.set-hint { font-size: 11.5px; color: var(--txt-3); line-height: 1.55; }
.set-row { flex-direction: row; align-items: flex-start; justify-content: space-between; gap: 16px; }
.set-row > div { display: flex; flex-direction: column; gap: 5px; max-width: 75%; }
.set-note { font-size: 12px; color: var(--warn); }

kbd {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--txt-2);
  background: var(--panel-3);
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  white-space: nowrap;
}

.seg {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1;
  padding: 7px 6px;
  border-radius: 10px;
  font-size: 12.5px;
  color: var(--txt-3);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  transition: color .15s, background-color .15s;
}
.seg button small { font-size: 10px; opacity: .75; font-family: var(--mono); }
.seg button:hover { color: var(--txt-2); }
.seg button.on { background: var(--panel-3); color: var(--txt); box-shadow: inset 0 0 0 1px var(--line-2); }
.seg button:focus-visible { outline: 2px solid rgba(34, 211, 238, .55); outline-offset: 1px; }

.switch {
  width: 42px; height: 24px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  position: relative;
  flex: none;
  transition: background-color .2s, border-color .2s;
  margin-top: 3px;
}
/*
 * Switch knob — explicit per-direction rules (logical `inset-inline-start`
 * cannot be animated consistently, and a plain translateX travels the wrong
 * way in RTL). Track content box is 40px, knob 18px → on-state offset 20px.
 */
.switch i {
  position: absolute; top: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--txt-3);
  transition: background-color .2s;
}
html[dir="ltr"] .switch i { left: 2px; transition-property: left, background-color; }
html[dir="ltr"] .switch[aria-checked="true"] i { left: 20px; }
html[dir="rtl"] .switch i { right: 2px; transition-property: right, background-color; }
html[dir="rtl"] .switch[aria-checked="true"] i { right: 20px; }
.switch[aria-checked="true"] { background: rgba(34, 211, 238, .22); border-color: rgba(34, 211, 238, .55); }
.switch[aria-checked="true"] i { background: var(--acc-2); }

.about-block {
  border-top: 1px solid var(--line);
  padding-top: 18px;
  display: flex; flex-direction: column; gap: 9px;
}
.about-block p { font-size: 12px; color: var(--txt-3); line-height: 1.65; }
.about-credit { font-size: 11px; }
.about-credit a { color: var(--txt-3); text-decoration-color: var(--txt-3); }
.about-credit a:hover { color: var(--txt-2); }

/* details drawer */
.verdict { font-size: 12.5px; color: var(--txt-2); line-height: 1.65; }

.score-block {
  display: flex; align-items: center; gap: 18px;
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.score-num {
  font-family: var(--mono);
  font-size: 38px; font-weight: 700;
  line-height: 1;
  direction: ltr;
}
.score-side { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.score-grade { font-size: 14px; font-weight: 600; }
.score-bar { height: 5px; border-radius: 3px; background: var(--panel-3); overflow: hidden; }
.score-bar i { display: block; height: 100%; border-radius: 3px; background: var(--acc-grad); transition: width .6s var(--ease); }

.d-sec-title {
  font-size: 11.5px; font-weight: 600;
  color: var(--txt-3);
}
html[lang="en"] .d-sec-title { letter-spacing: .08em; text-transform: uppercase; }

.stat-rows { display: flex; flex-direction: column; }
.stat-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 14px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.stat-row:last-child { border-bottom: 0; }
.stat-row .k { color: var(--txt-2); }
.stat-row .v { font-family: var(--mono); font-size: 12.5px; color: var(--txt); direction: ltr; text-align: end; }
.stat-row .v small { color: var(--txt-3); font-size: 11px; }

.caps { list-style: none; display: flex; flex-direction: column; }
.cap {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.cap:last-child { border-bottom: 0; }
.cap .st { width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex: none; }
.cap .st svg { width: 11px; height: 11px; }
.cap.yes .st { background: rgba(52, 211, 153, .13); color: var(--ok); }
.cap.no .st { background: rgba(248, 113, 113, .12); color: var(--bad); }
.cap .lbl { color: var(--txt-2); flex: 1; }
.cap .res { font-size: 11.5px; color: var(--txt-3); font-family: var(--mono); }

.history { list-style: none; display: flex; flex-direction: column; }
.hrow {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 14px; align-items: baseline;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.hrow:last-child { border-bottom: 0; }
.hrow .t { color: var(--txt-3); }
.hrow .x { font-family: var(--mono); color: var(--txt-2); direction: ltr; }
.hrow .x b { color: var(--txt); font-weight: 500; }
.h-empty { font-size: 12px; color: var(--txt-3); }

.drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.drawer-actions .btn { height: 36px; padding: 0 13px; font-size: 12.5px; }

/* ═══ toast ═══ */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line-2);
  color: var(--txt-2);
  border-radius: 999px;
  padding: 9px 19px;
  font-size: 13px;
  box-shadow: var(--shadow-pop);
  z-index: 80;
  animation: rise .25s var(--ease);
  max-width: calc(100vw - 40px);
  text-align: center;
}
@keyframes rise { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }

/* ═══ noscript ═══ */
.nojs {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  color: var(--txt-2);
  padding: 30px;
  text-align: center;
  z-index: 100;
}

/* ═══ post-test sections: connection panel · suitability · history ═══ */

.connpanel, .capsrow, .history-sec {
  width: min(880px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 15px 18px 13px;
  backdrop-filter: blur(10px);
}

.cp-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 700;
  color: var(--txt-3);
  margin-bottom: 10px;
}
html[lang="en"] .cp-head { letter-spacing: .08em; text-transform: uppercase; font-size: 11px; }
.cp-head svg { width: 15px; height: 15px; opacity: .85; flex: none; }

/* connection rows — 2 columns on wide, 1 on phones */
.cp-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0 26px;
}
.cp-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  min-width: 0;
}
.cp-row:nth-last-child(-n+2):nth-child(odd),
.cp-row:last-child { border-bottom: 0; }
.cp-row .k { color: var(--txt-3); white-space: nowrap; }
.cp-row .v {
  color: var(--txt); font-weight: 500;
  font-family: var(--mono); font-size: 12.5px;
  direction: ltr; text-align: end;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cp-row .v small { color: var(--txt-3); font-size: 11px; }

.ip-toggle {
  margin-inline-start: 8px;
  padding: 1px 9px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  font-size: 10.5px; font-weight: 600;
  color: var(--acc-2);
  vertical-align: middle;
}
.ip-toggle:hover { border-color: var(--acc); }

.cp-grade { font-family: var(--disp); font-weight: 700; }
.cp-grade.good { color: var(--ok); }
.cp-grade.mid { color: var(--warn); }
.cp-grade.low { color: var(--bad); }

/* suitability chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips .chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  font-size: 12.5px; font-weight: 600;
  color: var(--txt-2);
  background: rgba(255, 255, 255, .02);
}
.chips .chip small { font-size: 10px; color: var(--txt-3); font-family: var(--mono); font-weight: 600; }
.chips .chip .st {
  width: 17px; height: 17px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
}
.chips .chip .st svg { width: 10px; height: 10px; }
.chips .chip.ok { border-color: rgba(52, 211, 153, .32); }
.chips .chip.ok .st { background: rgba(52, 211, 153, .14); color: var(--ok); }
.chips .chip.no { opacity: .55; }
.chips .chip.no .st { background: rgba(248, 113, 113, .12); color: var(--bad); }

/* history section */
.hs-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}
.hs-head .cp-head { margin-bottom: 0; }
.hs-best {
  font-size: 11.5px;
  color: var(--txt-3);
}
.hs-best b { font-family: var(--mono); color: var(--txt-2); font-weight: 700; }
.hs-best small { font-size: 10px; }
.hs-actions { display: flex; gap: 6px; }
.chip-btn.warn { color: var(--bad); border-color: rgba(248, 113, 113, .45); }

.hs-chart {
  display: block;
  width: 100%;
  height: 64px;
  margin: 12px 0 6px;
}

.hs-list { display: flex; flex-direction: column; }
.hs-row {
  display: grid;
  grid-template-columns: auto 1fr 1fr auto auto;
  gap: 8px 14px;
  align-items: center;
  padding: 7px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.hs-row:last-child { border-bottom: 0; }
.hs-row.now { background: linear-gradient(90deg, rgba(34, 211, 238, .07), rgba(129, 140, 248, .05)); border-radius: 8px; }
.hs-time { color: var(--txt-3); font-family: var(--mono); font-size: 11px; direction: ltr; }
.hs-dl, .hs-ul { display: inline-flex; align-items: center; gap: 6px; color: var(--txt-2); direction: ltr; justify-self: start; }
.hs-dl svg, .hs-ul svg { width: 12px; height: 12px; opacity: .8; flex: none; }
.hs-dl svg, .hs-ul svg { color: var(--txt-3); }
.hs-dl b, .hs-ul b { font-family: var(--mono); font-weight: 700; color: var(--txt); }
.hs-pg { color: var(--txt-3); font-family: var(--mono); direction: ltr; font-size: 11.5px; }
.hs-pg small { font-size: 9.5px; }
.hs-score {
  font-family: var(--mono); font-weight: 700; font-size: 11.5px;
  color: var(--ok);
  min-width: 2ch;
  text-align: center;
}
.hs-note { font-size: 10.5px; color: var(--txt-3); margin-top: 9px; }

/* ═══ install sheet ═══ */
.ins-hero {
  display: flex; align-items: center; gap: 14px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.ins-hero img { width: 56px; height: 56px; border-radius: 14px; flex: none; box-shadow: 0 8px 24px rgba(0, 0, 0, .4); }
.ins-hero b { font-size: 15px; display: block; margin-bottom: 3px; }
.ins-hero p { font-size: 12px; color: var(--txt-3); line-height: 1.6; }

.ins-block { display: flex; flex-direction: column; gap: 8px; }
.ins-t { font-size: 12.5px; font-weight: 700; color: var(--txt-2); }
.ins-steps ol {
  list-style: none;
  counter-reset: ins;
  display: flex; flex-direction: column; gap: 7px;
}
.ins-steps li {
  counter-increment: ins;
  display: flex; align-items: flex-start; gap: 11px;
  padding: 11px 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-size: 12.5px; color: var(--txt-2);
  line-height: 1.6;
}
.ins-steps li::before {
  content: counter(ins);
  flex: none;
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: rgba(34, 211, 238, .14);
  border: 1px solid rgba(34, 211, 238, .4);
  color: var(--acc-2);
  font-family: var(--mono);
  font-size: 11.5px; font-weight: 700;
  margin-top: 1px;
}
.ins-do { width: 100%; justify-content: center; height: 46px; font-size: 14px; }

/* ═══ responsive ═══ */

/* phones: download & upload become hero tiles, the rest a compact row */
@media (max-width: 620px) {
  .metrics {
    grid-template-columns: repeat(6, 1fr);
    gap: 10px 0;
    border-top: 0;
    padding-top: 4px;
  }
  .metric { padding: 0; }
  .metric + .metric { border-inline-start: 0; }
  #m-download { order: -3; grid-column: span 3; }
  #m-upload { order: -2; grid-column: span 3; }
  #m-ping, #m-jitter, #m-loss { grid-column: span 2; }
  #m-download .m-val .num, #m-upload .m-val .num { font-size: clamp(22px, 6.4vw, 30px); }
  #m-download, #m-upload {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 12px 8px 10px;
  }
  #m-ping, #m-jitter, #m-loss {
    background: rgba(17, 22, 33, .4);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 9px 4px 7px;
  }
  .m-head span { font-size: 11px; }

  /* post-test sections go single-column and tight on phones */
  .connpanel, .capsrow, .history-sec { padding: 12px 13px 11px; border-radius: var(--r-md); }
  .cp-grid { grid-template-columns: 1fr; gap: 0; }
  .cp-row { padding: 7px 0; }
  .cp-row:nth-last-child(-n+2):nth-child(odd) { border-bottom: 1px solid var(--line); }
  .cp-row:last-child { border-bottom: 0; }
  .hs-chart { height: 52px; margin: 9px 0 4px; }
  .hs-row { grid-template-columns: auto 1fr 1fr auto; gap: 6px 10px; padding: 6px 1px; }
  .hs-score { display: none; }
  .chips .chip { padding: 6px 11px; font-size: 12px; }
  .chips .chip small { display: none; }
}

@media (max-width: 700px) {
  .gauge { width: clamp(228px, 37svh, 300px); }
  .spark { height: 46px; }
  .start-btn { width: 104px; height: 104px; font-size: 17px; }
  .start-hint { margin-top: 10px; }
  .ph { padding: 4px 10px; font-size: 11.5px; }
  .actions { gap: 8px; }
  .btn { height: 40px; padding: 0 15px; font-size: 12.5px; }
  .foot { gap: 10px; }
  .drawer-head, .drawer-body { padding-inline: 17px; }
  .stage { gap: clamp(10px, 2vh, 18px); }

  /* share sheet becomes a bottom sheet */
  .drawer.sheet {
    top: auto; bottom: 0; left: 0; right: 0;
    width: 100%;
    max-height: 92dvh;
    border-radius: 22px 22px 0 0;
    border: 1px solid var(--line-2);
    border-bottom: 0;
    transform: translateY(105%);
  }
  .drawer.sheet.open { transform: translateY(0); }
  .share-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .share-tile { font-size: 11.5px; padding: 10px 5px 8px; gap: 6px; }
  .share-tile svg { width: 19px; height: 19px; }
  .share-tile.st-accent {
    grid-column: 1 / -1;              /* full-width hero button — no label wrapping */
    flex-direction: row;
    justify-content: center;
    padding: 12px;
    gap: 10px;
  }
  .share-preview { min-height: 0; padding: 10px; }
}

@media (max-width: 380px) {
  .actions { flex-direction: column; width: 100%; }
  .actions .btn { width: 100%; justify-content: center; }
  .share-grid { grid-template-columns: repeat(2, 1fr); }
  .brand-name { font-size: 14px; }
  .ph-sep { display: none; }
}

@media (max-height: 780px) {
  .stage { gap: 12px; padding-block: 10px; }
  .gauge { width: clamp(232px, 38svh, 350px); }
  .spark { height: 44px; }
  .metrics { padding-top: 10px; }
}

@media (max-width: 700px) and (max-height: 700px) {
  .gauge { width: clamp(216px, 34svh, 276px); }
  .stage { gap: 10px; }
  .spark { height: 38px; }
  .g-num { font-size: 36px; }
}

@media (max-height: 640px) {
  .conn-line { display: none; }
  .stage { gap: 8px; }
  .gauge { width: min(204px, 32svh); }
  .spark { height: 34px; }
  .g-num { font-size: 34px; }
  .start-btn { width: 86px; height: 86px; font-size: 15px; }
  .start-hint { display: none; }
  .foot { min-height: 40px; }
}

/* ═══ motion ═══ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* history best/count separation */
.hs-cnt { color: var(--txt-3); font-size: 11px; }
