:root {
  --ink: #120f2b;
  --paper: #fdfbf4;
  --lime: #c6f432;
  --pink: #ff4fa3;
  --violet: #6c3bff;
  --orange: #ff6b1a;
  --cyan: #3fe0d0;
  --yellow: #ffd23f;
  --red: #ff3b3b;
  --forest: #0e3b2e;
  --font: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--ink);
  color: var(--paper);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
[hidden] { display: none !important; }
button, input { font: inherit; }
a { color: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.screen { position: fixed; inset: 0; display: grid; place-items: center; }

/* ---------- Landing ---------- */
.landing { overflow: hidden; padding: 16px; }
.blob { position: absolute; border-radius: 50%; filter: blur(2px); animation: drift 18s ease-in-out infinite alternate; }
.blob-a { width: 60vmax; height: 60vmax; background: var(--violet); top: -25vmax; left: -20vmax; }
.blob-b { width: 45vmax; height: 45vmax; background: var(--pink); bottom: -20vmax; right: -15vmax; animation-delay: -6s; }
.blob-c { width: 22vmax; height: 22vmax; background: var(--lime); top: 55%; left: 8%; animation-delay: -12s; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(4vmax, -3vmax) scale(1.08); }
}

.landing-card {
  position: relative;
  width: min(440px, 100%);
  padding: 36px 28px 26px;
  border-radius: 28px;
  background: rgba(18, 15, 43, 0.82);
  backdrop-filter: blur(18px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
  text-align: center;
}
.eyebrow { margin: 0; font-weight: 800; letter-spacing: 0.24em; text-transform: uppercase; color: var(--lime); font-size: 0.85rem; }
.wordmark {
  margin: 4px 0 8px;
  font-size: clamp(3.4rem, 15vw, 5rem);
  font-weight: 900;
  letter-spacing: -0.05em;
  line-height: 0.95;
  background: linear-gradient(100deg, var(--pink), var(--orange) 45%, var(--yellow));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { margin: 0 0 24px; opacity: 0.85; line-height: 1.4; }

.form { display: grid; gap: 14px; }
.input {
  width: 100%;
  padding: 16px 20px;
  border-radius: 999px;
  border: 2px solid transparent;
  background: var(--paper);
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 700;
  outline: none;
  text-align: center;
}
.input:focus { border-color: var(--lime); box-shadow: 0 0 0 4px rgba(198, 244, 50, 0.3); }

.periods { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; border: 0; margin: 0; padding: 0; }
.periods label { cursor: pointer; }
.periods input { position: absolute; opacity: 0; pointer-events: none; }
.periods span {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 999px;
  border: 2px solid rgba(253, 251, 244, 0.25);
  font-weight: 700;
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.periods input:checked + span { background: var(--lime); color: var(--ink); border-color: var(--lime); }
.periods input:focus-visible + span { outline: 3px solid var(--pink); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 15px 26px;
  font-weight: 800; font-size: 1.05rem; cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn:hover { filter: brightness(1.06); }
.btn-primary { background: var(--lime); color: var(--ink); }
.btn-ghost { background: rgba(255, 255, 255, 0.16); color: inherit; }
.btn-dark { background: var(--ink); color: var(--paper); }
.btn:focus-visible { outline: 3px solid var(--pink); outline-offset: 3px; }

.error { margin: 0; color: #ffd0e4; background: rgba(255, 79, 163, 0.18); padding: 10px 14px; border-radius: 14px; font-weight: 600; }
.fine { margin: 22px 0 0; font-size: 0.78rem; opacity: 0.6; line-height: 1.5; }

/* ---------- Loading ---------- */
.loading { background: var(--ink); align-content: center; gap: 22px; text-align: center; padding: 16px; }
.loading p { margin: 0; font-weight: 700; font-size: 1.15rem; }
.eq { display: flex; gap: 8px; align-items: flex-end; height: 70px; justify-content: center; }
.eq i { width: 14px; border-radius: 7px; background: var(--lime); animation: eq 0.9s ease-in-out infinite alternate; }
.eq i:nth-child(2) { background: var(--pink); animation-delay: -0.3s; }
.eq i:nth-child(3) { background: var(--cyan); animation-delay: -0.6s; }
.eq i:nth-child(4) { background: var(--orange); animation-delay: -0.15s; }
.eq i:nth-child(5) { background: var(--yellow); animation-delay: -0.45s; }
@keyframes eq { from { height: 14px; } to { height: 70px; } }

/* ---------- Story shell ---------- */
.story-screen { background: #08061a; }
.story {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
@media (min-width: 600px) and (min-height: 600px) {
  .story {
    height: min(92vh, 900px);
    width: auto;
    aspect-ratio: 9 / 16;
    border-radius: 24px;
    box-shadow: 0 40px 120px rgba(0, 0, 0, 0.6);
  }
}
.progress {
  position: absolute; z-index: 20; top: 0; left: 0; right: 0;
  display: flex; gap: 4px; padding: max(12px, env(safe-area-inset-top)) 12px 0;
}
/* Segments are buttons (tap to jump) with a taller hit area than they look. */
.progress button { flex: 1; padding: 8px 0; margin: -8px 0; border: 0; background: none; cursor: pointer; }
.progress button div { height: 3px; border-radius: 2px; background: rgba(255, 255, 255, 0.35); overflow: hidden; }
.progress button span { display: block; height: 100%; width: 0; background: #fff; }
.progress button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.story-top {
  position: absolute; z-index: 20; top: calc(max(12px, env(safe-area-inset-top)) + 10px); right: 8px;
  display: flex; gap: 2px;
}
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; color: #fff;
  display: grid; place-items: center; cursor: pointer; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn:focus-visible { outline: 2px solid #fff; }
.speed-btn { width: auto; min-width: 40px; padding: 0 8px; border-radius: 999px; font-weight: 800; font-size: 0.9rem; }
.nav { position: absolute; z-index: 10; top: 0; bottom: 0; border: 0; background: transparent; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.nav:focus-visible { outline: none; }
.nav-prev { left: 0; width: 30%; }
.nav-next { right: 0; width: 70%; }
/* Slides are their own stacking contexts (container queries), so tap zones
   would sit over a slide's buttons. On interactive slides keep only a small
   "back" zone in the top corner. */
.story[data-interactive] .nav-next { display: none; }
.story[data-interactive] .nav-prev { bottom: auto; height: 22%; width: 25%; }

.slides { position: absolute; inset: 0; }
.slide {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: center;
  padding: 72px 28px 40px;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
  container-type: inline-size;
}
.slide.active { visibility: visible; opacity: 1; transition: opacity 0.35s ease; }
.slide > * { position: relative; z-index: 1; }

/* Entrance animations: each .rise child staggers in via --d. */
.rise { opacity: 0; transform: translateY(28px); }
.slide.active .rise { animation: rise 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; animation-delay: var(--d, 0s); }
@keyframes rise { to { opacity: 1; transform: none; } }
.pop { opacity: 0; transform: scale(0.6) rotate(-6deg); }
.slide.active .pop { animation: pop 0.8s cubic-bezier(0.2, 1.4, 0.4, 1) forwards; animation-delay: var(--d, 0s); }
@keyframes pop { to { opacity: 1; transform: none; } }

/* Decorative shapes */
.shape { position: absolute; z-index: 0; pointer-events: none; }
.shape.circle { border-radius: 50%; }
.slide.active .shape.spin { animation: spin 24s linear infinite; }
.slide.active .shape.float { animation: float 6s ease-in-out infinite alternate; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes float { to { transform: translateY(-24px) rotate(8deg); } }
.stripes {
  background: repeating-linear-gradient(-45deg, var(--c) 0 18px, transparent 18px 36px);
}

/* Typography */
.kicker { font-size: clamp(1.2rem, 6.5cqi, 1.8rem); font-weight: 800; line-height: 1.15; margin: 0 0 12px; letter-spacing: -0.01em; }
.mega { font-size: clamp(3rem, 24cqi, 7.5rem); font-weight: 900; line-height: 0.9; letter-spacing: -0.05em; margin: 0; }
.big { font-size: clamp(2.2rem, 13cqi, 4.2rem); font-weight: 900; line-height: 0.95; letter-spacing: -0.04em; margin: 0; overflow-wrap: anywhere; }
.sub { font-size: clamp(1rem, 5cqi, 1.3rem); font-weight: 600; line-height: 1.35; margin: 14px 0 0; opacity: 0.9; }
.tag {
  display: inline-block; align-self: flex-start; padding: 6px 14px; border-radius: 999px;
  background: var(--fg); color: var(--bg); font-weight: 800; font-size: 0.85rem;
  letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 18px;
}
.center { text-align: center; align-items: center; }
.center .tag { align-self: center; }

/* Artwork */
.art {
  display: block; width: min(68cqi, 300px); aspect-ratio: 1; object-fit: cover;
  background: rgba(0, 0, 0, 0.15); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  margin-bottom: 24px;
}
.art.round { border-radius: 50%; }
.art.square { border-radius: 6px; }
.art-fallback {
  display: grid; place-items: center; font-weight: 900; font-size: min(28cqi, 120px);
  color: var(--bg); background: var(--fg);
}

/* Ranked lists */
.rank { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 12px; }
.rank li { display: grid; grid-template-columns: 2.2ch 56px 1fr; align-items: center; gap: 12px; }
.rank .n { font-size: 1.6rem; font-weight: 900; }
.rank img, .rank .thumb {
  width: 56px; height: 56px; object-fit: cover; border-radius: 6px; background: rgba(0, 0, 0, 0.2);
  display: grid; place-items: center; font-weight: 900; font-size: 1.4rem;
}
.rank.round-thumbs img, .rank.round-thumbs .thumb { border-radius: 50%; }
.rank .t { min-width: 0; }
.rank .t b, .rank .t small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank .t b { font-size: 1.15rem; font-weight: 800; }
.rank .t small { font-size: 0.9rem; opacity: 0.75; font-weight: 600; margin-top: 2px; }

/* Genres */
.genres { display: grid; gap: 14px; margin-top: 10px; }
.genre b { display: flex; justify-content: space-between; gap: 12px; font-size: clamp(1.15rem, 6.5cqi, 1.6rem); font-weight: 900; margin-bottom: 6px; }
.genre b span { opacity: 0.6; font-size: 0.9rem; align-self: flex-end; }
.genre .bar { height: 14px; border-radius: 7px; background: rgba(0, 0, 0, 0.2); overflow: hidden; }
.genre .bar i { display: block; height: 100%; width: 0; background: var(--fg); border-radius: 7px; transition: width 1.1s cubic-bezier(0.2, 0.8, 0.2, 1); }

/* Albums */
.albums { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 10px; }
.albums figure { margin: 0; min-width: 0; }
.albums figure:first-child { grid-column: span 2; display: grid; grid-template-columns: 46% 1fr; gap: 14px; align-items: end; }
.albums img, .albums .thumb { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; background: rgba(0, 0, 0, 0.15); display: grid; place-items: center; font-weight: 900; font-size: 2rem; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); }
.albums figcaption { font-size: 0.85rem; font-weight: 700; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.albums figure:first-child figcaption { white-space: normal; font-size: 1.05rem; }
.albums figcaption small { display: block; font-weight: 600; opacity: 0.7; }

/* Clock */
.clock { width: min(78cqi, 320px); align-self: center; margin: 4px 0 18px; }
.clock .bar-h { transform-origin: 0 0; transform: scale(0); transition: transform 0.9s cubic-bezier(0.2, 0.8, 0.2, 1); }
.slide.active .clock .bar-h { transform: scale(1); }
.clock text { font: 800 11px var(--font); fill: currentColor; }

/* Personality */
.persona-badge {
  position: relative; isolation: isolate;
  width: min(56cqi, 230px); aspect-ratio: 1; border-radius: 50%; margin: 0 auto 26px;
  display: grid; place-items: center; font-size: min(26cqi, 110px);
  box-shadow: 0 0 0 10px rgba(255, 255, 255, 0.12), 0 30px 80px rgba(0, 0, 0, 0.4);
}
.persona-badge::before {
  content: ""; position: absolute; inset: 0; z-index: -1; border-radius: 50%;
  background: conic-gradient(from 0deg, var(--pink), var(--yellow), var(--lime), var(--cyan), var(--violet), var(--pink));
}
.slide.active .persona-badge::before { animation: spin 14s linear infinite; }

/* Summary */
.summary { padding: 64px 22px 22px; justify-content: flex-start; }
.summary-card { display: flex; flex-direction: column; gap: 16px; flex: 1; min-height: 0; }
.summary-hero { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.summary-hero img, .summary-hero .thumb { width: min(62cqi, 34vh); aspect-ratio: 1; object-fit: cover; border-radius: 6px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3); background: rgba(0, 0, 0, 0.2); display: grid; place-items: center; font-size: 3rem; font-weight: 900; }
.summary-hero h2 { margin: 0; font-size: clamp(1.3rem, 7cqi, 2rem); line-height: 1; font-weight: 900; letter-spacing: -0.03em; }
.summary-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.summary-cols h3, .summary-stats h3 { margin: 0 0 6px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.75; }
.summary-cols ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; counter-reset: r; }
.summary-cols li { font-weight: 800; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; counter-increment: r; }
.summary-cols li::before { content: counter(r) " "; opacity: 0.6; }
.summary-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.summary-stats p { margin: 0; font-size: clamp(1.4rem, 8cqi, 2rem); font-weight: 900; letter-spacing: -0.03em; line-height: 1; overflow-wrap: anywhere; }
.summary-actions { position: relative; z-index: 15; display: flex; flex-wrap: wrap; gap: 10px; margin-top: auto; padding-top: 12px; }
.summary-actions .btn { flex: 1 1 auto; padding: 13px 18px; font-size: 0.95rem; }
.toast { font-size: 0.85rem; font-weight: 700; text-align: center; margin: 4px 0 0; min-height: 1.2em; }

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

/* Top Artist Sprint */
.race { position: relative; height: 330px; margin-top: 6px; }
.race-row { position: absolute; left: 0; right: 0; top: 0; height: 58px; transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1); }
.race-row .name { display: flex; justify-content: space-between; gap: 10px; font-weight: 800; font-size: 1rem; margin-bottom: 4px; }
.race-row .name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.race-row .name span:last-child { font-variant-numeric: tabular-nums; opacity: 0.8; }
.race-bar { height: 26px; border-radius: 8px; background: var(--c); min-width: 6px; transition: width 0.2s linear; }
.race-tick { margin: 0; text-align: right; font-size: clamp(2.6rem, 17cqi, 4.6rem); font-weight: 900; letter-spacing: -0.04em; line-height: 1; opacity: 0.35; }

/* Top Song Quiz */
.quiz { display: grid; gap: 10px; margin-top: 18px; }
.quiz button {
  text-align: left; padding: 13px 18px; border-radius: 16px; border: 2px solid var(--fg);
  background: transparent; color: var(--fg); font-weight: 800; font-size: 1.05rem; cursor: pointer;
  transition: background 0.2s, color 0.2s, opacity 0.2s;
}
.quiz button small { display: block; font-weight: 600; opacity: 0.75; font-size: 0.85rem; }
.quiz button:hover:not(:disabled) { background: rgba(0, 0, 0, 0.12); }
.quiz button.correct { background: var(--fg); color: var(--bg); }
.quiz button.wrong { opacity: 0.4; text-decoration: line-through; }
.quiz button:disabled { cursor: default; }
.quiz-result { font-weight: 900; font-size: 1.3rem; min-height: 1.5em; margin: 14px 0 0; }

/* Bottom sheet (top 50 songs, compare with a friend) */
.sheet { position: absolute; inset: 0; z-index: 40; background: rgba(8, 6, 26, 0.6); display: flex; align-items: flex-end; }
.sheet-panel {
  width: 100%; max-height: 88%; display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink); border-radius: 24px 24px 0 0;
  animation: sheet-up 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes sheet-up { from { transform: translateY(100%); } }
.sheet header { display: flex; justify-content: space-between; align-items: center; padding: 16px 12px 6px 22px; }
.sheet h2 { margin: 0; font-size: 1.4rem; font-weight: 900; letter-spacing: -0.02em; }
.sheet .icon-btn { color: var(--ink); filter: none; }
.sheet .icon-btn:focus-visible { outline-color: var(--violet); }
.sheet-body { overflow: auto; padding: 4px 22px 26px; }
.top50 { list-style: none; margin: 0; padding: 0; }
.top50 li { display: grid; grid-template-columns: 2.6ch 1fr auto; gap: 10px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid rgba(18, 15, 43, 0.08); }
.top50 .n { font-weight: 900; opacity: 0.45; }
.top50 b { display: block; font-weight: 800; overflow-wrap: anywhere; }
.top50 small { opacity: 0.65; font-weight: 600; }
.top50 .p { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.compare-form { display: flex; gap: 8px; margin: 6px 0 14px; }
.compare-form .input { flex: 1; min-width: 0; padding: 12px 16px; font-size: 1rem; text-align: left; background: #fff; border: 2px solid rgba(18, 15, 43, 0.15); }
.compare-form .btn { padding: 12px 18px; font-size: 1rem; }
.sheet-note { margin: 0 0 8px; font-size: 0.9rem; opacity: 0.7; line-height: 1.4; }
.match { text-align: center; padding: 6px 0 4px; }
.match .score { font-size: 5rem; font-weight: 900; letter-spacing: -0.05em; line-height: 1; color: var(--violet); }
.match p { margin: 8px 0 0; font-weight: 600; line-height: 1.4; }
.match-vs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.match-vs div { background: rgba(18, 15, 43, 0.06); border-radius: 14px; padding: 12px; min-width: 0; }
.match-vs h3 { margin: 0 0 4px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.6; }
.match-vs b { display: block; font-weight: 900; overflow-wrap: anywhere; }
.sheet .error { color: #b0105a; background: rgba(255, 79, 163, 0.14); }

/* Playlist export */
.export-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 10px; }
.export-row .btn { padding: 10px 16px; font-size: 0.95rem; }
.btn-ghost-dark { background: rgba(18, 15, 43, 0.08); color: var(--ink); }
.open-in { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 3px; }
.open-in a { font-size: 0.78rem; font-weight: 700; color: var(--violet); text-decoration: none; }
.open-in a:hover { text-decoration: underline; }

/* On light slides, switch the progress bar and controls to ink. */
.story[data-light] .icon-btn { color: var(--ink); filter: none; }
.story[data-light] .progress button div { background: rgba(18, 15, 43, 0.22); }
.story[data-light] .progress button span { background: var(--ink); }
.story[data-light] .icon-btn:focus-visible { outline-color: var(--ink); }

.party-link { display: inline-block; margin-top: 18px; font-weight: 800; color: var(--lime); text-decoration: none; }
.party-link:hover { text-decoration: underline; }
