:root {
  --bg-top: #fff7ed;
  --bg-bot: #fef3c7;
  --ink: #1c1917;
  --muted: #78716c;
  --accent: #c2410c;
  --accent-soft: rgba(194, 65, 12, 0.14);
  --good: #059669;
  --warn: #d97706;
  --bad: #dc2626;
  --panel: rgba(255, 255, 255, 0.82);
  --font: "DM Sans", "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 18% 12%, rgba(255, 255, 255, 0.95), transparent 32%),
    radial-gradient(circle at 82% 18%, rgba(251, 146, 60, 0.28), transparent 36%),
    radial-gradient(circle at 50% 88%, rgba(194, 65, 12, 0.1), transparent 40%),
    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;
}

body.flash-perfect {
  animation: eclipse-flash 480ms ease-out;
}

body.shake-miss #stage {
  animation: stage-shake 280ms ease-out;
}

body.eclipse-punch #stage {
  animation: eclipse-punch 220ms ease-out;
}

/* Totality: sky goes night on perfect eclipse */
body.totality {
  background:
    radial-gradient(circle at 50% 42%, rgba(251, 191, 36, 0.22), transparent 28%),
    radial-gradient(circle at 18% 12%, rgba(148, 163, 184, 0.12), transparent 34%),
    radial-gradient(circle at 82% 18%, rgba(251, 146, 60, 0.14), transparent 36%),
    linear-gradient(180deg, #0f172a 0%, #1e1b4b 48%, #312e81 100%);
  color: #f8fafc;
  transition: background 220ms ease-out, color 220ms ease-out;
}

body.totality .round-label,
body.totality .side-hint,
body.totality .continue-hint,
body.totality .scoreline {
  color: rgba(226, 232, 240, 0.78);
}

body.totality .delta-text {
  text-shadow:
    0 1px 0 rgba(15, 23, 42, 0.55),
    0 0 18px rgba(251, 191, 36, 0.35);
}

body.totality .grade-text {
  text-shadow:
    0 1px 0 rgba(15, 23, 42, 0.45),
    0 0 20px rgba(251, 191, 36, 0.45);
}

body.totality .side-text,
body.totality .round-result.is-eclipse .side-text {
  color: #fff7ed;
  font-weight: 600;
  font-size: clamp(1.15rem, 3.4vw, 1.35rem);
  letter-spacing: 0.04em;
  text-shadow:
    0 1px 2px rgba(15, 23, 42, 0.95),
    0 0 12px rgba(15, 23, 42, 0.7);
}

body.totality .acc-text {
  background: rgba(15, 23, 42, 0.55);
  color: #f8fafc;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

body.totality-ring {
  animation: totality-ring 160ms ease-out;
}

@keyframes eclipse-flash {
  0% { filter: brightness(1.28); }
  40% { filter: brightness(1.1); }
  100% { filter: none; }
}

@keyframes totality-ring {
  0% { filter: brightness(1.55) saturate(1.2); }
  55% { filter: brightness(1.15); }
  100% { filter: none; }
}

@keyframes stage-shake {
  0% { transform: translate(0, 0); }
  18% { transform: translate(-5px, 2px); }
  36% { transform: translate(5px, -2px); }
  54% { transform: translate(-3px, 1px); }
  72% { transform: translate(3px, -1px); }
  100% { transform: translate(0, 0); }
}

@keyframes eclipse-punch {
  0% { transform: scale(1); }
  35% { transform: scale(1.035); }
  100% { transform: scale(1); }
}

#wrap {
  position: relative;
  width: 100%;
  height: 100%;
  margin: 0;
  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;
  background: transparent;
}

.top {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  z-index: 3;
  flex-shrink: 0;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

.round-meta {
  display: flex;
  align-items: center;
  gap: 14px;
}

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

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

.dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: inset 0 0 0 2px rgba(28, 25, 23, 0.12);
  transition: transform 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

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

.dot.perfect {
  background: #ea580c;
  box-shadow: 0 0 0 4px rgba(234, 88, 12, 0.28);
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
  transform-origin: center center;
}

#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  z-index: 1;
}

.prompt {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  margin: 0;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--panel);
  font-size: clamp(1.15rem, 3.6vw, 1.35rem);
  font-weight: 600;
  color: var(--ink);
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(28, 25, 23, 0.06);
}

.prompt.hidden {
  display: none;
}

.side-hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  margin: 0;
  max-width: 88%;
  text-align: center;
  font-size: clamp(1.05rem, 3.2vw, 1.2rem);
  color: var(--muted);
  pointer-events: none;
}

.side-hint.hidden {
  display: none;
}

.round-result {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(18%, 72px) 24px max(16%, 64px);
  background: transparent;
  pointer-events: none;
  animation: result-in 220ms ease-out;
}

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

.result-top,
.result-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  max-width: 420px;
}

.result-top {
  padding-top: 4px;
}

.result-bottom {
  padding-bottom: 4px;
}

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

.delta-text {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(2.2rem, 8vw, 3.1rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.85),
    0 0 18px rgba(255, 247, 237, 0.9);
}

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

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

.delta-text.deep {
  color: #0d9488;
}

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

.grade-text {
  margin: 2px 0 0;
  font-size: clamp(1.65rem, 6vw, 2.25rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.75),
    0 0 16px rgba(255, 247, 237, 0.85);
}

.side-text {
  margin: 0;
  font-size: clamp(1.05rem, 3vw, 1.2rem);
  font-weight: 500;
  color: var(--muted);
  text-transform: lowercase;
}

.round-result.is-eclipse .side-text {
  color: #9a3412;
  font-weight: 600;
  font-size: clamp(1.12rem, 3.3vw, 1.3rem);
  letter-spacing: 0.03em;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.9),
    0 0 10px rgba(255, 247, 237, 0.85);
}

.acc-text {
  margin: 8px 0 0;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  font-family: var(--mono);
  font-size: clamp(1.2rem, 3.8vw, 1.45rem);
  font-weight: 600;
  color: var(--ink);
  box-shadow: 0 2px 10px rgba(28, 25, 23, 0.05);
}

.continue-hint {
  margin: 0;
  font-size: clamp(1.05rem, 3vw, 1.2rem);
  color: var(--muted);
  animation: pulse-hint 1.4s ease-in-out infinite;
}

@keyframes pulse-hint {
  0%,
  100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.scoreline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  font-family: var(--mono);
  font-size: clamp(1.05rem, 3vw, 1.2rem);
  color: var(--muted);
  z-index: 3;
}

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

.confetti.hidden {
  display: none;
}

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

@keyframes confetti-fall {
  to {
    top: 110%;
    transform: translateX(30px) rotate(240deg);
    opacity: 0.2;
  }
}

.result {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 28px 22px;
  background:
    radial-gradient(circle at 50% 20%, rgba(251, 191, 36, 0.35), transparent 42%),
    linear-gradient(180deg, rgba(255, 247, 237, 0.96), rgba(254, 243, 199, 0.97));
}

.result.hidden {
  display: none;
}

.result-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

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

.result-tier {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.result-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  width: min(100%, 320px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  font-family: var(--mono);
  font-size: 0.88rem;
  color: var(--ink);
}

.result-hint {
  margin: 18px 0 0;
  font-size: 0.95rem;
  color: var(--muted);
  animation: pulse-hint 1.4s ease-in-out infinite;
}

.hidden {
  display: none !important;
}

@media (min-width: 600px) {
  #wrap {
    gap: 16px;
  }

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

  .round-label {
    font-size: 1.6rem;
  }

  .prompt {
    font-size: 1.4rem;
    padding: 12px 22px;
  }

  .side-hint {
    font-size: 1.25rem;
  }

  .scoreline {
    font-size: 1.2rem;
  }
}

@media (min-width: 900px) {
  .top,
  .scoreline {
    max-width: 640px;
  }
}

@media (orientation: landscape) and (min-width: 700px) {
  .top,
  .scoreline {
    max-width: min(560px, 70vh);
  }
}
