:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e4e9f0;
  --border-strong: #d4dce7;
  --text: #1c2738;
  --text-2: #4b5b70;
  --muted: #8996a8;
  --accent: #2f61d5;
  --accent-soft: #eaf0ff;
  --accent-text: #ffffff;
  --danger: #b8443c;
  --danger-soft: #fdf0ef;
  --warn: #9a6512;
  --warn-soft: #fdf6e7;
  --ok: #2d7a58;
  --shadow: 0 1px 2px rgba(23, 38, 61, .04), 0 8px 28px rgba(23, 38, 61, .055);
  --doc-bg: #ffffff;
  --doc-text: #26313f;
  --doc-font: 19px;
  --doc-lh: 1.9;
  --doc-w: 720px;
}

body[data-theme="sepia"] {
  --bg: #f2ece0;
  --surface: #fbf6ea;
  --surface-2: #f6efe1;
  --border: #e3d8c2;
  --border-strong: #d3c4a8;
  --text: #3b3125;
  --text-2: #635440;
  --muted: #9a8a71;
  --accent: #8a6428;
  --accent-soft: #f0e4cb;
  --doc-bg: #fbf6ea;
  --doc-text: #40372a;
}

body[data-theme="night"] {
  --bg: #151a22;
  --surface: #1d242e;
  --surface-2: #222b37;
  --border: #2e3947;
  --border-strong: #3c495a;
  --text: #e6ebf2;
  --text-2: #b3bfcd;
  --muted: #8493a5;
  --accent: #7ba2ff;
  --accent-soft: #263349;
  --accent-text: #101722;
  --danger: #f0837c;
  --danger-soft: #3a2426;
  --warn: #e6bc6f;
  --warn-soft: #3a3020;
  --ok: #79cfa6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .2), 0 10px 30px rgba(0, 0, 0, .24);
  --doc-bg: #1d242e;
  --doc-text: #d8e0ea;
}

* { box-sizing: border-box; }

/* 作者样式中的 display 会覆盖浏览器对 [hidden] 的默认处理，这里统一兜底 */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition: background-color .2s ease, color .2s ease;
}

.wrap { width: min(1120px, calc(100% - 40px)); margin: 0 auto; }

/* ---------- top bar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.topbar-inner { height: 64px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 17px; letter-spacing: .06em; }
.brand-text span { font-size: 11.5px; color: var(--muted); letter-spacing: .02em; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--ok);
  background: color-mix(in srgb, var(--ok) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--ok) 22%, transparent);
  padding: 4px 10px; border-radius: 100px;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.icon-btn {
  width: 34px; height: 34px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); border-radius: 8px; cursor: pointer; display: grid; place-items: center;
  transition: .15s;
}
.icon-btn:hover { border-color: var(--border-strong); color: var(--accent); background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.input-card { margin-top: 26px; overflow: hidden; }

.tabs { display: flex; align-items: center; gap: 4px; padding: 8px 18px 0; border-bottom: 1px solid var(--border); }
.tab {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  padding: 9px 14px 12px; font-size: 13.5px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500;
  transition: .15s;
}
.tab:hover { color: var(--text-2); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs-hint { margin-left: auto; font-size: 11.5px; color: var(--muted); padding-bottom: 10px; }

.pane { display: none; padding: 18px; }
.pane.active { display: block; }
.url-row { display: flex; gap: 10px; }
.input-shell {
  flex: 1; display: flex; align-items: center; gap: 9px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface-2); padding: 0 12px;
  transition: .15s;
}
.input-shell:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
.input-icon { width: 17px; height: 17px; color: var(--muted); flex: none; }
.input-shell input {
  flex: 1; height: 42px; border: 0; outline: 0; background: transparent;
  color: var(--text); font-size: 13.5px; min-width: 0; font-family: inherit;
}
.input-shell input::placeholder { color: var(--muted); }

.btn {
  appearance: none; border-radius: 8px; cursor: pointer; font-family: inherit;
  font-size: 13.5px; font-weight: 500; padding: 0 20px; height: 42px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; transition: .15s; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .65; cursor: wait; }
.btn-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-ghost:disabled { opacity: .4; cursor: not-allowed; }
.btn.full { width: 100%; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.advanced { margin-top: 12px; }
.advanced summary { font-size: 12px; color: var(--muted); cursor: pointer; width: fit-content; }
.advanced summary:hover { color: var(--accent); }
.advanced-body { padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.advanced-body label { font-size: 11.5px; color: var(--text-2); }
.advanced-body input {
  height: 36px; border: 1px solid var(--border-strong); border-radius: 7px;
  background: var(--surface-2); color: var(--text); padding: 0 10px;
  font-size: 12.5px; font-family: ui-monospace, Consolas, monospace; outline: 0;
}
.advanced-body input:focus { border-color: var(--accent); }

#pasteInput {
  width: 100%; height: 130px; resize: vertical; border: 1px solid var(--border-strong);
  border-radius: 8px; background: var(--surface-2); color: var(--text);
  padding: 12px; font-size: 13px; font-family: inherit; line-height: 1.7; outline: 0;
}
#pasteInput:focus { border-color: var(--accent); }
.paste-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; gap: 12px; }
.muted { color: var(--muted); font-size: 11.5px; }

/* ---------- 在线搜书 ---------- */
.src-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.src-label { font-size: 11.5px; color: var(--muted); margin-right: 2px; }
.chip {
  appearance: none; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-2); font-family: inherit; font-size: 12px; cursor: pointer;
  height: 28px; padding: 0 11px; border-radius: 99px; transition: .15s;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.custom-src { display: flex; gap: 8px; margin-top: 10px; }
.custom-src input {
  flex: 1; min-width: 0; height: 36px; border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface-2); color: var(--text); padding: 0 11px;
  font-size: 12.5px; font-family: inherit; outline: 0;
}
.custom-src input:focus { border-color: var(--accent); }
.custom-src .btn { height: 36px; padding: 0 14px; flex: none; width: auto; }

.openbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px;
  padding: 10px 12px; border-radius: 9px; background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  font-size: 12.5px; color: var(--text-2);
}
.openbar a { color: var(--accent); font-weight: 600; text-decoration: none; }
.openbar a:hover { text-decoration: underline; }

.book-tips { margin-top: 14px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 9px; padding: 12px 14px; }
.book-tips p { margin: 0 0 7px; font-size: 12px; line-height: 1.75; color: var(--text-2); }
.book-tips p:last-child { margin-bottom: 0; }
.book-tips b { color: var(--text); }

.hist { margin-top: 14px; }
.hist-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.hist-head span { font-size: 12px; color: var(--muted); }
.link-btn {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  font-family: inherit; font-size: 11.5px; cursor: pointer; padding: 2px 4px;
}
.link-btn:hover { color: var(--danger); }
.hist-list { display: flex; gap: 6px; flex-wrap: wrap; }
.hist-item {
  display: inline-flex; align-items: center; max-width: 230px; height: 28px; padding: 0 11px;
  border-radius: 99px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); font-size: 12px; font-family: inherit; cursor: pointer;
}
.hist-item:hover { border-color: var(--accent); color: var(--accent); }
.hist-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-extra { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.book-extra .tool { border-color: var(--border); background: var(--surface-2); }
.book-extra .tool:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- notice ---------- */
.notice { margin-top: 14px; border-radius: 9px; padding: 11px 14px; font-size: 12.5px; border: 1px solid transparent; }
.notice.error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.notice.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.notice.info { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 22%, transparent); }

/* ---------- reader ---------- */
.reader-card { margin-top: 18px; overflow: hidden; }
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); flex-wrap: wrap;
  position: sticky; top: 64px; z-index: 20;
}
.toolbar-left { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.tool {
  appearance: none; border: 1px solid transparent; background: transparent;
  color: var(--text-2); font-family: inherit; font-size: 12.5px; cursor: pointer;
  height: 32px; padding: 0 10px; border-radius: 7px;
  display: inline-flex; align-items: center; gap: 6px; transition: .15s;
}
.tool svg { width: 15px; height: 15px; }
.tool:hover { background: var(--surface); border-color: var(--border); color: var(--accent); }
.tool.active { background: var(--accent-soft); color: var(--accent); }
.divider { width: 1px; height: 18px; background: var(--border-strong); margin: 0 6px; }
.toolbar-right { font-size: 11.5px; color: var(--muted); white-space: nowrap; }

.article { background: var(--doc-bg); min-height: 380px; }
.empty-state { text-align: center; padding: 78px 24px 86px; color: var(--text-2); }
.empty-icon { color: var(--border-strong); margin-bottom: 16px; }
.empty-icon svg { width: 48px; height: 48px; }
.empty-state h2 { font-size: 17px; font-weight: 600; color: var(--text); margin: 0 0 10px; }
.empty-state p { font-size: 13px; margin: 0 auto 8px; max-width: 520px; line-height: 1.8; }
.empty-state .empty-sub { color: var(--muted); font-size: 12px; margin-top: 16px; }

.doc { max-width: var(--doc-w); margin: 0 auto; padding: 44px 32px 60px; }
.doc-meta { font-size: 11.5px; color: var(--accent); letter-spacing: .08em; font-weight: 600; margin-bottom: 10px; }
.doc-title { font-size: 25px; line-height: 1.45; font-weight: 650; margin: 0 0 10px; color: var(--text); letter-spacing: .01em; }
.doc-info { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 16px; }
.rule { height: 1px; background: var(--border); margin: 26px 0 30px; }
.doc-body {
  font-size: var(--doc-font); line-height: var(--doc-lh); color: var(--doc-text);
  font-family: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", Georgia, serif;
  letter-spacing: .015em;
  word-break: break-word;
}
.doc-body.text-align { text-align: justify; text-justify: inter-ideograph; }
.doc-body p { margin: 0 0 .85em; }
.doc-body.indent p { text-indent: 2em; }
.doc-body p:last-child { margin-bottom: 0; }
.doc-body h2, .doc-body h3 { font-size: 1.06em; font-weight: 650; margin: 1.6em 0 .7em; text-indent: 0; }
.doc-body ::selection, .doc-body::selection { background: color-mix(in srgb, var(--accent) 24%, transparent); }

.chapter-nav {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-top: 1px solid var(--border); background: var(--surface-2);
}
.chapter-pos { font-size: 11.5px; color: var(--muted); }

/* ---------- footer ---------- */
.footer { padding: 26px 4px 44px; color: var(--muted); font-size: 11.5px; line-height: 1.9; }
.footer p { margin: 0 0 5px; }
.footer strong { color: var(--text-2); font-weight: 600; }
.footer-sub { opacity: .8; }

/* ---------- drawer ---------- */
.drawer-mask { position: fixed; inset: 0; background: rgba(15, 24, 38, .28); z-index: 40; backdrop-filter: blur(1px); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 92vw); z-index: 41;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -14px 0 40px rgba(15, 24, 38, .12);
  display: flex; flex-direction: column;
  animation: slideIn .2s ease-out;
}
@keyframes slideIn { from { transform: translateX(20px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-head {
  height: 60px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; border-bottom: 1px solid var(--border);
}
.drawer-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.drawer-body { padding: 20px 18px 40px; overflow-y: auto; flex: 1; }
.field { margin-bottom: 24px; }
.field > label { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-2); margin-bottom: 10px; }
.field output { color: var(--accent); font-variant-numeric: tabular-nums; }
.seg { display: flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.seg button {
  flex: 1; height: 34px; border: 0; background: var(--surface); color: var(--text-2);
  font-family: inherit; font-size: 12.5px; cursor: pointer; border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--accent); color: var(--accent-text); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.check { display: flex !important; align-items: center; gap: 8px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }
.field-note { font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 14px; }

.fix-intro { font-size: 12px; color: var(--text-2); line-height: 1.8; margin: 0 0 16px; }
.fix-summary { font-size: 11.5px; color: var(--accent); background: var(--accent-soft); padding: 9px 11px; border-radius: 7px; margin-bottom: 14px; }
.fix-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(94px, 1fr)); gap: 8px; margin-bottom: 20px; }
.fix-item { display: flex; flex-direction: column; gap: 4px; }
.fix-item label { font-size: 10.5px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.fix-item input {
  width: 100%; height: 34px; text-align: center; font-size: 17px;
  border: 1px solid var(--border-strong); border-radius: 7px;
  background: var(--surface-2); color: var(--text); font-family: inherit; outline: 0;
}
.fix-item input:focus { border-color: var(--accent); background: var(--surface); }
.fix-item.overridden input { border-color: var(--accent); color: var(--accent); }

/* ---------- 章节目录 ---------- */
.cat-search { margin-bottom: 12px; }
.cat-search input {
  width: 100%; height: 36px; padding: 0 11px; box-sizing: border-box;
  font-size: 13px; font-family: inherit;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface-2); color: var(--text); outline: 0;
}
.cat-search input:focus { border-color: var(--accent); background: var(--surface); }
.cat-summary {
  font-size: 11.5px; color: var(--accent); background: var(--accent-soft);
  padding: 9px 11px; border-radius: 7px; margin-bottom: 12px;
}
.cat-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 20px; }
.cat-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; padding: 9px 11px; text-align: left; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text); font-family: inherit;
}
.cat-item:hover { border-color: var(--accent); }
.cat-item.current { border-color: var(--accent); background: var(--accent-soft); }
.cat-title {
  font-size: 12.5px; line-height: 1.5; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cat-flag { flex: none; font-size: 10.5px; color: var(--accent); }
.cat-item.locked .cat-flag { color: var(--muted); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: #202a38; color: #fff; font-size: 13px; padding: 10px 20px;
  border-radius: 8px; box-shadow: 0 8px 28px rgba(0, 0, 0, .2); z-index: 60;
  animation: toastIn .18s ease-out;
}
body[data-theme="night"] .toast { background: #3b4959; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (max-width: 760px) {
  .wrap { width: calc(100% - 24px); }
  .tabs-hint { display: none; }
  .url-row { flex-direction: column; }
  .btn { width: 100%; }
  .toolbar { position: static; }
  .toolbar-right { width: 100%; }
  .doc { padding: 30px 18px 44px; }
  .doc-title { font-size: 21px; }
  .empty-state { padding: 54px 18px 64px; }
}
