:root {
  color-scheme: light;
  --bg: #f6f3ed;
  --panel: #fffdf8;
  --ink: #24211d;
  --muted: #706a60;
  --line: #ddd5c8;
  --accent: #7f4b26;
  --accent-strong: #5f341b;
  --gold: #b97924;
  --danger: #a34335;
  --shadow: 0 16px 40px rgba(46, 37, 22, 0.12);
  --cycle-sidebar: #27231d;
  --cycle-sidebar-deep: #17140f;
  --cycle-sidebar-line: #776b59;
  --cycle-sidebar-card: #342f27;
  --cycle-sidebar-card-active: #423729;
  --cycle-sidebar-card-hover: #463726;
  --cycle-sidebar-text: #f8f0df;
  --cycle-sidebar-muted: #cfc3ae;
  --cycle-sidebar-label: #d6c8af;
  --cycle-sidebar-accent: #ffd480;
  --cycle-sidebar-accent-line: #c89742;
  --cycle-sidebar-button: #5d5141;
  --cycle-sidebar-card-line: #4b4337;
  --cycle-sidebar-hover-line: #e8bd6a;
}

/* 主色取自 assets/cycle-symbols 的五枚循环图标，浅底和深侧栏使用同色系。 */
body[data-cycle="c1"] {
  --bg: #f6f0eb;
  --panel: #fffdfb;
  --line: #e3d4c8;
  --accent: #7f4b26;
  --accent-strong: #5f341b;
  --gold: #9a682c;
  --cycle-sidebar: #4a2d1e;
  --cycle-sidebar-deep: #321d14;
  --cycle-sidebar-line: #916b50;
  --cycle-sidebar-card: #5e3b29;
  --cycle-sidebar-card-active: #754a32;
  --cycle-sidebar-card-hover: #845538;
  --cycle-sidebar-text: #fff8f1;
  --cycle-sidebar-muted: #dfc4b1;
  --cycle-sidebar-label: #eed5c2;
  --cycle-sidebar-accent: #f2b67e;
  --cycle-sidebar-accent-line: #c88a5f;
  --cycle-sidebar-button: #815642;
  --cycle-sidebar-card-line: #86553b;
  --cycle-sidebar-hover-line: #ffd0a8;
}

body[data-cycle="c2"] {
  --bg: #fbefed;
  --panel: #fffdfc;
  --line: #ead1cc;
  --accent: #a52206;
  --accent-strong: #7f1c08;
  --gold: #9b6722;
  --cycle-sidebar: #4b1c12;
  --cycle-sidebar-deep: #32130d;
  --cycle-sidebar-line: #9d5c4c;
  --cycle-sidebar-card: #61281c;
  --cycle-sidebar-card-active: #762f21;
  --cycle-sidebar-card-hover: #883a29;
  --cycle-sidebar-text: #fff6f3;
  --cycle-sidebar-muted: #e7bcb2;
  --cycle-sidebar-label: #f0d0c7;
  --cycle-sidebar-accent: #ffac96;
  --cycle-sidebar-accent-line: #d87c65;
  --cycle-sidebar-button: #85493b;
  --cycle-sidebar-card-line: #904737;
  --cycle-sidebar-hover-line: #ffd0c5;
}

body[data-cycle="c3"] {
  --bg: #f6f2fc;
  --panel: #fbfdff;
  --line: #e0d7ee;
  --accent: #752a7f;
  --accent-strong: #54205d;
  --gold: #a26d25;
  --cycle-sidebar: #3c2046;
  --cycle-sidebar-deep: #29162f;
  --cycle-sidebar-line: #89659a;
  --cycle-sidebar-card: #52305d;
  --cycle-sidebar-card-active: #663d71;
  --cycle-sidebar-card-hover: #75477f;
  --cycle-sidebar-text: #fff7ff;
  --cycle-sidebar-muted: #d9bddd;
  --cycle-sidebar-label: #ebd5ed;
  --cycle-sidebar-accent: #e6b6ef;
  --cycle-sidebar-accent-line: #b17ac0;
  --cycle-sidebar-button: #724d79;
  --cycle-sidebar-card-line: #80518c;
  --cycle-sidebar-hover-line: #f2d4f8;
}

body[data-cycle="c4"] {
  --bg: #faf7ed;
  --panel: #fffef9;
  --line: #e8dfc4;
  --accent: #a0843d;
  --accent-strong: #765d24;
  --gold: #8e732f;
  --cycle-sidebar: #51451f;
  --cycle-sidebar-deep: #352d14;
  --cycle-sidebar-line: #9a884d;
  --cycle-sidebar-card: #685a28;
  --cycle-sidebar-card-active: #7e6d30;
  --cycle-sidebar-card-hover: #927d39;
  --cycle-sidebar-text: #fffdf0;
  --cycle-sidebar-muted: #e5d8a7;
  --cycle-sidebar-label: #f1e6bb;
  --cycle-sidebar-accent: #ffdc75;
  --cycle-sidebar-accent-line: #c4a84d;
  --cycle-sidebar-button: #817139;
  --cycle-sidebar-card-line: #8f7b36;
  --cycle-sidebar-hover-line: #ffedaa;
}

body[data-cycle="c5"] {
  --bg: #eef3f7;
  --panel: #fbfdff;
  --line: #d3e0e8;
  --accent: #06243d;
  --accent-strong: #041b2e;
  --gold: #95702b;
  --cycle-sidebar: #31536e;
  --cycle-sidebar-deep: #031827;
  --cycle-sidebar-line: #42617b;
  --cycle-sidebar-card: #123a59;
  --cycle-sidebar-card-active: #1d4c70;
  --cycle-sidebar-card-hover: #245d85;
  --cycle-sidebar-text: #f2f8fc;
  --cycle-sidebar-muted: #b9cedc;
  --cycle-sidebar-label: #d0e0eb;
  --cycle-sidebar-accent: #a9d9f3;
  --cycle-sidebar-accent-line: #6b9fbe;
  --cycle-sidebar-button: #315a78;
  --cycle-sidebar-card-line: #376582;
  --cycle-sidebar-hover-line: #c5e9ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
}

.sidebar {
  min-height: 100vh;
  padding: 22px;
  background: var(--cycle-sidebar);
  color: var(--cycle-sidebar-text);
  border-right: 1px solid var(--cycle-sidebar-deep);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 24px;
}

.mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: var(--cycle-sidebar-accent);
  font-weight: 800;
  letter-spacing: 0;
}

.mark .cycle-symbol {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.2;
}

.brand p {
  margin-top: 4px;
  color: var(--cycle-sidebar-muted);
  font-size: 13px;
}

.home-link {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-bottom: 18px;
  border: 1px solid var(--cycle-sidebar-line);
  border-radius: 6px;
  background: var(--cycle-sidebar-deep);
  color: var(--cycle-sidebar-text);
  font-weight: 800;
  text-decoration: none;
}

.home-link:hover {
  border-color: var(--cycle-sidebar-accent-line);
  color: var(--cycle-sidebar-accent);
}

.record-link {
  border-color: var(--cycle-sidebar-accent-line);
  color: var(--cycle-sidebar-accent);
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field span {
  color: var(--cycle-sidebar-label);
  font-size: 13px;
}

select,
input,
button {
  min-height: 42px;
  border-radius: 6px;
  font: inherit;
}

select,
input {
  width: 100%;
  border: 1px solid var(--cycle-sidebar-line);
  background: var(--cycle-sidebar-deep);
  color: var(--cycle-sidebar-text);
  padding: 0 12px;
}

button {
  border: 0;
  padding: 0 14px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  background: var(--accent-strong);
}

.quick-row {
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 10px;
  margin-bottom: 10px;
}

.memory-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.memory-tools button {
  width: 100%;
  min-width: 0;
  padding-inline: 8px;
}

.copy-paragraph-status {
  grid-column: 1 / -1;
  min-height: 0;
  color: var(--cycle-sidebar-muted);
  font-size: 12px;
  line-height: 1.4;
}

.copy-paragraph-status:empty {
  display: none;
}

#backButton {
  background: var(--cycle-sidebar-button);
}

body[data-cycle="c5"] .quick-row button,
body[data-cycle="c5"] .memory-tools button {
  border: 1px solid var(--cycle-sidebar-accent-line);
}

body[data-cycle="c5"] .quick-row button:hover,
body[data-cycle="c5"] .memory-tools button:hover {
  border-color: var(--cycle-sidebar-hover-line);
}

.result-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 520px);
  overflow: auto;
  padding-right: 3px;
}

.chapter-summary {
  min-height: 30px;
  margin-bottom: 12px;
  color: var(--cycle-sidebar-muted);
  font-size: 13px;
  line-height: 1.45;
}

.battle-shortcuts {
  display: grid;
  gap: 8px;
  margin: -2px 0 14px;
}

.battle-shortcuts[hidden] {
  display: none;
}

.battle-shortcuts-title {
  color: var(--cycle-sidebar-accent);
  font-size: 13px;
  font-weight: 800;
}

.battle-shortcut {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--cycle-sidebar-card-line);
  background: var(--cycle-sidebar-card);
  color: var(--cycle-sidebar-text);
  text-align: left;
  font-size: 12px;
  line-height: 1.25;
}

.battle-shortcut:hover,
.battle-shortcut.active {
  border-color: var(--cycle-sidebar-hover-line);
  background: var(--cycle-sidebar-card-hover);
  color: var(--cycle-sidebar-accent);
}

.memory-panel {
  margin-bottom: 14px;
}

.memory-title {
  margin-bottom: 8px;
  color: var(--cycle-sidebar-label);
  font-size: 13px;
  font-weight: 700;
}

.memory-list {
  display: grid;
  gap: 8px;
  max-height: 180px;
  overflow: auto;
  padding-right: 3px;
}

.memory-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
}

.memory-jump,
.memory-remove {
  min-height: 0;
  border-radius: 6px;
}

.memory-jump {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--cycle-sidebar-card-line);
  background: var(--cycle-sidebar-card);
  text-align: left;
}

.memory-id {
  color: var(--cycle-sidebar-accent);
  font-weight: 800;
}

.memory-meta {
  color: var(--cycle-sidebar-muted);
  font-size: 12px;
  line-height: 1.35;
}

.memory-remove {
  padding: 0 10px;
  background: var(--cycle-sidebar-button);
}

.result-item {
  width: 100%;
  min-height: 0;
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--cycle-sidebar-card-line);
  background: var(--cycle-sidebar-card);
  color: var(--cycle-sidebar-text);
  text-align: left;
  border-radius: 6px;
}

.result-item.active {
  border-color: var(--cycle-sidebar-hover-line);
  background: var(--cycle-sidebar-card-active);
}

.result-id {
  color: var(--cycle-sidebar-accent);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.result-section,
.result-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--cycle-sidebar-muted);
  font-size: 12px;
}

.reader {
  min-width: 0;
  padding: 34px clamp(20px, 5vw, 64px);
}

.reader-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.section-label {
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 800;
}

.pharos-title-decode {
  margin-top: 12px;
  padding: 6px 12px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--panel);
  color: var(--accent-strong);
  font-weight: 700;
  cursor: pointer;
}

.pharos-title-decode:hover {
  background: var(--accent);
  color: #fff;
}

h2 {
  margin-top: 6px;
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1.12;
}

#entryTitle { overflow-wrap: anywhere; }

.entry-badge {
  flex: 0 0 auto;
  min-width: 86px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--accent);
  text-align: center;
  font-weight: 900;
  font-size: 22px;
  box-shadow: var(--shadow);
}

.story-text {
  margin-top: 24px;
  max-width: 1400px;
  width: 100%;
  padding: 4px 0 34px;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  font-size: 18px;
  line-height: 1.85;
  white-space: pre-wrap;
}

.story-version-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--cycle-sidebar-label);
  font-size: 13px;
}

.story-version-toggle select {
  min-height: 34px;
  width: auto;
  padding: 0 8px;
}

.second-screen-mode-toggle {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.second-screen-mode-toggle[hidden] {
  display: none;
}

.second-screen-mode-toggle input {
  width: 16px;
  min-height: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

.second-screen-mode-toggle.disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

/* 第二屏故事文本没写进存档时，别让它悄悄停在旧内容上。 */
.second-screen-mode-toggle.sync-error {
  border-color: #b4552f;
  color: #b4552f;
}

.ai-translation {
  padding: 20px;
  border: 1px solid rgba(42, 84, 123, 0.28);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background: rgba(42, 84, 123, 0.06);
  white-space: normal;
}

.ai-translation-label {
  display: inline-flex;
  margin-bottom: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.ai-translation-notice {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.ai-translation-body {
  white-space: pre-wrap;
}

.source-original {
  margin-top: 24px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.38);
  white-space: normal;
}

.source-original summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-weight: 800;
}

.source-page-note {
  margin: 16px 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.source-original-text {
  max-height: 520px;
  overflow: auto;
  padding: 16px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.52);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.supplement-gallery {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr));
}

.supplement-gallery-hint {
  margin: 2px 0 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.supplement-gallery .battle-page {
  width: 100%;
  margin: 0;
}

.supplement-gallery .zoomable-page {
  cursor: zoom-in;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.supplement-gallery .zoomable-page:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(33, 25, 13, 0.2);
  transform: translateY(-2px);
}

.supplement-gallery .zoomable-page:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.page-viewer[hidden] {
  display: none;
}

.page-viewer {
  position: fixed;
  inset: 0;
  z-index: 3000;
  padding: 16px;
  display: grid;
  place-items: center;
  background: rgba(9, 8, 6, 0.9);
  backdrop-filter: blur(3px);
}

.page-viewer-dialog {
  width: min(1400px, 100%);
  height: min(94vh, 1100px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  color: #f8edd5;
  background: #181510;
  border: 1px solid rgba(226, 184, 104, 0.5);
  border-radius: 10px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.page-viewer-toolbar {
  min-height: 52px;
  padding: 8px 10px 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid rgba(226, 184, 104, 0.28);
}

.page-viewer-title {
  font-size: 14px;
  white-space: nowrap;
}

.page-viewer-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-viewer-controls button {
  min-width: 38px;
  height: 36px;
  padding: 0 10px;
  color: #f8edd5;
  background: #2a241a;
  border: 1px solid rgba(226, 184, 104, 0.38);
  border-radius: 5px;
  font: inherit;
  cursor: pointer;
}

.page-viewer-controls button:hover,
.page-viewer-controls button:focus-visible {
  color: #1b160e;
  background: #e2b868;
  outline: none;
}

.page-viewer-controls [data-page-viewer-action="reset"] {
  min-width: 64px;
}

.page-viewer-controls .page-viewer-close {
  margin-left: 6px;
  font-size: 24px;
}

.page-viewer-stage {
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: default;
  background-color: #0d0c0a;
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.025) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.025) 75%);
  background-size: 32px 32px;
  background-position: 0 0, 0 16px, 16px -16px, -16px 0;
}

.page-viewer-stage.is-dragging {
  cursor: grabbing;
}

.page-viewer-image {
  max-width: calc(100% - 24px);
  max-height: calc(100% - 24px);
  object-fit: contain;
  transform-origin: center;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}

.page-viewer-image.is-pannable {
  cursor: grab;
}

.page-viewer-stage.is-dragging .page-viewer-image {
  cursor: grabbing;
}

.page-viewer-help {
  padding: 7px 12px;
  color: rgba(248, 237, 213, 0.68);
  border-top: 1px solid rgba(226, 184, 104, 0.2);
  font-size: 12px;
  text-align: center;
}

@media (max-width: 640px) {
  .page-viewer {
    padding: 0;
  }

  .page-viewer-dialog {
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .page-viewer-title {
    display: none;
  }

  .page-viewer-toolbar {
    justify-content: center;
    padding-inline: 6px;
  }

  .page-viewer-controls {
    gap: 4px;
  }

  .page-viewer-controls button {
    min-width: 36px;
    padding-inline: 8px;
  }
}

.story-html {
  white-space: normal;
}

.story-html p {
  margin: 0 0 1em;
}

.story-html ul,
.story-html ol {
  margin: 0 0 1em 1.4em;
  padding: 0;
}

.battle-image {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto 1em auto;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.jump-link {
  border: 0;
  min-height: 0;
  padding: 0 3px;
  background: transparent;
  color: var(--danger);
  text-decoration: underline;
  font-weight: 800;
}

.jump-link:hover {
  background: #fff0d8;
  color: var(--danger);
}

.character-link {
  border: 0;
  min-height: 0;
  padding: 0;
  background: transparent;
  color: var(--accent);
  text-decoration: none;
  font-weight: 800;
}

.character-link:hover {
  background: transparent;
  color: var(--accent-strong);
}

.reader-foot {
  width: 100%;
  max-width: 1400px;
  margin-top: 18px;
}

.link-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.battle-page {
  width: 100%;
  max-width: 800px;
  margin: 0 auto 8px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.battle-gallery {
  margin-top: 28px;
  margin-bottom: 30px;
  white-space: normal;
}

.battle-table-wrap {
  margin: 10px 0 16px;
  overflow-x: auto;
}

.battle-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.6);
  font-size: 16px;
}

.battle-table th,
.battle-table td {
  padding: 10px 12px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.battle-table th {
  background: rgba(42, 84, 123, 0.12);
  color: var(--accent-strong);
  font-weight: 800;
}

.battle-table tbody tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.35);
}

/* 正文里的管道表格（原书排版遗留，见 assets/story-tables.js）。
   结构必须是字符保真的 span：竖线与分隔行只是隐藏，不能删除，否则混排按字符偏移插图会失败。 */
.story-table {
  display: table;
  width: 100%;
  margin: 12px 0 16px;
  border-collapse: collapse;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.6);
  font-size: 16px;
  white-space: normal;
}


.story-table-row {
  display: table-row;
}

.story-table-cell {
  display: table-cell;
  padding: 10px 12px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.story-table-head {
  background: rgba(42, 84, 123, 0.12);
  color: var(--accent-strong);
  font-weight: 800;
}

.story-table-row:not(.story-table-sep-row):nth-child(even) .story-table-cell {
  background: rgba(255, 255, 255, 0.35);
}

.story-table-bar,
.story-table-sep,
.story-table-sep-row {
  display: none;
}

.battle-subheading {
  margin: 32px 0 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--line);
  color: var(--accent-strong);
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 900;
  line-height: 1.25;
  white-space: normal;
}

.battle-block {
  margin: 0 0 18px;
  white-space: pre-wrap;
}

.battle-aibp-action {
  display: flex;
  white-space: normal;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
}

/* 「拆信封」段落里的隐藏 BOSS 按钮：正文下的独立一条，点了只弹提示。 */
.envelope-aibp-action {
  margin-top: 22px;
  margin-bottom: 18px;
  padding-top: 16px;
  border-top: 1px dashed var(--line);
}

.battle-aibp-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
}

.battle-aibp-button:hover {
  background: var(--accent-strong);
}

/* 不跳转、只弹提示的按钮（button 元素）。 */
button.battle-aibp-button {
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

.aibp-hint-layer {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(20, 16, 11, 0.55);
}

.aibp-hint-layer[hidden] {
  display: none;
}

.aibp-hint-box {
  width: min(440px, calc(100vw - 40px));
  padding: 22px 20px 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
}

.aibp-hint-box p {
  margin: 0 0 16px;
  color: var(--ink);
  font-weight: 700;
  line-height: 1.7;
}

.aibp-hint-close {
  min-height: 40px;
  padding: 0 18px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

.aibp-hint-close:hover {
  background: var(--accent-strong);
}

.reader-actions {
  display: flex;
  align-items: center;
  flex: 0 1 auto;
  min-width: 0;
  flex-wrap: nowrap;
  gap: 8px;
}

.entity-bio-toggle {
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.85em;
  white-space: nowrap;
}

.entity-bio-toggle:hover {
  border-color: var(--accent);
  background: #eef6f3;
  color: var(--accent-strong);
}

.entity-bio-toggle.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.tts-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 6px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9em;
  white-space: nowrap;
}
.tts-btn:hover {
  background: var(--accent-strong);
}

.tts-select {
  width: auto;
  min-width: 58px;
  max-width: 156px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font-size: 0.85em;
  cursor: pointer;
}

#ttsVoice {
  min-width: 112px;
}

#ttsEngine {
  min-width: 90px;
}

.tts-config-btn {
  min-height: 28px;
  padding: 0 10px;
  background: var(--cycle-sidebar-button);
  font-size: 12px;
  white-space: nowrap;
}

.tts-status {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  width: min(360px, calc(100vw - 36px));
  overflow: hidden;
  border: 1px solid rgba(36, 33, 29, 0.18);
  border-radius: 8px;
  background: var(--cycle-sidebar);
  color: var(--cycle-sidebar-text);
  box-shadow: 0 18px 50px rgba(24, 20, 14, 0.24);
}

.tts-status-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.tts-status-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.tts-status-head strong {
  min-width: 0;
  overflow: hidden;
  color: var(--cycle-sidebar-accent);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tts-status-actions button {
  min-height: 28px;
  padding: 0 10px;
  background: var(--cycle-sidebar-button);
  font-size: 12px;
}

.tts-status-body {
  max-height: 220px;
  overflow: auto;
  padding: 6px 12px 10px;
}

.tts-quick-config {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.tts-quick-field {
  display: grid;
  min-width: 0;
  gap: 4px;
  color: var(--cycle-sidebar-muted);
  font-size: 11px;
  font-weight: 700;
}

.tts-quick-field .tts-select {
  width: 100%;
  min-width: 0;
  max-width: none;
  min-height: 30px;
  border-color: var(--cycle-sidebar-line);
  background: var(--cycle-sidebar-deep);
  color: var(--cycle-sidebar-text);
}

/* 收起后整块只剩一个按钮：标题和「引擎配置」都藏起来 */
.tts-status.collapsed {
  width: auto;
  border: 0;
  border-radius: 999px;
  background: transparent;
  box-shadow: none;
}

.tts-status.collapsed .tts-status-head {
  justify-content: flex-end;
  padding: 0;
  border-bottom: 0;
}

.tts-status.collapsed .tts-status-head strong,
.tts-status.collapsed .tts-config-btn,
.tts-status.collapsed .tts-quick-config {
  display: none;
}

.tts-status.collapsed .tts-status-actions {
  gap: 0;
}

.tts-status.collapsed .tts-status-actions button {
  min-height: 34px;
  padding: 0 16px;
  border-radius: 999px;
  background: var(--cycle-sidebar);
  box-shadow: 0 10px 28px rgba(24, 20, 14, 0.3);
}

.tts-status.collapsed .tts-status-actions button:hover {
  background: #3a3227;
}

.tts-status-row {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
}

.tts-status-row span {
  color: var(--cycle-sidebar-muted);
}

.tts-status-row p {
  color: var(--cycle-sidebar-text);
  line-height: 1.45;
  word-break: break-word;
}

.tts-status-row.success span {
  color: #6cc08b;
}

.tts-status-row.warn span,
.tts-status-row.pending span {
  color: var(--cycle-sidebar-hover-line);
}

.tts-status-row.error span {
  color: #e77c6f;
}

.tts-status-empty {
  padding: 8px 0;
  color: var(--cycle-sidebar-muted);
  font-size: 12px;
  line-height: 1.5;
}

.tts-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 12, 8, 0.58);
}

.tts-overlay[hidden] {
  display: none;
}

.character-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 12, 8, 0.52);
}

.character-overlay[hidden] {
  display: none;
}

.character-card {
  width: min(780px, 96vw);
  max-height: 88vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

.character-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  background: var(--cycle-sidebar);
  color: var(--cycle-sidebar-text);
}

.character-head h3 {
  margin: 4px 0 0;
  font-size: 22px;
  line-height: 1.2;
}

.character-kicker {
  color: var(--cycle-sidebar-accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.character-head button {
  min-height: 32px;
  background: var(--cycle-sidebar-button);
}

.character-body {
  display: grid;
  gap: 14px;
  padding: 18px;
  line-height: 1.7;
}

.character-bio-tabs {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.character-bio-tabs button {
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--accent);
  font-size: 13px;
}

.character-bio-tabs button.active {
  border-color: var(--accent);
  background: #e6f3ef;
  color: var(--accent-strong);
}

.character-bio {
  padding: 12px 14px;
  border-left: 3px solid var(--accent);
  background: #f8fbf8;
  white-space: pre-line;
}

.character-wiki {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid #e4d8c7;
  border-radius: 8px;
  background: #fffaf0;
}

.character-wiki h4 {
  margin: 0;
  color: var(--gold);
  font-size: 14px;
}

.character-wiki p {
  color: #3a342c;
  line-height: 1.65;
}

.character-wiki-source {
  color: var(--muted);
  font-size: 12px;
}

.character-wiki-source a {
  color: var(--accent);
  font-weight: 800;
}

.character-meta,
.character-aliases {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.character-meta span,
.character-aliases span {
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.character-aliases strong {
  display: inline-flex;
  align-items: center;
  color: var(--accent);
  font-size: 13px;
}

.character-notes {
  margin: 0 0 0 1.2em;
  padding: 0;
  color: var(--muted);
}

.character-story-preview {
  display: grid;
  gap: 10px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.character-story-preview h4 {
  margin: 0;
  color: var(--accent-strong);
  font-size: 15px;
}

.character-story-groups {
  display: grid;
  gap: 12px;
  max-height: 46vh;
  overflow: auto;
  padding-right: 4px;
}

.character-story-group {
  display: grid;
  gap: 8px;
}

.character-story-group h5 {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f2eadf;
  color: var(--accent-strong);
  font-size: 13px;
}

.character-story-preview ol {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 1.35em;
}

.character-story-preview li {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.character-story-preview li span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.character-story-preview li p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.tts-modal {
  display: flex;
  flex-direction: column;
  width: min(880px, 96vw);
  max-height: 88vh;
  /* 移动端地址栏收起时 vh 偏大，支持的浏览器用 dvh 更准 */
  max-height: 88dvh;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

.tts-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex: none;
  padding: 20px 24px;
  background: linear-gradient(135deg, #2b2620, #1c1813);
  color: var(--cycle-sidebar-text);
}

.tts-modal-head h3 {
  margin: 0;
  font-size: 17px;
}

.tts-modal-head p {
  margin: 6px 0 0;
  max-width: 58ch;
  color: #b9ac95;
  font-size: 12px;
  line-height: 1.5;
}

.tts-btn-close {
  flex: none;
  width: 32px;
  min-height: 32px;
  padding: 0;
  border: 1px solid #4d4437;
  border-radius: 8px;
  background: transparent;
  color: var(--cycle-sidebar-muted);
  font-size: 14px;
  line-height: 1;
}

.tts-btn-close:hover {
  background: #3a3227;
  color: #ffffff;
}

.tts-modal-body {
  display: grid;
  /* 卡片带 overflow:hidden，作为网格项的自动最小尺寸是 0，会被压缩到撑不出滚动条。
     显式按内容定高，让内容溢出到滚动区。 */
  grid-auto-rows: max-content;
  align-content: start;
  gap: 16px;
  /* flex 子项默认 min-height:auto，不写 0 就撑破弹窗、滚动条不出现 */
  flex: 1 1 auto;
  min-height: 0;
  padding: 18px 24px;
  overflow: auto;
  overscroll-behavior: contain;
}

.tts-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffefb;
}

.tts-card-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #faf6ee;
}

.tts-card-head h4 {
  margin: 0;
  color: var(--accent-strong);
  font-size: 14px;
}

.tts-card-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.tts-card-body {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.tts-group {
  display: grid;
  gap: 12px;
}

.tts-group[hidden] {
  display: none;
}

.tts-group-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.tts-group-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.tts-field-grid {
  display: grid;
  gap: 12px;
}

.tts-field-grid.cols-1 {
  grid-template-columns: 1fr;
}

.tts-field-grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tts-field-grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tts-modal-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.tts-modal-field.span-2 {
  grid-column: span 2;
}

.tts-modal-field input,
.tts-modal-field select,
.tts-modal-field textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 11px;
  font: inherit;
  font-weight: 400;
}

.tts-modal-field textarea {
  min-height: 64px;
  resize: vertical;
  line-height: 1.5;
}

.tts-modal-field input:focus,
.tts-modal-field select:focus,
.tts-modal-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 107, 95, 0.14);
}

.tts-note {
  margin: 0;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: #f2f8f6;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.55;
}

.tts-card-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: #faf6ee;
}

.tts-spacer {
  flex: 1;
}

.tts-card-actions button,
.tts-modal-foot button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.tts-card-actions button:hover,
.tts-modal-foot button:hover {
  border-color: var(--accent);
  background: #f2f8f6;
}

/* 这些按钮会随服务商切换隐藏 */
.tts-card-actions button[hidden] {
  display: none;
}

.tts-btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.tts-card-actions .tts-btn-primary:hover,
.tts-modal-foot button#ttsSaveConfig:hover {
  background: var(--accent-strong);
  color: #ffffff;
}

.tts-modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: none;
  padding: 14px 24px;
  border-top: 1px solid var(--line);
  background: #faf6ee;
}

.tts-modal-foot > div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#ttsSaveConfig {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

@media (max-width: 720px) {
  .tts-modal-body,
  .tts-modal-head,
  .tts-modal-foot {
    padding-inline: 16px;
  }

  .tts-field-grid.cols-2,
  .tts-field-grid.cols-3 {
    grid-template-columns: 1fr;
  }

  .tts-modal-field.span-2 {
    grid-column: auto;
  }
}

.link-chip {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--accent);
}

.empty {
  color: var(--cycle-sidebar-muted);
  padding: 14px 2px;
  font-size: 14px;
}

@media (max-width: 1200px) {
  body {
    grid-template-columns: minmax(210px, 260px) minmax(0, 1fr);
  }
}

@media (max-width: 1500px) and (min-width: 821px) {
  .reader-head {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .reader-actions {
    justify-content: flex-start;
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }
}

@media (max-width: 820px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
  }

  .result-list {
    max-height: 260px;
  }

  .reader {
    padding: 24px 16px;
  }

  .reader-head {
    align-items: stretch;
    flex-direction: column;
  }

  .reader-actions {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .entry-badge {
    width: max-content;
  }
}
