@import url("https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;600;700&family=Ma+Shan+Zheng&display=swap");

:root {
  --ink: #0d0a0b;
  --wine: #4b151a;
  --red: #8e1e24;
  --gold: #a47a3c;
  --paper: #d9d4c8;
  --cool: #65747a;
  --serif: "Noto Serif SC", "Songti SC", "STSong", serif;
  --brush: "Ma Shan Zheng", "Kaiti SC", "STKaiti", serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%; background: #000; color: var(--paper);
  font-family: var(--serif); overflow: hidden; user-select: none;
}

#stage-wrap {
  position: relative; width: 100vw; height: 100vh;
  display: flex; align-items: center; justify-content: center; background: #000;
}
#stage {
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  display: block; background: #000;
}

/* 所有 DOM 覆盖层都以 stage 尺寸为坐标系 */
.overlay-anchor {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(100vw, calc(100vh * 16 / 9)); height: min(100vh, calc(100vw * 9 / 16));
  pointer-events: none;
}

.hidden { opacity: 0 !important; pointer-events: none !important; }
.boot.hidden { visibility: hidden; transition: opacity 1.2s ease, visibility 0s 1.2s; }

/* ---------- 摄像头小窗 ---------- */
.cam-panel {
  position: absolute;
  right: calc(50% - min(50vw, 50vh * 16 / 9) + 1.4%);
  top: calc(50% - min(50vh, 50vw * 9 / 16) + 2.4%);
  width: 12.5%; aspect-ratio: 4 / 3;
  border: 2px solid #6e5a2f; border-radius: 3px;
  box-shadow: 0 0 0 1px #2b2118, 0 0 18px rgba(0,0,0,.8), inset 0 0 12px rgba(0,0,0,.6);
  background: #050405; overflow: hidden;
  transition: opacity .8s ease, border-color .4s ease;
  z-index: 5;
}
.cam-panel.calibrating { border-color: #c9a642; animation: camBlink .8s ease-in-out infinite; }
.cam-panel.ready { border-color: #8e1e24; animation: none; }
.cam-panel.lost { border-color: #d9b34a; }
.cam-panel.dim { opacity: .6; }
.cam-panel.faint { opacity: .2; }
@keyframes camBlink { 0%,100% { box-shadow: 0 0 0 1px #2b2118, 0 0 8px #c9a64266; } 50% { box-shadow: 0 0 0 1px #2b2118, 0 0 22px #c9a642cc; } }
.cam-panel video, .cam-panel canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  transform: scaleX(-1);
}
.cam-panel canvas { pointer-events: none; }
.cam-label {
  position: absolute; left: 6px; bottom: 4px; font-size: 10px; letter-spacing: .2em;
  color: #c9a642; opacity: .75; text-shadow: 0 0 4px #000;
}

/* ---------- 音量开关（贴在摄像头小窗正下方） ---------- */
.audio-ctl {
  position: absolute;
  right: calc(50% - min(50vw, 50vh * 16 / 9) + 1.4%);
  top: calc(50% - min(50vh, 50vw * 9 / 16) + 2.4% + 9.375vw + 8px);
  width: 12.5%; min-width: 116px;
  display: flex; align-items: center; gap: 7px;
  padding: 5px 8px;
  background: rgba(10,7,8,.74); border: 1px solid #6e5a2f; border-radius: 3px;
  box-shadow: 0 0 12px rgba(0,0,0,.7);
  z-index: 6;
}
.audio-btn {
  flex: 0 0 auto; width: 22px; height: 22px; line-height: 1;
  font-family: var(--serif); font-size: 13px; color: #c9a642;
  background: transparent; border: 1px solid #6e5a2f; border-radius: 2px;
  cursor: pointer; padding: 0; transition: color .25s, border-color .25s;
}
.audio-btn:hover { color: #e8dcc8; border-color: #a47a3c; }
.audio-btn.muted { color: #7a6552; border-color: #4a3a30; }
.audio-range {
  flex: 1 1 auto; min-width: 0; height: 3px; appearance: none;
  background: linear-gradient(90deg, #8e1e24, #6e5a2f); border-radius: 2px; cursor: pointer;
}
.audio-range::-webkit-slider-thumb {
  appearance: none; width: 11px; height: 11px; border-radius: 50%;
  background: #d9c9a8; border: 1px solid #4b151a; cursor: pointer;
}
.audio-range::-moz-range-thumb {
  width: 11px; height: 11px; border-radius: 50%;
  background: #d9c9a8; border: 1px solid #4b151a; cursor: pointer;
}
.audio-ctl.muted .audio-range { filter: grayscale(1) brightness(.6); }

/* ---------- 题签 ---------- */
.scroll-layer {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.35), rgba(0,0,0,.92));
  transition: opacity 1.2s ease; z-index: 8; pointer-events: none;
}
.scroll-layer.clickable { pointer-events: auto; cursor: pointer; }
.scroll-paper {
  width: min(56vw, 56vh * 16 / 9); padding: 4.5vh 5vw;
  background:
    linear-gradient(rgba(0,0,0,.08), rgba(0,0,0,.08)),
    repeating-linear-gradient(0deg, rgba(0,0,0,.025) 0 2px, transparent 2px 6px),
    #c9c0ad;
  border: 1px solid #5a2a2a; outline: 6px solid #2a1517; outline-offset: -10px;
  box-shadow: 0 30px 80px rgba(0,0,0,.9), inset 0 0 60px rgba(70,30,20,.35);
  color: #2b1a17;
}
#scroll-text {
  font-size: clamp(18px, 2.4vh, 32px); line-height: 2.1; letter-spacing: .12em;
  text-align: left; font-weight: 600;
}
#scroll-text .row { opacity: 0; transform: translateY(6px); transition: opacity .9s ease, transform .9s ease; display: block; }
#scroll-text .row.show { opacity: 1; transform: none; }
#scroll-text .who { font-family: var(--brush); color: var(--red); margin-right: .6em; font-weight: 400; }

/* 翻页提示 + 页码点 */
.scroll-paper { position: relative; }
.scroll-next {
  margin-top: 3.2vh; text-align: right; font-size: clamp(13px, 1.8vh, 20px);
  letter-spacing: .22em; color: #7a3a2c; transition: opacity .6s ease;
  animation: nextBlink 1.6s ease-in-out infinite;
}
@keyframes nextBlink { 0%,100% { opacity: .45; } 50% { opacity: 1; } }
.scroll-dots {
  position: absolute; left: 5vw; bottom: 2.4vh; display: flex; gap: .7em;
}
.scroll-dots i { width: .55em; height: .55em; border-radius: 50%; background: #2b1a17; opacity: .22; transition: opacity .4s ease; }
.scroll-dots i.on { opacity: .8; background: var(--red); }

/* ---------- 操作提示 ---------- */
.hint {
  position: absolute; left: 50%; bottom: 6.5%; transform: translateX(-50%);
  padding: .55em 1.6em; font-size: clamp(16px, 2.2vh, 28px); letter-spacing: .14em;
  color: #e8dcc8; background: rgba(15, 8, 9, .72); border: 1px solid #5a2a2a;
  border-left: 3px solid var(--red); border-right: 3px solid var(--red);
  transition: opacity .5s ease; z-index: 6; white-space: nowrap;
}
.hint::before { content: "▸ "; color: #c9a642; }

/* ---------- 贾母心声 ---------- */
.voice {
  position: absolute; left: 50%; top: 16%; transform: translateX(-50%);
  font-family: var(--brush); white-space: nowrap;
  font-size: clamp(22px, 3.4vh, 44px); color: #d9c9a8; letter-spacing: .16em;
  text-shadow: 0 0 14px rgba(0,0,0,.95), 0 2px 3px #000;
  transition: opacity 1s ease; z-index: 6; opacity: .92;
}
.voice::before { content: "「"; } .voice::after { content: "」"; }

/* ---------- 原著台词 ---------- */
.line {
  position: absolute; left: 50%; top: 24%; transform: translateX(-50%);
  font-size: clamp(18px, 2.6vh, 34px); color: #f0e6d2; letter-spacing: .12em;
  text-shadow: 0 0 14px #000, 0 0 3px #000; transition: opacity .6s ease; z-index: 7;
  white-space: nowrap;
}
.line .who { color: #c9a642; font-family: var(--brush); margin-right: .5em; }
/* 太虚幻境的对白：落在画面下缘，允许换行 */
.line.taixu {
  top: auto; bottom: 11%; width: 74%; white-space: normal; text-align: center;
  font-size: clamp(19px, 2.9vh, 38px); line-height: 1.7; color: #f6f0e4;
  text-shadow: 0 0 26px rgba(10,6,18,.95), 0 0 6px #000;
}
.line.taixu .who { color: #c9b6da; }

/* 黛玉插影的台词：落在屏风画面下方 */
.line.daiyu { top: 76%; color: #f4e8d4; font-size: clamp(20px, 3vh, 40px); text-shadow: 0 0 22px rgba(0,0,0,.95), 0 0 6px #000; }
.line.daiyu .who { color: #b8d0d6; }

/* ---------- 唱礼 ---------- */
.chant {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
  font-family: var(--brush); font-size: clamp(40px, 9vh, 120px); color: #b8252c;
  letter-spacing: .3em; text-shadow: 0 0 30px rgba(140, 20, 20, .8), 0 0 6px #000;
  transition: opacity .8s ease; z-index: 7; white-space: nowrap;
}

/* ---------- 贾母终局独白 ---------- */
.mono {
  position: absolute; left: 50%; bottom: 12%; transform: translateX(-50%);
  width: 74%; text-align: center; font-size: clamp(18px, 2.9vh, 38px);
  line-height: 1.75; letter-spacing: .12em; color: #ddcdae;
  text-shadow: 0 0 24px rgba(0,0,0,.95), 0 0 6px #000;
  transition: opacity 1.1s ease; z-index: 9;
}

/* ---------- 终局标题卡 ---------- */
.title-end {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1.6vh;
  background: #000; transition: opacity 3s ease; z-index: 20;
}
.title-end > * { opacity: 0; }
.title-end.show .end-title { animation: endIn 1.8s ease .5s forwards; }
.title-end.show .end-sub { animation: endIn 1.8s ease 1.6s forwards; }
.title-end.show .end-fin { animation: finIn 2.6s ease 3.1s forwards; }
.end-title {
  font-family: var(--brush); font-size: clamp(40px, 9vh, 120px); color: #8e1e24;
  letter-spacing: .3em; text-shadow: 0 0 46px rgba(142,30,36,.55);
}
.end-sub { font-size: clamp(12px, 1.8vh, 22px); color: #8a7a68; letter-spacing: .32em; }
.end-by { font-size: clamp(11px, 1.5vh, 17px); color: #6a5a4c; letter-spacing: .22em; margin-top: .6vh; }
.title-end.show .end-by { animation: endIn 1.8s ease 4.8s forwards; }
.end-fin {
  margin-top: 3.4vh; font-family: var(--brush); font-size: clamp(90px, 27vh, 340px);
  color: #6d151b; letter-spacing: 0; line-height: 1;
  text-shadow: 0 0 70px rgba(142,30,36,.5), 0 0 14px rgba(0,0,0,.9);
}
@keyframes endIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes finIn { from { opacity: 0; transform: scale(1.28); } to { opacity: 1; transform: none; } }

/* ---------- 启动层 ---------- */
.boot {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 1.2vh; background: radial-gradient(ellipse at center, #1a0d0f 0%, #050304 70%);
  z-index: 30; transition: opacity 1.2s ease;
}
.boot-title { font-family: var(--brush); font-size: clamp(40px, 9vh, 120px); color: #8e1e24; letter-spacing: .3em; text-shadow: 0 0 40px rgba(142,30,36,.5); }
.boot-sub { font-size: clamp(12px, 1.8vh, 22px); color: #8a7a68; letter-spacing: .3em; }
.boot-by { font-size: clamp(11px, 1.5vh, 17px); color: #6a5a4c; letter-spacing: .22em; margin-top: .8vh; margin-bottom: 4vh; }
.boot button {
  font-family: var(--serif); font-size: clamp(14px, 2vh, 24px); letter-spacing: .2em;
  color: #e8dcc8; background: #4b151a; border: 1px solid #8e1e24; padding: .7em 2.4em; cursor: pointer;
  transition: background .3s;
}
.boot button:hover { background: #6a1c23; }
.boot button.ghost { background: transparent; border-color: #4a3a30; color: #9a8a78; font-size: clamp(12px, 1.6vh, 18px); }
.boot-note { margin-top: 3vh; font-size: clamp(10px, 1.4vh, 15px); color: #5a4a40; letter-spacing: .1em; }
#boot-status { font-size: clamp(11px, 1.5vh, 16px); color: #c9a642; min-height: 1.5em; }
