:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --border: #d8dee8;
  --text: #1d2733;
  --muted: #5f6c7b;
  --accent: #146c63;
  --accent-dark: #0d4f49;
  --danger: #b42318;
  --shadow: 0 18px 42px rgba(29, 39, 51, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(circle at 50% 0%, #ffffff 0, var(--bg) 44rem);
  color: var(--text);
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid rgba(20, 108, 99, 0.28);
  outline-offset: 3px;
}

.speedtest-app {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 22px;
}

.speedtest-card {
  width: min(840px, 100%);
  padding: clamp(20px, 4vw, 34px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.45rem);
  line-height: 1.1;
}

.ghost-button,
.start-button {
  min-height: 42px;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 800;
}

.ghost-button {
  padding: 0 14px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.ghost-button:not(:disabled):hover {
  border-color: var(--accent);
  color: var(--accent);
}

.gauge {
  position: relative;
  width: min(440px, 100%);
  aspect-ratio: 2 / 1;
  margin: 34px auto 0;
  overflow: hidden;
}

.gauge-track,
.gauge-fill {
  position: absolute;
  inset: 0;
  border-radius: 999px 999px 0 0;
}

.gauge-track {
  background: conic-gradient(from 270deg at 50% 100%, #e7ecf2 0deg 180deg, transparent 180deg 360deg);
}

.gauge-fill {
  background: conic-gradient(from 270deg at 50% 100%, var(--accent) 0deg var(--gauge-angle, 0deg), transparent var(--gauge-angle, 0deg) 360deg);
  transition: background 0.2s ease;
}

.gauge::after {
  content: "";
  position: absolute;
  left: 9%;
  right: 9%;
  bottom: -1px;
  height: 82%;
  border-radius: 999px 999px 0 0;
  background: var(--surface);
}

.needle {
  position: absolute;
  left: 50%;
  bottom: 0;
  z-index: 2;
  width: 4px;
  height: 42%;
  border-radius: 99px;
  background: var(--text);
  transform: translateX(-50%) rotate(var(--needle-angle, -90deg));
  transform-origin: 50% 100%;
  transition: transform 0.25s ease;
}

.gauge-center {
  position: absolute;
  inset: auto 12% 10px;
  z-index: 3;
  display: grid;
  justify-items: center;
  gap: 3px;
  text-align: center;
}

.gauge-center span,
.gauge-center small,
.metric span,
.metric small,
.ip-grid dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.gauge-center strong {
  font-size: clamp(2.4rem, 9vw, 4.6rem);
  line-height: 1;
}

.start-button {
  display: block;
  width: min(220px, 100%);
  margin: 24px auto 0;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
}

.start-button:hover {
  background: var(--accent-dark);
}

.start-button.is-running {
  border-color: var(--danger);
  background: var(--danger);
}

.status {
  min-height: 25px;
  margin: 12px 0 0;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

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

.metric {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  text-align: center;
}

.metric strong {
  display: block;
  min-height: 40px;
  margin: 8px 0 2px;
  font-size: clamp(1.55rem, 4vw, 2.15rem);
  line-height: 1;
}

.ip-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0 0;
}

.ip-grid div {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.ip-grid dt {
  margin-bottom: 6px;
}

.ip-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-weight: 800;
}

@media (max-width: 720px) {
  .speedtest-app {
    align-items: start;
    padding: 14px;
  }

  .topbar,
  .ip-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .ghost-button {
    width: 100%;
  }

  .metrics {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 440px) {
  .metrics,
  .ip-grid {
    grid-template-columns: 1fr;
  }
}
