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

html, body {
  width: 100%; height: 100%;
  background: #1a1014;
  font-family: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
  color: #f5e9dc;
  overflow: hidden;
  user-select: none;
}

#app {
  position: relative;
  width: 100%; max-width: 960px;
  height: 100%; max-height: 640px;
  margin: 0 auto;
  top: 50%; transform: translateY(-50%);
  overflow: hidden;
  box-shadow: 0 0 40px rgba(0,0,0,.6);
}

/* ---------- 背景 ---------- */
#bg {
  position: absolute; inset: 0;
  transition: background 1.2s ease;
  background: linear-gradient(180deg, #3b1d2a, #1a1014);
}
#bg::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 120%, rgba(0,0,0,.55), transparent 60%);
}
.bg-home    { background: linear-gradient(180deg, #7a9e9f 0%, #c9d6c3 55%, #5e7461 100%) !important; }
.bg-gate    { background: linear-gradient(180deg, #d98b5f 0%, #a33b2f 50%, #4a1a17 100%) !important; }
.bg-hall    { background: linear-gradient(180deg, #c99a3d 0%, #8a2b22 55%, #2d0f0c 100%) !important; }
.bg-room    { background: linear-gradient(180deg, #caa98a 0%, #8c6450 55%, #3a261d 100%) !important; }
.bg-garden  { background: linear-gradient(180deg, #0f1c3a 0%, #2c3e6b 50%, #1b2a2a 100%) !important; }
.bg-banquet { background: linear-gradient(180deg, #25163d 0%, #7d2e4a 50%, #d8964a 100%) !important; }
.bg-cold    { background: linear-gradient(180deg, #4b5563 0%, #2b3038 60%, #111418 100%) !important; }
.bg-hunt    { background: linear-gradient(180deg, #e0a96d 0%, #8f6b3a 50%, #3b3a1f 100%) !important; }
.bg-inn     { background: linear-gradient(180deg, #5b4636 0%, #8a6a4a 50%, #2e2118 100%) !important; }
.bg-study   { background: linear-gradient(180deg, #3d2b1f 0%, #7a5530 50%, #2a1a10 100%) !important; }
.bg-temple  { background: linear-gradient(180deg, #6b5a3e 0%, #b39661 50%, #3a2f1f 100%) !important; }
.bg-snow    { background: linear-gradient(180deg, #9aa7b8 0%, #d7dde6 45%, #56606e 100%) !important; }

/* 花瓣 */
#petals { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.petal {
  position: absolute; top: -20px;
  width: 12px; height: 10px;
  background: #f7b8c6;
  border-radius: 12px 0 12px 0;
  opacity: .8;
  animation: fall linear infinite;
}
@keyframes fall {
  to { transform: translate(-120px, 700px) rotate(540deg); }
}

/* ---------- 通用 ---------- */
.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

.btn {
  display: block;
  width: 220px; margin: 12px auto;
  padding: 12px 0;
  font-family: inherit; font-size: 18px; letter-spacing: 4px;
  color: #fff4e6;
  background: linear-gradient(180deg, rgba(196,74,58,.9), rgba(120,32,30,.9));
  border: 1px solid #e8c38a;
  border-radius: 4px;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(232,195,138,.4); }
.btn.small { width: 140px; font-size: 15px; padding: 8px 0; }

/* ---------- 标题 ---------- */
#title-screen { background: linear-gradient(180deg, rgba(90,20,30,.3), rgba(20,8,12,.8)); }
.title-box { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; }
.title-box h1 {
  font-size: 72px; letter-spacing: 20px;
  color: #f3d8a6;
  text-shadow: 0 0 20px rgba(243,120,80,.6), 2px 2px 0 #6b1d1d;
  margin-bottom: 10px;
}
.subtitle { font-size: 16px; color: #e7cdb3; letter-spacing: 3px; margin-bottom: 36px; opacity: .85; }

/* ---------- 游戏页 ---------- */
#stats {
  position: absolute; top: 12px; left: 12px;
  display: flex; gap: 10px; flex-wrap: wrap;
  z-index: 5;
}
.stat {
  background: rgba(20,10,14,.6);
  border: 1px solid rgba(232,195,138,.5);
  border-radius: 3px;
  padding: 4px 10px;
  font-size: 13px;
  min-width: 96px;
}
.stat .bar { height: 4px; background: rgba(255,255,255,.15); margin-top: 3px; border-radius: 2px; overflow: hidden; }
.stat .bar i { display: block; height: 100%; background: linear-gradient(90deg, #f0a35e, #e8505b); transition: width .5s; }

#menu-bar { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; z-index: 5; }
#menu-bar button {
  font-family: inherit; font-size: 13px;
  padding: 5px 10px;
  color: #f5e9dc;
  background: rgba(20,10,14,.6);
  border: 1px solid rgba(232,195,138,.5);
  border-radius: 3px; cursor: pointer;
}
#menu-bar button:hover { background: rgba(160,50,40,.8); }

/* 立绘 */
#portrait {
  position: absolute; bottom: 0; left: 50%;
  transform: translateX(-50%);
  height: 94%;
  display: flex; align-items: flex-end; justify-content: center;
  transition: opacity .4s;
  pointer-events: none;
}
#portrait.empty { opacity: 0; }
.figure {
  height: 100%;
  -webkit-mask-image: linear-gradient(180deg, #000 80%, transparent 100%);
  mask-image: linear-gradient(180deg, #000 80%, transparent 100%);
  animation: appear .4s ease;
}
@keyframes appear { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* 对话框 */
#dialog {
  position: absolute; left: 16px; right: 16px; bottom: 16px;
  height: 150px;
  padding: 26px 26px 18px;
  background: linear-gradient(180deg, rgba(40,16,22,.88), rgba(24,10,14,.95));
  border: 1px solid #c9a36a;
  border-radius: 6px;
  cursor: pointer;
  z-index: 4;
}
#dialog::before {
  content: ""; position: absolute; inset: 4px;
  border: 1px solid rgba(201,163,106,.35); border-radius: 4px; pointer-events: none;
}
#speaker {
  position: absolute; top: -16px; left: 24px;
  padding: 4px 18px;
  font-size: 16px; letter-spacing: 3px;
  background: linear-gradient(180deg, #b8403a, #7a211f);
  border: 1px solid #e8c38a; border-radius: 3px;
}
#speaker:empty { display: none; }
#text { font-size: 18px; line-height: 1.8; }
#text.narration { color: #e0d2c0; font-style: italic; }
#next-hint {
  position: absolute; right: 20px; bottom: 10px;
  font-size: 12px; color: #e8c38a;
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: .2; } }

/* 选项 */
#choices {
  position: absolute; left: 50%; top: 42%;
  transform: translate(-50%, -50%);
  width: 80%; max-width: 520px;
  z-index: 6;
}
.choice {
  display: block; width: 100%;
  margin: 10px 0; padding: 14px 18px;
  font-family: inherit; font-size: 17px; letter-spacing: 1px;
  color: #3b1a12;
  background: linear-gradient(90deg, rgba(255,240,215,.95), rgba(248,220,180,.95));
  border: 1px solid #b0803f; border-radius: 4px;
  cursor: pointer;
  animation: appear .3s ease both;
}
.choice:hover { background: linear-gradient(90deg, #ffe4b5, #f5c07a); transform: scale(1.02); }
.choice.special { border-color: #c4372d; box-shadow: 0 0 10px rgba(196,55,45,.5); }
.choice.special::before { content: "【洞察】"; color: #b3261e; }

/* 数值浮动提示 */
#toasts { position: absolute; top: 56px; left: 12px; z-index: 9; }
.toast {
  width: fit-content;
  margin: 4px 0; padding: 4px 16px;
  font-size: 15px;
  background: rgba(20,10,14,.75);
  border-radius: 12px;
  animation: toast 2s ease forwards;
}
.toast.up { color: #ffd479; }
.toast.down { color: #9ec3ff; }
@keyframes toast {
  0% { opacity: 0; transform: translateY(10px); }
  15%, 75% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-14px); }
}

/* 章节标题卡 */
#chapter-card {
  position: absolute; inset: 0; z-index: 15;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10,4,6,.82);
  cursor: pointer;
}
#chapter-card span {
  font-size: 40px; letter-spacing: 12px;
  color: #f3d8a6;
  text-shadow: 0 0 16px rgba(243,120,80,.5);
  animation: appear 1s ease;
}

/* ---------- 结局 ---------- */
#ending-screen { background: rgba(10,4,6,.75); }
.ending-box {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 80%; max-width: 560px; text-align: center;
  animation: fadein 1s ease;
}
@keyframes fadein { from { opacity: 0; } }
.ending-tag { color: #e8c38a; letter-spacing: 6px; margin-bottom: 10px; }
.ending-box h2 { font-size: 44px; letter-spacing: 10px; color: #f3d8a6; margin-bottom: 20px; text-shadow: 0 0 16px rgba(243,120,80,.5); }
.ending-box p { font-size: 17px; line-height: 2; margin-bottom: 20px; text-align: left; text-indent: 2em; }
#ending-stats { font-size: 14px; color: #d9c2a8; margin-bottom: 16px; }

/* ---------- 弹窗 ---------- */
#modal {
  position: absolute; inset: 0; z-index: 20;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  width: 86%; max-width: 520px; max-height: 80%;
  display: flex; flex-direction: column;
  padding: 22px;
  background: linear-gradient(180deg, #3a1a20, #1e0d11);
  border: 1px solid #c9a36a; border-radius: 6px;
}
.modal-box h3 { text-align: center; letter-spacing: 6px; color: #f3d8a6; margin-bottom: 14px; }
#modal-body { overflow-y: auto; flex: 1; margin-bottom: 10px; }
.slot {
  padding: 12px 14px; margin-bottom: 10px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(201,163,106,.4); border-radius: 4px;
  cursor: pointer; font-size: 15px;
}
.slot:hover { background: rgba(196,74,58,.35); }
.slot small { display: block; color: #bfa88c; margin-top: 4px; }
.log-line { padding: 6px 0; border-bottom: 1px dashed rgba(201,163,106,.2); font-size: 15px; line-height: 1.6; }
.log-line b { color: #f0b37a; margin-right: 6px; }
.gallery-item { padding: 12px; margin-bottom: 8px; border: 1px solid rgba(201,163,106,.4); border-radius: 4px; }
.gallery-item.locked { color: #6f5e55; }
.gallery-item b { font-size: 17px; letter-spacing: 3px; }
.gallery-item small { display: block; margin-top: 4px; color: #bfa88c; }

@media (max-width: 600px) {
  .title-box h1 { font-size: 52px; letter-spacing: 12px; }
  #portrait { height: 80%; }
  #text { font-size: 16px; }
  .stat { min-width: 76px; font-size: 12px; }
  #menu-bar { top: auto; bottom: 172px; }
}
