/* 西行客 · 水墨国风 UI */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --paper: #ece5d3;
  --paper-dim: #e2d9c2;
  --ink: #2a2622;
  --ink-soft: #4a443c;
  --vermilion: #9f3b2b;
  --gold: #8a6d3b;
  --fog: rgba(236, 229, 211, .92);
}
html, body { height: 100%; }
body {
  font-family: "Kaiti SC", "STKaiti", "KaiTi", "FZKai-Z03S", "Noto Serif SC", serif;
  color: var(--ink);
  background: #1b1915;
  overflow: hidden;
}
.hidden { display: none !important; }

/* ---------- 场景层 ---------- */
#bg { position: fixed; inset: 0; z-index: 0; transition: opacity .8s; }
#bg img { width: 100%; height: 100%; object-fit: cover; display: block;
  filter: sepia(.18) saturate(.85) brightness(.92); }
#bg .vignette { position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 38%, transparent 40%, rgba(20,16,10,.55) 100%); }
/* 无图时的水墨渐变兜底 */
#bg { background: #6c6a5e; }
.scene-huangpo  { background: linear-gradient(180deg,#a8a28e 0%,#7d7a68 55%,#4c493d 100%) !important; }
.scene-shandao  { background: linear-gradient(180deg,#8f8d7c 0%,#5d5f52 60%,#33342c 100%) !important; }
.scene-linzhong { background: linear-gradient(180deg,#77836d 0%,#4a5644 60%,#242b21 100%) !important; }
.scene-yingdi   { background: linear-gradient(180deg,#3a3f4a 0%,#23262e 60%,#101114 100%) !important; }
.scene-dongwai  { background: linear-gradient(180deg,#6e675f 0%,#453f3a 60%,#211d1a 100%) !important; }
.scene-dongnei  { background: linear-gradient(180deg,#3c3230 0%,#241c1c 60%,#0f0b0b 100%) !important; }
.scene-shankou  { background: linear-gradient(180deg,#b3a88e 0%,#79705c 60%,#3d382e 100%) !important; }

/* ---------- 章节题卡 ---------- */
#titleCard {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: rgba(16,13,9,.72); animation: fadein .5s;
}
#titleCardText {
  writing-mode: vertical-rl; letter-spacing: .35em; font-size: 34px; color: var(--paper);
  padding: 40px 34px; border: 1px solid rgba(236,229,211,.45);
  background: rgba(26,22,16,.6); box-shadow: 0 0 60px rgba(0,0,0,.6);
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------- 立绘 ---------- */
/* 立绘已抠成透明底（tools/cutout.py），不能用 mix-blend-mode：
   #portrait 自带 z-index 会生成层叠上下文，multiply 只会跟自己的透明底混，白底照样露出来 */
#portrait { position: fixed; right: 2vw; bottom: 34vh; z-index: 5; width: min(30vw, 340px);
  display: flex; justify-content: center; pointer-events: none; }
#portrait img { max-width: 100%; max-height: 52vh;
  filter: drop-shadow(0 8px 22px rgba(30,22,12,.45)) sepia(.12) saturate(.95);
  animation: fadein .4s; }
#portraitPlate {
  writing-mode: vertical-rl; font-size: 30px; letter-spacing: .3em; color: var(--paper);
  background: rgba(30,25,18,.72); border: 1px solid rgba(236,229,211,.4);
  padding: 26px 14px; animation: fadein .4s;
}

/* ---------- 顶栏 ---------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px; padding: 8px 16px;
  background: linear-gradient(180deg, rgba(24,20,14,.85), rgba(24,20,14,.55) 75%, transparent);
  color: var(--paper); font-size: 14px;
}
.hud-left { white-space: nowrap; }
.hud-sep { opacity: .5; margin: 0 4px; }
.hud-mid { flex: 1; text-align: center; opacity: .85; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.hud-right { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.stat { opacity: .9; }
.stat b { font-weight: normal; margin-left: 3px; color: #e8c987; }
.hud-btn {
  font-family: inherit; font-size: 13px; color: var(--paper);
  background: rgba(236,229,211,.12); border: 1px solid rgba(236,229,211,.35);
  padding: 2px 9px; cursor: pointer; border-radius: 2px;
}
.hud-btn:hover { background: rgba(236,229,211,.25); }
.hud-btn b { font-weight: normal; margin-left: 2px; color: #e8c987; }

/* ---------- 对话卷轴 ---------- */
#stage { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; flex-direction: column; height: 46vh; }
#log {
  flex: 1; overflow-y: auto; padding: 18px max(4vw, 20px) 8px;
  background: linear-gradient(180deg, transparent, var(--fog) 46px),
              linear-gradient(180deg, rgba(236,229,211,0) 0, rgba(236,229,211,.96) 46px);
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 40px);
          mask-image: linear-gradient(180deg, transparent, #000 40px);
  scrollbar-width: thin; scrollbar-color: #b6a98b transparent;
}
#log::-webkit-scrollbar { width: 6px; }
#log::-webkit-scrollbar-thumb { background: #b6a98b; }
.narr { margin: 0 0 10px; line-height: 1.85; font-size: 16.5px; color: var(--ink);
  text-shadow: 0 1px 0 rgba(255,255,255,.35); }
.dlg { margin: 2px 0 12px; display: flex; gap: 10px; align-items: flex-start; }
.dlg .who {
  flex: none; font-size: 13px; color: var(--paper); background: var(--ink-soft);
  padding: 3px 8px; border-radius: 2px; letter-spacing: .15em; margin-top: 3px;
}
.dlg.mood-怒 .who { background: #8c3226; }
.dlg.mood-喜 .who { background: #6e5a1e; }
.dlg.mood-哀 .who { background: #3f4a5a; }
.dlg.mood-惧 .who { background: #4a3a5a; }
.dlg.mood-疑 .who { background: #55503f; }
.dlg .say { line-height: 1.8; font-size: 17px; color: #1f1b17; }
.player-line { margin: 6px 0 12px; text-align: right; }
.player-line span {
  display: inline-block; background: rgba(159,59,43,.1); border: 1px solid rgba(159,59,43,.35);
  color: #6d2a1e; padding: 5px 12px; border-radius: 2px; font-size: 15.5px; line-height: 1.7;
}
.sys-line { margin: 8px 0; text-align: center; font-size: 13px; color: #877c62; }

#suggest { display: flex; gap: 10px; padding: 8px max(4vw, 20px); background: var(--fog); flex-wrap: wrap; }
.chip {
  font-family: inherit; font-size: 14.5px; color: var(--ink);
  background: rgba(42,38,34,.06); border: 1px solid rgba(42,38,34,.35);
  padding: 5px 14px; border-radius: 18px; cursor: pointer;
}
.chip:hover { background: rgba(159,59,43,.12); border-color: var(--vermilion); color: var(--vermilion); }

#inputbar { display: flex; gap: 10px; padding: 8px max(4vw, 20px) 14px; background: var(--fog); }
#input {
  flex: 1; font-family: inherit; font-size: 16px; color: var(--ink);
  background: rgba(255,255,255,.55); border: 1px solid #a2957a; border-radius: 2px;
  padding: 9px 12px; outline: none;
}
#input:focus { border-color: var(--vermilion); }
#input:disabled { opacity: .55; }
#btnSend {
  font-family: inherit; font-size: 17px; letter-spacing: .1em; color: var(--paper);
  background: var(--vermilion); border: none; padding: 0 26px; cursor: pointer; border-radius: 2px;
}
#btnSend:disabled { opacity: .5; cursor: default; }

/* ---------- 覆盖层与卡片 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(18,14,10,.66); animation: fadein .3s; padding: 20px;
}
.card {
  background: var(--paper); color: var(--ink); max-width: 520px; width: 100%;
  padding: 30px 34px; border: 1px solid #b7a780; box-shadow: 0 10px 60px rgba(0,0,0,.5);
  max-height: 86vh; overflow-y: auto; text-align: center;
}
.card.wide { max-width: 640px; text-align: left; }
.card-title { font-size: 20px; letter-spacing: .2em; text-align: center; margin-bottom: 16px; }
.row { display: flex; gap: 12px; justify-content: center; margin-top: 18px; }
.btn-main {
  font-family: inherit; font-size: 17px; letter-spacing: .18em; color: var(--paper);
  background: var(--vermilion); border: none; padding: 10px 30px; cursor: pointer; border-radius: 2px;
}
.btn-main:hover { filter: brightness(1.1); }
.btn-sub {
  font-family: inherit; font-size: 15px; color: var(--ink-soft);
  background: transparent; border: 1px solid #a2957a; padding: 9px 22px; cursor: pointer;
  border-radius: 2px; margin-top: 6px;
}
.btn-sub:hover { border-color: var(--vermilion); color: var(--vermilion); }

/* 开局 */
#screenTitle { background: radial-gradient(ellipse at 50% 30%, #3e382c 0%, #211d15 70%, #14110c 100%); }
.title-wrap { text-align: center; color: var(--paper); }
.game-title { font-size: 88px; letter-spacing: .28em; text-indent: .28em; font-weight: normal;
  text-shadow: 0 0 40px rgba(232,201,135,.25); }
.game-sub { margin-top: 6px; font-size: 18px; letter-spacing: .5em; text-indent: .5em; color: #cbbb96; }
.title-desc { margin: 26px auto 30px; font-size: 15px; line-height: 2; color: #a99b7d; max-width: 460px; }
.title-form { display: flex; flex-direction: column; gap: 12px; align-items: center; }
#playerName {
  font-family: inherit; font-size: 17px; text-align: center; letter-spacing: .1em;
  background: rgba(236,229,211,.08); color: var(--paper); border: 1px solid #6d6248;
  padding: 10px 16px; width: 260px; outline: none; border-radius: 2px;
}
#playerName:focus { border-color: #cbbb96; }

/* 账号面板 */
#authPanel { width: 320px; margin: 0 auto; }
.auth-tabs { display: flex; gap: 4px; justify-content: center; margin-bottom: 16px; }
.auth-tab {
  font-family: inherit; font-size: 14px; color: #a99b7d; background: transparent;
  border: none; border-bottom: 1px solid transparent; padding: 6px 12px; cursor: pointer;
}
.auth-tab.on { color: var(--paper); border-bottom-color: var(--vermilion); }
.auth-tab:hover { color: var(--paper); }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input {
  font-family: inherit; font-size: 15px; color: var(--paper); letter-spacing: .05em;
  background: rgba(236,229,211,.08); border: 1px solid #6d6248;
  padding: 10px 14px; outline: none; border-radius: 2px; width: 100%;
}
.auth-form input:focus { border-color: #cbbb96; }
.auth-form input::placeholder { color: #7d735c; }
.auth-form .btn-main { margin-top: 4px; }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; }
.btn-code {
  font-family: inherit; font-size: 14px; color: #cbbb96; white-space: nowrap;
  background: rgba(236,229,211,.08); border: 1px solid #6d6248;
  padding: 0 14px; cursor: pointer; border-radius: 2px;
}
.btn-code:hover:not(:disabled) { border-color: #cbbb96; color: var(--paper); }
.btn-code:disabled { opacity: .45; cursor: default; }
.auth-note { margin-top: 16px; font-size: 12px; line-height: 1.8; color: #7d735c; }
.welcome { font-size: 15px; color: #cbbb96; margin-bottom: 4px; letter-spacing: .1em; }
.link-btn {
  font-family: inherit; font-size: 13px; color: #7d735c; background: none;
  border: none; cursor: pointer; margin-top: 4px; text-decoration: underline;
}
.link-btn:hover { color: #a99b7d; }

/* 批注 */
.anno-card { position: relative; }
.anno-seal {
  position: absolute; top: 18px; right: 20px; color: var(--vermilion);
  border: 2px solid var(--vermilion); border-radius: 4px; padding: 3px 6px;
  font-size: 14px; letter-spacing: .15em; transform: rotate(8deg); opacity: .85;
}
.anno-title { font-size: 22px; letter-spacing: .2em; margin-bottom: 14px; }
.anno-quote { font-size: 15px; line-height: 2; color: #5c5140; background: rgba(42,38,34,.05);
  border-left: 3px solid var(--gold); padding: 10px 14px; text-align: left; margin-bottom: 12px; }
.anno-quote::before { content: "原著 · "; color: var(--gold); font-size: 13px; }
.anno-note { font-size: 15.5px; line-height: 2; color: var(--ink-soft); text-align: left; margin-bottom: 8px; }
.collection { display: flex; flex-direction: column; gap: 12px; max-height: 54vh; overflow-y: auto; }
.collection .item { border-bottom: 1px dashed #b7a780; padding-bottom: 10px; }
.collection .item h4 { font-size: 16px; margin-bottom: 6px; }
.collection .item h4 span { color: var(--gold); font-size: 13px; margin-left: 8px; }
.collection .item p { font-size: 14px; line-height: 1.9; color: var(--ink-soft); }
.collection .locked { color: #a2957a; font-size: 14px; }

/* 结局 */
.ending-card { max-width: 560px; }
.ending-title { font-size: 56px; letter-spacing: .3em; text-indent: .3em; color: var(--vermilion); }
.ending-epithet { margin-top: 6px; font-size: 15px; color: var(--gold); letter-spacing: .2em; }
.ending-text { margin: 18px 0; font-size: 15.5px; line-height: 2.1; color: var(--ink-soft); text-align: left; }
.ending-sep { font-size: 13px; color: #a2957a; letter-spacing: .3em; margin: 14px 0 10px; }
.butterfly { text-align: left; }
.butterfly div {
  font-size: 14.5px; line-height: 1.9; color: var(--ink); padding: 4px 0 4px 18px; position: relative;
  opacity: 0; animation: fadein .6s forwards;
}
.butterfly div::before { content: "﹅"; position: absolute; left: 0; color: var(--vermilion); font-size: 10px; top: 9px; }
.ending-meta { margin-top: 14px; font-size: 13px; color: #877c62; }

/* 死亡 */
.death-card { background: #241c19; border-color: #5a3a32; color: #d8c9b8; }
.death-mark {
  font-size: 92px; color: #b03a26; text-shadow: 0 0 30px rgba(176,58,38,.5);
  animation: fadein 1s;
}
.death-text { margin: 14px 0 6px; font-size: 15.5px; line-height: 2; color: #bfae9a; }

/* 存档 */
.saves { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.saves .slot {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  border: 1px solid #b7a780; padding: 10px 14px; cursor: pointer; font-size: 14px;
}
.saves .slot:hover { border-color: var(--vermilion); background: rgba(159,59,43,.06); }
.saves .slot .meta { color: #877c62; font-size: 12.5px; }
.saves .empty { text-align: center; color: #877c62; padding: 20px 0; }

/* 提示 */
#toast {
  position: fixed; top: 52px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: rgba(24,20,14,.9); color: var(--paper); font-size: 14px;
  padding: 8px 18px; border-radius: 2px; border: 1px solid rgba(236,229,211,.3);
  animation: fadein .3s;
}

/* 窄屏 */
@media (max-width: 760px) {
  .game-title { font-size: 56px; }
  #portrait { width: 44vw; bottom: 40vh; }
  #stage { height: 52vh; }
  .hud-mid { display: none; }
  .narr { font-size: 15.5px; }
  .dlg .say { font-size: 16px; }
}
