:root {
  --milk: #FFF7F4;
  --pink-100: #FFE6EC;
  --pink-200: #FFCCD8;
  --pink-300: #FF9FB6;
  --strawberry: #E0466C;
  --berry-ink: #5C2433;
  --leaf: #5FAE7E;
  --cream: #FFF0D6;
  --butter: #FFC95C;
  --white: #FFFFFF;
  --flip: 900ms;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; background: var(--milk); color: var(--berry-ink); font: 400 16px/1.6 "Nunito", sans-serif; }
button { font: inherit; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--butter); outline-offset: 3px; }
[tabindex="-1"]:focus { outline: none; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
svg { display: block; max-width: 100%; }
p, h1, h2 { margin: 0; }
h1, h2 { font-family: "Bagel Fat One", cursive; font-weight: 400; line-height: 1.12; }
h2 { font-size: 28px; text-wrap: balance; }
.handwriting { font-family: "Caveat", cursive; font-weight: 600; line-height: 1.2; }
.svg-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.doodle { stroke: var(--berry-ink); stroke-width: 3px; stroke-linecap: round; stroke-linejoin: round; }
svg path, svg ellipse, svg rect { vector-effect: non-scaling-stroke; }
.bow-fill { fill: var(--pink-200); }

/* ---------- Book ---------- */
.stage { position: relative; height: 100%; height: 100dvh; display: flex; flex-direction: column; align-items: center; }
.book { position: relative; flex: 1; width: 100%; perspective: 2200px; cursor: pointer; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
.page { position: absolute; inset: 0; background: var(--white); overflow: hidden; transform-origin: left center; backface-visibility: hidden; -webkit-backface-visibility: hidden; transition: transform var(--flip) cubic-bezier(.6, .05, .3, 1), visibility 0s 0s; }
.page::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: var(--berry-ink); opacity: 0; pointer-events: none; transition: opacity var(--flip) ease-in; }
.page.is-turned { transform: rotateY(-180deg); visibility: hidden; transition: transform var(--flip) cubic-bezier(.6, .05, .3, 1), visibility 0s var(--flip); }
.page.is-turned::after { opacity: .22; }
.page-cover { background: var(--pink-100); }
.page-inner { position: relative; height: 100%; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; align-items: center; text-align: center; padding: max(40px, calc(env(safe-area-inset-top) + 28px)) 20px max(28px, env(safe-area-inset-bottom)); }
.page-inner > :first-child { margin-top: auto; }
.page-inner > :last-child { margin-bottom: auto; }

.progress { position: absolute; z-index: 30; top: max(12px, env(safe-area-inset-top)); left: 16px; right: 16px; display: flex; gap: 4px; pointer-events: none; }
.progress span { flex: 1; height: 4px; border-radius: 999px; background: var(--pink-200); transition: background .3s ease; }
.progress span.is-done { background: var(--strawberry); }
.progress.on-dark span { background: var(--berry-ink); outline: 1px solid var(--pink-300); outline-offset: -1px; opacity: .6; }
.progress.on-dark span.is-done { background: var(--pink-300); opacity: 1; }
.tap-hint { margin-top: 24px; font-size: 22px; animation: nudge 2.4s ease-in-out infinite; }
.tap-hint span { display: inline-block; }

/* ---------- Shared ---------- */
.chapter, .eyebrow { font-size: 14px; font-weight: 800; }
.chapter { display: block; margin-bottom: 8px; }
.page-lede { margin-top: 8px; font-size: 16px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; max-width: 100%; padding: 12px 24px; border: 3px solid var(--berry-ink); border-radius: 999px; background: var(--strawberry); color: var(--white); box-shadow: 0 6px 0 var(--pink-200); font-size: 18px; font-weight: 800; line-height: 1.25; cursor: pointer; transition: transform .18s ease, box-shadow .18s ease; }
.button:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 var(--pink-200); }
.button:disabled { opacity: .5; }
.button-secondary { color: var(--berry-ink); background: var(--white); }
.button-doodle { width: 24px; height: 24px; flex: 0 0 24px; fill: var(--butter); stroke: currentColor; }
.card { background: var(--white); border: 3px solid var(--berry-ink); border-radius: 24px; box-shadow: 0 6px 0 var(--pink-200); }

/* ---------- Cover ---------- */
.page-cover .page-inner { isolation: isolate; }
.cover-art { position: absolute; inset: 0; z-index: -1; pointer-events: none; }
.floating { position: absolute; animation: float 5s ease-in-out infinite; }
.heart-one { width: 36px; right: 8%; top: 9%; fill: var(--pink-300); rotate: 14deg; }
.heart-two { width: 28px; left: 8%; bottom: 22%; fill: var(--white); rotate: -18deg; animation-delay: -1s; }
.heart-three { width: 24px; right: 14%; bottom: 8%; fill: var(--strawberry); rotate: 10deg; animation-delay: -2.5s; animation-duration: 6s; }
.sparkle-one { width: 28px; left: 9%; top: 14%; fill: var(--butter); animation-delay: -3s; }
.sparkle-two { width: 24px; right: 6%; top: 60%; fill: var(--butter); animation-duration: 6s; }
.cover-bow { width: 96px; margin-top: auto; margin-bottom: 16px; rotate: -6deg; }
.eyebrow { margin-bottom: 16px; }
h1 { color: var(--strawberry); font-size: clamp(48px, 14vw, 88px); letter-spacing: -.03em; }
.hero-note { margin: 16px auto 24px; max-width: 240px; font-size: 28px; rotate: -3deg; }
.date-line { font-weight: 800; font-size: 16px; }
.birthday-clock { font-size: 14px; min-height: 24px; margin: 4px 0 8px; font-variant-numeric: tabular-nums; }

/* ---------- Cake ---------- */
.page-cake h2 { font-size: 28px; }
.cake-scene { width: min(100%, 480px, calc((100dvh - 420px) * 1.43)); min-width: 220px; margin: 12px auto 4px; }
.cake-illustration { width: 100%; height: auto; overflow: visible; }
.candle { cursor: pointer; outline: none; -webkit-tap-highlight-color: transparent; }
.candle .hit { fill: transparent; stroke: none; }
.candle-body { fill: var(--white); }
.candle:nth-child(even) .candle-body { fill: var(--pink-300); }
.candle-stripe { fill: none; stroke: var(--strawberry); }
.candle:nth-child(even) .candle-stripe { stroke: var(--white); }
.flame { fill: var(--butter); transform-box: fill-box; transform-origin: 50% 100%; animation: flicker 1.4s ease-in-out infinite alternate; animation-delay: var(--flicker-delay); }
.candle.is-out .flame { opacity: 0; transform: scale(.2); transition: opacity .2s, transform .2s; animation: none; }
.candle.is-out { cursor: default; }
.candle:focus-visible .candle-body { stroke: var(--butter); stroke-width: 5px; }
.smoke { fill: none; stroke: var(--berry-ink); opacity: 0; }
.candle.just-out .smoke { animation: smoke .8s ease-out both; }
.candle-count { font-size: 14px; font-weight: 800; min-height: 24px; margin-bottom: 12px; }
.cake-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.page-cake .button { font-size: 16px; padding: 10px 14px; }
.page-cake .page-inner { padding-inline: 12px; }
.page-cake .cake-controls { gap: 8px; }
.mic-status { max-width: 360px; margin-top: 12px; min-height: 24px; font-size: 14px; }
.wish-heading { font-size: 28px; }
.wish-made { font-weight: 800; font-size: 18px; min-height: 28px; margin: 0 0 12px; }
.noscript-note { max-width: 360px; margin-top: 16px; }

/* ---------- Letter ---------- */
.page-letter .page-inner { text-align: left; align-items: stretch; padding: 24px; }
.page-letter .chapter, .page-letter h2 { text-align: left; }
.letter-bow { position: absolute; width: 80px; top: max(32px, calc(env(safe-area-inset-top) + 20px)); right: 16px; rotate: 12deg; }
.page-letter h2 { margin-top: auto; margin-bottom: 16px; }
.page-letter .signature-row { margin-bottom: auto; }
.letter-body { font-size: 15px; line-height: 1.55; }
.letter-body p + p { margin-top: 10px; }
.signature-row { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.signature { font-size: 28px; }
.letter-heart { width: 36px; fill: var(--pink-200); rotate: -12deg; }

/* ---------- Sky ---------- */
.page-sky { background: var(--berry-ink); color: var(--pink-100); }
.page-sky h2 { color: var(--white); font-size: 26px; }
.page-sky .chapter { color: var(--pink-200); }
.sky-wrap { width: min(100%, 480px, calc(100dvh - 320px)); min-width: 260px; margin: 12px auto 8px; }
.sky-chart { width: 100%; height: auto; overflow: visible; }
.sky-horizon { fill: var(--berry-ink); stroke: var(--pink-300); stroke-width: 2px; }
.sky-ring { fill: none; stroke: var(--pink-300); stroke-width: 1px; stroke-dasharray: 2 8; opacity: .45; }
.sky-lines line { stroke: var(--pink-300); stroke-width: 2px; stroke-linecap: round; opacity: .75; stroke-dasharray: 1; stroke-dashoffset: 0; }
.sky-stars circle { fill: var(--white); animation: twinkle 3.2s ease-in-out infinite; animation-delay: var(--d); }
.sky-labels text, .sky-names text, .sky-you text, .sky-compass text { font-family: "Caveat", cursive; font-weight: 600; }
.sky-labels text { font-size: 32px; fill: var(--pink-200); }
.sky-names text { font-size: 28px; fill: var(--cream); }
.sky-compass text { font-size: 32px; fill: var(--pink-300); dominant-baseline: middle; }
.sky-you circle { fill: none; stroke: var(--butter); stroke-width: 2px; stroke-dasharray: 4 6; }
.sky-you text { font-size: 32px; fill: var(--butter); }
.sky-caption { max-width: 380px; font-size: 15px; line-height: 1.5; }
.sign-off { margin-top: 12px; font-size: 22px; color: var(--pink-200); }
.page-sky.is-active .sky-lines line { animation: draw 2.4s .5s ease-out both; }
.page-sky.is-active .sky-you { animation: fade-in 1s 2.2s ease-out both; }

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

@keyframes nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(6px); } }
@keyframes twinkle { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-8px) rotate(3deg); } }
@keyframes flicker { 0%, 100% { transform: scale(.92, 1.05) rotate(-4deg); } 40% { transform: scale(1.08, .92) rotate(4deg); } 70% { transform: scale(.98, 1.06); } }
@keyframes smoke { 0% { opacity: .8; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-24px); } }
@keyframes note-pop { 0% { transform: translateY(12px) rotate(-3deg) scale(.96); } 65% { transform: translateY(-4px) rotate(1deg); } 100% { transform: none; } }

@media (min-height: 760px) {
  .cake-scene { margin-block: 24px 12px; }
}
@media (min-width: 700px) {
  .stage { padding: 24px; }
  .book { max-width: 560px; }
  .page { border: 3px solid var(--berry-ink); border-radius: 24px; box-shadow: 0 6px 0 var(--pink-200); }
  .progress { position: static; width: 100%; max-width: 560px; margin-bottom: 16px; }
  .progress.on-dark span { background: var(--pink-200); outline: none; opacity: 1; }
  .progress.on-dark span.is-done { background: var(--strawberry); }
  .page-inner { padding: 40px; }
  .page-letter .page-inner { padding: 40px 48px; }
  .letter-bow { width: 104px; right: 24px; top: 16px; }
  .letter-body { font-size: 17px; line-height: 1.7; }
  .letter-body p + p { margin-top: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
  .page, .page.is-turned { transform: none; transition: opacity .2s ease, visibility 0s .2s; }
  .page { opacity: 1; transition: opacity .2s ease, visibility 0s 0s; }
  .page.is-turned { opacity: 0; }
  .page.is-turned::after { opacity: 0; }
  #confetti { display: none !important; }
}
