:root {
  --night: #05030a;
  --ink: #fff4ea;
  --muted: rgba(255, 236, 224, 0.72);
  --faint: rgba(255, 236, 224, 0.48);
  --gold: #f6c56f;
  --gold-hi: #ffe6a8;
  --rose: #ff8fb4;
  --coral: #ff7a52;
  --cocoa: #7a4428;
  --paper: #fbf5ec;
  --paper-ink: #3a2a2c;
  --line: rgba(255, 226, 196, 0.22);
  --f-display: "Fraunces", Georgia, serif;
  --f-hand: "Caveat", "Segoe Print", cursive;
  --f-ui: "Manrope", system-ui, -apple-system, sans-serif;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
  background: var(--night);
  scrollbar-width: none;
  scroll-snap-type: y proximity;
}
html::-webkit-scrollbar { display: none; }

body {
  background: var(--night);
  color: var(--ink);
  font-family: var(--f-ui);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* the 3D layer sits behind everything and never takes touches, so scrolling stays native */
#gl {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100lvh;
  display: block;
  z-index: 0;
  pointer-events: none;
}
#track { position: relative; z-index: 1; display: block; }
#track .snap { position: absolute; left: 0; width: 1px; height: 1px; scroll-snap-align: start; }

/* fixed overlays on top of the 3D; only their buttons take touches */
.ui { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
.ui button { pointer-events: auto; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.kicker, .ch-kicker {
  font: 700 11px/1.2 var(--f-ui);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--gold);
}

/* ---------- loader ---------- */
.loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: var(--night);
  transition: opacity 0.9s var(--ease-out), visibility 0s linear 0.9s;
}
.loader i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 24px 6px rgba(246, 197, 111, 0.45);
  animation: beat 1.1s ease-in-out infinite;
}
.loader.done { opacity: 0; visibility: hidden; }
@keyframes beat { 50% { transform: scale(1.6); opacity: 0.6; } }

/* ---------- sound ---------- */
.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: rgba(30, 16, 14, 0.55);
  border: 1px solid var(--line);
  transition: transform 0.14s var(--ease-out), opacity 0.6s var(--ease-out);
}
.icon-btn:active { transform: scale(0.92); }
#soundBtn {
  position: fixed;
  z-index: 20;
  top: calc(var(--sat) + 12px);
  right: 12px;
  opacity: 0;
  pointer-events: none;
}
#soundBtn.is-on { opacity: 1; pointer-events: auto; }
#soundBtn .slash { display: none; }
#soundBtn.muted .slash { display: inline; }
#soundBtn.muted .wave { display: none; }

/* ---------- buttons ---------- */
.row { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14.5px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  transition: transform 0.14s var(--ease-out), background 0.25s;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  color: #2b1408;
  background: linear-gradient(135deg, var(--gold-hi), var(--gold) 55%, #f0976a);
  border-color: transparent;
  box-shadow: 0 10px 30px -12px rgba(246, 197, 111, 0.7);
}
@media (hover: hover) and (pointer: fine) {
  .btn:hover { background: rgba(255, 255, 255, 0.14); }
  .btn-primary:hover { background: linear-gradient(135deg, #fff0c8, var(--gold) 55%, #f0976a); }
}


/* ======================================================= hero (the cake) */
.hero-ui {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: calc(var(--sat) + 46px) 16px 0;
  user-select: none;
  -webkit-user-select: none;
  text-shadow: 0 2px 24px rgba(5, 3, 10, 0.6);
}
.hero-text { width: 100%; max-width: 640px; }
.hb { margin-top: 14px; font-weight: 400; }
#hbText {
  display: block;
  font: 600 clamp(40px, 12.4vw, 92px)/0.98 var(--f-display);
  letter-spacing: -0.02em;
  white-space: nowrap;
}
#hbText .ch {
  display: inline-block;
  opacity: 0;
  transform: translateY(0.4em) scale(0.6) rotate(-8deg);
}
.ready #hbText .ch { animation: pop 0.9s var(--ease-out) forwards; animation-delay: calc(0.25s + var(--i) * 45ms); }
.party #hbText .ch { animation: pop 0.9s var(--ease-out) forwards, hop 0.7s var(--ease-out) calc(var(--i) * 40ms) 1 both; opacity: 1; transform: none; }
@keyframes pop {
  60% { opacity: 1; transform: translateY(-0.08em) scale(1.08) rotate(2deg); }
  to { opacity: 1; transform: none; }
}
@keyframes hop {
  0% { transform: none; }
  40% { transform: translateY(-0.22em) rotate(-4deg); }
  100% { transform: none; }
}
.hb-name {
  display: block;
  margin-top: 2px;
  font: italic 500 clamp(64px, 23vw, 168px)/0.95 var(--f-display);
  letter-spacing: -0.02em;
  background: linear-gradient(100deg, #ffe6a8 0%, #f6c56f 28%, #ff9ab8 50%, #f6c56f 72%, #ffe6a8 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 1.2s var(--ease-out) 0.9s, transform 1.4s var(--ease-out) 0.9s;
  animation: shimmer 7s linear infinite;
  padding: 0 0.08em;
}
.ready .hb-name { opacity: 1; transform: none; }
@keyframes shimmer { to { background-position: -220% 0; } }
.hero-sub {
  margin-top: 6px;
  font: 600 25px/1.1 var(--f-hand);
  color: var(--muted);
  opacity: 0;
  transition: opacity 1s var(--ease-out) 1.5s;
}
.ready .hero-sub { opacity: 1; }
#heroKicker { opacity: 0; transition: opacity 1s var(--ease-out) 0.1s; }
.ready #heroKicker { opacity: 1; }

.hero-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--sab) + 20px);
  display: grid;
  justify-items: center;
  pointer-events: none;
}
.hero-hint .pill { grid-area: 1 / 1; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 11px 18px;
  border-radius: 999px;
  font: 700 13.5px/1 var(--f-ui);
  color: var(--ink);
  background: rgba(30, 14, 10, 0.62);
  border: 1px solid var(--line);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.6s var(--ease-out), transform 0.7s var(--ease-out);
}
.pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 0 rgba(246, 197, 111, 0.6);
  animation: ping 1.6s ease-out infinite;
}
@keyframes ping { 70% { box-shadow: 0 0 0 10px rgba(246, 197, 111, 0); } 100% { box-shadow: 0 0 0 0 rgba(246, 197, 111, 0); } }
.pill-scroll svg { color: var(--gold); animation: nudge 1.4s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateX(3px); } }
.hint-tap #hintTap, .hint-scroll #hintScroll { opacity: 1; transform: none; transition-delay: 0.2s; }
.hero-hint .pill-scroll { pointer-events: none; }
.hint-scroll .hero-hint .pill-scroll { pointer-events: auto; }
.pill-scroll { background: rgba(246, 197, 111, 0.16); border-color: rgba(246, 197, 111, 0.45); }
.hint-scroll .pill-scroll:active { transform: scale(0.96); }


/* ======================================================= HUD while flying */
.hud { opacity: 0; transition: opacity 0.5s var(--ease-out); }
.hud.on { opacity: 1; }
.hud:not(.on) button { pointer-events: none; }
.hud-top {
  position: absolute;
  top: calc(var(--sat) + 16px);
  left: 64px;
  right: 64px;
  text-align: center;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.45s var(--ease-out), transform 0.5s var(--ease-out);
  text-shadow: 0 2px 18px rgba(5, 3, 10, 0.8);
}
.hud.show-date .hud-top { opacity: 1; transform: none; }
.hud-top .kicker { font-size: 10px; }
.hud-date { margin-top: 4px; font: italic 500 22px/1.1 var(--f-display); color: var(--ink); }
.hud-bot {
  position: absolute;
  left: 14px;
  right: 18px;
  bottom: calc(var(--sab) + 34px);
  display: flex;
  align-items: center;
  gap: 14px;
}
.play-btn { flex: none; width: 46px; height: 46px; background: rgba(246, 197, 111, 0.16); border-color: rgba(246, 197, 111, 0.45); }
.play-btn .i-pause, .play-btn.on .i-play { display: none; }
.play-btn.on .i-pause { display: block; }
.play-btn .i-play { margin-left: 2px; }
.hud-bar { flex: 1; height: 2px; border-radius: 2px; background: rgba(255, 236, 224, 0.16); overflow: hidden; }
.hud-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--rose), var(--gold)); transform-origin: 0 50%; transform: scaleX(0); }
.hud-count { flex: none; min-width: 52px; text-align: right; font: 700 12px/1 var(--f-ui); letter-spacing: 0.12em; color: var(--muted); font-variant-numeric: tabular-nums; }
.hud-tip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--sab) + 12px);
  text-align: center;
  font: 600 11px/1 var(--f-ui);
  letter-spacing: 0.06em;
  color: var(--faint);
}

/* ======================================================= finale overlay */
.fin-ui {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  text-align: center;
  padding: calc(var(--sat) + 54px) 20px calc(var(--sab) + 22px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.9s var(--ease-out), visibility 0s linear 0.9s;
  text-shadow: 0 2px 24px rgba(5, 3, 10, 0.75);
}
.fin-ui.on { opacity: 1; visibility: visible; transition: opacity 1.2s var(--ease-out) 0.2s, visibility 0s; }
.fin-ui:not(.on) button { pointer-events: none; }
.fin-head { max-width: 520px; transform: translateY(14px); transition: transform 1.4s var(--ease-out) 0.2s; }
.fin-ui.on .fin-head { transform: none; }
.fin-title {
  font: 400 clamp(38px, 11vw, 72px)/1 var(--f-display);
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.fin-title em {
  font-style: italic;
  font-size: 1.32em;
  font-weight: 500;
  background: linear-gradient(100deg, #ffe6a8 0%, #f6c56f 28%, #ff9ab8 50%, #f6c56f 72%, #ffe6a8 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 7s linear infinite;
  padding: 0 0.08em;
}
.fin-note { margin: 14px auto 0; max-width: 28ch; font: 600 24px/1.22 var(--f-hand); color: var(--muted); }
.fin-sign { margin-top: 6px; font: 700 28px/1 var(--f-hand); color: var(--gold-hi); }
.fin-foot { width: 100%; max-width: 520px; }
.fin-tip { margin-bottom: 14px; font: 600 12px/1.4 var(--f-ui); letter-spacing: 0.04em; color: var(--faint); }

/* ======================================================= plain album (only if there's no WebGL) */
.album { display: none; padding-bottom: 80px; }


.chapter { position: relative; padding: 96px 0 8px; }
.chapter::before {
  content: "";
  position: absolute;
  top: 18px;
  left: 50%;
  width: 1px;
  height: 62px;
  background: linear-gradient(rgba(246, 197, 111, 0), rgba(246, 197, 111, 0.55));
}
.ch-head {
  position: relative;
  text-align: center;
  padding: 0 22px 34px;
  isolation: isolate;
}
.ch-day {
  position: absolute;
  z-index: -1;
  left: 50%;
  top: -34px;
  transform: translateX(-50%);
  font: italic 300 150px/1 var(--f-display);
  color: transparent;
  -webkit-text-stroke: 1px rgba(246, 197, 111, 0.2);
  pointer-events: none;
  user-select: none;
}
.ch-dot {
  display: block;
  width: 7px;
  height: 7px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 14px 3px rgba(246, 197, 111, 0.5);
}
.ch-title {
  margin-top: 10px;
  font: italic 400 clamp(31px, 9vw, 48px)/1.04 var(--f-display);
  letter-spacing: -0.015em;
  text-wrap: balance;
}
.ch-sub {
  margin-top: 8px;
  font: 600 22px/1.15 var(--f-hand);
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px 16px;
  max-width: 600px;
  margin: 0 auto;
  padding: 0 18px;
}
.pol { position: relative; min-width: 0; }
.pol.wide { grid-column: 1 / -1; }
.pol.feature { grid-column: 1 / -1; width: 76%; justify-self: center; }
.pol.low { margin-top: 26px; }
.pol-btn {
  position: relative;
  display: block;
  width: 100%;
  padding: 7px 7px 0;
  text-align: center;
  background: var(--paper);
  border-radius: 3px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 14px 30px -10px rgba(0, 0, 0, 0.65), 0 2px 6px rgba(0, 0, 0, 0.3);
  transform: rotate(var(--r));
  transition: transform 0.16s var(--ease-out);
}
.pol.wide .pol-btn { padding: 9px 9px 0; }
.pol.tape .pol-btn::before {
  content: "";
  position: absolute;
  z-index: 2;
  top: -10px;
  left: 50%;
  width: 76px;
  height: 22px;
  transform: translateX(-50%) rotate(-4deg);
  background: rgba(255, 238, 205, 0.62);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}
.ph {
  display: block;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #3a2218, #24130e);
}
.ph img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.6s var(--ease-out), transform 0.5s var(--ease-out);
}
.ph img.ok { opacity: 1; }
.pol figcaption {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 7px 4px 9px;
  font: 600 19px/1.02 var(--f-hand);
  color: var(--paper-ink);
  text-wrap: balance;
}
.pol.wide figcaption, .pol.feature figcaption { font-size: 22px; min-height: 50px; }
.pol.broken { display: none; }


.nogl-msg { position: fixed; inset: 0; display: grid; place-items: center; padding: 30px; text-align: center; }
.nogl #gl, .nogl #track, .nogl #hud, .nogl #finUI { display: none; }
html:has(.nogl) { scroll-snap-type: none; }
.nogl .hero-ui { position: relative; min-height: 70svh; }
.nogl .hero-hint { display: none; }
.nogl .album { display: block; }

/* ---------- small phones ---------- */
@media (max-width: 360px) {
  .grid { gap: 24px 12px; padding: 0 14px; }
  .pol figcaption { font-size: 17px; }
  .btn { padding: 0 16px; font-size: 13.5px; }
  .fin-note { font-size: 21px; }
}
@media (min-width: 760px) {
  .grid { max-width: 900px; grid-template-columns: repeat(3, 1fr); gap: 40px 26px; }
  .pol.wide { grid-column: span 2; }
}

@media (prefers-reduced-motion: reduce) {
  #hbText .ch { animation: none !important; opacity: 1 !important; transform: none !important; }
  .hb-name, .fin-title em { animation: none; }
}

/* ---------- star-portrait intro ---------- */
html.intro { overflow: hidden; }
.intro-skip {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--sab) + 22px);
  z-index: 6;
  text-align: center;
  font: 600 11px/1 var(--f-ui);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--faint);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s var(--ease-out);
}
html.intro .intro-skip { opacity: 0; }
