/* 生日纪念页 · 极简深色电影感
   原则:画面归 3D,文字归 DOM,两者不抢戏 */

:root {
  --bg: #05060a;
  --ink: #f2eee8;
  --dim: rgba(242, 238, 232, 0.55);
  --faint: rgba(242, 238, 232, 0.28);
  --line: rgba(242, 238, 232, 0.14);
  --accent: #e8b48c;
  --serif: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
  /* 手写感:用系统自带的楷体,零下载、离线可用(iOS 是 Kaiti SC) */
  --hand: "Kaiti SC", "STKaiti", "KaiTi", "楷体", "Songti SC", "STSong",
    "Noto Serif SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

/* 单独一层负责过渡黑场,永远在最上面 */
#fade {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  z-index: 40;
  transition: opacity 0.36s ease;
}

#fade.on {
  opacity: 1;
}

/* ------------------------------------------------------------ 通用层 */

.layer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  padding-top: calc(32px + var(--safe-top));
  padding-bottom: calc(32px + var(--safe-bottom));
  text-align: center;
}

.layer.hidden,
.hidden {
  display: none !important;
}

/* 字幕靠下放,给画面中央的主体(粒子名字、蛋糕)让出位置 */
.caption-bottom {
  justify-content: flex-end;
  padding-bottom: calc(20vh + var(--safe-bottom));
}

.fade-in {
  animation: fadeIn 1.1s ease both;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.eyebrow {
  font-size: 12px;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: var(--faint);
  margin-bottom: 18px;
}

.title {
  font-family: var(--serif);
  font-size: clamp(28px, 8vw, 46px);
  font-weight: 500;
  letter-spacing: 0.1em;
  text-indent: 0.1em;
  line-height: 1.5;
}

.subtitle {
  margin-top: 16px;
  font-size: clamp(13px, 3.6vw, 15px);
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  color: var(--dim);
}

.body-text {
  max-width: 30em;
  font-size: clamp(14px, 4vw, 16px);
  line-height: 2;
  letter-spacing: 0.06em;
  color: rgba(242, 238, 232, 0.82);
}

/* ------------------------------------------------------------ 加载中 */

#loader .loader-text {
  font-size: 13px;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  color: var(--dim);
}

#loader .track {
  position: relative;
  width: min(46vw, 190px);
  height: 1px;
  margin-top: 26px;
  background: var(--line);
  overflow: hidden;
}

#loader .track i {
  position: absolute;
  inset: 0 100% 0 0;
  background: linear-gradient(90deg, transparent, var(--accent));
  transition: right 0.4s ease;
}

#loader .slow {
  margin-top: 18px;
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--faint);
  opacity: 0;
  transition: opacity 0.6s ease;
}

#loader .slow.on {
  opacity: 1;
}

.ghost-btn {
  pointer-events: auto;
  margin-top: 34px;
  padding: 13px 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  cursor: pointer;
  transition: background 0.4s ease, border-color 0.4s ease;
  animation: fadeIn 1.4s ease both;
}

.ghost-btn:hover,
.ghost-btn:active {
  background: rgba(232, 180, 140, 0.12);
  border-color: rgba(232, 180, 140, 0.5);
}

/* ------------------------------------------------------------ 底部提示 */

.hint {
  position: absolute;
  left: 50%;
  bottom: calc(30px + var(--safe-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: var(--faint);
  white-space: nowrap;
  transition: opacity 0.6s ease;
  cursor: pointer;
  padding: 12px 18px;
  border-radius: 999px;
}

.hint.hidden {
  display: block !important;
  opacity: 0;
}

.hint .chev {
  font-style: normal;
  font-size: 11px;
  text-indent: 0;
  animation: bob 2.1s ease-in-out infinite;
}

.hint.is-empty {
  display: none;
}

@keyframes bob {
  0%,
  100% {
    transform: translateY(-1px);
    opacity: 0.5;
  }
  50% {
    transform: translateY(3px);
    opacity: 1;
  }
}

/* ------------------------------------------------------------ 章节小点 */

.dots {
  position: absolute;
  right: calc(16px + var(--safe-top));
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--faint);
  transition: background 0.4s ease, transform 0.4s ease;
}

.dots i.on {
  background: var(--accent);
  transform: scale(1.7);
}

/* ------------------------------------------------------------ 音乐开关 */

.audio-btn {
  position: absolute;
  pointer-events: auto;
  right: calc(14px + var(--safe-top));
  top: calc(14px + var(--safe-top));
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(5, 6, 10, 0.35);
  color: var(--dim);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.3s ease, border-color 0.3s ease;
}

.audio-btn.on {
  color: var(--accent);
  border-color: rgba(232, 180, 140, 0.45);
}

/* ------------------------------------------------------------ 时间轴卡片 */

.card-bottom {
  justify-content: flex-end;
  padding-bottom: calc(8vh + var(--safe-bottom));
}

.card {
  pointer-events: auto;
  width: min(92vw, 460px);
  padding: 18px 22px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(8, 10, 16, 0.66);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  text-align: left;
}

.card-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.card .date {
  font-size: 12px;
  letter-spacing: 0.24em;
  color: var(--accent);
}

.card .tag {
  margin-left: 10px;
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--faint);
}

.card .text {
  margin-top: 10px;
  font-family: var(--serif);
  font-size: clamp(13.5px, 3.8vw, 15.5px);
  line-height: 1.9;
  letter-spacing: 0.04em;
  color: rgba(242, 238, 232, 0.9);
}

/* 屏幕很矮的时候(手机横屏),卡片收紧一点,给照片让位置 */
@media (max-height: 520px) {
  .card {
    padding: 12px 16px;
  }
  .card .text {
    font-size: 12.5px;
    line-height: 1.7;
    margin-top: 6px;
  }
  .card-bottom {
    padding-bottom: calc(5vh + var(--safe-bottom));
  }
}

/* ------------------------------------------------------------ 情书 */

.letter-layer {
  overflow: hidden;
}

/* 背后那张虚化的照片,把信纸托起来 */
.letter-backdrop {
  position: absolute;
  inset: -8%;
  background-size: cover;
  background-position: center;
  /* 图本身已经是预先模糊+压暗的极小图,这里不再用 CSS 滤镜 */
  opacity: 0.95;
  transform: scale(1.06);
}

.letter-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    115% 85% at 50% 42%,
    rgba(10, 10, 14, 0.2) 0%,
    rgba(4, 4, 7, 0.92) 72%
  );
}

/* 飘浮的微尘 */
.motes {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.motes i {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(255, 228, 184, 0.8);
  box-shadow: 0 0 6px rgba(255, 210, 150, 0.75);
  animation-name: mote;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}

@keyframes mote {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(18px, -92vh, 0);
  }
}

/* 缓缓升起、轻轻跳动的心 */
.hearts {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.heart-float {
  position: absolute;
  bottom: -10vh;
  animation-name: heartFloat;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  will-change: transform, opacity;
}

/* 用一个旋转 45 度的方块 + 两个圆拼出心形,不用图片 */
.heart {
  display: block;
  position: relative;
  background: rgba(240, 118, 142, 0.92);
  box-shadow: 0 0 12px rgba(255, 120, 150, 0.5);
  transform-origin: center;
  animation-name: heartBeat;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}

.heart::before,
.heart::after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: inherit;
  box-shadow: inherit;
}

.heart::before {
  top: -50%;
  left: 0;
}

.heart::after {
  top: 0;
  left: 50%;
}

@keyframes heartFloat {
  0% {
    transform: translate3d(0, 0, 0);
    opacity: 0;
  }
  12% {
    opacity: var(--peak, 0.5);
  }
  86% {
    opacity: var(--peak, 0.5);
  }
  100% {
    transform: translate3d(var(--drift, 20px), -118vh, 0);
    opacity: 0;
  }
}

/* 心跳:两下快、一下慢,像真的在跳 */
@keyframes heartBeat {
  0%,
  100% {
    transform: rotate(-45deg) scale(1);
  }
  16% {
    transform: rotate(-45deg) scale(1.24);
  }
  32% {
    transform: rotate(-45deg) scale(0.95);
  }
  48% {
    transform: rotate(-45deg) scale(1.14);
  }
  64% {
    transform: rotate(-45deg) scale(1);
  }
}

.paper {
  position: relative;
  pointer-events: auto; /* #ui 整体是穿透的,信纸要自己接住点击(点一下跳过打字) */
  /* 加宽 + 收紧行距,目标是整封信一页读完,不需要上下滑动 */
  width: min(94vw, 580px);
  max-height: 92vh;
  overflow-y: auto;
  padding: 26px 26px 22px;
  /* 万一还是超长(比如很矮的横屏),让它能滚但别露出滚动条 */
  scrollbar-width: none;
  --letter-size: clamp(13.5px, 3.6vw, 15.5px);
  border: 1px solid rgba(150, 120, 85, 0.35);
  border-radius: 6px;
  /* 暖色信纸:整站都是暗的,这封信是唯一亮起来的东西 */
  background:
    radial-gradient(120% 90% at 15% 0%, rgba(255, 252, 245, 0.9), rgba(255, 255, 255, 0) 58%),
    linear-gradient(158deg, #f7f0e1 0%, #efe4cd 48%, #e5d6bd 100%);
  box-shadow:
    0 30px 70px rgba(0, 0, 0, 0.62),
  text-align: left;
  -webkit-overflow-scrolling: touch;
  /* 这两个是"字发虚"的解药:
     1) 全局开了 antialiased,浅色底上会把笔画削细、显得糊;
     2) 动画结束后不能再留着 transform,否则整块信纸会被当成位图缩放。 */
  -webkit-font-smoothing: auto;
  text-rendering: optimizeLegibility;
}

.paper::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.paper.fade-in {
  animation: paperIn 1.5s cubic-bezier(0.22, 0.9, 0.25, 1) both;
}

@keyframes paperIn {
  from {
    opacity: 0;
    transform: translateY(22px) scale(0.96) rotate(-0.7deg);
  }
  to {
    opacity: 1;
    transform: none; /* 关键:结束时不要留下任何 transform */
  }
}

.paper h2 {
  font-family: var(--hand);
  font-size: clamp(16px, 4.2vw, 18px);
  font-weight: 500;
  letter-spacing: 0.18em;
  color: #8a6a45;
  margin-bottom: 14px;
}

.paper p {
  font-family: var(--hand);
  font-size: var(--letter-size);
  line-height: 1.95;
  letter-spacing: 0.05em;
  color: #3d2f26;
  margin-bottom: 0.85em;
  text-align: left;
}

/* 楷体有些设备上显得软,想要更清晰可以切成宋体 */
.paper-serif,
.paper-serif h2,
.paper-serif p,
.paper-serif .sign {
  font-family: var(--serif);
}

.paper .sign {
  text-align: right;
  font-family: var(--hand);
  color: #6b5443;
  letter-spacing: 0.2em;
  margin-bottom: 0;
}

.seal-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.seal {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  color: #f8e7dd;
  background: radial-gradient(circle at 34% 28%, #c25a44, #7c2a1f 72%);
  box-shadow:
    0 6px 14px rgba(0, 0, 0, 0.4),
    inset 0 1px 2px rgba(255, 255, 255, 0.25),
    inset 0 -6px 12px rgba(0, 0, 0, 0.28);
  transform: rotate(-9deg);
}

.caret::after {
  content: "";
  display: inline-block;
  width: 1px;
  height: 1em;
  margin-left: 2px;
  vertical-align: -0.14em;
  background: var(--accent);
  animation: blink 1s steps(1) infinite;
}

/* 信纸是浅色的,光标要用深色才看得见 */
.paper .caret::after {
  background: #8a6a45;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* ------------------------------------------------------------ 结尾 */

.outro-credit {
  position: absolute;
  left: 50%;
  bottom: calc(16px + var(--safe-bottom));
  transform: translateX(-50%);
  font-size: 10px;
  letter-spacing: 0.14em;
  color: rgba(242, 238, 232, 0.24);
  white-space: nowrap;
}

/* ------------------------------------------------------------ 照片浏览 */

.pswp-gallery {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .fade-in,
  .ghost-btn {
    animation: none;
  }
}
