:root {
  --bg-top: #e8f7f4;
  --bg-bot: #f7f3ea;
  --ink: #1a2e2b;
  --muted: #5c736e;
  --accent: #0f766e;
  --accent-soft: rgba(15, 118, 110, 0.14);
  --good: #059669;
  --warn: #d97706;
  --bad: #dc2626;
  --panel: rgba(255, 255, 255, 0.78);
  --blind: #0a1211;
  --font: "Outfit", "Trebuchet MS", "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

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

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 16% 10%, rgba(255, 255, 255, 0.95), transparent 30%),
    radial-gradient(circle at 84% 16%, rgba(15, 118, 110, 0.16), transparent 32%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bot));
  color: var(--ink);
  font-family: var(--font);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 80ms linear;
}

body.state-blind {
  background: var(--blind);
  color: rgba(255, 255, 255, 0.08);
}

#wrap {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding:
    max(14px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  z-index: 3;
}

.round-label {
  font-size: clamp(1.1rem, 3.2vw, 1.35rem);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
}

body.state-blind .round-label,
body.state-blind .scoreline,
body.state-blind .dot {
  opacity: 0;
}

.dots {
  display: flex;
  gap: 10px;
}

.dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: inset 0 0 0 2px rgba(26, 46, 43, 0.12);
  transition: transform 180ms ease, background 180ms ease;
}

.dot.on {
  background: var(--accent);
  transform: scale(1.12);
  box-shadow: none;
}

.dot.perfect {
  background: #10b981;
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.28);
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border-radius: 32px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.28) 45%, rgba(15, 118, 110, 0.08));
  border: 3px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 14px 34px rgba(15, 118, 110, 0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 22px;
  transition: background 80ms linear, border-color 80ms linear, box-shadow 80ms linear;
}

body.state-blind #stage {
  background: #050908;
  border-color: #0a1211;
  box-shadow: none;
}

.heartbeat {
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.045), transparent 68%);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.92);
}

body.state-blind .heartbeat {
  animation: heartbeat 1s ease-in-out infinite;
}

@keyframes heartbeat {
  0%,
  100% {
    opacity: 0.02;
    transform: scale(0.92);
  }
  50% {
    opacity: 0.055;
    transform: scale(1.04);
  }
}

.prompt {
  margin: 0 0 16px;
  font-size: clamp(1.2rem, 3.8vw, 1.45rem);
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  z-index: 2;
}

body.state-blind .prompt,
body.state-blind .timer {
  opacity: 0;
  pointer-events: none;
}

/* Faint coach text in the dark so “tap at blackout” is less tempting */
body.state-blind .side-hint {
  opacity: 0.28;
  color: rgba(255, 255, 255, 0.62);
  pointer-events: none;
  transition: opacity 160ms ease, color 160ms ease;
}

body.state-blind.nudge-early .side-hint {
  opacity: 0.92;
  color: rgba(255, 255, 255, 0.95);
}

.timer {
  font-family: var(--mono);
  font-size: clamp(4.4rem, 17vw, 6.4rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--ink);
  z-index: 2;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
  transition: opacity 40ms linear;
}

.side-hint {
  margin: 20px 0 0;
  max-width: 20rem;
  text-align: center;
  font-size: clamp(1rem, 3vw, 1.2rem);
  line-height: 1.35;
  color: var(--muted);
  z-index: 2;
}

.round-result {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px 22px;
  background: #ffffff;
  z-index: 4;
}

.round-result.hidden {
  display: none;
}

body.state-round_end .timer,
body.state-round_end .prompt,
body.state-round_end .side-hint,
body.state-final .timer,
body.state-final .prompt,
body.state-final .side-hint {
  visibility: hidden;
}

.delta-text {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(3rem, 12vw, 4.2rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.delta-text.early {
  color: var(--warn);
}

.delta-text.late {
  color: var(--accent);
}

.delta-text.perfect {
  color: var(--good);
}

.delta-text.fail {
  color: var(--bad);
}

.grade-text {
  margin: 0;
  font-size: clamp(1.45rem, 5vw, 1.85rem);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.side-text {
  margin: 0;
  font-size: clamp(1.05rem, 3vw, 1.2rem);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.timeline {
  width: min(100%, 320px);
  margin-top: 22px;
}

.timeline-track {
  position: relative;
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(90deg, #cfe8e3, #e8efe0 62.5%, #f3d5c8);
  box-shadow: inset 0 0 0 1px rgba(26, 46, 43, 0.08);
}

.timeline-zero {
  position: absolute;
  left: 62.5%;
  top: -5px;
  bottom: -5px;
  width: 3px;
  margin-left: -1.5px;
  background: var(--ink);
  opacity: 0.55;
  border-radius: 2px;
}

.timeline-tap {
  position: absolute;
  top: 50%;
  width: 20px;
  height: 20px;
  margin-left: -10px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.2);
  left: 62.5%;
  transition: left 220ms ease;
}

.timeline-tap.fail {
  background: var(--bad);
  box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.18);
}

.timeline-tap.perfect {
  background: var(--good);
  box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.22);
}

.timeline-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--muted);
}

.continue-hint {
  margin: 22px 0 0;
  font-size: clamp(1.05rem, 3vw, 1.2rem);
  font-weight: 600;
  color: var(--muted);
}

.scoreline {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 6px 8px 4px;
  font-family: var(--mono);
  font-size: clamp(0.95rem, 2.8vw, 1.15rem);
  color: var(--muted);
}

.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 5;
}

.confetti.hidden {
  display: none;
}

.confetti span {
  position: absolute;
  top: -12px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  animation: confetti-fall 900ms ease-out forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(110vh) rotate(280deg);
    opacity: 0;
  }
}

body.flash-perfect #stage {
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.45), 0 14px 34px rgba(15, 118, 110, 0.12);
}

.result {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px 26px;
  background:
    radial-gradient(circle at 50% 20%, rgba(255, 255, 255, 0.95), transparent 42%),
    linear-gradient(180deg, rgba(232, 247, 244, 0.97), rgba(247, 243, 234, 0.98));
}

.result.hidden {
  display: none;
}

.result-title {
  margin: 0;
  font-size: clamp(1.1rem, 3vw, 1.3rem);
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.result-score {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(3.4rem, 12vw, 4.6rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}

.result-tier {
  margin: 0 0 10px;
  font-size: clamp(1.35rem, 4vw, 1.65rem);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.result-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  width: min(100%, 280px);
  border-top: 1px solid rgba(26, 46, 43, 0.12);
  border-bottom: 1px solid rgba(26, 46, 43, 0.12);
}

.result-list li {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 4px;
  font-family: var(--mono);
  font-size: clamp(1.05rem, 3vw, 1.2rem);
  border-bottom: 1px solid rgba(26, 46, 43, 0.06);
}

.result-list li:last-child {
  border-bottom: none;
}

.result-hint {
  margin: 20px 0 0;
  font-size: clamp(1.05rem, 3vw, 1.2rem);
  font-weight: 600;
  color: var(--muted);
}

@media (min-width: 600px) {
  #wrap {
    max-width: 560px;
  }

  .dot {
    width: 24px;
    height: 24px;
  }

  .timer {
    font-size: clamp(5.2rem, 10vw, 7rem);
  }

  .timeline {
    width: min(100%, 360px);
  }

  .timeline-track {
    height: 16px;
  }

  .timeline-tap {
    width: 24px;
    height: 24px;
    margin-left: -12px;
    margin-top: -12px;
  }
}

@media (min-width: 900px) {
  #wrap {
    max-width: 600px;
  }
}

@media (orientation: landscape) and (min-width: 700px) {
  #wrap {
    max-width: min(520px, 72vh);
  }

  #stage {
    border-radius: 28px;
  }
}
