/* novel_editor.css — 墨 / 宣纸 主题
   设计取向：写作工具本身要安静、不打断长时间码字；
   AI 相关的动作（改写/扩展/纠错/采纳）统一用「印章朱红」标记，
   呼应中文手稿上编辑用朱笔批注、盖印确认的传统。
*/

:root {
  --bg-app: #1e1c19;
  --bg-sidebar: #161513;
  --bg-panel: #211f1c;
  --bg-editor: #faf6ec;
  --ink: #2b2a27;
  --ink-soft: #4a463d;
  --border: #38352e;
  --border-soft: #2a2824;
  --text-inverse: #efe9dc;
  --text-muted: #8f8877;
  --seal: #b33b2e;
  --seal-soft: rgba(179, 59, 46, 0.14);
  --seal-hover: #c94a3c;
  --diff-add: #2e5f3e;
  --diff-add-bg: rgba(94, 179, 120, 0.18);
  --diff-del-bg: rgba(179, 59, 46, 0.14);
  --radius: 3px;
  --font-ui: "Noto Sans SC", -apple-system, "Segoe UI", sans-serif;
  --font-serif: "Noto Serif SC", "Songti SC", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-app);
  color: var(--text-inverse);
  font-family: var(--font-ui);
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: var(--side-w, 240px) 1fr;
  grid-template-rows: 48px 1fr;
  height: 100vh;
}

/* ---------- 顶栏 ---------- */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}

.topbar .brand {
  font-family: var(--font-serif);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-inverse);
  font-size: 15px;
  margin-right: 4px;
}

.topbar select {
  background: var(--bg-panel);
  color: var(--text-inverse);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 8px;
  font-size: 13px;
}

.topbar .spacer { flex: 1; }

.save-status {
  color: var(--text-muted);
  font-size: 12px;
  min-width: 90px;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-inverse);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--seal); color: var(--seal-hover); }

/* ---------- 侧边栏：章节树 ---------- */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar-header button {
  background: none;
  border: none;
  color: var(--seal);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}

#chapterList {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 4px 0;
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text-inverse);
  cursor: pointer;
  border-left: 2px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chapter-item:hover { background: rgba(255,255,255,0.03); }
.chapter-item.active {
  background: var(--seal-soft);
  border-left-color: var(--seal);
  color: #f2d9d4;
}
.chapter-item .idx { color: var(--text-muted); font-size: 11px; width: 22px; flex-shrink: 0; }
.chapter-item.dragging { opacity: 0.4; }

/* ---------- 主编辑区 ---------- */
.editor-area {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-editor);
}

.chapter-title-bar {
  padding: 10px 24px 0;
  background: var(--bg-editor);
}
.chapter-title-bar input {
  border: none;
  background: transparent;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  width: 100%;
  outline: none;
}

#editor {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: var(--bg-editor);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: var(--ed-fs, 16px);
  line-height: 2;
  padding: 16px 24px 60px;
  white-space: pre-wrap;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  font-family: var(--font-serif);
  font-size: 14px;
}

/* ---------- 查找替换工具条 ---------- */
.findbar {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  display: none;
  gap: 6px;
  align-items: center;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
}
.findbar.open { display: flex; }
.findbar input {
  background: var(--bg-app);
  border: 1px solid var(--border);
  color: var(--text-inverse);
  border-radius: var(--radius);
  padding: 4px 7px;
  font-size: 12px;
  width: 130px;
}
.findbar button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-inverse);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}
.findbar button:hover { border-color: var(--seal); }
.findbar .count { font-size: 11px; color: var(--text-muted); min-width: 40px; }

/* ---------- 右键菜单 ---------- */
.ctx-menu {
  position: fixed;
  z-index: 100;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 190px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  font-size: 13px;
  display: none;
}
.ctx-menu.open { display: block; }
.ctx-menu .ctx-item {
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-inverse);
  display: flex;
  justify-content: space-between;
}
.ctx-menu .ctx-item:hover { background: var(--seal-soft); color: #f2d9d4; }
.ctx-menu .ctx-sep { height: 1px; background: var(--border-soft); margin: 4px 2px; }
.ctx-menu .ctx-label { padding: 6px 10px 2px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }

/* ---------- 对比面板（侧边抽屉） ---------- */
.diff-panel {
  position: fixed;
  top: 48px;
  right: calc(-1 * var(--diff-w, 420px) - 30px);
  width: var(--diff-w, 420px);
  height: calc(100vh - 48px);
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  transition: right 0.25s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 24px rgba(0,0,0,0.4);
}
.diff-panel.open { right: 0; }

.diff-panel-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.diff-panel-header h3 {
  margin: 0;
  font-size: 14px;
  font-family: var(--font-serif);
  color: var(--text-inverse);
}
.diff-panel-header .op-tag {
  font-size: 11px;
  color: var(--seal);
  border: 1px solid var(--seal);
  border-radius: 10px;
  padding: 2px 8px;
}

.diff-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  font-family: var(--font-serif);
  font-size: 14px;
  line-height: 1.9;
}
.diff-body .diff-block-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 14px 0 6px;
}
.diff-body .diff-block-label:first-child { margin-top: 0; }
.diff-content {
  color: var(--text-inverse);
  white-space: pre-wrap;
}
.diff-content ins { background: var(--diff-add-bg); color: #cdeed6; text-decoration: none; }
.diff-content del { background: var(--diff-del-bg); color: #e8b6ae; text-decoration: line-through; }

#diffEditBox {
  width: 100%;
  min-height: 140px;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-inverse);
  font-family: var(--font-serif);
  font-size: 14px;
  line-height: 1.8;
  padding: 10px;
  resize: vertical;
}

.diff-panel-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  gap: 10px;
  align-items: center;
}

.seal-btn {
  width: 56px;
  height: 56px;
  border-radius: 6px;
  border: 2px solid var(--seal);
  background: var(--seal);
  color: #fff2ef;
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.1em;
  cursor: pointer;
  transform: rotate(-2deg);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  box-shadow: 0 2px 0 rgba(0,0,0,0.3);
}
.seal-btn:hover { box-shadow: 0 3px 6px rgba(179,59,46,0.4); }
.seal-btn:active { transform: rotate(-2deg) scale(0.92); box-shadow: none; }

.ghost-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-inverse);
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
}
.ghost-btn:hover { border-color: var(--text-muted); }

.diff-loading {
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px 0;
  text-align: center;
}

/* ---------- 模态框（设置 / Prompt模板管理） ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 520px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px 22px;
}
.modal h2 {
  font-family: var(--font-serif);
  font-size: 17px;
  margin: 0 0 16px;
  color: var(--text-inverse);
}
.modal label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin: 12px 0 4px;
}
.modal input[type="text"], .modal input[type="url"], .modal select, .modal textarea {
  width: 100%;
  background: var(--bg-app);
  border: 1px solid var(--border);
  color: var(--text-inverse);
  border-radius: var(--radius);
  padding: 7px 9px;
  font-size: 13px;
}
.modal textarea { min-height: 90px; font-family: var(--font-ui); line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.radio-row { display: flex; gap: 16px; margin-top: 4px; }
.radio-row label { display: flex; align-items: center; gap: 6px; color: var(--text-inverse); font-size: 13px; }

.tpl-list { border-top: 1px solid var(--border-soft); margin-top: 16px; padding-top: 8px; }
.tpl-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}
.tpl-row .tpl-type { color: var(--text-muted); font-size: 11px; margin-left: 6px; }
.tpl-row .tpl-actions button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 12px; margin-left: 8px; }
.tpl-row .tpl-actions button:hover { color: var(--seal); }

.close-x {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}
.modal { position: relative; }

@media (max-width: 720px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .diff-panel { width: 100%; right: -100%; }
}

/* 2026-10-24: reader library, save status, settings hints */
#docList { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; max-height: 40vh; }
.doc-item .doc-size { margin-left: auto; color: var(--text-muted); font-size: 11px; padding-left: 6px; flex-shrink: 0; }
.doc-item .ch-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mode-tag { font-size: 12px; color: var(--text-inverse); background: var(--seal-soft); border: 1px solid var(--seal); border-radius: 3px; padding: 2px 8px; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-status { cursor: default; }
.save-status.error { color: #ff9b8e; cursor: pointer; text-decoration: underline; }
.save-status.ok { color: var(--text-muted); }
.modal .hint { font-size: 12px; color: var(--text-muted); margin-top: 8px; line-height: 1.6; }
.ghost-btn.small { padding: 2px 8px; font-size: 11px; margin-left: 8px; }
.modal label.think-row { display:flex; align-items:center; gap:8px; margin-top:12px; cursor:pointer; }
.modal label.think-row input { width:auto; }

/* 2026-10-24: resize handles, format check, streaming */
.sidebar { position: relative; }
.resize-handle { position: absolute; top: 0; bottom: 0; width: 8px; cursor: col-resize; z-index: 60; touch-action: none; }
.resize-handle:hover, .resize-handle.active { background: var(--seal-soft); }
.side-handle { right: -4px; }
.diff-handle { left: -4px; }
body.resizing { user-select: none; cursor: col-resize; }
.fmt-panel { position: fixed; top: 56px; right: 16px; width: min(380px, 92vw); max-height: 70vh; overflow: auto; background: var(--bg-panel); color: var(--text-inverse); border: 1px solid var(--border); border-radius: 4px; padding: 12px 14px; z-index: 70; display: none; box-shadow: 0 8px 24px rgba(0,0,0,.4); font-size: 13px; }
.fmt-panel.open { display: block; }
.fmt-panel .close-x { top: 8px; right: 10px; }
.fmt-panel .hint { font-size: 12px; color: var(--text-muted); }
.fmt-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border-soft); }
.fmt-item .cnt { margin-left: auto; color: var(--seal); font-weight: 700; }
.fmt-item button { background: none; border: 1px solid var(--border); color: var(--text-inverse); border-radius: 3px; font-size: 11px; cursor: pointer; padding: 2px 6px; }
.fmt-ok { color: #9fd3a8; padding: 8px 0; }
.fmt-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.stream-box { white-space: pre-wrap; font-family: var(--font-serif); line-height: 1.9; color: var(--text-inverse); }
.stream-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
@media (max-width: 720px) { .resize-handle { display: none; } .diff-panel { width: 100% !important; right: -110% !important; } .diff-panel.open { right: 0 !important; } }

.chapter-title-bar input:not(:disabled) { cursor: text; border-bottom: 1px dashed transparent; }
.chapter-title-bar input:not(:disabled):hover { border-bottom-color: #bbb; }
.chapter-title-bar input:focus { border-bottom: 1px solid #c97; outline: none; }

.chapter-item { position: relative; }
.chapter-item .ch-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-item .ch-del { visibility: hidden; border: none; background: transparent; cursor: pointer; padding: 0 2px; font-size: 12px; opacity: .7; flex-shrink: 0; }
.chapter-item:hover .ch-del, .chapter-item.active .ch-del { visibility: visible; }
.chapter-item .ch-del:hover { opacity: 1; filter: drop-shadow(0 0 2px #e66); }
@media (hover: none) { .chapter-item .ch-del { visibility: visible; } }

/* ================= 2026-10-26: mobile layout (<=900px) ================= */
.m-only { display: none; }
.drawer-backdrop { display: none; }
.chapter-item .ch-move { display: none; }
@media (max-width: 900px) {
  .m-only { display: inline-flex; align-items: center; justify-content: center; }
  html, body { overscroll-behavior: none; }
  #app { grid-template-columns: 1fr !important; grid-template-rows: auto 1fr; height: var(--vvh, 100dvh); }
  .topbar { flex-wrap: wrap; gap: 6px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); row-gap: 6px; }
  .topbar .brand { display: none; }
  .topbar select { flex: 1; min-width: 0; height: 44px; font-size: 15px; }
  .topbar .spacer { display: none; }
  .topbar .icon-btn { min-height: 44px; min-width: 44px; font-size: 15px; padding: 0 10px; }
  .topbar .m-more, .topbar .mode-tag { display: none !important; }
  .topbar.more-open .m-more { display: inline-flex !important; flex: 1 1 40%; }
  .topbar.more-open .mode-tag[style*="inline-block"] { display: block !important; flex-basis: 100%; max-width: none; }
  .save-status { order: 10; flex-basis: 100%; min-width: 0; font-size: 12px; line-height: 1.2; }
  .save-status:empty { display: none; }
  #saveBtn { font-size: 15px; }
  .resize-handle { display: none !important; }

  /* drawer */
  .sidebar { display: flex !important; position: fixed; top: 0; bottom: 0; left: 0; width: min(86vw, 360px); z-index: 90;
    transform: translateX(-105%); transition: transform .22s ease; padding-top: env(safe-area-inset-top); box-shadow: 8px 0 24px rgba(0,0,0,.5); }
  body.drawer-open .sidebar { transform: none; }
  body.drawer-open .drawer-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 85; }
  .sidebar-header { min-height: 48px; font-size: 14px; }
  .sidebar-header button { min-width: 44px; min-height: 44px; font-size: 20px; }
  #chapterList { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  #docList { max-height: 35vh; }
  .chapter-item, .doc-item { min-height: 46px; font-size: 15px; display: flex; align-items: center; }
  .chapter-item .ch-del, .chapter-item .ch-move { visibility: visible; min-width: 40px; min-height: 44px; font-size: 16px; opacity: .85; }
  .chapter-item .ch-move { display: inline-flex; align-items: center; justify-content: center; border: none; background: transparent; color: var(--text-muted); cursor: pointer; }

  /* editor */
  .chapter-title-bar { padding: 2px 12px 0; }
  .chapter-title-bar input { font-size: 16px; min-height: 36px; }
  #editor { font-size: var(--ed-fs, 15px); line-height: 1.8; padding: 6px 12px 90px; }
  .findbar { flex-wrap: wrap; }
  .findbar input, .findbar button { min-height: 40px; }

  /* AI floating button */
  .ai-fab { position: fixed; right: 14px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 60; min-height: 48px; padding: 0 18px;
    border-radius: 24px; border: none; background: var(--seal); color: #fff; font-size: 15px; box-shadow: 0 4px 14px rgba(0,0,0,.35); }
  .ai-fab.has-sel { background: #2e5f3e; }
  body.drawer-open .ai-fab, body.sheet-open .ai-fab { display: none; }

  /* AI templates as bottom sheet */
  .ctx-menu { left: 0 !important; right: 0 !important; top: auto !important; bottom: 0; min-width: 0; max-height: 65vh; overflow-y: auto;
    border-radius: 12px 12px 0 0; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); font-size: 16px; z-index: 120; }
  .ctx-item { min-height: 46px; display: flex; align-items: center; }

  /* AI result panel as bottom sheet */
  .diff-panel { top: auto !important; bottom: 0; right: 0 !important; left: 0; width: 100% !important; height: 78% !important; max-height: calc(var(--vvh, 100dvh) - 40px);
    border-left: none; border-top: 1px solid var(--border); border-radius: 12px 12px 0 0; transform: translateY(105%); transition: transform .22s ease; }
  .diff-panel.open { transform: none; }
  .diff-panel-header { gap: 8px; }
  .diff-panel-header .ghost-btn { min-height: 40px; margin-left: auto; }
  .diff-panel-footer { flex-wrap: wrap; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .diff-panel-footer button { min-height: 46px; flex: 1 1 28%; font-size: 15px; }

  /* format panel / modals */
  .fmt-panel { top: auto; bottom: 0; left: 0; right: 0; width: 100%; max-height: 70vh; border-radius: 12px 12px 0 0; z-index: 110; }
  .fmt-panel button { min-height: 44px; }
  .modal { width: 96vw !important; max-height: 90vh; padding: 16px; }
  .modal input, .modal select, .modal textarea { font-size: 16px; min-height: 40px; }
  .modal button { min-height: 44px; }
}
/* edit menu + AI submenu */
.ctx-menu .ctx-ai { color: #f2d9d4; font-weight: 600; }
.ctx-menu .ctx-back { color: var(--text-muted); font-size: 12px; }

/* font size control + dual layout */
.font-ctl { display: inline-flex; align-items: center; gap: 2px; }
.font-ctl #fontVal { min-width: 26px; text-align: center; font-size: 12px; color: var(--text-muted); }
.ed-split { flex: 1; display: flex; min-height: 0; }
.ed-split #editor { min-width: 0; }
.preview { display: none; }
body.layout-pages .preview {
  display: block; flex: 1; min-width: 0; border-left: 1px solid rgba(0,0,0,.12); background: #fbf8f1; color: var(--ink);
  font-family: var(--font-serif); font-size: var(--ed-fs, 16px); line-height: 1.95; padding: 18px 32px 60px; overflow-y: auto; cursor: text; }
.preview p { margin: 0 0 .25em; text-indent: 0; text-align: justify; }
.preview p.h { font-weight: 700; font-size: 1.15em; margin: .6em 0 .4em; text-align: center; }
.preview p.blank { height: .6em; }
.preview p:hover { background: rgba(180,60,40,.06); }
.preview .pv-title { font-weight: 700; font-size: 1.3em; text-align: center; margin-bottom: .8em; column-span: all; }
body.layout-pages .preview { overflow-x: auto; overflow-y: hidden; column-count: 2; column-gap: 56px; column-fill: auto;
  column-rule: 1px solid rgba(0,0,0,.10); height: 100%; padding: 22px 36px 28px; }
body.layout-dual #editor { flex: 1 1 50%; }
body.layout-pages #editor { flex-basis: 36%; }
@media (max-width: 900px) {
  .d-only { display: none !important; }
  .preview { display: none !important; }
  .ed-split #editor { flex: 1 !important; }
  .topbar.more-open .font-ctl { flex: 1 1 100%; justify-content: center; gap: 10px; }
  .font-ctl #fontVal { font-size: 14px; min-width: 40px; }
  .topbar .icon-btn { min-height: 40px; min-width: 40px; }
  .topbar { padding: 4px 6px; gap: 4px; }
  .topbar select { height: 40px; }
}

/* dual-chapter view */
.pane2 { display: none; }
body.layout-dual .pane2 { display: flex; flex-direction: column; flex: 1 1 50%; min-width: 0; border-left: 2px solid rgba(0,0,0,.14); background: var(--bg-editor); }
.pane2-bar { display: flex; align-items: center; gap: 6px; padding: 8px 12px 6px; background: var(--bg-app); border-bottom: 1px solid rgba(0,0,0,.2); }
.pane2-bar select { flex: 1; min-width: 0; }
.pane2-bar .p2-status { font-size: 11px; color: var(--text-muted); white-space: nowrap; min-width: 60px; text-align: right; }
.pane2-bar .p2-status.error { color: var(--seal); }
#editor2 { flex: 1; border: none; outline: none; resize: none; background: var(--bg-editor); color: var(--ink); font-family: var(--font-serif);
  font-size: var(--ed-fs, 16px); line-height: 2; padding: 16px 24px 60px; white-space: pre-wrap; min-height: 0; }
body.layout-dual #editor:focus, body.layout-dual #editor2:focus { box-shadow: inset 0 2px 0 var(--seal); }
@media (max-width: 900px) { .pane2 { display: none !important; } }

/* ---- desktop word count badge ---- */
.wc-badge {
  position: absolute; right: 18px; bottom: 14px; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 5px 12px; border-radius: 999px;
  background: rgba(250, 246, 236, 0.86);
  border: 1px solid rgba(43, 42, 39, 0.10);
  box-shadow: 0 2px 10px rgba(30, 28, 25, 0.08);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  font-family: var(--font-ui); font-size: 12px; color: var(--text-muted);
  user-select: none; pointer-events: auto; opacity: 0.72;
  transition: opacity .2s ease, box-shadow .2s ease;
}
.wc-badge:hover { opacity: 1; box-shadow: 0 3px 14px rgba(30, 28, 25, 0.14); }
.wc-item { display: inline-flex; align-items: baseline; gap: 5px; white-space: nowrap; }
.wc-item i { font-style: normal; letter-spacing: .05em; }
.wc-item b { font-weight: 600; color: var(--ink-soft); font-variant-numeric: tabular-nums; min-width: 1.2em; text-align: right; }
.wc-sep { width: 1px; height: 11px; background: rgba(43, 42, 39, 0.16); }
.wc-badge.has-sel { opacity: 1; }
.wc-badge.has-sel .wc-sel b { color: var(--seal); }
body.layout-dual .wc-badge { right: 22px; }
@media (max-width: 900px), (hover: none) and (pointer: coarse) { .wc-badge { display: none !important; } }
/* 自动写书 */
.ag-modal { max-width: 720px; width: 94vw; max-height: 90vh; overflow-y: auto; }
.ag-modal input[type=text], .ag-modal input[type=number], .ag-modal textarea { width: 100%; box-sizing: border-box; }
.ag-job { padding: 5px 8px; cursor: pointer; border-radius: 4px; font-size: 13px; }
.ag-job:hover, .ag-job.active { background: rgba(0,0,0,.06); }
.ag-status { margin: 10px 0; line-height: 1.7; }
.ag-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.ag-plan { font-size: 13px; max-height: 200px; overflow-y: auto; padding-left: 22px; }
.ag-plan li.ag-cur { color: #b03a2e; }
.ag-st.ag-running { color: #2e7d32; } .ag-st.ag-error { color: #c62828; } .ag-st.ag-paused { color: #ef6c00; }

/* delete reader doc */
.doc-item .doc-del { background: none; border: none; cursor: pointer; padding: 0 4px; margin-left: 4px; opacity: .45; font-size: 13px; flex-shrink: 0; }
.doc-item .doc-del:hover { opacity: 1; }
.danger-btn { background: #c0392b; color: #fff; border: none; border-radius: 4px; padding: 9px 18px; cursor: pointer; }
.danger-btn:hover { background: #a93226; }
.danger-btn:disabled { opacity: .6; cursor: default; }
/* ============================================================
   自动写书 v2（2026-11-04）—— 列表 / 向导 / 监控 三视图
   与旧 .ag-* 样式共存，不影响其它弹窗
   ============================================================ */
.modal.agx {
  width: 800px; max-width: 94vw; max-height: 88vh;
  padding: 0; overflow: hidden;
  display: flex; flex-direction: column;
}
.agx-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 52px 14px 18px;
  border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.agx-head h2.agx-title { font-family: var(--font-serif); font-size: 16px; margin: 0; color: var(--text-inverse); }
.agx-back {
  background: none; border: 1px solid var(--border); color: var(--text-inverse);
  border-radius: var(--radius); width: 26px; height: 26px; cursor: pointer;
  line-height: 1; padding: 0; flex: 0 0 auto;
}
.agx-back:hover { border-color: var(--text-muted); }
.agx-chip {
  margin-left: auto; font-size: 11px; padding: 2px 9px;
  border-radius: 999px; border: 1px solid var(--border); color: var(--text-muted);
  white-space: nowrap;
}
.agx-body { flex: 1 1 auto; overflow-y: auto; padding: 16px 18px 24px; }
.agx-toast {
  margin: 10px 18px 0; padding: 8px 12px; border-radius: var(--radius);
  font-size: 12.5px; line-height: 1.5; flex: 0 0 auto;
}
.agx-toast.err { background: rgba(179,59,46,.16); border: 1px solid rgba(179,59,46,.55); color: #f2bdb5; }
.agx-toast.ok { background: rgba(94,179,120,.14); border: 1px solid rgba(94,179,120,.45); color: #b9e0c6; }

.modal.agx textarea { min-height: 0; }
.modal.agx input[type=number] {
  width: 100%; background: var(--bg-app); border: 1px solid var(--border);
  color: var(--text-inverse); border-radius: var(--radius); padding: 7px 9px; font-size: 13px;
}
.modal.agx label { margin: 12px 0 4px; }
.modal.agx label.agx-check {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px;
  color: var(--text-inverse); margin: 14px 0; cursor: pointer;
}
.modal.agx label.agx-check input { width: auto; }

.agx-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.agx-muted { color: var(--text-muted); font-size: 12px; }
.agx-empty {
  color: var(--text-muted); font-size: 12.5px; padding: 26px 14px;
  text-align: center; border: 1px dashed var(--border); border-radius: var(--radius);
}
.agx-mini { padding: 3px 9px !important; font-size: 11.5px !important; }
.seal-btn.agx-primary {
  width: auto; height: auto; padding: 8px 16px;
  border-radius: var(--radius); transform: none; font-size: 13px;
}
.seal-btn.agx-primary:hover { transform: none; }
.ghost-btn.agx-go { border-color: var(--seal); color: #e8917f; }
.ghost-btn.agx-go:hover { background: var(--seal-soft); }

/* ---- 任务列表 ---- */
.agx-job {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 11px 13px; margin-bottom: 9px; cursor: pointer;
  background: rgba(255,255,255,.02);
}
.agx-job:hover { border-color: var(--text-muted); background: rgba(255,255,255,.05); }
.agx-job-top { display: flex; align-items: center; gap: 10px; }
.agx-job-top b { font-size: 13.5px; font-weight: 500; color: var(--text-inverse); }
.agx-job-top .agx-chip { margin-left: auto; }
.agx-job-msg { font-size: 12px; color: var(--text-muted); margin: 6px 0 8px; line-height: 1.5;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agx-meta { display: flex; gap: 14px; font-size: 11.5px; color: var(--text-muted); flex-wrap: wrap; }
.agx-meta.big { font-size: 12.5px; margin-bottom: 14px; color: var(--text-inverse); }
.agx-meta.big span { white-space: nowrap; }
.agx-prog { height: 5px; border-radius: 3px; background: var(--border); overflow: hidden; margin-bottom: 8px; }
.agx-prog.sm { height: 4px; margin: 0 0 7px; }
.agx-prog i { display: block; height: 100%; background: var(--seal); transition: width .3s; }

.agx-st-running, .agx-st-done { color: #85c79a !important; border-color: rgba(94,179,120,.55) !important; }
.agx-st-paused { color: #e0a860 !important; border-color: rgba(224,168,96,.55) !important; }
.agx-st-error { color: #e58e83 !important; border-color: rgba(179,59,46,.6) !important; }
.agx-st-queued, .agx-st-cancelled, .agx-st-none { color: var(--text-muted) !important; }

/* ---- 向导 ---- */
.agx-steps { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.agx-step {
  font-size: 11.5px; padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-muted);
}
.agx-step.done { color: #85c79a; border-color: rgba(94,179,120,.45); }
.agx-step.cur { color: #f0efe8; border-color: var(--seal); background: var(--seal-soft); }
.agx-grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.agx-hint { font-size: 11.5px; line-height: 1.6; margin-top: 5px; color: var(--text-muted); }
.agx-hint.ok { color: #85c79a; }
.agx-hint.warn { color: #e0a860; }
.agx-fold { margin: 14px 0 0; }
.agx-fold a { font-size: 12px; color: var(--text-muted); cursor: pointer; user-select: none; }
.agx-fold a:hover { color: var(--text-inverse); }
.agx-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border);
}
.agx-note {
  font-size: 11.5px; color: var(--text-muted); line-height: 1.6;
  margin: 2px 0 14px; padding-left: 9px; border-left: 2px solid var(--border);
}
.agx-pvlist { max-height: 46vh; overflow-y: auto; padding-right: 4px; }
.agx-pv {
  display: grid; grid-template-columns: 24px 1fr 88px 40px;
  gap: 7px; align-items: center;
  padding: 7px 0; border-bottom: 1px solid var(--border-soft);
}
.agx-pv-n { font-size: 11.5px; color: var(--text-muted); text-align: right; }
.modal.agx .agx-pv .pv-t, .modal.agx .agx-pv .pv-w { padding: 5px 8px; font-size: 12.5px; }
.modal.agx .agx-pv .pv-b { grid-column: 2 / 5; padding: 5px 8px; font-size: 12px; }
.agx-sum {
  font-size: 13px; color: var(--text-inverse); padding: 10px 13px;
  background: rgba(255,255,255,.04); border-radius: var(--radius); margin-bottom: 4px;
}
.agx-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.agx-pick-card {
  display: flex; flex-direction: column; gap: 5px; text-align: left;
  background: var(--bg-app); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 14px; cursor: pointer; color: var(--text-inverse);
}
.agx-pick-card:hover { border-color: var(--seal); background: var(--seal-soft); }
.agx-pick-card b { font-size: 13px; font-weight: 500; }
.agx-pick-card span { font-size: 11.5px; color: var(--text-muted); line-height: 1.5; }

/* ---- 监控 ---- */
.agx-stages { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 7px; margin-bottom: 12px; }
.agx-stage {
  font-size: 11.5px; padding: 6px 10px; border-radius: var(--radius);
  border: 1px solid var(--border); color: var(--text-muted); text-align: center;
}
.agx-stage.done { color: #85c79a; border-color: rgba(94,179,120,.45); background: rgba(94,179,120,.1); }
.agx-stage.cur { color: #f0efe8; border-color: var(--seal); background: var(--seal-soft); }
.agx-now {
  border-left: 2px solid var(--seal); padding: 3px 0 3px 11px; margin: 12px 0;
}
.agx-now-t { font-size: 12.5px; color: var(--text-inverse); line-height: 1.5; }
.agx-now-e { font-size: 11.5px; color: #e58e83; margin-top: 4px; line-height: 1.5; }
.agx-val { font-size: 11.5px; color: var(--text-inverse); margin: 8px 0; line-height: 1.6; }
.agx-actions { display: flex; flex-wrap: wrap; gap: 7px; margin: 12px 0 4px; }
.agx-actions .ghost-btn { padding: 5px 11px; font-size: 12px; }

.agx-chlist { margin-top: 10px; border-top: 1px solid var(--border); }
.agx-ch { border-bottom: 1px solid var(--border-soft); }
.agx-ch-row {
  display: grid; grid-template-columns: 14px minmax(0,1fr) 108px 76px auto;
  gap: 8px; align-items: center; padding: 8px 2px; font-size: 12.5px;
}
.agx-ch.cur .agx-ch-t { color: #e8917f; }
.agx-ch.skip .agx-ch-t { color: var(--text-muted); text-decoration: line-through; }
.agx-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.agx-dot.done { background: #5eb378; }
.agx-dot.cur { background: var(--seal); }
.agx-dot.part { background: #e0a860; }
.agx-dot.skip { background: #4a463d; }
.agx-ch-t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-inverse); }
.agx-ch-m { font-size: 11.5px; color: var(--text-muted); text-align: right; }
.agx-ch-s { font-size: 11.5px; color: var(--text-muted); }
.agx-ch-b { display: flex; gap: 5px; justify-content: flex-end; flex-wrap: wrap; }

.agx-scedit { padding: 4px 12px 14px 22px; background: rgba(0,0,0,.22); border-radius: var(--radius); margin-bottom: 8px; }
.agx-scedit .agx-l { margin: 9px 0 3px; }
.agx-sc { border-left: 2px solid var(--border); padding-left: 10px; margin: 10px 0; }
.agx-sc-h { font-size: 11.5px; color: var(--seal-hover); margin-bottom: 2px; }
.agx-l { display: block; font-size: 11.5px; color: var(--text-muted); margin: 8px 0 3px; }
.agx-l.hi { color: #e0a860; }
.modal.agx .agx-scedit input[type=text], .modal.agx .agx-scedit textarea {
  padding: 5px 8px; font-size: 12.5px;
}

.agx-drawer {
  position: absolute; inset: 0; background: var(--bg-panel);
  display: flex; flex-direction: column; border-radius: 6px;
}
.agx-drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 18px; border-bottom: 1px solid var(--border); font-size: 12.5px;
  color: var(--text-inverse);
}
.agx-drawer-body { flex: 1 1 auto; overflow-y: auto; padding: 18px 26px 40px; }
.agx-drawer-body p {
  font-family: var(--font-serif); font-size: 14px; line-height: 2;
  color: var(--text-inverse); margin: 0 0 14px; text-indent: 2em;
}
.agx-drawer-close { background: none; border: 1px solid var(--border); color: var(--text-inverse); }

@media (max-width: 620px) {
  .agx-grid2 { grid-template-columns: 1fr; }
  .agx-pick { grid-template-columns: 1fr; }
  .agx-ch-row { grid-template-columns: 14px 1fr 70px; }
  .agx-ch-m, .agx-ch-s { display: none; }
  .agx-ch-b { grid-column: 2 / 4; justify-content: flex-start; }
  .agx-stages { grid-template-columns: 1fr; }
}

/* 2026-11-04 修复：.agx-drawer 自带 display:flex，会盖掉 HTML hidden 属性的
   UA 默认 display:none，导致试读抽屉常驻并遮住整个弹窗（表现为“弹窗空白，
   只剩一个关闭按钮”）。下面这条通用规则让 agx 内部所有 hidden 都可靠。 */
.modal.agx [hidden] { display: none !important; }

/* 历史任务：删除按钮 + 已完成折叠 */
.agx-del {
  margin-left: 4px; flex: 0 0 auto;
  font-size: 11px; padding: 2px 8px; border-radius: var(--radius);
  border: 1px solid transparent; background: none; color: var(--text-muted); cursor: pointer;
}
.agx-del:hover { color: #e58e83; border-color: rgba(179,59,46,.6); background: var(--seal-soft); }
.agx-done-toggle {
  display: block; width: 100%; text-align: left; margin-top: 16px;
  background: none; border: none; border-top: 1px dashed var(--border);
  color: var(--text-muted); font-size: 12px; padding: 11px 2px 0; cursor: pointer;
}
.agx-done-toggle:hover { color: var(--text-inverse); }

/* 交互优化（2026-11-04）：统一“处理中”反馈、长表单底部栏常驻 */
.agx-loading { opacity: .6; pointer-events: none; }
.agx-spin {
  display: inline-block; width: 11px; height: 11px; margin-right: 6px;
  border: 1.5px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: agxspin .8s linear infinite; vertical-align: -1px;
}
@keyframes agxspin { to { transform: rotate(360deg); } }
.agx-busy {
  display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px;
  color: var(--text-inverse); line-height: 1.6;
  background: var(--seal-soft); border: 1px solid rgba(179,59,46,.45);
  border-radius: var(--radius); padding: 10px 13px; margin-bottom: 12px;
}
.agx-busy .agx-spin { margin-top: 4px; color: #e8917f; }
.agx-pvlist.busy { opacity: .4; pointer-events: none; }
.agx-pvlist { padding-right: 8px; }
.agx-pv { grid-template-columns: 24px 1fr 88px 46px; }
.agx-pv:hover { background: rgba(255,255,255,.03); }
.agx-body { padding-bottom: 10px; }
.agx-foot {
  position: sticky; bottom: 0; z-index: 2;
  background: var(--bg-panel); padding-bottom: 6px;
}

/* 无人值守：未过校验的章节提示 */
.agx-warn {
  font-size: 11.5px; line-height: 1.6; color: #e8c07a; margin: 6px 0 10px;
  padding: 8px 11px; border-left: 2px solid #b8863b; background: rgba(184,134,59,.12);
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* 校验未通过：定位与跳转 */
.agx-ch.bad { background: rgba(179,59,46,.07); }
.agx-ch.bad .agx-ch-t { color: #e8917f; }
.agx-ch.bad .agx-dot { background: var(--seal); }
.agx-fix {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--text-muted); margin: 8px 0 10px;
}

/* 第 1 步：全自动开关 */
.agx-check.agx-auto {
  align-items: flex-start; gap: 9px; margin: 16px 0 4px;
  padding: 11px 13px; border-radius: var(--radius);
  background: var(--seal-soft); border: 1px solid rgba(179,59,46,.4);
}
.agx-check.agx-auto input { margin-top: 2px; }
.agx-check.agx-auto span { font-size: 12px; line-height: 1.65; color: var(--text-inverse); }
.agx-check.agx-auto b { color: #f0b0a4; font-weight: 500; }
.agx-foot-btns { display: flex; gap: 8px; align-items: center; }
.agx-note.ok { border-left-color: #5eb378; color: #a9d6b6; }

/* 第 1 步：输入方式切换与场景卡导入 */
.agx-tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.agx-tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-muted); font-size: 12.5px; padding: 8px 12px; cursor: pointer;
}
.agx-tab:hover { color: var(--text-inverse); }
.agx-tab.on { color: #f0efe8; border-bottom-color: var(--seal); }
.agx-cardrow {
  display: flex; align-items: center; gap: 10px; padding: 6px 2px;
  border-bottom: 1px solid var(--border-soft); font-size: 12.5px;
}
.agx-cardrow-t { flex: 1; color: var(--text-inverse); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 同名书稿「新建 / 续写」下拉（2026-11-12） */
.modal.agx select {
  width: 100%; box-sizing: border-box; margin-bottom: 6px;
  background: var(--bg-app); border: 1px solid var(--border);
  color: var(--text-inverse); border-radius: var(--radius);
  padding: 7px 9px; font-size: 13px;
}

/* 本书人物卡 / 总纲（2026-11-12） */
.modal.bm-modal { width: min(760px, 94vw); max-height: 92vh; overflow-y: auto; }
.modal.bm-modal textarea { min-height: 180px; }
.modal.bm-modal #bmOutline { min-height: 220px; }
.modal .bm-label { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.modal .bm-label .ghost-btn.small { margin-left: auto; font-size: 12px; padding: 3px 8px; }
.bm-count { font-size: 12px; color: var(--text-muted); font-weight: normal; }
.bm-status { margin-right: auto; align-self: center; font-size: 12.5px; color: var(--text-muted); }
.bm-status.ok { color: #7cc48f; }
.bm-status.warn { color: #e0b766; }
.bm-status.error { color: #e8857a; }
.modal.bm-modal [hidden] { display: none !important; }
