@import url("https://fonts.googleapis.com/css2?family=Long+Cang&family=Ma+Shan+Zheng&display=swap");

:root {
  --cream: #fff9f2;
  --cream-deep: #f7eadb;
  --peach: #eeb59f;
  --peach-deep: #d99079;
  --gold: #d4a574;
  --ink: #7e6043;
  --paper: #fffdf9;
  --shadow: rgba(125, 86, 53, 0.17);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background: var(--cream);
  color: var(--ink);
  font-family: "Long Cang", "STKaiti", "KaiTi", cursive;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100svh;
  background:
    radial-gradient(circle at 50% 15%, rgba(255, 255, 255, 0.95), transparent 31rem),
    radial-gradient(circle at 13% 82%, rgba(238, 181, 159, 0.1), transparent 22rem),
    linear-gradient(180deg, var(--cream-deep), var(--cream) 24%, var(--cream) 75%, var(--cream-deep));
}

button { border: 0; font: inherit; }

.card-scene {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 100svh;
  padding: clamp(0.75rem, 2.4vw, 1.5rem);
  isolation: isolate;
  overflow: hidden;
}

.card-scene::before,
.card-scene::after {
  content: "";
  position: fixed;
  width: 18rem;
  aspect-ratio: 1;
  border: 1px solid rgba(212, 165, 116, 0.12);
  border-radius: 50%;
  pointer-events: none;
}

.card-scene::before { top: -11rem; left: -9rem; box-shadow: 0 0 0 2.8rem rgba(212,165,116,.025); }
.card-scene::after { right: -10rem; bottom: -12rem; box-shadow: 0 0 0 3.8rem rgba(238,181,159,.025); }

.stage {
  position: relative;
  display: grid;
  place-items: center;
  width: min(100%, 48rem);
  min-height: calc(100svh - clamp(1.5rem, 4.8vw, 3rem));
}

.intro {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(.7rem, 2vw, 1.15rem);
}

.is-opened .intro {
  animation: intro-away .52s ease 1.72s both;
  pointer-events: none;
}

.envelope-button {
  width: clamp(17rem, 72vw, 28rem);
  aspect-ratio: 1.43;
  padding: 0;
  background: transparent;
  cursor: pointer;
  perspective: 1100px;
  filter: drop-shadow(0 1.25rem 1.4rem rgba(125, 86, 53, .16));
  touch-action: manipulation;
  transition: transform .25s ease;
}

.envelope-button:hover:not(:disabled) { transform: translateY(-.28rem) scale(1.01); }
.envelope-button:focus-visible,
.voice-button:focus-visible { outline: .18rem solid rgba(212,165,116,.8); outline-offset: .4rem; }

.envelope-card { position: relative; display: block; width: 100%; height: 100%; transform-style: preserve-3d; }

.envelope-back,
.envelope-front,
.envelope-flap,
.envelope-letter { position: absolute; display: block; }

.envelope-back {
  inset: 19% 4% 2%;
  border: 3px solid var(--gold);
  border-radius: 1.1rem;
  background: #fbf0e4;
}

.envelope-letter {
  inset: 21% 9% 14%;
  border-radius: .75rem;
  background: var(--paper);
  box-shadow: 0 0 0 1px rgba(212,165,116,.18);
}

.envelope-front {
  inset: 19% 4% 2%;
  z-index: 3;
  overflow: hidden;
  border: 3px solid var(--gold);
  border-radius: 1.1rem;
  background:
    linear-gradient(145deg, transparent 49.5%, rgba(212,165,116,.9) 50%, transparent 50.8%) left / 51% 100% no-repeat,
    linear-gradient(215deg, transparent 49.5%, rgba(212,165,116,.9) 50%, transparent 50.8%) right / 51% 100% no-repeat,
    linear-gradient(145deg, transparent 49%, #fffdf9 49.4%) left / 51% 100% no-repeat,
    linear-gradient(215deg, transparent 49%, #fffdf9 49.4%) right / 51% 100% no-repeat;
}

.envelope-flap {
  left: 4%;
  right: 4%;
  top: 18.8%;
  height: 55%;
  z-index: 4;
  clip-path: polygon(0 0, 44% 0, 50% 3%, 56% 0, 100% 0, 50% 84%);
  background: linear-gradient(180deg, #fffdf9, #fdf4e9);
  border-top: 3px solid var(--gold);
  transform-origin: 50% 0;
  backface-visibility: hidden;
}

.is-opened .envelope-flap { animation: flap-open 1s cubic-bezier(.45,0,.22,1) .08s both; }

.recipient {
  position: absolute;
  z-index: 5;
  top: 46%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--ink);
  font-family: "Ma Shan Zheng", "STKaiti", cursive;
  font-size: clamp(1.7rem, 6vw, 2.45rem);
  white-space: nowrap;
}

.wax-seal {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 61%;
  display: grid;
  place-items: center;
  width: clamp(3.3rem, 11vw, 4rem);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: .26rem solid var(--gold);
  border-radius: 50%;
  background: var(--peach);
  color: #fffaf4;
  font-family: Georgia, serif;
  font-size: 1.42rem;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.28);
}

.is-opened .wax-seal { animation: seal-away .32s ease .06s both; }

.hint {
  margin: 0;
  color: rgba(126,96,67,.5);
  font-size: clamp(1.25rem, 4.4vw, 1.9rem);
  animation: hint-breathe 1.5s ease-in-out infinite alternate;
}

.light-pulse {
  position: absolute;
  z-index: 8;
  top: 50%;
  left: 50%;
  width: clamp(10rem, 43vw, 18rem);
  aspect-ratio: 1;
  opacity: 0;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0 10%, rgba(255,255,255,.74) 30%, transparent 70%);
  transform: translate(-50%,-50%) scale(.5);
  mix-blend-mode: screen;
  pointer-events: none;
}

.is-opened .light-pulse { animation: light-burst .58s ease-out .58s both; }

.petal-layer { position: absolute; inset: 0; z-index: 9; pointer-events: none; }

.petal {
  --petal-x: 0px;
  --petal-y: -250px;
  --petal-r: 180deg;
  --petal-s: 1;
  --petal-delay: .8s;
  position: absolute;
  top: 51%;
  left: 50%;
  width: clamp(.72rem, 2.2vw, 1.25rem);
  height: clamp(1rem, 3vw, 1.75rem);
  opacity: 0;
  border-radius: 85% 12% 82% 14%;
  background: var(--peach);
  transform: translate(-50%,-50%) rotate(45deg) scale(.5);
  filter: drop-shadow(0 .15rem .12rem rgba(125,86,53,.09));
}

.petal-2 { background: #f8d1b5; border-radius: 60% 20% 70% 28%; }
.petal-3 { background: #ffe6d6; border-radius: 72% 18% 56% 30%; }
.petal-4 { background: #f3c0c5; border-radius: 50% 16% 82% 20%; }
.is-opened .petal { animation: petal-flight 1.55s cubic-bezier(.18,.75,.22,1) var(--petal-delay) both; }

.reveal {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: calc(100svh - clamp(1.5rem, 4.8vw, 3rem));
  padding: clamp(.7rem, 2vw, 1.25rem) 0;
  pointer-events: none;
}

.is-opened .reveal { pointer-events: auto; }

.title {
  z-index: 3;
  margin: 0 0 clamp(.2rem, 1.2vw, .65rem);
  opacity: 0;
  transform: scale(.8);
  color: var(--ink);
  font-family: "Ma Shan Zheng", "STKaiti", cursive;
  font-size: clamp(2.15rem, 7vw, 3.55rem);
  font-weight: 400;
  line-height: 1.1;
  text-align: center;
  letter-spacing: .04em;
}

.is-opened .title { animation: title-in .62s cubic-bezier(.2,1.35,.5,1) 2.55s both; }

.avatar-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: min(86vw, 25rem);
  height: clamp(17rem, 45svh, 22.8rem);
  margin: 0 auto clamp(.2rem, 1vw, .55rem);
}

.magic-circle {
  position: absolute;
  left: 50%;
  bottom: .6rem;
  z-index: 0;
  width: min(76vw, 22rem);
  aspect-ratio: 1;
  opacity: 0;
  transform: translateX(-50%) scale(.65) rotate(0deg);
  border: 2px solid rgba(212,165,116,.68);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(238,181,159,.25), rgba(212,165,116,.08) 52%, transparent 69%);
  box-shadow: 0 0 2.4rem rgba(238,181,159,.32), inset 0 0 1.1rem rgba(212,165,116,.14);
}

.magic-circle::before,
.magic-circle::after,
.magic-orbit { content: ""; position: absolute; border: 1.5px solid rgba(212,165,116,.54); border-radius: 50%; }
.magic-circle::before { inset: 12%; }
.magic-circle::after { inset: 26%; }
.magic-orbit { inset: 5% 31%; border-radius: 50%; transform: rotate(45deg); }
.orbit-b { transform: rotate(-45deg); }
.orbit-c { inset: 31% 5%; }
.spark { position: absolute; color: var(--gold); font-family: Georgia, serif; font-size: 1.35rem; }
.spark-a { top: -4%; left: 48%; }
.spark-b { right: -2%; top: 43%; }
.spark-c { bottom: -4%; left: 48%; }
.spark-d { left: -1%; top: 43%; font-size: 2.2rem; }

.is-opened .magic-circle { animation: magic-rise .72s ease-out 1.15s both, magic-spin 22s linear 1.88s infinite; }

.portrait-shell {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: clamp(11.8rem, 35vw, 16.3rem);
  height: clamp(17rem, 44svh, 22.3rem);
  opacity: 0;
  transform: translateY(9rem) scale(.05) rotateY(-10deg);
  transform-origin: 50% 86%;
  filter: drop-shadow(0 1.15rem 1rem rgba(125,86,53,.16));
}

.teacher-avatar {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  border-radius: 8rem 8rem 3.2rem 3.2rem;
  mix-blend-mode: multiply;
  -webkit-mask-image: linear-gradient(#000 0 90%, transparent 100%);
  mask-image: linear-gradient(#000 0 90%, transparent 100%);
}

.is-opened .portrait-shell {
  animation: portrait-rise 1.24s cubic-bezier(.2,1.25,.35,1) 1.32s both,
    portrait-float 2.4s ease-in-out 2.62s infinite alternate;
}

.blessing {
  z-index: 3;
  width: min(100%, 32rem);
  margin: 0;
  padding: 0 clamp(.7rem, 4vw, 1.2rem);
  opacity: 0;
  transform: translateY(.65rem);
  color: var(--ink);
  font-size: clamp(1.03rem, 3.4vw, 1.34rem);
  line-height: 1.72;
  text-align: center;
}

.blessing span { display: inline-block; margin-top: .08rem; }
.is-opened .blessing { animation: copy-in .82s ease-out 3.3s both; }

.voice-button {
  z-index: 4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  min-width: 10.3rem;
  min-height: 3.25rem;
  margin-top: clamp(.58rem, 2vw, .95rem);
  padding: .62rem 1.05rem;
  opacity: 0;
  transform: scale(.55);
  border: 1px solid rgba(255,255,255,.68);
  border-radius: 999px;
  background: linear-gradient(135deg, var(--peach), var(--peach-deep));
  color: #fff;
  box-shadow: 0 .65rem 1.35rem rgba(125,86,53,.17), inset 0 0 0 1px rgba(255,255,255,.22);
  font-size: clamp(1rem, 3.3vw, 1.17rem);
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.voice-button:disabled { cursor: default; }
.voice-icon { font-family: system-ui, sans-serif; font-size: 1rem; }
.is-opened .voice-button { animation: voice-in .52s cubic-bezier(.2,1.5,.45,1) 4.08s both, voice-pulse 1.7s ease-in-out 4.7s infinite alternate; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

@keyframes hint-breathe { to { opacity: .9; transform: translateY(-.2rem); } }
@keyframes intro-away { to { opacity: 0; visibility: hidden; } }
@keyframes flap-open { to { transform: rotateX(178deg); opacity: .6; } }
@keyframes seal-away { to { transform: translate(-50%,-50%) scale(.55); opacity: 0; } }
@keyframes light-burst { 0% { opacity: 1; transform: translate(-50%,-50%) scale(.45); } 100% { opacity: 0; transform: translate(-50%,-50%) scale(2.2); } }
@keyframes petal-flight {
  0% { opacity: 0; transform: translate(-50%,-50%) rotate(45deg) scale(.35); }
  10% { opacity: 1; }
  72% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--petal-x)), calc(-50% + var(--petal-y))) rotate(var(--petal-r)) scale(var(--petal-s)); }
}
@keyframes title-in { to { opacity: 1; transform: scale(1); } }
@keyframes magic-rise { to { opacity: .72; transform: translateX(-50%) scale(1) rotate(16deg); } }
@keyframes magic-spin { from { transform: translateX(-50%) scale(1) rotate(16deg); } to { transform: translateX(-50%) scale(1) rotate(376deg); } }
@keyframes portrait-rise {
  0% { opacity: 0; transform: translateY(9rem) scale(.05) rotateY(-10deg); }
  62% { opacity: 1; transform: translateY(-.5rem) scale(1.035) rotateY(8deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotateY(0); }
}
@keyframes portrait-float { to { transform: translateY(.32rem) scale(1); } }
@keyframes copy-in { to { opacity: 1; transform: translateY(0); } }
@keyframes voice-in { to { opacity: 1; transform: scale(1); } }
@keyframes voice-pulse { to { transform: scale(1.035); box-shadow: 0 .85rem 1.7rem rgba(125,86,53,.2), 0 0 0 .35rem rgba(238,181,159,.08); } }

@media (max-height: 720px) and (min-width: 560px) {
  .title { font-size: 2.65rem; }
  .avatar-wrap { height: 18rem; }
  .portrait-shell { width: 12.6rem; height: 17.7rem; }
  .magic-circle { width: 18rem; }
  .blessing { font-size: 1.08rem; line-height: 1.52; }
  .voice-button { min-height: 2.8rem; margin-top: .45rem; }
}

@media (max-width: 420px) {
  .card-scene { padding: .55rem; }
  .stage, .reveal { min-height: calc(100svh - 1.1rem); }
  .title { margin-bottom: .1rem; }
  .avatar-wrap { width: 92vw; }
  .blessing { line-height: 1.62; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
