/**
 * WireGod-inspired / nPerf-style speed test theme
 * All brand colors are CSS custom properties — edit :root to recolor.
 */

:root {
  /* Backgrounds */
  --bg-base: #0b0909;
  --bg-gradient-center: #1e0a0a;
  --bg-gradient-edge: #0d0d0d;
  --bg-card: #1a1212;
  --bg-card-elevated: #1c1616;
  --bg-info: #141010;

  /* Accents */
  --accent-red: #9e1b1b;
  --accent-red-bright: #a31d1d;
  --accent-red-deep: #8b1a1a;
  --accent-gold: #c5a059;
  --accent-gold-muted: rgba(197, 160, 89, 0.35);

  /* Text */
  --text-primary: #ffffff;
  --text-secondary: #b0b0b0;
  --text-muted: #999191;
  --text-dim: #6e6666;

  /* Borders & tracks */
  --border-subtle: #2d2323;
  --border-tile: #2d2d2d;
  --gauge-track: #2d2323;
  --gauge-arc: #9e1b1b;
  --gauge-arc-glow: rgba(163, 29, 29, 0.45);
  --gauge-dot: rgba(163, 29, 29, 0.28);
  --gauge-ring: rgba(158, 27, 27, 0.18);

  /* Layout */
  --radius-card: 20px;
  --radius-pill: 999px;
  --radius-tile: 16px;
  --shadow-card: 0 12px 40px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 32px rgba(163, 29, 29, 0.25);

  /* Typography */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Brand (edit in HTML or here) */
  --brand-name-size: 1.25rem;
  --tagline-tracking: 0.22em;
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(ellipse 120% 80% at 50% 0%, var(--bg-gradient-center) 0%, var(--bg-gradient-edge) 55%, var(--bg-base) 100%);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* subtle grid overlay */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(158, 27, 27, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(158, 27, 27, 0.06) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 30%, black 20%, transparent 75%);
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 520px;
  margin: 0 auto;
  padding: 1rem 1rem 2.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Header ─── */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0 1.25rem;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: var(--shadow-glow);
}

.brand-text h1 {
  margin: 0;
  font-size: var(--brand-name-size);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-tagline {
  margin: 0.15rem 0 0;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: var(--tagline-tracking);
  text-transform: uppercase;
  color: var(--text-muted);
}

.live-pulse {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-pill);
  background: var(--accent-red-deep);
  color: var(--text-primary);
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(158, 27, 27, 0.35);
}

.live-pulse svg {
  width: 14px;
  height: 14px;
}

.live-pulse.is-idle {
  background: var(--bg-card);
  color: var(--text-muted);
  box-shadow: none;
  border: 1px solid var(--border-subtle);
}

/* ─── Loading ─── */
#loading {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

#loading.hidden {
  display: none;
}

span.loadCircle {
  display: inline-block;
  width: 1.5rem;
  height: 1.5rem;
  vertical-align: middle;
  margin-right: 0.5rem;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--accent-red);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#testWrapper.hidden {
  display: none;
}

#testWrapper.visible {
  display: block;
  animation: fadeIn 0.35s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ─── Central gauge ─── */
.gauge-section {
  position: relative;
  width: 100%;
  max-width: 340px;
  margin: 0 auto 1.5rem;
  aspect-ratio: 1;
}

#mainGauge {
  display: block;
  width: 100%;
  height: 100%;
  --gauge-track: #2d2323;
  --gauge-arc: #9e1b1b;
  --gauge-arc-glow: rgba(163, 29, 29, 0.45);
  --gauge-dot: rgba(163, 29, 29, 0.28);
  --gauge-ring: rgba(158, 27, 27, 0.18);
}

.gauge-center {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  width: 55%;
}

#gaugeValue {
  display: block;
  font-size: clamp(2.5rem, 12vw, 3.5rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

#gaugeValue:empty::before {
  content: "0";
  color: var(--text-dim);
}

#gaugeUnit {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

#gaugePhase {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-gold);
  min-height: 1em;
}

/* ─── GO button ─── */
#startStopBtn {
  position: absolute;
  left: 50%;
  bottom: 4%;
  transform: translateX(-50%);
  width: 5.5rem;
  height: 5.5rem;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-primary);
  background: linear-gradient(145deg, var(--accent-red-bright) 0%, var(--accent-red-deep) 100%);
  box-shadow:
    0 8px 28px rgba(158, 27, 27, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    background 0.2s ease;
  z-index: 2;
}

#startStopBtn:hover {
  transform: translateX(-50%) scale(1.04);
  box-shadow:
    0 12px 36px rgba(163, 29, 29, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

#startStopBtn:active {
  transform: translateX(-50%) scale(0.98);
}

#startStopBtn::before {
  content: "GO";
}

#startStopBtn.running {
  background: linear-gradient(145deg, #3a1515 0%, #1a0808 100%);
  border: 2px solid var(--accent-red);
  box-shadow: 0 0 24px rgba(163, 29, 29, 0.4);
}

#startStopBtn.running::before {
  content: "STOP";
  font-size: 0.85rem;
}

#startStopBtn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ─── Metric tiles ─── */
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.metric-tile {
  background: linear-gradient(160deg, var(--bg-card-elevated) 0%, var(--bg-card) 100%);
  border: 1px solid var(--border-tile);
  border-radius: var(--radius-tile);
  padding: 0.85rem 0.9rem;
  box-shadow: var(--shadow-card);
  text-align: left;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.metric-tile.is-active {
  border-color: var(--accent-red);
  box-shadow: var(--shadow-card), 0 0 0 1px rgba(158, 27, 27, 0.35);
}

.metric-tile-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.metric-tile-head svg {
  width: 18px;
  height: 18px;
  color: var(--accent-red-bright);
  flex-shrink: 0;
}

.metric-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.metric-value-row {
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
}

.metric-tile .meterText {
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.metric-tile .meterText:empty::before {
  content: "—";
  color: var(--text-dim);
  font-weight: 500;
}

.metric-tile .unit {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* ─── IP / ISP info card ─── */
.info-card {
  background: var(--bg-info);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}

.info-card-label {
  display: block;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

#ip {
  font-size: 0.85rem;
  color: var(--text-secondary);
  word-break: break-word;
  line-height: 1.5;
}

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

.connection-dl {
  margin: 0;
  display: grid;
  gap: 0.65rem;
}

.connection-row {
  display: grid;
  grid-template-columns: 4.5rem 1fr;
  gap: 0.5rem;
  align-items: baseline;
}

.connection-row dt {
  margin: 0;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.connection-row dd {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
  word-break: break-word;
}

/* ─── Share / privacy / footer ─── */
.util-links {
  text-align: center;
  margin: 0.5rem 0 1rem;
}

a.privacy,
.util-links a {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-decoration: none;
}

a.privacy:hover,
.util-links a:hover {
  color: var(--accent-gold);
}

#shareArea {
  display: none;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 1rem;
  margin-bottom: 1rem;
}

#shareArea h3 {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  font-weight: 700;
}

#shareArea input {
  width: 100%;
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 0.8rem;
  margin: 0.5rem 0;
}

#resultsImg {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin-top: 0.5rem;
}

.site-footer {
  margin-top: auto;
  padding-top: 1rem;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-dim);
}

#privacyPolicy {
  position: fixed;
  inset: 1rem;
  max-width: 36rem;
  margin: auto;
  overflow-y: auto;
  z-index: 9999;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 1.25rem;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.8);
}

#privacyPolicy h2,
#privacyPolicy h4 {
  margin-top: 1rem;
}

#privacyPolicy ul {
  padding-left: 1.25rem;
}

#privacyPolicy a {
  color: var(--accent-gold);
}

.closePrivacyPolicy {
  text-align: center;
  margin-top: 1rem;
}

/* ─── Desktop ─── */
@media (min-width: 640px) {
  .app {
    max-width: 560px;
    padding: 1.5rem 1.5rem 3rem;
  }

  .metrics-grid {
    gap: 1rem;
  }

  .metric-tile .meterText {
    font-size: 1.85rem;
  }

  .gauge-section {
    max-width: 380px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #startStopBtn,
  .metric-tile,
  #testWrapper.visible {
    transition: none;
    animation: none;
  }

  span.loadCircle {
    animation: none;
  }
}
