:root {
  --ink: #ece4cf;
  --ink-dim: rgba(236, 228, 207, .6);
  --gold: #d9b45a;
  --gold-hi: #f6e1a8;
  --teal: #39d0b8;
  --purple: #9a6be0;
  --seal: #a8241c;
  --bg: #060b10;
  --panel: rgba(10, 17, 24, .86);
  --line: rgba(217, 180, 90, .28);
  --brush: "Ma Shan Zheng", "STXingkai", "华文行楷", "KaiTi", "STKaiti", serif;
  --serif: "Noto Serif SC", "Songti SC", "SimSun", serif;
  --lb: 5.5vh;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--serif); overflow: hidden; }
#stage { position: fixed; inset: 0; }
#scene { display: block; width: 100%; height: 100%; touch-action: none; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: rgba(217,180,90,.06); }
::-webkit-scrollbar-thumb { background: linear-gradient(180deg, #8a6c2e, #d9b45a); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--gold-hi); }

/* ---------- 电影框 ---------- */
.letterbox { position: fixed; left: 0; right: 0; height: var(--lb); background: #000; z-index: 3; pointer-events: none; transition: height .8s; }
.letterbox.top { top: 0; } .letterbox.bottom { bottom: 0; }
#vignette { position: fixed; inset: 0; pointer-events: none; z-index: 2; background: radial-gradient(ellipse at center, transparent 52%, rgba(2,5,8,.62) 100%); }
#grain { position: fixed; inset: -40px; pointer-events: none; z-index: 2; opacity: .06; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain .45s steps(3) infinite; }
@keyframes grain { 0%{transform:translate(0,0)} 33%{transform:translate(-14px,9px)} 66%{transform:translate(11px,-13px)} 100%{transform:translate(0,0)} }
#flash { position: fixed; inset: 0; pointer-events: none; z-index: 4; opacity: 0; background: radial-gradient(circle at 50% 42%, #fffbe8 0%, #ffe9b0 42%, rgba(255,220,150,.5) 100%); mix-blend-mode: screen; }
#fade { position: fixed; inset: 0; pointer-events: none; z-index: 4; background: #000; opacity: 1; }

/* ---------- 字幕 ---------- */
#captions { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.cap { position: absolute; opacity: 0; visibility: hidden; transition: opacity .45s, transform .45s, filter .45s, visibility .45s; text-shadow: 0 2px 16px rgba(0,0,0,.9); }
.cap.show { opacity: 1; visibility: visible; }
#cap-title.show, #cap-lower.show, #cap-quote.show, #cap-tech.show { transform: none; filter: none; }
#cap-title { inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2.2vh; transform: scale(1.06); filter: blur(6px); }
#cap-title .big { font-family: var(--brush); font-size: clamp(44px, 11vh, 120px); letter-spacing: .22em; padding-left: .22em; color: #f5edd8; }
#cap-title .small { font-size: clamp(12px, 2.4vh, 20px); letter-spacing: .7em; padding-left: .7em; color: var(--gold); }
#cap-title .rule { width: 22vw; height: 1px; background: linear-gradient(90deg, transparent, var(--gold), transparent); }
#cap-lower { left: 4vw; right: 4vw; bottom: calc(var(--lb) + 9vh); text-align: center; font-size: clamp(13px, 2.5vh, 21px); letter-spacing: .16em; transform: translateY(12px); }
#cap-lower span { padding: .35em 1.4em; background: linear-gradient(90deg, transparent, rgba(0,0,0,.55) 18%, rgba(0,0,0,.55) 82%, transparent); }
#cap-quote { left: 6vw; right: 6vw; bottom: calc(var(--lb) + 15vh); text-align: center; font-size: clamp(14px, 2.8vh, 23px); letter-spacing: .12em; color: var(--gold-hi); transform: translateY(12px); }
#cap-quote span { padding: .35em 1.4em; background: linear-gradient(90deg, transparent, rgba(20,8,4,.6) 18%, rgba(20,8,4,.6) 82%, transparent); border-top: 1px solid rgba(217,180,90,.35); border-bottom: 1px solid rgba(217,180,90,.35); }
#cap-tech { top: calc(var(--lb) + 4vh); right: 5vw; display: flex; flex-direction: row-reverse; align-items: flex-start; gap: 1.1vw; transform: translateX(36px); }
#cap-tech .big { writing-mode: vertical-rl; font-family: var(--brush); font-size: clamp(28px, 6.5vh, 62px); line-height: 1.05; color: #f6efdc; letter-spacing: .08em; }
#cap-tech .small { writing-mode: vertical-rl; font-size: clamp(11px, 2vh, 16px); letter-spacing: .32em; color: var(--ink-dim); margin-top: .5em; }
#cap-tech .seal { position: absolute; right: -1.2em; bottom: -.6em; width: 1.7em; height: 1.7em; display: grid; place-items: center; font-family: var(--brush); font-size: clamp(12px, 2.4vh, 20px); color: #f5ddd0; background: var(--seal); border-radius: 3px; transform: rotate(-6deg); }

/* ---------- 顶栏 ---------- */
#topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 8; display: flex; align-items: center; justify-content: space-between; padding: calc(var(--lb) + 10px) 18px 10px; background: linear-gradient(180deg, rgba(3,6,9,.75), transparent); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.seal-box { width: 34px; height: 34px; flex: none; display: grid; place-items: center; font-family: var(--brush); font-size: 22px; color: #f5ddd0; background: var(--seal); border-radius: 4px; box-shadow: 0 0 14px rgba(168,36,28,.5); }
.brand-text { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.brand-text strong { font-size: 14px; letter-spacing: .12em; white-space: nowrap; }
.brand-text em { font-style: normal; font-size: 11px; color: var(--ink-dim); letter-spacing: .3em; white-space: nowrap; }
.top-actions { display: flex; gap: 8px; }
.tbtn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 12px; letter-spacing: .1em; color: var(--ink); background: rgba(10,17,24,.6); border: 1px solid var(--line); border-radius: 4px; padding: 7px 11px; cursor: pointer; backdrop-filter: blur(6px); transition: border-color .2s, color .2s, background .2s; }
.tbtn:hover { border-color: var(--gold); color: var(--gold-hi); }
.tbtn:focus-visible, .cbtn:focus-visible, .pbtn:focus-visible, .seg button:focus-visible, #chapters button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
#btn-sound .mut { display: none; }
#btn-sound.off { color: var(--ink-dim); }
#btn-sound.off .wav { display: none; }
#btn-sound.off .mut { display: block; }
#btn-camera.free { color: var(--teal); border-color: rgba(57,208,184,.5); }

/* ---------- 右侧面板 ---------- */
#panel { position: fixed; top: calc(var(--lb) + 64px); right: 14px; bottom: calc(var(--lb) + 76px); width: 248px; z-index: 7; overflow-y: auto; padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; backdrop-filter: blur(10px); transition: transform .45s cubic-bezier(.2,.8,.2,1), opacity .45s; }
#panel.hidden { transform: translateX(120%); opacity: 0; pointer-events: none; }
#panel h2 { margin: 4px 0 10px; font-size: 13px; letter-spacing: .4em; color: var(--gold); font-weight: 600; }
#panel h2:not(:first-child) { margin-top: 18px; padding-top: 14px; border-top: 1px solid rgba(217,180,90,.16); }
.prow { margin-bottom: 13px; }
.prow label { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-dim); letter-spacing: .12em; margin-bottom: 6px; }
.prow output { color: var(--gold); font-variant-numeric: tabular-nums; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 3px; background: linear-gradient(90deg, rgba(57,208,184,.5), rgba(217,180,90,.7)); border-radius: 2px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 13px; height: 13px; margin-top: -5px; border-radius: 50%; background: var(--gold); border: 1px solid #6e5626; box-shadow: 0 0 8px rgba(217,180,90,.7); }
input[type="range"]::-moz-range-track { height: 3px; background: linear-gradient(90deg, rgba(57,208,184,.5), rgba(217,180,90,.7)); border-radius: 2px; }
input[type="range"]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: var(--gold); border: 1px solid #6e5626; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.seg button { flex: 1; font: inherit; font-size: 12px; padding: 6px 0; color: var(--ink-dim); background: transparent; border: 0; cursor: pointer; transition: background .2s, color .2s; }
.seg button + button { border-left: 1px solid rgba(217,180,90,.16); }
.seg button.on { background: rgba(217,180,90,.18); color: var(--gold-hi); }
.prow.btns { display: flex; gap: 8px; }
.pbtn { flex: 1; font: inherit; font-size: 12px; letter-spacing: .08em; color: var(--ink); background: rgba(217,180,90,.08); border: 1px solid var(--line); border-radius: 4px; padding: 7px 4px; cursor: pointer; }
.pbtn:hover { border-color: var(--gold); color: var(--gold-hi); }
#chapters { margin: 0; padding: 0; list-style: none; }
#chapters li { margin: 0; }
#chapters button { display: flex; align-items: baseline; gap: 8px; width: 100%; text-align: left; font: inherit; font-size: 12px; color: var(--ink-dim); background: transparent; border: 0; border-left: 2px solid rgba(217,180,90,.18); padding: 6px 8px; cursor: pointer; transition: color .2s, border-color .2s, background .2s; }
#chapters button .no { font-size: 10px; color: rgba(217,180,90,.55); font-variant-numeric: tabular-nums; }
#chapters button:hover { color: var(--ink); background: rgba(217,180,90,.06); }
#chapters button.on { color: var(--gold-hi); border-left-color: var(--gold); background: rgba(217,180,90,.1); }
.note { font-size: 11px; line-height: 1.8; color: rgba(236,228,207,.38); margin: 12px 0 2px; }

/* ---------- 底部播放栏 ---------- */
#controls { position: fixed; left: 0; right: 0; bottom: 0; z-index: 8; display: flex; align-items: center; gap: 12px; padding: 12px 18px calc(var(--lb) + 10px); background: linear-gradient(0deg, rgba(3,6,9,.85) 55%, transparent); }
.cbtn { width: 40px; height: 36px; flex: none; display: grid; place-items: center; font: inherit; color: var(--ink); background: rgba(10,17,24,.6); border: 1px solid var(--line); border-radius: 4px; cursor: pointer; }
.cbtn:hover { border-color: var(--gold); color: var(--gold-hi); }
#time { font-size: 12px; color: var(--ink-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.track { position: relative; flex: 1; height: 26px; }
#progress { position: absolute; left: 0; top: 11px; height: 3px; width: 0; background: linear-gradient(90deg, var(--teal), var(--gold)); border-radius: 2px; pointer-events: none; box-shadow: 0 0 8px rgba(217,180,90,.5); }
#scrub { position: absolute; inset: 0; width: 100%; height: 26px; opacity: 0; cursor: pointer; }
.track::before { content: ""; position: absolute; left: 0; right: 0; top: 11px; height: 3px; background: rgba(236,228,207,.14); border-radius: 2px; }
#markers { position: absolute; left: 0; right: 0; top: 0; height: 100%; pointer-events: none; }
.marker { position: absolute; top: 9px; width: 7px; height: 7px; transform: translateX(-50%) rotate(45deg); background: var(--gold); border-radius: 1px; opacity: .75; pointer-events: auto; cursor: pointer; }
.marker::after { content: attr(data-label); position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%) rotate(-45deg); transform-origin: center; white-space: nowrap; font-size: 11px; letter-spacing: .1em; color: var(--gold-hi); background: rgba(6,10,14,.9); border: 1px solid var(--line); padding: 3px 8px; border-radius: 3px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.marker:hover::after { opacity: 1; }
#chapter-now { font-size: 12px; letter-spacing: .18em; color: var(--gold); white-space: nowrap; min-width: 7em; text-align: right; }
#hint { position: fixed; top: calc(var(--lb) + 66px); left: 50%; transform: translateX(-50%); z-index: 7; font-size: 12px; letter-spacing: .15em; color: var(--ink-dim); background: rgba(6,10,14,.7); border: 1px solid var(--line); padding: 6px 16px; border-radius: 20px; opacity: 0; transition: opacity .4s; pointer-events: none; }
#hint.show { opacity: 1; }

/* ---------- 开场 / 结尾 ---------- */
#start, #endcard { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; grid-template-columns: minmax(0, 1fr); padding: 20px; transition: opacity .9s; }
#start { background: radial-gradient(ellipse at 50% 38%, #12222e 0%, #05090c 72%); }
#start.gone, #endcard.gone { opacity: 0; pointer-events: none; }
#endcard { background: radial-gradient(ellipse at 50% 45%, rgba(10,8,14,.88), rgba(2,2,4,.97)); opacity: 0; pointer-events: none; z-index: 9; }
#endcard.show { opacity: 1; pointer-events: auto; }
.start-inner, .end-inner { text-align: center; max-width: 620px; width: 100%; }
.start-seal { display: inline-block; font-size: 12px; letter-spacing: .5em; padding-left: .5em; color: var(--gold); border: 1px solid var(--line); padding: 6px 14px 6px 18px; border-radius: 3px; margin-bottom: 20px; }
.start-inner h1 { font-family: var(--brush); font-weight: 400; font-size: clamp(42px, 9vw, 88px); margin: 0 0 8px; letter-spacing: .14em; color: #f5edd8; text-shadow: 0 0 40px rgba(217,180,90,.25); }
.start-inner .sub { color: var(--gold); letter-spacing: .4em; font-size: 13px; margin-bottom: 26px; }
.start-inner p, .end-inner p { color: var(--ink-dim); line-height: 2.1; font-size: 13.5px; margin: 0 0 30px; letter-spacing: .06em; }
#btn-go, #btn-replay { font: inherit; font-size: 17px; letter-spacing: .4em; padding: 12px 40px 12px 46px; color: var(--gold-hi); background: rgba(217,180,90,.12); border: 1px solid var(--gold); border-radius: 4px; cursor: pointer; transition: background .25s, box-shadow .25s; }
#btn-go:hover, #btn-replay:hover { background: rgba(217,180,90,.25); box-shadow: 0 0 30px rgba(217,180,90,.35); }
.start-inner small { display: block; margin-top: 26px; color: rgba(236,228,207,.38); font-size: 11.5px; line-height: 2; letter-spacing: .1em; }
.end-small { font-size: 13px; letter-spacing: .5em; padding-left: .5em; color: var(--gold); margin-bottom: 18px; }
.end-big { font-family: var(--brush); font-size: clamp(40px, 8vw, 76px); letter-spacing: .2em; color: #f5edd8; margin-bottom: 22px; }
#fatal { position: fixed; inset: 0; z-index: 30; display: none; place-items: center; background: rgba(4,6,9,.96); text-align: center; padding: 24px; }
#fatal.show { display: grid; }
#fatal h2 { font-family: var(--brush); font-weight: 400; letter-spacing: .2em; color: var(--gold); }
#fatal p { color: var(--ink-dim); font-size: 13px; line-height: 2; }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  #panel { width: 224px; }
  .brand-text em { display: none; }
}
@media (max-width: 640px) {
  :root { --lb: 3.5vh; }
  .brand-text { display: none; }
  .tbtn span { display: none; }
  .tbtn { padding: 7px 9px; }
  #time { display: none; }
  #chapter-now { min-width: 0; font-size: 11px; }
  #controls { gap: 8px; padding-left: 10px; padding-right: 10px; }
  #panel { top: calc(var(--lb) + 58px); right: 8px; bottom: calc(var(--lb) + 66px); width: min(78vw, 240px); }
  #cap-tech { right: 4vw; }
  #cap-lower { bottom: calc(var(--lb) + 11vh); left: 3vw; right: 3vw; font-size: clamp(12px, 2vh, 16px); letter-spacing: .08em; }
  #cap-quote { left: 3vw; right: 3vw; font-size: clamp(12px, 2.1vh, 16px); letter-spacing: .06em; }
  #cap-lower span, #cap-quote span { padding: .3em .7em; }
  #cap-title .big { font-size: clamp(34px, 8vh, 56px); letter-spacing: .14em; }
  .start-inner h1 { font-size: clamp(30px, 8.6vw, 44px); letter-spacing: .1em; }
  .start-inner .sub { letter-spacing: .28em; font-size: 12px; }
  .start-inner p, .end-inner p { font-size: 12.5px; line-height: 1.9; }
  .end-big { font-size: clamp(30px, 8vw, 44px); }
}
@media (prefers-reduced-motion: reduce) { #grain { animation: none; } }