html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: #fef8f6;
}

body {
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

.pb-safe { padding-bottom: env(safe-area-inset-bottom, 0px); }
.pt-safe { padding-top: env(safe-area-inset-top, 0px); }

::-webkit-scrollbar { display: none; }

.paper-grain {
  background-image:
    radial-gradient(#dcc0bd 0.5px, transparent 0.5px),
    radial-gradient(#dcc0bd 0.5px, #fef8f6 0.5px);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
  opacity: 0.28;
}

.is-hidden { display: none !important; }

.is-dim {
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.7s cubic-bezier(0.16, 1, 0.3, 1), transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

.is-dim.is-ready,
.is-ready {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.tw-safelist { display: none !important; }

.stage-enter {
  animation: stage-in 0.72s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.stage-leave {
  animation: stage-leave 0.22s ease forwards;
}

@keyframes stage-in {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

@keyframes stage-leave {
  to { opacity: 0; transform: translateY(-10px); }
}

.seal-breathe {
  animation: seal-breathe 3.2s ease-in-out infinite;
}

@keyframes seal-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.envelope-stage {
  perspective: 1050px;
  perspective-origin: 50% 34%;
  isolation: isolate;
}

.envelope-shell {
  position: absolute;
  inset: 0;
  border-radius: 7px;
  background: linear-gradient(155deg, #34171e, #652d39 62%, #431b26);
  box-shadow: 0 28px 42px -23px #431b269e, 0 3px 5px #32141c38;
}

.sealed-sheet {
  position: absolute;
  inset: 10% 8% auto;
  height: 85%;
  z-index: 3;
  display: grid;
  place-items: start center;
  align-content: start;
  gap: 7px;
  padding: 9% 8%;
  color: #783e38;
  background: linear-gradient(145deg, #fffdf6, #f3e9d7);
  border: 1px solid #d9c7aa;
  border-radius: 3px;
  box-shadow: 0 3px 12px #40241c38;
}

.sealed-sheet::before {
  content: '';
  position: absolute;
  inset: 7px;
  border: 1px solid #b8996466;
}

.sheet-title {
  font: 400 clamp(18px, 5vw, 25px)/1.4 'Noto Serif SC', serif;
  letter-spacing: .25em;
  text-indent: .25em;
}

.sheet-caption {
  font: 10px/1.4 Georgia, serif;
  letter-spacing: .2em;
}

.fold-left, .fold-right, .pocket-lip, .envelope-frame {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
}

.fold-left, .fold-right { z-index: 4; }

.fold-left {
  background: linear-gradient(110deg, #773946, #4f232e);
  clip-path: polygon(0 0, 62% 68%, 0 100%);
}

.fold-right {
  background: linear-gradient(250deg, #713440, #391923);
  clip-path: polygon(100% 0, 38% 68%, 100% 100%);
}

.pocket-lip {
  z-index: 5;
  background:
    repeating-linear-gradient(128deg, #ffffff05 0 1px, transparent 1px 5px),
    linear-gradient(150deg, #783945, #50212d 65%, #431b26);
  clip-path: polygon(0 100%, 0 37%, 50% 67%, 100% 37%, 100% 100%);
}

.envelope-frame {
  z-index: 5;
  box-shadow: inset 0 0 0 1px #d9ac7459;
}

.envelope-flap {
  position: absolute;
  inset: 0 0 auto;
  height: 66%;
  z-index: 6;
  transform-origin: center top;
  transform-style: preserve-3d;
}

.flap-face, .flap-lining {
  position: absolute;
  inset: 0;
  clip-path: polygon(0 0, 100% 0, 52% 98%, 50% 100%, 48% 98%);
  backface-visibility: hidden;
}

.flap-face {
  border-radius: 7px 7px 0 0;
  background: linear-gradient(133deg, #c19462, #ebcda0 42%, #80553e 80%);
}

.flap-face::before {
  content: '';
  position: absolute;
  inset: 0 2px 2px;
  border-radius: inherit;
  clip-path: inherit;
  background:
    repeating-linear-gradient(125deg, #ffffff06 0 1px, transparent 1px 5px),
    radial-gradient(ellipse at 30% 0, #925362, transparent 68%),
    linear-gradient(155deg, #733544, #4a1d29);
}

.flap-face::after {
  content: '';
  position: absolute;
  inset: 10px 18px 13px;
  clip-path: polygon(0 0, 100% 0, 50% 100%, 0 0, 1% 0, 50% 98%, 99% 0);
  background: linear-gradient(140deg, #e5bb825c, #e5bb8220);
}

.flap-lining {
  transform: rotateY(180deg);
  background: repeating-linear-gradient(120deg, #ffffff0c 0 1px, transparent 1px 8px),
    linear-gradient(155deg, #a35762, #571f30);
}

#wax-seal { backface-visibility: hidden; }

#seal-body {
  border-radius: 49% 46% 51% 45% / 46% 53% 44% 53%;
  background: radial-gradient(ellipse at 30% 20%, #efcd93, #bd8650 48%, #84532f 80%, #6f4028);
  box-shadow: 0 6px 10px #30101980, inset 0 1px 2px #ffebbf;
}

#seal-emblem {
  color: #684325;
  background: radial-gradient(circle at 65% 80%, #dec18b, #b7814e);
  border: 1px solid #f2d6a17a;
  box-shadow: inset 0 1px 3px #633a3166;
  text-shadow: 0 1px #f8dfa2a6;
}

.envelope-stage.is-open #wax-seal {
  animation: release-seal .36s ease-out both;
}

.envelope-stage.is-open .envelope-flap {
  animation: flap-open 1.05s cubic-bezier(.25,.65,.25,1) .34s both;
}

.envelope-stage.is-open .sealed-sheet:not(.has-paper-preview) {
  animation: sheet-rise 1.3s cubic-bezier(.18,.72,.25,1) 1.14s both;
}

@keyframes release-seal {
  45% { opacity: 1; transform: scale(.94) rotate(-5deg); }
  100% { opacity: 0; transform: translateY(7px) scale(.88) rotate(-9deg); }
}

@keyframes flap-open {
  0% { transform: rotateX(0); z-index: 6; }
  48% { transform: rotateX(90deg); z-index: 6; }
  49% { z-index: 2; }
  100% { transform: rotateX(164deg); z-index: 2; }
}

@keyframes sheet-rise {
  from { transform: translateY(0); }
  to { transform: translateY(-52%) rotate(-2deg); }
}

@media (prefers-reduced-motion: reduce) {
  .envelope-stage.is-open #wax-seal,
  .envelope-stage.is-open .envelope-flap,
  .envelope-stage.is-open .sealed-sheet { animation-delay: 0s; }
}

.letter-rise {
  animation: letter-rise 1.15s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes letter-rise {
  from { opacity: 0; transform: translateY(78px); }
  to { opacity: 1; transform: translateY(0); }
}

.ink-line,
.ink-block {
  animation: ink-in 0.9s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.ink-line { display: inline-block; }

@keyframes ink-in {
  from { opacity: 0; transform: translateY(8px); filter: blur(3px); }
  to { opacity: 1; transform: none; filter: none; }
}

.deal-in {
  animation: deal-in 0.78s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes deal-in {
  from { opacity: 0; transform: translateY(28px) rotate(var(--tilt, -3deg)); }
  to { opacity: 1; transform: none; }
}

.card-flipper {
  transform-style: preserve-3d;
  transition: transform 1s cubic-bezier(0.16, 1, 0.3, 1);
}

.card-face {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-face.front { transform: rotateY(180deg); }

.rise-in {
  animation: rise-in 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: none; }
}

.wax-press {
  animation: wax-press 0.48s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes wax-press {
  0% { transform: scale(1.35) rotate(-14deg); }
  55% { transform: scale(0.9) rotate(4deg); }
  100% { transform: scale(1) rotate(0); }
}

#music-btn.is-on .material-symbols-outlined {
  animation: spin-slow 8s linear infinite;
}

@keyframes spin-slow {
  to { transform: rotate(360deg); }
}

.clip-triangle {
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

#progress-fill {
  width: 0;
  transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.birthday-ritual {
  position: relative;
  width: min(100%, 320px);
}

.birthday-ritual.is-loading .envelope-stage,
.birthday-ritual.is-wishing .envelope-stage { visibility: hidden; }
.birthday-candle[hidden] { display: none; }

.birthday-candle {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.is-wishing .birthday-candle { animation: candle-scene 4.1s ease both; }

.birthday-candle > div {
  position: absolute;
  left: 50%;
  translate: -50% 0;
}

.candle-light {
  bottom: 27%;
  width: 160px;
  height: 150px;
  background: radial-gradient(ellipse, #efb35e70, #efb35e19 49%, transparent 72%);
  animation: candle-light-out 2.6s both;
}

.candle-plinth {
  bottom: 13%;
  width: 108px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(#f3d8a6, #b68652);
  box-shadow: 0 4px 0 #986840, 0 10px 18px #48252a35;
}

.candle-stick {
  bottom: 18%;
  height: 38%;
  width: 19px;
  border-radius: 46% 46% 24% 24% / 5%;
  background: repeating-linear-gradient(145deg, transparent 0 13px, #f2d19b88 14px 16px, transparent 17px 23px),
    linear-gradient(90deg, #683041, #a65b67 33%, #783541 82%, #552534);
  box-shadow: inset 0 2px 1px #edd1a58c, 2px 2px 5px #43212629;
}

.candle-wick {
  bottom: 56%;
  width: 2px;
  height: 7px;
  border-radius: 2px;
  background: #54332b;
}

.candle-flame {
  bottom: calc(56% + 4px);
  width: 16px;
  height: 29px;
  border-radius: 75% 25% 55% 45% / 75% 37% 63% 25%;
  background: radial-gradient(ellipse at 48% 76%, #fffce0 0 20%, #fbd27e 44%, #e59849 72%, #c36136);
  box-shadow: 0 0 12px #edb461a6;
  transform-origin: center bottom;
  animation: candle-blow 2.6s both;
}

.candle-smoke {
  bottom: calc(56% + 6px);
  width: 22px;
  height: 38px;
  border-left: 2px solid #806e70;
  border-radius: 50%;
  filter: blur(1.4px);
  animation: candle-smoke 2.6s ease-out both;
}

@keyframes candle-scene {
  0%, 100% { opacity: 0; }
  9%, 91% { opacity: 1; }
}

@keyframes candle-light-out {
  0%, 48% { opacity: 1; }
  62%, 100% { opacity: 0; }
}

@keyframes candle-blow {
  0%, 28% { transform: rotate(-5deg) scale(.94, 1); }
  15%, 42% { transform: rotate(7deg) scale(1, .92); }
  48% { opacity: 1; transform: skewX(32deg) scale(1.14, .63); }
  58%, 100% { opacity: 0; transform: skewX(47deg) scale(.4, .15); }
}

@keyframes candle-smoke {
  0%, 52% { opacity: 0; transform: translate(0, 10px) scale(.55); }
  64% { opacity: .5; }
  100% { opacity: 0; transform: translate(19px, -35px) scale(1.45) rotate(20deg); }
}

.envelope-stage.is-arriving {
  animation: envelope-arrive 1.15s cubic-bezier(.2,.65,.3,1) both;
}

@keyframes envelope-arrive {
  0% { opacity: 0; transform: translate(-12%, 22%) rotate(-9deg) scale(.92); }
  63% { opacity: 1; transform: translate(1%, -3%) rotate(1.2deg) scale(1); }
  100% { opacity: 1; transform: none; }
}

.candle-greeting {
  position: absolute;
  inset: auto -12px 69%;
  text-align: center;
  white-space: nowrap;
  font: italic 500 clamp(27px, 8vw, 42px)/1.25 "Segoe Script", "Apple Chancery", "Snell Roundhand", Georgia, cursive;
  letter-spacing: -.035em;
  color: #805124;
  text-shadow: 0 1px #fff3d7, 0 0 14px #e8ad6666;
  animation: candle-greeting-rise 4.1s cubic-bezier(.22,.65,.32,1) both;
}

@keyframes candle-greeting-rise {
  0%, 33% { opacity: 0; transform: translateY(13px) scale(.94); }
  49%, 89% { opacity: 1; transform: translateY(-7px) scale(1); }
  100% { opacity: 0; transform: translateY(-14px) scale(1); }
}

.sealed-sheet.has-paper-preview {
  display: block;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: #fffaf5;
  overflow: hidden;
}

.sealed-sheet.has-paper-preview::before { content: none; }
.sealed-sheet.has-paper-preview > * { margin: 0; }
.sealed-sheet.has-paper-preview .ink-line,
.sealed-sheet.has-paper-preview .ink-block { animation: none; }

::view-transition-group(birthday-paper) {
  animation-duration: .55s;
  animation-timing-function: cubic-bezier(.22,.72,.27,1);
}

#epistle-card,
#letterPaper { transform-origin: top left; }

::view-transition-group(birthday-paper) {
  animation-duration: .95s;
  animation-timing-function: cubic-bezier(.22,.68,.28,1);
}

::view-transition-old(birthday-paper) { display: none; }

::view-transition-new(birthday-paper) {
  animation: paper-unfold .95s cubic-bezier(.22,.68,.28,1) both;
  height: 100%;
  mix-blend-mode: normal;
}

@keyframes paper-unfold {
  from { clip-path: inset(0 0 100% 0); translate: 0 0; }
  74% { clip-path: inset(0); translate: 0 -12px; }
  to { clip-path: inset(0); translate: 0 0; }
}

.is-folding-letter #letterPaper {
  transform-origin: center bottom;
  animation: fold-birthday-letter .2s ease-in both;
}

@keyframes fold-birthday-letter {
  to { transform: perspective(650px) rotateX(13deg) translateY(14px) scale(.96); }
}

::view-transition-group(selected-blessing) {
  animation-duration: .72s;
  animation-timing-function: cubic-bezier(.22,.68,.28,1);
}

#epistle-card::after {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px solid #e9c17666;
  border-radius: inherit;
  pointer-events: none;
}

.is-letter-arriving #letterPaper {
  animation: letter-flight-to-page 2.4s linear both;
}

.is-letter-arriving #letter-text {
  animation: letter-flight-ink 2.4s linear both;
}

.is-letter-arriving > :not(:nth-child(2)),
.is-letter-arriving #letterPaper + div,
.is-letter-arriving #letterPaper > div > :not(:nth-child(2)),
.is-letter-arriving #letterPaper > div > :nth-child(2) > :not(h2),
.is-letter-arriving :has(+ #letterPaper) {
  animation: letter-flight-details 2.4s ease-out both;
}

@keyframes letter-flight-to-page {
  0% {
    opacity: 0;
    transform: translate(-45vw, 48vh) rotate(-13deg) scale(.22);
    clip-path: polygon(0 39%, 100% 0, 77% 93%, 50% 69%, 33% 93%, 29% 59%);
    animation-timing-function: cubic-bezier(.35,.05,.72,.62);
  }
  22% { opacity: 1; }
  34% {
    clip-path: polygon(0 39%, 100% 0, 77% 93%, 50% 69%, 33% 93%, 29% 59%);
  }
  56% {
    transform: translate(10%, -5vh) rotate(-12deg) scale(.63);
    clip-path: polygon(0 35%, 100% 0, 94% 91%, 55% 77%, 19% 94%, 10% 65%);
    animation-timing-function: cubic-bezier(.16,.62,.34,1);
  }
  100% {
    opacity: 1;
    transform: none;
    clip-path: polygon(0 0, 100% 0, 100% 100%, 55% 100%, 0 100%, 0 50%);
  }
}

@keyframes letter-flight-details {
  0%, 54% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes letter-flight-ink {
  0%, 46% { opacity: 0; }
  94%, 100% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .is-letter-arriving #letterPaper { animation-name: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .is-letter-arriving #letterPaper::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 30;
    background: linear-gradient(150deg, #fffef9 7%, #f8e7cf 65%, #ecd1af);
    clip-path: polygon(0 39%, 100% 0, 29% 59%, 33% 93%, 50% 69%, 77% 93%, 100% 0);

    animation: letter-flight-folds 2.4s linear both;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .is-letter-arriving #letterPaper::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 31;
    pointer-events: none;
    background: linear-gradient(135deg, #e4c3a0 32%, #bd9471);
    clip-path: polygon(29% 59%, 100% 0, 50% 69%, 33% 93%);
    animation: letter-flight-folds 2.4s linear both;
  }
}

@keyframes letter-flight-folds {
  0%, 39% { opacity: 1; }
  74%, 100% { opacity: 0; }
}
