/* ============================================================
   生日快乐贺卡 · 样式（编辑杂志风 / 暖纸感）
   - 真实摄影为主角，衬线标题 + 纸张纹理，刻意避开霓虹渐变与玻璃态
   - 彩带与烟花复用 canvas-confetti (MIT)
   - 信封开场、点蜡烛、点击蛋糕掉落祝福等交互思路，
     参考开源项目 engrshuvodas/Birthday-Wish-Card 与
     「Интерактивная поздравительная открытка на JavaScript」
   ============================================================ */

:root {
  --paper:      #fbf7ee;
  --paper-2:    #f2e9d9;
  --paper-3:    #e8dcc6;
  --ink:        #2b2119;
  --ink-soft:   #6d5b46;
  --ink-faint:  rgba(43, 33, 25, 0.42);
  --rose:       #b84b64;
  --rose-deep:  #8e3348;
  --gold:       #b8863b;
  --gold-soft:  #d9ac5a;
  --line:       rgba(43, 33, 25, 0.16);
  --line-soft:  rgba(43, 33, 25, 0.09);
  --shadow:     0 16px 40px rgba(60, 42, 22, 0.16);
  --shadow-lg:  0 26px 60px rgba(60, 42, 22, 0.22);
  --radius:     4px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Songti SC", "Noto Serif SC", "SimSun", serif;
  --sans: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 40px;
}

/* 纸张纹理：一层极淡的颗粒，替代以往的高饱和渐变 */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.16 0 0 0 0 0.12 0 0 0 0 0.08 0 0 0 0.06 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.9;
  mix-blend-mode: multiply;
}

/* ---------- 背景装饰 ---------- */
.bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.bg-wash {
  position: absolute; inset: -10%;
  background:
    radial-gradient(46% 40% at 8% 4%, rgba(216, 172, 90, 0.20), transparent 70%),
    radial-gradient(48% 42% at 96% 12%, rgba(184, 75, 100, 0.14), transparent 70%),
    radial-gradient(60% 50% at 50% 108%, rgba(184, 75, 100, 0.12), transparent 70%);
}
.bokeh i {
  position: absolute;
  border-radius: 50%;
  filter: blur(0.5px);
  opacity: 0;
  animation: rise linear infinite;
}
@keyframes rise {
  0% { transform: translateY(10vh) scale(0.8); opacity: 0; }
  12% { opacity: 0.5; }
  85% { opacity: 0.35; }
  100% { transform: translateY(-105vh) scale(1.15); opacity: 0; }
}

/* ---------- 音乐按钮 ---------- */
.music-btn {
  position: fixed;
  top: 16px; right: 16px;
  z-index: 40;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 15px;
  font: inherit; font-size: 0.8rem; letter-spacing: 0.06em;
  color: var(--ink);
  background: rgba(251, 247, 238, 0.92);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}
.music-btn:hover { transform: translateY(-2px); background: #fff; }
.music-btn.playing { color: var(--paper); background: var(--rose); border-color: var(--rose); }

/* ---------- 信封开场（暖色暗调） ---------- */
.envelope-screen {
  position: fixed; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 38px;
  background:
    radial-gradient(60% 50% at 50% 30%, rgba(184, 75, 100, 0.28), transparent 70%),
    radial-gradient(80% 60% at 50% 100%, rgba(184, 134, 59, 0.16), transparent 70%),
    #22151a;
  transition: opacity 0.7s ease, visibility 0.7s ease;
}
.envelope-screen.hidden { opacity: 0; visibility: hidden; }

.env-dateline { font-family: var(--sans); font-size: 0.72rem; letter-spacing: 0.42em; color: rgba(251,247,238,0.55); text-indent: 0.42em; }

.envelope {
  position: relative;
  width: 330px; height: 214px;
  cursor: pointer;
  transition: transform 0.3s ease;
  transform-style: preserve-3d;
}
.envelope:hover { transform: translateY(-6px) rotate(-1deg); }
.envelope.opening { cursor: default; }

.env-shadow {
  position: absolute; left: 6%; right: 6%; bottom: -28px; height: 42px;
  background: radial-gradient(closest-side, rgba(0,0,0,0.6), transparent 75%);
  filter: blur(7px);
}
.env-body, .env-front { position: absolute; inset: 0; border-radius: 3px; }
.env-body { background: linear-gradient(160deg, #e8c3ab, #c9906f); }
.env-front {
  background: linear-gradient(160deg, #f6e3d0, #e0b394);
  clip-path: polygon(0 0, 50% 42%, 100% 0, 100% 100%, 0 100%);
  box-shadow: var(--shadow-lg);
  z-index: 3;
}
.env-flap {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 60%;
  background: linear-gradient(160deg, #edd0b6, #d8a483);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transition: transform 0.75s cubic-bezier(0.6, 0, 0.3, 1);
  z-index: 4;
  backface-visibility: hidden;
}
.envelope.opening .env-flap { transform: rotateX(-176deg); }

.env-letter {
  position: absolute; left: 6%; right: 6%; top: 12%;
  height: 84%;
  padding: 20px 18px;
  text-align: center;
  background: linear-gradient(180deg, #fffdf8, #f7ecd9);
  color: var(--ink);
  border-radius: 3px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.22);
  transform: translateY(0);
  transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) 0.4s;
  z-index: 2;
}
.envelope.opening .env-letter { transform: translateY(-152%) scale(1.04); }
.env-letter-stamp {
  position: absolute; top: 10px; right: 12px;
  padding: 2px 7px;
  font-size: 0.6rem; letter-spacing: 0.14em;
  color: var(--rose-deep);
  border: 1px solid rgba(142, 51, 72, 0.5);
  border-radius: 2px;
  transform: rotate(6deg);
}
.env-letter-to { margin-top: 30px; font-family: var(--serif); font-size: 1.5rem; letter-spacing: 0.02em; }
.env-letter-mid { margin-top: 8px; font-family: var(--serif); font-style: italic; font-size: 0.9rem; color: var(--ink-soft); }

.env-seal {
  position: absolute; left: 50%; top: 36%;
  width: 52px; height: 52px;
  display: grid; place-items: center;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 34% 28%, #e06a5a, #8e3348 78%);
  color: #f7e6d3;
  font-family: var(--serif); font-weight: 700; font-size: 1.35rem;
  border-radius: 50%;
  box-shadow: 0 8px 18px rgba(120, 40, 55, 0.5), inset 0 -3px 8px rgba(0,0,0,0.28);
  z-index: 6;
  transition: transform 0.5s ease, opacity 0.5s ease;
}
.envelope.opening .env-seal { transform: translate(-50%, -50%) scale(0.4) rotate(35deg); opacity: 0; }

.env-hint { font-size: 0.88rem; letter-spacing: 0.12em; color: rgba(251,247,238,0.62); animation: breathe 2.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.35; } }

/* ---------- 主体 ---------- */
.card-content {
  position: relative; z-index: 2;
  max-width: 860px;
  margin: 0 auto;
  padding: 56px 22px 20px;
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.9s ease 0.15s, transform 0.9s ease 0.15s;
}
.card-content.visible { opacity: 1; transform: none; }

/* ---------- 杂志封面 ---------- */
.cover { position: relative; text-align: center; }
.cover-kicker {
  font-family: var(--sans);
  font-size: 0.68rem; letter-spacing: 0.4em; text-indent: 0.4em;
  color: var(--rose-deep);
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 26px;
}
.cover-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.6rem, 10vw, 5.2rem);
  line-height: 0.98;
  letter-spacing: -0.01em;
}
.cover-title em {
  font-style: italic;
  color: var(--rose);
  position: relative;
  white-space: nowrap;
}
.cover-title em::after {
  content: "";
  position: absolute; left: 2%; right: 2%; bottom: 0.16em;
  height: 0.24em;
  background: rgba(184, 134, 59, 0.28);
  z-index: -1;
}
.cover-sub {
  margin: 20px auto 0;
  max-width: 34em;
  min-height: 1.7em;
  font-family: var(--serif);
  font-size: clamp(0.95rem, 2.5vw, 1.08rem);
  color: var(--ink-soft);
  line-height: 1.8;
}
.cover-sub .caret {
  display: inline-block; width: 2px; height: 1.05em; margin-left: 2px;
  background: var(--rose); vertical-align: -0.18em;
  animation: blink 0.9s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.cover-photo {
  position: relative;
  margin: 34px 0 0;
  background: #fff;
  padding: 12px 12px 0;
  box-shadow: var(--shadow-lg);
  transform: rotate(-0.6deg);
}
.cover-photo img { display: block; width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: cover; object-position: center; }
.cover-photo figcaption {
  padding: 12px 4px 14px;
  font-family: var(--serif); font-style: italic;
  font-size: 0.86rem; color: var(--ink-soft);
}
.cover-photo figcaption span { font-style: normal; letter-spacing: 0.14em; text-transform: uppercase; font-size: 0.7rem; color: var(--rose-deep); margin-right: 6px; }

.cover-stamp {
  position: absolute;
  right: -6px; bottom: 68px;
  width: 74px; height: 74px;
  display: grid; place-items: center;
  font-family: var(--serif); font-size: 1.05rem; line-height: 1; text-align: center;
  color: var(--rose-deep);
  border: 1px dashed rgba(142, 51, 72, 0.55);
  border-radius: 50%;
  transform: rotate(9deg);
  background: rgba(251, 247, 238, 0.7);
}

/* ---------- 卡片与标题 ---------- */
.card {
  margin-top: 40px;
  padding: 34px 30px;
  background: #fff;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(60, 42, 22, 0.10);
  opacity: 0; transform: translateY(26px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}
.card.reveal { opacity: 1; transform: none; }

.section-label {
  font-size: 0.66rem; letter-spacing: 0.34em; text-indent: 0.34em;
  color: var(--rose-deep);
  text-align: center; margin-bottom: 12px;
}
.section-title {
  font-family: var(--serif); font-weight: 400; font-size: clamp(1.4rem, 4.4vw, 1.9rem);
  text-align: center; letter-spacing: 0.01em;
}

/* ---------- 状态 / 倒计时 ---------- */
.status { text-align: center; }
.status h2 { font-family: var(--serif); font-weight: 400; font-size: 1.3rem; margin-bottom: 10px; }
.status p { font-size: 0.94rem; color: var(--ink-soft); line-height: 1.8; }
.status-birthday h2 { color: var(--rose-deep); }

.countdown { display: flex; justify-content: center; gap: 10px; margin: 22px 0 16px; }
.cd-cell {
  min-width: 74px; padding: 14px 8px;
  background: var(--paper-2);
  border: 1px solid var(--line-soft);
  border-top: 2px solid var(--rose);
  border-radius: 3px;
}
.cd-cell b { display: block; font-family: var(--serif); font-size: 1.65rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.cd-cell span { font-size: 0.72rem; letter-spacing: 0.12em; color: var(--ink-faint); }
.lock-note { margin-top: 6px; }
.preview-link { display: inline-block; margin-top: 14px; font-size: 0.8rem; color: var(--ink-faint); text-decoration: none; border-bottom: 1px dashed var(--line); }
.preview-link:hover { color: var(--rose-deep); border-color: var(--rose); }

/* ---------- 真实照片墙 ---------- */
.gallery { margin-top: 56px; }
.gallery .section-label { margin-bottom: 10px; }
.section-intro {
  max-width: 40em; margin: 14px auto 30px;
  text-align: center; font-family: var(--serif); font-style: italic;
  font-size: 0.95rem; color: var(--ink-soft); line-height: 1.85;
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}
.shot {
  background: #fff;
  padding: 10px 10px 0;
  border-radius: 2px;
  box-shadow: 0 10px 26px rgba(60, 42, 22, 0.16);
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.45s ease;
}
.shot img { display: block; width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: cover; }
.shot:nth-child(odd) { transform: rotate(-1.4deg); }
.shot:nth-child(even) { transform: rotate(1.1deg); }
.shot:hover { transform: rotate(0) translateY(-4px) scale(1.015); box-shadow: 0 20px 44px rgba(60, 42, 22, 0.24); z-index: 2; }
.shot-wide { grid-column: 1 / -1; }
.shot-wide::after { content: none; }
.shot figcaption {
  padding: 11px 4px 13px;
  text-align: center;
  font-family: var(--serif); font-style: italic;
  font-size: 0.82rem; color: var(--ink-soft);
}

/* ---------- 蛋糕 ---------- */
.cake-section { text-align: center; }
.cake {
  position: relative;
  width: 240px;
  margin: 34px auto 8px;
  cursor: pointer;
  transition: transform 0.25s ease;
  filter: drop-shadow(0 14px 20px rgba(60, 42, 22, 0.22));
}
.cake:active { transform: scale(0.97); }
.cake.pop { transform: scale(1.06); }

.candles { display: flex; justify-content: center; gap: 18px; margin-bottom: -4px; }
.candle { position: relative; width: 8px; height: 42px; background: repeating-linear-gradient(45deg, #fffdf8, #fffdf8 5px, #f0cf6f 5px, #f0cf6f 10px); border-radius: 4px 4px 2px 2px; }
.flame {
  position: absolute; left: 50%; top: -20px;
  width: 13px; height: 20px;
  transform: translateX(-50%) scale(0);
  transform-origin: 50% 100%;
  background: radial-gradient(circle at 50% 72%, #fff, var(--gold-soft) 55%, #e07a2f);
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  transition: transform 0.3s ease;
}
.cake.lit .flame { transform: translateX(-50%) scale(1); animation: flicker 0.32s ease-in-out infinite alternate; }
@keyframes flicker {
  from { transform: translateX(-50%) scale(1) rotate(-2deg); }
  to   { transform: translateX(-50%) scale(1.12) rotate(2deg); }
}
.smoke {
  position: absolute; left: 50%; top: -18px;
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(120, 100, 80, 0.5);
  opacity: 0;
}
.cake.blown .smoke { animation: smoke 1.4s ease-out forwards; }
@keyframes smoke {
  0% { opacity: 0.7; transform: translate(-50%, 0) scale(0.6); }
  100% { opacity: 0; transform: translate(-50%, -46px) scale(2.2); }
}

.plate { height: 12px; margin: 0 auto -2px; width: 240px; background: linear-gradient(180deg, #efd9c8, #c9a98f); border-radius: 50%; box-shadow: 0 10px 22px rgba(60, 42, 22, 0.28); }
.layer { position: relative; margin: 0 auto; border-radius: 4px; box-shadow: inset 0 -10px 0 rgba(0,0,0,0.07); }
.layer-1 { width: 200px; height: 44px; background: linear-gradient(180deg, #f6e8d3, #e3cbb0); z-index: 1; }
.layer-2 { width: 168px; height: 40px; margin-top: -6px; background: linear-gradient(180deg, #f7dfe0, #dfa9ad); z-index: 2; }
.layer-3 { width: 140px; height: 36px; margin-top: -6px; background: linear-gradient(180deg, #f6e8d3, #e3cbb0); z-index: 3; }
.drip { position: absolute; top: -1px; left: 12%; width: 16px; height: 18px; background: inherit; filter: brightness(1.05); border-radius: 0 0 10px 10px; }
.drip-b { left: 58%; }

.cake-actions { margin-top: 26px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.btn {
  padding: 13px 32px; font: inherit; font-weight: 600; font-size: 0.95rem; letter-spacing: 0.04em;
  color: var(--paper);
  background: var(--ink);
  border: none; border-radius: 999px; cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease, background 0.2s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-2px); background: var(--rose-deep); box-shadow: 0 12px 26px rgba(142, 51, 72, 0.32); }
.btn:disabled { opacity: 0.34; cursor: not-allowed; }
.cake-tip { font-size: 0.82rem; color: var(--ink-faint); }

/* ---------- 翻转祝福卡 ---------- */
.wishes-section { margin-top: 56px; }
.wishes { margin-top: 28px; display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.flip { perspective: 1200px; height: 156px; opacity: 0; transform: translateY(24px); transition: opacity 0.6s ease, transform 0.6s ease; }
.flip.reveal { opacity: 1; transform: none; }
.flip-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 0.7s cubic-bezier(0.4, 0.2, 0.2, 1); cursor: pointer; }
.flip.flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 9px; padding: 22px;
  text-align: center;
  border-radius: 3px;
  backface-visibility: hidden;
  border: 1px solid var(--line);
}
.flip-front { background: #fff; box-shadow: 0 10px 26px rgba(60, 42, 22, 0.12); }
.flip-front .num { font-family: var(--serif); font-size: 1.4rem; color: var(--rose); }
.flip-front .tt { font-family: var(--serif); font-size: 1.05rem; }
.flip-front .hint { font-size: 0.7rem; letter-spacing: 0.16em; color: var(--ink-faint); }
.flip-back { background: var(--rose-deep); color: var(--paper); transform: rotateY(180deg); font-family: var(--serif); font-style: italic; font-size: 0.98rem; line-height: 1.7; }

/* ---------- 信 ---------- */
.letter { text-align: center; }
.polaroid {
  width: min(430px, 100%);
  margin: 6px auto 26px;
  padding: 12px 12px 30px;
  background: #fffdf8;
  border-radius: 2px;
  box-shadow: var(--shadow-lg);
  transform: rotate(-1.6deg);
  transition: transform 0.5s ease;
}
.polaroid:hover { transform: rotate(0deg) scale(1.02); }
.polaroid img { width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: cover; display: block; }
.polaroid figcaption { margin-top: 14px; font-family: var(--serif); font-style: italic; color: var(--ink-soft); font-size: 0.82rem; letter-spacing: 0.06em; }
.letter-body { text-align: left; max-width: 620px; margin: 0 auto; }
.letter-body p { margin-bottom: 15px; font-family: var(--serif); font-size: 1.02rem; line-height: 2; color: var(--ink); }
.letter-body em { font-style: italic; color: var(--rose-deep); }
.letter-body .sign { margin-top: 24px; text-align: right; font-style: italic; font-size: 0.92rem; color: var(--ink-soft); }

.foot { margin-top: 46px; text-align: center; font-size: 0.74rem; color: var(--ink-faint); line-height: 1.9; }
.foot a { color: inherit; }

/* ---------- 飘浮气球（JS 生成） ---------- */
.balloon {
  position: fixed; bottom: -140px; z-index: 1;
  width: 40px; height: 52px;
  border-radius: 50% 50% 50% 50% / 46% 46% 54% 54%;
  opacity: 0.5;
  pointer-events: none;
  animation: float-up linear forwards;
}
.balloon::after {
  content: ""; position: absolute; left: 50%; top: 100%;
  width: 1px; height: 44px; background: rgba(109, 91, 70, 0.4);
  transform: translateX(-50%);
}
@keyframes float-up { to { transform: translateY(-135vh) rotate(10deg); } }

/* ---------- 提示气泡 ---------- */
.toast {
  position: fixed; left: 50%; top: 74px;
  z-index: 50;
  max-width: min(460px, 88vw);
  padding: 14px 24px;
  text-align: center;
  font-family: var(--serif); font-style: italic;
  font-size: 0.98rem;
  color: var(--paper);
  background: var(--ink);
  border-radius: 2px;
  box-shadow: 0 14px 34px rgba(60, 42, 22, 0.3);
  opacity: 0;
  transform: translate(-50%, -14px) scale(0.94);
  transition: opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* ---------- 响应式 ---------- */
@media (max-width: 620px) {
  .envelope { width: 270px; height: 176px; }
  .env-letter-to { font-size: 1.25rem; margin-top: 24px; }
  .card { padding: 26px 20px; }
  .cover-stamp { right: 0; bottom: 46px; width: 62px; height: 62px; font-size: 0.9rem; }
  .cd-cell { min-width: 62px; padding: 10px 6px; }
  .cd-cell b { font-size: 1.3rem; }
  .cake { width: 210px; }
  .plate { width: 210px; }
  .photo-grid { gap: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; }
}
