/* 信笺夜灯 · 唯一视觉：暖米纸 + 床头灯光晕 + 手写标题 */
:root {
  --paper: #f6efe3;
  --paper-2: #fbf7ee;
  --ink: #4a3f35;
  --ink-soft: #8a7d6e;
  --accent: #c96f4a;
  --accent-soft: #e8b89d;
  --gold: #b98a3e;
  --line: #d9cbb4;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: #191410;
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.fancy { font-family: "Kaiti SC", "STKaiti", "KaiTi", "Noto Serif SC", serif; }

#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
}
/* 夜灯：中央暖光，随 data-lit 增强（1 拆信 → 3 全亮） */
#glow {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: radial-gradient(ellipse 90% 70% at 50% 42%, rgba(255, 214, 150, var(--lit, .35)), rgba(255, 190, 120, calc(var(--lit, .35) * .5)) 45%, #191410 78%);
  transition: background 1.6s ease;
}
#glow::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .5;
  background-image: radial-gradient(rgba(255, 255, 255, .06) 1px, transparent 1px);
  background-size: 3px 3px;
  mix-blend-mode: overlay;
}
/* 纸面 */
#paper {
  position: absolute;
  z-index: 1;
  inset: 4.5% 5%;
  border-radius: 6px;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, .65), transparent 30%),
    linear-gradient(340deg, rgba(120, 90, 40, .06), transparent 40%),
    var(--paper);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55), 0 2px 0 rgba(255, 255, 255, .5) inset;
  display: flex;
  flex-direction: column;
}
#paper::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  pointer-events: none;
}
#paper::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .35;
  background-image: repeating-linear-gradient(0deg, transparent 0 27px, rgba(160, 130, 80, .14) 27px 28px);
}

#screen {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: calc(env(safe-area-inset-top) + 26px) 24px calc(env(safe-area-inset-bottom) + 30px);
  overflow: hidden;
}
#screen > section { width: 100%; max-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
[hidden] { display: none !important; }
.soft { color: var(--ink-soft); }
.status { color: var(--gold); font-size: 15px; }

/* 蜡封章 */
.seal {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff7ea;
  font-size: 22px;
  background: radial-gradient(circle at 35% 30%, #e08a5f, #b04a28 70%);
  box-shadow: 0 6px 16px rgba(140, 60, 20, .45), inset 0 0 0 3px rgba(255, 240, 220, .35);
  animation: seal-breathe 2.6s ease-in-out infinite;
}
@keyframes seal-breathe { 50% { transform: scale(1.06) rotate(-2deg); } }

/* 胶带贴角 */
.tape {
  position: absolute;
  width: 92px;
  height: 26px;
  background: rgba(222, 197, 156, .8);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .12);
  opacity: .9;
}
.tape.tl { top: -12px; left: 26px; transform: rotate(-38deg); }
.tape.br { bottom: -12px; right: 26px; transform: rotate(-38deg); }

/* 旅程脚印（顶部） */
#trail { position: absolute; top: calc(env(safe-area-inset-top) + 12px); left: 0; right: 0; z-index: 6; display: flex; justify-content: center; gap: 10px; }
#trail i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-soft); opacity: .3; transition: .4s; }
#trail i.on { opacity: 1; background: var(--accent); transform: scale(1.35); box-shadow: 0 0 10px rgba(201, 111, 74, .8); }

/* 通用文字 */
.eyebrow { margin: 0; font-size: 12px; letter-spacing: .35em; color: var(--gold); }
.title-lg { margin: 0; font-size: 30px; font-weight: 700; line-height: 1.5; }
.body-text { margin: 0; font-size: 17px; line-height: 2.1; white-space: pre-wrap; }

/* 通用按钮 */
.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 12px 26px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  color: #fff7ea;
  background: linear-gradient(160deg, #d3805a, #b04a28);
  box-shadow: 0 10px 22px rgba(140, 60, 20, .35);
  cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }

/* 入场动画 */
.a-up { animation: rise .9s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(26px); } to { opacity: 1; transform: none; } }
.a-pop { animation: pop .7s cubic-bezier(.34, 1.56, .64, 1) both; }
@keyframes pop { 0% { opacity: 0; transform: scale(.5); } 70% { transform: scale(1.06); } 100% { opacity: 1; transform: none; } }
.a-zoom { animation: zoom-in .9s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes zoom-in { from { opacity: 0; transform: scale(.82); } to { opacity: 1; transform: none; } }

/* 媒体 */
.photo-frame {
  position: relative;
  background: var(--paper-2);
  padding: 8px 8px 10px;
  box-shadow: 0 12px 26px rgba(70, 45, 20, .25);
  transform: rotate(-1.2deg);
}
.photo-frame:nth-child(even) { transform: rotate(1.4deg); }
.photo-frame img, .photo-frame video { display: block; max-width: 100%; max-height: 56vh; }
.photo-cap { margin: 8px 0 0; font-size: 13px; color: var(--ink-soft); text-align: center; }

/* 回忆时间线 */
.timeline { display: flex; flex-direction: column; gap: 0; width: 100%; max-width: 420px; }

/* 照片墙：错落两列 + 按张数自适应布局 */
.wall { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: flex-start; width: 100%; max-width: 430px; max-height: 56vh; overflow: auto; padding: 6px 2px; }
.wall .photo-frame { width: calc(50% - 14px); }
.wall .photo-frame.add { display: flex; align-items: center; justify-content: center; min-height: 150px; border: 2px dashed var(--accent-soft); color: var(--accent); cursor: pointer; font-size: 14px; background: rgba(255, 253, 246, .6); }
.wall .photo-frame .mini { position: absolute; top: -10px; right: -8px; min-width: 30px; min-height: 30px; padding: 4px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: #fffdf6; box-shadow: 0 2px 8px rgba(70, 45, 20, .25); }
.wall .photo-frame .mini.danger { color: #b04a28; }
.wall::-webkit-scrollbar { width: 4px; }
.wall::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.wall-empty { color: var(--ink-soft); font-size: 14px; }
/* 1 张：大图独占 */
.wall.n1 .photo-frame { width: min(86%, 320px); }
.wall.n1 .photo-frame img { max-height: 44vh; }
/* 2 张：两张并排（加照片位自动换行到下一行） */
.wall.n2 .photo-frame { width: calc(50% - 8px); }
/* 3 张：一大二小 */
.wall.n3 .photo-frame:nth-child(1) { width: 100%; }
.wall.n3 .photo-frame:nth-child(1) img { max-height: 34vh; }
.wall.n3 .photo-frame:nth-child(2), .wall.n3 .photo-frame:nth-child(3) { width: calc(50% - 8px); }
.wall.n3 .photo-frame.add { width: calc(50% - 8px); }
/* 4 张：田字 */
.wall.n4 .photo-frame { width: calc(50% - 8px); }
.wall.n4 .photo-frame img, .wall.n2 .photo-frame img { aspect-ratio: 1; object-fit: cover; height: auto; max-height: none; }
/* 5+：两列流式 */
.wall.n5 .photo-frame { width: calc(50% - 14px); }
/* 展开查看大图 */
.zoom-overlay { position: absolute; inset: 0; z-index: 50; background: rgba(25, 20, 16, .8); display: flex; align-items: center; justify-content: center; padding: 20px; }
.zoom-overlay .photo-frame { transform: none; }
.zoom-overlay img { max-height: 74vh; max-width: 100%; }
.memory { display: flex; gap: 14px; align-items: flex-start; text-align: left; }
.memory .when {
  flex: 0 0 auto;
  min-width: 64px;
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--accent);
  color: #fff7ea;
  font-size: 12px;
  text-align: center;
  box-shadow: 0 4px 10px rgba(140, 60, 20, .3);
}
.memory .what { font-size: 15px; line-height: 1.8; padding: 2px 0 18px; border-left: 2px dashed var(--accent-soft); margin-left: 2px; padding-left: 16px; flex: 1; }
.memory:last-child .what { border-left-color: transparent; }
.memory .what-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.memory img { max-width: 100%; border-radius: 6px; margin: 8px 0 4px; box-shadow: 0 8px 18px rgba(70, 45, 20, .2); display: block; }
.mini.danger { color: #b04a28; border-color: #e3c4b4; }
.mini.danger:hover { background: #fbeee8; }

/* 小卡片 */
.mini-cards { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 400px; }
.mini-card {
  position: relative;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px 14px;
  box-shadow: 0 8px 20px rgba(70, 45, 20, .16);
  text-align: left;
  cursor: pointer;
  transition: transform .35s ease;
}
.mini-card h4 { margin: 0 0 6px; font-size: 15px; color: var(--accent); }
.mini-card p { margin: 0; font-size: 14px; line-height: 1.9; }
.mini-card .fold { position: absolute; right: 12px; top: 12px; font-size: 12px; color: var(--gold); }
.mini-card.open .fold { display: none; }
.mini-card:not(.open) p { display: none; }
.mini-card:not(.open) { padding-bottom: 14px; }
.mini-card.open { cursor: default; transform: rotate(0) !important; }

/* 隐藏信：闭合态小信封；点开后信纸抽出平铺整页 */
.envelope {
  position: relative;
  width: min(62%, 240px);
  aspect-ratio: 3 / 2;
  cursor: pointer;
  filter: drop-shadow(0 16px 30px rgba(70, 40, 15, .35));
  transition: transform .4s ease, opacity .6s ease;
}
.envelope:hover { transform: translateY(-6px); }
.envelope .body {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: linear-gradient(170deg, #efdcc0, #e2c9a4);
}
.envelope .body::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: linear-gradient(200deg, transparent 48%, rgba(255, 250, 240, .5) 49%, transparent 56%);
}
.envelope .flap {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 58%;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: linear-gradient(180deg, #e6cfa9, #d9bd92);
  transform-origin: top;
  transition: transform .7s cubic-bezier(.6, 0, .3, 1);
  z-index: 2;
}
.envelope.open .flap { transform: rotateX(180deg); }
.envelope .note {
  position: absolute;
  left: 7%;
  right: 7%;
  top: 10%;
  bottom: 12%;
  background: #fffdf6;
  box-shadow: 0 4px 12px rgba(70, 40, 15, .2);
  padding: 14px;
  font-size: 14px;
  line-height: 2;
  color: var(--ink);
  text-align: left;
  overflow: auto;
  transform: translateY(30%) scale(.9);
  opacity: 0;
  transition: .6s cubic-bezier(.3, .8, .3, 1) .35s;
  z-index: 1;
}
.envelope.open .note { transform: none; opacity: 1; z-index: 3; }
.envelope.open .note img { max-width: 100%; border-radius: 4px; margin-top: 8px; }

/* 开信后：纸面切换为"信纸模式"，信抽出铺满整页 */
#screen.letter-mode .envelope .flap { opacity: 0; transition: opacity .5s; }
#screen.letter-mode .envelope {
  position: absolute;
  inset: 0;
  width: auto;
  aspect-ratio: auto;
  filter: none;
  cursor: default;
  transform: none !important;
  transition: all .8s cubic-bezier(.3, .8, .3, 1);
  z-index: 9;
}
#screen.letter-mode .envelope .body,
#screen.letter-mode .envelope .flap { opacity: 0; transition: opacity .4s .3s; }
#screen.letter-mode .envelope .note {
  position: absolute;
  inset: 0;
  transform: none;
  opacity: 1;
  font-size: 18px;
  line-height: 2.3;
  padding: 30px 26px;
  transition: all .8s cubic-bezier(.3, .8, .3, 1);
  z-index: 3;
}
/* 信纸模式下后续提示藏进 note 内，隐藏原有 next-hint */
#screen.letter-mode ~ .next-hint, #screen.letter-mode .next-hint { display: none; }

/* 生日信纸 */
.letter {
  width: 100%;
  max-width: 420px;
  max-height: 62vh;
  overflow: auto;
  text-align: left;
  font-size: 16px;
  line-height: 2.2;
  white-space: pre-wrap;
  padding: 6px 8px;
}
.letter::-webkit-scrollbar { width: 4px; }
.letter::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

/* 蛋糕蜡烛（彩蛋） */
.cake {
  position: relative;
  width: 150px;
  height: 92px;
  margin: 10px auto 0;
  border-radius: 10px 10px 14px 14px;
  background: linear-gradient(180deg, #f3dfc0, #dfbf94);
  box-shadow: 0 16px 30px rgba(70, 40, 15, .3);
}
.cake::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -8px;
  height: 16px;
  border-radius: 10px;
  background:
    radial-gradient(circle at 10px 8px, #fff7ea 8px, transparent 9px) 0 0/40px 16px repeat-x,
    linear-gradient(180deg, #fffdf6, #f6ead2);
}
.candles { position: absolute; left: 0; right: 0; bottom: 100%; height: 50px; }
.candle { position: absolute; bottom: 0; width: 9px; height: 42px; margin-left: -4px; border-radius: 3px; background: repeating-linear-gradient(45deg, #fff7ea, #fff7ea 5px, var(--accent) 5px, var(--accent) 10px); }
.flame {
  position: absolute;
  left: 50%;
  bottom: 100%;
  width: 11px;
  height: 17px;
  margin-left: -5px;
  transform-origin: 50% 100%;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: radial-gradient(circle at 50% 72%, #fff7c2, #ffb347 58%, rgba(255, 120, 40, 0) 78%);
  filter: drop-shadow(0 0 8px rgba(255, 190, 80, .9));
  animation: flicker .7s ease-in-out infinite alternate;
}
@keyframes flicker { from { transform: scale(1) rotate(-2deg); } to { transform: scale(1.12) rotate(2deg); } }
.candle.out .flame { animation: none; opacity: 0; transform: scale(.2); transition: .35s; }
.wish { margin: 0; font-size: 26px; font-weight: 700; color: var(--accent); animation: pop .7s cubic-bezier(.34, 1.56, .64, 1) both; }
.candle-hint { margin: 0; font-size: 14px; }

/* 进度提示 */
.next-hint { margin: 4px 0 0; font-size: 12px; color: var(--ink-soft); animation: hint-pulse 1.8s ease-in-out infinite; }
@keyframes hint-pulse { 50% { opacity: .4; } }

/* 编辑态 */
.edit-text, .edit-cap, .title-lg[contenteditable], .body-text[contenteditable], .letter[contenteditable], .when[contenteditable], .what[contenteditable], .photo-cap[contenteditable], .mini-card h4[contenteditable], .mini-card p[contenteditable] {
  outline: none;
  min-width: 2em;
}
[contenteditable]:focus { outline: 2px dashed var(--accent-soft); outline-offset: 5px; border-radius: 6px; }
[contenteditable]:empty::before { content: attr(data-ph); color: var(--ink-soft); opacity: .55; pointer-events: none; }
.edit-text { width: 100%; min-height: 5.5em; text-align: left; font-size: 15px; line-height: 2; white-space: pre-wrap; background: rgba(255, 253, 246, .75); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.secret-edit { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.secret-edit img { max-width: 120px; border-radius: 6px; box-shadow: 0 6px 14px rgba(70, 45, 20, .2); }
.mini { appearance: none; border: 1px solid var(--line); background: rgba(255, 253, 246, .85); color: var(--accent); border-radius: 8px; padding: 5px 12px; font-size: 13px; font-family: inherit; cursor: pointer; }
.mini-card .mini { position: static; display: inline-block; margin-top: 8px; }

/* 工具条（编辑器） */
.bar { position: absolute; left: 0; right: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: 10px 14px; }
.bar-top { top: 0; padding-top: calc(env(safe-area-inset-top) + 10px); justify-content: space-between; }
.bar-bottom { bottom: 0; padding-bottom: calc(env(safe-area-inset-bottom) + 12px); justify-content: center; flex-wrap: wrap; }
.bar .chip {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 253, 246, .92);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(70, 45, 20, .18);
}
.bar .chip.primary { background: linear-gradient(160deg, #d3805a, #b04a28); color: #fff7ea; border-color: transparent; }
.bar .chip:disabled { opacity: .4; }
.step-tag { font-size: 12px; color: var(--gold); letter-spacing: .2em; }

/* 底部面板与覆盖层（编辑器） */
.sheet, .overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(25, 20, 16, .55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.sheet { align-items: flex-end; padding: 0; background: rgba(25, 20, 16, .35); }
.sheet .panel, .result-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .4);
  text-align: center;
}
.sheet .panel { border-radius: 16px 16px 0 0; max-height: 72%; overflow: auto; text-align: left; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel-head b { font-size: 15px; }
.panel-head button { border: 0; background: none; color: var(--ink-soft); font-size: 14px; }
.music-row { display: flex; align-items: center; gap: 10px; background: rgba(255, 253, 246, .8); border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; cursor: pointer; }
.music-row.active { border-color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent-soft); }
.music-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.upload-line { display: block; font-size: 13px; color: var(--ink-soft); margin-top: 10px; }
.upload-line input { display: block; margin-top: 6px; max-width: 100%; }
#qr { display: inline-block; background: #fffdf6; padding: 8px; border-radius: 10px; min-height: 40px; min-width: 40px; }
#qr img, #qr canvas { display: block; }
#cardLink { font-size: 12px; word-break: break-all; color: var(--ink-soft); margin: 12px 0; }
.result-actions { display: flex; flex-direction: column; gap: 8px; }
.result-actions button, .result-actions a { display: block; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 253, 246, .8); color: var(--ink); text-decoration: none; font-size: 14px; }
.result-actions .primary { background: linear-gradient(160deg, #d3805a, #b04a28); color: #fff7ea; border-color: transparent; font-weight: 600; }

#toast { position: absolute; left: 50%; bottom: 96px; transform: translate(-50%, 20px); z-index: 60; background: rgba(30, 24, 18, .95); color: #fff7ea; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; max-width: 80vw; }
#toast.show { opacity: .95; transform: translate(-50%, 0); }

/* 粒子画布 */
#fx { position: absolute; inset: 0; z-index: 5; width: 100%; height: 100%; pointer-events: none; }

/* 桌面 9:16 居中 */
@media (min-width: 768px) {
  #stage { width: min(100vw, 56.25vh); box-shadow: 0 0 120px rgba(0, 0, 0, .7); }
  #paper { inset: 4% 6%; }
}
