/**
 * Rhythm game — blueprint / technical aesthetic
 * ---------------------------------------------------------------------------
 * Visual systems:
 * 1) Atmospheric stack (.atmospheric-bg) — full-bleed art, blur + dim + blue veil.
 * 2) Lane runway (.lane-scene + .lane) — perspective + rotateX runway, clip-path trapezoid.
 * 3) Notes (.note) — energy orbs; scale, opacity, --note-emphasis + filter from JS by distance.
 * 4) Hit line (.hit-line) — blueprint-style target; CSS-only hit/miss pulse (no image decode).
 * 5) HUD / chrome — minimal overlays; gameplay reads first.
 * 6) Landing overlay — welcome + Start, then same flow as transport play.
 */

:root {
  /** HUD score / timer / transport pulse length — keep in sync with `SCORE_HUD_PULSE_MS` in script.js */
  --hud-score-pulse-ms: 400ms;
  --bp-veil: rgba(10, 30, 60, 0.6);
  --bp-lane-fill: rgba(12, 36, 72, 0.55);
  --bp-yellow: #f0d24a;
  --bp-yellow-soft: rgba(240, 210, 74, 0.55);
  --bp-edge-glow: 0 0 14px rgba(240, 210, 74, 0.35),
    0 0 28px rgba(240, 210, 74, 0.12);
  --bp-text: rgba(255, 255, 255, 0.92);
  --bp-muted: rgba(255, 255, 255, 0.55);
  --lane-trap-top-inset: 30%;
  --lane-trap-bottom-inset: 0%;
  --hit-line-from-top: 82%;
  --hit-line-hit-pulse-ms: 340ms;
  --hit-line-miss-pulse-ms: 260ms;
  /** Orb diameter (current pass: 20% bigger than last tuning step). */
  --note-size: calc(44px * 0.85 * 0.8 * 0.72);
  --font-body: "Tiro Devanagari Sanskrit", ui-serif, "Noto Serif", serif;
}

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

html,
body {
  height: 100%;
  margin: 0;
}

/* Global credit — above overlays (landing, count-in, end) so it stays visible */
.game-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 55;
  pointer-events: none;
  padding: 0.4rem 1rem calc(0.45rem + env(safe-area-inset-bottom, 0px));
  text-align: center;
}

.game-footer__credit {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.58);
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.55);
}

.game-footer__socials {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
  pointer-events: auto;
}

.game-footer__social {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  min-height: 2.25rem;
  padding: 0.35rem;
  color: rgba(255, 255, 255, 0.48);
  text-decoration: none;
  border-radius: 8px;
  transition: color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

.game-footer__social:hover {
  color: rgba(255, 248, 210, 0.95);
  background: rgba(255, 255, 255, 0.06);
}

.game-footer__social:focus-visible {
  outline: 2px solid rgba(240, 210, 74, 0.65);
  outline-offset: 2px;
}

.game-footer__social:active {
  transform: scale(0.94);
}

.game-footer__icon {
  display: block;
  width: 1.15rem;
  height: 1.15rem;
}

body {
  font-family: var(--font-body);
  color: var(--bp-text);
  background: #050a14;
  overflow-x: hidden;
}

/* --- 1. Atmospheric layer (below all gameplay) --- */
.atmospheric-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.symbol-rain-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  opacity: 0.41;
  filter: none;
}

.atmospheric-bg::before {
  content: "";
  position: absolute;
  inset: -8%;
  background: url("assets/mathematics.png") center / cover no-repeat;
  transform: scale(1.05);
  filter: blur(8px) brightness(0.62);
  will-change: transform, filter;
}

.atmospheric-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--bp-veil);
}

/* --- App shell (above atmosphere) --- */
.app {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.75rem 1rem 1.5rem;
  max-width: 720px;
  margin: 0 auto;
}

/* --- 8. HUD (score top-left, time top-right; fixed bar) --- */
.hud-overlay {
  position: fixed;
  top: 0.65rem;
  left: 0.85rem;
  right: 0.85rem;
  z-index: 25;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin: 0;
  padding: 0.2rem 0;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--bp-muted);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.hud-overlay__cluster--end {
  text-align: right;
  align-items: flex-end;
}

.hud-overlay__cluster--timer {
  align-items: flex-end;
}

.hud-overlay__cluster {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  align-items: flex-start;
}

.hud-overlay__value {
  display: inline-block;
  transform-origin: center center;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--bp-text);
  font-variant-numeric: tabular-nums;
}

/* Match .feedback--perfect / .feedback--good (gold) and .feedback--miss (cool gray) */
@keyframes hudScoreTickUp {
  0% {
    transform: scale(1) translateY(0);
    color: var(--bp-text);
    text-shadow: none;
  }
  18% {
    transform: scale(1.084) translateY(-3.6px);
    color: rgba(255, 250, 220, 0.98);
    text-shadow: 0 0 20px rgba(240, 210, 74, 0.5), 0 0 34px rgba(240, 210, 74, 0.28);
  }
  38% {
    transform: scale(1.042) translateY(-1.4px);
    color: rgba(255, 252, 238, 0.96);
    text-shadow: 0 0 14px rgba(240, 210, 74, 0.42);
  }
  58% {
    transform: scale(0.982) translateY(0);
    color: rgba(255, 252, 235, 0.95);
    text-shadow: 0 0 12px rgba(240, 210, 74, 0.35);
  }
  80% {
    transform: scale(1.006) translateY(0);
    color: var(--bp-text);
    text-shadow: 0 0 6px rgba(240, 210, 74, 0.12);
  }
  100% {
    transform: scale(1) translateY(0);
    color: var(--bp-text);
    text-shadow: none;
  }
}

@keyframes hudScoreTickDown {
  0% {
    transform: scale(1) translateY(0);
    color: var(--bp-text);
    text-shadow: none;
  }
  24% {
    transform: scale(0.965) translateY(1.1px);
    color: rgba(208, 216, 232, 0.92);
    text-shadow: 0 0 8px rgba(150, 175, 210, 0.28);
  }
  46% {
    transform: scale(0.916) translateY(2.4px);
    color: rgba(200, 210, 230, 0.95);
    text-shadow: 0 0 14px rgba(150, 175, 210, 0.45), 0 0 26px rgba(120, 150, 190, 0.2);
  }
  68% {
    transform: scale(1.018) translateY(0);
    color: rgba(215, 225, 240, 0.88);
    text-shadow: 0 0 8px rgba(160, 185, 220, 0.28);
  }
  88% {
    transform: scale(1.003) translateY(0);
    color: rgba(235, 240, 248, 0.9);
    text-shadow: 0 0 4px rgba(160, 185, 220, 0.12);
  }
  100% {
    transform: scale(1) translateY(0);
    color: var(--bp-text);
    text-shadow: none;
  }
}

.hud-overlay__value.hud-overlay__value--score-up {
  animation: hudScoreTickUp var(--hud-score-pulse-ms, 400ms) cubic-bezier(0.28, 1.1, 0.4, 1) both;
}

.hud-overlay__value.hud-overlay__value--score-down {
  animation: hudScoreTickDown var(--hud-score-pulse-ms, 400ms) cubic-bezier(0.22, 0.92, 0.34, 1)
    both;
}

/* Formatted time is vertically centered in the 48px ring; nudge score down to match */
.hud-overlay__cluster:not(.hud-overlay__cluster--end) .hud-overlay__value {
  margin-top: 0.85rem;
}

/* --- Circular elapsed timer (HUD) --- */
.song-timer {
  position: relative;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  transform-origin: center center;
}

/* Shared with `.app-chrome` transport; same motion as score (glow via filter so controls + label read as one unit) */
@keyframes songTimerTickUp {
  0% {
    transform: scale(1) translateY(0);
    filter: none;
  }
  18% {
    transform: scale(1.084) translateY(-3.6px);
    filter: drop-shadow(0 0 8px rgba(240, 210, 74, 0.55))
      drop-shadow(0 0 18px rgba(240, 210, 74, 0.32));
  }
  38% {
    transform: scale(1.042) translateY(-1.4px);
    filter: drop-shadow(0 0 6px rgba(240, 210, 74, 0.42));
  }
  58% {
    transform: scale(0.982) translateY(0);
    filter: drop-shadow(0 0 5px rgba(240, 210, 74, 0.35));
  }
  80% {
    transform: scale(1.006) translateY(0);
    filter: drop-shadow(0 0 3px rgba(240, 210, 74, 0.15));
  }
  100% {
    transform: scale(1) translateY(0);
    filter: none;
  }
}

@keyframes songTimerTickDown {
  0% {
    transform: scale(1) translateY(0);
    filter: none;
  }
  24% {
    transform: scale(0.965) translateY(1.1px);
    filter: drop-shadow(0 0 5px rgba(150, 175, 210, 0.32));
  }
  46% {
    transform: scale(0.916) translateY(2.4px);
    filter: drop-shadow(0 0 7px rgba(150, 175, 210, 0.45))
      drop-shadow(0 0 14px rgba(120, 150, 190, 0.22));
  }
  68% {
    transform: scale(1.018) translateY(0);
    filter: drop-shadow(0 0 4px rgba(160, 185, 220, 0.26));
  }
  88% {
    transform: scale(1.003) translateY(0);
    filter: drop-shadow(0 0 2px rgba(160, 185, 220, 0.12));
  }
  100% {
    transform: scale(1) translateY(0);
    filter: none;
  }
}

.song-timer.song-timer--pulse-up,
.app-chrome.app-chrome--pulse-up {
  animation: songTimerTickUp var(--hud-score-pulse-ms, 400ms) cubic-bezier(0.28, 1.1, 0.4, 1) both;
}

.song-timer.song-timer--pulse-down,
.app-chrome.app-chrome--pulse-down {
  animation: songTimerTickDown var(--hud-score-pulse-ms, 400ms) cubic-bezier(0.22, 0.92, 0.34, 1) both;
}

.song-timer__svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* No visible track — only the gold arc appears as elapsed time grows */
.song-timer__track {
  stroke: none;
}

.song-timer__arc {
  stroke: var(--bp-yellow);
  stroke-width: 2.75;
  stroke-linecap: round;
  filter: drop-shadow(0 0 4px rgba(240, 210, 74, 0.45));
}

.song-timer__elapsed {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  font-size: 0.68rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 1;
  color: var(--bp-text);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

/* --- Transport chrome --- */
.app-chrome {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  max-width: 640px;
  margin-bottom: 0.65rem;
  transform-origin: center center;
}

.app-chrome__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 0.75rem;
}

.app-chrome__now-playing {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--bp-muted);
  text-align: center;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}

.app-chrome__track-title {
  color: var(--bp-yellow);
  font-weight: 700;
}

.chrome-transport {
  display: flex;
  gap: 0.35rem;
}

.btn {
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 0.5rem 1.2rem;
  background: rgba(12, 30, 62, 0.38);
  color: var(--bp-text);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: border-color 0.22s ease, box-shadow 0.22s ease, background 0.22s ease,
    filter 0.22s ease;
  box-shadow: none;
}

.btn--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border-radius: 50%;
}

.btn__icon {
  display: block;
  pointer-events: none;
}

.btn:hover {
  border-color: rgba(240, 210, 74, 0.22);
  background: rgba(16, 36, 72, 0.48);
  box-shadow: 0 6px 28px rgba(4, 14, 36, 0.35);
}

.btn:focus-visible {
  outline: 2px solid var(--bp-yellow-soft);
  outline-offset: 2px;
}

.btn--primary {
  /* Track gold (--bp-yellow) as fill; white labels/icons for contrast */
  background: linear-gradient(
    160deg,
    rgba(255, 236, 140, 0.98) 0%,
    rgba(240, 210, 74, 0.95) 42%,
    rgba(188, 155, 42, 0.94) 72%,
    rgba(120, 92, 22, 0.92) 100%
  );
  border-color: rgba(255, 248, 200, 0.45);
  color: rgba(255, 255, 255, 0.98);
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
  box-shadow: 0 4px 22px rgba(60, 48, 10, 0.38),
    0 0 20px rgba(240, 210, 74, 0.18);
}

.btn--primary:hover {
  border-color: rgba(255, 255, 255, 0.55);
  box-shadow: 0 8px 32px rgba(70, 55, 12, 0.42),
    0 0 26px rgba(240, 210, 74, 0.22);
  filter: brightness(1.04);
  background: linear-gradient(
    160deg,
    rgba(255, 244, 168, 0.99) 0%,
    rgba(248, 220, 88, 0.97) 42%,
    rgba(200, 168, 48, 0.95) 72%,
    rgba(132, 100, 28, 0.93) 100%
  );
}

.btn--ghost {
  background: rgba(8, 22, 52, 0.28);
  border-color: rgba(255, 255, 255, 0.05);
}

/* --- Playfield --- */
.game-wrap {
  width: 100%;
  max-width: 640px;
  flex: 1;
  min-height: min(58vh, 520px);
  display: flex;
  align-items: stretch;
  justify-content: center;
}

/**
 * Lane scene: establishes 3D perspective for the runway.
 * Child .lane rotates toward the camera (rotateX) with origin at the top
 * so notes travel "down" the blueprint floor.
 */
.lane-scene {
  flex: 1;
  perspective: 800px;
  perspective-origin: 50% 22%;
  display: flex;
  justify-content: center;
  align-items: stretch;
}

.lane {
  position: relative;
  width: 100%;
  max-width: 520px;
  align-self: stretch;
  transform: rotateX(58deg);
  transform-origin: top center;
  transform-style: preserve-3d;
  background: var(--bp-lane-fill);
  clip-path: polygon(
    var(--lane-trap-top-inset) 0%,
    calc(100% - var(--lane-trap-top-inset)) 0%,
    calc(100% - var(--lane-trap-bottom-inset)) 100%,
    var(--lane-trap-bottom-inset) 100%
  );
  border: 1px solid rgba(240, 210, 74, 0.28);
  box-shadow: var(--bp-edge-glow), inset 0 0 60px rgba(0, 0, 0, 0.35);
  outline: none;
}

.lane:focus-visible {
  box-shadow: var(--bp-edge-glow), 0 0 0 2px rgba(240, 210, 74, 0.45);
}

/**
 * Runway bounce on judgment — base `rotateX(58deg)` must match `.lane` default transform above.
 * Last pass: 20% harder than prior keyframes (all deviations × 1.2).
 * Motion stays inverted vs first version (Z / tilt / wobble).
 * Keep `LANE_REACTION_MS` in script.js in sync with animation duration (0.48s).
 */
@keyframes laneReactPerfect {
  0% {
    transform: rotateX(58deg) translateZ(0) scale(1);
  }
  18% {
    transform: rotateX(58.54deg) translateZ(-1.62px) scale(1.00108);
  }
  42% {
    transform: rotateX(57.82deg) translateZ(0.54px) scale(0.99964);
  }
  72% {
    transform: rotateX(58.05deg) translateZ(-0.36px) scale(1.00018);
  }
  100% {
    transform: rotateX(58deg) translateZ(0) scale(1);
  }
}

@keyframes laneReactGood {
  0% {
    transform: rotateX(58deg) translateZ(0) scale(1);
  }
  20% {
    transform: rotateX(58.36deg) translateZ(-0.9px) scale(1.00054);
  }
  48% {
    transform: rotateX(57.91deg) translateZ(0.27px) scale(0.99973);
  }
  100% {
    transform: rotateX(58deg) translateZ(0) scale(1);
  }
}

@keyframes laneReactMiss {
  0% {
    transform: rotateX(58deg) translateZ(0) rotateZ(0deg);
  }
  12% {
    transform: rotateX(57.73deg) translateZ(0.9px) rotateZ(0.0675deg);
  }
  28% {
    transform: rotateX(58.09deg) translateZ(0.36px) rotateZ(-0.0765deg);
  }
  44% {
    transform: rotateX(57.82deg) translateZ(0.72px) rotateZ(0.0405deg);
  }
  100% {
    transform: rotateX(58deg) translateZ(0) rotateZ(0deg);
  }
}

.lane.lane--react-perfect {
  animation: laneReactPerfect 0.48s cubic-bezier(0.28, 1.1, 0.4, 1) both;
}

.lane.lane--react-good {
  animation: laneReactGood 0.48s cubic-bezier(0.28, 1.05, 0.42, 1) both;
}

.lane.lane--react-miss {
  animation: laneReactMiss 0.48s cubic-bezier(0.22, 0.92, 0.34, 1) both;
}

/**
 * Blueprint grid — horizontal spacing from --lane-grid-row-pct (beat period in lane %).
 */
.lane__grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.42;
  background-image: linear-gradient(
      rgba(255, 255, 255, 0.055) 1px,
      transparent 1px
    ),
    linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.045) 1px,
      transparent 1px
    );
  background-size: 100% var(--lane-grid-row-pct, 11%), 9% 100%;
  mask-image: linear-gradient(to bottom, transparent 0%, black 16%, black 100%);
}

/* Medium/hard: tighter horizontal stripes — stronger lines + slightly brighter mask */
.lane.lane--dense-grid .lane__grid {
  opacity: 0.55;
  background-image: linear-gradient(
      rgba(255, 252, 240, 0.09) 1px,
      transparent 1px
    ),
    linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.06) 1px,
      transparent 1px
    );
  mask-image: linear-gradient(to bottom, transparent 0%, black 12%, black 100%);
}

/**
 * Blueprint "measurement" bar at the judgment line — pure CSS, no bitmap.
 * Sits under notes (z-index) so orbs pass over the glow.
 */
.hit-line {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--hit-line-from-top);
  transform: translateY(-50%);
  transform-origin: center center;
  z-index: 1;
  height: 3px;
  pointer-events: none;
  border-radius: 1px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(120, 190, 255, 0.25) 12%,
    rgba(240, 210, 74, 0.95) 45%,
    rgba(255, 248, 200, 1) 50%,
    rgba(240, 210, 74, 0.95) 55%,
    rgba(120, 190, 255, 0.25) 88%,
    transparent 100%
  );
  box-shadow: 0 0 12px rgba(240, 210, 74, 0.5),
    0 0 28px rgba(80, 150, 255, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.hit-line::before,
.hit-line::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 1px;
  height: 14px;
  margin-top: -7px;
  background: linear-gradient(
    180deg,
    transparent,
    rgba(240, 210, 74, 0.85),
    transparent
  );
  box-shadow: 0 0 6px rgba(240, 210, 74, 0.4);
  opacity: 0.85;
}

.hit-line::before {
  left: 8%;
}

.hit-line::after {
  right: 8%;
}

@keyframes hitLineHitPulse {
  0% {
    transform: translateY(-50%) scaleY(1);
    filter: brightness(1) drop-shadow(0 0 6px rgba(240, 210, 74, 0.45));
    box-shadow: 0 0 12px rgba(240, 210, 74, 0.5),
      0 0 28px rgba(80, 150, 255, 0.22),
      inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  }
  /* Peak / settle scaled to 60% of prior intensity (40% reduction) */
  22% {
    transform: translateY(-50%) scaleY(2.44);
    filter: brightness(1.45) drop-shadow(0 0 11px rgba(255, 252, 220, 0.57))
      drop-shadow(0 0 19px rgba(240, 210, 74, 0.54))
      drop-shadow(0 0 29px rgba(120, 195, 255, 0.33));
    box-shadow: 0 0 19px rgba(255, 252, 210, 0.57),
      0 0 34px rgba(240, 210, 74, 0.51),
      0 0 48px rgba(100, 175, 255, 0.27),
      inset 0 0 0 1px rgba(255, 255, 255, 0.21);
  }
  48% {
    transform: translateY(-50%) scaleY(1.51);
    filter: brightness(1.24) drop-shadow(0 0 8px rgba(240, 210, 74, 0.45));
    box-shadow: 0 0 13px rgba(240, 210, 74, 0.45),
      0 0 24px rgba(80, 150, 255, 0.21),
      inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  }
  100% {
    transform: translateY(-50%) scaleY(1);
    filter: brightness(1) drop-shadow(0 0 6px rgba(240, 210, 74, 0.45));
    box-shadow: 0 0 12px rgba(240, 210, 74, 0.5),
      0 0 28px rgba(80, 150, 255, 0.22),
      inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  }
}

.hit-line.hit-line--hit {
  animation: hitLineHitPulse var(--hit-line-hit-pulse-ms) cubic-bezier(0.34, 1.45, 0.48, 1);
}

@keyframes hitLineMissPulse {
  0% {
    transform: translateY(-50%) scaleY(1);
    filter: brightness(1) drop-shadow(0 0 4px rgba(240, 210, 74, 0.35));
    box-shadow: 0 0 12px rgba(240, 210, 74, 0.5),
      0 0 28px rgba(80, 150, 255, 0.22),
      inset 0 0 0 1px rgba(255, 255, 255, 0.12);
    opacity: 1;
  }
  35% {
    transform: translateY(-50%) scaleY(1.96);
    filter: brightness(0.73) drop-shadow(0 0 10px rgba(255, 120, 130, 0.39))
      drop-shadow(0 0 17px rgba(200, 60, 90, 0.21));
    box-shadow: 0 0 14px rgba(255, 130, 140, 0.3),
      0 0 26px rgba(180, 40, 70, 0.15),
      inset 0 0 0 1px rgba(255, 200, 200, 0.09);
    opacity: 0.95;
  }
  100% {
    transform: translateY(-50%) scaleY(1);
    filter: brightness(1) drop-shadow(0 0 4px rgba(240, 210, 74, 0.35));
    box-shadow: 0 0 12px rgba(240, 210, 74, 0.5),
      0 0 28px rgba(80, 150, 255, 0.22),
      inset 0 0 0 1px rgba(255, 255, 255, 0.12);
    opacity: 1;
  }
}

.hit-line.hit-line--miss {
  animation: hitLineMissPulse var(--hit-line-miss-pulse-ms) cubic-bezier(0.36, 1.1, 0.4, 1);
}

.notes-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

/**
 * Hit surface: invisible tap target aligned with the hit line.
 * Must match script.js HIT_LINE_FROM_TOP_PCT and --hit-line-from-top.
 */
.hit-tap-zone {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--hit-line-from-top) - 14%);
  bottom: 0;
  z-index: 4;
  cursor: pointer;
  touch-action: manipulation;
  background: transparent;
}

/* --- 4. Notes (energy orbs) --- */
.note {
  --note-emphasis: 0;
  position: absolute;
  width: var(--note-size);
  height: var(--note-size);
  margin: 0;
  border-radius: 50%;
  background: radial-gradient(
    circle at 35% 35%,
    #fff6a8 0%,
    var(--bp-yellow) 28%,
    #2a5a9e 72%,
    #0a1a3a 100%
  );
  /* Glow scales with --note-emphasis (set from JS by distance to hit line). */
  box-shadow: 0 0 calc(8px + 22px * var(--note-emphasis))
      rgba(240, 210, 74, calc(0.26 + 0.52 * var(--note-emphasis))),
    0 0 calc(3px + 14px * var(--note-emphasis))
      rgba(100, 180, 255, calc(0.16 + 0.42 * var(--note-emphasis))),
    inset 0 0 calc(5px + 14px * var(--note-emphasis))
      rgba(255, 255, 255, calc(0.07 + 0.22 * var(--note-emphasis)));
  transform: translate(-50%, -50%);
  transform-origin: center;
  will-change: transform, opacity, filter;
}

.note::after {
  content: "";
  position: absolute;
  inset: -30%;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(240, 210, 74, calc(0.14 + 0.38 * var(--note-emphasis))) 0%,
    transparent 65%
  );
  opacity: calc(0.38 + 0.55 * var(--note-emphasis));
  pointer-events: none;
  z-index: -1;
}

/**
 * Success: brief gold bloom on the orb while it shrinks away.
 * Miss: red failure glow while fading (auto-miss and late tap).
 */
@keyframes noteHitExit {
  0% {
    opacity: 1;
    box-shadow: 0 0 14px rgba(240, 210, 74, 0.42),
      0 0 5px rgba(80, 140, 255, 0.32), inset 0 0 10px rgba(255, 255, 255, 0.12);
    /* Match script NOTE_SCALE_NEAR (~1.2) so the bloom doesn’t pop from a scale reset */
    transform: translate(-50%, -50%) scale(1.2);
  }
  22% {
    opacity: 1;
    transform: translate(-50%, calc(-50% - 8px)) scale(1.24);
  }
  38% {
    opacity: 1;
    box-shadow: 0 0 36px rgba(255, 236, 160, 1),
      0 0 58px rgba(240, 210, 74, 0.88), 0 0 12px rgba(255, 200, 80, 0.95),
      inset 0 0 18px rgba(255, 248, 200, 0.55);
    filter: brightness(1.35);
    transform: translate(-50%, calc(-50% - 12px)) scale(1.16);
  }
  68% {
    opacity: 0.52;
    filter: brightness(1.2);
    transform: translate(-50%, calc(-50% - 18px)) scale(0.88);
    box-shadow: 0 0 20px rgba(240, 210, 74, 0.3);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, calc(-50% - 24px)) scale(0.64);
    filter: brightness(1.02);
    box-shadow: 0 0 8px rgba(240, 210, 74, 0.12);
  }
}

@keyframes noteMissExit {
  0% {
    opacity: 1;
    box-shadow: 0 0 14px rgba(240, 210, 74, 0.42),
      0 0 5px rgba(80, 140, 255, 0.32), inset 0 0 10px rgba(255, 255, 255, 0.12);
    transform: translate(-50%, -50%) scale(1);
  }
  22% {
    opacity: 1;
    box-shadow: 0 0 32px rgba(255, 70, 90, 0.95),
      0 0 50px rgba(220, 35, 55, 0.72),
      0 0 8px rgba(255, 130, 130, 0.85),
      inset 0 0 14px rgba(255, 100, 110, 0.35);
    filter: brightness(1.08) saturate(1.35);
    transform: translate(-50%, calc(-50% + 6px)) scale(0.98);
  }
  55% {
    opacity: 0.45;
    filter: brightness(0.75) saturate(1.1);
    box-shadow: 0 0 20px rgba(200, 40, 60, 0.4);
    transform: translate(-50%, calc(-50% + 14px)) scale(0.88);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, calc(-50% + 26px)) scale(0.82);
    filter: brightness(0.45);
    box-shadow: 0 0 8px rgba(140, 25, 45, 0.2);
  }
}

.note.note--hit-exit {
  animation: noteHitExit 0.22s cubic-bezier(0.24, 0.9, 0.34, 1) forwards;
}

.note.note--hit-exit::after {
  background: radial-gradient(
    circle,
    rgba(255, 230, 140, 0.55) 0%,
    rgba(240, 210, 74, 0.2) 45%,
    transparent 70%
  );
  opacity: 0.9;
}

.note.note--miss-exit {
  animation: noteMissExit 0.24s cubic-bezier(0.33, 0.85, 0.4, 1) forwards;
}

.note.note--miss-exit::after {
  background: radial-gradient(
    circle,
    rgba(255, 90, 100, 0.5) 0%,
    rgba(200, 30, 50, 0.22) 50%,
    transparent 70%
  );
  opacity: 0.85;
}

/* --- Landing (first screen; same stacking idea as count-in) --- */
.landing-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(4, 12, 28, 0.32);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  cursor: pointer;
}

.landing-overlay[hidden] {
  display: none !important;
}

.landing-overlay__stack {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  align-items: stretch;
  cursor: auto;
}

.landing-overlay__card {
  width: 100%;
  padding: 1.75rem 1.5rem 1.6rem;
  border-radius: 22px;
  border: 1px solid rgba(240, 210, 74, 0.08);
  background: rgba(8, 22, 52, 0.29);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.18),
    0 0 28px rgba(240, 210, 74, 0.03), inset 0 1px 0 rgba(255, 255, 255, 0.03);
  text-align: center;
}

.landing-overlay__card--intro {
  padding-bottom: 1.5rem;
}

.landing-overlay__card--play {
  padding-top: 1.5rem;
}

.landing-overlay__title {
  margin: 0;
  font-size: clamp(1.65rem, 5vw, 2rem);
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--bp-text);
  text-shadow: 0 0 24px rgba(240, 210, 74, 0.2);
}

.landing-overlay__difficulty {
  margin: 0 0 1.15rem;
  text-align: center;
}

.landing-overlay__difficulty-legend {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}

.landing-overlay__difficulty-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
}

.difficulty-option {
  position: relative;
  cursor: pointer;
  margin: 0;
}

.difficulty-option input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
}

.difficulty-option__label {
  display: inline-block;
  padding: 0.4rem 0.95rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--bp-muted);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(8, 22, 52, 0.35);
  transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease,
    box-shadow 0.18s ease;
}

.difficulty-option input:focus-visible + .difficulty-option__label {
  outline: 2px solid var(--bp-yellow-soft);
  outline-offset: 2px;
}

.difficulty-option:hover .difficulty-option__label {
  border-color: rgba(240, 210, 74, 0.25);
  color: rgba(255, 255, 255, 0.78);
}

.difficulty-option input:checked + .difficulty-option__label {
  color: var(--bp-yellow);
  border-color: rgba(240, 210, 74, 0.45);
  background: rgba(240, 210, 74, 0.1);
  box-shadow: 0 0 16px rgba(240, 210, 74, 0.12);
}

.landing-overlay__track {
  color: var(--bp-yellow);
  font-weight: 700;
}

.landing-overlay__start {
  min-width: 8rem;
  padding: 0.55rem 1.35rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  border: none;
}

.btn.btn--primary.landing-overlay__start:hover,
.btn.btn--primary.landing-overlay__start:focus-visible,
.btn.btn--primary.landing-overlay__start:active {
  border: none;
}

/* --- End of run (Stop or song finished) --- */
.end-overlay {
  position: fixed;
  inset: 0;
  z-index: 47;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(4, 12, 28, 0.32);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  cursor: pointer;
}

.end-overlay[hidden] {
  display: none !important;
}

.end-overlay__card {
  width: 100%;
  max-width: 420px;
  padding: 1.75rem 1.5rem 1.6rem;
  border-radius: 22px;
  border: 1px solid rgba(240, 210, 74, 0.08);
  background: rgba(8, 22, 52, 0.29);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.18),
    0 0 28px rgba(240, 210, 74, 0.03), inset 0 1px 0 rgba(255, 255, 255, 0.03);
  text-align: center;
  cursor: auto;
}

.end-overlay__title {
  margin: 0 0 1rem;
  font-size: clamp(1.45rem, 4.5vw, 1.85rem);
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--bp-text);
  text-shadow: 0 0 24px rgba(240, 210, 74, 0.2);
}

.end-overlay__celebration {
  margin: 0 0 1rem;
  padding: 0 0.15rem;
}

.end-overlay__celebration[hidden] {
  display: none !important;
}

.end-overlay__celebration-lead {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--bp-text);
}

.end-overlay__score {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--bp-muted);
}

.end-overlay__score-value {
  color: var(--bp-yellow);
  font-weight: 700;
}

.end-overlay__actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  align-items: stretch;
}

.end-overlay__action {
  width: 100%;
}

a.end-overlay__link {
  display: block;
  box-sizing: border-box;
  text-align: center;
  text-decoration: none;
}

.end-overlay__story {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.end-overlay__story-label {
  margin: 0 0 0.55rem;
  font-size: 1rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.72);
  text-align: center;
  line-height: 1.45;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}

.end-overlay__embed-wrap {
  position: relative;
  width: 100%;
  max-width: 240px;
  margin: 0 auto 0.45rem;
  aspect-ratio: 9 / 16;
  max-height: min(38vh, 320px);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(240, 210, 74, 0.12);
  background: #000;
}

.end-overlay__iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* --- Start count-in (3–2–1; overlay off for blank beat; play) --- */
.countdown-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  pointer-events: none;
  background: rgba(5, 14, 32, 0.3);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.countdown-overlay__instruction {
  margin: 0;
  padding: 0 1.25rem;
  max-width: 22rem;
  text-align: center;
  font-size: clamp(0.8rem, 2.6vw, 0.95rem);
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
  color: rgba(230, 236, 255, 0.92);
  text-shadow: 0 1px 10px rgba(4, 12, 28, 0.95),
    0 0 24px rgba(240, 210, 74, 0.12);
}

.countdown-overlay[hidden] {
  display: none !important;
}

.countdown-display {
  font-size: clamp(3.5rem, 16vw, 6.5rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: rgba(255, 252, 230, 0.98);
  text-shadow: 0 0 36px rgba(240, 210, 74, 0.85),
    0 0 72px rgba(100, 180, 255, 0.35),
    0 0 2px rgba(255, 255, 255, 0.4);
  line-height: 1;
}

.countdown-display.countdown-display--go {
  font-size: clamp(2.2rem, 10vw, 4rem);
  letter-spacing: 0.05em;
  font-variant-numeric: normal;
}

@keyframes countdownDigitIn {
  from {
    transform: scale(0.65);
    opacity: 0.35;
    filter: blur(4px);
  }
  to {
    transform: scale(1);
    opacity: 1;
    filter: blur(0);
  }
}

.countdown-display.countdown-display--tick {
  animation: countdownDigitIn 0.32s cubic-bezier(0.34, 1.2, 0.64, 1) forwards;
}

@keyframes countdownGoOut {
  from {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
  }
  to {
    opacity: 0;
    transform: scale(0.92);
    filter: blur(4px);
  }
}

/* Name must match animationend `animationName` check in script.js */
.countdown-display.countdown-display--go-out {
  animation: countdownGoOut 0.32s ease-in forwards;
}

/* --- 6. Hit feedback copy --- */
.feedback {
  position: fixed;
  left: 50%;
  bottom: min(30%, 200px);
  transform: translateX(-50%) translateY(0);
  z-index: 20;
  margin: 0;
  font-size: 1.15rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.94);
  text-shadow: 0 0 18px rgba(240, 210, 74, 0.25);
  pointer-events: none;
  opacity: 0;
}

.feedback.feedback--perfect,
.feedback.feedback--good {
  color: rgba(255, 250, 220, 0.98);
  text-shadow: 0 0 20px rgba(240, 210, 74, 0.45);
}

.feedback.feedback--miss {
  color: rgba(200, 210, 230, 0.75);
  text-shadow: none;
}

@keyframes feedbackFloatFade {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
  }
  12% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(-28px);
  }
}

.feedback.feedback--show {
  animation: feedbackFloatFade 1.05s ease-out forwards;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  .atmospheric-bg::before {
    filter: brightness(0.62);
    transform: none;
  }

  .symbol-rain-canvas {
    opacity: 0.42;
    filter: none;
  }
}
