/* ---------- Fonts (self-hosted, see assets/fonts/README.md) ---------- */
@font-face { font-family: "Pixelify Sans"; src: url("../assets/fonts/pixelify-sans-400.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Pixelify Sans"; src: url("../assets/fonts/pixelify-sans-700.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Instrument Serif"; src: url("../assets/fonts/instrument-serif-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Shrikhand"; src: url("../assets/fonts/shrikhand.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "DM Serif Display"; src: url("../assets/fonts/dm-serif-display.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }

/* the current level's colours (set from js), animated when the level changes */
@property --lvl-glow { syntax: "<color>"; inherits: true; initial-value: #6f86b8; }
@property --lvl-accent { syntax: "<color>"; inherits: true; initial-value: #8fa6d6; }
@property --lvl-deep { syntax: "<color>"; inherits: true; initial-value: #0f1a2e; }

:root {
  --font-pixel: "Pixelify Sans", "Courier New", monospace;      /* title, HUD, small labels */
  --font-tagline: "Instrument Serif", Georgia, serif;           /* elegant italic */
  --font-groovy: "Shrikhand", "Trebuchet MS", sans-serif;       /* how-to-play lines */
  --font-song: "DM Serif Display", Georgia, serif;              /* song titles */
  --bg: #f3f2ee; --text: #1c1c1a; --text-secondary: #6b6a64;
  --card-bg: #ffffff; --border: #dedbd2; --accent: #d4537e;      /* pink accent */
  --pink: #ff5d8f; --pink-soft: #ff9ec0;
  --glass: rgba(14, 11, 22, 0.55); --glass-line: rgba(255, 255, 255, 0.14);
  --ease-pop: cubic-bezier(0.2, 0.9, 0.3, 1.35); --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --heart: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 8' shape-rendering='crispEdges'%3E%3Cpath d='M1 0h2v1h1v1h1V1h1V0h2v1h1v3H8v1H7v1H6v1H5v1H4V7H3V6H2V5H1V4H0V1h1z'/%3E%3C/svg%3E");
  --lock: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 8' shape-rendering='crispEdges'%3E%3Cpath d='M2 0h3v1h1v2h1v5H0V3h1V1h1zm0 1v2h3V1zM3 5v2h1V5z'/%3E%3C/svg%3E");
  transition: --lvl-glow 1.2s ease, --lvl-accent 1.2s ease, --lvl-deep 1.2s ease;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121317; --text: #eceae4; --text-secondary: #9a988f; --card-bg: #1c1d22; --border: #2e3036; --accent: #ed93b1; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; color: var(--text); font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(900px 520px at 50% -140px, color-mix(in srgb, var(--lvl-glow) 38%, transparent), transparent 70%),
    var(--bg);
  touch-action: manipulation; overscroll-behavior-y: none; -webkit-touch-callout: none;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { max-width: 720px; margin: 0 auto; padding: 1.5rem 1rem 2rem; }
button { font: inherit; }

/* ---------- Stage ---------- */
.stage {
  position: relative; width: min(100%, calc((100vh - 24px) * 1.6)); width: min(100%, calc((100dvh - 24px) * 1.6));
  margin-inline: auto; border-radius: 18px; overflow: hidden; background: #07060b; user-select: none; -webkit-user-select: none;
  box-shadow: 0 30px 70px -28px color-mix(in srgb, var(--lvl-glow) 75%, transparent), 0 18px 40px -24px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0, 0, 0, 0.08);
}
canvas#game { display: block; width: 100%; height: auto; touch-action: none; image-rendering: pixelated; image-rendering: crisp-edges; }

/* ---------- HUD ---------- */
.hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 12px 26px; font-family: var(--font-pixel); font-weight: 700; color: #fff;
  background: linear-gradient(rgba(6, 4, 12, 0.5), rgba(6, 4, 12, 0)); pointer-events: none;
  transition: opacity 0.3s ease, transform 0.4s var(--ease-out);
}
.stage:not([data-state="playing"]):not([data-state="dying"]):not([data-state="clearing"]) .hud { opacity: 0; transform: translateY(-8px); }
.hud-level, .hud-count {
  padding: 5px 10px; border-radius: 999px; background: var(--glass); border: 1px solid var(--glass-line);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); font-size: 14px; letter-spacing: 0.03em; line-height: 1; white-space: nowrap;
}
.hud-count { min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.hud-count.pop { animation: count-pop 0.35s var(--ease-pop); }
@keyframes count-pop { 0% { transform: scale(1); } 40% { transform: scale(1.22); color: var(--pink-soft); } 100% { transform: scale(1); } }
.hud-right { display: flex; align-items: center; gap: 6px; }
.hud-hearts { display: flex; gap: 5px; padding: 5px 9px; border-radius: 999px; background: var(--glass); border: 1px solid var(--glass-line); }
.hud-hearts i, .reveal-hearts i, .track-hearts i, .finale-hearts i {
  display: block; width: 14px; height: 13px; background: rgba(255, 255, 255, 0.28);
  -webkit-mask: var(--heart) center / contain no-repeat; mask: var(--heart) center / contain no-repeat;
}
.hud-hearts i.on { background: var(--pink); filter: drop-shadow(0 0 4px var(--pink)); }
.hud-hearts i.pop { animation: heart-pop 0.5s var(--ease-pop); }
@keyframes heart-pop { 0% { transform: scale(0.4); } 50% { transform: scale(1.6); } 100% { transform: scale(1); } }
.hud-pause {
  pointer-events: auto; width: 30px; height: 30px; display: grid; grid-auto-flow: column; place-content: center; gap: 4px; cursor: pointer;
  border-radius: 50%; background: var(--glass); border: 1px solid var(--glass-line); padding: 0;
}
.hud-pause span { display: block; width: 3px; height: 11px; border-radius: 1px; background: #fff; }
.hud-bar { position: absolute; left: 0; right: 0; top: 0; height: 3px; background: rgba(255, 255, 255, 0.08); }
.hud-bar-fill {
  height: 100%; transform-origin: left; transform: scaleX(0); transition: transform 0.35s var(--ease-out);
  background: linear-gradient(90deg, var(--lvl-accent), var(--pink)); box-shadow: 0 0 10px var(--pink);
}

.countdown {
  position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; pointer-events: none;
  font-family: var(--font-pixel); font-weight: 700; font-size: 88px; color: #fff; text-shadow: 4px 4px 0 var(--accent), 0 0 30px var(--pink);
}
.countdown.tick { animation: count-tick 0.5s var(--ease-out); }
@keyframes count-tick { 0% { transform: scale(1.8); opacity: 0; } 30% { opacity: 1; } 100% { transform: scale(1); opacity: 1; } }

/* ---------- Loader ---------- */
.loader {
  position: absolute; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: #07060b; transition: opacity 0.5s ease;
}
.loader.done { opacity: 0; pointer-events: none; }
.loader-heart { width: 40px; color: var(--pink); filter: drop-shadow(0 0 12px var(--pink)); animation: beat 0.9s ease-in-out infinite; }
.loader-heart svg { display: block; width: 100%; }
.loader-bar { width: 120px; height: 4px; border-radius: 2px; overflow: hidden; background: rgba(255, 255, 255, 0.12); }
.loader-bar i { display: block; height: 100%; background: var(--pink); transform-origin: left; transform: scaleX(0); transition: transform 0.2s ease; }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.18); } 30% { transform: scale(1); } 45% { transform: scale(1.1); } }

/* ---------- Overlay: start / card / pause / finale ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 1.25rem; color: #fff; text-align: center;
  background: radial-gradient(ellipse 75% 70% at 50% 46%, rgba(8, 6, 14, 0.28), rgba(8, 6, 14, 0.8));
}
.overlay.hide { display: none; }
.overlay .ov { display: none; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.overlay[data-mode="start"] .ov-start, .overlay[data-mode="card"] .ov-card, .overlay[data-mode="pause"] .ov-pause, .overlay[data-mode="finale"] .ov-finale { display: flex; }
.overlay[data-mode="pause"] { background: rgba(8, 6, 14, 0.62); -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px); }
.overlay p, .overlay h2 { margin: 0; }
.overlay.enter .ov > * { animation: rise 0.6s var(--ease-out) both; }
.overlay.enter .ov > *:nth-child(2) { animation-delay: 0.06s; }
.overlay.enter .ov > *:nth-child(3) { animation-delay: 0.12s; }
.overlay.enter .ov > *:nth-child(4) { animation-delay: 0.18s; }
.overlay.enter .ov > *:nth-child(5) { animation-delay: 0.24s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* start */
.brand-heart { width: 34px; color: var(--pink); filter: drop-shadow(0 0 14px var(--pink)); }
.brand-heart svg { display: block; width: 100%; animation: beat 1.3s ease-in-out infinite; }
.brand {
  font-family: var(--font-pixel); font-size: clamp(30px, 7.4vw, 48px); font-weight: 400; letter-spacing: 0.03em; line-height: 1.05; color: #fff;
  text-shadow: 0 1px 0 #ffd1e3, 0 3px 0 var(--pink), 0 5px 0 #c43a6c, 0 7px 0 #7d1f45, 0 14px 26px rgba(0, 0, 0, 0.55);
}
.brand span { display: inline-block; animation: letter-in 0.7s var(--ease-pop) both, wave 3.2s ease-in-out infinite; animation-delay: calc(var(--i) * 45ms), calc(0.8s + var(--i) * 90ms); }
@keyframes letter-in { from { opacity: 0; transform: translateY(-26px) scale(0.6); } to { opacity: 1; transform: none; } }
@keyframes wave { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.tagline { font-family: var(--font-tagline); font-style: italic; font-size: 22px; line-height: 1.25; color: #f5efe6; max-width: 320px; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6); }
.howto { display: flex; flex-direction: column; align-items: center; font-family: var(--font-groovy); font-size: 17px; line-height: 1.35; letter-spacing: 0.02em; margin-top: 4px !important; }
.howto span { background: linear-gradient(90deg, #ff8fb1, #ffc857); -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent; filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.5)); }
.howto span:nth-child(2) { transform: rotate(-1.5deg); }
.begin {
  position: relative; margin-top: 10px !important; padding: 8px 18px; border-radius: 999px; font-family: var(--font-pixel); font-size: 15px; font-weight: 400;
  letter-spacing: 0.08em; color: #fff; background: rgba(255, 93, 143, 0.18); border: 1px solid rgba(255, 158, 192, 0.55);
  box-shadow: 0 0 22px rgba(255, 93, 143, 0.35);
}
.overlay.enter .begin { animation: rise 0.6s var(--ease-out) 0.3s both, blink 1.4s steps(2, jump-none) 1s infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* level intro and fail cards */
.card-tile { width: 64px; height: 64px; image-rendering: pixelated; filter: drop-shadow(0 0 14px var(--lvl-glow)) drop-shadow(0 6px 10px rgba(0, 0, 0, 0.5)); }
.overlay.enter .card-tile { animation: tile-in 0.8s var(--ease-pop) both; }
@keyframes tile-in { from { opacity: 0; transform: scale(0.3) rotate(-10deg); } to { opacity: 1; transform: none; } }
.card-title { display: flex; flex-direction: column; align-items: center; gap: 4px; font-family: var(--font-song); font-size: 32px; font-weight: 400; line-height: 1.08; text-shadow: 0 2px 14px rgba(0, 0, 0, 0.6); }
.card-kicker { font-family: var(--font-pixel); font-size: 13px; font-weight: 400; letter-spacing: 0.2em; text-transform: uppercase; color: var(--lvl-accent); text-shadow: 0 0 12px color-mix(in srgb, var(--lvl-glow) 60%, transparent); }
.overlay[data-card="fail"] .card-name { font-family: var(--font-pixel); font-weight: 700; font-size: 30px; letter-spacing: 0.04em; color: #fff; text-shadow: 3px 3px 0 #b3264f, 0 0 24px rgba(255, 60, 110, 0.5); }
.overlay.enter[data-card="fail"] .card-title { animation: glitch 0.5s steps(6) both; }
@keyframes glitch { 0% { transform: translate(-6px, 0); opacity: 0; } 20% { transform: translate(5px, -1px); opacity: 1; } 40% { transform: translate(-3px, 1px); } 60% { transform: translate(2px, 0); } 100% { transform: none; } }
.card-meter { width: 180px; height: 6px; border-radius: 3px; overflow: hidden; background: rgba(255, 255, 255, 0.15); }
.card-meter i { display: block; height: 100%; transform-origin: left; transform: scaleX(0); transition: transform 0.7s var(--ease-out) 0.15s; background: linear-gradient(90deg, #ff3d6e, var(--pink-soft)); box-shadow: 0 0 10px #ff3d6e; }
.card-pips { display: flex; gap: 6px; }
.card-pips i { width: 8px; height: 8px; border-radius: 2px; background: rgba(255, 255, 255, 0.2); }
.card-pips i.done { background: var(--pink); box-shadow: 0 0 6px var(--pink); }
.card-pips i.now { background: transparent; outline: 2px solid #fff; outline-offset: -1px; animation: blink 1s steps(2, jump-none) infinite; }
.card-text { font-size: 13px; color: #e2dfd8; max-width: 320px; letter-spacing: 0.01em; }
.overlay[data-card="intro"] .card-text, .overlay[data-card="fail"] .card-text { font-family: var(--font-tagline); font-style: italic; font-size: 18px; color: #f1ece4; }

/* buttons */
.btn { height: 44px; width: 100%; padding: 0 18px; font-family: -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px; font-weight: 650; letter-spacing: 0.01em; border-radius: 12px; cursor: pointer; transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.2s ease; }
.btn:active { transform: scale(0.97); }
.btn-primary { color: #2c0d18; background: linear-gradient(180deg, #ff9ec0, var(--pink)); border: 1px solid rgba(255, 255, 255, 0.55); box-shadow: 0 8px 22px -8px var(--pink), inset 0 1px 0 rgba(255, 255, 255, 0.6); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }
.btn-ghost { color: #fff; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.35); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }

/* pause */
.ov-pause { max-width: 260px; gap: 14px !important; }
.pause-title { font-family: var(--font-pixel); font-size: 30px; font-weight: 700; letter-spacing: 0.06em; text-shadow: 3px 3px 0 var(--accent); }
.pause-row { display: flex; gap: 8px; width: 100%; }
.chip { flex: 1; height: 38px; border-radius: 10px; font-family: -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; font-weight: 600; color: #fff; cursor: pointer; background: rgba(255, 93, 143, 0.22); border: 1px solid rgba(255, 158, 192, 0.6); }
.chip.off { background: rgba(255, 255, 255, 0.05); border-color: rgba(255, 255, 255, 0.2); color: rgba(255, 255, 255, 0.5); text-decoration: line-through; }
.link { background: none; border: 0; color: rgba(255, 255, 255, 0.7); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* ---------- Finale ---------- */
.fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.ov-finale { max-width: 320px; position: relative; }
.finale-col { position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.heart-badge {
  position: relative; width: 78px; height: 78px; border-radius: 50%; color: #fff; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #ff9ec0, var(--pink) 55%, #c43a6c); box-shadow: 0 10px 30px -6px rgba(255, 93, 143, 0.7), inset 0 2px 0 rgba(255, 255, 255, 0.4);
}
.heart-badge svg { animation: beat 1.2s ease-in-out infinite; }
.heart-badge::before, .heart-badge::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid rgba(255, 158, 192, 0.7); animation: ring 2.4s ease-out infinite; }
.heart-badge::after { animation-delay: 1.2s; }
@keyframes ring { from { transform: scale(0.9); opacity: 0.9; } to { transform: scale(1.7); opacity: 0; } }
.finale-heading { font-family: var(--font-song); font-size: 28px; font-weight: 400; line-height: 1.1; text-shadow: 0 2px 14px rgba(0, 0, 0, 0.5); }
.finale-body { font-size: 13px; color: #e2dfd8; line-height: 1.5; max-width: 280px; }
.finale-tape { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; }
.finale-tape img { width: 30px; height: 30px; image-rendering: pixelated; padding: 3px; border-radius: 7px; background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.14); animation: tile-in 0.6s var(--ease-pop) both; animation-delay: calc(0.3s + var(--i) * 90ms); }
.finale-hearts { display: flex; align-items: center; gap: 6px; font-family: var(--font-pixel); font-size: 15px; font-weight: 400; color: var(--pink-soft); }
.finale-hearts i { background: var(--pink); }
.finale-divider { width: 40px; height: 1px; background: rgba(255, 255, 255, 0.25); margin: 4px 0; }
.finale-cta { font-family: var(--font-song); font-size: 21px; font-weight: 400; letter-spacing: 0.01em; }
.finale-sub { font-size: 12px; color: rgba(255, 255, 255, 0.7); line-height: 1.5; max-width: 280px; margin-top: -4px !important; }
#emailForm { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.ov-finale input[type="email"] {
  height: 44px; width: 100%; padding: 0 14px; font-size: 16px; color: #fff; background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 12px; outline: none; transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.ov-finale input[type="email"]:focus { border-color: var(--pink-soft); box-shadow: 0 0 0 3px rgba(255, 93, 143, 0.3); }
.ov-finale input[type="email"]::placeholder { color: rgba(255, 255, 255, 0.45); }
.finale-error { display: none; font-size: 12px; color: #ffb3b3; }
.finale-success { display: none; font-size: 13px; line-height: 1.45; color: #fff; background: rgba(255, 93, 143, 0.14); border: 1px solid rgba(255, 158, 192, 0.35); border-radius: 12px; padding: 10px 12px; }

/* ---------- The "Track unlocked" card ---------- */
.reveal {
  position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; overflow: hidden;
  background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--glow) 42%, #0a0710), #07060b 72%);
  opacity: 0; pointer-events: none; transition: opacity 0.35s ease; --glow: #8fa6d6; --accent: #8fa6d6;
}
.reveal.show { opacity: 1; pointer-events: auto; }
.reveal-rays {
  position: absolute; left: 50%; top: 38%; width: 180%; aspect-ratio: 1; translate: -50% -50%; opacity: 0.22;
  background: repeating-conic-gradient(from 0deg, color-mix(in srgb, var(--glow) 80%, white) 0deg 6deg, transparent 6deg 20deg);
  -webkit-mask: radial-gradient(circle, #000 0%, transparent 60%); mask: radial-gradient(circle, #000 0%, transparent 60%);
  animation: spin 40s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.reveal-card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 1.5rem; color: #fff; }
.reveal-art { position: relative; width: 132px; height: 132px; margin-bottom: 10px; }   /* room for the number badge that hangs below the tile */
.reveal-tile {
  position: relative; z-index: 2; display: block; width: 132px; height: 132px; padding: 10px; image-rendering: pixelated; border-radius: 14px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--glow) 55%, #1a1224), #120d1a);
  border: 1px solid rgba(255, 255, 255, 0.22); box-shadow: 0 0 34px color-mix(in srgb, var(--glow) 70%, transparent), 0 16px 30px -10px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.vinyl {
  position: absolute; z-index: 1; top: 6px; left: 6px; width: 120px; height: 120px; border-radius: 50%;
  background:
    radial-gradient(circle, #07060b 0 3%, var(--accent) 3.5% 21%, #111 22% 24%, transparent 25%),
    repeating-radial-gradient(circle, #1b1b1f 0 1.5px, #0c0c0f 1.5px 3px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
}
.vinyl::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(from 20deg, transparent 0 10%, rgba(255, 255, 255, 0.16) 14%, transparent 22% 60%, rgba(255, 255, 255, 0.1) 64%, transparent 72%); }
.vinyl-label { position: absolute; inset: 40%; border-radius: 50%; background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.5), transparent 60%); }
.reveal.play .vinyl { animation: vinyl-out 0.9s var(--ease-out) 0.45s both, spin 1.8s linear 1.2s infinite; }
@keyframes vinyl-out { from { transform: translateX(0); } to { transform: translateX(46px); } }
@keyframes pop { 0% { transform: scale(0.4) rotate(-8deg); opacity: 0; } 60% { transform: scale(1.1) rotate(3deg); opacity: 1; } 100% { transform: none; opacity: 1; } }
.reveal.play .reveal-tile { animation: pop 0.7s var(--ease-pop) both, slide-left 0.9s var(--ease-out) 0.45s both; }
@keyframes slide-left { from { translate: 0 0; } to { translate: -22px 0; } }
.reveal-num {
  position: absolute; z-index: 3; right: -34px; bottom: -8px; min-width: 32px; padding: 4px 8px; border-radius: 999px; background: rgba(8, 8, 10, 0.9);
  border: 1px solid var(--glow); box-shadow: 0 0 12px color-mix(in srgb, var(--glow) 60%, transparent); font-family: var(--font-pixel); font-size: 13px; font-weight: 700; text-align: center;
}
.reveal.play .reveal-num { animation: tile-in 0.5s var(--ease-pop) 0.7s both; }
.reveal-label { margin: 0; font-family: var(--font-song); font-size: 13px; font-weight: 400; letter-spacing: 0.24em; text-transform: uppercase; color: color-mix(in srgb, var(--glow) 50%, white); }
.reveal.play .reveal-label { animation: track-in 0.8s var(--ease-out) 0.3s both; }
@keyframes track-in { from { opacity: 0; letter-spacing: 0.6em; } to { opacity: 1; letter-spacing: 0.24em; } }
.reveal-title { margin: 0; max-width: 320px; font-family: var(--font-song); font-size: 34px; font-weight: 400; line-height: 1.08; text-align: center; text-shadow: 0 2px 16px rgba(0, 0, 0, 0.6); }
.reveal.play .reveal-title { animation: rise 0.7s var(--ease-out) 0.45s both; }
.reveal-hearts { display: flex; gap: 5px; margin: 0; }
.reveal-hearts i.on { background: var(--pink); filter: drop-shadow(0 0 5px var(--pink)); }
.reveal.play .reveal-hearts i { animation: heart-pop 0.5s var(--ease-pop) both; }
.reveal.play .reveal-hearts i:nth-child(1) { animation-delay: 0.8s; }
.reveal.play .reveal-hearts i:nth-child(2) { animation-delay: 0.92s; }
.reveal.play .reveal-hearts i:nth-child(3) { animation-delay: 1.04s; }
.reveal-hint { display: flex; align-items: center; gap: 8px; margin: 6px 0 0; font-size: 12px; color: rgba(255, 255, 255, 0.72); }
.reveal.play .reveal-hint, .reveal.play .reveal-progress { animation: rise 0.6s var(--ease-out) 0.6s both; }
.reveal-progress { width: 180px; height: 3px; margin-top: 10px; overflow: hidden; background: rgba(255, 255, 255, 0.2); border-radius: 2px; }
.reveal-progress-fill { width: 100%; height: 100%; transform-origin: left; transform: scaleX(0); background: linear-gradient(90deg, var(--glow), #fff); box-shadow: 0 0 8px var(--glow); }

/* equalizer bars (unlock card, the playing track) */
.eq { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.eq i { display: block; width: 3px; height: 100%; background: currentColor; transform-origin: bottom; animation: eq 0.9s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: -0.3s; }
.eq i:nth-child(3) { animation-delay: -0.6s; }
.eq i:nth-child(4) { animation-delay: -0.15s; }
.reveal-hint .eq { color: var(--glow); }
@keyframes eq { 0%, 100% { transform: scaleY(0.3); } 50% { transform: scaleY(1); } }

/* ---------- Tracklist card ---------- */
.panel {
  margin-top: 1.1rem; padding: 1rem 1.1rem; background: var(--card-bg); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: 0 18px 40px -30px rgba(0, 0, 0, 0.45);
}
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.panel h3 { margin: 0; font-family: var(--font-song); font-size: 19px; font-weight: 400; letter-spacing: 0.01em; }
.panel-count { font-family: var(--font-pixel); font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.panel-tools { margin-left: auto; display: flex; gap: 6px; }
.icon-btn { width: 32px; height: 32px; display: grid; place-items: center; padding: 0; cursor: pointer; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .off, .icon-btn.off .on { display: none; }
.icon-btn.off .off { display: inline; }
.icon-btn.off { color: var(--text-secondary); }
.tracks { display: flex; flex-direction: column; gap: 6px; }
.track-row {
  position: relative; display: grid; grid-template-columns: 24px 26px 1fr auto auto; align-items: center; gap: 10px; overflow: hidden;
  padding: 6px 10px; border-radius: 12px; background: var(--bg); border: 1px solid transparent; font-family: var(--font-song); font-size: 16px;
  transition: background 0.3s ease, border-color 0.3s ease;
}
.track-num { position: relative; display: grid; place-items: center; font-family: var(--font-pixel); font-size: 13px; font-weight: 400; color: var(--text-secondary); }
.track-num .eq { display: none; color: var(--accent); }
.track-row.playing .track-num b { display: none; }
.track-row.playing .track-num .eq { display: inline-flex; }
.track-tile { width: 26px; height: 26px; image-rendering: pixelated; }
.track-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-hearts { display: flex; gap: 2px; }
.track-hearts i { width: 10px; height: 9px; background: color-mix(in srgb, var(--text-secondary) 40%, transparent); }
.track-hearts i.on { background: var(--accent); }
.track-status { display: inline-flex; align-items: center; gap: 5px; font-family: var(--font-tagline); font-style: italic; font-size: 15px; font-weight: 400; padding: 3px 8px; border-radius: 999px; }
.track-row.locked { color: var(--text-secondary); }
.track-row.locked .track-tile { filter: grayscale(1) brightness(0.8); opacity: 0.35; }
.track-row.locked .track-status::before { content: ""; width: 9px; height: 10px; background: currentColor; -webkit-mask: var(--lock) center / contain no-repeat; mask: var(--lock) center / contain no-repeat; }
.track-row.unlocked { color: var(--text); border-color: color-mix(in srgb, var(--accent) 22%, transparent); }
.track-row.unlocked .track-status { color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, transparent); }
.track-row.playing { background: color-mix(in srgb, var(--accent) 9%, var(--bg)); }
.track-row.fresh { animation: row-glow 1.6s ease-out; }
.track-row.fresh::after {
  content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.7) 50%, transparent 70%);
  transform: translateX(-100%); animation: shine 1.2s ease-out 0.2s;
}
@keyframes shine { to { transform: translateX(100%); } }
@keyframes row-glow { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 70%, transparent); } 100% { box-shadow: 0 0 0 10px transparent; } }

/* ---------- Phones ---------- */
@media (max-width: 640px), (max-height: 500px) {
  .wrap { padding: max(0.5rem, env(safe-area-inset-top)) 0 calc(1.5rem + env(safe-area-inset-bottom)); }
  .stage { border-radius: 0; box-shadow: 0 20px 40px -26px color-mix(in srgb, var(--lvl-glow) 80%, transparent); }
  .panel { margin: 0.75rem 0.75rem 0; padding: 0.9rem 1rem; }
  .hud { padding: 10px 10px 18px; }
  .hud-level, .hud-count { font-size: 13px; padding: 5px 9px; }
  .hud-hearts { padding: 5px 7px; gap: 4px; }
  .hud-hearts i { width: 12px; height: 11px; }

  /* the start screen and the fail/intro cards stay inside the game area, so keep them compact */
  .overlay { gap: 6px; padding: 0.75rem; }
  .overlay .ov { gap: 7px; }
  .brand { font-size: 28px; text-shadow: 0 1px 0 #ffd1e3, 0 2px 0 var(--pink), 0 3px 0 #c43a6c, 0 5px 0 #7d1f45, 0 10px 20px rgba(0, 0, 0, 0.55); }
  .brand-heart { width: 26px; }
  .tagline { font-size: 17px; }
  .howto { font-size: 13px; line-height: 1.3; }
  .begin { font-size: 13px; padding: 6px 14px; }
  .card-title { font-size: 25px; }
  .card-tile { width: 52px; height: 52px; }
  .countdown { font-size: 64px; }

  /* the end screen and the unlock card become full-screen layers so nothing gets clipped */
  .overlay.full, .reveal {
    position: fixed; inset: 0; z-index: 100; height: 100vh; height: 100dvh;
  }
  .overlay.full { background: radial-gradient(circle at 50% 20%, color-mix(in srgb, var(--lvl-glow) 30%, #0a0710), #07060b 75%); overflow-y: auto; -webkit-overflow-scrolling: touch; justify-content: flex-start; gap: 0; padding: calc(1.25rem + env(safe-area-inset-top)) 1.25rem calc(1.25rem + env(safe-area-inset-bottom)); }
  .overlay.full .ov-finale { margin-block: auto; max-width: 340px; gap: 12px; }
  .overlay.full .fx { position: fixed; }
  .overlay.full .heart-badge { width: 70px; height: 70px; }
  .overlay.full .finale-heading { font-size: 30px; line-height: 1.1; }
  .overlay.full .finale-body { font-size: 15px; max-width: 300px; }
  .overlay.full .finale-cta { font-size: 23px; }
  .overlay.full .finale-sub { font-size: 13px; max-width: 300px; }
  .overlay.full .ov-finale input[type="email"] { height: 48px; font-size: 16px; }   /* 16px stops iPhones zooming on focus */
  .overlay.full .btn { height: 48px; font-size: 17px; }
  .overlay.full .finale-error, .overlay.full .finale-success { font-size: 14px; }
  html:has(.overlay.full), html:has(.reveal.show) { overflow: hidden; }

  .reveal-card { gap: 10px; padding: calc(1.5rem + env(safe-area-inset-top)) 1.5rem calc(1.5rem + env(safe-area-inset-bottom)); }
  .reveal-art, .reveal-tile { width: 156px; height: 156px; }
  .vinyl { width: 144px; height: 144px; }
  .reveal-num { font-size: 15px; }
  .reveal-label { font-size: 13px; }
  .reveal-title { font-size: 36px; max-width: 320px; }
  .reveal-hint { font-size: 14px; }
  .reveal-hearts i { width: 18px; height: 16px; }
  .reveal-progress { width: min(240px, 70vw); height: 4px; }
}

/* landscape phones: compact unlock card, and a two-column end screen so it fits one screen */
@media (max-height: 500px) and (orientation: landscape) {
  .reveal-card { padding-block: 0.75rem; gap: 6px; }
  .reveal-art, .reveal-tile { width: 88px; height: 88px; }
  .reveal-tile { padding: 6px; }
  .vinyl { width: 80px; height: 80px; }
  .reveal-title { font-size: 26px; }
  .overlay.full .ov-finale { flex-direction: row; max-width: 640px; gap: 28px; align-items: center; }
  .overlay.full .finale-col { flex: 1 1 0; gap: 8px; }
  .overlay.full .finale-divider { width: 1px; height: 150px; margin: 0; }
  .overlay.full .finale-heading { font-size: 26px; }
  .overlay.full .heart-badge { width: 56px; height: 56px; }
  .overlay.full .ov-finale input[type="email"], .overlay.full .btn { height: 42px; }
}

/* portrait phones: the game takes roughly the top half, and the tracklist card fills the rest of the screen */
@media (max-width: 640px) and (orientation: portrait) {
  .wrap { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; padding-bottom: 0; }
  .stage { flex: 0 0 auto; width: 100%; height: clamp(80vw, calc(100vh - 318px), 88vw); height: clamp(80vw, calc(100svh - 318px), 88vw); }   /* svh: stays put when the browser bar hides */
  .stage canvas#game { height: 100%; }
  .panel { flex: 1 1 auto; display: flex; flex-direction: column; margin: 8px 0 0; border-radius: 20px 20px 0 0; border-bottom: 0; padding: 0.7rem 0.9rem calc(0.7rem + env(safe-area-inset-bottom)); }
  .panel-head { flex: none; margin-bottom: 6px; }
  .panel h3 { font-size: 18px; }
  .tracks { flex: 1 1 auto; gap: 5px; }
  .track-row { flex: 1 1 0; min-height: 30px; padding: 0 10px; font-size: 15px; gap: 8px; grid-template-columns: 20px 22px 1fr auto auto; }
  .track-tile { width: 22px; height: 22px; }
  .track-hearts i { width: 8px; height: 7px; }
}

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