/* ==========================================================
   给张冉 · 11.12
   暖色纸感 + 信封 + 两页信纸
   ========================================================== */

:root {
  --bg1: #FBF0E2;
  --bg2: #F4DCC6;
  --bg3: #EFC9AD;
  --paper: #FFFDF6;
  --ink: #3D3129;
  --ink-soft: #7A6455;
  --rose: #B5483B;
  --rose-deep: #9C382E;
  --gold: #C0913F;
  --env: #F4E4CE;
  --env-deep: #E6CEAF;
  --env-line: #D9BE9B;
  --serif: "Songti SC", "STSong", "SimSun", "Noto Serif SC", "Source Han Serif SC", Georgia, serif;
  --sans: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(120% 90% at 50% 0%, #FFF7EC 0%, var(--bg1) 38%, var(--bg2) 78%, var(--bg3) 100%);
  overflow-x: hidden;
}

body.locked { overflow: hidden; }

/* ---------- 氛围层 ---------- */

.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.bokeh {
  position: absolute;
  border-radius: 50%;
  filter: blur(46px);
  opacity: .55;
}

.b1 { width: 46vw; height: 46vw; left: -14vw; top: -16vw; background: rgba(255, 214, 178, .75); }
.b2 { width: 38vw; height: 38vw; right: -12vw; top: 6vw; background: rgba(240, 168, 140, .45); }
.b3 { width: 42vw; height: 42vw; left: 18vw; bottom: -22vw; background: rgba(255, 236, 204, .85); }
.b4 { width: 26vw; height: 26vw; right: 16vw; bottom: -12vw; background: rgba(214, 140, 120, .28); }

.confetti { position: absolute; inset: 0; }

.bit {
  position: absolute;
  top: -12vh;
  width: 7px;
  height: 11px;
  border-radius: 2px;
  opacity: .75;
  animation-name: fall;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}

.bit.round { border-radius: 50%; width: 8px; height: 8px; }

@keyframes fall {
  to { transform: translateY(118vh) rotate(560deg); }
}

/* ---------- 场景 ---------- */

.scene {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 2.4vh, 26px);
  padding: 44px 20px 90px;
}

.eyebrow {
  margin: 0;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .32em;
  text-transform: uppercase;
  text-indent: .32em;
  color: rgba(176, 120, 70, .85);
}

.dateline {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(12px, 1.1vw, 14px);
  letter-spacing: .42em;
  color: rgba(122, 86, 66, .85);
  text-indent: .42em;
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  perspective: 1400px;
}

/* ---------- 信封 ---------- */

.envelope {
  position: relative;
  width: min(460px, 86vw);
  aspect-ratio: 1.58;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform .7s cubic-bezier(.2, .75, .25, 1), opacity .7s ease;
  -webkit-tap-highlight-color: transparent;
}

.envelope:focus-visible {
  outline: 2px solid var(--rose);
  outline-offset: 6px;
  border-radius: 8px;
}

.envelope:hover { transform: translateY(-4px); }

.env-back,
.env-pocket,
.env-front {
  position: absolute;
  inset: 0;
  border-radius: 8px;
}

.env-back {
  background: var(--env-deep);
  box-shadow:
    0 34px 60px -22px rgba(96, 58, 36, .45),
    0 2px 0 rgba(255, 255, 255, .5) inset;
}

.env-pocket {
  background: linear-gradient(180deg, #F7E8D4 0%, var(--env) 100%);
  clip-path: polygon(0 0, 50% 34%, 100% 0, 100% 100%, 0 100%);
}

.env-front {
  background: transparent;
  z-index: 3;
}

.env-flap {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 46%;
  background: linear-gradient(180deg, #F8EAD8 0%, #EFD9BE 100%);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  border-radius: 8px 8px 0 0;
  transform-origin: 50% 0;
  transform: rotateX(0deg);
  transition: transform .95s cubic-bezier(.3, .8, .3, 1);
  backface-visibility: hidden;
  z-index: 4;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .6) inset;
  filter: drop-shadow(0 3px 5px rgba(120, 80, 50, .10));
}

.stage.opened .env-flap { transform: rotateX(178deg); }

.stage.opened .envelope {
  transform: translateY(30px) scale(.955);
  opacity: .5;
}

.stage.opened .seal {
  opacity: 0;
  transform: translate(-50%, -50%) scale(.78);
  transition: opacity .45s ease, transform .45s ease;
}

/* 邮票 */
.stamp {
  position: absolute;
  right: 7%;
  top: 55%;
  width: 15%;
  aspect-ratio: .82;
  background: #FFF6E8;
  border: 1px solid var(--env-line);
  border-radius: 2px;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(120, 80, 50, .12);
  background-image:
    radial-gradient(circle at 0 0, transparent 0 3px, #FFF6E8 3px),
    radial-gradient(circle at 100% 0, transparent 0 3px, #FFF6E8 3px),
    radial-gradient(circle at 0 100%, transparent 0 3px, #FFF6E8 3px),
    radial-gradient(circle at 100% 100%, transparent 0 3px, #FFF6E8 3px);
}

.stamp-inner {
  font-family: var(--serif);
  font-size: clamp(9px, 1.05vw, 12px);
  letter-spacing: .08em;
  color: var(--rose);
  border-top: 1px solid rgba(181, 72, 59, .35);
  border-bottom: 1px solid rgba(181, 72, 59, .35);
  padding: 3px 2px;
}

/* 地址 */
.addr {
  position: absolute;
  left: 0;
  right: 0;
  top: 56%;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: .55em;
  color: #5B4232;
}

.addr-to {
  font-family: var(--serif);
  font-size: clamp(12px, 1.5vw, 16px);
  color: rgba(91, 66, 50, .75);
  letter-spacing: .2em;
}

.addr-name {
  font-family: var(--serif);
  font-size: clamp(21px, 3.4vw, 34px);
  letter-spacing: .28em;
  padding-left: .1em;
  border-bottom: 1px solid rgba(120, 84, 58, .35);
  padding-bottom: 2px;
}

/* 火漆印 */
.seal {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  width: clamp(46px, 7vw, 62px);
  height: clamp(46px, 7vw, 62px);
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 32%, #C75A4B 0%, var(--rose) 45%, var(--rose-deep) 100%);
  display: grid;
  place-items: center;
  color: #FBEADF;
  box-shadow:
    0 6px 14px rgba(120, 40, 30, .35),
    0 0 0 4px rgba(181, 72, 59, .18);
  z-index: 6;
  transition: opacity .45s ease, transform .45s ease;
}

.seal span {
  font-family: var(--serif);
  font-size: clamp(14px, 2vw, 19px);
  letter-spacing: .04em;
}

.hint {
  margin: 0;
  font-size: 12px;
  letter-spacing: .26em;
  color: rgba(110, 76, 56, .8);
  text-indent: .26em;
}

/* ---------- 信纸 ---------- */

.letter-layer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px 16px 32px;
}

.letter-layer[hidden] { display: none; }

.letter-scrim {
  position: absolute;
  inset: 0;
  background: rgba(64, 40, 28, .38);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity .5s ease;
}

.letter-layer.show .letter-scrim { opacity: 1; }

.paper {
  position: relative;
  width: min(720px, 94vw);
  height: min(82vh, 800px);
  background: var(--paper);
  border-radius: 10px;
  box-shadow:
    0 50px 90px -30px rgba(60, 32, 20, .55),
    0 0 0 1px rgba(255, 255, 255, .8) inset,
    0 0 0 1px rgba(150, 110, 80, .12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(90px) scale(.96) rotate(-.8deg);
  transition: opacity .6s ease, transform .8s cubic-bezier(.2, .8, .2, 1);
}

.letter-layer.show .paper {
  opacity: 1;
  transform: translateY(0) scale(1) rotate(0deg);
}

/* 纸纹 */
.paper::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(140, 100, 70, .035) 1px, transparent 1px);
  background-size: 100% 30px;
  opacity: .5;
}

.paper-viewport {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow: hidden;
}

/* 花边边框 + 角落枫叶 */
.paper-frame {
  position: absolute;
  inset: 10px;
  z-index: 2;
  border: 1px solid rgba(176, 120, 70, .42);
  border-radius: 4px;
  pointer-events: none;
}

.paper-frame::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(176, 120, 70, .16);
  border-radius: 2px;
}

.maple {
  position: absolute;
  font-size: 44px;
  line-height: 1;
  opacity: .92;
  filter: sepia(1) saturate(3.1) hue-rotate(-31deg) brightness(.82) drop-shadow(0 2px 4px rgba(110, 40, 30, .28));
}

.ml-left {
  left: -13px;
  bottom: -13px;
  font-size: 52px;
  transform: rotate(-14deg);
}

.ml-right {
  right: -9px;
  bottom: -9px;
  font-size: 30px;
  transform: rotate(32deg);
  opacity: .75;
}

.pages {
  display: flex;
  width: 200%;
  height: 100%;
  transition: transform .7s cubic-bezier(.22, .8, .24, 1);
}

.paper[data-page="2"] .pages { transform: translateX(-50%); }

.page {
  width: 50%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: clamp(26px, 4.4vw, 54px) clamp(24px, 4.6vw, 62px);
  scrollbar-width: thin;
  scrollbar-color: rgba(150, 110, 80, .35) transparent;
}

.page::-webkit-scrollbar { width: 6px; }
.page::-webkit-scrollbar-thumb { background: rgba(150, 110, 80, .3); border-radius: 3px; }

.page-inner { position: relative; z-index: 1; width: 100%; margin: auto 0; }

.page p {
  margin: 0 0 1.02em;
  font-family: var(--serif);
  font-size: clamp(15px, 1.12vw, 17.5px);
  line-height: 1.98;
  color: var(--ink);
  text-align: justify;
  text-indent: 2em;
  letter-spacing: .02em;
}

.salute {
  text-indent: 0 !important;
  font-size: 1.18em !important;
  font-weight: 600;
  letter-spacing: .1em;
  margin-bottom: 1.5em !important;
}

.photo {
  margin: 1.4em auto 1em;
  text-align: center;
}

.photo img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(46vh, 430px);
  margin: 0 auto;
  border: 7px solid #fff;
  border-radius: 4px;
  box-shadow: 0 14px 30px -12px rgba(80, 50, 30, .4);
}

.page .sign {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  text-indent: 0 !important;
  text-align: right;
  margin-top: 1.3em !important;
}

.sign-name {
  font-family: var(--serif);
  font-size: 1.02em;
  letter-spacing: .16em;
  color: var(--ink);
}

.sign-date {
  font-family: var(--serif);
  font-size: .82em;
  letter-spacing: .14em;
  color: var(--ink-soft);
}

.page .flourish {
  text-indent: 0 !important;
  text-align: center;
  letter-spacing: .9em;
  color: rgba(176, 120, 70, .75);
  font-size: .88em !important;
  margin-top: 2.4em !important;
}

/* 关闭 */
.close {
  position: absolute;
  right: 12px;
  top: 10px;
  z-index: 5;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(90, 62, 46, .55);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background .2s ease, color .2s ease;
}

.close:hover { background: rgba(181, 72, 59, .1); color: var(--rose); }

.close:focus-visible,
.nav-btn:focus-visible {
  outline: 2px solid var(--rose);
  outline-offset: 3px;
}

.music:focus-visible {
  outline: 2px solid #F8E7D6;
  outline-offset: 3px;
}

/* 翻页 */
.paper-nav {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 3vw, 26px);
  padding: 12px 18px 16px;
  border-top: 1px dashed rgba(130, 96, 68, .22);
  background: linear-gradient(180deg, rgba(255, 253, 246, 0), rgba(255, 250, 240, .9));
}

.nav-btn {
  min-width: 42px;
  height: 42px;
  padding: 0 14px;
  border: 1px solid rgba(150, 110, 80, .3);
  border-radius: 999px;
  background: #FFFBF2;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: .06em;
  cursor: pointer;
  transition: background .2s ease, color .2s ease, transform .2s ease, border-color .2s ease;
}

.nav-btn:hover:not(:disabled) {
  background: var(--rose);
  border-color: var(--rose);
  color: #FFF6EA;
  transform: translateY(-1px);
}

.nav-btn:disabled { opacity: .35; cursor: default; }

.nav-btn.end {
  background: var(--rose);
  border-color: var(--rose);
  color: #FFF6EA;
  padding: 0 22px;
}

.indicator {
  font-family: var(--serif);
  font-size: 12px;
  letter-spacing: .3em;
  color: rgba(110, 78, 58, .7);
  text-indent: .3em;
}

/* ---------- 音乐 ---------- */

.music {
  position: fixed;
  right: clamp(14px, 2.4vw, 26px);
  bottom: clamp(14px, 2.4vw, 26px);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 15px 7px 8px;
  border: 0;
  border-radius: 999px;
  background: rgba(61, 42, 32, .9);
  color: #F8E7D6;
  font-size: 12px;
  letter-spacing: .16em;
  cursor: pointer;
  box-shadow: 0 10px 26px -10px rgba(50, 26, 16, .7);
  transition: background .25s ease, transform .25s ease;
}

.music:hover { background: rgba(80, 52, 38, .95); transform: translateY(-2px); }

.vinyl {
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #D9A441 0 7px, #2A1C15 8px 12px, #3A281F 13px 100%);
  box-shadow: 0 0 0 2px rgba(255, 246, 234, .14);
}

.vinyl .label {
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: #D9A441;
}

.music[aria-pressed="true"] .vinyl { animation: spin 5s linear infinite; }

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

.music.prompt { animation: pulse 1.8s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(217, 164, 65, .55); }
  50% { box-shadow: 0 0 0 12px rgba(217, 164, 65, 0); }
}

/* ---------- 无 JS 兜底 ---------- */

.fallback {
  display: none;
  position: relative;
  z-index: 2;
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 22px 80px;
}

.fallback-date {
  text-align: center;
  letter-spacing: .5em;
  color: var(--rose);
  font-family: var(--serif);
}

.fallback h1 {
  font-family: var(--serif);
  font-size: 30px;
  text-align: center;
  font-weight: 600;
  margin: 8px 0 30px;
}

.fallback p {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.95;
  text-indent: 2em;
  text-align: justify;
}

.fallback img {
  width: 100%;
  height: auto;
  border: 7px solid #fff;
  border-radius: 4px;
  box-shadow: 0 14px 30px -12px rgba(80, 50, 30, .4);
  margin: 10px 0 18px;
}

.fallback-sign {
  text-align: right !important;
  text-indent: 0 !important;
  color: var(--ink-soft);
  font-size: 14px !important;
}

/* ---------- 响应式 ---------- */

@media (max-width: 720px) {
  .scene { padding: 30px 14px 84px; }
  .paper { height: 86svh; }
  .page { padding: 26px 22px 32px; }
  .page p { font-size: 15.5px; line-height: 1.92; }
  .stamp { width: 17%; top: 56%; }
  .seal { top: 41%; }
}

@media (max-width: 420px) {
  .page p { font-size: 15px; }
  .addr-name { font-size: 24px; }
  .nav-btn { min-width: 38px; height: 38px; }
}

/* ---------- 减少动态效果 ---------- */

@media (prefers-reduced-motion: reduce) {
  .confetti { display: none; }
  .envelope,
  .env-flap,
  .paper,
  .pages,
  .letter-scrim,
  .close,
  .nav-btn,
  .music { transition-duration: .001s; }
  .paper { transform: none; }
  .music[aria-pressed="true"] .vinyl { animation: none; }
  .music.prompt { animation: none; }
  .bit { animation: none; display: none; }
}
