/* ===================================================================
   Pulse Speed Test — design tokens
   Palette: deep space navy + fiber-optic cyan / signal violet / ping amber
   Type: Space Grotesk (display) · Inter (body) · JetBrains Mono (data)
   Signature element: the "pulse ring" gauge — concentric rings that
   echo outward like a sonar ping while idle, then resolve into a single
   progress ring while a phase is measuring.
=================================================================== */

:root {
  --bg: #070b14;
  --bg-radial: radial-gradient(120% 120% at 50% -10%, #101a2e 0%, #070b14 55%);
  --surface: #0e1526;
  --surface-2: #131c33;
  --border: #1f2c47;
  --text: #eaf2ff;
  --muted: #8393b4;
  --muted-dim: #56617e;

  --ping: #ffc857;
  --download: #29f1ce;
  --upload: #8b7cff;

  --font-display: 'Space Grotesk', 'Inter', sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;

  --radius-lg: 28px;
  --radius-md: 16px;
  --radius-sm: 10px;

  --phase-color: var(--muted);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-radial);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--download);
  outline-offset: 3px;
  border-radius: 6px;
}

/* ---------------- Topbar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.brand-mark {
  display: inline-flex;
  color: var(--download);
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.01em;
}

/* ---------------- Language switcher ---------------- */

.lang-switcher {
  position: relative;
}

.lang-button {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.lang-button:hover {
  color: var(--text);
  border-color: #2c3c5e;
  background: var(--surface-2);
}

.lang-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 260px;
  max-height: 340px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 40;
}

.lang-panel[hidden] {
  display: none;
}

[dir='rtl'] .lang-panel { right: auto; left: 0; }

.lang-search {
  margin: 10px 10px 6px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
}

.lang-search:focus {
  outline: none;
  border-color: var(--download);
}

.lang-list {
  list-style: none;
  margin: 0;
  padding: 4px 6px 8px;
  overflow-y: auto;
}

.lang-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text);
}

.lang-list li:hover,
.lang-list li.active {
  background: rgba(41, 241, 206, 0.1);
  color: var(--download);
}

.lang-list li .lang-english {
  color: var(--muted-dim);
  font-size: 11.5px;
}

.lang-list li.active .lang-english { color: var(--download); opacity: 0.7; }

.lang-list .lang-empty {
  color: var(--muted-dim);
  padding: 14px 10px;
  text-align: center;
  cursor: default;
}

/* ---------------- Hero ---------------- */

.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: clamp(20px, 5vh, 56px);
}

.tagline {
  margin: 0 0 clamp(28px, 5vh, 52px);
  color: var(--muted);
  font-size: 15.5px;
  max-width: 40ch;
  line-height: 1.5;
}

/* ---------------- Gauge ---------------- */

.gauge-wrap {
  position: relative;
  width: min(300px, 78vw);
  height: min(300px, 78vw);
  display: flex;
  align-items: center;
  justify-content: center;
}

.pulse-rings {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.pulse-rings .ring {
  position: absolute;
  width: 62%;
  height: 62%;
  border-radius: 50%;
  border: 1.5px solid var(--download);
  opacity: 0;
}

.app.is-idle .pulse-rings .ring {
  animation: pulse-out 3.2s cubic-bezier(0.2, 0.6, 0.35, 1) infinite;
}

.app.is-idle .pulse-rings .r2 { animation-delay: 1.07s; }
.app.is-idle .pulse-rings .r3 { animation-delay: 2.14s; }

@keyframes pulse-out {
  0%   { transform: scale(1);    opacity: 0; }
  8%   { opacity: 0.45; }
  100% { transform: scale(1.62); opacity: 0; }
}

.gauge-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.gauge-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 10;
}

.gauge-progress {
  fill: none;
  stroke: var(--phase-color);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 816.8;
  stroke-dashoffset: 816.8;
  transition: stroke-dashoffset 0.25s linear, stroke 0.3s ease;
}

.gauge-center {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.gauge-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: clamp(48px, 12vw, 64px);
  line-height: 1;
  color: var(--text);
}

.gauge-unit {
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.04em;
  margin-top: 4px;
}

.gauge-phase {
  margin-top: 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--phase-color);
  min-height: 16px;
  transition: color 0.3s ease;
}

.start-btn {
  position: absolute;
  bottom: 14%;
  min-width: 116px;
  padding: 13px 30px;
  border-radius: 999px;
  border: none;
  background: var(--download);
  color: #04231c;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 10px 30px -8px rgba(41, 241, 206, 0.55);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.2s ease;
}

.start-btn:hover { transform: translateY(-1px); box-shadow: 0 14px 34px -8px rgba(41, 241, 206, 0.7); }
.start-btn:active { transform: translateY(0); }

.app.is-testing .start-btn,
.app.is-testing .gauge-center { opacity: 0; pointer-events: none; }

.app.is-testing .gauge-value,
.app.is-testing .gauge-phase,
.app.is-testing .gauge-unit,
.app.is-testing .gauge-center { opacity: 1; pointer-events: auto; }

.app.is-testing .start-btn { opacity: 0; pointer-events: none; }

.app.is-done .start-btn { opacity: 1; pointer-events: auto; }

/* ---------------- Results ---------------- */

.results {
  margin-top: clamp(28px, 5vh, 48px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 520px;
  animation: rise-in 0.4s ease both;
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.stat-icon { width: 20px; height: 20px; }
.stat-ping .stat-icon { color: var(--ping); }
.stat-download .stat-icon { color: var(--download); }
.stat-upload .stat-icon { color: var(--upload); }

.stat-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.stat-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 19px;
  color: var(--text);
}

.stat-unit {
  font-size: 11.5px;
  color: var(--muted-dim);
  font-weight: 500;
}

.error-note {
  margin-top: 20px;
  color: var(--ping);
  font-size: 13.5px;
}

/* ---------------- Footer ---------------- */

.site-footer {
  margin-top: clamp(28px, 6vh, 56px);
  text-align: center;
}

.site-footer p {
  margin: 0;
  color: var(--muted-dim);
  font-size: 12px;
  max-width: 44ch;
  margin-inline: auto;
  line-height: 1.5;
}

/* ---------------- Responsive ---------------- */

@media (max-width: 420px) {
  .brand-name { font-size: 15px; }
  .results { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .stat { padding: 12px 8px; }
  .stat-value { font-size: 16px; }
}

/* ---------------- Reduced motion ---------------- */

@media (prefers-reduced-motion: reduce) {
  .app.is-idle .pulse-rings .ring { animation: none; opacity: 0.18; transform: scale(1.2); }
  .gauge-progress { transition: none; }
  .results { animation: none; }
}
