/* 山居雅事 · 冬。Chrome 61 基线：不用 flex gap / inset / aspect-ratio / clamp()。
 * 动效只用 transform 与 opacity。 */
:root {
  --ink: #2c2a2b;
  --ink-soft: #5d5752;
  --paper: #f6f1e9;
  --paper-2: #ece4d6;
  --green: #5f8f7d;
  --green-soft: #dfeae3;
  --red: #b8423a;
  --peach: #e9a5a4;
  --night: #27313f;
  --gold: #d8b06a;
  --fw: 390px;
  --fh: 520px;
  --safe-top: 0px;
  --safe-bottom: 0px;
  --xhs-right: 0px;
}

[hidden] { display: none !important; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #1f2732;
  color: var(--ink);
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

html.in-xhs { --xhs-right: 76px; }

button { font: inherit; color: inherit; }

.app-shell {
  position: relative;
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #2b3646 0%, #3a4656 40%, #efe8dc 40.1%, #f6f1e9 100%);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- 画框 3:4 ---------- */
.frame-wrap {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  background: #1f2732;
}

.frame {
  position: relative;
  width: var(--fw);
  height: var(--fh);
  overflow: hidden;
  background: linear-gradient(160deg, #cfd8e3, #eef1f5 60%, #dfe5ec);
}

.frame-img {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity .9s ease, transform 1.2s ease;
}

img.img-failed { opacity: 0; }
.has-img-failed::before,
.frame.has-img-failed::after {
  content: "画卷未展开 · 山居仍在";
  position: absolute;
  left: 0;
  right: 0;
  top: 45%;
  text-align: center;
  color: #6b7280;
  font-size: 14px;
  letter-spacing: .2em;
  z-index: 0;
}
.g-pic.has-img-failed::before, .card-pic.has-img-failed::before { content: "画未展开"; font-size: 12px; }

/* 游戏中：底图虚化压暗，揭晓时清晰 */
.play-frame .frame-img { filter: blur(6px) brightness(.72) saturate(.85); transform: scale(1.06); }
.play-frame.revealed .frame-img { filter: none; transform: none; }
.play-frame.revealed .play-layer { opacity: 0; pointer-events: none; }
.sweep-frame .frame-img { filter: none; transform: none; }
.cg-swap { opacity: 0; z-index: 5; }
.cg-swap.in { opacity: 1; filter: none !important; transform: none !important; }
.to-cg .play-layer, .to-cg .sprite, .to-cg .snow { opacity: 0; transition: opacity .8s; }

.play-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  transition: opacity .8s ease;
}
.play-layer.dark { background: rgba(20, 22, 30, .35); }
.play-layer.snowy { background: rgba(246, 248, 252, .35); }

.game-canvas {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  display: block;
}

/* ---------- 落雪（CSS transform） ---------- */
.snow {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 6;
}
.snow i {
  position: absolute;
  top: -12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 4px rgba(255, 255, 255, .8);
  animation-name: snowfall;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  will-change: transform;
}
@keyframes snowfall {
  0% { transform: translate3d(0, 0, 0); }
  50% { transform: translate3d(14px, 50vh, 0); }
  100% { transform: translate3d(-6px, 100vh, 0); }
}

.storm {
  position: absolute;
  left: -20%;
  top: 0;
  width: 140%;
  height: 100%;
  pointer-events: none;
  z-index: 7;
  background: linear-gradient(100deg, rgba(255,255,255,0) 30%, rgba(255,255,255,.28) 48%, rgba(255,255,255,0) 66%);
  animation: gust 5.5s ease-in-out infinite;
}
@keyframes gust {
  0% { transform: translateX(-30%); opacity: .2; }
  50% { opacity: .9; }
  100% { transform: translateX(30%); opacity: .2; }
}
.lantern-on .storm { animation-duration: 9s; opacity: .4; }

/* ---------- 开场：灯笼光与雪球 ---------- */
.lantern-glow {
  position: absolute;
  left: 32%;
  top: 40%;
  width: 22%;
  height: 16%;
  margin-left: -11%;
  margin-top: -8%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 196, 110, .85) 0%, rgba(255, 170, 80, .35) 40%, rgba(255, 170, 80, 0) 70%);
  opacity: .25;
  z-index: 4;
  transform-origin: 50% 0;
  animation: sway 3.2s ease-in-out infinite;
  transition: opacity 1.4s ease;
}
.lantern-on .lantern-glow { opacity: 1; }
@keyframes sway {
  0%, 100% { transform: rotate(-4deg) scale(1); }
  50% { transform: rotate(4deg) scale(1.08); }
}

/* ---------- Q 版小人：外层与画框同大，translate% = 画框% ---------- */
.sprite {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transition: transform 2.6s linear;
  --depth: 1;
}
.sprite-body {
  position: absolute;
  left: 0;
  top: 0;
  height: 22%;
  pointer-events: auto;
  cursor: pointer;
  transform: translate(-50%, -100%) scale(var(--depth));
  transform-origin: 50% 100%;
}
.sprite-flip { height: 100%; transition: transform .3s ease; }
.face-left .sprite-flip { transform: scaleX(-1); }
.sprite-img {
  display: block;
  height: 100%;
  width: auto;
  transform-origin: 50% 100%;
  animation: breathe 3.4s ease-in-out infinite;
  filter: drop-shadow(0 4px 3px rgba(40, 50, 70, .22));
}
@keyframes breathe {
  0%, 100% { transform: scale(1, 1); }
  50% { transform: scale(1.012, 1.028); }
}
.walking .sprite-img { animation: bob .42s ease-in-out infinite alternate; }
@keyframes bob {
  0% { transform: translateY(0) rotate(-2.5deg); }
  100% { transform: translateY(-5%) rotate(2.5deg); }
}
.hop .sprite-img { animation: hop .5s ease-out 1; }
@keyframes hop {
  0% { transform: translateY(0) scale(1, 1); }
  30% { transform: translateY(-9%) scale(.97, 1.04); }
  60% { transform: translateY(0) scale(1.04, .96); }
  100% { transform: translateY(0) scale(1, 1); }
}
.s-xiansheng .sprite-body { height: 25%; }
.s-xiansheng .sprite-img { animation: sway-soft 5s ease-in-out infinite; }
@keyframes sway-soft {
  0%, 100% { transform: rotate(-1deg); }
  50% { transform: rotate(1deg) scale(1.006, 1.014); }
}
.s-taoyao .sprite-body { height: 23%; }
.s-taoling .sprite-body { height: 14%; }
.s-xueqiu .sprite-body { height: 11%; }
.s-xueqiu.pose-xueqiu-dog-sleep .sprite-body { height: 7%; }
.s-xueqiu.pose-xueqiu-boy-run .sprite-body,
.s-xueqiu.pose-xueqiu-boy-dodge .sprite-body,
.s-xueqiu.pose-xueqiu-boy-sulk .sprite-body { height: 14%; }
.pose-taoling-sleep .sprite-img, .pose-xueqiu-dog-sleep .sprite-img { animation-duration: 5s; }


.tea-taoling { z-index: 5; transform: translate(-30%, 92%); transition: transform 1.6s ease-out; }
.tea-taoling .sprite-body { height: 18%; }
.taoling-in .tea-taoling { transform: translate(20%, 92%); }
.tea-frame.revealed .tea-taoling { opacity: 0; transition: opacity .6s; }

.plum-dog { z-index: 5; transform: translate(50%, 96%); }
.plum-dog .sprite-body { height: 12%; pointer-events: none; }
.dog-hint .plum-dog .sprite-img { animation: bob .35s ease-in-out infinite alternate; }
.plum-frame.revealed .plum-dog { opacity: 0; }

.sweep-xs { z-index: 4; transform: translate(80%, 68%); }
.sweep-xs .sprite-body { height: 24%; }

/* ---------- 庭院 ---------- */
.hub-frame .lamp {
  position: absolute;
  left: 46.5%;
  top: 29%;
  width: 16%;
  height: 13%;
  margin-left: -8%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 200, 120, .9), rgba(255, 170, 80, .25) 45%, rgba(255, 170, 80, 0) 70%);
  opacity: 0;
  z-index: 2;
  transform-origin: 50% 0;
  animation: sway 3.6s ease-in-out infinite;
  transition: opacity 1.2s;
  pointer-events: none;
}
.hub-frame.lamp-lit .lamp { opacity: .9; }
.hub-frame.welcome .lamp { opacity: 1; }
.hub-frame.t-night .frame-img { filter: brightness(.7) saturate(.8); }
.hub-frame.t-night::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(18, 26, 52, .55), rgba(26, 34, 64, .3));
}
.hub-frame.t-dusk .frame-img { filter: brightness(.86) sepia(.18); }
.sprites { position: absolute; left: 0; top: 0; width: 100%; height: 100%; z-index: 3; }

.topbar {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  z-index: 8;
  padding: 10px 12px 18px;
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-right: calc(12px + var(--xhs-right));
  background: linear-gradient(180deg, rgba(30, 38, 50, .55), rgba(30, 38, 50, 0));
  color: #fff;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
}
.greet { flex: 1 1 100%; display: flex; align-items: baseline; }
.greet p { margin: 0; text-shadow: 0 1px 3px rgba(0, 0, 0, .4); }
.greet-time {
  font-size: 22px;
  margin-right: 8px !important;
  width: 34px;
  height: 34px;
  line-height: 34px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: 50%;
  flex: 0 0 auto;
}
.greet-line { font-size: 14px; line-height: 1.5; }
.stats { margin-top: 6px; }
.stat {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  margin-right: 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .22);
}
.icon-btn {
  margin-top: 6px;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .6);
  background: transparent;
  color: #fff;
}
.letter-btn {
  position: absolute;
  left: 12px;
  top: 40%;
  z-index: 9;
  padding: 8px 12px;
  border: 0;
  border-radius: 4px;
  background: #fbf3df;
  color: var(--red);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .25);
  animation: nudge 2.4s ease-in-out infinite;
}
@keyframes nudge { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg) translateY(-3px); } }

.bubble {
  position: absolute;
  z-index: 50;
  width: -webkit-max-content;
  width: max-content;
  max-width: 64%;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 252, 246, .96);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
  transform: translate(-50%, -100%) scale(.9);
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
.bubble.show { opacity: 1; transform: translate(-50%, -100%) scale(1); }

/* ---------- 下方面板 ---------- */
.panel {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid rgba(0, 0, 0, .06);
}
.dialog { min-height: 100%; display: flex; flex-direction: column; cursor: pointer; }
.speaker {
  align-self: flex-start;
  font-size: 13px;
  letter-spacing: .15em;
  padding: 2px 10px;
  border-radius: 10px;
  background: var(--green-soft);
  color: var(--green);
  margin-bottom: 8px;
}
.speaker.empty { visibility: hidden; }
.speaker.who-taoling { background: #fbe4e2; color: #c0605c; }
.speaker.who-xueqiu { background: #eef1f6; color: #5a6b85; }
.speaker.who-taoyao { background: #fbeaf0; color: #b05a78; }
.line { margin: 0 0 10px; font-size: 17px; line-height: 1.75; flex: 1 1 auto; }
.line.narr { color: var(--ink-soft); font-size: 16px; }
.fade { animation: fadein .45s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.row { display: flex; flex-wrap: wrap; align-items: center; margin: 0 -4px; }
.row > * { margin: 4px; }
.row.end { justify-content: flex-end; }

.btn {
  min-height: 42px;
  padding: 8px 18px;
  border-radius: 21px;
  border: 1px solid #cdbfa8;
  background: #fffaf2;
  color: var(--ink);
  font-size: 15px;
  cursor: pointer;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.ghost { background: transparent; }
.btn[disabled] { opacity: .5; }
.btn.hold { min-width: 60%; }

.step-title { margin: 0 0 6px; font-size: 17px; }
.step-hint { margin: 0 0 10px; font-size: 14px; color: var(--ink-soft); line-height: 1.6; }
.meter { height: 6px; border-radius: 3px; background: var(--paper-2); overflow: hidden; margin: 6px 0 10px; }
.meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--peach), var(--red)); transform: scaleX(0); transform-origin: 0 50%; transition: transform .25s; }

.choices { display: flex; flex-direction: column; }
.choice {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  text-align: left;
  border-radius: 10px;
  margin-bottom: 8px;
  padding: 10px 14px;
}
.choice small { color: var(--ink-soft); font-size: 12px; margin-left: 10px; flex: 0 0 auto; }

/* ---------- 煮茶 ---------- */
.stove { position: absolute; left: 50%; top: 52%; width: 46%; height: 34%; transform: translate(-50%, -50%); }
.kettle {
  position: absolute;
  left: 18%;
  top: 0;
  width: 64%;
  height: 46%;
  border-radius: 46% 46% 30% 30%;
  background: radial-gradient(ellipse at 40% 30%, #8a6a52, #4a3426 70%);
  overflow: hidden;
  box-shadow: inset 0 -6px 12px rgba(0, 0, 0, .35);
}
.bubbles { position: absolute; left: 10%; top: 18%; width: 80%; height: 40%; border-radius: 50%; background: rgba(180, 160, 120, .4); overflow: hidden; opacity: 0; transition: opacity .6s; }
.boiling .bubbles { opacity: 1; }
.bubbles i { position: absolute; bottom: -6px; width: 5px; height: 5px; border-radius: 50%; background: rgba(255, 255, 255, .85); animation: rise 1.4s ease-in infinite; }
[data-boil="crab"] .bubbles i { width: 8px; height: 8px; animation-duration: 1.1s; }
[data-boil="fish"] .bubbles i { width: 11px; height: 11px; animation-duration: .8s; }
[data-boil="spring"] .bubbles i { width: 13px; height: 13px; animation-duration: .5s; }
@keyframes rise { from { transform: translateY(0); opacity: .9; } to { transform: translateY(-40px); opacity: 0; } }
.brazier {
  position: absolute;
  left: 8%;
  bottom: 0;
  width: 84%;
  height: 52%;
  border-radius: 12% 12% 40% 40%;
  background: linear-gradient(180deg, #a0704f, #6b4632);
  box-shadow: inset 0 8px 14px rgba(0, 0, 0, .3);
}
.flame { position: absolute; left: 30%; top: 8%; width: 40%; height: 46%; transform: scale(.4); transform-origin: 50% 100%; transition: transform .3s; }
.flame i { position: absolute; bottom: 0; width: 40%; height: 100%; border-radius: 50% 50% 40% 40%; background: radial-gradient(ellipse at 50% 80%, #ffd27a, #ff7a3c 60%, rgba(255, 90, 40, 0) 75%); opacity: .4; animation: flicker .5s ease-in-out infinite alternate; }
.flame i:nth-child(1) { left: 0; }
.flame i:nth-child(2) { left: 30%; height: 120%; animation-delay: .15s; }
.flame i:nth-child(3) { left: 60%; animation-delay: .3s; }
.fire-on .flame i { opacity: 1; }
@keyframes flicker { from { transform: scaleY(1); } to { transform: scaleY(.82) translateY(2px); } }
.boil-label {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 8%;
  margin: 0;
  text-align: center;
  color: #fff;
  font-size: 15px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .6);
}

/* ---------- 寻梅 ---------- */
.plum-field { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
.plum-spot {
  position: absolute;
  width: 18%;
  height: 13.5%;
  margin-left: -9%;
  margin-top: -6.75%;
  border: 0;
  border-radius: 50% 50% 46% 46%;
  background: radial-gradient(ellipse at 45% 35%, #ffffff, #e3e9f2 70%, #c9d3e0);
  box-shadow: 0 6px 10px rgba(60, 80, 110, .25);
  padding: 0;
  cursor: pointer;
  transition: transform .3s;
}
.plum-spot:active { transform: scale(.94); }
.plum-spot i { position: absolute; left: 0; top: 0; width: 100%; height: 100%; opacity: 0; transition: opacity .5s; }
.plum-spot.bare i { opacity: .7; background: linear-gradient(70deg, transparent 48%, #7d6a5c 48.5%, #7d6a5c 51%, transparent 51.5%), linear-gradient(20deg, transparent 60%, #7d6a5c 60.5%, #7d6a5c 62.5%, transparent 63%); }
.plum-spot.bloom i {
  opacity: 1;
  background:
    radial-gradient(circle at 30% 40%, #d8434a 0, #d8434a 9%, transparent 10%),
    radial-gradient(circle at 60% 30%, #e05a5f 0, #e05a5f 10%, transparent 11%),
    radial-gradient(circle at 55% 62%, #c93a41 0, #c93a41 9%, transparent 10%),
    radial-gradient(circle at 76% 52%, #e46c70 0, #e46c70 7%, transparent 8%),
    linear-gradient(55deg, transparent 46%, #5d4637 47%, #5d4637 52%, transparent 53%);
}
.plum-spot.bare { opacity: .7; }
.plum-spot.bloom { background: radial-gradient(ellipse, #fff8f6, #f6dede 75%); }
.plum-spot.sniff { animation: glow 1s ease-in-out infinite alternate; }
@keyframes glow { from { transform: scale(1); box-shadow: 0 0 0 rgba(255, 200, 120, 0); } to { transform: scale(1.08); box-shadow: 0 0 18px rgba(255, 190, 110, .9); } }

/* ---------- 写春联 ---------- */
.write-paper {
  position: absolute;
  left: 50%;
  top: 6%;
  width: 22%;
  height: 86%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #a92f2a, #c83f37 30%, #c03a33 70%, #a92f2a);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
  padding: 8% 0;
  opacity: 0;
  transition: opacity .6s;
}
.writing .write-paper { opacity: 1; }
.glyph {
  font-size: calc(var(--fh) * .072);
  line-height: 1;
  color: #1d1a1a;
  font-weight: 700;
  opacity: .08;
  transform: scale(1.3);
  transition: opacity .5s ease, transform .5s ease;
}
.glyph.inked { opacity: 1; transform: scale(1); }
.couplet-overlay { position: absolute; left: 0; top: 0; width: 100%; height: 100%; z-index: 4; pointer-events: none; animation: fadein 1.2s ease; }
.couplet-strip {
  position: absolute;
  left: 37.6%;
  top: 63.5%;
  width: 9.5%;
  height: 19.5%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
  transform: rotate(-3deg);
}
.couplet-strip span { font-size: calc(var(--fh) * .022); line-height: 1; color: #241a18; font-weight: 700; opacity: .9; }
.couplet-square {
  position: absolute;
  left: 64%;
  top: 59.5%;
  width: 18%;
  height: 6%;
  font-size: calc(var(--fh) * .036);
  line-height: calc(var(--fh) * .06);
  text-align: center;
  color: #241a18;
  font-weight: 700;
  transform: rotate(5deg) skewX(-12deg);
  opacity: .88;
}

/* ---------- 庭院面板 ---------- */
.acts { display: flex; flex-wrap: wrap; margin: 0 -4px; }
.act {
  flex: 1 1 46%;
  margin: 4px;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #ddd0bb;
  background: #fffaf2;
  position: relative;
  cursor: pointer;
}
.act.main { flex-basis: 100%; background: linear-gradient(120deg, #2f3b4a, #4a5a6c); color: #fff; border-color: #2f3b4a; }
.act strong { display: block; font-size: 16px; }
.act small { display: block; margin-top: 2px; font-size: 12px; color: var(--ink-soft); }
.act.main small { color: rgba(255, 255, 255, .78); }
.act-tag { position: absolute; right: 10px; top: 8px; font-size: 11px; color: var(--green); }
.act.main .act-tag { color: var(--gold); }
.act.done { border-style: dashed; }
.act[disabled] { opacity: .45; }
.toolbar { display: flex; margin: 8px -4px 0; }
.toolbar .btn { flex: 1 1 50%; margin: 4px; }
.season-note { margin: 8px 0 0; text-align: center; font-size: 12px; color: var(--ink-soft); letter-spacing: .1em; }

/* ---------- 弹层 ---------- */
.modal {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  background: rgba(20, 24, 32, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top));
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  animation: fadein .35s ease;
}
.card {
  width: 100%;
  max-width: 340px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--paper);
  border-radius: 6px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .35);
  border: 6px solid #fffaf2;
  outline: 1px solid #d9c9ad;
}
.card-pic { position: relative; height: 0; padding-top: 100%; overflow: hidden; background: #e9e2d6; }
.card-pic img { position: absolute; left: 0; top: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%; }
.card-body { padding: 14px 16px 12px; }
.card-title { margin: 0 0 6px; font-size: 13px; letter-spacing: .3em; color: var(--red); }
.card-poem { margin: 0; font-size: 18px; line-height: 1.7; }
.card-by { margin: 4px 0 8px; font-size: 12px; color: var(--ink-soft); text-align: right; }
.card-detail { margin: 0 0 8px; font-size: 13px; color: var(--ink-soft); line-height: 1.6; }
.chips { margin: 0 -3px 6px; }
.chip { display: inline-block; margin: 3px; padding: 2px 9px; border-radius: 10px; font-size: 12px; background: var(--green-soft); color: var(--green); }
.chip.warm { background: #fbe4e2; color: var(--red); }
.chip.soft { background: var(--paper-2); color: var(--ink-soft); }

.note-card, .letter {
  width: 100%;
  max-width: 340px;
  background: #fbf6ea;
  border-radius: 6px;
  padding: 18px 18px 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .35);
}
.note-title { margin: 0 0 8px; font-size: 13px; letter-spacing: .3em; color: var(--gold); }
.letter { background: linear-gradient(180deg, #fbf3df, #f5ead2); border-left: 3px solid var(--red); }
.letter-to { margin: 0 0 6px; font-size: 16px; }
.letter-body { margin: 0; text-indent: 2em; font-size: 16px; line-height: 1.9; }
.letter-from { margin: 8px 0; text-align: right; font-size: 14px; color: var(--ink-soft); }
.letter-gift { margin: 0 0 8px; font-size: 13px; color: var(--red); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24%;
  z-index: 200;
  max-width: 80%;
  padding: 8px 14px;
  border-radius: 16px;
  background: rgba(30, 36, 46, .88);
  color: #fff;
  font-size: 14px;
  transform: translate(-50%, 10px);
  opacity: 0;
  transition: opacity .3s, transform .3s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 签匣 / 闲话 页面 ---------- */
.page {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  padding: 12px 16px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-right: calc(16px + var(--xhs-right));
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.page-head { display: flex; align-items: center; margin-bottom: 8px; }
.page-head h1 { margin: 0 0 0 12px; font-size: 19px; font-weight: 600; white-space: nowrap; }
.gallery { display: flex; flex-wrap: wrap; margin: 0 -5px; }
.g-item { flex: 0 0 auto; width: calc(50% - 10px); margin: 5px; padding: 0; border: 1px solid #ddd0bb; background: #fffaf2; border-radius: 6px; overflow: hidden; cursor: pointer; text-align: center; }
.g-pic { position: relative; height: 0; padding-top: 120%; background: #e9e2d6; overflow: hidden; }
.g-pic img { position: absolute; left: 0; top: 0; width: 100%; height: 100%; object-fit: cover; }
.g-pic span { position: absolute; left: 0; right: 0; top: 45%; color: #a99c88; font-size: 13px; letter-spacing: .3em; }
.g-title { display: block; padding: 6px 0; font-size: 14px; }
.g-item.locked { opacity: .6; cursor: default; }

.chat-page { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
.chat-portrait { height: 120px; display: flex; justify-content: center; flex: 0 0 auto; }
.chat-portrait img { height: 100%; width: auto; }
.chat-log { flex: 1 1 auto; overflow-y: auto; padding: 8px 2px; min-height: 120px; }
.msg { display: flex; margin: 6px 0; }
.msg span { max-width: 78%; padding: 8px 12px; border-radius: 14px; font-size: 15px; line-height: 1.6; word-break: break-all; white-space: pre-wrap; }
.msg.him span { background: #fffaf2; border: 1px solid #e3d6c1; }
.msg.me { justify-content: flex-end; }
.msg.me span { background: var(--green); color: #fff; }
.chat-status { margin: 4px 0; min-height: 18px; font-size: 12px; color: var(--ink-soft); }
.chat-bar { display: flex; align-items: center; }
.chat-input { flex: 1 1 auto; min-width: 0; height: 42px; padding: 0 12px; border-radius: 21px; border: 1px solid #cdbfa8; background: #fff; font: inherit; font-size: 15px; margin-right: 8px; -webkit-user-select: text; user-select: text; }

/* ---------- 结局 ---------- */
.ending-frame .frame-img { animation: thaw 6s ease forwards; }
@keyframes thaw { from { transform: scale(1.06); opacity: .6; } to { transform: scale(1); opacity: 1; } }
.petals { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; overflow: hidden; }
.petals i { position: absolute; top: -10px; width: 9px; height: 7px; border-radius: 60% 0 60% 0; background: #f3b6bd; animation: petal 9s linear infinite; }
@keyframes petal {
  0% { transform: translate3d(0, 0, 0) rotate(0deg); }
  100% { transform: translate3d(40px, 100vh, 0) rotate(540deg); }
}
.ending-title {
  position: absolute;
  left: 0;
  right: 0;
  top: 8%;
  text-align: center;
  color: #fff;
  z-index: 5;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 1.6s, transform 1.6s;
  text-shadow: 0 2px 8px rgba(80, 40, 40, .5);
}
.ending-title p { margin: 0; font-size: 30px; letter-spacing: .5em; }
.ending-title small { font-size: 14px; letter-spacing: .4em; }
.titled .ending-title { opacity: 1; transform: none; }

/* ---------- 启动 ---------- */
.boot { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #2b3646; color: #fff; }
.boot-title { margin: 0; font-size: 28px; letter-spacing: .4em; }
.boot-sub { margin: 10px 0 0; font-size: 14px; letter-spacing: .5em; opacity: .7; animation: fadein 1.6s ease infinite alternate; }

/* ---------- 页面隐藏：暂停一切 CSS 动画 ---------- */
.is-hidden *, .is-hidden *::before, .is-hidden *::after { animation-play-state: paused !important; }

@media (prefers-reduced-motion: reduce) {
  .snow i, .storm, .petals i { animation: none; opacity: .4; }
}

/* 开场镜头：缓推，雪球出现时再推近一点 */
.opening-frame .frame-img { transition: transform 4s ease; transform: scale(1.02); }
.opening-frame.lantern-on .frame-img { transform: scale(1.05) translate(1.5%, 0); }
.opening-frame.dog-on .frame-img { transform: scale(1.09) translate(4%, -2%); }
