:root {
  color-scheme: dark;
  --cream: #f5eee1;
  --gold: #f3cc82;
  --ink: #020403;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--ink);
}

body {
  color: var(--cream);
  font-family: Georgia, "Times New Roman", "Songti SC", "STSong", serif;
  overflow: hidden;
}

button {
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 5px;
}

.experience {
  position: relative;
  width: 100%;
  height: 100svh;
  min-height: 520px;
  overflow: hidden;
  background: #020403;
}

.scene {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(28px, env(safe-area-inset-top)) 22px max(24px, env(safe-area-inset-bottom));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 1.15s ease, visibility 1.15s;
}

.scene.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.opening {
  background: radial-gradient(circle at 50% 46%, #111510 0, #050706 34%, #010201 76%);
}

.opening::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .18;
  background-image: radial-gradient(#fff 0 .6px, transparent .8px);
  background-size: 6px 6px;
  mask-image: linear-gradient(to bottom, transparent, #000 40%, transparent);
}

.opening-whispers { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.opening-whispers span { position: absolute; color: #f6eadf2e; font-size: 13px; font-style: italic; letter-spacing: .08em; animation: whisper-drift 9s ease-in-out infinite alternate; }
.opening-whispers span:nth-child(1) { left: 12%; top: 22%; }
.opening-whispers span:nth-child(2) { right: 13%; top: 64%; animation-delay: -3s; }
.opening-whispers span:nth-child(3) { left: 20%; bottom: 12%; animation-delay: -6s; }

.to-teacher {
  position: absolute;
  top: clamp(25%, 31vh, 34%);
  margin: 0;
  color: #c7c2b8;
  font-family: "Songti SC", "STSong", serif;
  font-size: 13px;
  letter-spacing: .32em;
  text-indent: .32em;
  opacity: .72;
  animation: soft-arrive 1.5s ease both;
}

.letter-button {
  position: relative;
  min-width: min(72vw, 230px);
  min-height: 58px;
  padding: 0 50px 0 34px;
  border: 1px solid #e8d4a64d;
  border-radius: 3px;
  background: linear-gradient(145deg, #171b17b8, #0a0d0bdb);
  box-shadow: 0 18px 55px #000, inset 0 0 28px #f7d99908;
  letter-spacing: .08em;
  animation: button-breathe 3.2s 1s ease-in-out infinite, soft-arrive 1.4s .3s ease both;
  transition: transform .25s ease, border-color .25s ease;
}

.letter-button:hover { transform: scale(1.045); border-color: #f2d38f8f; }
.letter-button:active { transform: scale(.98); }
.letter-button i { position: absolute; right: 20px; top: 18px; color: var(--gold); font-style: normal; opacity: .7; }

.letter {
  background: #08130f;
}

.letter-backdrop {
  position: absolute;
  inset: 0;
  background-image: linear-gradient(180deg, #03100b30, #0104039c), url("assets/chalkboard-sunset-stars.png");
  background-position: center;
  background-size: cover;
  transform: scale(1.03);
  transition: transform 8s ease-out;
}

.letter.is-active .letter-backdrop { transform: scale(1); }

.letter::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, transparent 5%, #0208074f 64%, #010302d9 100%);
}

.message-card {
  position: relative;
  z-index: 2;
  width: min(90vw, 690px);
  padding: clamp(26px, 5vw, 46px) clamp(22px, 6vw, 58px);
  border: 1px solid #f8deb635;
  border-radius: 2px 24px 2px 24px;
  background: linear-gradient(145deg, #071713c7, #07110fc2);
  box-shadow: 0 30px 80px #0009, inset 0 0 60px #ddbf7a0d;
  backdrop-filter: blur(5px);
  text-align: center;
}

.message-line {
  min-height: 1.55em;
  margin: 0 0 3px;
  color: #f7f0e5;
  font-size: clamp(16px, 3.8vw, 24px);
  line-height: 1.48;
  letter-spacing: .025em;
  text-shadow: 0 2px 18px #000;
}

.message-line.typing::after {
  content: "";
  display: inline-block;
  width: 1px;
  height: .9em;
  margin-left: 5px;
  background: var(--gold);
  animation: blink .7s steps(1) infinite;
}

.message-space { height: clamp(10px, 2vh, 18px); }
.message-last { margin-bottom: 0; color: #ffe0a1; }

.chinese-message {
  margin-top: clamp(18px, 3.5vh, 30px);
  padding-top: clamp(15px, 2.6vh, 22px);
  border-top: 1px solid #efd6a830;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 1s ease, transform 1s ease;
}

.chinese-message.is-visible { opacity: 1; transform: none; }
.chinese-message p { margin: 0 0 5px; color: #f6ebd7; font-family: "Songti SC", "STSong", serif; font-size: clamp(15px, 3.7vw, 20px); line-height: 1.7; letter-spacing: .04em; }

.continue-button {
  min-width: min(78vw, 260px);
  min-height: 46px;
  margin-top: clamp(20px, 3.5vh, 30px);
  border: 1px solid #f5d39078;
  border-radius: 999px;
  background: #07120fc7;
  box-shadow: 0 12px 34px #0006;
  letter-spacing: .1em;
  text-indent: .1em;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity .8s ease, transform .8s ease, background .25s ease;
}

.continue-button.is-visible { opacity: 1; transform: none; pointer-events: auto; }
.continue-button:hover { background: #173129de; }

.floating-letters { position: absolute; inset: 0; z-index: 1; overflow: hidden; pointer-events: none; }
.floating-letters span { position: absolute; color: #ffe6ae42; font-style: italic; animation: float 8s ease-in-out infinite alternate; }
.floating-letters span:nth-child(1) { left: 9%; top: 20%; font-size: 18px; }
.floating-letters span:nth-child(2) { right: 12%; top: 26%; font-size: 13px; animation-delay: -2s; }
.floating-letters span:nth-child(3) { left: 14%; bottom: 17%; font-size: 12px; animation-delay: -4s; }
.floating-letters span:nth-child(4) { right: 10%; bottom: 15%; font-size: 13px; animation-delay: -1s; }
.floating-letters span:nth-child(5) { right: 25%; top: 10%; font-size: 14px; animation-delay: -3s; }

.finale {
  background: radial-gradient(circle at 50% 45%, #183e35 0, #0a211c 27%, #030907 68%, #010201 100%);
}

.finale::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .35;
  background-image: radial-gradient(circle at 20% 22%, #fff 0 1px, transparent 1.5px), radial-gradient(circle at 72% 16%, #ffd895 0 1px, transparent 1.6px), radial-gradient(circle at 84% 66%, #fff 0 1px, transparent 1.5px), radial-gradient(circle at 14% 75%, #ffd895 0 1px, transparent 1.6px);
  background-size: 180px 210px, 240px 270px, 210px 190px, 260px 230px;
}

.final-glow {
  position: absolute;
  width: min(90vw, 680px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, #e9bf6725 0, transparent 63%);
  animation: glow-pulse 3.2s ease-in-out infinite;
}

.plane-transition { position: absolute; z-index: 4; left: 50%; top: 50%; width: min(70vw, 440px); opacity: 0; pointer-events: none; transform: translate(-130vw, 28vh) rotate(-12deg) scale(.35); }
.plane-transition img { display: block; width: 100%; filter: drop-shadow(0 15px 28px #000a); }
.finale.is-active .plane-transition { animation: plane-arrive 2.25s cubic-bezier(.22,.8,.28,1) forwards; }

.final-letter {
  position: relative;
  z-index: 3;
  width: min(91vw, 620px);
  padding: clamp(31px, 6vh, 55px) clamp(24px, 7vw, 66px) clamp(28px, 5vh, 46px);
  overflow: hidden;
  border: 1px solid #cda95a66;
  border-radius: 2px 22px 2px 22px;
  color: #352b20;
  background: linear-gradient(155deg, #fffaf0f2, #f0dfc4f5);
  box-shadow: 0 28px 90px #000b, inset 0 0 70px #b38a4230;
  opacity: 0;
  transform: scaleX(.06) scaleY(.16) rotate(-5deg);
  transform-origin: 50% 50%;
}

.final-letter::before { content: ""; position: absolute; inset: 10px; border: 1px solid #99743b2b; border-radius: 1px 15px 1px 15px; pointer-events: none; }
.finale.is-active .final-letter { animation: letter-unfold 1.15s 1.65s cubic-bezier(.2,.75,.25,1) forwards; }
.final-dear { position: relative; margin: 0 0 clamp(22px, 4vh, 34px); color: #71542d; font-size: clamp(18px, 4.5vw, 25px); font-style: italic; letter-spacing: .04em; opacity: 0; }
.final-wishes { position: relative; }
.final-wishes p { margin: 0 0 8px; font-family: "Songti SC", "STSong", serif; font-size: clamp(16px, 4vw, 21px); line-height: 1.72; letter-spacing: .035em; opacity: 0; }
.final-letter h1 { position: relative; margin: clamp(26px, 4.5vh, 38px) 0 0; color: #8a5228; font-family: "Songti SC", "STSong", serif; font-size: clamp(24px, 6.4vw, 38px); font-weight: 600; letter-spacing: .08em; text-indent: .08em; opacity: 0; }
.signature { position: relative; margin: 20px 0 0; color: #8a6335; font-size: 16px; font-style: italic; letter-spacing: .12em; text-align: right; opacity: 0; }
.finale.is-active .final-dear { animation: ink-in .75s 2.85s ease forwards; }
.finale.is-active .final-wishes p:nth-child(1) { animation: ink-in .7s 3.15s ease forwards; }
.finale.is-active .final-wishes p:nth-child(2) { animation: ink-in .7s 3.43s ease forwards; }
.finale.is-active .final-wishes p:nth-child(3) { animation: ink-in .7s 3.71s ease forwards; }
.finale.is-active .final-wishes p:nth-child(4) { animation: ink-in .7s 3.99s ease forwards; }
.finale.is-active .final-letter h1 { animation: ink-in .9s 4.45s ease forwards; }
.finale.is-active .signature { animation: ink-in .8s 4.9s ease forwards; }

.replay-button {
  position: absolute;
  z-index: 2;
  bottom: max(26px, env(safe-area-inset-bottom));
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: #b2aa98;
  font-size: 13px;
  letter-spacing: .14em;
  opacity: 0;
}

.finale.is-active .replay-button { animation: final-in .8s 5.5s ease forwards; }

.music-toggle {
  position: fixed;
  z-index: 20;
  top: max(18px, env(safe-area-inset-top));
  right: max(18px, env(safe-area-inset-right));
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid #f2d69b52;
  border-radius: 50%;
  color: #f7dda6;
  background: #06110ed1;
  box-shadow: 0 10px 28px #0008, inset 0 0 18px #f4d28b0a;
  backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity .6s ease, visibility .6s, transform .6s ease, border-color .25s ease;
}

.music-toggle.is-visible { opacity: .82; visibility: visible; transform: none; }
.music-toggle:hover { opacity: 1; border-color: #f2d69ba3; }
.music-toggle span { display: block; font-size: 19px; line-height: 1; }
.music-toggle.is-playing span { animation: music-pulse 1.25s ease-in-out infinite; }
.music-toggle:not(.is-playing)::after { content: ""; position: absolute; left: 8px; right: 8px; top: 20px; height: 1px; background: currentColor; transform: rotate(-45deg); opacity: .82; }

.blessing-confetti { position: absolute; inset: 0; z-index: 2; overflow: hidden; pointer-events: none; }
.blessing-confetti span { position: absolute; left: 50%; top: 50%; color: #f7d98e; font-size: clamp(15px, 4vw, 24px); font-style: italic; opacity: 0; text-shadow: 0 0 12px #ffc957; }
.finale.is-active .blessing-confetti span { animation: confetti-bloom 3.6s 1.9s ease-out infinite; }
.blessing-confetti span:nth-child(1) { --x:-43vw; --y:-32vh; animation-delay:1.85s!important; }
.blessing-confetti span:nth-child(2) { --x:-26vw; --y:-40vh; animation-delay:2.05s!important; }
.blessing-confetti span:nth-child(3) { --x:3vw; --y:-44vh; animation-delay:2.25s!important; }
.blessing-confetti span:nth-child(4) { --x:35vw; --y:-34vh; animation-delay:2.45s!important; }
.blessing-confetti span:nth-child(5) { --x:45vw; --y:-5vh; animation-delay:2.65s!important; }
.blessing-confetti span:nth-child(6) { --x:39vw; --y:31vh; animation-delay:2.85s!important; }
.blessing-confetti span:nth-child(7) { --x:8vw; --y:42vh; animation-delay:3.05s!important; }
.blessing-confetti span:nth-child(8) { --x:-28vw; --y:38vh; animation-delay:3.25s!important; }
.blessing-confetti span:nth-child(9) { --x:-44vw; --y:13vh; animation-delay:3.45s!important; }
.blessing-confetti span:nth-child(10) { --x:27vw; --y:40vh; animation-delay:3.65s!important; }

@keyframes soft-arrive { from { opacity: 0; filter: blur(5px); transform: translateY(8px); } }
@keyframes button-breathe { 50% { box-shadow: 0 18px 62px #000, 0 0 28px #f1cc7626, inset 0 0 28px #f7d9990c; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes float { to { transform: translate3d(8px, -17px, 0) rotate(4deg); opacity: .35; } }
@keyframes whisper-drift { to { transform: translate3d(12px, -15px, 0); opacity: .32; } }
@keyframes glow-pulse { 50% { transform: scale(1.08); opacity: .72; } }
@keyframes final-in { from { opacity: 0; filter: blur(7px); transform: translateY(14px); } to { opacity: 1; filter: blur(0); transform: none; } }
@keyframes plane-arrive { 0% { opacity: 0; transform: translate(-130vw, 28vh) rotate(-12deg) scale(.35); } 18% { opacity: 1; } 70% { opacity: 1; transform: translate(-50%, -50%) rotate(2deg) scale(.78); } 100% { opacity: 0; transform: translate(-50%, -50%) rotate(0) scale(1.03); filter: blur(2px); } }
@keyframes letter-unfold { 0% { opacity: 0; transform: scaleX(.06) scaleY(.16) rotate(-5deg); } 38% { opacity: 1; transform: scaleX(.16) scaleY(.72) rotate(-2deg); } 72% { transform: scaleX(1.02) scaleY(.84) rotate(.5deg); } 100% { opacity: 1; transform: scale(1) rotate(0); } }
@keyframes ink-in { from { opacity: 0; transform: translateY(8px); filter: blur(3px); } to { opacity: 1; transform: none; filter: blur(0); } }
@keyframes confetti-bloom { 0% { opacity: 0; transform: translate(0,0) scale(.45) rotate(0); } 22% { opacity: .85; } 72%,100% { opacity: 0; transform: translate(var(--x),var(--y)) scale(1.25) rotate(95deg); } }
@keyframes music-pulse { 50% { transform: scale(1.14); text-shadow: 0 0 12px #ffd47d; } }

@media (max-width: 600px) {
  .letter-backdrop { background-position: 55% center; }
  .message-card { padding-block: 27px; }
  .message-line { margin-bottom: 2px; }
  .floating-letters span:nth-child(3), .floating-letters span:nth-child(4) { display: none; }
  .final-letter { padding-inline: 23px; }
}

@media (max-height: 700px) {
  .message-card { padding-block: 18px; }
  .message-line { font-size: clamp(14px, 3.5vw, 19px); line-height: 1.35; }
  .message-space { height: 5px; }
  .chinese-message { margin-top: 12px; padding-top: 10px; }
  .chinese-message p { font-size: 14px; line-height: 1.45; }
  .continue-button { min-height: 42px; margin-top: 14px; }
  .final-letter { padding-block: 23px 20px; }
  .final-dear { margin-bottom: 14px; }
  .final-wishes p { margin-bottom: 3px; line-height: 1.5; }
  .final-letter h1 { margin-top: 17px; }
  .signature { margin-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}
