:root {
  color-scheme: light;
  --surface: #fffdf7;
  --paper: #f8f3e7;
  --ink: #302b23;
  --muted: #6f6555;
  --edge: #ded2bd;
  --accent: #825028;
  --wash: #efe3cb;
  --font-size: 19px;
  --leading: 1.95;
  --paragraph: 14px;
  --reader-width: 820px;
  --body-font: "Noto Serif SC", "Songti SC", SimSun, serif;
  --body-align: start;
  --custom-ink: var(--ink);
  --custom-paper: var(--surface);
}

:root[data-theme="parchment"] {
  --surface: #f1e2c2;
  --paper: #e9d7ae;
  --ink: #3a2a1b;
  --muted: #675337;
  --edge: #cbb68b;
  --accent: #7a421f;
  --wash: #e4cea2;
}

:root[data-theme="gray"] {
  --surface: #fcfcfb;
  --paper: #efefee;
  --ink: #292d32;
  --muted: #5c6066;
  --edge: #d9dadd;
  --accent: #3d566e;
  --wash: #e2e8ed;
}

:root[data-theme="dark"], :root[data-theme="black"] {
  color-scheme: dark;
  --surface: #21252b;
  --paper: #181b20;
  --ink: #e8e2d6;
  --muted: #bdb6a7;
  --edge: #40454e;
  --accent: #edbb84;
  --wash: #343039;
}

:root[data-theme="black"] {
  --surface: #101012;
  --paper: #050505;
  --edge: #353537;
  --wash: #272527;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.6 "Microsoft YaHei", system-ui, sans-serif;
}

a { color: var(--accent); text-underline-offset: .25em; }
button, input, select { font: inherit; color: inherit; }
button, select, input[type="search"] {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 7px;
  padding: 7px 11px;
}
button { cursor: pointer; }
button[aria-pressed="true"], button:hover, .button:hover { background: var(--wash); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
input[type="range"], input[type="checkbox"] { accent-color: var(--accent); }
[hidden] { display: none !important; }
.masthead { background: var(--surface); border-bottom: 1px solid var(--edge); }
.bar {
  max-width: 1210px;
  margin: auto;
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 12px 22px;
}
.wordmark {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--ink);
  font-weight: 750;
  text-decoration: none;
}
.wordmark small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.emblem {
  padding: 3px 10px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  font-size: 22px;
  color: var(--accent);
  background: var(--wash);
}
.bar nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.bar nav a {
  color: var(--muted);
  border-radius: 6px;
  padding: 6px 9px;
  text-decoration: none;
}
.bar nav a[aria-current], .bar nav a:hover { background: var(--wash); color: var(--ink); }
#view { max-width: 1200px; margin: auto; min-height: 68vh; padding: 32px 22px 56px; }
h1, h2, h3, p { margin: 0; }
h1 { font: 700 clamp(1.85rem, 4vw, 3rem)/1.24 var(--body-font); overflow-wrap: anywhere; }
h2 { font-size: 1.22rem; line-height: 1.35; }
h3 { font-size: 1.05rem; }
.heading { margin-bottom: 24px; }
.heading > * + *, .block > * + * { margin-top: 9px; }
.muted, .kicker, .status, .footer { color: var(--muted); }
.kicker { font-size: .83rem; letter-spacing: .08em; }
.status { padding: 18px 0; }
.footer { text-align: center; padding: 18px; font-size: .8rem; border-top: 1px solid var(--edge); }
.panel, .card, .hero {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 12px;
}
.panel, .hero { padding: clamp(14px, 4vw, 32px); }
.hero { margin-bottom: 20px; }
.hero p { max-width: 58ch; }
.stack { display: grid; gap: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(225px, 100%), 1fr)); gap: 12px; }
.card { display: block; padding: 15px; text-decoration: none; color: inherit; overflow-wrap: anywhere; }
a.card:hover { border-color: var(--accent); }
.card strong { display: block; margin-bottom: 3px; }
.tools, .filters, .pager, .actions, .choices { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters { margin: 0 0 16px; }
.filters input[type="search"] { flex: 1 1 240px; min-width: 0; }
.filters select { max-width: 100%; }
.button { display: inline-block; padding: 7px 11px; color: var(--ink); text-decoration: none;
  background: var(--surface); border: 1px solid var(--edge); border-radius: 7px; }
.primary { background: var(--wash); border-color: var(--accent); }
.badge { display: inline-block; color: var(--muted); background: var(--wash); font-size: .8rem;
  border-radius: 5px; padding: 1px 6px; }
.section-list { padding: 0; margin: 0; list-style: none; }
.section-list li + li { border-top: 1px solid var(--edge); }
.section-list li > a { display: flex; justify-content: space-between; gap: 8px; padding: 11px 0; }
.section-list small { white-space: nowrap; }
.read-layout { max-width: var(--reader-width); margin: auto; }
.read-toolbar { margin: 12px 0; justify-content: space-between; }
.read-outline { margin-bottom: 12px; border: 1px solid var(--edge); border-radius: 8px;
  padding: 8px 12px; background: var(--surface); }
.read-outline select { display: block; max-width: 100%; margin: 7px 0 2px; }
.paper {
  background: var(--custom-paper);
  color: var(--custom-ink);
  border: 1px solid var(--edge);
  border-radius: 12px;
  padding: clamp(14px, 4vw, 38px);
  overflow-wrap: anywhere;
  font: var(--font-size)/var(--leading) var(--body-font);
  text-align: var(--body-align);
}
.scene + .scene { margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--edge); }
.scene-heading, .read-meta { font: .85rem/1.6 "Microsoft YaHei", system-ui, sans-serif; text-align: start; }
.scene-heading { margin-bottom: 20px; color: var(--muted); }
.dialogue { margin-bottom: var(--paragraph); scroll-margin-top: 32px; }
.line { position: relative; padding-inline-end: 25px; margin: 0; white-space: pre-wrap; scroll-margin-top: 36px; }
.speaker { display: inline-block; font: 650 .88em/1.5 "Microsoft YaHei", system-ui, sans-serif; }
.speaker a { color: inherit; text-decoration: underline dotted; }
.narration .line { font-style: italic; }
.line-save { position: absolute; inset: 0 0 auto auto; padding: 0 3px; border: 0;
  background: transparent; color: var(--accent); font: 15px/1.8 system-ui, sans-serif; opacity: .65; }
.line-save:hover, .line-save:focus, .line-save[aria-pressed="true"] { opacity: 1; }
.highlight { background: var(--wash); box-shadow: 0 0 0 3px var(--wash); border-radius: 3px; }
.choice-box, .branch-note { border: 1px solid var(--edge); border-radius: 7px;
  padding: 10px; margin: 10px 0; font: .86rem/1.65 "Microsoft YaHei", system-ui, sans-serif; }
.choice-box button { text-align: start; white-space: pre-wrap; }
.read-meta { margin: 16px 0; }
.read-meta summary, details summary { cursor: pointer; }
.pager { justify-content: space-between; margin-top: 20px; }
.focus-mode .bar nav, .focus-mode .footer { display: none; }
.portrait-grid { grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr)); }
.portrait-grid img, .portrait-grid .portrait-placeholder { display: block; width: 100%; aspect-ratio: 1;
  object-fit: contain; background: var(--wash); border-radius: 7px; margin-bottom: 8px; }
.portrait-placeholder { display: grid !important; place-items: center; color: var(--muted); font-size: .86rem; }
.profile { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 18px; }
.gallery img { display: block; width: 100%; height: clamp(200px, 42vh, 450px);
  object-fit: contain; background: var(--paper); border-radius: 8px; margin-top: 10px; }
.gallery select { width: 100%; }
.facts { display: grid; grid-template-columns: minmax(4.5em, auto) 1fr; gap: 5px 12px; margin: 0; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts dt { color: var(--muted); }
.source-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.voice-row, .search-row { scroll-margin-top: 32px; overflow-wrap: anywhere; }
.voice-row audio { display: block; max-width: 100%; margin-top: 7px; }
mark { background: var(--wash); color: inherit; box-shadow: 0 0 0 1px var(--accent); }
dialog { width: min(94vw, 600px); max-height: 90dvh; border: 1px solid var(--edge);
  border-radius: 14px; padding: clamp(13px, 3vw, 22px); background: var(--surface); color: var(--ink); overflow: auto; }
dialog::backdrop { background: #1d1b1780; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 9px; }
.settings-controls { display: grid; gap: 10px; margin: 16px 0; }
.settings-panel { min-width: 0; margin: 0; padding: 12px; border: 1px solid var(--edge);
  border-radius: 10px; background: var(--paper); }
.settings-panel legend { padding: 0 5px; color: var(--muted); font-size: .88rem; }
.settings-panel h3 { font-weight: 650; font-size: .96rem; }
.setting { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; align-items: center; }
.setting output { min-width: 48px; color: var(--muted); text-align: end; }
.setting + .setting, .setting-range, .setting-switch { border-top: 1px solid var(--edge); padding-top: 10px; }
.setting-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.setting-tiles button { display: grid; justify-items: center; align-content: center; min-width: 0;
  min-height: 58px; padding: 6px; gap: 3px; }
.setting-tiles button[aria-pressed="true"], .setting-segments button[aria-pressed="true"] {
  outline: 1px solid var(--accent); border-color: var(--accent); background: var(--wash); font-weight: 650;
}
.theme-preview { display: grid; width: 70%; max-width: 74px; justify-items: center; gap: 3px;
  --preview-ink: #8c9096; --preview-line: #bbc0c6; }
.preview-parchment { --preview-ink: #ae7443; --preview-line: #d4b88f; }
.preview-gray { --preview-ink: #647e8e; --preview-line: #a7bac8; }
.theme-preview i { display: block; width: 100%; height: 3px; background: var(--preview-line); border-radius: 2px; }
.theme-preview i:first-child { width: 72%; background: var(--preview-ink); }
.theme-preview i:last-child { width: 83%; }
.font-preview { font-size: 1.35rem; line-height: 1.2; }
.setting-segments, .size-stepper { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.size-stepper output { text-align: center; min-width: 58px; }
.setting-switch input { appearance: none; width: 42px; height: 23px; border: 1px solid var(--edge);
  border-radius: 20px; background: var(--wash); position: relative; cursor: pointer; }
.setting-switch input::before { content: ""; position: absolute; inset: 3px auto 3px 3px;
  aspect-ratio: 1; border-radius: 50%; background: var(--muted); }
.setting-switch input:checked { background: var(--accent); }
.setting-switch input:checked::before { inset-inline: auto 3px; background: var(--surface); }
.setting-range input { display: block; width: 100%; margin: 7px 0 3px; }
.text-button { border: 0; padding: 3px; background: transparent; color: var(--accent); text-decoration: underline; }

@media (max-width: 760px) {
  .bar { padding: 10px 13px; gap: 7px; }
  .bar nav { order: 3; width: 100%; font-size: .87rem; }
  #view { padding: 22px 12px 36px; }
  .profile { grid-template-columns: 1fr; }
  .section-list small { white-space: normal; text-align: end; }
}
