:root {
  --paper: #f7f0e4;
  --paper-deep: #e7d7c2;
  --ink: #3c2d25;
  --ink-soft: #776255;
  --gold: #a97742;
  --gold-light: #e8c88f;
  --brown: #5a3b27;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: #2d211b;
  color: var(--ink);
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  overflow-x: hidden;
}

button, audio { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.birthday-book {
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 8%, rgba(236, 201, 143, .26), transparent 24rem),
    linear-gradient(135deg, #4a3224 0%, #241915 100%);
}

.music-toggle {
  position: fixed;
  z-index: 30;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 999px;
  padding: 10px 14px;
  color: #fff7e8;
  background: rgba(42, 29, 23, .64);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
  cursor: pointer;
  font-family: system-ui, sans-serif;
  font-size: 12px;
  letter-spacing: .04em;
}

.music-toggle span:first-child { font-size: 18px; }
.music-toggle:disabled { opacity: .58; cursor: default; }

.cover {
  position: relative;
  min-height: 100svh;
  padding: clamp(18px, 4vw, 48px);
  display: grid;
  place-items: center;
}

.cover-glow {
  position: absolute;
  width: 40rem;
  height: 40rem;
  border-radius: 50%;
  background: rgba(229, 190, 121, .18);
  filter: blur(80px);
  pointer-events: none;
}

.book-page {
  position: relative;
  width: min(100%, 700px);
  min-height: min(92svh, 920px);
  padding: clamp(42px, 8vw, 82px) clamp(22px, 7vw, 76px) 34px;
  border: 1px solid rgba(132, 93, 53, .25);
  border-radius: 10px 28px 28px 10px;
  background:
    linear-gradient(90deg, rgba(99,66,36,.08), transparent 6%, transparent 94%, rgba(99,66,36,.06)),
    radial-gradient(circle at 75% 12%, rgba(211,165,97,.12), transparent 16rem),
    var(--paper);
  box-shadow: 0 28px 90px rgba(0,0,0,.34), inset 10px 0 20px rgba(99,66,36,.05);
  text-align: center;
}

.book-page::before {
  content: "";
  position: absolute;
  inset: 10px -9px -10px 8px;
  z-index: -1;
  border-radius: inherit;
  background: #d3b88f;
  box-shadow: 8px 12px 0 #765039;
}

.eyebrow, .letter-date {
  margin: 0 0 14px;
  font-family: Georgia, serif;
  font-size: 11px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--gold);
}

.cover h1 {
  margin: 0;
  font-size: clamp(42px, 9vw, 74px);
  line-height: 1.12;
  font-weight: 500;
  letter-spacing: .08em;
  color: var(--brown);
}

.cover-copy {
  margin: 18px 0 28px;
  color: var(--ink-soft);
  font-size: clamp(14px, 3vw, 18px);
  letter-spacing: .18em;
}

.photo-frame {
  margin: 0;
  padding: 12px 12px 20px;
  background: #fdfaf3;
  box-shadow: 0 16px 40px rgba(66, 43, 28, .19);
}

.photo-frame img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  background: #dacbb7;
  object-fit: contain;
}

.hero-photo { transform: rotate(-1.4deg); }

.photo-frame figcaption {
  margin-top: 14px;
  color: #6f5543;
  font-family: "Kaiti SC", "STKaiti", cursive;
  font-size: clamp(15px, 3vw, 19px);
  letter-spacing: .05em;
}

.image-missing { opacity: 0; }

.reveal-button {
  width: min(100%, 390px);
  margin: 30px auto 12px;
  padding: 15px 24px;
  display: flex;
  justify-content: center;
  gap: 14px;
  border: 1px solid #8b603a;
  border-radius: 999px;
  color: #fff7e8;
  background: linear-gradient(135deg, #6b452c, #9b6a3e);
  box-shadow: 0 10px 24px rgba(74,45,25,.24), inset 0 1px rgba(255,255,255,.3);
  cursor: pointer;
  font-size: 16px;
  letter-spacing: .12em;
  transition: transform .2s ease, box-shadow .2s ease;
}

.reveal-button:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(74,45,25,.3); }
.reveal-button:focus-visible, .music-toggle:focus-visible { outline: 3px solid #f3cc8a; outline-offset: 3px; }
.reveal-button:disabled { cursor: default; opacity: .78; }

.signature-preview {
  margin: 0;
  color: var(--gold);
  font-family: "Kaiti SC", cursive;
  font-size: 14px;
}

.sparkle-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.sparkle-layer i {
  position: absolute;
  top: 55%;
  width: 7px;
  height: 12px;
  border-radius: 2px;
  opacity: 0;
}

.is-revealed .sparkle-layer i { animation-name: celebration; animation-timing-function: cubic-bezier(.15,.7,.2,1); }

.wishes {
  position: relative;
  height: 0;
  opacity: 0;
  overflow: hidden;
  visibility: hidden;
  background:
    linear-gradient(rgba(117,84,51,.055) 1px, transparent 1px),
    var(--paper);
  background-size: 100% 32px;
  transition: opacity .8s ease .45s;
}

.wishes::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 8% 16%, rgba(202, 157, 89, .15) 0 2px, transparent 3px),
    radial-gradient(circle at 92% 39%, rgba(202, 157, 89, .12) 0 3px, transparent 4px),
    radial-gradient(circle at 12% 68%, rgba(202, 157, 89, .12) 0 2px, transparent 3px),
    radial-gradient(circle at 88% 84%, rgba(202, 157, 89, .14) 0 2px, transparent 3px);
  background-size: 190px 240px, 260px 310px, 230px 280px, 210px 270px;
}

.is-revealed .wishes {
  height: auto;
  min-height: 100vh;
  opacity: 1;
  overflow: visible;
  visibility: visible;
}

.story-intro, .chapter-heading, .memory, .memory-thread, .wish-card, .letter, .finale-card, .ending {
  width: min(calc(100% - 32px), 900px);
  margin-inline: auto;
}

.story-intro {
  position: relative;
  padding: clamp(98px, 20vw, 180px) 20px clamp(70px, 13vw, 120px);
  text-align: center;
}

.story-intro::before,
.story-intro::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 1px;
  height: 54px;
  background: linear-gradient(transparent, var(--gold-light), transparent);
}

.story-intro::before { top: 24px; }
.story-intro::after { bottom: 0; }

.story-kicker {
  display: block;
  margin-bottom: 28px;
  color: var(--gold);
  font: 10px/1.4 Georgia, serif;
  letter-spacing: .28em;
}

.story-intro p {
  margin: 0 0 16px;
  color: var(--ink-soft);
  font-size: 15px;
  letter-spacing: .12em;
}

.story-intro strong {
  display: block;
  font-size: clamp(26px, 6vw, 44px);
  font-weight: 500;
  line-height: 1.65;
  letter-spacing: .08em;
}

.story-intro i {
  display: block;
  margin-top: 26px;
  color: var(--gold-light);
  font-style: normal;
  font-size: 18px;
}

.chapter-heading {
  padding: clamp(80px, 14vw, 150px) 8px 40px;
  display: flex;
  align-items: flex-start;
  gap: 20px;
}

.chapter-heading span {
  font: italic 42px/1 Georgia, serif;
  color: var(--gold-light);
}

.chapter-heading p {
  margin: 0;
  font-size: clamp(25px, 5vw, 46px);
  line-height: 1.45;
  letter-spacing: .08em;
}

.memory { position: relative; padding-bottom: 72px; }
.landscape-frame { padding: clamp(10px, 2vw, 18px) clamp(10px, 2vw, 18px) 24px; transform: rotate(1.2deg); }
.memory-flowers .landscape-frame { transform: rotate(-1deg); }

.memory-note {
  width: max-content;
  max-width: 84%;
  margin: -20px 3% 0 auto;
  position: relative;
  z-index: 2;
  padding: 20px 28px;
  background: #efe1c9;
  box-shadow: 0 10px 24px rgba(75,50,32,.12);
  transform: rotate(-2deg);
}

.memory-note p { margin: 0; line-height: 1.8; letter-spacing: .08em; }
.note-star { position: absolute; right: 12px; top: 8px; color: var(--gold); }
.chapter-two { padding-top: 46px; }

.memory-thread {
  position: relative;
  padding: 42px 26px 72px 68px;
  color: var(--ink-soft);
}

.memory-thread > span {
  position: absolute;
  left: 32px;
  top: 24px;
  bottom: 56px;
  width: 1px;
  background: linear-gradient(var(--gold-light), rgba(169,119,66,.12));
}

.memory-thread > span::before,
.memory-thread > span::after {
  content: "";
  position: absolute;
  left: -4px;
  width: 9px;
  height: 9px;
  border: 1px solid var(--gold);
  border-radius: 50%;
  background: var(--paper);
}

.memory-thread > span::before { top: 0; }
.memory-thread > span::after { bottom: 0; }
.memory-thread p { margin: 0 0 12px; color: var(--gold); font-size: 13px; letter-spacing: .18em; }
.memory-thread strong { font-size: clamp(20px, 4.8vw, 32px); font-weight: 500; line-height: 1.7; letter-spacing: .06em; }

.pressed-flower {
  position: absolute;
  right: 2%;
  bottom: 30px;
  margin: 0;
  color: #b98e63;
  font-size: 64px;
  transform: rotate(16deg);
}

.wish-card {
  margin-top: 18px;
  margin-bottom: clamp(80px, 16vw, 150px);
  padding: clamp(30px, 7vw, 58px);
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  border: 1px solid rgba(169,119,66,.28);
  background: rgba(255, 251, 241, .72);
  box-shadow: 0 18px 44px rgba(84,57,36,.09);
}

.wish-card::before {
  content: "✦";
  position: absolute;
  top: -16px;
  left: 50%;
  padding: 6px 12px;
  color: var(--gold);
  background: var(--paper);
  transform: translateX(-50%);
}

.wish-card > p {
  grid-column: 1 / -1;
  margin: 0 0 12px;
  text-align: center;
  color: var(--gold);
  font-size: 13px;
  letter-spacing: .18em;
}

.wish-card div {
  padding: 22px 10px;
  text-align: center;
  border-top: 1px solid rgba(169,119,66,.2);
}

.wish-card div span { display: block; margin-bottom: 14px; color: var(--gold-light); font: italic 28px/1 Georgia, serif; }
.wish-card div strong { color: #5f4a3d; font-size: 16px; font-weight: 500; line-height: 1.75; letter-spacing: .04em; }

.letter {
  margin-top: 30px;
  margin-bottom: 80px;
  padding: clamp(38px, 8vw, 84px) clamp(24px, 8vw, 86px);
  position: relative;
  background: rgba(255,252,245,.86);
  border: 1px solid rgba(150,112,72,.3);
  box-shadow: 0 24px 60px rgba(84,57,36,.13);
}

.letter::before, .letter::after {
  content: "";
  position: absolute;
  width: 90px;
  height: 26px;
  background: rgba(202,172,126,.38);
}

.letter::before { left: -24px; top: 18px; transform: rotate(-12deg); }
.letter::after { right: -24px; bottom: 18px; transform: rotate(-10deg); }
.letter h2 { margin: 10px 0 34px; font-size: clamp(29px, 5vw, 45px); font-weight: 500; }
.letter-body { color: #5f4a3d; font-size: clamp(16px, 2.5vw, 20px); line-height: 2.05; letter-spacing: .04em; }
.letter-body p { margin: 0 0 18px; }

.letter-signature { margin-top: 40px; text-align: right; color: var(--gold); }
.letter-signature span { display: block; font-size: 14px; }
.letter-signature strong { font-family: "Kaiti SC", cursive; font-size: 34px; font-weight: 500; }
.letter-signature i { margin-left: 8px; font-size: 24px; }

.finale-card {
  position: relative;
  margin-bottom: 76px;
  padding: clamp(62px, 14vw, 120px) 24px;
  overflow: hidden;
  text-align: center;
  color: #fff7e8;
  border: 1px solid rgba(235,202,146,.32);
  background:
    radial-gradient(circle at 50% 18%, rgba(225,185,116,.25), transparent 18rem),
    linear-gradient(145deg, #6a4932, #2f211b 72%);
  box-shadow: 0 26px 60px rgba(55,35,25,.25);
}

.finale-card::before,
.finale-card::after {
  content: "";
  position: absolute;
  width: 160px;
  height: 160px;
  border: 1px solid rgba(238,205,150,.16);
  border-radius: 50%;
}

.finale-card::before { left: -86px; top: -74px; }
.finale-card::after { right: -90px; bottom: -80px; }
.finale-star { display: block; margin-bottom: 24px; color: var(--gold-light); font-size: 22px; }
.finale-card > p { margin: 0 0 18px; color: #e8c88f; font-size: 15px; letter-spacing: .28em; }
.finale-card h2 { margin: 0 0 36px; font-size: clamp(28px, 6vw, 46px); font-weight: 500; line-height: 1.65; letter-spacing: .08em; }
.finale-card div { color: rgba(255,247,232,.78); font-size: 16px; line-height: 2.1; letter-spacing: .08em; }
.finale-card div strong { display: inline-block; margin-top: 8px; color: #fff7e8; font-size: 19px; font-weight: 500; }
.finale-heart { display: block; margin-top: 30px; color: var(--gold-light); font-size: 30px; }

.reveal-on-scroll {
  opacity: 0;
  transform: translateY(28px) scale(.99);
  transition: opacity .9s ease, transform 1.05s cubic-bezier(.2,.72,.25,1);
}

.reveal-on-scroll.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.ending { padding: 20px 0 90px; text-align: center; color: var(--ink-soft); }
.ending p { margin: 0 0 12px; font: italic clamp(25px, 5vw, 42px)/1.2 Georgia, serif; color: var(--brown); }
.ending span { font-size: 14px; letter-spacing: .18em; }

@keyframes celebration {
  0% { opacity: 0; transform: translateY(0) rotate(0deg) scale(.6); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-65vh) rotate(340deg) scale(1); }
}

@media (min-width: 760px) {
  .cover-page { padding-inline: 90px; }
  .memory { padding-inline: 40px; }
}

@media (max-width: 480px) {
  .music-toggle { top: max(10px, env(safe-area-inset-top)); right: 10px; padding: 8px 11px; }
  .cover { padding: 18px 12px; }
  .book-page { border-radius: 7px 18px 18px 7px; min-height: calc(100svh - 36px); padding-top: 54px; }
  .cover h1 { font-size: 44px; }
  .hero-photo { padding: 8px 8px 16px; }
  .letter::before, .letter::after { width: 68px; }
  .chapter-heading, .memory, .story-intro, .memory-thread, .wish-card, .letter, .finale-card, .ending { width: min(calc(100% - 24px), 900px); }
  .chapter-heading { padding-top: 72px; gap: 14px; }
  .memory { padding-bottom: 58px; }
  .memory-thread { padding-left: 56px; }
  .memory-thread > span { left: 24px; }
  .wish-card { grid-template-columns: 1fr; gap: 0; padding: 32px 24px; }
  .wish-card div { display: grid; grid-template-columns: 48px 1fr; align-items: center; text-align: left; }
  .wish-card div span { margin: 0; }
  .finale-card { padding-inline: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .reveal-on-scroll { opacity: 1; transform: none; }
}
