/* Тест скорости СамараЛан. Одна кнопка, один экран; тема — по системе (или ?theme=dark|light) */

@font-face { font-family: Inter; font-weight: 400; font-display: swap; src: url(fonts/Inter-Regular.ttf) format("truetype"); }
@font-face { font-family: Inter; font-weight: 600; font-display: swap; src: url(fonts/Inter-SemiBold.ttf) format("truetype"); }
@font-face { font-family: Inter; font-weight: 700; font-display: swap; src: url(fonts/Inter-Bold.ttf) format("truetype"); }

:root {
  --bg: #f3f5fa;
  --glow-1: rgba(37, 99, 235, .14);
  --glow-2: rgba(224, 122, 16, .10);
  --surface: rgba(255, 255, 255, .78);
  --surface-solid: #ffffff;
  --line: rgba(15, 23, 41, .08);
  --text: #0f1729;
  --muted: #5d6679;
  --faint: #9aa3b5;
  --track: rgba(15, 23, 41, .07);
  --down: #2563eb; --down-a: #1d4ed8; --down-b: #38bdf8;
  --up: #d26900;   --up-a: #d26900;   --up-b: #f5b041;
  --ping: #7c3aed; --ping-a: #7c3aed; --ping-b: #c084fc;
  --ok: #15803d; --ok-bg: rgba(21, 128, 61, .09);
  --warn: #b45309; --warn-bg: rgba(180, 83, 9, .10);
  --start-a: #2f6bff; --start-b: #00296b;
  --start-text: #ffffff;
  --shadow: 0 10px 30px rgba(15, 23, 41, .08);
  --accent: var(--down);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #070b16;
    --glow-1: rgba(61, 123, 255, .22);
    --glow-2: rgba(255, 138, 61, .10);
    --surface: rgba(255, 255, 255, .045);
    --surface-solid: #111727;
    --line: rgba(255, 255, 255, .08);
    --text: #eef2ff;
    --muted: #97a3bb;
    --faint: #5c6880;
    --track: rgba(255, 255, 255, .07);
    --down: #5b9dff; --down-a: #3d7bff; --down-b: #5fd4ff;
    --up: #ffa94d;   --up-a: #ff8a3d;   --up-b: #ffd166;
    --ping: #b18cff; --ping-a: #8b5cf6; --ping-b: #d8b4fe;
    --ok: #4ade80; --ok-bg: rgba(74, 222, 128, .10);
    --warn: #fbbf24; --warn-bg: rgba(251, 191, 36, .10);
    --start-a: #3d7bff; --start-b: #1e3a9a;
    --shadow: 0 10px 40px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #070b16;
  --glow-1: rgba(61, 123, 255, .22);
  --glow-2: rgba(255, 138, 61, .10);
  --surface: rgba(255, 255, 255, .045);
  --surface-solid: #111727;
  --line: rgba(255, 255, 255, .08);
  --text: #eef2ff;
  --muted: #97a3bb;
  --faint: #5c6880;
  --track: rgba(255, 255, 255, .07);
  --down: #5b9dff; --down-a: #3d7bff; --down-b: #5fd4ff;
  --up: #ffa94d;   --up-a: #ff8a3d;   --up-b: #ffd166;
  --ping: #b18cff; --ping-a: #8b5cf6; --ping-b: #d8b4fe;
  --ok: #4ade80; --ok-bg: rgba(74, 222, 128, .10);
  --warn: #fbbf24; --warn-bg: rgba(251, 191, 36, .10);
  --start-a: #3d7bff; --start-b: #1e3a9a;
  --shadow: 0 10px 40px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

.s-down-a { stop-color: var(--down-a); } .s-down-b { stop-color: var(--down-b); }
.s-up-a { stop-color: var(--up-a); }     .s-up-b { stop-color: var(--up-b); }
.s-ping-a { stop-color: var(--ping-a); } .s-ping-b { stop-color: var(--ping-b); }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(60% 45% at 50% 18%, var(--glow-1), transparent 70%),
    radial-gradient(50% 40% at 85% 95%, var(--glow-2), transparent 70%),
    var(--bg);
}

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

button { font: inherit; color: inherit; }

[hidden] { display: none !important; }

/* ---------- Шапка ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px 0;
}

.brand {
  display: block;
  background: #fff;
  border-radius: 10px;
  padding: 6px 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

.brand img { display: block; height: 24px; width: auto; }

.badge {
  font-size: 13px;
  font-weight: 600;
  color: var(--ping);
  background: color-mix(in srgb, var(--ping) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--ping) 28%, transparent);
  padding: 4px 10px;
  border-radius: 999px;
}

main {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 4px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.chip i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 20%, transparent);
}

.chip.outside i { background: var(--faint); box-shadow: 0 0 0 4px color-mix(in srgb, var(--faint) 20%, transparent); }

/* ---------- Стрелка ---------- */

.stage {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.gauge {
  position: relative;
  width: min(100%, 340px);
  aspect-ratio: 1;
  margin-top: 8px;
}

.gauge svg { width: 100%; height: 100%; overflow: visible; }

.track, .arc {
  fill: none;
  stroke-width: 14;
  stroke-linecap: round;
}

.track { stroke: var(--track); stroke-dasharray: 584.34 778.85; }

.arc {
  stroke: url(#g-down);
  stroke-dasharray: 0 778.85;
  opacity: 0;
  transition: opacity .4s;
  filter: drop-shadow(0 0 10px color-mix(in srgb, var(--accent) 45%, transparent));
}

body[data-phase="up"] .arc { stroke: url(#g-up); }
body[data-phase="ping"] .arc { stroke: url(#g-ping); }
body[data-phase="up"] { --accent: var(--up); }
body[data-phase="ping"] { --accent: var(--ping); }

.dot {
  fill: #fff;
  stroke: var(--accent);
  stroke-width: 4;
  opacity: 0;
  transition: opacity .4s;
  filter: drop-shadow(0 0 8px var(--accent));
}

.ticks text {
  fill: var(--faint);
  font-size: 11px;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: middle;
  font-variant-numeric: tabular-nums;
  transition: fill .3s;
}

.ticks text.passed { fill: var(--muted); }

.ticks { opacity: 0; transition: opacity .5s .1s; }

.start {
  position: absolute;
  inset: 18%;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: var(--start-text);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: .01em;
  background: radial-gradient(circle at 30% 25%, var(--start-a), var(--start-b));
  box-shadow:
    0 18px 50px color-mix(in srgb, var(--start-a) 40%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, .25);
  transition: transform .45s cubic-bezier(.2, .8, .2, 1), opacity .35s, box-shadow .3s;
  -webkit-tap-highlight-color: transparent;
}

.start::before {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--start-a) 50%, transparent);
  animation: pulse 2.4s ease-out infinite;
}

.start:hover { transform: scale(1.03); }
.start:active { transform: scale(.97); }
.start:focus-visible { outline: 3px solid var(--down-b); outline-offset: 6px; }

@keyframes pulse {
  0% { transform: scale(.92); opacity: .9; }
  100% { transform: scale(1.22); opacity: 0; }
}

.readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transform: scale(.94);
  transition: opacity .4s .15s, transform .5s .15s cubic-bezier(.2, .8, .2, 1);
}

.phase {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  min-height: 22px;
}

.phase svg { width: 16px; height: 16px; }

.value {
  font-size: clamp(56px, 18vw, 76px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -.03em;
}

.value.wide { font-size: clamp(46px, 14vw, 60px); }

.unit { font-size: 15px; color: var(--muted); font-weight: 600; }

body[data-state="test"] .start { opacity: 0; transform: scale(.6); pointer-events: none; }
body[data-state="test"] .readout { opacity: 1; transform: none; }
/* Дуге и точке transform не трогать: поворот дуги задан атрибутом SVG, CSS его перекрыл бы */
body[data-state="test"] .ticks,
body[data-state="test"] .arc,
body[data-state="test"] .dot { opacity: 1; }

.spark {
  width: 100%;
  max-width: 420px;
  height: 56px;
  margin-top: -18px;
  opacity: 0;
  transition: opacity .4s;
}

body[data-state="test"] .spark { opacity: 1; }

.steps {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 420px;
  margin: 12px 0 0;
  padding: 0;
}

.steps li {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  transition: border-color .3s, background .3s;
}

.steps span { font-size: 12px; color: var(--muted); font-weight: 600; }
.steps b { font-size: 17px; font-weight: 700; color: var(--faint); }
.steps li[data-state="active"] { border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
.steps li[data-state="active"] b { color: var(--accent); }
.steps li[data-state="done"] b { color: var(--text); }

body[data-state="idle"] .steps,
body[data-state="idle"] .spark { display: none; }

body[data-state="idle"] main,
body[data-state="test"] main { justify-content: center; padding-bottom: 8vh; }

.hint { margin: 4px 0 0; font-size: 13px; color: var(--faint); text-align: center; }
body:not([data-state="idle"]) .hint { display: none; }

.lead {
  margin: 18px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  min-height: 24px;
}

.lead b { color: var(--text); font-weight: 600; }

body[data-state="test"] .lead { display: none; }

.link {
  margin-top: 14px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
}

.link:hover { color: var(--text); }

body:not([data-state="test"]) #cancel { display: none; }
body[data-state="result"] .stage,
body[data-state="notice"] .stage { display: none; }

/* ---------- Итог ---------- */

.result {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.result > * { animation: rise .55s cubic-bezier(.2, .8, .2, 1) both; }
.result > :nth-child(2) { animation-delay: .07s; }
.result > :nth-child(3) { animation-delay: .14s; }
.result > :nth-child(4) { animation-delay: .21s; }
.result > :nth-child(5) { animation-delay: .28s; }
.result > :nth-child(6) { animation-delay: .35s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.verdict {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 16px 18px;
  border-radius: 18px;
  background: var(--ok-bg);
  border: 1px solid color-mix(in srgb, var(--ok) 25%, transparent);
}

.verdict.warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }

.verdict .ico {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--ok);
  color: var(--bg);
}

.verdict.warn .ico { background: var(--warn); }
.verdict .ico svg { width: 22px; height: 22px; }
.verdict b { display: block; font-size: 17px; line-height: 1.3; }
.verdict span { display: block; color: var(--muted); font-size: 14px; margin-top: 2px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.tile { padding: 16px 16px 14px; position: relative; overflow: hidden; }

.tile::after {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(90deg, var(--a), var(--b));
}

.tile.down { --a: var(--down-a); --b: var(--down-b); }
.tile.up { --a: var(--up-a); --b: var(--up-b); }

.tile .lbl { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.tile .lbl svg { width: 15px; height: 15px; }
.tile.down .lbl svg { color: var(--down); }
.tile.up .lbl svg { color: var(--up); }
.tile .big { font-size: clamp(34px, 11vw, 44px); font-weight: 700; letter-spacing: -.03em; line-height: 1.15; margin-top: 6px; }
.tile .u { font-size: 13px; color: var(--muted); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); padding: 6px; }

.stat { padding: 10px 8px; text-align: center; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.stat b { font-size: 20px; font-weight: 700; }
.stat small { font-size: 12px; color: var(--muted); font-weight: 600; margin-left: 2px; }

.tips { padding: 16px 18px; }
.tips h2 { font-size: 15px; margin: 0 0 8px; }
.tips ul { margin: 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.tips li + li { margin-top: 6px; }
.tips a { color: var(--down); }

.more { padding: 4px 18px; }
.more summary { cursor: pointer; padding: 12px 0; font-weight: 600; font-size: 15px; list-style: none; display: flex; justify-content: space-between; align-items: center; }
.more summary::-webkit-details-marker { display: none; }
.more summary::after { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .25s; margin-right: 4px; }
.more[open] summary::after { transform: rotate(-135deg); }
.more dl { margin: 0 0 12px; }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.row dt { color: var(--muted); }
.row dd { margin: 0; text-align: right; font-weight: 600; }
.more .note { font-size: 13px; color: var(--warn); margin: 0 0 12px; }

.compare { padding: 6px 16px 10px; }
.compare table { width: 100%; border-collapse: collapse; font-size: 14px; }
.compare th { font-size: 12px; color: var(--muted); font-weight: 600; text-align: right; padding: 10px 0 6px; }
.compare th:first-child { text-align: left; }
.compare td { padding: 9px 0; border-top: 1px solid var(--line); text-align: right; font-weight: 700; font-size: 16px; }
.compare td:first-child { text-align: left; font-weight: 600; color: var(--text); font-size: 14px; white-space: nowrap; }
.compare td:first-child small { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.compare th, .compare td { padding-left: 8px; }
.compare th:first-child, .compare td:first-child { padding-left: 0; }
.compare td.d { font-size: 13px; font-weight: 600; color: var(--muted); }
.compare td.d.bad { color: var(--warn); }
.compare .col-in { color: var(--ok); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 4px; }

.button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 14px 16px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--start-a), var(--start-b));
  box-shadow: 0 8px 24px color-mix(in srgb, var(--start-a) 30%, transparent);
  transition: transform .15s;
}

.button:active { transform: scale(.98); }
.button.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--line); box-shadow: none; }

/* ---------- Сообщение (занято, ошибка) ---------- */

.notice { width: 100%; max-width: 420px; text-align: center; margin-top: 12vh; animation: rise .5s both; }
.notice-icon { width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 50%; display: grid; place-items: center; background: var(--warn-bg); color: var(--warn); }
.notice-icon svg { width: 30px; height: 30px; }
.notice h1 { font-size: 22px; line-height: 1.3; margin: 0 0 8px; }
.notice p { color: var(--muted); margin: 0 0 24px; }

.foot {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  padding: 8px 16px max(20px, env(safe-area-inset-bottom));
}

.foot a { color: inherit; font-weight: 600; text-decoration: none; white-space: nowrap; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--surface-solid);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
}

@media (min-width: 720px) {
  main { padding-top: 24px; }
  .gauge { width: 380px; }
}

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

/* Снимки макета (?still): без анимаций, чтобы кадр не ловил середину перехода */
html.still *, html.still *::before, html.still *::after { animation: none !important; transition: none !important; }
