/* 武侠江湖 · 水墨界面 */

:root {
  --paper: #f3ece0;
  --paper-rgb: 243, 236, 224;
  --ink: #23272e;
  --ink-soft: #5c636d;
  --ink-faint: #9aa0a8;
  --seal: #9d3a2f;
  --line: rgba(35, 39, 46, 0.18);
  --hud-h: 78px;
  --choice-h: 168px;
}

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

html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: "Songti SC", "STSong", "Source Han Serif SC", "Noto Serif CJK SC", "SimSun", serif;
}

/* ── 3D 画布与纸纹 ── */

#gl { position: fixed; inset: 0; display: block; z-index: 0; background: var(--paper); }

#paper {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(255,255,255,0) 40%, rgba(120,110,95,0.16) 100%),
    repeating-linear-gradient(90deg, rgba(0,0,0,0.014) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(0deg, rgba(0,0,0,0.012) 0 1px, transparent 1px 4px);
  mix-blend-mode: multiply;
}

/* ── 顶栏 ── */

.hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  height: var(--hud-h);
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px;
  background: linear-gradient(180deg, rgba(var(--paper-rgb),0.94) 0%, rgba(var(--paper-rgb),0.72) 72%, rgba(var(--paper-rgb),0) 100%);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(2px);
}

.hud .chapter {
  flex: 0 0 auto; font-size: 15px; letter-spacing: 2px; color: var(--ink-soft);
  border-left: 3px solid var(--seal); padding-left: 10px; line-height: 1.35;
}
.hud .chapter b { display: block; font-size: 17px; color: var(--ink); font-weight: 600; }

.attrs { display: flex; gap: 16px; flex: 1 1 auto; flex-wrap: wrap; }

.attr { min-width: 62px; }
.attr .k { font-size: 12px; color: var(--ink-faint); letter-spacing: 1px; }
.attr .v { font-size: 20px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.attr .v.up { animation: bump .55s ease-out; color: #2c6b4f; }
.attr .v.down { animation: bump .55s ease-out; color: var(--seal); }
@keyframes bump {
  0% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-5px) scale(1.22); }
  100% { transform: translateY(0) scale(1); }
}

.meter { width: 96px; height: 5px; margin-top: 4px; background: rgba(35,39,46,0.12); border-radius: 3px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; transition: width .5s ease; }
.meter.favor i { background: linear-gradient(90deg, #7d9b86, #4a7a63); }
.meter.hp i { background: linear-gradient(90deg, #c06a58, #9d3a2f); }

.attr.wide { min-width: 108px; }

/* ── 正文（竖排） ── */

/* 右上角锚定：竖排从右起，新列向左生长，已出现的字不再位移 */
#stage {
  position: fixed; inset: var(--hud-h) 0 var(--choice-h) 0; z-index: 4;
  display: flex; justify-content: flex-end; align-items: flex-start;
  padding: 24px 52px 16px 24px;
}

.verse {
  position: relative;
  writing-mode: vertical-rl;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 19px;
  line-height: 1.9;
  letter-spacing: 3px;
  overflow: visible;
  padding: 18px 14px;
  cursor: pointer;
}

/* 宣纸衬底：跟着文字块走，边缘羽化，压住背后的深色松竹 */
.verse::before {
  content: '';
  position: absolute;
  inset: -22px -34px;
  z-index: -1;
  border-radius: 40px;
  background:
    radial-gradient(ellipse 62% 74% at 50% 50%,
      rgba(var(--paper-rgb), 0.97) 0%,
      rgba(var(--paper-rgb), 0.93) 40%,
      rgba(var(--paper-rgb), 0.68) 70%,
      rgba(var(--paper-rgb), 0) 100%);
  filter: blur(7px);
  pointer-events: none;
  transition: opacity .4s ease;
}
/* 正文清空时（换章、结局）衬底一并淡掉，不留一块空白纸影 */
.verse:empty::before { opacity: 0; }

.verse .col {
  white-space: nowrap;
  animation: colIn .6s ease both;
  text-shadow:
    0 0 6px rgba(var(--paper-rgb),1),
    0 0 14px rgba(var(--paper-rgb),0.98),
    0 0 26px rgba(var(--paper-rgb),0.9),
    0 0 40px rgba(var(--paper-rgb),0.75);
}
.verse .col.node-title {
  color: var(--seal); font-size: 1.16em; letter-spacing: 6px; font-weight: 600;
}
.verse .col.result { color: #35507a; }
.verse .col.fail { color: var(--seal); }

.verse .ch { opacity: 0; animation: inkIn .5s ease forwards; }
@keyframes inkIn {
  from { opacity: 0; filter: blur(2.5px); }
  to { opacity: 1; filter: blur(0); }
}
@keyframes colIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.shake { animation: shake .4s ease; }
@keyframes shake {
  0%,100% { transform: translate(0,0); }
  25% { transform: translate(-4px,2px); }
  55% { transform: translate(3px,-2px); }
  80% { transform: translate(-2px,1px); }
}

.hint-skip {
  position: fixed; z-index: 4; left: 20px; bottom: calc(var(--choice-h) + 6px);
  font-size: 12px; color: var(--ink-faint); letter-spacing: 1px;
}

/* ── 选项 ── */

.choices {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  min-height: var(--choice-h);
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: center;
  padding: 18px 20px 24px;
  background: linear-gradient(0deg, rgba(var(--paper-rgb),0.95) 0%, rgba(var(--paper-rgb),0.75) 60%, rgba(var(--paper-rgb),0) 100%);
}

.choice {
  position: relative;
  font-family: inherit; font-size: 16px; letter-spacing: 2px;
  color: var(--ink); background: rgba(255,253,247,0.82);
  border: 1px solid rgba(35,39,46,0.55);
  border-radius: 2px 12px 2px 12px;
  padding: 12px 20px; cursor: pointer;
  box-shadow: inset 0 0 14px rgba(35,39,46,0.06), 0 2px 0 rgba(35,39,46,0.08);
  transition: transform .18s ease, background .25s ease, color .25s ease, box-shadow .25s ease;
  max-width: min(420px, 88vw); text-align: left;
}
.choice:hover:not(.locked) { background: var(--ink); color: #f6f1e6; transform: translateY(-3px); }
.choice:focus-visible { outline: 2px solid var(--seal); outline-offset: 3px; }

.choice .gain {
  display: block; margin-top: 5px; font-size: 12px; letter-spacing: 1px; color: var(--ink-faint);
}
.choice:hover:not(.locked) .gain { color: rgba(246,241,230,0.8); }

.choice .risk {
  position: absolute; top: -9px; right: -9px;
  width: 22px; height: 22px; line-height: 22px; text-align: center;
  font-size: 12px; color: #fff; background: var(--seal);
  border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

.choice.locked {
  cursor: not-allowed; color: var(--ink-faint);
  background: rgba(240,236,228,0.55);
  border-color: rgba(35,39,46,0.2);
  border-style: dashed;
  filter: grayscale(1); opacity: .62;
  box-shadow: none;
  user-select: none;
}
.choice.locked:hover { background: rgba(240,236,228,0.7); transform: none; }
.choice.locked .req { display: block; margin-top: 5px; font-size: 12px; color: #a2564c; letter-spacing: 1px; }

#tip {
  position: fixed; z-index: 20; pointer-events: none; opacity: 0;
  transform: translate(-50%, -100%);
  background: var(--ink); color: #f6f1e6;
  font-size: 13px; letter-spacing: 1px; padding: 7px 11px; border-radius: 3px;
  transition: opacity .16s ease; white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
}
#tip.on { opacity: 1; }
#tip::after {
  content: ''; position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--ink); border-bottom: 0;
}

/* ── 开场 / 结局 覆盖层 ── */

.overlay {
  position: fixed; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 20px; padding: 32px 24px;
  background: rgba(var(--paper-rgb),0.90);
  backdrop-filter: blur(3px);
  overflow: auto;
}
.overlay[hidden] { display: none; }

.title-main {
  font-size: clamp(34px, 8vw, 66px); letter-spacing: 14px; margin: 0;
  font-weight: 600;
}
.title-sub { color: var(--ink-soft); letter-spacing: 5px; font-size: 15px; margin: 0; }
.title-note { color: var(--ink-faint); font-size: 12.5px; letter-spacing: 1px; max-width: 460px; text-align: center; line-height: 1.9; }

.btn {
  font-family: inherit; font-size: 17px; letter-spacing: 6px; cursor: pointer;
  color: #f6f1e6; background: var(--ink); border: 0;
  padding: 13px 34px; border-radius: 2px 14px 2px 14px;
  box-shadow: 0 3px 0 rgba(35,39,46,0.25);
  transition: transform .18s ease, background .2s ease;
}
.btn:hover { transform: translateY(-2px); background: #101318; }
.btn.ghost { color: var(--ink); background: transparent; border: 1px solid rgba(35,39,46,0.5); box-shadow: none; }

/* 结局面板 */

.end-wrap { max-width: 900px; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 18px; }

.seal {
  width: 74px; height: 74px; display: grid; place-items: center;
  background: var(--seal); color: #f6f1e6;
  font-size: 38px; letter-spacing: 0;
  border-radius: 6px; transform: rotate(-6deg);
  box-shadow: 0 4px 16px rgba(157,58,47,0.35);
}
.end-title { font-size: clamp(26px, 5vw, 40px); letter-spacing: 10px; margin: 0; }

.end-text { max-width: 640px; line-height: 2.15; font-size: 16px; letter-spacing: 2px; color: #2c3138; }
.end-text p { margin: 0 0 6px; }

.summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px; width: 100%; max-width: 640px;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  padding: 14px 0;
}
.summary div { text-align: center; }
.summary .k { font-size: 12px; color: var(--ink-faint); letter-spacing: 1px; }
.summary .v { font-size: 24px; font-weight: 600; }

.route { width: 100%; max-width: 640px; max-height: 34vh; overflow: auto; font-size: 13.5px; line-height: 1.95; }
.route h4 { margin: 0 0 6px; font-size: 13px; letter-spacing: 3px; color: var(--ink-soft); font-weight: 600; }
.route ol { margin: 0; padding-left: 22px; color: #3a3f47; }
.route li { margin-bottom: 3px; }
.route .ch { color: var(--ink-faint); }
.route .ok { color: #2c6b4f; }
.route .bad { color: var(--seal); }

.notice {
  position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 40;
  font-size: 12.5px; color: var(--ink-soft); background: rgba(255,253,247,0.9);
  border: 1px solid var(--line); padding: 6px 12px; border-radius: 3px;
}
.notice[hidden] { display: none; }

/* ── 窄屏：转为横排 ── */

@media (max-width: 720px), (max-height: 520px) {
  :root { --hud-h: 96px; --choice-h: 200px; }
  .hud { flex-wrap: wrap; gap: 10px 14px; padding: 8px 14px; align-content: center; }
  .hud .chapter { font-size: 13px; }
  .hud .chapter b { font-size: 15px; }
  .attrs { gap: 10px; }
  .attr { min-width: 52px; }
  .attr .v { font-size: 17px; }
  .meter { width: 70px; }

  #stage { justify-content: flex-start; align-items: flex-start; padding: 14px 18px; }
  .verse {
    writing-mode: horizontal-tb;
    flex-direction: column; gap: 4px;
    font-size: 16px; line-height: 1.95; letter-spacing: 1.5px;
  }
  .verse { padding: 14px 12px; }
  .verse::before { inset: -14px -18px; border-radius: 26px; filter: blur(5px); }
  .verse .col { white-space: normal; }
  .verse .col.node-title { font-size: 1.18em; letter-spacing: 4px; }

  .choices { gap: 8px; padding: 12px 12px 18px; }
  .choice { font-size: 14.5px; padding: 10px 14px; max-width: 92vw; }
  .hint-skip { left: 14px; }
}
