:root {
  --bg-top:    #1f1d3a;
  --bg-bottom: #2e2351;
  --ink:       #f6f1e8;
  --ink-dim:   rgba(246, 241, 232, 0.62);
  --ink-dim2:  rgba(246, 241, 232, 0.35);
  --accent:    #ffd166;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 35%, var(--bg-top) 0%, var(--bg-bottom) 75%, #1a1632 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(ellipse at 50% 50%, transparent 50%, rgba(0,0,0,0.35) 100%);
}

/* ---------- HUD ---------- */
/* Wrapper so we can toggle the whole HUD off in IDLE in one place. */
.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  user-select: none;
  z-index: 5;
}
.hud[hidden] { display: none; }

.hud .score {
  position: absolute;
  top: 28px;
  left: 50%;
  transform: translateX(-50%);
  font: 700 72px -apple-system, system-ui, sans-serif;
  color: var(--ink);
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.hud .score.pop { animation: pop 0.3s ease-out; }
@keyframes pop {
  0%   { transform: translateX(-50%) scale(1); }
  40%  { transform: translateX(-50%) scale(1.18); }
  100% { transform: translateX(-50%) scale(1); }
}

.hud .combo {
  position: absolute;
  top: 116px;
  left: 50%;
  transform: translateX(-50%);
  font: 700 22px -apple-system, system-ui, sans-serif;
  color: var(--accent);
  letter-spacing: 0.06em;
  text-shadow: 0 2px 12px rgba(255, 209, 102, 0.35);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.hud .combo[hidden] { display: none; }
.hud .combo.visible { opacity: 1; }
/* SMASH "thwack": briefly scale up to 1.3 then back. Same pattern as
   the score pop, scoped to the combo line so it doesn't fight with
   the transform that centres it. */
.hud .combo.smash {
  animation: smashPop 0.42s cubic-bezier(0.34, 1.56, 0.64, 1);
  color: #fff7c2;
  text-shadow: 0 2px 18px rgba(255, 235, 130, 0.65), 0 0 32px rgba(255, 209, 102, 0.45);
}
@keyframes smashPop {
  0%   { transform: translateX(-50%) scale(1);    }
  30%  { transform: translateX(-50%) scale(1.55); }
  100% { transform: translateX(-50%) scale(1);    }
}

.hud .best {
  position: absolute;
  top: 18px;
  left: 18px;
  font: 600 12px -apple-system, system-ui, sans-serif;
  color: var(--ink-dim2);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  transition: color 0.3s ease;
  transform-origin: left center;
}
/* Fires once per run when score crosses the previous best (see setScore). */
.hud .best.new-best {
  animation: newBestPulse 1.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes newBestPulse {
  0%   { transform: scale(1);    color: var(--ink-dim2); text-shadow: none; }
  15%  { transform: scale(1.55); color: var(--accent);   text-shadow: 0 0 22px rgba(255, 209, 102, 0.8); }
  100% { transform: scale(1);    color: var(--accent);   text-shadow: 0 0 6px rgba(255, 209, 102, 0.4); }
}

/* ---------- overlays (start + death share .card) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  /* Soft tint + light blur. Death overlay overrides to a weaker blur
     so the lingering particle aftermath stays readable. */
  background: rgba(15, 13, 30, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 20;
  /* Subtle pop-in. No-op on first paint of start; small breath on death. */
  animation: overlayFade 0.18s ease-out;
}
@keyframes overlayFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.overlay[hidden] { display: none; }

/* Death overlay: soften the blur so debris/sparks remain visible
   behind the card, and snap in instantly — death should feel immediate. */
#overlayDead {
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  background: rgba(15, 13, 30, 0.32);
  animation: none;
}

.card {
  text-align: center;
  color: var(--ink);
  padding: 8px 24px;
  max-width: 360px;
}

.card .title {
  font: 700 42px -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif;
  margin: 0 0 12px;
  letter-spacing: -0.01em;
  line-height: 1.05;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.card .lede {
  margin: 0 0 28px;
  font: 400 15px -apple-system, system-ui, sans-serif;
  color: var(--ink-dim);
  line-height: 1.55;
}

.card .stat {
  margin: 0 0 28px;
  font: 500 14px -apple-system, system-ui, sans-serif;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
}
.card .stat span {
  color: var(--ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.play {
  appearance: none;
  border: 0;
  cursor: pointer;
  padding: 14px 44px;
  border-radius: 999px;
  background: var(--accent);
  color: #2a1f3b;
  font: 700 17px -apple-system, system-ui, sans-serif;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 28px rgba(255, 209, 102, 0.35);
  transition: transform 0.12s ease, box-shadow 0.18s ease;
}
.play:hover  { transform: translateY(-2px); box-shadow: 0 12px 32px rgba(255, 209, 102, 0.45); }
.play:active { transform: translateY(1px); }
.play:focus-visible {
  outline: 2px solid rgba(255, 209, 102, 0.6);
  outline-offset: 4px;
}

.back {
  display: inline-block;
  margin-top: 22px;
  color: var(--ink-dim2);
  text-decoration: none;
  font: 500 12px -apple-system, system-ui, sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 6px 4px;
}
.back:hover { color: var(--ink-dim); }

/* ---------- leaderboard ---------- */
.lb {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 188px;
  z-index: 6;
  background: rgba(15, 13, 30, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 12px 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--ink);
  user-select: none;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  box-shadow: 0 8px 24px rgba(0,0,0,0.28);
}
.lb-toggle {
  display: none; /* hidden on desktop; visible on mobile */
  position: absolute;
  top: 6px;
  right: 8px;
  background: transparent;
  border: 0;
  color: var(--ink-dim);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
}
.lb-head {
  font: 700 10px ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
  margin-bottom: 6px;
}
.lb-list {
  list-style: none;
  padding: 0;
  margin: 0 0 6px 0;
  font-variant-numeric: tabular-nums;
}
.lb-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 6px;
  align-items: baseline;
  padding: 2px 0;
  font-size: 12px;
  color: var(--ink-dim);
}
.lb-row .lb-rank {
  color: var(--ink-dim2);
  font-size: 11px;
  text-align: right;
}
.lb-row .lb-name-cell {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-row .lb-score {
  color: var(--ink);
  font-weight: 700;
}
.lb-row.lb-mine {
  background: rgba(255, 209, 102, 0.10);
  border-radius: 6px;
  padding: 2px 4px;
  margin: 0 -4px;
}
.lb-row.lb-mine .lb-rank,
.lb-row.lb-mine .lb-name-cell,
.lb-row.lb-mine .lb-score { color: var(--accent); }
.lb-empty {
  font-size: 11px;
  color: var(--ink-dim2);
  font-style: italic;
  padding: 4px 0;
}
.lb-you {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 6px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--ink-dim);
}
.lb-you strong { color: var(--accent); font-weight: 700; }
.lb-name {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 8px;
  margin-top: 8px;
}
.lb-name-label {
  display: block;
  font: 700 9px ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.18em;
  color: var(--ink-dim2);
  margin-bottom: 4px;
  text-transform: uppercase;
}
.lb-name-row {
  display: flex;
  gap: 6px;
}
.lb-name-row input {
  flex: 1;
  min-width: 0;
  font: 600 12px -apple-system, system-ui, sans-serif;
  color: var(--ink);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 6px;
  padding: 5px 8px;
  outline: none;
}
.lb-name-row input:focus {
  border-color: rgba(255, 209, 102, 0.5);
}
.lb-name-row input::placeholder { color: var(--ink-dim2); }
.lb-name-row button {
  appearance: none;
  border: 0;
  cursor: pointer;
  background: var(--accent);
  color: #2a1f3b;
  font: 700 11px -apple-system, system-ui, sans-serif;
  padding: 0 10px;
  border-radius: 6px;
  letter-spacing: 0.02em;
}
.lb-name-row button:disabled { opacity: 0.5; cursor: default; }
.lb-name-msg {
  font-size: 10px;
  color: var(--ink-dim2);
  min-height: 12px;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

/* Collapsed state hides everything except the toggle button + a slim header. */
.lb.lb-collapsed { padding: 6px 8px; width: auto; }
.lb.lb-collapsed .lb-list,
.lb.lb-collapsed .lb-you,
.lb.lb-collapsed .lb-name,
.lb.lb-collapsed .lb-head { display: none; }
.lb.lb-collapsed .lb-toggle { position: static; display: inline-block; }
.lb.lb-collapsed .lb-toggle::after { content: " TOP 10"; font: 700 10px ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.18em; color: var(--ink-dim); }

/* ---------- mobile ---------- */
@media (max-width: 540px) {
  .lb {
    top: 10px;
    right: 10px;
    width: 160px;
    padding: 8px 10px 10px;
  }
  .lb-toggle { display: inline-block; }
  .lb-row { font-size: 11px; padding: 1px 0; }
  .lb-row .lb-rank { font-size: 10px; }
  .hud .score { font-size: 56px !important; top: 12px !important; }
  .hud .best  { top: 12px !important; left: 12px !important; font-size: 11px !important; }
  .hud .combo { top: 76px !important; font-size: 18px !important; }
}
@media (max-width: 380px) {
  .lb { width: 144px; padding: 6px 8px 8px; }
  .hud .score { font-size: 48px !important; }
}

/* Leaderboard hidden on helixjump.world — backend not deployed here yet.
   The widget calls /api/helix/* which 404s; the JS handles failure silently,
   but the empty "loading…" UI is ugly. Re-enable when a backend exists. */
.lb { display: none !important; }

/* Red flash overlay — fired briefly on death (see gameOver() in game.js).
   Sits above the vignette, below the death overlay. Animation plays once
   per added .visible class, then JS removes the class. */
#redFlash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 55%, rgba(255, 46, 79, 0.55) 0%, rgba(255, 46, 79, 0) 70%);
  opacity: 0;
  z-index: 5;
}
#redFlash.visible {
  animation: redFlash 400ms ease-out;
}
@keyframes redFlash {
  0%   { opacity: 0; }
  12%  { opacity: 1; }
  100% { opacity: 0; }
}

/* World-crossing flash — gold radial, fires when the ball crosses into a
   new world (every 8 rings). Same idea as #redFlash but warmer + softer. */
#worldFlash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, rgba(255, 209, 102, 0.5) 0%, rgba(255, 209, 102, 0) 65%);
  opacity: 0;
  z-index: 4;
}
#worldFlash.visible {
  animation: worldFlash 720ms ease-out;
}
@keyframes worldFlash {
  0%   { opacity: 0; }
  15%  { opacity: 1; }
  100% { opacity: 0; }
}
