/* ============================================================
   speed.halidov.com — dial layout (Speedtest.net-style instrument)
   ============================================================ */

:root {
  --bg: #141526;
  --bg-2: #0B0C14;
  --panel: #1B1D31;
  --panel-2: #23263D;

  --ink: #FFFFFF;
  --ink-dim: #9AA0BC;
  --ink-faint: #616880;

  --line: #2E3252;

  --down: #00C1FF;
  --up:   #FF9633;
  --ping: #A855F7;
  --go:   #00C1FF;

  --good: #37D67A;
  --warn: #FFB020;
  --bad:  #FF4D5E;

  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;
  --gutter: clamp(16px, 4vw, 40px);

  --r-md: 10px; --r-lg: 16px; --r-pill: 999px;

  --ease: cubic-bezier(.16, 1, .3, 1);
  --cur: var(--down);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  background-image:
    radial-gradient(120% 80% at 50% 0%, #1E2140 0%, #141526 45%, #0B0C14 100%);
  background-repeat: no-repeat;
  background-attachment: fixed;
}

.num {
  font-family: "Inter", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

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

:focus-visible { outline: 2px solid #7FD3FF; outline-offset: 3px; border-radius: 6px; }
a { color: inherit; text-decoration: none; }
.wrap { max-width: 860px; margin: 0 auto; padding: 0 var(--gutter); }

/* ============================== header ============================== */
header { padding: var(--s4) 0 0; }
.hdr { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); }

.brand { display: flex; align-items: center; gap: var(--s2); font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand .dotmark {
  width: 22px; height: 22px; border-radius: 50%;
  background: conic-gradient(from 210deg, #00C1FF, #A855F7, #FF9633, #00C1FF);
  display: grid; place-items: center;
}
.brand .dotmark::after {
  content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--bg-2);
}

.meta-chip {
  display: inline-flex; align-items: center; gap: var(--s2);
  font-size: 12px; color: var(--ink-dim);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-pill); padding: 6px 13px;
  max-width: 60vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.meta-chip strong { color: var(--ink); font-weight: 500; }
.meta-chip .wifi {
  width: 6px; height: 6px; border-radius: 50%; background: var(--good); flex: none;
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--good) 22%, transparent);
}

/* ============================== picker ============================== */
.picker { margin-top: var(--s5); }
.picker-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--s3); margin-bottom: var(--s2);
}
.picker-head .lbl {
  font-size: 11px; font-weight: 600; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-faint);
}
.picker-head .cnt { font-size: 11px; color: var(--ink-faint); }

.targets { display: flex; gap: var(--s2); overflow-x: auto; padding-bottom: 4px; }
.targets::-webkit-scrollbar { height: 4px; }
.targets::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }

.tgt {
  appearance: none; cursor: pointer; flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--s2);
  background: var(--panel); border: 1px solid var(--line); color: var(--ink-dim);
  font: inherit; font-size: 13px; padding: 8px 14px; border-radius: var(--r-pill);
  transition: border-color .2s, color .2s, background .2s;
}
.tgt:hover { border-color: var(--ink-faint); color: var(--ink); }
.tgt[aria-pressed="true"] {
  border-color: var(--down); color: #fff;
  background: color-mix(in oklab, var(--down) 14%, var(--panel));
}
.tgt .flag { font-size: 15px; line-height: 1; }
.tgt .nm { font-weight: 500; white-space: nowrap; }
.tgt .cc { font-size: 10.5px; color: var(--ink-faint); white-space: nowrap; }
.tgt .ms {
  font-size: 10px; font-variant-numeric: tabular-nums; font-weight: 600;
  padding: 1px 5px; border-radius: 3px; background: var(--panel-2);
  color: var(--ink-faint); white-space: nowrap;
}
.tgt[aria-pressed="true"] .ms { background: color-mix(in oklab, var(--down) 26%, var(--panel-2)); color: #CFF0FF; }
.tgt[aria-pressed="true"] .cc { color: var(--ink-dim); }
.tgt .tagk {
  font-size: 9px; letter-spacing: .06em; text-transform: uppercase; font-weight: 600;
  padding: 1px 5px; border-radius: 3px; background: var(--panel-2); color: var(--ink-faint);
}
.tgt[aria-pressed="true"] .tagk { background: color-mix(in oklab, var(--down) 26%, var(--panel-2)); color: #CFF0FF; }

/* ============================== dial ============================== */
.dial-zone { display: flex; justify-content: center; margin-top: var(--s4); }

.dial {
  position: relative;
  width: min(86vw, 420px);
  aspect-ratio: 1;
  --r: 46%;
}

.dial svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }

/* числата по скалата, позиционирани в проценти от квадрата на циферблата */
.dial-labels { position: absolute; inset: 0; pointer-events: none; }
.dial-labels span {
  position: absolute; transform: translate(-50%, -50%);
  font-size: 10.5px; font-weight: 600; color: #5C6485;
  font-variant-numeric: tabular-nums; letter-spacing: .02em;
}

.dial-track { fill: none; stroke: #262A45; stroke-width: 12; }
.dial-track-marks { stroke: #3A3F63; }
.dial-base { stroke: #C9CFEA; stroke-width: 2; opacity: .5; }

/* the value arc: three segments (ping / down / up) share one geometry */
.arc { fill: none; stroke-width: 12; stroke-linecap: round; transition: stroke .25s linear; }
.arc-ping { stroke: var(--ping); opacity: .9; }
.arc-down { stroke: var(--down); }
.arc-up   { stroke: var(--up); }

/* needle */
.needle { stroke: #fff; stroke-width: 2.5; stroke-linecap: round; opacity: 0; transition: opacity .3s ease; }
.dial[data-phase="latency"] .needle,
.dial[data-phase="download"] .needle,
.dial[data-phase="upload"] .needle,
.dial[data-phase="done"] .needle { opacity: 1; }
.needle-hub { fill: #fff; opacity: 0; transition: opacity .3s ease; }
.dial[data-phase="latency"] .needle-hub,
.dial[data-phase="download"] .needle-hub,
.dial[data-phase="upload"] .needle-hub,
.dial[data-phase="done"] .needle-hub { opacity: 1; }
.needle-hub-in { fill: var(--bg-2); }

/* dial centre readout */
.dial-center {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
  pointer-events: none;
  /* числото и етикетът сядат по-ниско от центъра, за да не се блъскат с иглата */
  padding-top: 30%;
}
.dial-center .readout-label {
  font-size: 11px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-dim); margin-bottom: 6px;
  /* етикетът е под иглата — даваме му собствен слой */
  position: relative; z-index: 4;
}
.dial-center .figure {
  font-size: clamp(44px, 13vw, 68px); font-weight: 700; line-height: .95;
  letter-spacing: -.03em; color: #fff;
  transition: color .2s linear;
  /* числото сяда над центъра, за да не се блъска с главината на иглата */
  position: relative; z-index: 3;
}
.dial-center .unit {
  font-size: 13px; font-weight: 500; color: var(--ink-dim);
  letter-spacing: .06em; margin-top: 2px;
}
.dial[data-phase="down"] .figure { color: #fff; }
.dial[data-phase="up"] .figure { color: var(--up); }

/* GO button sits under the dial, like a shutter */
.go-row { display: flex; justify-content: center; margin-top: calc(var(--s5) * -1); position: relative; z-index: 5; }

.btn-go {
  appearance: none; cursor: pointer;
  width: 118px; height: 118px; border-radius: 50%;
  border: 3px solid var(--go);
  background: radial-gradient(circle at 50% 40%, #2A3A6B 0%, #1A2040 70%);
  color: #fff; font: inherit; font-weight: 700; font-size: 17px; letter-spacing: .04em;
  display: grid; place-content: center;
  box-shadow: 0 0 0 6px color-mix(in oklab, var(--go) 12%, transparent),
              0 14px 40px -12px color-mix(in oklab, var(--go) 70%, transparent);
  transition: transform .15s ease, box-shadow .25s ease, border-color .25s ease;
}
.btn-go:hover { transform: scale(1.03); }
.btn-go:active { transform: scale(.97); }
.btn-go[data-running="true"] {
  border-color: var(--bad);
  box-shadow: 0 0 0 6px color-mix(in oklab, var(--bad) 14%, transparent);
  font-size: 13px;
}
.btn-go .sub2 { display: block; font-size: 10px; font-weight: 500; color: var(--ink-dim); margin-top: 3px; letter-spacing: .06em; }

/* progress ring around GO while running */
.go-ring { position: absolute; width: 132px; height: 132px; pointer-events: none; }
.go-ring circle { fill: none; stroke-width: 3; stroke-linecap: round; }
.go-ring .trk { stroke: var(--line); }
.go-ring .val { stroke: var(--cur); transition: stroke-dashoffset .25s linear, stroke .25s linear; }

/* ============================== metrics ============================== */
.metrics {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s3);
  margin-top: var(--s6);
}
.metric {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s4); display: flex; align-items: center; gap: var(--s3);
  transition: border-color .3s ease;
}
.metric:hover { border-color: var(--line); }
.metric .ico {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: var(--panel-2);
}
.metric .ico svg { width: 20px; height: 20px; }
.metric.ping .ico { color: var(--ping); }
.metric.down .ico { color: var(--down); }
.metric.up   .ico { color: var(--up); }

.metric .lbl {
  font-size: 10.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-faint);
}
.metric .val {
  font-size: 26px; font-weight: 700; line-height: 1.1; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; color: var(--ink-faint);
  transition: color .3s ease;
}
.metric .val .u { font-size: 11px; font-weight: 500; color: var(--ink-faint); margin-left: 3px; letter-spacing: .04em; }
.metric[data-done="true"] .val { color: #fff; }
.metric[data-done="true"].down .val { color: var(--down); }
.metric[data-done="true"].up .val { color: var(--up); }
.metric[data-done="true"].ping .val { color: #fff; }

/* ============================== status line ============================== */
.status {
  margin-top: var(--s4); text-align: center; font-size: 12.5px; color: var(--ink-faint);
  min-height: 20px; letter-spacing: .02em;
}
.status b { color: var(--ink-dim); font-weight: 500; }

/* ============================== bufferbloat ============================== */
.bloat {
  margin-top: var(--s4); background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: var(--s4); display: grid;
  grid-template-columns: auto 1fr auto; gap: var(--s4); align-items: center;
}
.bloat .grade {
  font-size: 26px; font-weight: 800; min-width: 46px; height: 46px;
  display: grid; place-items: center; border-radius: var(--r-md);
  background: var(--panel-2); color: var(--ink-faint);
  transition: color .35s ease, background .35s ease;
}
.bloat .grade[data-g="A+"], .bloat .grade[data-g="A"] { color: var(--good); background: color-mix(in oklab, var(--good) 12%, var(--panel-2)); }
.bloat .grade[data-g="B"] { color: var(--warn); background: color-mix(in oklab, var(--warn) 12%, var(--panel-2)); }
.bloat .grade[data-g="C"] { color: var(--warn); background: color-mix(in oklab, var(--warn) 16%, var(--panel-2)); }
.bloat .grade[data-g="D"], .bloat .grade[data-g="F"] { color: var(--bad); background: color-mix(in oklab, var(--bad) 14%, var(--panel-2)); }
.bloat .bt { font-size: 10.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); }
.bloat .bv { font-size: 12.5px; color: var(--ink-dim); margin-top: 2px; font-variant-numeric: tabular-nums; }
.bloat .scale-bar { display: flex; gap: 3px; }
.bloat .seg { width: 14px; height: 5px; border-radius: 2px; background: var(--panel-2); transition: background .35s ease; }
.bloat .seg.on { background: currentColor; }

/* ============================== detail + history ============================== */
.section-h {
  font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-faint); margin: var(--s6) 0 var(--s2);
}
.detail { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.drow {
  display: grid; grid-template-columns: 1.2fr repeat(4, 1fr); gap: var(--s3);
  padding: 10px var(--s4); font-size: 12.5px; color: var(--ink-dim);
  border-bottom: 1px solid #23263C;
}
.drow:last-child { border-bottom: 0; }
.drow.head { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); background: #191B2E; }
.drow span:not(:first-child) { font-variant-numeric: tabular-nums; color: var(--ink); text-align: right; }
.drow.head span:not(:first-child) { color: var(--ink-faint); }

.hrow {
  display: grid; grid-template-columns: 1.4fr repeat(3, 1fr) 70px;
  gap: var(--s3); align-items: center; padding: 10px var(--s4);
  font-size: 12.5px; color: var(--ink-dim); border-bottom: 1px solid #23263C;
}
.hrow:last-child { border-bottom: 0; }
.hrow .t { color: var(--ink-faint); font-size: 11.5px; }
.hrow .n { font-variant-numeric: tabular-nums; color: #fff; text-align: right; font-weight: 600; }
.hrow .n.dl { color: var(--down); }
.hrow .n.up { color: var(--up); }
.spark { display: flex; align-items: flex-end; gap: 1.5px; height: 16px; justify-content: flex-end; }
.spark i { width: 2px; background: var(--down); opacity: .6; border-radius: 1px; min-height: 1px; }
.empty { padding: var(--s4); color: var(--ink-faint); font-size: 12.5px; text-align: center; }

.share {
  margin-top: var(--s3); display: none; text-align: center; font-size: 12.5px; color: var(--ink-dim);
}
.share a { color: var(--down); font-weight: 600; }

/* ============================== verdict ============================== */
.verdict {
  margin: var(--s4) auto 0; max-width: 620px; text-align: center;
  font-size: 14px; color: var(--ink-dim); max-height: 0; overflow: hidden; opacity: 0;
  transition: max-height .45s var(--ease), opacity .35s ease, margin .45s var(--ease);
}
.verdict.has { max-height: 6em; opacity: 1; }
.verdict b { color: #fff; font-weight: 600; }

/* ============================== footer ============================== */
footer {
  margin-top: var(--s7); padding: var(--s5) 0 var(--s7);
  border-top: 1px solid var(--line); font-size: 11.5px; color: var(--ink-faint);
  text-align: center; line-height: 1.7;
}
footer .mono { font-variant-numeric: tabular-nums; }

/* ============================== modal ============================== */
.modal {
  position: fixed; inset: 0; z-index: 100; display: none;
  align-items: center; justify-content: center; padding: var(--s4);
  background: rgb(6 7 12 / .82); backdrop-filter: blur(6px);
}
.modal.open { display: flex; }
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg);
  max-width: 420px; width: 100%; padding: var(--s5);
  max-height: 90vh; overflow-y: auto;
}
.modal-card h3 { margin: 0 0 var(--s2); font-size: 17px; font-weight: 700; }
.modal-card p { margin: 0 0 var(--s4); color: var(--ink-dim); font-size: 12.5px; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s3) 0; border-bottom: 1px solid #23263C; }
.opt label { font-size: 13px; }
.opt .desc { font-size: 11px; color: var(--ink-faint); margin-top: 2px; }
.seg-ctl { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.seg-ctl button {
  appearance: none; background: none; border: 0; color: var(--ink-dim); font: inherit;
  font-size: 12px; padding: 6px 11px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.seg-ctl button[aria-pressed="true"] { background: var(--down); color: #06121C; font-weight: 700; }
.modal-close {
  margin-top: var(--s4); width: 100%; height: 42px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--panel-2); color: #fff;
  font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.modal-close:hover { border-color: var(--ink-faint); }

.linkbtn {
  appearance: none; background: none; border: 0; color: var(--ink-dim);
  font: inherit; font-size: 12.5px; cursor: pointer; padding: 0;
  border-bottom: 1px dotted var(--ink-faint);
}
.linkbtn:hover { color: #fff; border-color: #fff; }

/* ============================== responsive ============================== */
@media (max-width: 720px) {
  .metrics { grid-template-columns: 1fr; gap: var(--s2); }
  .metric { padding: var(--s3) var(--s4); }
  .metric .val { font-size: 22px; }
  .drow { grid-template-columns: 1fr repeat(2, 1fr); }
  .drow span:nth-child(n+4) { display: none; }
  .hrow { grid-template-columns: 1.3fr repeat(2, 1fr); }
  .hrow .spark, .hrow .n.ping { display: none; }
  .bloat { grid-template-columns: auto 1fr; }
  .bloat .scale-bar { display: none; }
  .dial { width: min(80vw, 320px); }
  .btn-go { width: 96px; height: 96px; font-size: 15px; }
  .go-ring { width: 108px; height: 108px; }
}

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