/* The needle gauge: a speed test on a black page. A dial of ticks with the needle on a spring, the speed in the
   middle, two cards for the results and the button. Download is white, upload orange. */
:root {
  --page: #000000;          /* the page */
  --ink: #ffffff;           /* text */
  --muted: #6f6f74;         /* the dial's numbers, the units */
  --dim: #232326;           /* a tick still dark */
  --card: #111113;          /* the results' cards */
  --down: #ffffff;          /* the download's colour */
  --up: #ff6b1a;            /* the upload's colour */
}

* {
  box-sizing: border-box;
}

/* quick taps on the button never become a double tap that zooms the page */
html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Geist Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

/* the colour of the half being measured: the script swaps it */
.gauge {
  --phase: var(--down);
  display: grid;
  justify-items: center;
  gap: 18px;
  width: min(430px, 100%);
}

.gauge[data-kind='up'] {
  --phase: var(--up);
}

/* ---------------------------------------------------------------- the dial */
.gauge__dial {
  position: relative;
  width: 100%;
}

.gauge__face {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* the blur: a wedge of a conic gradient, strongest at the needle and fading the way it came; the script places it
   on the hub, as big as the needle, and gives it its angles */
.gauge__blur {
  --from: 0deg;
  --span: 0deg;
  --alpha: 0%;
  position: absolute;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(from var(--from), transparent 0deg, color-mix(in srgb, var(--phase) var(--alpha), transparent) var(--span), transparent var(--span));
  -webkit-mask-image: radial-gradient(closest-side, transparent 10%, #000 42%, #000 98%, transparent 100%);
  mask-image: radial-gradient(closest-side, transparent 10%, #000 42%, #000 98%, transparent 100%);
  opacity: 0;
  pointer-events: none;
}

/* turning back, the blur is on the other side of the needle */
.gauge__blur.is-back {
  background: conic-gradient(from var(--from), color-mix(in srgb, var(--phase) var(--alpha), transparent) 0deg, transparent var(--span));
}

.gauge__ticks line {
  stroke: var(--dim);
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke 0.35s ease;
}

.gauge__ticks line.is-major {
  stroke-width: 3.6;
}

.gauge__ticks line.is-lit {
  stroke: var(--phase);
}

.gauge__numbers text {
  fill: var(--muted);
  font-size: 13px;
  font-weight: 520;
  font-variant-numeric: tabular-nums;
  text-anchor: middle;
  dominant-baseline: central;
  transition: fill 0.3s ease;
}

.gauge__numbers text.is-lit {
  fill: var(--ink);
}

.gauge__pointer {
  fill: var(--phase);
  transition: fill 0.35s ease;
}

.gauge__hub {
  fill: var(--page);
  stroke: var(--phase);
  stroke-width: 3;
  transition: stroke 0.35s ease;
}

/* the reading, under the needle's hub */
.gauge__read {
  position: absolute;
  left: 50%;
  top: calc(100% * 260 / 356);
  translate: -50% 0;
  display: grid;
  justify-items: center;
  gap: 2px;
  pointer-events: none;
}

.gauge__phase {
  display: block;
  height: 20px;
  overflow: hidden;
}

.gauge__phase-in {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  color: var(--phase);
  font-size: 14px;
  font-weight: 600;
  transition: color 0.35s ease;
}

.gauge__phase-in svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.gauge__value {
  display: inline-block;
  font-size: clamp(42px, 13vw, 60px);
  font-weight: 620;
  line-height: 1;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
}

.gauge__unit {
  font-size: 14px;
  font-weight: 520;
  color: var(--muted);
}

/* ---------------------------------------------------------------- the results */
.gauge__results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
}

.result {
  display: grid;
  gap: 6px;
  padding: 14px 16px 15px;
  border-radius: 18px;
  background: var(--card);
  box-shadow: inset 0 0 0 1.5px transparent;
  transition: box-shadow 0.35s ease;
}

/* the card of the half being measured */
.result.is-on {
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--phase) 55%, transparent);
}

.result__name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 560;
  color: var(--muted);
}

.result__name svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: color 0.35s ease;
}

.result[data-result='down'] .result__name svg {
  color: var(--down);
}

.result[data-result='up'] .result__name svg {
  color: var(--up);
}

.result__num {
  display: flex;
  align-items: baseline;
  gap: 6px;
  height: 30px;
  overflow: hidden;
}

.result__value {
  display: inline-block;
  font-size: 26px;
  font-weight: 620;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.result__value.is-empty {
  color: var(--muted);
}

.result__unit {
  font-size: 13px;
  font-weight: 520;
  color: var(--muted);
}

/* ---------------------------------------------------------------- the button */
.go {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 180px;
  height: 54px;
  margin-top: 6px;
  padding: 0 30px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--page);
  font: inherit;
  font-size: 16px;
  font-weight: 620;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background-color 0.35s ease, color 0.35s ease, scale 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@media (hover: hover) and (pointer: fine) {
  .go:hover {
    scale: 1.035;
  }
}

.go:active {
  scale: 0.97;
}

.go:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 4px;
}

/* while the test runs the button goes dark and fills up with the time left */
.go.is-busy {
  background: #19191b;
  color: #9a9aa0;
  cursor: default;
  scale: 1;
}

.go__bar {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--phase) 16%, transparent);
  transform-origin: 0 50%;
  transform: scaleX(0);
}

.go__label {
  position: relative;
}

@media (max-width: 400px) {
  .result {
    padding: 12px 13px 13px;
  }

  .result__value {
    font-size: 23px;
  }
}

/* the number flying from the dial into its card */
.gauge__ghost {
  position: fixed;
  z-index: 5;
  margin: 0;
  color: var(--ink);
  transform-origin: 0 0;
  pointer-events: none;
}
