:root {
  --lilac: #f6ebff;
  --paper: #f3e4fb;
  --ink: #4a1868;
  --deep: #3b1458;
  --gold: #b8892e;
  --gold-soft: #e6c56a;
  --muted: #7a5a92;
  color-scheme: light;
  font-family: "Outfit", "Avenir Next", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #f3e6fb; color: var(--ink); }
body {
  overflow-x: hidden;
  overflow-y: auto;
  background:
    radial-gradient(circle at 50% 40%, #fff 0%, #f4e7ff 42%, #e4c8f4 100%);
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
#dust { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
.glow {
  position: fixed;
  width: 80vw;
  height: 80vw;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(255, 255, 255, .7), rgba(228, 200, 244, 0) 68%);
  z-index: 0;
  pointer-events: none;
}
#intro {
  --fly: 1;
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 50% 42%, #fff 0%, #f6ebff 46%, #e7cff6 100%);
  transition: opacity .8s ease, visibility .8s ease;
}
#intro.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.intro-label {
  margin: 0;
  min-height: 1.2em;
  letter-spacing: .28em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--deep);
}
.pieces { display: flex; gap: 8px; min-height: 64px; align-items: center; }
.piece {
  width: 46px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 10px 16px 10px 14px;
  background: #fff;
  color: var(--deep);
  border: 1px solid rgba(184, 137, 46, .7);
  box-shadow: 0 10px 18px rgba(74, 24, 104, .12);
  font-family: "Cinzel", Georgia, serif;
  font-size: 22px;
  opacity: 1;
  transform: translate(calc(var(--x) * var(--fly)), calc(var(--y) * var(--fly))) rotate(var(--r));
}
#intro.solve .piece {
  animation: snap .85s cubic-bezier(.16, .9, .24, 1) forwards;
  animation-delay: var(--d);
}
.code {
  margin: 0;
  min-height: 1.4em;
  font-family: "Cinzel", Georgia, serif;
  letter-spacing: .22em;
  font-size: clamp(16px, 4vw, 22px);
  color: var(--gold);
}
.bar {
  width: min(280px, 70vw);
  height: 3px;
  border-radius: 99px;
  background: rgba(74, 24, 104, .15);
  overflow: hidden;
}
.bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #b8892e, #4a1868);
}
#intro.solve .bar span { width: 100%; transition: width 5.2s linear; }
.intro-welcome {
  margin: 0;
  min-height: 1.2em;
  font-family: "Great Vibes", cursive;
  font-size: clamp(36px, 8vw, 54px);
  color: var(--deep);
  opacity: 0;
  transform: translateY(10px);
}
.intro-welcome.show { opacity: 1; animation: welcome .8s ease forwards; }
#skip {
  position: absolute;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(74, 24, 104, .3);
  color: var(--deep);
  background: rgba(255, 255, 255, .7);
}
@keyframes snap {
  0% { transform: translate(calc(var(--x) * var(--fly)), calc(var(--y) * var(--fly))) rotate(var(--r)) scale(.86); }
  100% { transform: none; }
}
@keyframes welcome { to { opacity: 1; transform: none; } }
@media (max-width: 700px) {
  #intro { --fly: .18; gap: 14px; padding-left: 12px; padding-right: 12px; }
  .intro-label, .code { position: relative; z-index: 3; background: rgba(246, 235, 255, .92); padding: 4px 10px; border-radius: 8px; }
  .piece { width: 34px; height: 42px; font-size: 16px; }
  .pieces { gap: 4px; max-width: 100%; }
  .intro-label { letter-spacing: .12em; font-size: 11px; text-align: center; }
  .code { letter-spacing: .06em; font-size: 14px; text-align: center; padding: 0 8px; }
  .intro-welcome { font-size: 34px; text-align: center; padding: 0 12px; }
}
.stage {
  opacity: 0;
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 100vw;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
  gap: 14px;
  overflow: visible;
}
.kicker {
  margin: 0;
  letter-spacing: .22em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--deep);
}
.book {
  position: relative;
  width: min(440px, 100%);
  min-width: 0;
  height: min(680px, calc(100dvh - 150px));
  min-height: 520px;
  perspective: 1600px;
  overflow: hidden;
  border-radius: 18px;
  filter: drop-shadow(0 24px 36px rgba(74, 24, 104, .28));
}
.leaf {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transition: transform .95s cubic-bezier(.7, .05, .2, 1), opacity .7s ease;
  opacity: 0;
  pointer-events: none;
  transform: translateX(28px) rotateY(-10deg) scale(.975);
}
.leaf.active { opacity: 1; pointer-events: auto; transform: none; z-index: 3; }
.leaf.after { z-index: 1; }
.leaf.before { opacity: 0; transform: translateX(-16%) rotateY(18deg) scale(.96); z-index: 2; }
.leaf.leaving { z-index: 4; opacity: 0; transform: translateX(-20%) rotateY(24deg) scale(.96); }
.book[data-turn="back"] .leaf.leaving { transform: translateX(16%) rotateY(-16deg) scale(.98); }
.paper {
  height: 100%;
  border-radius: 18px;
  overflow: auto;
  position: relative;
  background: #f7eefc center / cover no-repeat;
}
.poster { background-image: url("chis-world.png"); }
.floral {
  background-image:
    linear-gradient(180deg, rgba(247, 238, 252, .2), rgba(247, 238, 252, .08) 22%, rgba(247, 238, 252, .08) 78%, rgba(247, 238, 252, .2)),
    url("chis-world.png");
}
.inner {
  position: absolute;
  z-index: 1;
  left: 10%;
  right: 10%;
  top: 10%;
  bottom: 8%;
  display: flex;
  flex-direction: column;
  justify-content: safe center;
  text-align: center;
  padding: 18px 16px 20px;
  overflow: auto;
  background: #fbf7ff;
  border-radius: 18px;
  box-shadow: 0 12px 28px rgba(74, 24, 104, .12);
}
.eyebrow {
  margin: 0;
  letter-spacing: .34em;
  text-transform: uppercase;
  font-family: "Cinzel", Georgia, serif;
  font-size: 13px;
  color: var(--deep);
}
.eyebrow.long { letter-spacing: .14em; font-size: 11px; line-height: 1.45; }
.script, .name, .sign, .close, .age {
  font-family: "Great Vibes", cursive;
  font-weight: 400;
}
.script {
  margin: 22px 0 0;
  font-size: clamp(52px, 12vw, 68px);
  line-height: 1.35;
  color: #c6a24e;
  text-shadow: 0 1px 0 #fff6d8, 0 8px 18px rgba(184, 137, 46, .25);
}
.greet .eyebrow { margin-bottom: 2px; }
.greet .script { font-size: clamp(44px, 10vw, 58px); margin-top: 8px; }
.greet .age { font-size: clamp(60px, 14vw, 80px); }
.greet .name { font-size: clamp(46px, 11vw, 64px); }
.letter .name.small { font-size: 44px; margin-bottom: 2px; }
.letter p { margin-top: 6px; font-size: 15px; line-height: 1.45; }
.letter .sign { margin-top: 8px; font-size: 30px; }
.name {
  margin: 4px 0 0;
  font-size: clamp(52px, 13vw, 72px);
  line-height: 1.15;
  color: var(--deep);
}
.name.small { font-size: 56px; margin-bottom: 8px; }
.age {
  margin: 0;
  font-size: clamp(72px, 16vw, 96px);
  line-height: 1;
  color: var(--deep);
}
.hearts { margin: 4px 0; color: #b8892e; letter-spacing: .4em; font-size: 14px; }
.date {
  margin: 8px 0 0;
  font-family: "Cinzel", Georgia, serif;
  letter-spacing: .18em;
  text-transform: uppercase;
  font-size: 13px;
}
.line, .letter p, .wish p {
  margin: 10px 0 0;
  font-size: 16px;
  line-height: 1.55;
  font-weight: 300;
  color: #3d2454;
}
.sign, .close {
  margin: 12px 0 0;
  font-size: 34px;
  color: var(--gold);
}
.wishes {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}
.wishes li {
  margin: 7px 0;
  font-family: "Great Vibes", cursive;
  font-size: 28px;
  line-height: 1;
  color: var(--deep);
}
.wishes li:before { content: "♥ "; color: var(--gold); font-size: 14px; }
.controls {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  grid-template-rows: auto auto;
  align-items: center;
  width: min(440px, 100%);
  min-width: 0;
  gap: 8px 10px;
}
.controls button {
  min-height: 48px;
  border-radius: 999px;
  border: 1px solid rgba(74, 24, 104, .35);
  color: var(--deep);
  background: rgba(255, 255, 255, .55);
}
.dots { grid-column: 2; display: flex; justify-content: center; gap: 8px; }
#prev { grid-column: 1; }
#next { grid-column: 3; }
.controls .dot {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  display: grid;
  place-items: center;
}
.controls .dot::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(74, 24, 104, .28);
}
.controls .dot.on { background: transparent; transform: none; }
.controls .dot.on::before { background: var(--gold); transform: scale(1.3); }
.count {
  grid-column: 1 / -1;
  text-align: center;
  letter-spacing: .22em;
  font-size: 11px;
  color: var(--muted);
}
.rise { opacity: 1; }
.leaf.active .rise { animation: rise .9s cubic-bezier(.16, .84, .32, 1) both; }
.leaf.active .rise:nth-child(2) { animation-delay: .08s; }
.leaf.active .rise:nth-child(3) { animation-delay: .16s; }
.leaf.active .rise:nth-child(4) { animation-delay: .24s; }
.leaf.active .rise:nth-child(5) { animation-delay: .32s; }
.leaf.active .rise:nth-child(6) { animation-delay: .4s; }
.leaf.active .age span { display: inline-block; animation: pop .8s cubic-bezier(.2, .8, .2, 1) both; }
.leaf.active .age span:last-child { animation-delay: .1s; }
@keyframes rise { from { transform: translateY(14px); } to { transform: none; } }
@keyframes pop { from { transform: translateY(16px) scale(.94); } to { transform: none; } }
body.ready .stage { animation: arrive 1s cubic-bezier(.16, .84, .32, 1) forwards; }
.book { animation: float 6s ease-in-out infinite; }
@keyframes arrive {
  from { opacity: 0; transform: translateY(28px) scale(.92); }
  to { opacity: 1; transform: none; }
}
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@media (max-width: 700px) {
  html, body { height: 100%; overflow: hidden; }
  .stage {
    height: 100dvh;
    min-height: 0;
    max-height: 100dvh;
    justify-content: flex-start;
    overflow: hidden;
    padding: calc(8px + env(safe-area-inset-top)) 12px calc(8px + env(safe-area-inset-bottom));
    gap: 8px;
  }
  .kicker {
    flex: none;
    letter-spacing: .08em;
    text-align: center;
    font-size: 10px;
    max-width: 100%;
  }
  .book {
    flex: 1 1 auto;
    width: 100%;
    height: auto;
    min-height: 0;
    max-height: 100%;
  }
  .controls { flex: none; width: 100%; gap: 4px 8px; }
  .inner {
    left: 6%;
    right: 6%;
    top: 7%;
    bottom: 6%;
    padding: 12px 10px 14px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .greet .script { font-size: 40px; margin-top: 4px; line-height: 1.15; }
  .greet .age { font-size: 52px; }
  .greet .name { font-size: 40px; }
  .line, .letter p { font-size: 15px; }
  .date { letter-spacing: .08em; font-size: 11px; }
  .wishes li { font-size: 22px; line-height: 1.25; }
  .script { font-size: 40px; margin-top: 8px; }
  .name.small, .letter .name.small { font-size: 40px; }
  .letter .sign, .close { font-size: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  .book, .leaf, .rise, .age span, .piece, .intro-welcome { animation: none !important; transition: none !important; }
  .rise, .age span, .piece { opacity: 1; transform: none; }
  .stage { opacity: 1; }
}
