html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0c0d11;
  color: #f2f3f6;
  font-family: system-ui, ui-sans-serif, sans-serif;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#field {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: pointer;
}

#pulse {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.dot,
.ring {
  grid-area: 1 / 1;
  border-radius: 50%;
}

.dot {
  width: 14px;
  height: 14px;
  background: #e11d2a;
  opacity: 0.7;
  transform: scale(1);
}

#field:has(#bpm:not(:empty)) .dot {
  opacity: 0;
  animation: none;
}

.ring {
  border: 2px solid #e11d2a;
  opacity: 0;
  transform: scale(0.35);
}

.ring:nth-child(2) { width: 72px; height: 72px; }
.ring:nth-child(3) { width: 128px; height: 128px; }
.ring:nth-child(4) { width: 184px; height: 184px; }
.ring:nth-child(5) { width: 240px; height: 240px; }
.ring:nth-child(6) { width: 296px; height: 296px; }

#pulse.is-on .dot {
  animation: dot-hit 0.28s ease-out;
}

#pulse.is-on .ring {
  animation: ring-hit 0.55s ease-out;
}

#pulse.is-on .ring:nth-child(3) { animation-delay: 0.02s; }
#pulse.is-on .ring:nth-child(4) { animation-delay: 0.04s; }
#pulse.is-on .ring:nth-child(5) { animation-delay: 0.06s; }
#pulse.is-on .ring:nth-child(6) { animation-delay: 0.08s; }

@keyframes dot-hit {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0.45; transform: scale(1.15); }
}

@keyframes ring-hit {
  0% {
    opacity: 0.85;
    transform: scale(0.72);
    border-color: #e11d2a;
  }
  100% {
    opacity: 0;
    transform: scale(1.08);
    border-color: #4a1216;
  }
}

#readout {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 6px;
  pointer-events: none;
}

#bpm {
  font-size: clamp(4.5rem, 18vw, 8rem);
  font-weight: 560;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  letter-spacing: -0.04em;
  line-height: 0.9;
}

#bpm:empty {
  font-size: 0;
  line-height: 0;
}

#bpm:empty + .unit {
  display: none;
}

.unit {
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(242, 243, 246, 0.46);
}

#controls {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  gap: 10px;
  padding: 6px;
}

#controls button {
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.78);
  font: inherit;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px 14px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

#controls button:disabled {
  opacity: 0.38;
  cursor: default;
  pointer-events: none;
}

#controls button:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 2px;
}
