@font-face {
  font-family: "MoonTitle";
  src: url("fonts/title.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "MoonBody";
  src: url("fonts/body.woff2") format("woff2");
  font-display: swap;
}

:root {
  --gold: #ffe2a6;
  --gold-2: #f6c877;
  --gold-3: #d9a24e;
  --red: #c8322a;
  --ink: #0b1030;
  --title-font: "MoonTitle", "STKaiti", "KaiTi", "Kaiti SC", "楷体", serif;
  --ts: 1;
  --body-font: "MoonBody", "STKaiti", "KaiTi", "Kaiti SC", "Songti SC", "Noto Serif CJK SC", serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--ink); color: var(--gold);
  font-family: var(--body-font);
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100% !important;
  text-size-adjust: 100% !important;
}
button { font: inherit; color: inherit; }

#wxcover { position: absolute; width: 0; height: 0; overflow: hidden; opacity: 0; pointer-events: none; }
#wxcover img { width: 400px; height: 400px; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#vignette {
  position: fixed; inset: 0; pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 38%, transparent 55%, rgba(4, 6, 20, .55) 100%),
    linear-gradient(to bottom, transparent 55%, rgba(5, 7, 22, .35) 100%);
}

/* ---------------- 贺卡正文 ---------------- */
#card {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(env(safe-area-inset-top) + 14px) 14px calc(env(safe-area-inset-bottom) + 14px);
  pointer-events: none;
  opacity: 0; transition: opacity 1.2s ease;
}
#card.show { opacity: 1; }
#moonSpace { flex: 1 1 auto; width: 100%; min-height: 26vh; }

#yearTag {
  position: absolute; right: calc(env(safe-area-inset-right) + 22px); top: calc(env(safe-area-inset-top) + 72px);
  writing-mode: vertical-rl; letter-spacing: .35em;
  font-size: calc(13px * var(--ts)); color: rgba(255, 226, 166, .78);
  text-shadow: 0 0 8px rgba(255, 190, 100, .35);
}
#yearTag i {
  display: inline-block; width: 4px; height: 4px; margin: .5em 0; border-radius: 50%;
  background: rgba(255, 200, 120, .8);
}

#text {
  flex: 0 0 auto; width: 100%; max-width: 42em;
  text-align: center;
  transition: opacity .9s ease, transform .9s ease;
  text-shadow: 0 1px 10px rgba(5, 8, 30, .85), 0 0 2px rgba(5, 8, 30, .6);
}
#card.viewing #text, #card.viewing #hint { opacity: 0; transform: translateY(18px); }
#card.zoomed #text, #card.zoomed #hint, #card.zoomed #yearTag { opacity: 0; transform: translateY(18px); pointer-events: none; }
#yearTag { transition: opacity .6s; }

#to {
  font-size: calc(clamp(14px, min(4vw, 2.3vh), 19px) * var(--ts)); letter-spacing: .12em;
  color: rgba(255, 230, 185, .9); margin-bottom: .2em;
  animation: fadeUp 1.2s ease both;
}
#to::before, #to::after {
  content: ""; display: inline-block; vertical-align: middle; width: 2.2em; height: 1px; margin: 0 .7em;
  background: linear-gradient(90deg, transparent, rgba(255, 210, 140, .7), transparent);
}

#title {
  position: relative; display: inline-block; margin: 0 0 .12em; font-weight: normal; white-space: nowrap;
  font-family: var(--title-font);
  font-size: calc(clamp(42px, min(14vw, 9.5vh), 92px) * var(--ts)); line-height: 1.15; letter-spacing: .06em;
}
#title .t {
  background: linear-gradient(180deg, #fff6d9 0%, #ffd98a 45%, #e9a445 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 14px rgba(255, 180, 80, .45)) drop-shadow(0 2px 1px rgba(90, 30, 0, .55));
  text-shadow: none;
  opacity: 0; transition: opacity 1.6s ease, letter-spacing 2.2s cubic-bezier(.2, .8, .2, 1);
  letter-spacing: .5em;
}
#card.show #title .t { opacity: 1; letter-spacing: .06em; }

#seal {
  position: absolute; right: -1.05em; top: -.05em;
  width: 2.5em; height: 2.5em; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-family: var(--title-font); font-size: .24em; line-height: 1.02; letter-spacing: 0;
  text-shadow: none;
  color: #ffe9c4; background: radial-gradient(circle at 35% 30%, #e24a3b, #a8201a 70%);
  box-shadow: 0 0 0 2px rgba(255, 220, 170, .5) inset, 0 2px 8px rgba(80, 0, 0, .5);
  opacity: 0; transform: scale(2.4) rotate(-25deg);
}
#seal.stamp { animation: stamp .7s cubic-bezier(.3, 1.6, .5, 1) forwards; }
@keyframes stamp { to { opacity: .95; transform: scale(1) rotate(-12deg); } }

#poem p {
  margin: .25em 0; font-size: calc(clamp(16px, min(4.8vw, 3.2vh), 31px) * var(--ts)); letter-spacing: .1em;
  line-height: 1.55;
}
#wish {
  margin: .8em auto 0; max-width: 21em;
  font-size: calc(clamp(14px, min(4.1vw, 2.45vh), 21px) * var(--ts)); line-height: 1.95; letter-spacing: .06em;
  text-align: justify; text-align-last: center;
}
#from {
  margin-top: .6em; text-align: right; padding-right: .5em;
  font-size: calc(clamp(14px, min(4vw, 2.3vh), 19px) * var(--ts)); letter-spacing: .1em;
  animation: fadeUp 1.4s ease both; animation-delay: var(--d, 0s);
}

.ch { color: transparent; animation: inkIn 1.3s ease forwards; animation-delay: var(--d); }
#poem .ch { --c: #ffe7b3; }
#wish .ch { --c: #fbe9cb; }
@keyframes inkIn {
  0% { color: transparent; text-shadow: 0 0 14px rgba(255, 210, 140, 0); }
  45% { color: rgba(255, 236, 196, .4); text-shadow: 0 0 12px rgba(255, 200, 120, .9); }
  100% { color: var(--c); text-shadow: 0 0 10px rgba(255, 190, 100, .35), 0 1px 8px rgba(5, 8, 30, .9); }
}
#text.fading { opacity: 0; transform: translateY(-8px); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

#hint {
  margin: 1.1em 0 .7em; font-size: calc(12px * var(--ts)); letter-spacing: .12em;
  color: rgba(255, 226, 170, .6);
  opacity: 0; transition: opacity 1.2s ease, transform .9s;
}
#hint.show { opacity: 1; }

#bar {
  flex: 0 0 auto;
  display: flex; gap: 6px; flex-wrap: nowrap; justify-content: center; max-width: 100%;
  pointer-events: auto;
  opacity: 0; transform: translateY(12px); transition: opacity 1s ease, transform 1s ease;
}
#bar.show { opacity: 1; transform: none; }
#bar button {
  display: flex; align-items: center; gap: 4px;
  padding: calc(8px * var(--ts)) calc(11px * var(--ts)) calc(8px * var(--ts)) calc(10px * var(--ts)); border-radius: 999px; cursor: pointer;
  font-size: calc(13.5px * var(--ts)); letter-spacing: .04em; color: #ffe6b4; white-space: nowrap;
  background: linear-gradient(180deg, rgba(255, 220, 160, .14), rgba(255, 190, 110, .06));
  border: 1px solid rgba(255, 214, 150, .38);
  box-shadow: 0 4px 18px rgba(0, 0, 0, .25), inset 0 1px 0 rgba(255, 240, 210, .18);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  transition: transform .15s ease, background .3s;
}
#bar button:active { transform: scale(.94); background: rgba(255, 200, 120, .25); }
#bar svg, #music svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#btnView.on { background: rgba(255, 200, 120, .28); }

/* ---------------- 音乐按钮 ---------------- */
#music {
  position: fixed; z-index: 5; top: calc(env(safe-area-inset-top) + 16px); right: calc(env(safe-area-inset-right) + 16px);
  width: 42px; height: 42px; border-radius: 50%; padding: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #ffe6b4; background: rgba(255, 210, 140, .12); border: 1px solid rgba(255, 214, 150, .45);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  opacity: 0; pointer-events: none; transition: opacity 1s;
}
#music.show { opacity: 1; pointer-events: auto; }
#music svg { width: 20px; height: 20px; }
#music.on { animation: spin 5s linear infinite; }
#music.on::after {
  content: ""; position: absolute; inset: -5px; border-radius: 50%;
  border: 1px solid rgba(255, 214, 150, .5); animation: ripple 2.2s ease-out infinite;
}
#music.off::before {
  content: ""; position: absolute; width: 26px; height: 1.6px; background: currentColor; transform: rotate(-45deg); border-radius: 2px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes ripple { from { transform: scale(1); opacity: .9; } to { transform: scale(1.6); opacity: 0; } }

#btnReset {
  position: fixed; z-index: 5; left: 50%; top: calc(env(safe-area-inset-top) + 20px); transform: translateX(-50%);
  padding: calc(7px * var(--ts)) calc(16px * var(--ts)); border-radius: 999px; cursor: pointer;
  font-size: calc(13.5px * var(--ts)); letter-spacing: .1em; color: #ffe6b4; white-space: nowrap;
  background: rgba(40, 30, 70, .45); border: 1px solid rgba(255, 214, 150, .45);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  animation: fadeUp .4s ease both;
}

/* ---------------- 开场 ---------------- */
#intro {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(80% 60% at 50% 45%, rgba(20, 16, 50, .35), rgba(6, 8, 26, .82) 80%),
    rgba(6, 8, 26, .3);
  transition: opacity 1.4s ease, visibility 1.4s;
}
#intro.gone { opacity: 0; visibility: hidden; }
.intro-inner { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 0 24px; }
#introTo { font-size: calc(17px * var(--ts)); letter-spacing: .2em; margin-bottom: 18px; color: rgba(255, 232, 190, .92); }
.intro-title {
  font-family: var(--title-font); writing-mode: vertical-rl;
  font-size: calc(clamp(64px, min(22vw, 14vh), 120px) * var(--ts)); line-height: 1.05; letter-spacing: .08em;
  background: linear-gradient(90deg, #fff4d2, #ffd27a 50%, #e39a3c);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(255, 180, 80, .45));
  animation: fadeUp 1.6s ease both;
}
.intro-sub { margin-top: 18px; font-size: calc(14px * var(--ts)); letter-spacing: .3em; color: rgba(255, 226, 170, .75); animation: fadeUp 1.6s .3s ease both; }
#openBtn {
  position: relative; margin-top: 38px; width: 92px; height: 92px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  background: none; animation: fadeUp 1.6s .6s ease both;
}
#openBtn .seal-face {
  position: absolute; inset: 10px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--title-font); font-size: calc(36px * var(--ts)); color: #ffe8bd;
  background: radial-gradient(circle at 35% 30%, #ea5646, #a41d17 72%);
  box-shadow: 0 0 0 2px rgba(255, 215, 160, .55) inset, 0 0 26px rgba(255, 90, 60, .55), 0 6px 18px rgba(0, 0, 0, .45);
  transition: transform .3s;
}
#openBtn:not(:disabled) .seal-face { animation: beat 2s ease-in-out infinite; }
#openBtn:disabled .seal-face { filter: saturate(.5) brightness(.8); }
#openBtn .ring { position: absolute; inset: 0; width: 100%; height: 100%; animation: spin 14s linear infinite; }
#openBtn .ring circle { fill: none; stroke: rgba(255, 214, 150, .7); stroke-width: 1.2; stroke-dasharray: 3 7; }
@keyframes beat { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
.intro-tip { margin-top: 18px; font-size: calc(13px * var(--ts)); letter-spacing: .2em; color: rgba(255, 226, 170, .65); animation: fadeUp 1.6s .8s ease both; }

/* ---------------- 提示 & 分享 ---------------- */
#toast {
  position: fixed; z-index: 8; left: 50%; top: 42%;
  transform: translate(-50%, -50%) scale(.9);
  padding: 12px 22px; border-radius: 999px; max-width: 86vw; text-align: center;
  font-size: calc(16px * var(--ts)); letter-spacing: .12em; color: #fff1d2; white-space: nowrap;
  background: radial-gradient(120% 160% at 50% 0%, rgba(160, 40, 30, .75), rgba(60, 12, 20, .75));
  border: 1px solid rgba(255, 210, 150, .45);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35), 0 0 24px rgba(255, 120, 60, .25);
  opacity: 0; pointer-events: none; transition: opacity .45s ease, transform .45s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

#sheet {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(3, 5, 18, .55);
}
#sheet[hidden], #wxguide[hidden], [hidden] { display: none !important; }
.sheet-card {
  position: relative; width: 100%; max-width: 460px;
  padding: 26px 22px calc(env(safe-area-inset-bottom) + 22px);
  border-radius: 22px 22px 0 0;
  background: linear-gradient(180deg, #221a3e, #140f2a);
  border-top: 1px solid rgba(255, 214, 150, .4);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .4);
  animation: sheetUp .35s ease;
  -webkit-user-select: text; user-select: text;
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
.sheet-title { font-family: var(--title-font); font-size: calc(24px * var(--ts)); text-align: center; margin-bottom: 16px; color: var(--gold); }
.sheet-card label { display: flex; align-items: center; gap: 12px; margin: 10px 0; font-size: calc(15px * var(--ts)); color: rgba(255, 230, 190, .85); }
.sheet-card input {
  flex: 1; min-width: 0; padding: 11px 14px; border-radius: 12px; font: inherit; font-size: 16px;
  color: #fff3dc; background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 214, 150, .3); outline: none;
}
.sheet-card input:focus { border-color: rgba(255, 214, 150, .75); }
.sheet-card input::placeholder { color: rgba(255, 230, 190, .35); }
.sheet-actions { display: flex; gap: 12px; margin-top: 18px; }
.sheet-actions button {
  flex: 1; padding: 12px; border-radius: 999px; cursor: pointer; font-size: calc(15px * var(--ts)); letter-spacing: .1em;
  border: 1px solid rgba(255, 214, 150, .45); background: rgba(255, 214, 150, .08); color: #ffe6b4;
}
.sheet-actions .primary { background: linear-gradient(180deg, #e24a3b, #a8201a); border-color: rgba(255, 200, 150, .6); color: #fff1d8; }
.sheet-note { margin-top: 14px; font-size: calc(12.5px * var(--ts)); line-height: 1.7; text-align: center; color: rgba(255, 226, 170, .6); }
#sheetClose {
  position: absolute; right: 12px; top: 10px; width: 34px; height: 34px; border: 0; background: none; cursor: pointer;
  font-size: calc(26px * var(--ts)); line-height: 1; color: rgba(255, 226, 170, .7);
}

#wxguide {
  position: fixed; inset: 0; z-index: 30; background: rgba(3, 5, 18, .82);
  color: var(--gold); text-align: right; padding: calc(env(safe-area-inset-top) + 10px) 26px 0 0;
}
#wxguide svg { width: 110px; height: 110px; fill: none; stroke: var(--gold); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
#wxguide p { margin: 4px 0 8px; font-size: calc(19px * var(--ts)); line-height: 1.8; letter-spacing: .12em; }
#wxguide b { font-size: calc(24px * var(--ts)); }
#wxguide small { font-size: calc(12px * var(--ts)); color: rgba(255, 226, 170, .6); }

.noscript { position: fixed; inset: 0; padding: 40px; font-size: calc(20px * var(--ts)); line-height: 2; text-align: center; }

/* 无 WebGL 时的降级 */
body.no-webgl { background: radial-gradient(circle at 50% 22%, #fff3cf 0 60px, rgba(255, 220, 150, .35) 62px, transparent 150px), linear-gradient(#0b1030, #2a2250 70%, #3d2f5a); }

@media (min-aspect-ratio: 5/4) {
  #moonSpace { min-height: 36vh; }
  #wish { max-width: 23.5em; }
}
@media (max-height: 640px) {
  #hint { display: none; }
  #bar button { padding: calc(7px * var(--ts)) calc(11px * var(--ts)); font-size: calc(13px * var(--ts)); }
}
@media (max-width: 359px) {
  #bar svg { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .ch { animation-duration: .01s; }
}
