/* ── StrixSpeed ─────────────────────────────────────────── */

/* ── Design tokens (light default) ──────────────────────── */
:root {
  --bg:          #eef1f8;
  --bg-2:        #f7f8fc;
  --card-bg:     rgba(255, 255, 255, 0.72);
  --card-solid:  #ffffff;
  --bg-card:     #ffffff;
  --bg-track:    #e3e7ef;
  --bg-header:   #f1f3f9;
  --text:        #1f2733;
  --text-muted:  #677289;
  --text-subtle: #9aa3b5;
  --border:      rgba(20, 30, 60, 0.08);
  --accent:      #6366f1;
  --accent-hover:#4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.18);
  --down:        #0891b2;
  --up:          #7c3aed;
  --ping:        #d97706;
  --bar-from:    #6366f1;
  --bar-to:      #a78bfa;
  --shadow:      0 2px 8px rgba(20, 30, 60, 0.06);
  --shadow-lg:   0 16px 40px rgba(20, 30, 60, 0.12);
  --radius:      18px;
  --radius-sm:   12px;
  --glow-1:      rgba(99, 102, 241, 0.28);
  --glow-2:      rgba(167, 139, 250, 0.22);
}

[data-theme="dark"] {
  --bg:          #0a0b10;
  --bg-2:        #11131b;
  --card-bg:     rgba(26, 28, 38, 0.66);
  --card-solid:  #181a22;
  --bg-card:     #181a22;
  --bg-track:    #2a2d3a;
  --bg-header:   rgba(255, 255, 255, 0.03);
  --text:        #e7e9f0;
  --text-muted:  #9096a8;
  --text-subtle: #5a6072;
  --border:      rgba(255, 255, 255, 0.08);
  --accent:      #818cf8;
  --accent-hover:#a5b0ff;
  --accent-glow: rgba(129, 140, 248, 0.22);
  --down:        #22d3ee;
  --up:          #c4b5fd;
  --ping:        #fbbf24;
  --bar-from:    #818cf8;
  --bar-to:      #c4b5fd;
  --shadow:      0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg:   0 18px 44px rgba(0, 0, 0, 0.55);
  --glow-1:      rgba(99, 102, 241, 0.30);
  --glow-2:      rgba(167, 139, 250, 0.22);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 1rem;
  transition: background 0.4s ease, color 0.4s ease;
  -webkit-font-smoothing: antialiased;
}

/* ── Decorative background glows ────────────────────────── */
.bg-decor {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.bg-decor::before,
.bg-decor::after {
  content: '';
  position: absolute;
  width: 46vw;
  height: 46vw;
  max-width: 620px;
  max-height: 620px;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.9;
}
.bg-decor::before {
  top: -12vw;
  left: -8vw;
  background: var(--glow-1);
}
.bg-decor::after {
  bottom: -14vw;
  right: -10vw;
  background: var(--glow-2);
}

/* ── Theme toggle ───────────────────────────────────────── */
.theme-toggle {
  position: fixed;
  top: 1.1rem;
  right: 1.1rem;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card-bg);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.2s;
  box-shadow: var(--shadow);
}
@media (hover: hover) {
  .theme-toggle:hover { color: var(--accent); border-color: var(--accent); transform: rotate(15deg); }
}
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* ── Focus ring ─────────────────────────────────────────── */
/* Keyboard users need a ring that is visible in BOTH themes. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}
:focus:not(:focus-visible) { outline: none; }

/* Skip link — first tab stop, visible only when focused. */
.skip-link {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -120%);
  z-index: 200;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.7rem 1.2rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  text-decoration: none;
  transition: transform 0.18s ease;
}
.skip-link:focus { transform: translate(-50%, 0); }

/* Visually hidden but readable by screen readers. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ── Container ──────────────────────────────────────────── */
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 540px;
}

/* ── Header ─────────────────────────────────────────────── */
.header {
  text-align: center;
  margin-bottom: 1.8rem;
}
.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.logo-icon {
  color: var(--accent);
  filter: drop-shadow(0 2px 8px var(--accent-glow));
  animation: pulse-icon 2.4s ease-in-out infinite;
}
@keyframes pulse-icon {
  0%, 100% { opacity: 1; transform: translateY(0); }
  50%      { opacity: 0.65; transform: translateY(-2px); }
}
h1 {
  font-size: clamp(1.9rem, 6vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}
h1 span {
  background: linear-gradient(90deg, var(--bar-from), var(--bar-to));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 0.4rem;
}

/* ── Glass card base ────────────────────────────────────── */
.gauge-card,
.result-card,
#examples table {
  background: var(--card-bg);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

/* ── Hero gauge ─────────────────────────────────────────── */
.gauge-card {
  width: 100%;
  padding: 2rem 2rem 1.8rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: box-shadow 0.4s ease, border-color 0.4s ease;
}
.gauge-card.testing {
  border-color: var(--accent);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--accent-glow), 0 0 40px var(--accent-glow);
}
.speedometer {
  width: 280px;
  height: 182px;
  max-width: 100%;
  margin: 0 auto;
}
.speedometer svg { width: 100%; height: 100%; overflow: visible; }
#speedo-arc {
  transition: stroke-dashoffset 0.25s ease-out;
  filter: drop-shadow(0 0 6px var(--accent-glow));
}
#speedo-needle { transition: transform 0.12s ease-out; }

.gauge-readout { margin-top: -0.5rem; }
.gauge-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.gauge-label .icon { color: var(--accent); }
.gauge-value {
  font-size: clamp(2.4rem, 11vw, 3.6rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1;
  min-height: 1.1em;
  white-space: nowrap;
  background: linear-gradient(90deg, var(--bar-from), var(--bar-to));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.gauge-value:empty::before { content: '\2014'; -webkit-text-fill-color: var(--text-subtle); }
.gauge-value .unit {
  font-size: 0.36em;
  font-weight: 600;
  letter-spacing: 0;
  margin-left: 0.35em;
  -webkit-text-fill-color: var(--text-muted);
}
.gauge-sub {
  font-size: 0.82rem;
  color: var(--text-subtle);
  min-height: 1.1em;
  margin-top: 0.5rem;
}

/* ── Start button ───────────────────────────────────────── */
.btn-start {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-top: 1.4rem;
  min-height: 48px;
  padding: 0.9rem 2.4rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--bar-from), var(--up));
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.25s ease, opacity 0.2s;
  box-shadow: 0 8px 24px var(--accent-glow);
}
@media (hover: hover) {
  .btn-start:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px var(--accent-glow);
  }
}
.btn-start:active:not(:disabled) { transform: translateY(0); }
.btn-start:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-start .icon { flex-shrink: 0; }

/* ── Results ────────────────────────────────────────────── */
.results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.9rem;
  width: 100%;
  margin: 1.6rem 0;
}
.result-card {
  position: relative;
  overflow: hidden;
  padding: 1.2rem 0.8rem 1.1rem;
  text-align: center;
  transition: transform 0.2s ease, box-shadow 0.25s ease, border-color 0.25s;
}
.result-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  opacity: 0.9;
}
.result-card.ping::before { background: var(--ping); }
.result-card.down::before { background: var(--down); }
.result-card.up::before   { background: var(--up); }
@media (hover: hover) {
  .result-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
}

.result-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  margin-bottom: 0.55rem;
}
.result-card.ping .result-badge { color: var(--ping); background: color-mix(in srgb, var(--ping) 14%, transparent); }
.result-card.down .result-badge { color: var(--down); background: color-mix(in srgb, var(--down) 14%, transparent); }
.result-card.up   .result-badge { color: var(--up);   background: color-mix(in srgb, var(--up) 14%, transparent); }

.result-card .label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  font-weight: 600;
}
.result-card .value {
  font-size: 1.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text);
}
.result-card.ping .value { color: var(--ping); }
.result-card.down .value { color: var(--down); }
.result-card.up   .value { color: var(--up); }
.result-card .value .unit {
  font-size: 0.5em;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 0.25em;
}

/* ── Examples table ─────────────────────────────────────── */
#examples { width: 100%; }
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
#examples table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  font-size: 0.9rem;
}
#examples caption {
  caption-side: top;
  text-align: left;
  padding: 0 0.3rem 0.7rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
#examples thead th {
  text-align: left;
  padding: 0.7rem 1rem;
  background: var(--bg-header);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-bottom: 1px solid var(--border);
}
#examples thead th:first-child { width: 40px; text-align: center; }
/* Row header = the file name. Same weight/size as a body cell. */
#examples tbody th {
  text-align: left;
  padding: 0.62rem 1rem;
  border-top: 1px solid var(--border);
  color: var(--text);
  font-size: 1em;
  font-weight: 600;
  text-transform: none;
  letter-spacing: normal;
  vertical-align: middle;
}
#examples td {
  padding: 0.62rem 1rem;
  border-top: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
#examples thead th:nth-child(3), #examples thead th:nth-child(4),
#examples td:nth-child(3), #examples td:nth-child(4) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
#examples td:nth-child(3) { color: var(--text-muted); white-space: nowrap; }
#examples td:nth-child(4) { color: var(--accent); font-weight: 700; white-space: nowrap; }
#examples td.icon-cell { text-align: center; width: 40px; color: var(--text-subtle); }
#examples td.icon-cell svg { vertical-align: middle; }
#examples tbody tr { transition: background 0.15s; }
@media (hover: hover) {
    #examples tbody tr:hover td,
  #examples tbody tr:hover th { background: var(--accent-glow); }
}
#examples tr:last-child td, #examples tr:last-child th { border-bottom: none; }

/* ── Editorial content ──────────────────────────────────── */
.prose {
  width: 100%;
  max-width: 540px;
  margin: 2.6rem auto 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.65;
}
.prose section + section { margin-top: 2.2rem; }
.prose h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 0.7rem;
}
.prose h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin: 1.5rem 0 0.4rem;
}
.prose p { margin-bottom: 0.9rem; }
.prose p:last-child { margin-bottom: 0; }

.metric-list { margin-top: 1.1rem; }
.metric-list dt {
  font-weight: 700;
  color: var(--accent);
  margin-top: 1rem;
  font-size: 0.92rem;
}
.metric-list dd { margin-left: 0; }

.need-list, .tips-list {
  margin: 0 0 0.9rem;
  padding-left: 1.2rem;
}
.need-list li, .tips-list li { margin-bottom: 0.5rem; }
.need-list strong { color: var(--text); }

/* ── Footer ─────────────────────────────────────────────── */
.site-footer {
  width: 100%;
  max-width: 540px;
  margin: 2.8rem auto 0;
  padding-top: 1.4rem;
  border-top: 1px solid var(--border);
  color: var(--text-subtle);
  font-size: 0.8rem;
  line-height: 1.6;
  text-align: center;
}

/* ── Responsive ─────────────────────────────────────────── */
/* The theme toggle is fixed to the viewport corner; on narrow screens the
   centred brand grows into it, so push the header clear of it. */
@media (max-width: 600px) {
  .header { padding-top: 3.2rem; }
}

@media (max-width: 480px) {
  body { padding: 1.4rem 0.8rem; }
  .gauge-card { padding: 1.5rem 1.1rem 1.4rem; }
  .speedometer { width: 230px; height: 150px; }
  .results { gap: 0.6rem; }
  .result-card { padding: 1rem 0.5rem 0.9rem; }
  .result-badge { width: 34px; height: 34px; }
  .result-card .value { font-size: 1.15rem; }
  .btn-start { min-height: 48px; padding: 0.8rem 1.8rem; font-size: 1rem; }
  .prose { font-size: 0.9rem; margin-top: 2.2rem; }
  .prose h2 { font-size: 1.12rem; }
  #examples { font-size: 0.82rem; }
  #examples th, #examples td { padding: 0.5rem 0.7rem; }
  #examples tbody th { padding: 0.5rem 0.7rem; }
}

/* ── Reduced motion ─────────────────────────────────────── */
/* Honour the OS setting: no infinite pulse, no arc/needle easing.
   (The needle's random jitter is disabled in JS by the same query.) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .logo-icon { animation: none; opacity: 1; }
}
