:root {
  --night: #070b16;
  --night-deep: #0c1224;
  --night-soft: #151d35;
  /* 更亮、更暖的月光色（偏米金，少一点冷蓝） */
  --moon: #f4ecdf;
  --moon-dim: #cbbba3;
  --gold: #d4b07a;
  --gold-soft: rgba(212, 176, 122, 0.42);
  --paper: #f0e6d4;
  --paper-edge: #e2d3b8;
  --ink: #2a241c;
  --ink-soft: #5c5348;
  --font-display: "Ma Shan Zheng", cursive;
  --font-serif: "Noto Serif SC", serif;
  --font-latin: "Cormorant Garamond", serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* 防止 .letter-wrap / .finale 的 display:flex 盖掉 hidden */
[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-serif);
  color: var(--moon);
  background: var(--night);
  overflow-x: hidden;
  line-height: 1.75;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body.is-opening {
  overflow: hidden;
  touch-action: none;
}

#stars {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.night-veil {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(90, 120, 180, 0.18), transparent 55%),
    radial-gradient(ellipse 60% 40% at 80% 90%, rgba(40, 55, 100, 0.25), transparent 50%),
    linear-gradient(180deg, transparent 0%, rgba(7, 11, 22, 0.35) 100%);
}

.hero,
.memories,
.letter-wrap,
.finale {
  position: relative;
  z-index: 2;
}

/* —— Music toggle —— */
.music-toggle {
  position: fixed;
  top: calc(0.85rem + env(safe-area-inset-top, 0px));
  right: calc(0.85rem + env(safe-area-inset-right, 0px));
  z-index: 20;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(196, 165, 116, 0.4);
  background: rgba(10, 16, 32, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--gold);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
  -webkit-appearance: none;
  appearance: none;
}

.music-toggle:hover,
.music-toggle:focus-visible {
  background: rgba(196, 165, 116, 0.14);
  box-shadow: 0 0 18px rgba(196, 165, 116, 0.22);
  outline: none;
}

.music-icon {
  width: 20px;
  height: 20px;
  display: none;
  overflow: visible;
}

.music-toggle.is-playing .music-icon--on {
  display: block;
  animation: music-beat 1.2s ease-in-out infinite;
}

.music-toggle.is-muted .music-icon--off,
.music-toggle:not(.is-playing) .music-icon--off {
  display: block;
}

.music-toggle.is-playing:not(.is-muted) .music-icon--off {
  display: none;
}

.music-toggle.is-muted {
  color: var(--moon-dim);
  border-color: rgba(154, 168, 194, 0.35);
}

.music-toggle.is-playing:not(.is-muted) {
  color: var(--gold);
  border-color: rgba(196, 165, 116, 0.5);
}

@keyframes music-beat {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.06);
  }
}

/* —— Hero —— */
.hero {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding:
    calc(2rem + env(safe-area-inset-top, 0px))
    calc(1.25rem + env(safe-area-inset-right, 0px))
    calc(2.5rem + env(safe-area-inset-bottom, 0px))
    calc(1.25rem + env(safe-area-inset-left, 0px));
  gap: 0.4rem;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

.hero-copy {
  position: relative;
  z-index: 3;
}

.hero-eyebrow {
  font-family: var(--font-latin);
  font-style: italic;
  font-size: clamp(0.95rem, 2.2vw, 1.15rem);
  letter-spacing: 0.18em;
  color: var(--moon-dim);
  text-transform: none;
  opacity: 0;
  animation: rise 1.4s ease 0.35s forwards;
}

.hero-name {
  font-family: var(--font-display);
  font-size: clamp(3.8rem, 16vw, 7.5rem);
  font-weight: 400;
  line-height: 1.05;
  margin: 0.2em 0 0.15em;
  color: var(--moon);
  text-shadow: 0 0 40px rgba(244, 220, 180, 0.28);
  opacity: 0;
  animation: rise-glow 1.7s ease 0.55s forwards;
}

.hero-line {
  max-width: 22em;
  margin: 0 auto;
  font-size: clamp(0.92rem, 2.4vw, 1.1rem);
  color: var(--moon-dim);
  font-weight: 400;
  opacity: 0;
  animation: rise 1.4s ease 0.9s forwards;
}

/* —— Envelope —— */
.envelope-scene {
  position: relative;
  z-index: 4;
  margin-top: 1.4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0;
  transform: translateY(36px) scale(0.92);
  animation: envelope-enter 1.2s cubic-bezier(0.22, 1, 0.36, 1) 1.2s forwards;
}

.env-hint {
  margin-top: 1.1rem;
  font-size: 0.86rem;
  letter-spacing: 0.18em;
  color: var(--moon-dim);
  animation: hint-pulse 2.4s ease-in-out 2.2s infinite;
}

.envelope {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  position: relative;
  width: min(280px, 72vw);
  height: 180px;
  perspective: 1200px;
  transform-style: preserve-3d;
  padding: 0;
  filter: drop-shadow(0 18px 28px rgba(0, 0, 0, 0.45));
  transition: transform 0.45s ease;
}

.envelope:hover {
  transform: translateY(-6px) rotateX(4deg);
}

.envelope:focus-visible {
  outline: 1px solid var(--gold-soft);
  outline-offset: 10px;
}

.env-shadow {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -14px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.45), transparent 70%);
  filter: blur(4px);
}

.env-body {
  position: absolute;
  inset: 36px 0 0;
  background:
    linear-gradient(160deg, #d7c4a0 0%, #c4a878 45%, #a88b5c 100%);
  border-radius: 0 0 10px 10px;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
  z-index: 2;
}

.env-body::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background:
    linear-gradient(135deg, transparent 49%, rgba(90, 65, 35, 0.22) 50%, transparent 51%),
    linear-gradient(45deg, transparent 49%, rgba(90, 65, 35, 0.22) 50%, transparent 51%);
  transition: opacity 0.5s ease;
}

.envelope.is-opening .env-body::before {
  opacity: 0.9;
}

.env-inner {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 248, 230, 0.12), transparent 40%);
}

.env-flap {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 92px;
  transform-origin: top center;
  transform: rotateX(0deg);
  transform-style: preserve-3d;
  z-index: 4;
  transition: transform 1.15s cubic-bezier(0.33, 0.1, 0.2, 1);
}

.env-flap-front,
.env-flap-back {
  position: absolute;
  inset: 0;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.env-flap-front {
  background: linear-gradient(180deg, #e8d6b4 0%, #c9ae7f 100%);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22);
}

.env-flap-front::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 55%);
  clip-path: inherit;
}

.env-flap-back {
  background: linear-gradient(180deg, #8f7350 0%, #6f5740 100%);
  transform: rotateX(180deg);
  box-shadow: inset 0 8px 16px rgba(0, 0, 0, 0.25);
}

.env-seal {
  position: absolute;
  left: 50%;
  top: 58px;
  width: 46px;
  height: 46px;
  margin-left: -23px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #e8b070, #b06a3a 55%, #8a4e28 100%);
  box-shadow:
    0 0 0 3px rgba(196, 165, 116, 0.35),
    0 6px 14px rgba(0, 0, 0, 0.35),
    inset 0 2px 0 rgba(255, 230, 190, 0.35);
  z-index: 5;
  display: grid;
  place-items: center;
  transition: opacity 0.4s ease, transform 0.7s cubic-bezier(0.34, 1.4, 0.64, 1);
  animation: seal-glow 2.8s ease-in-out infinite;
}

.env-seal em {
  font-style: normal;
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: #fff4e4;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(80, 40, 10, 0.35);
}

.env-letter {
  position: absolute;
  left: 50%;
  top: 48px;
  width: 78%;
  height: 120px;
  margin-left: -39%;
  background:
    linear-gradient(180deg, #fffaf0, #f3e6d0);
  border-radius: 4px;
  z-index: 1;
  transform: translateY(28px) scale(0.96);
  transition:
    transform 1.15s cubic-bezier(0.22, 1, 0.36, 1) 0.42s,
    box-shadow 1.15s ease 0.42s;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  color: #5a4a38;
}

.env-letter-lines {
  width: 70%;
  height: 28px;
  background:
    linear-gradient(#d7c8b0, #d7c8b0) 0 4px / 100% 2px no-repeat,
    linear-gradient(#d7c8b0, #d7c8b0) 0 14px / 100% 2px no-repeat,
    linear-gradient(#d7c8b0, #d7c8b0) 0 24px / 78% 2px no-repeat;
  opacity: 0.85;
}

.env-letter-heart {
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: 0.12em;
  color: #7a5a38;
}

/* Opening states */
.envelope.is-opening {
  pointer-events: none;
  animation: none;
  transform: translateY(4px) scale(0.985);
}

.envelope.is-opening .env-body {
  transform: translateY(3px);
  transition: transform 0.8s ease;
}

.envelope.is-opening .env-shadow {
  opacity: 0.7;
  transform: scaleX(1.06);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

.envelope.is-opening .env-flap {
  transform: rotateX(175deg);
  z-index: 0;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.35));
}

.envelope.is-opening .env-seal {
  opacity: 0;
  transform: scale(0.35) translateY(18px) rotate(18deg);
  animation: none;
}

.envelope.is-opening .env-letter {
  transform: translateY(-96px) scale(1.04) rotate(-1.5deg);
  z-index: 3;
  box-shadow:
    0 18px 36px rgba(0, 0, 0, 0.35),
    0 0 28px rgba(240, 220, 180, 0.25);
}

.envelope-scene.is-done {
  opacity: 0;
  transform: scale(1.05) translateY(-20px);
  transition: opacity 0.7s ease, transform 0.7s ease;
  pointer-events: none;
}

body.is-opened .hero-copy {
  transition: opacity 0.8s ease, transform 0.8s ease;
}

body.is-opened .env-hint {
  opacity: 0;
  animation: none;
  height: 0;
  margin: 0;
  overflow: hidden;
}

body.is-opened .envelope-scene {
  height: 0;
  margin: 0;
  overflow: hidden;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes rise-glow {
  from {
    opacity: 0;
    transform: translateY(22px);
    text-shadow: 0 0 0 rgba(244, 220, 180, 0);
  }
  to {
    opacity: 1;
    transform: translateY(0);
    text-shadow: 0 0 40px rgba(244, 220, 180, 0.32);
  }
}

@keyframes envelope-enter {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes seal-glow {
  0%,
  100% {
    box-shadow:
      0 0 0 3px rgba(196, 165, 116, 0.28),
      0 6px 14px rgba(0, 0, 0, 0.35),
      0 0 12px rgba(220, 150, 80, 0.25);
  }
  50% {
    box-shadow:
      0 0 0 4px rgba(196, 165, 116, 0.45),
      0 6px 14px rgba(0, 0, 0, 0.35),
      0 0 22px rgba(240, 180, 100, 0.55);
  }
}

@keyframes hint-pulse {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

/* —— Memories —— */
.memories {
  padding: 4rem 1.25rem 2rem;
  max-width: 920px;
  margin: 0 auto;
}

.section-head {
  text-align: center;
  margin-bottom: 3.5rem;
}

.section-head h2 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 6vw, 2.8rem);
  font-weight: 400;
  color: var(--moon);
  margin-bottom: 0.6rem;
}

.section-head p {
  color: var(--moon-dim);
  font-size: 0.95rem;
}

.memory {
  display: grid;
  gap: 1.25rem;
  margin-bottom: 4.5rem;
  align-items: center;
}

@media (min-width: 768px) {
  .memory {
    grid-template-columns: 1.15fr 0.85fr;
    gap: 2.5rem;
    margin-bottom: 5.5rem;
  }

  .memory--flip .photo-frame {
    order: 2;
  }

  .memory--flip figcaption {
    order: 1;
    text-align: right;
  }

  .memory--flip .memory-num {
    margin-left: auto;
  }
}

.photo-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 5;
  background: var(--night-soft);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  will-change: transform;
  transform: translate3d(0, var(--frame-y, 0px), 0);
  transition: transform 0.15s linear;
}

.photo-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 1px rgba(215, 224, 240, 0.08);
  pointer-events: none;
  z-index: 1;
}

.photo-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: saturate(0.92) contrast(1.02);
  transform: translate3d(0, var(--img-y, 0px), 0) scale(1.12);
  will-change: transform;
  transition: transform 0.15s linear;
}

.memory:hover .photo-frame img {
  transform: translate3d(0, var(--img-y, 0px), 0) scale(1.16);
}

.photo-frame img.is-placeholder {
  object-fit: cover;
}

figcaption {
  padding: 0.25rem 0.15rem;
  transform: translate3d(0, var(--cap-y, 0px), 0);
  transition: transform 0.15s linear;
  will-change: transform;
}

.memory-num {
  display: block;
  font-family: var(--font-latin);
  font-style: italic;
  font-size: 1.35rem;
  color: var(--gold);
  letter-spacing: 0.08em;
  margin-bottom: 0.55rem;
}

figcaption p {
  color: var(--moon-dim);
  font-size: 1.02rem;
  max-width: 18em;
}

.memory--flip figcaption p {
  margin-left: auto;
}

/* —— Letter —— */
.letter-wrap {
  padding: 2rem 1.25rem 4rem;
  display: flex;
  justify-content: center;
}

.letter {
  width: min(560px, 100%);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 28%),
    var(--paper);
  color: var(--ink);
  padding: clamp(2rem, 5vw, 3rem) clamp(1.4rem, 4vw, 2.4rem) 2.6rem;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.35) inset,
    0 25px 60px rgba(0, 0, 0, 0.45);
  position: relative;
  transform: rotate(-0.4deg);
}

.letter::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(42, 36, 28, 0.08);
  pointer-events: none;
}

.letter-date {
  font-family: var(--font-latin);
  font-style: italic;
  color: var(--ink-soft);
  font-size: 0.95rem;
  margin-bottom: 1.4rem;
}

.letter-to {
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 5vw, 2.2rem);
  font-weight: 400;
  margin-bottom: 1.2rem;
  color: var(--ink);
}

.letter-body p {
  margin-bottom: 1.05rem;
  font-size: 1.02rem;
  text-indent: 2em;
  color: var(--ink);
}

.letter-body p.is-typing,
.letter-body p.is-visible {
  opacity: 1;
}

.letter-sign {
  margin-top: 2rem;
  text-align: right;
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: var(--ink-soft);
}

/* —— Finale / Cake —— */
.finale {
  min-height: 92vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.25rem 5rem;
  text-align: center;
}

.cake-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  width: min(440px, 100%);
}

.cake-stage.is-in .cake {
  animation: cake-rise 1.1s cubic-bezier(0.22, 1, 0.36, 1) both,
    cake-bob 4.8s ease-in-out 1.1s infinite;
}

.cake-stage.is-in .cake.is-blown {
  animation: cake-rise 1.1s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.finale-hint {
  color: var(--moon-dim);
  font-size: 0.95rem;
  letter-spacing: 0.12em;
  min-height: 1.5em;
  transition: opacity 0.5s ease;
}

.finale-wish {
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 4vw, 1.85rem);
  color: var(--moon);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.8s ease, transform 0.8s ease;
  max-width: 16em;
  text-wrap: balance; /* 避免换行后只剩「真。」这样的孤字 */
}

.finale-wish.show {
  opacity: 1;
  transform: translateY(0);
}

.finale-name {
  margin-top: 0.25rem;
  font-family: var(--font-latin);
  font-style: italic;
  letter-spacing: 0.16em;
  color: var(--gold);
  font-size: 1.05rem;
}

.cake {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  position: relative;
  width: 300px;
  height: 340px;
  margin: 0.4rem 0 0.4rem;
  padding: 0;
  transform-origin: center bottom;
  transition: filter 0.4s ease;
}

.cake:hover {
  filter: brightness(1.04);
}

.cake:focus-visible {
  outline: 1px solid var(--gold-soft);
  outline-offset: 12px;
}

.cake-aura {
  position: absolute;
  left: 50%;
  top: 18%;
  width: 210px;
  height: 210px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 210, 140, 0.22), transparent 68%);
  filter: blur(8px);
  pointer-events: none;
  animation: aura-pulse 3.2s ease-in-out infinite;
  transition: opacity 0.9s ease;
}

.cake.is-blown .cake-aura {
  opacity: 0.25;
  animation: none;
}

/* 盘子底下的一圈落地光。原先在 bottom:18px、alpha 0.55，
   位置正好压住盘子（而且盘子被裁掉时它就顶替成了那团「雾」） */
.cake-glow {
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: 268px;
  height: 40px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse, rgba(210, 180, 120, 0.4), transparent 72%);
  filter: blur(10px);
  pointer-events: none;
  transition: opacity 0.8s ease;
}

.cake.is-blown .cake-glow {
  opacity: 0.3;
}

/* 7 根蜡烛平排 */
.candles {
  position: absolute;
  left: 50%;
  top: 0;
  width: 150px;
  height: 78px;
  transform: translateX(-50%);
  z-index: 8;
  pointer-events: none;
}

.cndl {
  position: absolute;
  bottom: 6px;
  width: 7px;
  height: var(--h, 31px);
  transform: translateX(-50%);
}

.cndl .wx {
  position: absolute;
  inset: 0;
  border-radius: 3.5px 3.5px 2px 2px;
  display: block;
  background: var(--wax, linear-gradient(90deg, #e8d7b0, #f7ecda));
  box-shadow:
    inset -2px 0 3px rgba(0, 0, 0, 0.16),
    inset 2px 0 3px rgba(255, 255, 255, 0.42),
    0 1px 2px rgba(0, 0, 0, 0.18);
}

.cndl .wk {
  position: absolute;
  left: 50%;
  top: -6px;
  width: 1.5px;
  height: 7px;
  margin-left: -0.75px;
  background: #2a241c;
  border-radius: 1px;
  display: block;
}

.cndl .fl {
  position: absolute;
  left: 50%;
  top: -22px;
  width: 10px;
  height: 17px;
  margin-left: -5px;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: radial-gradient(ellipse 62% 72% at 50% 78%, #fffdf6 0%, #ffeab5 30%, #f5b757 56%, #e2701f 80%, rgba(226, 112, 31, 0) 100%);
  box-shadow: 0 0 10px rgba(240, 180, 80, 0.5), 0 0 22px rgba(220, 120, 40, 0.26);
  animation: flicker 2.1s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
  transform-origin: center bottom;
  display: block;
  transition: opacity 0.5s ease, transform 0.5s ease, filter 0.5s ease;
  transition-delay: var(--out-delay, 0s);
}

/* 焰心底部的冷色，让火苗不是一团纯橘 */
.cndl .fl::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 6px;
  height: 6px;
  margin-left: -3px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(130, 180, 255, 0.5), transparent 70%);
  filter: blur(1.5px);
}

.cndl .fl::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -3px;
  width: 16px;
  height: 14px;
  margin-left: -8px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 200, 120, 0.4), transparent 70%);
  filter: blur(3px);
  animation: glow-pulse 2.1s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
  pointer-events: none;
}

.cake.is-blown .fl {
  opacity: 0;
  transform: scale(0.1) translateY(8px);
  animation: none;
  filter: none;
}

.cake.is-blown .fl::after {
  opacity: 0;
  animation: none;
}

/* ── 蛋糕分层 ──
   每层由三块拼成：椭圆顶面 (.tier-face) + 圆柱侧面 (.tier-side) + 垂坠糖霜 (.tier-frost)。
   几何全部由 --rx / --ry / --h / --top 四个变量推出：
   --top 是「顶面椭圆的中心线」的 y 坐标，--rx/--ry 是顶面椭圆半径，--h 是侧面高度。 */

.tier {
  position: absolute;
  left: 50%;
  top: var(--top);
  width: calc(var(--rx) * 2);
  height: calc(var(--h) + var(--ry));
  transform: translateX(-50%);
}

/* 上层压住下层，所以 z-index 从底到顶递增。
   --frost 是糖霜垂坠的颜色，必须等于糖霜带的下缘色，否则接缝会露出来 */
/* --drip-shift 把三层的垂坠图案错开相位，否则三层会出现一模一样的节奏 */
.tier-top  { --rx: 64px;  --ry: 11px; --h: 52px; --top: 78px;  z-index: 5; --drip-shift: 0px;
            --body-a: #ecd2a8; --body-b: #cfa473; --frost: #f7ebd6; }
.tier-mid  { --rx: 91px;  --ry: 15px; --h: 58px; --top: 136px; z-index: 4; --drip-shift: 14px;
            --body-a: #e6c99a; --body-b: #c79a63; --frost: #f7ebd6; }
.tier-base { --rx: 120px; --ry: 20px; --h: 62px; --top: 200px; z-index: 3; --drip-shift: 27px;
            --body-a: #e0c08e; --body-b: #bd8d55; --frost: #f7ebd6; }

/* 侧面：底部用椭圆圆角收成弧，和顶面椭圆同半径，拼起来才是圆柱 */
.tier-side {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: calc(var(--h) + var(--ry));
  border-radius: 0 0 50% 50% / 0 0 var(--ry) var(--ry);
  background: linear-gradient(180deg, var(--body-a) 0%, var(--body-b) 100%);
  box-shadow:
    inset -20px 0 26px rgba(74, 46, 20, 0.24),
    inset 20px 0 26px rgba(74, 46, 20, 0.16);
}

/* 顶面：这是「俯视露出来的那圈面」，也是烛光打在蛋糕上的地方 */
.tier-face {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--ry) * -1);
  height: calc(var(--ry) * 2);
  border-radius: 50%;
  background: radial-gradient(ellipse at 42% 32%, #fffdf8 0%, #fdf4e3 48%, #efdec0 100%);
  box-shadow: inset 0 -4px 8px rgba(150, 110, 60, 0.14);
}

/* 糖霜：盖住侧面顶部，颜色刻意比蛋糕体浅一档，否则整层糊成一个色 */
.tier-frost {
  position: absolute;
  left: 1px;
  right: 1px;
  top: 0;
  height: calc(var(--h) * 0.55);
  border-radius: 0 0 50% 50% / 0 0 calc(var(--ry) * 0.8) calc(var(--ry) * 0.8);
  background: linear-gradient(180deg, #fffdf8 0%, var(--frost) 100%);
  box-shadow: 0 2px 5px rgba(120, 85, 40, 0.15);
}

/* 垂坠糖霜：三层不同周期的半圆叠在一起。
   用单层等距半圆会变成「齿轮牙」——必须让周期互质、半径各不相同，
   看起来才是不规则的糖霜往下淌。 */
.tier-frost::after {
  content: "";
  position: absolute;
  left: 1px;
  right: 1px;
  top: 100%;
  height: 15px;
  background-image:
    radial-gradient(circle at 50% 0, var(--frost) 0 10px, transparent 10.5px),
    radial-gradient(circle at 50% 0, var(--frost) 0 7px, transparent 7.5px),
    radial-gradient(circle at 50% 0, var(--frost) 0 4.5px, transparent 5px);
  background-size: 41px 15px, 29px 11px, 17px 8px;
  background-position:
    calc(3px + var(--drip-shift, 0px)) 0,
    calc(11px + var(--drip-shift, 0px)) 0,
    calc(6px + var(--drip-shift, 0px)) 0;
  background-repeat: repeat-x;
}

/* 星星挂在顶层原点（顶面椭圆中心线）之上。原先它在 top:-34px，
   正好落在蜡烛堆里又被 .candles 的 z-index:8 压住，整颗看不见。 */
.star-topper {
  position: absolute;
  left: 50%;
  top: -78px;
  width: 18px;
  height: 18px;
  transform: translateX(-50%) rotate(20deg);
  background: linear-gradient(135deg, #fff6d8, #c9a574);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  filter: drop-shadow(0 0 6px rgba(240, 200, 120, 0.7));
  z-index: 6;
  animation: star-twinkle 2.4s ease-in-out infinite;
}

/* 位置按新的分层几何重新算：中层的可见桶身在糖霜垂坠之下 */
.ribbon {
  position: absolute;
  left: 50%;
  top: 74%;
  transform: translate(-50%, -50%);
  min-width: 72px;
  padding: 0.28rem 0.85rem 0.22rem;
  /* 原来和蛋糕体同色系、亮度也接近，糊在一起；压深到古铜才立得住 */
  background: linear-gradient(180deg, #bf9455, #97703a 55%, #74542a);
  border-radius: 3px;
  box-shadow:
    0 2px 0 rgba(255, 230, 180, 0.35) inset,
    0 4px 10px rgba(0, 0, 0, 0.28);
  z-index: 4;
}

.ribbon::before,
.ribbon::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 14px;
  height: 18px;
  background: #7d5b2d;
  transform: translateY(-50%);
  clip-path: polygon(0 0, 100% 0, 70% 50%, 100% 100%, 0 100%);
}

.ribbon::before {
  left: -12px;
  clip-path: polygon(100% 0, 0 0, 30% 50%, 0 100%, 100% 100%);
}

.ribbon::after {
  right: -12px;
}

.ribbon-text {
  font-family: var(--font-latin);
  font-weight: 600;
  font-size: 1.55rem;
  letter-spacing: 0.08em;
  color: #fff8ec;
  text-shadow: 0 1px 0 rgba(80, 50, 20, 0.35);
  line-height: 1;
}

.name-tag {
  position: absolute;
  left: 50%;
  top: 64%;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-size: 1.55rem;
  color: #4a3016;
  text-shadow: 0 1px 0 rgba(255, 248, 236, 0.6);
  z-index: 4;
  letter-spacing: 0.12em;
}

/* 盘子：改成暖白瓷器。之前是冷灰椭圆，比蛋糕还宽，像浮在空中的 UFO。
   位置跟着新的分层几何走（底座最低点在 y≈282） */
.plate {
  position: absolute;
  left: 50%;
  top: 268px;
  width: 266px;
  height: 28px;
  transform: translateX(-50%);
  background:
    radial-gradient(ellipse at 50% 22%, #f3e7d0 0%, #ddc8a4 48%, #bd9d74 78%, #9c7f57 100%);
  border-radius: 50%;
  box-shadow:
    0 10px 22px rgba(0, 0, 0, 0.42),
    inset 0 2px 0 rgba(255, 255, 255, 0.42),
    inset 0 -3px 7px rgba(96, 64, 26, 0.22);
  z-index: 2;
}

/* 蛋糕落在盘子上的接触阴影，否则底座边缘和盘面糊在一起 */
.plate::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -6px;
  width: 232px;
  height: 20px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(58, 36, 16, 0.5), transparent 72%);
  filter: blur(4px);
}

/* 盘面前缘的高光，让盘子有瓷的厚度。做太亮会变成一道发光的弧 */
.plate-shine {
  position: absolute;
  left: 50%;
  top: 283px;
  width: 168px;
  height: 4px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  border-radius: 50%;
  z-index: 3;
  pointer-events: none;
}

.sparkles {
  position: absolute;
  inset: 6% 0 28%;
  pointer-events: none;
  overflow: visible;
}

.sparkle {
  position: absolute;
  left: 50%;
  top: 36%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f0e2c4;
  opacity: 0;
  box-shadow: 0 0 8px rgba(240, 210, 140, 0.9);
}

.sparkles.is-burst .sparkle {
  animation: spark-burst 1.15s ease-out forwards;
}

@keyframes flicker {
  0%,
  100% {
    transform: scaleY(1) scaleX(1) rotate(-2deg) translateX(0);
    opacity: 1;
    filter: brightness(1);
  }
  18% {
    transform: scaleY(1.08) scaleX(0.92) rotate(3deg) translateX(0.4px);
    opacity: 0.92;
    filter: brightness(1.08);
  }
  36% {
    transform: scaleY(0.9) scaleX(1.1) rotate(-4deg) translateX(-0.5px);
    opacity: 0.85;
    filter: brightness(0.92);
  }
  55% {
    transform: scaleY(1.14) scaleX(0.86) rotate(2deg) translateX(0.3px);
    opacity: 1;
    filter: brightness(1.12);
  }
  72% {
    transform: scaleY(0.95) scaleX(1.05) rotate(-1deg) translateX(-0.2px);
    opacity: 0.94;
    filter: brightness(1);
  }
}

@keyframes glow-pulse {
  0%,
  100% {
    opacity: 0.55;
    transform: scale(1);
  }
  40% {
    opacity: 0.9;
    transform: scale(1.25);
  }
  70% {
    opacity: 0.45;
    transform: scale(0.9);
  }
}

@keyframes cake-rise {
  from {
    opacity: 0.35;
    transform: translateY(36px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes cake-bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-7px);
  }
}

@keyframes aura-pulse {
  0%,
  100% {
    opacity: 0.7;
    transform: translateX(-50%) scale(1);
  }
  50% {
    opacity: 1;
    transform: translateX(-50%) scale(1.06);
  }
}

@keyframes star-twinkle {
  0%,
  100% {
    filter: drop-shadow(0 0 4px rgba(240, 200, 120, 0.5));
    transform: translateX(-50%) rotate(20deg) scale(1);
  }
  50% {
    filter: drop-shadow(0 0 10px rgba(255, 230, 160, 0.95));
    transform: translateX(-50%) rotate(20deg) scale(1.12);
  }
}

@keyframes spark-burst {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--tx), var(--ty)) scale(0.25);
  }
}

/* —— Reveal —— */
[data-reveal] {
  opacity: 0;
  transform: translateY(28px);
  transition: opacity 0.9s ease, transform 0.9s ease;
}

[data-reveal].is-in {
  opacity: 1;
  transform: translateY(0);
}

body.is-opened .hero {
  min-height: auto;
  padding-top: 18vh;
  padding-bottom: 12vh;
  transition: padding 0.8s ease;
}

/* —— Mobile —— */
@media (max-width: 767px) {
  .hero {
    justify-content: flex-start;
    padding-top: calc(4.5rem + env(safe-area-inset-top, 0px));
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
    gap: 0.2rem;
  }

  .hero-eyebrow {
    font-size: 0.88rem;
    letter-spacing: 0.14em;
  }

  .hero-name {
    font-size: clamp(3.4rem, 18vw, 5.2rem);
    margin: 0.12em 0 0.1em;
  }

  .hero-line {
    font-size: 0.95rem;
    line-height: 1.65;
    padding: 0 0.25rem;
  }

  .envelope-scene {
    margin-top: 1rem;
  }

  .envelope {
    width: min(250px, 78vw);
    height: 162px;
  }

  .env-hint {
    font-size: 0.8rem;
    letter-spacing: 0.12em;
    margin-top: 0.9rem;
    padding: 0 1rem;
  }

  .memories {
    padding: 2.5rem 1rem 1.5rem;
  }

  .section-head {
    margin-bottom: 2.4rem;
  }

  .section-head h2 {
    font-size: clamp(1.7rem, 7vw, 2.2rem);
    line-height: 1.25;
    padding: 0 0.4rem;
  }

  .section-head p {
    font-size: 0.9rem;
    padding: 0 0.5rem;
  }

  .memory {
    margin-bottom: 2.8rem;
    gap: 0.9rem;
  }

  .photo-frame {
    border-radius: 2px;
    max-height: 72vh;
  }

  figcaption p {
    font-size: 0.98rem;
    max-width: none;
    line-height: 1.7;
  }

  .letter-wrap {
    padding: 1.5rem 0.85rem 3rem;
  }

  .letter {
    transform: none;
    width: 100%;
    padding: 1.6rem 1.15rem 1.9rem;
    border-radius: 2px;
  }

  .letter-to {
    font-size: 1.55rem;
  }

  .letter-body p {
    font-size: 0.96rem;
    text-indent: 1.8em;
    line-height: 1.85;
    margin-bottom: 0.95rem;
  }

  .letter-sign {
    font-size: 1.2rem;
  }

  .finale {
    min-height: auto;
    padding:
      2.5rem 1rem
      calc(4rem + env(safe-area-inset-bottom, 0px));
  }

  .cake-stage {
    width: 100%;
    gap: 0.75rem;
  }

  .finale-hint {
    font-size: 0.86rem;
    letter-spacing: 0.08em;
    padding: 0 0.5rem;
  }

  .finale-wish {
    font-size: clamp(1.25rem, 5.5vw, 1.6rem);
    padding: 0 0.5rem;
  }

  .cake-stage {
    transform: scale(0.86);
    transform-origin: center top;
    margin-bottom: -2.2rem;
  }

  .cake {
    width: 300px;
    height: 340px;
    max-width: none;
    margin: 0.2rem 0 0;
  }

  body.is-opened .hero {
    padding-top: 10vh;
    padding-bottom: 6vh;
  }

  .music-toggle {
    width: 42px;
    height: 42px;
  }
}

/* Short phones / landscape-ish height */
@media (max-height: 720px) and (max-width: 767px) {
  .hero {
    padding-top: calc(3.2rem + env(safe-area-inset-top, 0px));
    justify-content: center;
  }

  .hero-name {
    font-size: clamp(2.8rem, 14vw, 4rem);
  }

  .hero-line {
    font-size: 0.88rem;
  }

  .envelope {
    width: min(220px, 70vw);
    height: 142px;
  }

  .env-flap {
    height: 74px;
  }

  .env-seal {
    top: 46px;
    width: 38px;
    height: 38px;
    margin-left: -19px;
  }

  .env-seal em {
    font-size: 1.1rem;
  }
}

@media (max-width: 380px) {
  .cake-stage {
    transform: scale(0.78);
    margin-bottom: -3.2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .photo-frame,
  .photo-frame img,
  figcaption {
    transform: none !important;
  }

  .cake-stage.is-in .cake {
    animation: none !important;
  }
}
