:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --line: #e4e6eb;
  --text: #121620;
  --muted: #687082;
  --brand: #2470c2;
  --brand-ink: #1d5ba0;
  --brand-soft: #e8f1fb;
  --brand-grad: linear-gradient(135deg, #2b3990, #27a7df);
  --good: #158a4a;
  --warn: #c27406;
  --bad: #d42c22;
  --track: #e8eaee;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .05);
  --radius: 14px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1015;
    --card: #171a21;
    --line: #272c37;
    --text: #e9ebf0;
    --muted: #98a0b0;
    --brand: #2470c2;
    --brand-ink: #2a7fd6;
    --brand-soft: #10243a;
    --good: #2fbf6d;
    --warn: #f0a52a;
    --bad: #ff6259;
    --track: #262a33;
    --shadow: none;
    color-scheme: dark;
  }
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.6); }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1160px; margin: 0 auto; padding: 0 20px; }

h1, h2, h3, p { margin: 0; }

.ico {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

.mono { font-family: var(--mono); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); }
.topbar__in { display: flex; align-items: center; gap: 16px; height: 60px; }
.logo { display: block; height: 30px; width: auto; }
.topbar__name { color: var(--muted); font-size: 15px; padding-left: 16px; border-left: 1px solid var(--line); }

/* ---------- hero ---------- */
.hero {
  display: grid; grid-template-columns: 1fr auto; gap: 40px; align-items: center;
  padding: 40px 0 28px;
}
.hero h1 { font-size: clamp(26px, 3.2vw, 36px); line-height: 1.15; letter-spacing: -.02em; }
.lead { margin-top: 12px; color: var(--muted); max-width: 60ch; }

.client { margin: 24px 0 0; display: grid; gap: 2px; max-width: 560px; }
.client__row {
  display: grid; grid-template-columns: 170px 1fr; gap: 12px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.client__row:last-child { border-bottom: 0; }
.client dt { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.client dd { margin: 0; font-weight: 600; min-width: 0; overflow-wrap: anywhere; display: flex; align-items: center; gap: 8px; }
.client .flagimg { width: 22px; height: 16px; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0,0,0,.08); }
.skeleton { color: var(--muted); font-weight: 400; }

/* ---------- dial ---------- */
.dial { position: relative; width: 280px; height: 280px; }
.dial__ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.dial__track, .dial__bar { fill: none; stroke-width: 5; }
.dial__track { stroke: var(--track); }
.dial__bar {
  stroke: url(#dialGrad); stroke-linecap: round;
  stroke-dasharray: 0 100; transition: stroke-dasharray .3s linear;
}
.dial[data-state="idle"] .dial__bar { opacity: 0; }

.dial__start {
  position: absolute; inset: 22px; border-radius: 50%;
  border: 0; cursor: pointer; font: inherit;
  background: var(--brand-grad); color: #fff;
  font-size: 26px; font-weight: 700; line-height: 1.15; letter-spacing: .01em;
  box-shadow: 0 10px 30px -8px rgba(39, 120, 200, .55);
  transition: transform .2s ease, filter .2s ease, box-shadow .2s ease;
}
.dial__start:hover { filter: brightness(1.1); transform: scale(1.03); }
.dial__start:active { transform: scale(.98); }
.dial__start:focus-visible { outline: 3px solid var(--text); outline-offset: 4px; }
.dial[data-state="idle"] .dial__start::after {
  content: ""; position: absolute; inset: -10px; border-radius: 50%;
  border: 2px solid var(--brand); opacity: 0;
  animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse { 0% { transform: scale(.92); opacity: .5; } 100% { transform: scale(1.12); opacity: 0; } }

.dial[data-state="done"] .dial__start {
  inset: auto; left: 50%; bottom: 46px; transform: translateX(-50%);
  width: auto; height: auto; padding: 8px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; box-shadow: none;
}
.dial[data-state="done"] .dial__start:hover { transform: translateX(-50%) scale(1.03); }

.dial__live {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  pointer-events: none; opacity: 0; transition: opacity .25s;
}
.dial[data-state="running"] .dial__live,
.dial[data-state="done"] .dial__live { opacity: 1; }
.dial[data-state="running"] .dial__start { opacity: 0; pointer-events: none; transform: scale(.6); }
.dial[data-state="done"] .dial__live { padding-bottom: 40px; }
.dial__phase { color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: .08em; }
.dial__value { font-size: 64px; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.dial__unit { color: var(--muted); font-size: 15px; }

/* ---------- steps ---------- */
.steps {
  list-style: none; margin: 0 0 24px; padding: 0;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
}
.steps li { font-size: 13px; color: var(--muted); }
.steps__bar { display: block; height: 4px; border-radius: 4px; background: var(--track); overflow: hidden; margin-bottom: 6px; }
.steps__bar i { display: block; height: 100%; width: 0; background: var(--brand); border-radius: inherit; transition: width .3s linear; }
.steps li.is-active { color: var(--text); font-weight: 600; }
.steps li.is-done .steps__bar i { width: 100% !important; background: var(--good); }
.steps li.is-done { color: var(--text); }
.steps li.is-failed .steps__bar i { width: 100% !important; background: var(--bad); }

/* ---------- verdict ---------- */
.verdict {
  display: grid; grid-template-columns: 1fr auto; gap: 20px 32px; align-items: center;
  margin-bottom: 20px; padding: 20px 24px;
  background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--muted);
  border-radius: var(--radius); box-shadow: var(--shadow);
  animation: rise .35s ease both;
}
.verdict[data-rate="good"] { border-left-color: var(--good); }
.verdict[data-rate="warn"] { border-left-color: var(--warn); }
.verdict[data-rate="bad"] { border-left-color: var(--bad); }
.verdict h2 { font-size: 20px; }
.verdict[data-rate="good"] h2 { color: var(--good); }
.verdict[data-rate="warn"] h2 { color: var(--warn); }
.verdict[data-rate="bad"] h2 { color: var(--bad); }
.verdict ul { margin: 8px 0 0; padding-left: 20px; }
.verdict ul:empty { display: none; }
.verdict p { margin-top: 8px; color: var(--muted); font-size: 14px; }
.verdict__actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 600;
  transition: background-color .15s, border-color .15s;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; min-width: 0;
}
.card h3 {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 600;
}
.card h3 small { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: auto; }
.card__note { color: var(--muted); font-size: 13px; }

.metrics {
  display: grid; gap: 16px; margin-bottom: 16px;
  grid-template-columns: repeat(4, 1fr);
}
.metrics .speed { grid-column: span 2; }
.metrics .lat { grid-column: span 1; }

.speed__value, .lat__value { margin: 6px 0 2px; }
.speed__value .num { font-size: 44px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.lat__value .num { font-size: 34px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.unit { color: var(--muted); font-size: 15px; }

[data-rate="good"] .num[data-k] { color: var(--good); }
[data-rate="warn"] .num[data-k] { color: var(--warn); }
[data-rate="bad"] .num[data-k] { color: var(--bad); }
.card[data-rate="bad"] { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }

.spark { display: block; width: 100%; height: 28px; margin: 6px 0 8px; overflow: visible; }
.spark polyline { fill: none; stroke: var(--muted); stroke-width: 1.5; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
[data-rate="good"] .spark polyline { stroke: var(--good); }
[data-rate="warn"] .spark polyline { stroke: var(--warn); }
[data-rate="bad"] .spark polyline { stroke: var(--bad); }

.lat__stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 0; }
.lat__stats div { min-width: 0; }
.lat__stats dt { color: var(--muted); font-size: 12px; }
.lat__stats dd { margin: 0; font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; }

.flag { width: 20px; height: 14px; border-radius: 2px; flex: none; box-shadow: 0 0 0 1px rgba(0,0,0,.08); }
.flag--ua { background: linear-gradient(#0057b7 50%, #ffd700 50%); }
.flag--de { background: linear-gradient(#000 33.3%, #dd0000 33.3% 66.6%, #ffce00 66.6%); }
.flag--nl { background: linear-gradient(#ae1c28 33.3%, #fff 33.3% 66.6%, #21468b 66.6%); }
.ico--globe { color: var(--muted); }

/* ---------- map + trace ---------- */
.bottom { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; margin-bottom: 32px; }
.map-card { padding: 0; overflow: hidden; }
#map { height: 380px; background: var(--track); }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { font-size: 11px; }

.trace-card { display: flex; flex-direction: column; }
.trace {
  flex: 1; margin: 12px 0 0; padding: 12px 14px; min-height: 200px; max-height: 330px;
  overflow: auto; white-space: pre; font: 12px/1.55 var(--mono);
  background: #0f131a; color: #b8f5c6; border-radius: 10px;
}
.trace.is-muted { color: #8a93a3; white-space: pre-wrap; }

/* map markers */
.pin { background: none; border: 0; }
.pin span {
  display: block; width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.pin--user span { background: var(--brand); }
.pin--user::after {
  content: ""; position: absolute; left: 0; top: 0; width: 18px; height: 18px; border-radius: 50%;
  background: var(--brand); opacity: .35; animation: ping 1.8s ease-out infinite; z-index: -1;
}
@keyframes ping { from { transform: scale(1); opacity: .45; } to { transform: scale(3); opacity: 0; } }
.pin--ua span { background: linear-gradient(#0057b7 50%, #ffd700 50%); }
.pin--de span { background: linear-gradient(#000 33.3%, #dd0000 33.3% 66.6%, #ffce00 66.6%); }
.pin--nl span { background: linear-gradient(#ae1c28 33.3%, #fff 33.3% 66.6%, #21468b 66.6%); }
.leaflet-tooltip.pin-label {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px;
}
.leaflet-tooltip.pin-label::before { display: none; }

.route { stroke: var(--muted); stroke-dasharray: 6 8; transition: stroke .3s; }
.route--good { stroke: var(--good); }
.route--warn { stroke: var(--warn); }
.route--bad { stroke: var(--bad); }
.route--anim { animation: dash .8s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -14; } }

/* ---------- misc ---------- */
.footer {
  display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between;
  padding-top: 20px; padding-bottom: 32px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 13px;
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 10px;
  background: #1d222c; color: #fff; font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.25);
  z-index: 2000; animation: rise .25s ease both;
}

.noscript { position: fixed; inset: auto 0 0; padding: 12px; background: var(--bad); color: #fff; text-align: center; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metrics .speed, .metrics .lat { grid-column: auto; }
  .bottom { grid-template-columns: 1fr; }
  .verdict { grid-template-columns: 1fr; }
  .verdict__actions { justify-content: flex-start; }
}

@media (max-width: 720px) {
  .wrap { padding: 0 16px; }
  .topbar__name { display: none; }
  .hero { grid-template-columns: 1fr; gap: 28px; padding-top: 28px; }
  .dial { justify-self: center; order: -1; width: 240px; height: 240px; }
  .dial__value { font-size: 54px; }
  .client__row { grid-template-columns: 130px 1fr; }
  .steps { grid-template-columns: repeat(2, 1fr); }
  #map { height: 300px; }
}

@media (max-width: 480px) {
  .metrics { grid-template-columns: 1fr; }
  .speed__value .num { font-size: 38px; }
  .client__row { grid-template-columns: 1fr; gap: 2px; }
  .btn { flex: 1 1 auto; justify-content: center; }
}

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