:root, html[data-theme="dark"] {
  --bg: #070b14;
  --bg-elev: rgba(12, 18, 32, 0.72);
  --ink: #f4f7fb;
  --muted: #93a4bd;
  --line: rgba(148, 163, 184, 0.18);
  --cyan: #22d3ee;
  --teal: #2dd4bf;
  --lime: #a3e635;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #fb7185;
  --btn-face: linear-gradient(155deg, #1a3a5c, #0d223c 60%, #0a1a30);
  --orb-a: rgba(45, 212, 191, 0.35);
  --orb-b: rgba(34, 211, 238, 0.22);
  --font: "Outfit", system-ui, sans-serif;
  --display: "Syne", "Outfit", sans-serif;
}

html[data-theme="light"] {
  --bg: #f3f6fb;
  --bg-elev: rgba(255, 255, 255, 0.86);
  --ink: #0f172a;
  --muted: #5b6b82;
  --line: rgba(15, 23, 42, 0.1);
  --cyan: #0891b2;
  --teal: #0d9488;
  --lime: #65a30d;
  --ok: #059669;
  --warn: #d97706;
  --bad: #e11d48;
  --btn-face: linear-gradient(155deg, #e0f2fe, #ccfbf1 55%, #ecfeff);
  --orb-a: rgba(13, 148, 136, 0.18);
  --orb-b: rgba(8, 145, 178, 0.14);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  color: var(--ink);
  font-family: var(--font);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(2rem, env(safe-area-inset-bottom));
  overflow-x: hidden;
  transition: background 0.25s ease, color 0.25s ease;
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(70px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.55;
}
.orb-a {
  width: min(420px, 90vw); height: min(420px, 90vw);
  top: -100px; left: 50%;
  transform: translateX(-55%);
  background: radial-gradient(circle, var(--orb-a), transparent 70%);
}
.orb-b {
  width: min(320px, 80vw); height: min(320px, 80vw);
  bottom: 8%; right: -60px;
  background: radial-gradient(circle, var(--orb-b), transparent 70%);
}

.topbar, .shell, .results, footer {
  position: relative;
  z-index: 1;
  width: min(540px, 100%);
}

.topbar { margin-bottom: 0.75rem; }
.controls {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-elev);
}
.seg-btn, .theme-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 0.45rem 0.7rem;
  cursor: pointer;
  min-height: 36px;
}
.seg-btn.active {
  background: rgba(45, 212, 191, 0.18);
  color: var(--teal);
}
.theme-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev);
  min-width: 40px;
}

.banner {
  text-align: center;
  font-size: 0.82rem;
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--bg-elev);
  backdrop-filter: blur(10px);
  margin: 0 auto;
  width: fit-content;
  max-width: 100%;
}
.banner.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.banner.degraded { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.banner.down { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }

.shell { text-align: center; }
.eyebrow {
  margin: 0.4rem 0 0;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.7rem;
  color: var(--teal);
  font-weight: 700;
}
.brand {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(2.4rem, 10vw, 3.5rem);
  letter-spacing: -0.04em;
  margin: 0.3rem 0 0.45rem;
  line-height: 0.95;
  background: linear-gradient(115deg, var(--ink) 8%, var(--cyan) 45%, var(--teal) 75%, var(--lime));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline {
  margin: 0 auto 1.25rem;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.45;
  max-width: 28rem;
  padding: 0 0.25rem;
}

.gauge-block {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(300px, 88vw);
  height: auto;
  min-height: 280px;
  margin: 0 auto 0.5rem;
}
.gauge { width: 100%; height: auto; display: block; }
.gauge-actions {
  position: relative;
  margin-top: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gauge-track {
  fill: none;
  stroke: color-mix(in srgb, var(--muted) 28%, transparent);
  stroke-width: 14;
  stroke-linecap: round;
}
.gauge-fill {
  fill: none;
  stroke: url(#gArc);
  stroke-width: 14;
  stroke-linecap: round;
  stroke-dasharray: 283;
  stroke-dashoffset: 283;
  transition: stroke-dashoffset 0.35s ease, stroke 0.25s ease;
}
.gauge-fill.tone-ok { stroke: url(#gArcOk); }
.gauge-fill.tone-warn { stroke: url(#gArcWarn); }
.gauge-fill.tone-bad { stroke: url(#gArcBad); }
.gauge-value {
  fill: var(--ink);
  font-family: var(--display);
  font-size: 40px;
  font-weight: 800;
}
.gauge-unit {
  fill: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
}
.gauge-quality-svg {
  fill: var(--muted);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.gauge-quality-svg.tone-ok { fill: var(--ok); }
.gauge-quality-svg.tone-warn { fill: var(--warn); }
.gauge-quality-svg.tone-bad { fill: var(--bad); }

.ring {
  position: absolute;
  left: 50%; top: 50%;
  width: 124px; height: 124px;
  margin: -62px 0 0 -62px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--cyan);
  border-right-color: color-mix(in srgb, var(--teal) 55%, transparent);
  opacity: 0;
  pointer-events: none;
}
.gauge-block.scanning .ring {
  opacity: 1;
  animation: spin 0.85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.scan-btn {
  position: relative;
  width: 116px; height: 116px;
  margin: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: var(--ink);
  font-family: var(--font);
  font-weight: 700;
  font-size: 1.02rem;
  background: var(--btn-face);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--teal) 45%, transparent),
    0 16px 36px rgba(0, 0, 0, 0.28);
  transition: transform 0.18s ease;
  -webkit-tap-highlight-color: transparent;
  z-index: 1;
}
.scan-btn:hover { transform: scale(1.03); }
.scan-btn:disabled { cursor: wait; }
.gauge-block.ok .scan-btn { box-shadow: 0 0 0 2px color-mix(in srgb, var(--ok) 55%, transparent), 0 16px 36px rgba(0,0,0,0.25); }
.gauge-block.warn .scan-btn { box-shadow: 0 0 0 2px color-mix(in srgb, var(--warn) 55%, transparent), 0 16px 36px rgba(0,0,0,0.25); }
.gauge-block.blocked .scan-btn { box-shadow: 0 0 0 2px color-mix(in srgb, var(--bad) 55%, transparent), 0 16px 36px rgba(0,0,0,0.25); }

.meta {
  color: var(--muted);
  font-size: 0.92rem;
  min-height: 1.4em;
  margin: 0.35rem 0 1rem;
  padding: 0 0.35rem;
  word-break: break-word;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}
@media (min-width: 420px) {
  .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.metrics[hidden] { display: none; }
.metric {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0.85rem 0.45rem;
  background: var(--bg-elev);
}
.metric-k {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.3rem;
}
.metric-v {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(0.95rem, 4.2vw, 1.15rem);
  font-variant-numeric: tabular-nums;
}
.metric-v.ok { color: var(--ok); }
.metric-v.warn { color: var(--warn); }
.metric-v.bad { color: var(--bad); }
.metric-h {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.65rem;
  color: var(--muted);
  line-height: 1.2;
}
.metric-h[hidden] { display: none; }

.results { margin-top: 1.35rem; animation: fadeUp 0.4s ease; }
.results[hidden] { display: none; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.verdict {
  margin: 0 0 0.4rem;
  font-family: var(--display);
  font-size: clamp(1.2rem, 5.2vw, 1.45rem);
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
}
.verdict.ok { color: var(--ok); }
.verdict.warn { color: var(--warn); }
.verdict.blocked { color: var(--bad); }
.detail, .hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 0.85rem;
}

.nodes {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  border-top: 1px solid var(--line);
}
.nodes li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.85rem 0.15rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.98rem;
}
.nodes .ms { font-variant-numeric: tabular-nums; color: var(--muted); }
.dot {
  width: 0.7rem; height: 0.7rem; border-radius: 50%;
  background: var(--muted);
}
.dot.ok { background: var(--ok); box-shadow: 0 0 8px color-mix(in srgb, var(--ok) 50%, transparent); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

.playbook {
  list-style: none;
  padding: 0;
  margin: 0 0 1.1rem;
  counter-reset: step;
}
.playbook li {
  position: relative;
  padding: 0.55rem 0 0.55rem 1.85rem;
  font-size: 0.95rem;
  line-height: 1.35;
}
.playbook li::before {
  content: counter(step);
  counter-increment: step;
  position: absolute;
  left: 0; top: 0.55rem;
  width: 1.3rem; height: 1.3rem;
  border-radius: 50%;
  background: color-mix(in srgb, var(--teal) 16%, transparent);
  color: var(--teal);
  font-size: 0.72rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.checks {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 1rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.report-box {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0;
  border-top: 1px solid var(--line);
}
.report-label { color: var(--muted); font-size: 0.78rem; margin-bottom: 0.15rem; }
.report-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.12rem;
  color: var(--cyan);
  letter-spacing: 0.04em;
}
.btn {
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.65rem 1.15rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
}
.btn:hover { border-color: var(--teal); }

footer {
  margin-top: auto;
  padding-top: 2rem;
  text-align: center;
  color: color-mix(in srgb, var(--muted) 70%, transparent);
  font-size: 0.78rem;
}

@media (max-width: 380px) {
  .gauge-block { min-height: 260px; height: auto; }
  .scan-btn { width: 104px; height: 104px; margin: 0; }
  .ring { width: 112px; height: 112px; margin: -56px 0 0 -56px; }
  .metric { padding: 0.75rem 0.3rem; }
}
