/* ============================================================
   C’est la vie. · 记忆盒子（V4）
   深绿布面硬盒 + 铜扣 + 麻绳。物件可拖出把玩，拖回吸附。
   ============================================================ */

:root {
  --cloth: #2c3d33;
  --cloth-d: #223028;
  --cloth-l: #3a4f42;
  --brass: #b08a3e;
  --brass-l: #d9b878;
  --paper: #f3ead6;
  --paper-2: #e8dcc4;
  --ink: #2b2419;
  --ink-soft: #5b4f3d;
  --red: #a5342a;
  --f-serif: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  --f-hand: "Hannotate SC", "HanziPen SC", "Kaiti SC", "STKaiti", cursive;
  --f-sans: "PingFang SC", "Hiragino Sans GB", -apple-system, sans-serif;
}

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

html, body {
  margin: 0; padding: 0; height: 100%;
  background: #171410;
  overscroll-behavior: none;
}

body {
  font-family: var(--f-serif);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.app {
  position: relative;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(90% 60% at 50% 0%, #3a3226 0%, #241e16 55%, #171410 100%);
}

/* ---------------- HUD ---------------- */
.hud {
  position: absolute; left: 0; right: 0; top: 0;
  z-index: 40;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 14px 0;
  display: flex; align-items: flex-start; justify-content: space-between;
  pointer-events: none;
}
.hud-title { display: flex; flex-direction: column; gap: 3px; }
.hud-mark {
  font-family: var(--f-serif); font-size: 13px; letter-spacing: .06em;
  color: rgba(244, 234, 214, .9);
}
.hud-sub {
  font-family: var(--f-sans); font-size: 9.5px; letter-spacing: .16em;
  color: rgba(228, 210, 182, .5);
}
.hud-actions { pointer-events: auto; display: flex; align-items: center; gap: 8px; }

.found {
  font-family: var(--f-sans); font-size: 10px;
  color: rgba(240, 230, 210, .72);
  background: rgba(20, 26, 22, .6);
  border: 1px solid rgba(176, 138, 62, .28);
  border-radius: 12px;
  padding: 4px 9px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.found b { font-size: 12px; color: var(--brass-l); }

.mus {
  display: inline-flex; align-items: center; gap: 5px;
  height: 28px; padding: 0 10px 0 8px;
  border-radius: 14px;
  border: 1px solid rgba(176, 138, 62, .28);
  background: rgba(20, 26, 22, .6);
  color: rgba(240, 230, 210, .75);
  font-family: var(--f-sans); font-size: 10px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.mus .slash { opacity: 1; transition: opacity .2s; }
.mus.is-playing .slash { opacity: 0; }
.mus.is-playing { color: var(--brass-l); border-color: rgba(217, 184, 120, .5); }

/* ---------------- 舞台 ---------------- */
.stage {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 64px 14px 40px;
}

.box {
  position: relative;
  width: min(94vw, 400px);
  height: min(76vh, 620px);
  perspective: 1600px;
  perspective-origin: 50% 0%;
}

.box-shadow {
  position: absolute; left: 6%; right: 6%; bottom: -14px; height: 34px;
  background: radial-gradient(closest-side, rgba(0,0,0,.55), transparent 78%);
  filter: blur(3px);
}

/* ---------------- 盒盖 ---------------- */
.lid {
  position: absolute; left: 0; right: 0; top: 0;
  height: 22%;
  z-index: 30;
  transform-origin: 50% 0%;
  transform: rotateX(0deg);
  transition: transform 1.1s cubic-bezier(.3,.85,.2,1);
  transform-style: preserve-3d;
}
.box.open .lid { transform: rotateX(-112deg); }
.lid-cloth {
  position: absolute; inset: 0;
  border-radius: 10px 10px 4px 4px;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.018) 0 2px, transparent 2px 4px),
    repeating-linear-gradient(-45deg, rgba(0,0,0,.05) 0 2px, transparent 2px 4px),
    linear-gradient(170deg, var(--cloth-l), var(--cloth) 60%, var(--cloth-d));
  box-shadow: inset 0 2px 0 rgba(255,255,255,.10), 0 8px 22px rgba(0,0,0,.45);
}
.lid-rim {
  position: absolute; left: 2%; right: 2%; bottom: -5px; height: 10px;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--cloth-d), #1a251f);
  box-shadow: 0 3px 8px rgba(0,0,0,.4);
}
.lid-plate {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 10px 18px;
  border: 1px solid rgba(176, 138, 62, .45);
  border-radius: 3px;
  background: rgba(20, 26, 22, .25);
}
.lp-brand {
  font-family: var(--f-serif); font-size: 13px; letter-spacing: .08em;
  color: var(--brass-l);
}
.lp-sub {
  font-family: var(--f-sans); font-size: 7.5px; letter-spacing: .2em;
  color: rgba(217, 184, 120, .6);
}
.lid-string {
  position: absolute; left: 50%; bottom: -16px;
  width: 2px; height: 22px; margin-left: -1px;
  background: #8a7048;
  box-shadow: 0 0 0 1px rgba(0,0,0,.2);
}
.lid-hint {
  position: absolute; left: 0; right: 0; bottom: -34px;
  text-align: center;
  font-family: var(--f-sans); font-size: 9px; letter-spacing: .14em;
  color: rgba(217, 184, 120, .6);
  animation: hintPulse 2.4s ease-in-out infinite;
}
@keyframes hintPulse { 0%,100% { opacity: .45; } 50% { opacity: .95; } }
.box.open .lid-hint { opacity: 0; }

/* ---------------- 盒体 ---------------- */
.body {
  position: absolute; left: 0; right: 0; top: 20%; bottom: 0;
  border-radius: 6px 6px 12px 12px;
  background: linear-gradient(170deg, var(--cloth), var(--cloth-d));
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.06),
    inset 0 -6px 14px rgba(0,0,0,.35),
    0 18px 40px rgba(0,0,0,.5);
  overflow: hidden;
}
.body-inner {
  position: absolute; inset: 8px;
  border-radius: 4px;
  background: linear-gradient(180deg, #241d15, #1b1610);
  box-shadow: inset 0 6px 18px rgba(0,0,0,.6);
  overflow: hidden;
}
.body-inner::after {
  content: "";
  position: absolute; inset: 0; z-index: 12;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.022) 0 2px, transparent 2px 5px),
    repeating-linear-gradient(-45deg, rgba(0,0,0,.05) 0 2px, transparent 2px 5px),
    radial-gradient(80% 60% at 50% 18%, rgba(70,58,44,.5), transparent 72%),
    linear-gradient(180deg, #221a13, #14100b);
  transition: opacity .7s .15s;
  pointer-events: none;
}
.box.open .body-inner::after { opacity: 0; }

/* 层 */
.tray, .main, .secret {
  position: absolute; left: 0; right: 0;
  transition: transform .7s cubic-bezier(.3,.85,.2,1), opacity .5s;
}
.tray {
  top: 0; height: 38%;
  z-index: 6;
  background: linear-gradient(180deg, #6b5236, #5a442c);
  border-bottom: 3px solid #3a2c1c;
  box-shadow: 0 6px 16px rgba(0,0,0,.5);
}
.tray.lifted {
  transform: translateY(-104%);
  opacity: .25;
}
.main {
  top: 38%; bottom: 16%;
  background: linear-gradient(180deg, #4a3a28, #3a2c1e);
}
.secret {
  bottom: 0; height: 16%;
  background: #2a2016;
  border-top: 2px solid #1a130c;
}
.layer-label {
  position: absolute; left: 10px; top: 7px;
  font-family: var(--f-sans); font-size: 7.5px; letter-spacing: .14em;
  color: rgba(240, 226, 200, .42);
  pointer-events: none;
  z-index: 3;
}

/* 托盘下的盒底纸条 */
.under-tray {
  position: absolute; left: 0; right: 0; top: 0; height: 38%;
  z-index: 5;
  display: grid; place-items: center;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.06) 0 1px, transparent 1px 22px),
    linear-gradient(180deg, #3a2c1e, #2e2216);
}
.ut-note {
  padding: 12px 18px;
  background: #f2e8d2;
  border: 1px solid rgba(120, 96, 60, .3);
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  transform: rotate(-1.6deg);
  font-family: var(--f-hand); font-size: 13px;
  color: #5a4630;
}

/* 托盘把手 */
.tray-handle {
  position: absolute; left: 50%; bottom: -13px;
  transform: translateX(-50%);
  z-index: 8;
  padding: 4px 14px;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--brass-l), var(--brass));
  border: 1px solid #8a6a2a;
  font-family: var(--f-sans); font-size: 8px; letter-spacing: .1em;
  color: #3a2c10;
  box-shadow: 0 3px 8px rgba(0,0,0,.45);
}
.tray.lifted .tray-handle { display: none; }

/* 夹层隔板 */
.secret-board {
  position: absolute; inset: 0;
  z-index: 5;
  display: grid; place-items: center;
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,.12) 0 2px, transparent 2px 24px),
    linear-gradient(180deg, #6b5236, #5a442c);
  border-top: 2px solid #7a5f3e;
  font-family: var(--f-sans); font-size: 8px; letter-spacing: .14em;
  color: rgba(240, 226, 200, .55);
  transition: transform .6s cubic-bezier(.3,.85,.2,1), opacity .4s;
}
.secret.open .secret-board { transform: translateY(102%); opacity: 0; }

/* ---------------- 物件 ---------------- */
.obj {
  position: absolute;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  cursor: grab;
  touch-action: none;
  transition: transform .2s, box-shadow .2s, filter .2s;
  will-change: transform;
}
.obj:active { cursor: grabbing; }
.obj .glyph {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  font-size: 17px;
  border-radius: 3px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25), inset 0 -2px 4px rgba(0,0,0,.18);
}
.obj .glyph::before {
  content: "";
  position: absolute; inset: 0;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.035) 0 1px, transparent 1px 4px);
  pointer-events: none;
}
.obj .tag {
  position: absolute; left: 50%; bottom: -12px;
  transform: translateX(-50%);
  white-space: nowrap;
  font-family: var(--f-sans); font-size: 7px;
  color: rgba(240, 226, 200, .62);
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}
.obj.found .tag { opacity: 1; }
.obj.found .glyph::after {
  content: "";
  position: absolute; right: 2px; top: 2px;
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--brass-l);
}
.obj.dragging {
  z-index: 900 !important;
  transform: scale(1.18) rotate(0deg) !important;
  box-shadow: 0 14px 30px rgba(0,0,0,.6);
  filter: brightness(1.08);
  cursor: grabbing;
}
.obj.snapping { transition: transform .35s cubic-bezier(.3,1.3,.5,1), left .35s, top .35s; }

/* 各类物件的底色 */
.o-paper .glyph { background: linear-gradient(160deg, #f7efdc, #e8dcc4); color: #5a4630; }
.o-photo .glyph { background: #fdf8ec; border: 3px solid #fff; color: #5a4630; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.o-metal .glyph { background: linear-gradient(160deg, #d9d4c8, #a8a294); color: #4a463c; }
.o-fabric .glyph { background: linear-gradient(160deg, #6a7a8c, #4a5a6c); color: #e8eef4; }
.o-red .glyph { background: linear-gradient(160deg, #c0503e, #9a3528); color: #f8e8dc; }
.o-green .glyph { background: linear-gradient(160deg, #5c6e5a, #3f4e3e); color: #e4ece0; }
.o-dark .glyph { background: linear-gradient(160deg, #3a3a42, #24242a); color: #d8dce4; }
.o-pink .glyph { background: linear-gradient(160deg, #e8a8c2, #c9789a); color: #fff; }
.o-gold .glyph { background: linear-gradient(160deg, #e8c46a, #b08a3e); color: #3a2c10; }
.o-white .glyph { background: linear-gradient(160deg, #f6f2e6, #ded6c4); color: #5a4630; }

/* 特定形状 */
.o-ticket .glyph { clip-path: polygon(0 8%, 6% 0, 94% 0, 100% 8%, 100% 92%, 94% 100%, 6% 100%, 0 92%); }
.o-round .glyph { border-radius: 50%; }
.o-envelope .glyph { clip-path: polygon(0 0, 50% 46%, 100% 0, 100% 100%, 0 100%); }

/* ---------------- 拖拽跟随 ---------------- */
.drag-ghost {
  position: fixed; left: 0; top: 0;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(1.15);
  transition: opacity .15s;
}
.drag-ghost.on { opacity: 1; }

/* ---------------- 提示 ---------------- */
.hint {
  position: absolute; left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  margin: 0;
  text-align: center;
  font-family: var(--f-sans); font-size: 9px; letter-spacing: .12em;
  color: rgba(217, 184, 120, .45);
  pointer-events: none;
}

/* ---------------- 特写 ---------------- */
.sheet {
  position: fixed; inset: 0; z-index: 200;
  visibility: hidden; pointer-events: none;
}
.sheet.on { visibility: visible; pointer-events: auto; }
.sheet-bg {
  position: absolute; inset: 0;
  background: rgba(14, 12, 9, .55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity .35s;
}
.sheet.on .sheet-bg { opacity: 1; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  top: calc(env(safe-area-inset-top, 0px) + 52px);
  background: var(--paper);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 40px rgba(0,0,0,.5);
  transform: translateY(100%);
  transition: transform .4s cubic-bezier(.2,.85,.2,1);
  overflow: hidden;
}
.sheet.on .sheet-panel { transform: translateY(0); }
.sheet-close {
  position: absolute; right: 12px; top: 12px; z-index: 5;
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid rgba(120, 96, 60, .25);
  background: rgba(255, 252, 244, .92);
  color: rgba(70, 54, 34, .8);
  font-size: 17px; line-height: 1;
}
.sheet-scroll {
  position: absolute; inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 20px 34px;
  overscroll-behavior: contain;
}
.sh-kicker {
  font-family: var(--f-sans); font-size: 8.5px; letter-spacing: .18em;
  color: rgba(110, 92, 64, .8);
  padding-right: 34px;
}
.sh-title {
  margin: 8px 0 0;
  font-family: var(--f-serif); font-size: 21px; line-height: 1.34; font-weight: 600;
}
.sh-hook {
  margin: 7px 0 0;
  font-family: var(--f-sans); font-size: 11px; line-height: 1.6;
  color: var(--ink-soft);
}
.sh-body { margin-top: 14px; }
.sh-foot {
  margin-top: 16px; padding-top: 10px;
  border-top: 1px dashed rgba(120, 96, 60, .28);
  font-family: var(--f-sans); font-size: 7.5px; line-height: 1.6;
  color: rgba(130, 114, 88, .72);
}

/* 特写内容 */
.vb-chat {
  display: flex; align-items: baseline; gap: 7px;
  padding: 5px 0;
  border-bottom: 1px dotted rgba(120, 96, 60, .18);
  font-family: var(--f-serif); font-size: 12.5px; line-height: 1.5;
}
.vb-who {
  flex: 0 0 auto;
  font-family: var(--f-sans); font-size: 8px;
  padding: 1px 4px; border-radius: 3px;
  background: rgba(90, 110, 140, .8); color: #fff;
}
.vb-chat.her .vb-who { background: rgba(150, 80, 100, .82); }
.vb-chat.punch .vb-txt { font-family: var(--f-hand); font-size: 14.5px; color: var(--red); }
.vb-at { flex: 0 0 auto; font-family: var(--f-sans); font-size: 7.5px; color: rgba(130, 114, 88, .7); }
.vb-note {
  margin: 10px 0 0;
  font-family: var(--f-sans); font-size: 9px; line-height: 1.65;
  color: rgba(96, 80, 56, .8);
}
.vb-img { width: 52%; margin: 0 auto; display: block; border: 5px solid #fff; box-shadow: 0 4px 14px -6px rgba(50,34,16,.5); }
.vb-gap {
  margin-top: 12px; padding: 11px 13px;
  border-left: 3px solid rgba(165, 52, 42, .55);
  background: rgba(165, 52, 42, .05);
}
.vb-gap b { display: block; font-family: var(--f-serif); font-size: 12.5px; color: var(--red); }
.vb-gap p { margin: 6px 0 0; font-family: var(--f-sans); font-size: 9px; line-height: 1.7; color: rgba(96, 80, 56, .85); }
.vb-next {
  display: block; width: 100%; margin-top: 14px;
  padding: 10px 14px;
  border: 1px dashed rgba(120, 96, 60, .4);
  border-radius: 4px;
  background: rgba(255, 252, 244, .7);
  font-family: var(--f-sans); font-size: 10px;
  color: #6b5436; text-align: left;
}

/* 奶茶 */
.vb-tea {
  display: flex; flex-direction: column; align-items: center;
  padding: 10px 0 6px;
  background: linear-gradient(180deg, rgba(232,69,124,.06), transparent);
  border-radius: 6px;
  cursor: pointer;
}
.vb-cup {
  position: relative;
  width: 48px; height: 66px;
  border-radius: 4px 4px 10px 10px;
  background: linear-gradient(180deg, #f6e2ea, #e8c4d4);
  border-top: 5px solid #f2c4d6;
}
.vb-cup::after {
  content: ""; position: absolute; left: 8px; right: 8px; bottom: 10px; height: 18px;
  background: repeating-linear-gradient(180deg, rgba(140,90,70,.22) 0 3px, transparent 3px 6px);
}
.vb-count {
  margin-top: 6px;
  font-family: var(--f-sans); font-size: 9px;
  color: rgba(110, 92, 64, .8);
}
.vb-reveal {
  margin-top: 10px;
  text-align: center;
  font-family: var(--f-hand); font-size: 19px;
  color: var(--red);
  opacity: 0;
  transition: opacity .5s;
}
.vb-reveal.on { opacity: 1; }

/* 信封 */
.vb-env { position: relative; min-height: 130px; cursor: pointer; margin-top: 4px; }
.vb-env .letter {
  position: absolute; left: 0; right: 0; top: 0;
  padding: 12px 14px;
  background: #fdf8ea;
  border: 1px solid rgba(100, 80, 50, .22);
  transform: translateY(40px) scale(.96);
  opacity: 0;
  transition: transform .5s, opacity .4s;
  z-index: 1;
}
.vb-env.open .letter { transform: translateY(0) scale(1); opacity: 1; }
.vb-env .env {
  position: absolute; left: 0; right: 0; bottom: 0; height: 88px;
  z-index: 2;
  display: grid; place-items: center;
  background: linear-gradient(180deg, #e8dcc4, #dccfb2);
  border: 1px solid rgba(100, 80, 50, .28);
  clip-path: polygon(0 0, 50% 40%, 100% 0, 100% 100%, 0 100%);
  font-family: var(--f-sans); font-size: 8.5px;
  color: rgba(110, 92, 64, .8);
  transition: transform .5s, opacity .4s;
}
.vb-env.open .env { transform: translateY(56px); opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  .lid, .tray, .secret-board, .sheet-panel, .obj { transition: none; }
  .lid-hint { animation: none; }
}
