:root {
  --bg: #f6ede1;
  --paper: #fffaf2;
  --ink: #5e4740;
  --ink-soft: #94796f;
  --pink: #eba3ae;
  --pink-deep: #d9798a;
  --pink-pale: #f8e1e2;
  --line: #e6d6c3;
  --sage: #8c946f;
  --shadow: 0 6px 18px rgba(110, 80, 60, .13);
  --hand: "Kaiti SC", "STKaiti", "KaiTi", "楷体", "Songti SC", serif;
  --sans: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  background-image: radial-gradient(rgba(150, 110, 80, .07) 1.2px, transparent 1.2px);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.8;
  overflow-x: hidden;
}
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
.decoration-library { position: absolute; width: 0; height: 0; overflow: hidden; }
:focus-visible { outline: 2px solid var(--pink-deep); outline-offset: 3px; }

/* ---------- 密码页 ---------- */
.lock {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 16px;
  background: var(--bg);
  transition: opacity .8s ease, visibility .8s;
}
.lock.open { opacity: 0; visibility: hidden; }
.envelope {
  position: relative; width: min(340px, 100%);
  background: var(--paper);
  border-radius: 14px;
  padding: 56px 24px 28px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 2px dashed var(--pink);
}
.seal {
  position: absolute; top: -26px; left: 50%; transform: translateX(-50%);
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--pink-deep); color: #fff; font-size: 24px;
  box-shadow: 0 3px 8px rgba(217, 121, 138, .45);
  animation: beat 1.4s ease-in-out infinite;
}
.lock-title { font-family: var(--hand); font-size: 22px; }
.lock-hint { color: var(--ink-soft); font-size: 14px; margin: 4px 0 18px; }
#lock-form { display: flex; gap: 8px; }
#lock-form input {
  flex: 1; min-width: 0;
  font-size: 20px; letter-spacing: 6px; text-align: center;
  padding: 10px; border-radius: 10px;
  border: 2px solid var(--pink-pale); background: #fff; color: var(--ink);
  outline: none;
}
#lock-form input:focus { border-color: var(--pink); }
#lock-form input[aria-invalid="true"] { border-color: var(--pink-deep); }
#lock-form button {
  flex: none; border: 0; border-radius: 10px; padding: 0 18px;
  background: var(--pink-deep); color: #fff; font-size: 16px; cursor: pointer;
  font-family: var(--hand);
}
#lock-form button:disabled { opacity: .7; }
.shake { animation: shake .4s; }

/* ---------- 飘浮爱心 ---------- */
.hearts { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.hearts span {
  position: absolute; bottom: -40px;
  color: var(--pink); opacity: .3;
  animation: float linear infinite;
}

main { position: relative; z-index: 1; }

/* ---------- 首屏 ---------- */
.hero {
  min-height: 100vh; min-height: 100svh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 40px 16px;
  position: relative;
}
.hero-small { letter-spacing: 4px; color: var(--ink-soft); font-size: 14px; }
.hero h1 {
  font-family: var(--hand);
  font-size: clamp(44px, 13vw, 76px);
  line-height: 1.25; margin: 10px 0 28px;
  color: var(--pink-deep);
  text-shadow: 3px 3px 0 var(--pink-pale);
}
.keepsake { position: relative; }
.pressed-flower {
  position: absolute; left: -46px; bottom: -34px;
  width: 64px; height: 124px;
  transform: rotate(-16deg);
  opacity: .85; pointer-events: none;
}
.counter {
  position: relative;
  background: var(--paper); border-radius: 16px;
  padding: 18px 28px; box-shadow: var(--shadow);
  transform: rotate(-1.5deg);
}
.counter::before { /* 胶带 */
  content: ""; position: absolute; top: -12px; left: 50%;
  width: 90px; height: 24px; transform: translateX(-50%) rotate(3deg);
  background: rgba(240, 214, 160, .75);
}
.counter .days { font-family: var(--hand); font-size: 22px; }
.counter .days b { font-size: 46px; color: var(--pink-deep); margin: 0 4px; font-variant-numeric: tabular-nums; }
.counter .hms { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.counter .since { font-size: 12px; color: var(--ink-soft); letter-spacing: 2px; }
.scroll-tip {
  position: absolute; bottom: 28px; font-size: 14px; color: var(--ink-soft); text-decoration: none;
  animation: bob 1.8s ease-in-out infinite;
}

/* ---------- 通用 section ---------- */
.section { max-width: 760px; margin: 0 auto; padding: 56px 16px; }
.section h2 {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 36px;
  font-family: var(--hand); font-size: 28px; font-weight: normal;
}
.section h2::before, .section h2::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.section h2 span { padding: 0 6px; background: linear-gradient(transparent 60%, var(--pink-pale) 60%); }
.reveal { opacity: 0; transform: translateY(24px); transition: opacity .8s ease, transform .8s ease; }
.reveal.in { opacity: 1; transform: none; }

/* ---------- 拍立得 ---------- */
.polaroid {
  background: #fffdf8; padding: 10px 10px 12px;
  box-shadow: var(--shadow);
  transform: rotate(var(--r, 0deg));
  position: relative; cursor: zoom-in;
  transition: transform .3s;
}
.polaroid:hover { transform: rotate(0) scale(1.02); }
.polaroid::before {
  content: ""; position: absolute; top: -10px; left: 50%; z-index: 1;
  width: 70px; height: 20px; transform: translateX(-50%) rotate(-4deg);
  background: var(--tape, rgba(235, 163, 174, .5));
}
.polaroid img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; background: var(--pink-pale); }
.polaroid figcaption { font-family: var(--hand); text-align: center; margin-top: 8px; font-size: 15px; }
.ph {
  width: 100%; aspect-ratio: 4 / 5;
  display: grid; place-items: center; text-align: center;
  font-size: 13px; color: var(--ink-soft); padding: 8px;
  background: repeating-linear-gradient(45deg, var(--pink-pale) 0 10px, #fdf3f1 10px 20px);
}

/* ---------- 时间线 ---------- */
.timeline { list-style: none; position: relative; padding-left: 30px; }
.timeline::before {
  content: ""; position: absolute; left: 9px; top: 6px; bottom: 6px;
  border-left: 2px dashed var(--pink);
}
.t-item { position: relative; margin-bottom: 44px; }
.t-item::before {
  content: "♥"; position: absolute; left: -31px; top: 0;
  width: 22px; height: 22px; line-height: 22px; text-align: center;
  color: var(--pink-deep); background: var(--bg); font-size: 16px;
}
.t-date { font-size: 13px; letter-spacing: 2px; color: var(--pink-deep); }
.t-card { background: var(--paper); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); margin-top: 6px; }
.t-card h3 { font-family: var(--hand); font-size: 22px; font-weight: normal; }
.t-card p { color: var(--ink); margin-top: 4px; }
.t-photos { display: flex; justify-content: center; gap: 14px; margin: 20px 0 6px; }
.t-photos .polaroid { flex: 0 1 260px; min-width: 0; }
.t-photos.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px 14px; }

/* ---------- 相册 ---------- */
.gallery { columns: 2; column-gap: 18px; }
.gallery .polaroid { break-inside: avoid; margin: 0 0 26px; display: inline-block; width: 100%; }
@media (min-width: 640px) { .gallery { columns: 3; } }

/* ---------- 信 ---------- */
.letter {
  background-color: var(--paper);
  background-image: repeating-linear-gradient(transparent 0 35px, rgba(217, 121, 138, .22) 35px 36px);
  background-position: 0 22px;
  padding: 22px 24px 30px; border-radius: 6px;
  box-shadow: var(--shadow);
  font-family: var(--hand); font-size: 18px; line-height: 36px;
  transform: rotate(.6deg);
}
.letter p { text-indent: 2em; }
.letter p:first-child { text-indent: 0; }
.letter .sign { text-align: right; margin-top: 12px; }

/* ---------- 心愿 ---------- */
.wishes { list-style: none; display: grid; gap: 12px; }
.wishes li {
  background: var(--paper); border-radius: 10px; padding: 12px 16px 12px 46px;
  position: relative; box-shadow: var(--shadow); cursor: pointer; user-select: none;
  font-family: var(--hand); font-size: 18px;
}
.wishes li::before {
  content: ""; position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--pink);
}
.wishes li.done::before { content: "♥"; color: #fff; background: var(--pink-deep); border-color: var(--pink-deep); text-align: center; line-height: 17px; font-size: 13px; }

/* ---------- 蛋糕 ---------- */
.cake-section { text-align: center; padding-bottom: 30px; }
.cake-tip { color: var(--ink-soft); margin-bottom: 30px; }
.cake { position: relative; width: 240px; height: 250px; margin: 0 auto; cursor: pointer; }
.layer { position: absolute; left: 50%; transform: translateX(-50%); border-radius: 14px 14px 10px 10px; }
.layer.bottom { bottom: 20px; width: 240px; height: 80px; background: #f3c1c8; }
.layer.top { bottom: 98px; width: 180px; height: 66px; background: #fbe0e2; }
.layer::before { /* 奶油 */
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 24px;
  border-radius: 14px 14px 0 0;
  background:
    radial-gradient(circle at 12px 0, #fff 10px, transparent 11px) 0 12px / 24px 12px repeat-x,
    linear-gradient(#fff, #fff) 0 0 / 100% 12px no-repeat;
}
.layer::after { /* 小草莓点点 */
  content: ""; position: absolute; left: 14px; right: 14px; bottom: 16px; height: 10px;
  background: radial-gradient(circle, var(--pink-deep) 4px, transparent 5px) 0 0 / 30px 10px repeat-x;
}
.plate { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); width: 280px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow); }
.candles { position: absolute; bottom: 160px; left: 0; right: 0; display: flex; justify-content: center; gap: 6px; }
.candle { position: relative; font-family: "Arial Rounded MT Bold", var(--sans); font-weight: 800; font-size: 60px; line-height: 1; color: var(--pink-deep); -webkit-text-stroke: 3px #fff; paint-order: stroke; }
.flame {
  position: absolute; left: 50%; top: -30px; width: 16px; height: 26px; margin-left: -8px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: radial-gradient(circle at 50% 70%, #fff6c8 20%, #ffc94a 55%, #ff8a3d 100%);
  box-shadow: 0 0 18px 6px rgba(255, 201, 74, .55);
  transform-origin: 50% 90%;
  animation: flicker .25s ease-in-out infinite alternate;
  transition: opacity .4s, transform .4s;
}
.cake.out .flame { opacity: 0; transform: scale(.2); animation: none; }
.cake-msg { font-family: var(--hand); font-size: 22px; color: var(--pink-deep); margin-top: 26px; opacity: 0; transition: opacity 1s .5s; }
.cake.out ~ .cake-msg { opacity: 1; }

.footer { text-align: center; padding: 30px 16px 60px; font-family: var(--hand); color: var(--ink-soft); }
.footer b { color: var(--pink-deep); }

/* ---------- 灯箱 / 音乐 / 彩带 ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 60; background: rgba(50, 36, 30, .86);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 16px; cursor: zoom-out;
}
.lightbox img { max-height: 80vh; border: 8px solid #fff; border-bottom-width: 40px; }
.lightbox p { color: var(--ink); font-family: var(--hand); margin-top: -34px; font-size: 16px; }
.lightbox-close {
  position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px;
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .15); color: #fff; font-size: 26px; line-height: 1; cursor: pointer;
}
.music-btn {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 40;
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--pink-deep); color: #fff; font-size: 20px; box-shadow: var(--shadow); cursor: pointer;
}
.music-btn.playing { animation: spin 3s linear infinite; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 55; }

/* ---------- 聊天 ---------- */
.chat-btn {
  position: fixed; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom, 0px)); z-index: 40;
  width: 52px; height: 52px; border-radius: 50%; border: 0;
  background: var(--paper); font-size: 24px; box-shadow: var(--shadow); cursor: pointer;
}
.chat-btn .dot { position: absolute; top: 4px; right: 4px; width: 12px; height: 12px; border-radius: 50%; background: #f0566b; border: 2px solid #fff; }
.chat {
  position: fixed; left: 0; right: 0; top: 0; z-index: 70;
  height: 100%; height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--bg);
  background-image: radial-gradient(rgba(150, 110, 80, .07) 1.2px, transparent 1.2px);
  background-size: 22px 22px;
}
.chat-head {
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  padding: 8px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--paper); box-shadow: 0 1px 0 var(--line);
  text-align: center; font-family: var(--hand); font-size: 19px;
}
.chat-head b { font-weight: normal; }
.chat-close { border: 0; background: none; font-size: 30px; line-height: 1; color: var(--ink); cursor: pointer; }
.chat-list { flex: 1; overflow-y: auto; padding: 14px 12px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.chat-more { display: block; margin: 0 auto 12px; border: 0; background: none; color: var(--ink-soft); font-size: 13px; cursor: pointer; }
.chat-empty { text-align: center; color: var(--ink-soft); margin-top: 30vh; font-family: var(--hand); }
.chat-time { text-align: center; font-size: 12px; color: var(--ink-soft); margin: 14px 0 8px; }
.msg { display: flex; align-items: flex-end; gap: 8px; margin: 8px 0; }
.msg.me { flex-direction: row-reverse; }
.avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-size: 20px; line-height: 1;
  background: var(--pink-pale); box-shadow: 0 0 0 2px #fff;
}
.avatar.bq { background: #dfe8f1; }
.bubble {
  max-width: 72%; padding: 9px 13px; border-radius: 16px 16px 16px 4px;
  background: #fffdf8; box-shadow: 0 2px 6px rgba(110, 80, 60, .08);
  white-space: pre-wrap; word-break: break-word; line-height: 1.6;
}
.msg.me .bubble { background: var(--pink); color: #fff; border-radius: 16px 16px 4px 16px; }
.msg.pending .bubble { opacity: .6; }
.msg.failed .bubble { outline: 1.5px solid #f0566b; cursor: pointer; }
.chat-form {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--paper); box-shadow: 0 -1px 0 var(--line);
}
.chat-form textarea {
  flex: 1; min-width: 0; resize: none; max-height: 120px;
  font: inherit; font-size: 16px; line-height: 1.5;
  padding: 8px 12px; border-radius: 18px; border: 1.5px solid var(--line);
  background: #fff; color: var(--ink); outline: none;
}
.chat-form textarea:focus { border-color: var(--pink); }
.chat-form button { flex: none; height: 40px; border: 0; border-radius: 20px; padding: 0 18px; background: var(--pink-deep); color: #fff; font-size: 15px; cursor: pointer; }

@keyframes beat { 0%, 100% { transform: translateX(-50%) scale(1); } 50% { transform: translateX(-50%) scale(1.12); } }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@keyframes float { to { transform: translateY(-115vh) rotate(30deg); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(6px); } }
@keyframes flicker { from { transform: rotate(-3deg) scaleY(1); } to { transform: rotate(3deg) scaleY(1.08); } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal { opacity: 1; transform: none; }
  html { scroll-behavior: auto; }
}
