:root {
  --ink: #1a1033;
  --cream: #fff6e5;
  --pink: #ff7eb6;
  --sun: #ffd23f;
  --red: #ff5a4f;
  --mint: #7be0c3;
  --grape: #6c3fc5;

  --sky-a: #150d3b;
  --sky-b: #3a1c71;
  --stars: 1;

  --display: 'Bagel Fat One', 'Arial Rounded MT Bold', system-ui, sans-serif;
  --body: 'Nunito', system-ui, sans-serif;
  --hand: 'Caveat', 'Bradley Hand', cursive;

  --top-h: 72px;
  --next-h: 104px;
  --lift: 0 6px 0 var(--ink);
}

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

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

body {
  background: var(--ink);
  color: var(--cream);
  font: 600 1.05rem/1.55 var(--body);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

@layer base {
  button:not(:disabled),
  [role='button']:not([aria-disabled='true']),
  [role='tab']:not([aria-disabled='true']),
  a[href],
  summary,
  label[for] { cursor: pointer; }
}

button { font: inherit; color: inherit; }
:focus-visible { outline: 4px solid var(--sun); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }

/* ---------- Stage, sky, iris wipe ---------- */
.stage { position: fixed; inset: 0; overflow: hidden; }
.stage.is-wiping { clip-path: circle(var(--iris, 200vmax) at var(--ix, 50%) var(--iy, 50%)); }

.sky {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, var(--sky-a), var(--sky-b));
}
.stars { position: absolute; inset: -20px; opacity: var(--stars); }
.star {
  position: absolute; width: 4px; height: 4px; border-radius: 50%;
  background: var(--cream);
  animation: twinkle 3s ease-in-out infinite;
}
.star.big { width: 7px; height: 7px; }
@keyframes twinkle { 50% { opacity: .15; transform: scale(.6); } }

.shoot {
  position: absolute; left: 0; top: 0; width: 110px; height: 3px; border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--cream));
  opacity: 0;
}

.horizon {
  position: absolute; left: -10%; right: -10%; bottom: -34vmin; height: 60vmin;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 246, 229, .35), transparent);
}

/* ---------- Scenes ---------- */
.scene {
  position: absolute; inset: var(--top-h) 0 var(--next-h) 0;
  display: none;
  flex-direction: column; align-items: center; gap: 16px;
  padding: 10px 20px 14px;
  overflow-y: auto; overflow-x: hidden;
  text-align: center;
}
.scene.is-active { display: flex; }
.scene > * { flex-shrink: 0; max-width: 640px; }
.scene::before, .scene::after { content: ''; margin: auto; } /* centre vertically, still scrolls */

.sticker-text {
  font: 400 clamp(1.75rem, 7vw, 3.2rem)/1.1 var(--display);
  color: var(--cream);
  -webkit-text-stroke: 9px var(--ink);
  paint-order: stroke fill;
  stroke-linejoin: round;
  text-shadow: 0 5px 0 var(--ink);
  letter-spacing: .01em;
  text-wrap: balance;
}
h2.sticker-text { font-size: clamp(1.6rem, 6.2vw, 2.6rem); }
.word { display: inline-block; white-space: pre; }

.lede {
  max-width: 34ch;
  text-shadow: 0 2px 0 rgba(26, 16, 51, .55);
  text-wrap: balance;
}

.card {
  background: var(--cream); color: var(--ink);
  border: 3px solid var(--ink); border-radius: 22px;
  box-shadow: var(--lift);
}

/* hover/press use `translate` so they never fight GSAP's `transform` */
.btn {
  background: var(--sun); color: var(--ink);
  border: 3px solid var(--ink); border-radius: 999px;
  padding: 12px 24px;
  font: 400 1.1rem/1.1 var(--display);
  box-shadow: var(--lift);
  transition: translate .12s, box-shadow .12s;
}
.btn:hover { translate: 0 -2px; box-shadow: 0 8px 0 var(--ink); }
.btn:active { translate: 0 5px; box-shadow: 0 1px 0 var(--ink); }
.btn-round { width: 46px; height: 46px; padding: 0; font-size: 1.6rem; line-height: 1; }
.btn-quiet { background: var(--cream); }
.btn:disabled { visibility: hidden; }

/* ---------- Top flow ---------- */
.steps {
  position: absolute; z-index: 3;
  top: max(12px, env(safe-area-inset-top)); left: 0; right: 0; margin: auto;
  width: min(520px, calc(100% - 20px));
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.steps-track {
  position: absolute; left: 10%; right: 10%; top: 9px; height: 8px;
  background: var(--cream); border-radius: 9px;
  box-shadow: 0 0 0 3px var(--ink);
  overflow: hidden;
}
.steps-fill { position: absolute; inset: 0; background: var(--pink); transform-origin: left center; transform: scaleX(0); }
.steps button {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 0 0 4px; border: 0; background: none;
  font: 400 .8rem/1 var(--display);
  color: var(--cream);
  -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill;
}
.steps b {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--cream); border: 3px solid var(--ink);
  transition: background-color .3s, scale .3s;
}
.steps button.done b { background: var(--pink); }
.steps button[aria-selected='true'] b { background: var(--sun); scale: 1.25; }

/* ---------- Bottom "tap to continue" ---------- */
.next {
  position: absolute; z-index: 3;
  left: 0; right: 0; bottom: max(20px, env(safe-area-inset-bottom)); margin: auto;
  width: fit-content; max-width: calc(100% - 32px);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 30px 13px;
  font-size: 1.2rem;
}
.next small { font: 800 .76rem/1 var(--body); opacity: .7; }
.next span::after { content: ' ›'; }

/* ---------- 1. Midnight ---------- */
.midnight-art { display: flex; align-items: flex-end; justify-content: center; }
.clock { width: clamp(120px, 34vw, 180px); overflow: visible; }
.me { width: clamp(80px, 22vw, 116px); margin-left: -14px; overflow: visible; }
.ring-lines { opacity: 0; }
.typed { min-height: 6.4em; max-width: 30ch; font-weight: 800; text-shadow: 0 2px 0 rgba(26, 16, 51, .55); }
.typed p + p { margin-top: 2px; }

/* ---------- 2. Story ---------- */
.book { width: min(100%, 440px); perspective: 1200px; }
.page { display: none; padding: 16px 18px 22px; transform-origin: left center; }
.page.is-open { display: block; }
.page svg { display: block; width: 100%; border-radius: 14px; background: #e9defc; border: 3px solid var(--ink); overflow: hidden; }
.page .when { margin-top: 12px; font-weight: 800; color: var(--grape); }
.page h3 { font: 400 1.6rem/1.15 var(--display); margin: 2px 0 8px; }
.page p { text-wrap: pretty; }
.book-nav { display: flex; align-items: center; justify-content: center; gap: 14px; min-height: 52px; }
.dots { display: flex; gap: 7px; }
.dots i { width: 11px; height: 11px; border-radius: 50%; border: 3px solid var(--ink); background: var(--cream); transition: background-color .2s, scale .2s; }
.dots i.on { background: var(--sun); scale: 1.35; }

/* ---------- 3. Reasons ---------- */
.balloons { position: relative; width: min(100%, 560px); height: clamp(240px, 40vh, 380px); }
.balloon {
  position: absolute; width: clamp(54px, 15vw, 84px);
  padding: 0; border: 0; background: none;
  transform: translate(-50%, -50%);
}
.balloon svg { display: block; width: 100%; overflow: visible; }
.balloon.popped { pointer-events: none; }
.spark { position: absolute; width: 12px; height: 12px; border-radius: 4px; border: 2px solid var(--ink); pointer-events: none; }
.reason { width: min(100%, 440px); padding: 14px 20px; min-height: 96px; display: flex; flex-direction: column; justify-content: center; }
.reason p { font: 400 1.2rem/1.25 var(--display); text-wrap: balance; }
.count { font-size: .9rem; font-weight: 800; color: var(--grape); margin-top: 4px; }

/* ---------- 4. Letter ---------- */
.paper {
  width: min(calc(100% - 14px), 520px); padding: 24px 24px 20px;
  background: #fffdf6; color: var(--ink);
  border: 3px solid var(--ink); border-radius: 10px;
  box-shadow: 8px 8px 0 var(--ink);
  transform: rotate(-1deg);
  text-align: left;
  font: 500 1.45rem/1.35 var(--hand);
  background-image: repeating-linear-gradient(transparent 0 calc(1.35em - 2px), rgba(108, 63, 197, .16) calc(1.35em - 2px) 1.35em);
  background-position: 0 22px;
}
.paper p + p { margin-top: 1.35em; }
.paper .sign { text-align: right; font-weight: 700; }

/* ---------- 5. Mood ---------- */
#scene-mood { bottom: 0; gap: 13px; padding-bottom: max(22px, env(safe-area-inset-bottom)); }
.mood-art { width: min(78vw, 300px); max-height: 27vh; overflow: visible; }
.bubble { position: relative; padding: 9px 18px; font: 400 1.05rem/1.2 var(--display); min-width: 220px; }
.bubble::before {
  content: ''; position: absolute; left: 38%; top: -11px; width: 18px; height: 18px;
  background: var(--cream); border: solid var(--ink); border-width: 3px 0 0 3px;
  transform: rotate(45deg);
}
.meter-wrap { width: min(100%, 440px); }
.meter {
  --m: 0;
  position: relative; height: 36px;
  background: var(--ink); border: 3px solid var(--ink); border-radius: 999px;
  box-shadow: var(--lift);
}
.meter-fill {
  position: absolute; inset: 0; border-radius: 999px;
  background:
    repeating-linear-gradient(115deg, rgba(255, 255, 255, .28) 0 12px, transparent 12px 26px),
    linear-gradient(90deg, var(--red), #ff9f43 45%, var(--sun) 75%, var(--mint));
  background-size: 52px 100%, 100% 100%;
  clip-path: inset(0 calc(100% - var(--m) * 100%) 0 0 round 999px);
  animation: stripes 1.2s linear infinite;
}
@keyframes stripes { to { background-position: 52px 0, 0 0; } }
.meter-knob {
  position: absolute; top: 50%; left: calc(23px + var(--m) * (100% - 46px));
  width: 46px; height: 46px; margin: -23px 0 0 -23px;
  display: grid; place-items: center;
  background: var(--cream); color: var(--red);
  border: 3px solid var(--ink); border-radius: 50%;
  font-size: 1.3rem; line-height: 1;
}
.meter-ends { display: flex; justify-content: space-between; align-items: baseline; margin-top: 12px; font-weight: 800; text-shadow: 0 2px 0 rgba(26, 16, 51, .55); }
.meter-ends strong { font: 400 1.6rem/1 var(--display); -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; }
#moodHint { font-size: .95rem; line-height: 1.35; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 12px; width: min(100%, 440px); margin-top: 6px; }
.act {
  position: relative;
  display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 8px;
  padding: 10px 10px; text-align: left;
  background: var(--cream); color: var(--ink);
  border: 3px solid var(--ink); border-radius: 18px;
  box-shadow: var(--lift);
  transition: translate .12s, box-shadow .12s;
}
.act:active { translate: 0 5px; box-shadow: 0 1px 0 var(--ink); }
.act-emoji { font-size: 1.7rem; line-height: 1; }
.act b { display: block; font: 400 1rem/1.1 var(--display); }
.act small { display: block; font-size: .78rem; font-weight: 800; line-height: 1.25; color: var(--grape); }
.act-plus {
  position: absolute; top: -13px; right: -5px;
  padding: 2px 9px;
  background: var(--mint); border: 3px solid var(--ink); border-radius: 999px;
  font: 400 .85rem/1.25 var(--display);
}

.fly { position: fixed; z-index: 5; pointer-events: none; font: 400 1.5rem/1 var(--display); color: var(--cream); -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill; }
.finale { width: min(100%, 440px); padding: 12px 20px 22px; }
.finale svg { width: 100%; max-height: 118px; overflow: visible; }
.finale h3 { font: 400 clamp(1.7rem, 7vw, 2.4rem)/1.1 var(--display); color: var(--grape); }
.finale p { margin: 6px auto 14px; max-width: 30ch; text-wrap: balance; }
.finale-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px 10px; }
.finale-buttons .btn { font-size: .92rem; padding: 10px 14px; }
.scene.is-done h2 { display: none; }
.scene.is-done .mood-art { max-height: 19vh; }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 10; }

@media (min-width: 720px) {
  .scene { gap: 20px; }
  .paper { font-size: 1.7rem; padding: 34px 40px 28px; }
}

@media (prefers-reduced-motion: reduce) {
  .star, .meter-fill { animation: none; }
}
