:root {
  color-scheme: dark;
  --bg: #08111f;
  --panel: rgba(13, 27, 48, 0.78);
  --panel-strong: #0d1c31;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f7fbff;
  --muted: #91a3ba;
  --cyan: #38d9ff;
  --blue: #4e7cff;
  --purple: #9b6cff;
  --green: #56e39f;
  --danger: #ff6b7d;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 0%, rgba(50, 116, 255, 0.22), transparent 38rem),
    radial-gradient(circle at 85% 48%, rgba(155, 108, 255, 0.12), transparent 26rem),
    var(--bg);
}

button, input { font: inherit; }

.background-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.28;
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, black, transparent 80%);
}

.site-header {
  position: relative;
  z-index: 2;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  text-decoration: none;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: #04111a;
  font-size: 1.3rem;
  background: linear-gradient(135deg, var(--cyan), var(--green));
  box-shadow: 0 8px 24px rgba(56, 217, 255, .24);
}

.privacy-pill {
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255,255,255,.035);
  font-size: .78rem;
  font-weight: 600;
}

.page-shell {
  position: relative;
  z-index: 1;
  width: min(920px, calc(100% - 28px));
  margin: 0 auto;
  padding: 38px 0 54px;
}

.hero { text-align: center; margin-bottom: 30px; }

.eyebrow {
  margin: 0 0 12px;
  color: var(--cyan);
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: .2em;
}

h1 {
  margin: 0;
  font-size: clamp(2.25rem, 7vw, 4.55rem);
  line-height: .98;
  letter-spacing: -0.065em;
}

.intro {
  max-width: 660px;
  margin: 18px auto 0;
  color: var(--muted);
  line-height: 1.7;
  font-size: clamp(.98rem, 2vw, 1.08rem);
}

.speed-card {
  position: relative;
  overflow: hidden;
  padding: 40px;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: linear-gradient(145deg, rgba(16, 34, 58, .96), rgba(8, 20, 36, .9));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.speed-card::before {
  content: "";
  position: absolute;
  width: 420px;
  height: 420px;
  top: -280px;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 50%;
  background: rgba(56, 217, 255, .1);
  filter: blur(16px);
}

.gauge-wrap {
  width: min(360px, 100%);
  margin: 0 auto 24px;
  position: relative;
}

.gauge {
  --progress: 0deg;
  width: min(330px, 84vw);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: 19px;
  border-radius: 50%;
  background:
    conic-gradient(from 220deg,
      var(--cyan) 0deg,
      var(--blue) var(--progress),
      rgba(255,255,255,.08) var(--progress),
      rgba(255,255,255,.08) 280deg,
      transparent 280deg);
  transform: rotate(0deg);
  box-shadow: 0 0 58px rgba(56,217,255,.09);
}

.gauge::after {
  content: "";
  position: absolute;
  inset: 31px;
  border: 1px solid rgba(255,255,255,.065);
  border-radius: 50%;
  pointer-events: none;
}

.gauge-inner {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 30%, rgba(44, 97, 155, .24), transparent 55%),
    #0b1728;
  box-shadow: inset 0 0 60px rgba(0,0,0,.4);
}

.test-stage {
  margin-bottom: 2px;
  color: var(--cyan);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .18em;
}

.speed-value {
  font-size: clamp(3.5rem, 12vw, 5.8rem);
  line-height: 1;
  letter-spacing: -.07em;
  font-variant-numeric: tabular-nums;
}

.speed-unit { margin-top: 8px; color: var(--muted); font-weight: 600; }

.gauge-scale {
  position: absolute;
  inset: auto 0 -2px;
  display: flex;
  justify-content: space-between;
  color: #63758d;
  font-size: .7rem;
  font-weight: 700;
}

.start-button {
  display: block;
  min-width: 180px;
  margin: 31px auto 0;
  padding: 16px 28px;
  border: 0;
  border-radius: 999px;
  color: #03131d;
  background: linear-gradient(135deg, var(--cyan), var(--green));
  box-shadow: 0 12px 34px rgba(56, 217, 255, .23);
  cursor: pointer;
  font-weight: 800;
  transition: transform .2s ease, filter .2s ease, opacity .2s ease;
}

.start-button:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.06); }
.start-button:active:not(:disabled) { transform: translateY(0); }
.start-button:disabled { cursor: wait; opacity: .72; }

.status-message {
  min-height: 22px;
  margin: 16px 0 30px;
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.028);
}

.metric-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: var(--cyan);
  background: rgba(56,217,255,.1);
  font-size: 1.2rem;
  font-weight: 800;
}
.metric-icon.download { color: var(--green); background: rgba(86,227,159,.1); }
.metric-icon.upload { color: #b894ff; background: rgba(155,108,255,.12); }

.metric-label { display: block; margin-bottom: 5px; color: var(--muted); font-size: .72rem; font-weight: 600; }
.metric-card strong { display: block; overflow: hidden; text-overflow: ellipsis; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.metric-card small { color: var(--muted); font-size: .68rem; font-weight: 600; }

.details-card {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--line);
}

.details-card > div { min-width: 0; padding: 18px 20px; background: rgba(11, 24, 42, .96); }
.details-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: .72rem; }
.details-card strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .88rem; }

.footnote { max-width: 700px; margin: 20px auto 0; color: #71849c; text-align: center; font-size: .77rem; line-height: 1.6; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 760px) {
  .page-shell { padding-top: 20px; }
  .speed-card { padding: 28px 18px; border-radius: 24px; }
  .results-grid { grid-template-columns: repeat(2, 1fr); }
  .details-card { grid-template-columns: 1fr; }
  .privacy-pill { display: none; }
}

@media (max-width: 430px) {
  .site-header { padding-top: 17px; }
  .hero { margin-bottom: 22px; }
  .metric-card { padding: 13px; }
  .metric-icon { width: 34px; height: 34px; }
}

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

/* Result sharing */
.share-panel[hidden] { display: none; }

.share-panel {
  margin-top: 22px;
  padding: 22px;
  border: 1px solid rgba(86, 227, 159, .2);
  border-radius: 22px;
  background:
    linear-gradient(145deg, rgba(86, 227, 159, .07), rgba(56, 217, 255, .035)),
    rgba(255,255,255,.025);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .3s ease, transform .3s ease;
}

.share-panel.is-visible { opacity: 1; transform: translateY(0); }

.share-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.share-kicker {
  margin: 0 0 5px;
  color: var(--green);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .17em;
}

.share-heading h3 {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: -.025em;
}

.share-heading p:not(.share-kicker) {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.5;
}

.share-primary,
.share-option {
  border: 1px solid var(--line);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}

.share-primary {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 13px 18px;
  border: 0;
  border-radius: 999px;
  color: #04141c;
  background: linear-gradient(135deg, var(--green), var(--cyan));
  box-shadow: 0 10px 28px rgba(56, 217, 255, .16);
}

.share-actions {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 9px;
  margin-top: 18px;
}

.share-option {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 9px;
  border-radius: 13px;
  background: rgba(255,255,255,.035);
  font-size: .72rem;
}

.share-icon {
  display: inline-grid;
  place-items: center;
  width: 23px;
  height: 23px;
  border-radius: 8px;
  color: var(--cyan);
  background: rgba(56,217,255,.1);
  font-size: .7rem;
  font-weight: 800;
}

.share-primary:hover,
.share-option:hover { transform: translateY(-2px); }
.share-option:hover { border-color: rgba(56,217,255,.35); background: rgba(56,217,255,.07); }
.share-primary:active,
.share-option:active { transform: translateY(0); }

.share-feedback {
  min-height: 18px;
  margin: 13px 0 0;
  color: var(--green);
  text-align: center;
  font-size: .75rem;
}
.share-feedback.is-error { color: var(--danger); }

@media (max-width: 760px) {
  .share-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .share-option:last-child { grid-column: 1 / -1; }
}

@media (max-width: 520px) {
  .share-heading { align-items: stretch; flex-direction: column; }
  .share-primary { justify-content: center; width: 100%; }
  .share-panel { padding: 18px; }
}
