/* ========== 设计变量 ========== */
:root {
  --ink: #0e0b09;
  --ink-2: #1a1512;
  --paper: #efe5d0;
  --paper-dim: rgba(239, 229, 208, 0.72);
  --paper-faint: rgba(239, 229, 208, 0.42);
  --gold: #c9a45c;
  --gold-soft: rgba(201, 164, 92, 0.45);
  --cinnabar: #b8322a;
  --cinnabar-deep: #8f231d;

  --font-brush: "Ma Shan Zheng", "STXingkai", "华文行楷", "KaiTi", "楷体", serif;
  --font-serif: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --gutter: clamp(16px, 4vw, 48px);

  --text-size: clamp(17px, 0.95rem + 0.45vw, 22px);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-serif);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body { overflow: hidden; }

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

#app {
  position: fixed;
  inset: 0;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* ========== 背景 ========== */
/* 背景自成一层并置于最底，不接收点击（否则暗角会盖住整个界面，按钮点不到） */
.backdrop { position: absolute; inset: 0; z-index: 0; pointer-events: none; }

.bg-layer {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0;
  /* 新图盖在旧图之上淡入：前后均匀的缓动，不要一开始就猛变 */
  transition: opacity 1.2s cubic-bezier(0.45, 0, 0.25, 1), filter 1.2s ease;
  animation: drift 40s ease-in-out infinite alternate;
}
.bg-layer.shown { opacity: 1; }
/* 页面打开时的第一张：保留原来的入场节奏（1.4 秒、前快后慢） */
.bg-layer.first { transition: opacity 1.4s var(--ease), filter 1.2s ease; }
@keyframes drift {
  from { transform: scale(1.04); }
  to   { transform: scale(1.12) translate(-1.5%, -1%); }
}

/* 两套暗角各占一层，靠透明度交叉淡变（渐变背景本身无法做过渡，直接替换会跳） */
.shade { position: absolute; inset: 0; } /* 在 DOM 中位于各背景图之后，自然盖在图上 */
.shade::before, .shade::after {
  content: "";
  position: absolute; inset: 0;
  transition: opacity 1.2s ease;
}
.shade::before {
  background:
    radial-gradient(120% 90% at 50% 40%, transparent 40%, rgba(8, 6, 5, 0.7) 100%),
    linear-gradient(to bottom, rgba(8, 6, 5, 0.55) 0%, transparent 18%, transparent 45%, rgba(8, 6, 5, 0.88) 100%);
}
.shade::after {
  opacity: 0;
  background:
    radial-gradient(110% 90% at 30% 50%, rgba(8, 6, 5, 0.35) 0%, rgba(8, 6, 5, 0.85) 75%),
    linear-gradient(to right, rgba(8, 6, 5, 0.2), rgba(8, 6, 5, 0.75));
}
body[data-screen="title"] .shade::before,
body[data-screen="end"] .shade::before { opacity: 0; }
body[data-screen="title"] .shade::after,
body[data-screen="end"] .shade::after { opacity: 1; }
body[data-screen="title"] .bg-layer { filter: saturate(0.7) brightness(0.8); }

/* ========== 屏幕通用 ========== */
.screen {
  position: absolute; inset: 0;
  padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + var(--gutter)) calc(var(--safe-b) + 16px) calc(var(--safe-l) + var(--gutter));
  animation: fade-in 0.8s var(--ease);
}
@keyframes fade-in { from { opacity: 0; } }

/* 纸色按钮 */
.title-menu button,
.end-actions button {
  min-width: 10em;
  padding: 0.7em 1.6em;
  background: rgba(14, 11, 9, 0.45);
  border: 1px solid var(--gold-soft);
  border-radius: 2px;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  font-size: 1.05rem;
  transition: background 0.25s, border-color 0.25s, color 0.25s;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.title-menu button:hover,
.end-actions button:hover {
  background: var(--cinnabar-deep);
  border-color: var(--cinnabar);
}

/* ========== 标题 ========== */
#screen-title {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 32px;
}

.title-block {
  justify-self: center;
  display: flex;
  align-items: flex-end;
  gap: 18px;
}
.title-mark {
  margin: 0;
  writing-mode: vertical-rl;
  font-family: var(--font-brush);
  font-weight: 400;
  font-size: clamp(64px, 12vh, 132px);
  line-height: 1;
  letter-spacing: 0.08em;
  color: var(--paper);
  text-shadow: 0 4px 30px rgba(0, 0, 0, 0.6);
  animation: ink-in 2.2s var(--ease) both;
}
@keyframes ink-in {
  from { opacity: 0; filter: blur(12px); letter-spacing: 0.3em; }
}
.seal {
  display: grid; place-items: center;
  width: 2.6em; height: 2.6em;
  writing-mode: vertical-rl;
  font-family: var(--font-brush);
  font-size: clamp(14px, 2vh, 20px);
  line-height: 1.05;
  color: #f6e8dc;
  background: var(--cinnabar);
  border-radius: 3px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.18);
  transform: rotate(-4deg);
  animation: fade-in 1s 1.6s var(--ease) both;
}

.title-side {
  display: flex; flex-direction: column; align-items: flex-end; gap: 28px;
  padding-right: 4vw;
}
.title-menu {
  display: flex; flex-direction: column; gap: 12px;
  animation: fade-in 1.2s 1.1s var(--ease) both;
}
.sound-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--paper-faint);
  letter-spacing: 0.2em;
  animation: breathe 2.6s ease-in-out infinite;
  transition: opacity 0.4s;
}
body.sound-on .sound-hint { opacity: 0; animation: none; }
@keyframes breathe { 50% { opacity: 0.35; } }


/* ========== 游戏 HUD ========== */
#screen-game { cursor: pointer; }

.hud {
  position: absolute;
  top: calc(var(--safe-t) + 10px);
  left: calc(var(--safe-l) + var(--gutter));
  right: calc(var(--safe-r) + var(--gutter));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  z-index: 3;
}
.hud-chapter {
  margin: 0;
  font-size: 0.85rem;
  letter-spacing: 0.3em;
  color: var(--paper-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hud-actions { display: flex; gap: 4px; }

.icon-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 50%;
  color: var(--paper-dim);
  transition: background 0.2s, color 0.2s;
}
.icon-btn:hover { background: rgba(239, 229, 208, 0.1); color: var(--paper); }
.icon-btn svg {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.icon-btn[aria-pressed="true"] { color: var(--ink); background: var(--gold); }
.icon-btn[aria-pressed="true"] svg { fill: currentColor; }

/* ========== 纪年 ========== */
.era {
  position: absolute;
  top: calc(var(--safe-t) + 76px);
  left: calc(var(--safe-l) + var(--gutter));
  display: flex; align-items: flex-start; gap: 10px;
  pointer-events: none;
  opacity: 0;
}
.era.in { animation: era-in 1.6s var(--ease) forwards; }
@keyframes era-in {
  from { opacity: 0; transform: translateY(-10px); filter: blur(6px); }
  to   { opacity: 1; transform: none; filter: none; }
}
.era-name {
  writing-mode: vertical-rl;
  font-family: var(--font-brush);
  font-size: clamp(34px, 6vh, 60px);
  line-height: 1;
  letter-spacing: 0.12em;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.75);
}
.era-year {
  writing-mode: vertical-rl;
  padding-top: 0.3em;
  font-size: 0.8rem;
  letter-spacing: 0.35em;
  color: var(--gold);
  border-left: 1px solid var(--gold-soft);
  padding-left: 6px;
}

/* ========== 对话框 ========== */
.dialogue {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + clamp(16px, 4vh, 40px));
  transform: translateX(-50%);
  width: min(960px, calc(100% - 2 * var(--gutter) - var(--safe-l) - var(--safe-r)));
  padding: clamp(18px, 3vh, 28px) clamp(20px, 3vw, 36px) 14px;
  background: linear-gradient(to bottom, rgba(18, 14, 11, 0.78), rgba(12, 9, 7, 0.9));
  border-top: 1px solid var(--gold-soft);
  border-radius: 2px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: rise 0.6s var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 12px); } }

.speaker {
  position: absolute;
  top: 0; left: clamp(20px, 3vw, 36px);
  transform: translateY(-55%);
  margin: 0;
  padding: 0.3em 0.9em 0.3em 1.2em;
  font-family: var(--font-brush);
  font-size: 1.05rem;
  line-height: 1.2;
  letter-spacing: 0.3em;
  color: #f4e6d6;
  background:
    radial-gradient(circle at 25% 30%, rgba(255, 255, 255, 0.1), transparent 50%),
    var(--cinnabar);
  border-radius: 2px;
  box-shadow: inset 0 0 0 2px var(--cinnabar), inset 0 0 0 3px rgba(244, 230, 214, 0.5);
}
/* 抉择提问：名牌两侧加金色菱形，顶部金线加粗 */
.dialogue.is-choice { border-top-color: var(--gold); }
.dialogue.is-choice .speaker::before,
.dialogue.is-choice .speaker::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 7px; height: 7px;
  background: var(--gold);
  transform: translateY(-50%) rotate(45deg);
}
.dialogue.is-choice .speaker::before { left: -14px; }
.dialogue.is-choice .speaker::after { right: -14px; }
.line {
  margin: 0;
  min-height: calc(var(--text-size) * 1.9 * 3);
  font-size: var(--text-size);
  line-height: 1.9;
  letter-spacing: 0.04em;
  text-align: justify;
  color: var(--paper);
}
.dialogue-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px;
  height: 20px;
}
.progress {
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  color: var(--paper-faint);
  font-variant-numeric: tabular-nums;
}
.next-mark {
  width: 10px; height: 10px;
  border-right: 1.5px solid var(--gold);
  border-bottom: 1.5px solid var(--gold);
  transform: rotate(45deg);
  opacity: 0;
}
.dialogue.asking .next-mark,
.dialogue.asking .progress { visibility: hidden; }
.dialogue.done .next-mark {
  opacity: 1;
  animation: nudge 1.4s ease-in-out infinite;
}
@keyframes nudge { 50% { transform: translateY(4px) rotate(45deg); } }

/* ========== 选项（木牌 + 角花 + 大写数字章） ========== */
.choices {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + clamp(16px, 4vh, 40px) + var(--dialogue-h, 0px) + 20px);
  transform: translateX(-50%);
  z-index: 2;
  width: min(580px, calc(100% - 2 * var(--gutter)));
  display: flex; flex-direction: column; gap: 12px;
  cursor: default;
  outline: none;
}
.choice {
  position: relative;
  display: flex; align-items: center; gap: 16px;
  width: 100%;
  padding: 14px 22px 14px 14px;
  text-align: left;
  font-size: calc(var(--text-size) * 0.95);
  letter-spacing: 0.08em;
  line-height: 1.6;
  color: var(--paper);
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.012) 0 2px, transparent 2px 7px),
    linear-gradient(90deg, rgba(30, 23, 17, 0.94), rgba(18, 13, 10, 0.86));
  border: 1px solid rgba(201, 164, 92, 0.4);
  border-radius: 0;
  box-shadow: inset 0 0 0 3px rgba(18, 13, 10, 0.9), inset 0 0 0 4px rgba(201, 164, 92, 0.16);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: border-color 0.3s, box-shadow 0.3s, transform 0.3s;
  animation: rise-c 0.6s var(--ease) both;
  overflow: hidden;
}
/* 角花 */
.choice::before, .choice::after {
  content: "";
  position: absolute;
  width: 12px; height: 12px;
  border: 0 solid var(--gold);
  opacity: 0.75;
  transition: opacity 0.3s, width 0.3s, height 0.3s;
}
.choice::before { top: 3px; left: 3px; border-width: 1.5px 0 0 1.5px; }
.choice::after { bottom: 3px; right: 3px; border-width: 0 1.5px 1.5px 0; }
.choice:nth-child(2) { animation-delay: 0.08s; }
.choice:nth-child(3) { animation-delay: 0.16s; }
.choice:nth-child(4) { animation-delay: 0.24s; }
@keyframes rise-c { from { opacity: 0; transform: translateY(10px); } }
.choice:hover, .choice:focus-visible {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 3px rgba(18, 13, 10, 0.9), inset 0 0 0 4px rgba(201, 164, 92, 0.4);
}
.choice:hover::before, .choice:hover::after { opacity: 1; width: 18px; height: 18px; }
.choice:focus-visible { outline: none; }

/* 大写数字小方章 */
.choice-key {
  flex: none;
  display: grid; place-items: center;
  width: 30px; height: 30px;
  font-family: var(--font-brush);
  font-size: 1.05rem;
  line-height: 1;
  color: var(--cinnabar);
  border: 1.5px solid var(--cinnabar);
  border-radius: 2px;
  box-shadow: inset 0 0 0 2px rgba(18, 13, 10, 0.9), inset 0 0 0 3px rgba(184, 50, 42, 0.45);
  transition: background 0.3s, color 0.3s;
}
.choice:hover .choice-key, .choice:focus-visible .choice-key {
  background: var(--cinnabar);
  color: #f4e6d6;
  box-shadow: inset 0 0 0 2px var(--cinnabar), inset 0 0 0 3px rgba(244, 230, 214, 0.55);
}

/* ========== 片尾：MV + 滚动演职员表 ========== */
#screen-finale {
  --roll-w: clamp(240px, 30vw, 400px);
  padding: 0;
  background: #000;
  z-index: 5;
  overflow: hidden;
  animation: fade-in 1.6s var(--ease);
}
/* 桌面：MV 在左，演职员表在右 */
.finale-video {
  position: absolute;
  top: 50%; left: calc((100% - var(--roll-w)) / 2);
  width: min(calc(100% - var(--roll-w) - 6vw), calc(78vh * 16 / 9));
  aspect-ratio: 16 / 9;
  transform: translate(-50%, -50%);
  transition: width 1.6s var(--ease), left 1.6s var(--ease);
}
.finale-video video { display: block; width: 100%; height: 100%; object-fit: contain; background: #000; }
.finale-roll {
  position: absolute;
  top: 0; bottom: 0; right: 0;
  width: var(--roll-w);
  overflow: hidden;
  /* 上下渐隐，字幕像从暗处浮现、消失 */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 16%, #000 84%, transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 16%, #000 84%, transparent 100%);
  transition: opacity 1.2s ease;
}
.roll-track {
  position: absolute; left: 0; right: 0; top: 0;
  padding: 0 28px;
  text-align: center;
  will-change: transform;
}
.roll-title { margin: 0 0 58vh; font-size: clamp(34px, 3.4vw, 52px); font-weight: 400; letter-spacing: 0.2em; text-indent: 0.2em; }
.roll-sec { margin: 0 0 6vh; }
.roll-head { margin: 0 0 12px; font-size: 0.8rem; font-weight: 400; color: var(--gold); letter-spacing: 0.4em; text-indent: 0.4em; }
.roll-row { margin: 0 0 8px; font-size: 1rem; letter-spacing: 0.2em; text-indent: 0.2em; color: var(--paper); }
.roll-row.pair { display: flex; justify-content: center; gap: 1.2em; }
.roll-role { color: var(--paper-dim); }
.roll-closing { margin: 16vh 0 0; font-size: 1.6rem; letter-spacing: 0.4em; text-indent: 0.4em; }
/* MV 自带的片尾字幕开始后：画面放大居中，演职员表淡出 */
#screen-finale.full .finale-video { left: 50%; width: min(96vw, calc(96vh * 16 / 9)); }
#screen-finale.full .finale-roll { opacity: 0; }
.finale-skip, .finale-play {
  position: absolute;
  z-index: 2;
  padding: 8px 18px;
  background: rgba(14, 11, 9, 0.6);
  border: 1px solid var(--gold-soft);
  border-radius: 2px;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  font-size: 0.85rem;
}
/* 放在右上角：演职员表在那里已经淡出，不会压住字幕 */
.finale-skip { right: calc(var(--safe-r) + 18px); top: calc(var(--safe-t) + 14px); opacity: 0.45; transition: opacity 0.3s; }
.finale-skip:hover, .finale-skip:focus-visible { opacity: 1; }
.finale-play { top: 50%; left: calc((100% - var(--roll-w)) / 2); transform: translate(-50%, -50%); padding: 14px 28px; font-size: 1rem; background: var(--cinnabar-deep); border-color: var(--cinnabar); }

/* 竖屏：MV 在上，演职员表在下 */
@media (max-aspect-ratio: 1/1) {
  .finale-video { top: calc(var(--safe-t) + 8vh); left: 50%; width: 100%; transform: translateX(-50%); }
  .finale-roll { top: calc(var(--safe-t) + 8vh + 56.25vw + 2vh); width: 100%; }
  .finale-play { left: 50%; top: calc(var(--safe-t) + 8vh + 28vw); }
  #screen-finale.full .finale-video { top: 50%; width: 100%; transform: translate(-50%, -50%); }
}

/* 内容比屏幕高时可滚动；margin:auto 居中，不会像 place-items 那样把顶部裁掉 */
#screen-end { display: flex; overflow-y: auto; overscroll-behavior: contain; user-select: text; -webkit-user-select: text; }
.end-wrap {
  margin: auto;
  width: 100%;
  max-width: 1120px;
  padding: 24px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 470px);
  align-items: center;
  gap: clamp(32px, 6vw, 88px);
}
.end-wrap:has(.end-persona[hidden]) { grid-template-columns: minmax(0, 1fr); justify-items: center; }
.end-card {
  max-width: 34em;
  text-align: center;
  justify-self: center;
}
.end-label {
  margin: 0 0 8px;
  color: var(--gold);
  letter-spacing: 0.6em;
  text-indent: 0.6em;
  font-size: 0.9rem;
}
.end-title {
  margin: 0;
  font-family: var(--font-brush);
  font-weight: 400;
  font-size: clamp(44px, 9vw, 84px);
  letter-spacing: 0.1em;
  text-shadow: 0 4px 30px rgba(0, 0, 0, 0.6);
  animation: ink-in 1.8s var(--ease) both;
}
.end-text {
  margin: 24px 0 0;
  text-wrap: balance;
  line-height: 1.9;
  font-size: var(--text-size);
  color: var(--paper-dim);
}
.end-count {
  margin: 20px 0 32px;
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  color: var(--paper-faint);
}
.end-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }

/* ========== 乱世画像 ========== */
.persona {
  position: relative;
  padding: 26px 26px 20px;
  background: linear-gradient(180deg, rgba(26, 21, 18, 0.88), rgba(14, 11, 9, 0.92));
  border: 1px solid var(--gold-soft);
  border-radius: 4px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fade-in 1.2s 0.6s var(--ease) both;
}
.p-head { text-align: left; }
.p-kicker {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.5em;
  color: var(--gold);
}
.p-name {
  margin: 6px 0 2px;
  font-family: var(--font-brush);
  font-weight: 400;
  font-size: clamp(44px, 6vw, 60px);
  line-height: 1.15;
  letter-spacing: 0.08em;
}
.p-tagline { margin: 0; letter-spacing: 0.2em; color: var(--paper-dim); }
.p-body {
  display: grid;
  grid-template-columns: 172px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  margin-top: 16px;
}
.p-radar { display: block; width: 100%; height: auto; overflow: visible; }
.r-ring { fill: rgba(239, 229, 208, 0.03); stroke: var(--gold-soft); stroke-width: 1; }
.r-mid { fill: none; stroke: rgba(201, 164, 92, 0.3); stroke-width: 1; stroke-dasharray: 3 4; }
.r-spoke { stroke: rgba(201, 164, 92, 0.18); stroke-width: 1; }
.r-shape { fill: rgba(184, 50, 42, 0.5); stroke: var(--cinnabar); stroke-width: 1.6; stroke-linejoin: round; }
.r-label { fill: var(--paper); font-size: 17px; font-weight: 600; text-anchor: middle; font-family: var(--font-serif); }
.p-desc { margin: 0; line-height: 1.85; font-size: 0.95rem; }
.p-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; }
.p-tag {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 2px 10px 3px;
  border: 1px solid rgba(201, 164, 92, 0.35);
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--paper-dim);
}
.p-tag b { color: var(--gold); font-weight: 600; font-size: 0.9rem; }
.p-kindred { margin: 12px 0 0; font-size: 0.82rem; line-height: 1.7; color: var(--paper-dim); }
.p-kindred-h { margin-right: 8px; font-size: 0.72rem; letter-spacing: 0.25em; color: var(--gold); }
.p-kindred b { margin-right: 8px; font-weight: 600; color: var(--paper); }
.p-because { margin-top: 18px; padding-top: 14px; border-top: 1px solid rgba(201, 164, 92, 0.18); text-align: left; }
.p-because h4 { margin: 0 0 6px; font-size: 0.78rem; font-weight: 400; letter-spacing: 0.4em; color: var(--gold); }
.p-because ul { list-style: none; margin: 0; padding: 0; }
.p-because li { padding: 3px 0; font-size: 0.9rem; line-height: 1.7; color: var(--paper-dim); }
.p-meta { margin: 14px 0 0; font-size: 0.76rem; letter-spacing: 0.08em; color: var(--paper-faint); text-align: left; }
.p-actions { margin-top: 16px; }
.p-share, .share-save, .share-native {
  display: inline-block;
  padding: 0.65em 1.6em;
  background: var(--cinnabar-deep);
  border: 1px solid var(--cinnabar);
  border-radius: 2px;
  color: var(--paper);
  font-size: 0.98rem;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  text-decoration: none;
  transition: background 0.25s;
}
.p-share:hover, .share-save:hover, .share-native:hover { background: var(--cinnabar); }
.p-share { width: 100%; }
.p-note { margin: 10px 0 0; font-size: 0.7rem; letter-spacing: 0.06em; color: var(--paper-faint); text-align: center; }

/* 画像弹层与分享图 */
.persona-sheet { padding: 16px; overflow-y: auto; }
.persona-sheet .persona { box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; animation: none; }
.share { padding: 16px 22px 22px; overflow-y: auto; text-align: center; }
.share-status { margin: 40px 0; color: var(--paper-dim); letter-spacing: 0.2em; }
.share-img {
  display: block;
  width: 100%;
  max-width: 360px;
  height: auto;
  margin: 0 auto;
  border: 1px solid rgba(201, 164, 92, 0.3);
  -webkit-touch-callout: default;
  user-select: auto;
  -webkit-user-select: auto;
}
.share-hint { margin: 12px 0 0; font-size: 0.78rem; color: var(--paper-faint); letter-spacing: 0.1em; }
.share-actions { display: flex; justify-content: center; gap: 10px; margin-top: 14px; }
.share-native { font: inherit; font-size: 0.98rem; }

.replay-finale {
  margin-top: 14px;
  padding: 0.55em 1.4em;
  background: none;
  border: 1px solid var(--gold-soft);
  border-radius: 2px;
  color: var(--gold);
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.replay-finale:hover { background: var(--cinnabar-deep); border-color: var(--cinnabar); color: var(--paper); }

/* 成就面板里的历次画像 */
.run-list { list-style: none; margin: 0; padding: 0; }
.run-list li + li { margin-top: 6px; }
.run-empty { padding: 10px 0; font-size: 0.85rem; color: var(--paper-faint); }
.run-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  background: rgba(239, 229, 208, 0.04);
  border: 1px solid rgba(201, 164, 92, 0.2);
  border-radius: 2px;
  transition: background 0.2s, border-color 0.2s;
}
.run-item:hover { background: var(--cinnabar-deep); border-color: var(--cinnabar); }
.run-name { font-family: var(--font-brush); font-size: 1.3rem; letter-spacing: 0.06em; }
.run-end { font-size: 0.8rem; color: var(--paper-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-date { font-size: 0.72rem; color: var(--paper-faint); font-variant-numeric: tabular-nums; }

/* 窄屏、竖屏：结局在上，画像在下 */
@media (max-width: 900px), (max-aspect-ratio: 1/1) {
  .end-wrap { grid-template-columns: minmax(0, 1fr); max-width: 560px; gap: 36px; padding: 32px 0 calc(var(--safe-b) + 24px); }
}
@media (max-width: 420px) {
  .persona { padding: 22px 18px 18px; }
  .p-body { grid-template-columns: minmax(0, 1fr); justify-items: center; }
  .p-radar-wrap { width: 200px; }
  .run-item { grid-template-columns: auto minmax(0, 1fr); }
  .run-date { grid-column: 1 / -1; }
}

/* ========== 章节卡 ========== */
.chapter-card {
  position: absolute; inset: 0;
  display: grid; place-content: center;
  text-align: center;
  background: radial-gradient(80% 60% at 50% 50%, rgba(8, 6, 5, 0.55), rgba(8, 6, 5, 0.88));
  animation: fade-in 1s var(--ease);
  z-index: 4;
}
.card-label {
  margin: 0 0 10px;
  color: var(--gold);
  letter-spacing: 0.8em;
  text-indent: 0.8em;
  font-size: clamp(1rem, 0.9rem + 0.4vw, 1.25rem);
  animation: fade-in 1s 0.2s var(--ease) both;
}
.card-title {
  margin: 0;
  font-family: var(--font-brush);
  font-weight: 400;
  font-size: clamp(48px, 10vw, 104px);
  letter-spacing: 0.12em;
  text-shadow: 0 4px 30px rgba(0, 0, 0, 0.6);
  animation: ink-in 2s var(--ease) both;
}

/* ========== 视频 ========== */
.video-layer {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: #000;
  z-index: 5;
  cursor: default;
}
.video-layer video { width: 100%; height: 100%; object-fit: contain; }
.video-skip {
  position: absolute;
  top: calc(var(--safe-t) + 14px);
  right: calc(var(--safe-r) + var(--gutter));
  padding: 8px 18px;
  background: rgba(14, 11, 9, 0.6);
  border: 1px solid var(--gold-soft);
  border-radius: 2px;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  font-size: 0.9rem;
}
.video-skip:hover { background: var(--cinnabar-deep); border-color: var(--cinnabar); }

/* ========== 提示（匾额 + 朱印） ========== */
.toasts {
  position: fixed;
  top: calc(var(--safe-t) + 64px);
  left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 10px; align-items: center;
  width: max-content;
  max-width: calc(100% - 2 * var(--gutter));
  z-index: 10;
  pointer-events: none;
}
.toast {
  position: relative;
  display: flex; align-items: center; gap: 16px;
  min-width: 240px;
  padding: 12px 26px 12px 12px;
  color: var(--paper);
  /* 漆面：深褐底 + 细微纵向木纹 */
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.012) 0 2px, transparent 2px 7px),
    linear-gradient(180deg, #221a13, #140f0b);
  border: 1px solid rgba(201, 164, 92, 0.55);
  box-shadow:
    inset 0 0 0 3px #150f0b,
    inset 0 0 0 4px rgba(201, 164, 92, 0.28),
    0 14px 40px rgba(0, 0, 0, 0.55);
  animation: toast-in 0.6s var(--ease);
  transition: opacity 0.6s, transform 0.6s;
}
/* 四角金色角花（左上 + 右下，另两角由 body 伪元素绘制） */
.toast::before, .toast::after,
.toast-body::before, .toast-body::after {
  content: "";
  position: absolute;
  width: 10px; height: 10px;
  border: 0 solid var(--gold);
}
.toast::before { top: -4px; left: -4px; border-width: 2px 0 0 2px; }
.toast::after { bottom: -4px; right: -4px; border-width: 0 2px 2px 0; }
.toast-body::before { top: -4px; right: -4px; border-width: 2px 2px 0 0; }
.toast-body::after { bottom: -4px; left: -4px; border-width: 0 0 2px 2px; }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-12px) scale(0.98); } }

/* 朱印：方章、白文、微斜，带一点印泥不均的质感 */
.toast-seal {
  flex: none;
  display: grid; place-items: center;
  width: 44px; height: 44px;
  writing-mode: vertical-rl;
  font-family: var(--font-brush);
  font-size: 17px;
  line-height: 1;
  letter-spacing: 0.05em;
  color: #f4e6d6;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.12), transparent 45%),
    radial-gradient(circle at 75% 80%, rgba(0, 0, 0, 0.18), transparent 50%),
    var(--cinnabar);
  border-radius: 3px;
  box-shadow: inset 0 0 0 2px var(--cinnabar), inset 0 0 0 3px rgba(244, 230, 214, 0.55);
  transform: rotate(-5deg);
  animation: stamp 0.5s 0.15s var(--ease) both;
}
@keyframes stamp {
  from { opacity: 0; transform: rotate(-5deg) scale(1.5); }
}
.toast-body { display: flex; flex-direction: column; gap: 2px; }
.toast-kind {
  font-size: 0.7rem;
  letter-spacing: 0.4em;
  color: var(--gold);
}
.toast-title {
  font-family: var(--font-brush);
  font-size: 1.35rem;
  line-height: 1.3;
  letter-spacing: 0.12em;
}

/* ========== 弹层 ========== */
.sheet {
  width: min(560px, calc(100% - 32px));
  max-height: min(78dvh, 720px);
  padding: 0;
  display: flex; flex-direction: column;
  color: var(--paper);
  background: var(--ink-2);
  border: 1px solid var(--gold-soft);
  border-radius: 4px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  user-select: text;
}
.sheet:not([open]) { display: none; }
.sheet::backdrop { background: rgba(5, 4, 3, 0.6); backdrop-filter: blur(3px); }
.sheet[open] { animation: sheet-in 0.35s var(--ease); }
@keyframes sheet-in { from { opacity: 0; transform: translateY(16px); } }

.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px 14px 22px;
  border-bottom: 1px solid rgba(201, 164, 92, 0.2);
}
.sheet-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.5em;
}
.close {
  width: 44px; height: 44px;
  background: none; border: 0;
  font-size: 1.6rem; line-height: 1;
  color: var(--paper-dim);
}
.close:hover { color: var(--paper); }

.backlog-list, .chapter-list {
  list-style: none;
  margin: 0;
  padding: 8px 22px 22px;
  overflow-y: auto;
}
.backlog-list li {
  position: relative;
  padding: 14px 44px 14px 0;
  border-bottom: 1px solid rgba(239, 229, 208, 0.08);
}
.backlog-list p { margin: 0; line-height: 1.85; color: var(--paper-dim); }
.backlog-list li:last-child p { color: var(--paper); }
.bl-era { display: block; margin-bottom: 4px; font-size: 0.75rem; letter-spacing: 0.2em; color: var(--gold); }
.bl-voice {
  position: absolute; right: 0; top: 12px;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: none; border: 1px solid rgba(201, 164, 92, 0.3); border-radius: 50%;
  color: var(--gold);
}
.bl-voice svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.bl-voice:hover { background: rgba(201, 164, 92, 0.15); }

.chapter-list li + li { margin-top: 8px; }
.chapter-item {
  display: grid;
  grid-template-columns: 4.5em 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  text-align: left;
  background: rgba(239, 229, 208, 0.04);
  border: 1px solid rgba(201, 164, 92, 0.25);
  border-radius: 2px;
  transition: background 0.2s, border-color 0.2s;
}
.chapter-item:not(:disabled):hover { background: var(--cinnabar-deep); border-color: var(--cinnabar); }
.chapter-item:disabled { opacity: 0.45; }
.ci-label { font-size: 0.8rem; letter-spacing: 0.2em; color: var(--gold); }
.ci-title { font-size: 1.05rem; letter-spacing: 0.15em; }
.ci-status { font-size: 0.72rem; letter-spacing: 0.15em; color: var(--paper-faint); }

.honors { padding: 4px 22px 22px; overflow-y: auto; }
.honors h3 {
  margin: 18px 0 10px;
  font-size: 0.9rem; font-weight: 600;
  letter-spacing: 0.3em;
  color: var(--gold);
}
.honors h3 span { margin-left: 8px; font-weight: 400; letter-spacing: 0.1em; color: var(--paper-faint); }
.ach-list, .end-list { list-style: none; margin: 0; padding: 0; }
.ach-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.ach-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(201, 164, 92, 0.2);
  color: var(--paper-faint);
  letter-spacing: 0.1em;
}
.h-mark { flex: none; width: 10px; height: 10px; transform: rotate(45deg); border: 1px solid var(--paper-faint); }
.ach-list li.got { color: var(--paper); border-color: var(--gold-soft); }
.ach-list li.got .h-mark { background: var(--cinnabar); border-color: var(--cinnabar); }
.end-list li { padding: 12px 0; border-bottom: 1px solid rgba(239, 229, 208, 0.08); }
.h-label { font-size: 0.8rem; letter-spacing: 0.2em; color: var(--paper-faint); }
.end-list li.got .h-label { color: var(--gold); }
.h-text { margin: 4px 0 0; line-height: 1.8; color: var(--paper-faint); font-size: 0.92rem; }
.end-list li.got .h-text { color: var(--paper-dim); }

.settings { padding: 8px 22px 22px; overflow-y: auto; }
.field {
  display: flex; flex-direction: column; gap: 10px;
  margin: 0; padding: 16px 0;
  border: 0;
  border-bottom: 1px solid rgba(239, 229, 208, 0.08);
  font-size: 0.95rem;
  letter-spacing: 0.15em;
}
.field legend { padding: 0; float: left; width: 100%; margin-bottom: 10px; }
.field.row { flex-direction: row; align-items: center; justify-content: space-between; }

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); clear: both; border: 1px solid var(--gold-soft); border-radius: 2px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: block; padding: 10px 0; text-align: center;
  font-size: 0.9rem; letter-spacing: 0.1em;
  transition: background 0.2s, color 0.2s;
}
.segmented label + label span { border-left: 1px solid rgba(201, 164, 92, 0.25); }
.segmented input:checked + span { background: var(--gold); color: var(--ink); }
.segmented input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }

input[type="range"] { width: 100%; accent-color: var(--cinnabar); height: 28px; }

.switch {
  appearance: none; -webkit-appearance: none;
  position: relative; width: 48px; height: 28px; margin: 0;
  border-radius: 14px; background: rgba(239, 229, 208, 0.18);
  cursor: pointer; transition: background 0.2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: var(--paper);
  transition: transform 0.2s var(--ease);
}
.switch:checked { background: var(--cinnabar); }
.switch:checked::after { transform: translateX(20px); }

.keys { margin: 16px 0 0; font-size: 0.78rem; line-height: 1.8; color: var(--paper-faint); letter-spacing: 0.05em; }

/* ========== 响应式 ========== */

/* 手机竖屏 */
@media (max-width: 720px) {
  #screen-title {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    align-items: stretch;
    padding-bottom: calc(var(--safe-b) + 24px);
  }
  .title-block { align-self: center; }
  .title-side { align-items: stretch; padding-right: 0; gap: 18px; }
  .title-menu { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .title-menu button { min-width: 0; width: 100%; padding-left: 0; padding-right: 0; letter-spacing: 0.3em; text-indent: 0.3em; }
  .title-menu [data-action="continue"],
  .title-menu [data-action="new"] { grid-column: 1 / -1; letter-spacing: 0.5em; text-indent: 0.5em; }
  .sound-hint { text-align: center; }

  .hud-chapter { font-size: 0.78rem; letter-spacing: 0.2em; }
  .icon-btn { width: 40px; height: 40px; }
  .era { top: calc(var(--safe-t) + 66px); }

  .dialogue {
    width: auto;
    left: 0; right: 0;
    transform: none;
    bottom: 0;
    padding: 22px calc(var(--gutter) + var(--safe-r)) calc(var(--safe-b) + 14px) calc(var(--gutter) + var(--safe-l));
    border-radius: 0;
    animation-name: rise-m;
  }
  @keyframes rise-m { from { opacity: 0; transform: translateY(12px); } }
  .speaker { left: var(--gutter); }
  .line { min-height: calc(var(--text-size) * 1.85 * 4); line-height: 1.85; }

  .choices { bottom: calc(var(--dialogue-h, 0px) + 16px); }
  .choice { padding: 12px 16px 12px 12px; gap: 12px; }

  .sheet {
    width: 100%; max-width: none;
    margin: auto 0 0;
    max-height: 82dvh;
    border-radius: 12px 12px 0 0;
    border-width: 1px 0 0;
    padding-bottom: var(--safe-b);
  }
  @keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
}

/* 手机横屏等矮屏 */
@media (max-height: 500px) {
  .title-mark { font-size: clamp(48px, 20vh, 90px); }
  .title-menu { gap: 8px; }
  .title-menu button { padding: 0.5em 1.4em; }
  .title-side { gap: 14px; }
  .era { top: calc(var(--safe-t) + 58px); }
  .era-name { font-size: 30px; }
  .dialogue { bottom: calc(var(--safe-b) + 10px); padding-top: 14px; padding-bottom: 8px; }
  .choices { bottom: calc(var(--safe-b) + 10px + var(--dialogue-h, 0px) + 10px); }
  .line { min-height: calc(var(--text-size) * 1.7 * 2); line-height: 1.7; font-size: 17px; }
  .choices { gap: 8px; }
  .choice { padding: 8px 16px 8px 10px; }
  .choice-key { width: 26px; height: 26px; font-size: 0.95rem; }
}

@media (hover: none) {
  .choice:hover, .title-menu button:hover, .end-actions button:hover { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .bg-layer { animation: none; transform: scale(1.04); }
}
