/* =========================================================
   共读平台 · 样式
   纸感底色 + 陶土色强调；英文衬线为主文，中文译文随段对照
   主题：跟随系统（默认）/ 日间 / 护眼 / 夜间
   ========================================================= */
:root {
  --paper: #fbf8f2;
  --paper-2: #f4eee3;
  --panel: #fffdf9;
  --panel-2: #f8f3ea;
  --ink: #26211d;
  --ink-2: #4f463e;
  --muted: #877c71;
  --line: #e6dccd;
  --line-2: #efe7da;
  --accent: #a34a32;
  --accent-dk: #82381f;
  --accent-soft: #f4e2d8;
  --accent-ink: #fff8f2;
  --zh-ink: #564b42;
  --zh-rule: #dccbb7;
  --quote-rule: #d7b9a6;
  --hl: #f6dd9b;
  --hl-mine: #f1c3ae;
  --ok: #3f7a52;
  --ok-soft: #e9f4ec;
  --warn: #8a6a2f;
  --warn-soft: #fbf3df;
  --danger: #a63324;
  --danger-soft: #fbe9e5;
  --shadow-sm: 0 1px 2px rgba(60, 40, 20, 0.06);
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.05), 0 10px 30px rgba(60, 40, 20, 0.08);
  --shadow-lg: 0 24px 70px rgba(50, 35, 20, 0.26);
  --overlay: rgba(36, 28, 20, 0.42);
  --focus: 0 0 0 3px rgba(163, 74, 50, 0.22);
  --scroll-thumb: color-mix(in srgb, var(--accent) 30%, var(--line));
  --scroll-thumb-hover: color-mix(in srgb, var(--accent) 60%, var(--line));

  --serif-en: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Charter, "Source Serif Pro", Georgia, "Songti SC", "Noto Serif SC", serif;
  --serif-zh: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "Source Han Serif CN", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;

  --font-step: 0px;
  --fs-en: calc(19.5px + var(--font-step));
  --fs-zh: calc(17px + var(--font-step));
  --fs-zh-solo: calc(19px + var(--font-step));
  --measure: 42rem;
  color-scheme: light;
}

/* 护眼：偏暖的米黄纸色，降低对比 */
:root[data-theme="sepia"] {
  --paper: #f3ead6;
  --paper-2: #ebdfc5;
  --panel: #f8f0de;
  --panel-2: #efe4cc;
  --ink: #3a2e22;
  --ink-2: #5a4a39;
  --muted: #8b7a64;
  --line: #ddcdaf;
  --line-2: #e6d9be;
  --accent: #9a4a2c;
  --accent-dk: #7a3820;
  --accent-soft: #ead2bd;
  --zh-ink: #5a4a39;
  --zh-rule: #cfb894;
  --quote-rule: #c9a88a;
  --hl: #ecd28a;
  --hl-mine: #e6b79c;
}

/* 夜间：深色暖灰，强调色提亮 */
:root[data-theme="dark"] {
  --paper: #191715;
  --paper-2: #221f1c;
  --panel: #201d1a;
  --panel-2: #2a2622;
  --ink: #ebe4da;
  --ink-2: #cbc1b4;
  --muted: #958a7d;
  --line: #36312c;
  --line-2: #2d2925;
  --accent: #e08a6c;
  --accent-dk: #f0a184;
  --accent-soft: #3b2a22;
  --accent-ink: #1b1512;
  --zh-ink: #c2b7aa;
  --zh-rule: #4a423a;
  --quote-rule: #5b4a3f;
  --hl: rgba(214, 172, 70, 0.34);
  --hl-mine: rgba(224, 138, 108, 0.36);
  --ok: #8cc59c;
  --ok-soft: #1f2d23;
  --warn: #e0c17a;
  --warn-soft: #2e2818;
  --danger: #f08a7a;
  --danger-soft: #3a211d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.55);
  --overlay: rgba(0, 0, 0, 0.55);
  --focus: 0 0 0 3px rgba(224, 138, 108, 0.3);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --paper: #191715;
    --paper-2: #221f1c;
    --panel: #201d1a;
    --panel-2: #2a2622;
    --ink: #ebe4da;
    --ink-2: #cbc1b4;
    --muted: #958a7d;
    --line: #36312c;
    --line-2: #2d2925;
    --accent: #e08a6c;
    --accent-dk: #f0a184;
    --accent-soft: #3b2a22;
    --accent-ink: #1b1512;
    --zh-ink: #c2b7aa;
    --zh-rule: #4a423a;
    --quote-rule: #5b4a3f;
    --hl: rgba(214, 172, 70, 0.34);
    --hl-mine: rgba(224, 138, 108, 0.36);
    --ok: #8cc59c;
    --ok-soft: #1f2d23;
    --warn: #e0c17a;
    --warn-soft: #2e2818;
    --danger: #f08a7a;
    --danger-soft: #3a211d;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.55);
    --overlay: rgba(0, 0, 0, 0.55);
    --focus: 0 0 0 3px rgba(224, 138, 108, 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); }
button, input, select, textarea { font-family: inherit; color: inherit; }
[hidden], .is-hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* 滚动条：细、圆角、与强调色同色系，轨道透明 */
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }
::selection { background: color-mix(in srgb, var(--accent) 24%, transparent); }

/* =========================== 通用控件 ========================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14.5px;
  line-height: 1.3;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 10px 16px;
  min-height: 42px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; letter-spacing: 0.02em; }
.btn-primary:hover { background: var(--accent-dk); border-color: var(--accent-dk); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--accent); background: var(--accent-soft); }
.btn-danger { color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn-danger-solid:hover { filter: brightness(0.92); }
.btn-danger:hover { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn-sm { min-height: 34px; padding: 6px 11px; font-size: 13px; border-radius: 8px; }

.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-2);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--accent); }
.icon-btn.is-on, .icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-dk); }
.icon-btn:disabled { opacity: 0.4; cursor: default; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.field { display: flex; flex-direction: column; gap: 7px; font-size: 13px; color: var(--ink-2); }
.field > span { letter-spacing: 0.03em; }
.field small { color: var(--muted); font-size: 12px; line-height: 1.5; }
.input, .field input, .field select {
  font-size: 15px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
  min-width: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .field input:focus, .field select:focus { border-color: var(--accent); box-shadow: var(--focus); }
.pw-wrap { position: relative; display: flex; }
.pw-wrap input { flex: 1; padding-right: 64px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--muted); font-size: 12.5px; padding: 6px 8px; border-radius: 7px; cursor: pointer;
}
.pw-toggle:hover { color: var(--accent); background: var(--accent-soft); }
.pw-meter { height: 4px; border-radius: 4px; background: var(--line-2); overflow: hidden; }
.pw-meter > i { display: block; height: 100%; width: 0; background: var(--danger); transition: width 0.2s, background 0.2s; }
.pw-meter[data-level="2"] > i { background: var(--warn); }
.pw-meter[data-level="3"] > i { background: var(--ok); }

/* =========================== 登录门 ========================= */
body.gate {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 12% -10%, color-mix(in srgb, var(--accent) 10%, transparent) 0%, transparent 60%),
    var(--paper);
}
.gate-wrap { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 1.05fr) minmax(360px, 0.95fr); }
.gate-art {
  position: relative;
  display: flex;
  align-items: center;
  padding: 6vh 5vw;
  background: linear-gradient(160deg, #a84d34, #7d3520 75%, #6a2c1a);
  color: #fdf3ea;
  overflow: hidden;
}
.gate-art::before {
  position: absolute;
  right: -6vw;
  top: -8vh;
  font: 600 52vh/1 var(--serif-zh);
  color: rgba(255, 240, 225, 0.05);
  content: "读";
  pointer-events: none;
}
.gate-art::after {
  content: "";
  position: absolute;
  inset: auto -20% -30% -20%;
  height: 62%;
  background:
    radial-gradient(closest-side at 30% 20%, rgba(255, 219, 178, 0.24), transparent 70%),
    radial-gradient(closest-side at 75% 60%, rgba(255, 236, 200, 0.14), transparent 70%);
  pointer-events: none;
}
.gate-art-inner { position: relative; z-index: 1; max-width: 34rem; }
.brand-mark {
  display: inline-block;
  font-size: 13px;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  padding: 6px 10px 6px 14px;
  margin-bottom: 28px;
}
.gate-title { font-family: var(--serif-zh); font-size: clamp(30px, 4.2vw, 46px); line-height: 1.25; margin: 0 0 10px; letter-spacing: 0.02em; font-weight: 600; }
.gate-sub { font-family: var(--serif-en); font-style: italic; font-size: clamp(17px, 1.8vw, 22px); margin: 0 0 18px; color: rgba(255, 245, 235, 0.88); }
.gate-author { font-size: 13.5px; letter-spacing: 0.06em; margin: 0 0 34px; color: rgba(255, 245, 235, 0.72); }
.gate-quote {
  font-family: var(--serif-zh);
  font-size: 16px;
  line-height: 1.9;
  padding-left: 16px;
  border-left: 2px solid rgba(255, 240, 228, 0.45);
  margin: 0 0 34px;
  color: rgba(255, 246, 238, 0.9);
}
.gate-feats { list-style: none; margin: 0; padding: 0; font-size: 14px; line-height: 2.1; color: rgba(255, 246, 238, 0.82); }
.gate-feats b { color: #fff6ee; font-weight: 600; margin-right: 6px; }
.gate-form { display: flex; align-items: center; justify-content: center; padding: 6vh 4vw; }
.gate-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 26px 26px 20px; }
.tabs { display: flex; gap: 6px; background: var(--paper-2); padding: 4px; border-radius: 11px; margin-bottom: 20px; }
.tab { flex: 1; border: 0; background: transparent; color: var(--muted); font-size: 14px; padding: 9px 6px; border-radius: 8px; cursor: pointer; transition: 0.18s; }
.tab.is-active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow-sm); font-weight: 600; }
.form { display: flex; flex-direction: column; gap: 14px; }
.gate-msg { min-height: 20px; margin: 12px 2px 0; font-size: 13px; color: var(--muted); }
.gate-msg.is-error { color: var(--danger); }
.gate-msg.is-ok { color: var(--ok); }
.gate-note { margin: 14px 0 0; font-size: 12px; line-height: 1.7; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 12px; }

/* =========================== 阅读器框架 ========================= */
body.reader { height: 100vh; height: 100dvh; overflow: hidden; }
.app { display: grid; grid-template-columns: 264px minmax(0, 1fr) 320px; height: 100vh; height: 100dvh; overflow: hidden; }
.skip-link { position: fixed; top: -100px; left: 16px; z-index: 100; padding: 12px; background: var(--panel); border-radius: 8px; }
.skip-link:focus { top: 12px; }

/* --- 左侧目录 --- */
.side { position: relative; display: flex; flex-direction: column; min-height: 0; height: 100%; overflow: hidden; background: var(--panel-2); border-right: 1px solid var(--line); }
.side-head { position: relative; padding: 22px 20px 16px; border-bottom: 1px solid var(--line-2); }
.brand-chip { display: inline-block; font-size: 11px; letter-spacing: 0.4em; text-indent: 0.4em; color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); border-radius: 999px; padding: 3px 8px 3px 10px; margin-bottom: 12px; }
.side-title { font-family: var(--serif-zh); font-size: 18px; line-height: 1.4; margin: 0 0 4px; font-weight: 600; }
.side-sub { font-family: var(--serif-en); font-style: italic; font-size: 14px; color: var(--ink-2); margin: 0; }
.side-author { font-size: 11.5px; color: var(--muted); margin: 8px 0 0; letter-spacing: 0.02em; }
.side-toc { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 10px 10px 18px; }
.toc-item {
  display: flex; gap: 10px; align-items: baseline; width: 100%; text-align: left;
  border: 0; background: transparent; padding: 9px 10px; margin: 1px 0; border-radius: 10px;
  cursor: pointer; color: var(--ink-2); font-size: 14px; line-height: 1.5; transition: background 0.15s, color 0.15s;
}
.toc-item:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.toc-item.is-active { background: var(--accent-soft); color: var(--accent-dk); font-weight: 600; }
.toc-num { flex: none; min-width: 1.6em; font-family: var(--serif-zh); font-size: 12.5px; color: var(--muted); text-align: center; }
.toc-item.is-active .toc-num { color: var(--accent); }
.toc-label { flex: 1; }
.toc-badge { flex: none; font-size: 11px; color: var(--accent); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; }
.side-foot { display: flex; align-items: center; gap: 4px; padding: 12px 12px max(12px, env(safe-area-inset-bottom)) 14px; border-top: 1px solid var(--line-2); }
.avatar { flex: none; width: 34px; height: 34px; margin-right: 6px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 14px; font-weight: 600; }
.who { flex: 1; min-width: 0; }
.who-name { font-size: 13.5px; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* --- 中间正文 --- */
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--paper); }
.topbar {
  position: relative; z-index: 20; flex: none;
  display: flex; align-items: center; gap: 10px;
  min-height: 60px; padding: 10px 24px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--line-2);
}
.topbar h2 { flex: 1; min-width: 0; margin: 0; font-family: var(--serif-en); font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.seg-ctl { flex: none; display: flex; gap: 2px; padding: 3px; background: var(--paper-2); border: 1px solid var(--line-2); border-radius: 11px; }
.seg-ctl button { min-height: 34px; border: 0; background: transparent; color: var(--muted); font-size: 13px; padding: 5px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; transition: 0.15s; }
.seg-ctl button:hover { color: var(--ink); }
.seg-ctl button.is-active { background: var(--panel); color: var(--accent-dk); font-weight: 600; box-shadow: var(--shadow-sm); }
.tool-group { flex: none; display: flex; gap: 2px; padding-left: 4px; }
.glyph-sm { font: 600 13px var(--serif-en); }
.glyph-lg { font: 600 19px var(--serif-en); }
.progress-rail { flex: none; height: 2px; background: var(--line-2); }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior-y: contain; scrollbar-gutter: stable; -webkit-overflow-scrolling: touch; }
.doc { max-width: calc(var(--measure) + 72px); margin: 0 auto; padding: 56px 36px max(96px, env(safe-area-inset-bottom)); }

/* --- 章首 --- */
.chap-head { text-align: center; margin: 0 0 44px; }
.chap-num { display: flex; justify-content: center; align-items: center; gap: 10px; margin-bottom: 18px; font-size: 12px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--accent); }
.chap-num-zh { letter-spacing: 0.3em; text-transform: none; color: var(--muted); }
.chap-num-zh::before { content: "·"; margin-right: 10px; color: var(--line); letter-spacing: 0; }
.chapter-title { margin: 0; font: inherit; }
.chap-en, .chap-zh { display: block; }
.chap-en { font-family: var(--serif-en); font-weight: 600; font-size: clamp(28px, 3.1vw, 40px); line-height: 1.2; letter-spacing: -0.005em; color: var(--ink); text-wrap: balance; }
.chap-zh { margin-top: 14px; font-family: var(--serif-zh); font-weight: 400; font-size: clamp(18px, 1.9vw, 22px); line-height: 1.5; color: var(--ink-2); letter-spacing: 0.06em; text-wrap: balance; overflow-wrap: anywhere; }
.chap-rule { width: 56px; height: 1px; margin: 30px auto 0; background: var(--accent); opacity: 0.55; }
.source-note { font: 13px/1.75 var(--sans); color: var(--muted); margin: 0 0 24px; }

/* --- 小节标题 --- */
.seg { position: relative; scroll-margin-block: 28px; }
.seg-h { margin: 3.2rem 0 1.6rem; }
.section-title { margin: 0; font: inherit; }
.h-en, .h-zh { display: block; }
.h-en { font-family: var(--serif-en); font-size: calc(var(--fs-en) + 3px); font-weight: 600; line-height: 1.35; color: var(--ink); text-wrap: balance; }
.h-zh { margin-top: 6px; font-family: var(--serif-zh); font-size: var(--fs-zh); font-weight: 500; line-height: 1.6; color: var(--ink-2); letter-spacing: 0.04em; }
.h-en::before { content: ""; display: block; width: 28px; height: 2px; margin-bottom: 14px; background: var(--accent); border-radius: 2px; }

/* --- 正文：逐段对照 --- */
.p-en { font-family: var(--serif-en); font-size: var(--fs-en); line-height: 1.75; color: var(--ink); margin: 0; overflow-wrap: anywhere; hyphens: auto; font-variant-numeric: oldstyle-nums; }
.p-zh { font-family: var(--serif-zh); font-size: var(--fs-zh); line-height: 1.9; color: var(--zh-ink); margin: 0; letter-spacing: 0.02em; overflow-wrap: anywhere; line-break: strict; text-align: justify; text-justify: inter-ideograph; }
.pair { margin: 0 0 1.55em; }
.pair > .p-zh, .reading-list li > .p-zh { margin-top: 0.6em; padding-left: 0.95em; border-left: 2px solid var(--zh-rule); }
.seg:has(+ .seg-h) .pair:last-child, .seg:last-of-type .pair:last-child { margin-bottom: 0; }

/* 引文：原书缩进引用 */
.pair.is-quote { margin: 0.4em 0 1.8em; padding: 2px 0 2px 1.3em; border-left: 3px solid var(--quote-rule); }
.pair.is-quote .p-en { font-size: calc(var(--fs-en) - 1.5px); color: var(--ink-2); font-style: italic; }
.pair.is-quote .p-zh { font-size: calc(var(--fs-zh) - 0.5px); border-left: 0; padding-left: 0; }

/* 编号列表：编号与正文分列，折行对齐 */
.reading-list { list-style: none; margin: 0.2em 0 1.6em; padding: 0; }
.reading-list > li { margin: 0; padding: 0; }
.reading-list > li + li { margin-top: 0.9em; }
.reading-list .p-en, .reading-list .p-zh { display: grid; grid-template-columns: 1.9em minmax(0, 1fr); column-gap: 0.25em; text-indent: 0; text-align: left; }
.list-marker { white-space: pre; hyphens: none; color: var(--accent); font-variant-numeric: lining-nums tabular-nums; }
.list-text { min-width: 0; }
.reading-anchor { display: block; height: 0; overflow: hidden; }
.seg-list-group { margin-bottom: 0.4rem; }

/* 后备排版：中英段落数不一致时，整段英文在上、整段中文在下 */
.seg-en > .p-en, .seg-zh > .p-zh { margin-bottom: 0.85em; }
body.mode-bi .seg-zh { margin: 0.6em 0 1.55em; padding-left: 0.95em; border-left: 2px solid var(--zh-rule); }

.translation-credit, .translation-missing { margin: 0 0 8px; font: 12px/1.6 var(--sans); color: var(--warn); }
.translation-missing { font-size: 13.5px; background: var(--warn-soft); padding: 10px 12px; border-radius: 8px; }

/* --- 语言模式 --- */
body.mode-en .p-zh, body.mode-en .h-zh, body.mode-en .chap-zh, body.mode-en .chap-num-zh,
body.mode-en .seg-zh, body.mode-en .translation-credit, body.mode-en .translation-missing { display: none; }
body.mode-zh .p-en, body.mode-zh .h-en, body.mode-zh .chap-en, body.mode-zh .seg-en { display: none; }
body.mode-en .pair { margin-bottom: 1.05em; }
body.mode-en .p-en { font-size: calc(var(--fs-en) + 0.5px); line-height: 1.78; }
body.mode-zh .pair { margin-bottom: 0.9em; }
body.mode-zh .p-zh { font-size: var(--fs-zh-solo); line-height: 1.95; color: var(--ink); text-indent: 2em; }
body.mode-zh .pair > .p-zh, body.mode-zh .reading-list li > .p-zh { margin-top: 0; padding-left: 0; border-left: 0; }
body.mode-zh .reading-list .p-zh, body.mode-zh .pair.is-quote .p-zh { text-indent: 0; }
body.mode-zh .pair.is-quote .p-zh { color: var(--ink-2); }
body.mode-zh .h-zh { margin-top: 0; font-size: calc(var(--fs-zh-solo) + 3px); font-weight: 600; color: var(--ink); }
body.mode-zh .h-zh::before { content: ""; display: block; width: 28px; height: 2px; margin-bottom: 14px; background: var(--accent); border-radius: 2px; }
body.mode-zh .chap-zh { margin-top: 0; font-weight: 600; font-size: clamp(26px, 2.8vw, 34px); color: var(--ink); letter-spacing: 0.04em; }
body.mode-zh .chap-num > span[lang="en"] { display: none; }
body.mode-zh .chap-num-zh::before { content: none; }
body.mode-zh .chap-num-zh { color: var(--accent); }

/* --- 章末翻页 --- */
.chap-nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 64px; padding-top: 26px; border-top: 1px solid var(--line); }
.chap-nav .btn { display: block; text-align: left; white-space: normal; line-height: 1.55; padding: 14px 16px; overflow-wrap: anywhere; font-family: var(--serif-en); }
.chap-nav .next { text-align: right; grid-column: 2; }
.chap-nav small { display: block; color: var(--muted); font: 12px var(--sans); margin-bottom: 4px; }

/* --- 划线 --- */
mark.hl { position: relative; background: linear-gradient(180deg, transparent 56%, var(--hl) 56%); color: inherit; padding: 0 1px; border-radius: 2px; cursor: pointer; transition: background 0.15s; }
mark.hl:hover { background: var(--hl); }
mark.hl.mine { background: linear-gradient(180deg, transparent 56%, var(--hl-mine) 56%); }
mark.hl.mine:hover { background: var(--hl-mine); }
/* 对应语言中的同步划线：虚线下划，点击同样打开该心得 */
mark.hl.echo, mark.hl.mine.echo { background: none; text-decoration: underline dashed color-mix(in srgb, var(--accent) 55%, transparent); text-decoration-thickness: 1.5px; text-underline-offset: 0.28em; }
mark.hl.echo:hover { background: color-mix(in srgb, var(--hl) 45%, transparent); }
mark.hl:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* 心得气泡：点击划线显示，只读 */
.note-pop {
  position: fixed; z-index: 65; display: none; width: min(340px, calc(100vw - 16px)); max-height: min(46vh, 380px); overflow-y: auto; overscroll-behavior: contain;
  padding: 4px 0; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink); box-shadow: var(--shadow-lg);
  font-family: var(--sans); text-indent: 0; animation: pop 0.14s ease-out;
}
.note-pop.is-open { display: block; }
.pop-note { padding: 11px 14px 10px; }
.pop-note + .pop-note { border-top: 1px solid var(--line-2); }
.pop-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-bottom: 6px; font-size: 12px; color: var(--muted); }
.pop-meta b { color: var(--ink); font-size: 13px; }
.pop-lang { color: var(--accent); }
.pop-body { font-size: 14px; line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; }


/* --- 右侧心得 --- */
.notes-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; background: var(--panel-2); border-left: 1px solid var(--line); }
.notes-head { display: flex; align-items: center; gap: 8px; min-height: 60px; padding: 10px 14px 10px 18px; border-bottom: 1px solid var(--line-2); }
.notes-head h3 { flex: 1; margin: 0; font-family: var(--serif-zh); font-size: 16px; font-weight: 600; }
.notes-count { font-size: 12px; color: var(--muted); }
.notes-close { display: none; }
.notes-filter { display: flex; gap: 6px; padding: 12px 14px 6px; }
.chip { min-height: 34px; padding: 4px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--muted); font-size: 12.5px; cursor: pointer; }
.chip:hover { color: var(--ink); }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.notes-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px 12px 40px; }
.note-card { margin-bottom: 10px; padding: 12px 13px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-sm); cursor: pointer; overflow-wrap: anywhere; transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s; }
.note-card:hover { border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); box-shadow: var(--shadow); }
.note-card:focus-visible { border-color: var(--accent); }
.note-card.is-flash { animation: card-flash 1.6s ease-out; }
@keyframes card-flash { 0%, 30% { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); } }
.note-edit { flex: none; display: grid; place-items: center; width: 30px; height: 30px; margin: -6px -6px -6px 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.note-edit:hover, .note-edit:focus-visible { background: var(--accent-soft); color: var(--accent-dk); }
.note-edit svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.note-quote { max-height: 5.2em; overflow: hidden; margin-bottom: 8px; padding: 5px 9px; border-left: 2px solid var(--quote-rule); border-radius: 4px; background: var(--paper-2); color: var(--accent-dk); font: 13px/1.6 var(--serif-zh); }
.note-body { font-size: 13.5px; line-height: 1.75; color: var(--ink); white-space: pre-wrap; word-break: break-word; }
.note-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 9px; font-size: 11.5px; color: var(--muted); }
.note-meta .dot { opacity: 0.5; }
.note-meta .spacer, .modal-foot .spacer { flex: 1; }
.tag { font-size: 11px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.tag.public { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); background: var(--ok-soft); }
.tag.private { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: var(--warn-soft); }
.empty { text-align: center; color: var(--muted); font-size: 13px; line-height: 2; padding: 34px 16px; }
.empty b { display: block; font-family: var(--serif-zh); font-size: 15px; color: var(--ink-2); margin-bottom: 6px; }

/* --- 心得批量选择 --- */
.notes-head .btn-sm { min-height: 30px; padding: 4px 10px; }
.notes-batch { display: flex; align-items: center; gap: 10px; margin: 6px 12px 4px; padding: 8px 8px 8px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow-sm); }
.batch-all { display: inline-flex; align-items: center; gap: 7px; padding: 4px 6px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); font-size: 13px; cursor: pointer; }
.batch-all:hover { background: var(--panel-2); }
.batch-all:disabled { opacity: 0.45; cursor: default; }
.batch-count { flex: 1; font-size: 12.5px; color: var(--muted); }
.note-check { flex: none; display: inline-grid; place-items: center; width: 18px; height: 18px; border: 1.5px solid color-mix(in srgb, var(--muted) 70%, transparent); border-radius: 50%; background: var(--panel); transition: 0.15s; }
.is-selected > .note-check, .batch-all.is-selected .note-check { border-color: var(--accent); background: var(--accent); }
.is-selected > .note-check::after, .batch-all.is-selected .note-check::after { content: ""; width: 8px; height: 4px; margin-top: -2px; border: solid var(--accent-ink); border-width: 0 0 2px 2px; transform: rotate(-45deg); }
.is-selecting .note-card { position: relative; padding-left: 42px; }
.is-selecting .note-card > .note-check { position: absolute; left: 13px; top: 14px; }
.note-card.is-selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 55%, var(--panel)); }
.note-card.is-locked { opacity: 0.5; cursor: not-allowed; }
.note-card.is-locked > .note-check { border-style: dashed; }

/* --- 划线工具条 --- */
.selbar { position: absolute; z-index: 60; display: none; gap: 2px; max-width: calc(100vw - 16px); padding: 5px; background: #2a2420; border-radius: 11px; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.26); transform: translate(-50%, -100%); }
.selbar.is-open { display: flex; }
.selbar::after { content: ""; position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%); border: 5px solid transparent; border-top-color: #2a2420; border-bottom: 0; }
.selbar.below { transform: translate(-50%, 0); }
.selbar.below::after { bottom: auto; top: -5px; border-top: 0; border-bottom: 5px solid #2a2420; }
.selbar button { min-height: 38px; padding: 6px 11px; border: 0; border-radius: 7px; background: transparent; color: #fdf6ee; font-size: 13px; cursor: pointer; white-space: nowrap; }
.selbar button:hover { background: rgba(255, 255, 255, 0.14); }
.selbar button.accent { color: #ffc99b; }

/* --- 弹层 --- */
.mask-drawer { display: none; position: fixed; inset: 0; z-index: 70; background: var(--overlay); }
.mask-drawer.is-open { display: block; }
.modal-mask { position: fixed; inset: 0; z-index: 80; display: none; align-items: center; justify-content: center; padding: 20px; background: var(--overlay); backdrop-filter: blur(2px); }
.modal-mask.is-open { display: flex; }
.modal { display: flex; flex-direction: column; width: min(560px, 100%); max-height: calc(var(--modal-viewport-height, 100dvh) - 40px); overflow: hidden; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); animation: pop 0.16s ease-out; }
@keyframes pop { from { transform: translateY(8px) scale(0.99); opacity: 0.6; } }
.modal-head { flex-shrink: 0; display: flex; align-items: center; gap: 10px; padding: 14px 14px 0 20px; }
.modal-head h4 { flex: 1; margin: 0; font-family: var(--serif-zh); font-size: 17px; }
.modal-quote { flex: 0 1 auto; max-height: 8em; overflow: auto; margin: 12px 20px 0; padding: 8px 12px; border-left: 3px solid var(--quote-rule); border-radius: 6px; background: var(--paper-2); color: var(--accent-dk); font: 13.5px/1.75 var(--serif-zh); overflow-wrap: anywhere; }
.modal-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 20px 4px; }
.modal-body textarea { width: 100%; min-height: 132px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--ink); font-size: 16px; line-height: 1.8; resize: vertical; outline: none; }
.modal-body textarea:focus { border-color: var(--accent); box-shadow: var(--focus); }
.vis-row { display: flex; gap: 8px; margin-top: 12px; }
.vis-opt { flex: 1; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink-2); font-size: 12.5px; line-height: 1.5; text-align: left; cursor: pointer; transition: 0.15s; }
.vis-opt b { display: block; margin-bottom: 2px; font-size: 13px; color: var(--ink); }
.vis-opt.is-active { border-color: var(--accent); background: var(--accent-soft); }
.vis-opt.is-active b { color: var(--accent-dk); }
.modal-err { min-height: 1em; color: var(--danger); font-size: 12.5px; }
.modal-foot { flex-shrink: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 20px 18px; }

/* --- 提示 --- */
.toast { position: fixed; left: 50%; bottom: max(26px, env(safe-area-inset-bottom)); z-index: 90; width: max-content; max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 10px; background: var(--ink); color: var(--paper); font-size: 13px; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(10px); transition: 0.2s; }
.toast.is-open { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- 语音朗读：仅单语模式显示 --- */
.tts-bar { flex: none; padding: 8px 24px 10px; background: var(--paper-2); border-bottom: 1px solid var(--line); }
body.mode-bi .tts-bar, body:not(.tts-open) .tts-bar { display: none; }
body.mode-bi #btn-tts { opacity: 0.45; }
.tts-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tts-btn, #tts-rate { min-height: 40px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--ink); font-size: 13px; cursor: pointer; }
.tts-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tts-btn:disabled, #tts-rate:disabled { opacity: 0.5; cursor: default; }
.tts-rate-label { display: flex; align-items: center; gap: 6px; margin-left: auto; font-size: 12px; color: var(--ink-2); }
.tts-status { min-height: 1.6em; margin: 6px 0 0; color: var(--ink-2); font: 12px/1.6 var(--sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tts-speaking { background: color-mix(in srgb, var(--hl) 70%, transparent); outline: 2px solid var(--hl); outline-offset: 4px; border-radius: 3px; scroll-margin-block: 20px; }
.tts-point-enabled #doc [data-p][tabindex="0"] { cursor: pointer; }
@media (hover: hover) { .tts-point-enabled #doc [data-p][tabindex="0"]:hover { background: color-mix(in srgb, var(--hl) 40%, transparent); } }

/* --- 确认框 --- */
.confirm-mask { z-index: 85; }
.confirm-box { width: min(400px, 100%); }
.confirm-body { padding: 22px 22px 4px; }
.confirm-body h4 { margin: 0 0 8px; font-family: var(--serif-zh); font-size: 17px; }
.confirm-body p { margin: 0; color: var(--ink-2); font-size: 14px; line-height: 1.7; }

/* --- 沉浸阅读：只保留正文 --- */
.immersive-exit { display: none; }
body.immersive .side, body.immersive .notes-panel, body.immersive .topbar, body.immersive .tts-bar, body.immersive .mask-drawer { display: none !important; }
body.immersive .app { grid-template-columns: minmax(0, 1fr) !important; }
body.immersive .doc { padding-top: 72px; }
body.immersive .immersive-exit {
  position: fixed; top: max(14px, env(safe-area-inset-top)); right: max(18px, env(safe-area-inset-right)); z-index: 40;
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px 7px 10px;
  border: 1px solid var(--line); border-radius: 999px; background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(8px); color: var(--muted); font-size: 12.5px; cursor: pointer; opacity: 0.5; transition: opacity 0.2s, color 0.2s;
}
body.immersive .immersive-exit:hover, body.immersive .immersive-exit:focus-visible { opacity: 1; color: var(--accent); }
.immersive-exit svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* --- 桌面收起心得面板 --- */
.reader.notes-hidden .app { grid-template-columns: 264px minmax(0, 1fr); }
.reader.notes-hidden .notes-panel { display: none; }
.mobile-only { display: none; }
.side.is-open, .notes-panel.is-open { visibility: visible; }

/* =========================== 响应式 ========================= */
@media (max-width: 1280px) {
  .app, .reader.notes-hidden .app { grid-template-columns: 248px minmax(0, 1fr); }
  .reader.notes-hidden .notes-panel { display: flex; }
  .notes-panel { position: fixed; inset: 0 0 0 auto; z-index: 75; width: min(380px, 92vw); height: 100vh; height: 100dvh; visibility: hidden; transform: translateX(105%); transition: transform 0.2s ease, visibility 0.2s; box-shadow: -12px 0 40px rgba(0, 0, 0, 0.16); }
  .notes-panel.is-open { transform: none; }
  .notes-close { display: grid; }
  .doc { padding-inline: 30px; }
}
@media (max-width: 860px) {
  .gate-wrap { grid-template-columns: 1fr; }
  .gate-art { padding: 6vh 7vw 4vh; }
  .gate-form { padding: 4vh 5vw 8vh; }
  .app, .reader.notes-hidden .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset: 0 auto 0 0; z-index: 75; width: min(320px, 88vw); height: 100vh; height: 100dvh; visibility: hidden; transform: translateX(-105%); transition: transform 0.2s ease, visibility 0.2s; box-shadow: 12px 0 40px rgba(0, 0, 0, 0.16); }
  .side.is-open { transform: none; }
  .mobile-only { display: grid; }
  .side-close { position: absolute; top: 12px; right: 10px; }
  .side-head { padding-right: 58px; }
  .topbar { padding: max(8px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left)); }
  .topbar h2 { font-size: 14.5px; }
  .doc { padding: 40px max(24px, env(safe-area-inset-right)) max(72px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left)); }
  :root { --fs-en: calc(18.5px + var(--font-step)); --fs-zh: calc(16.5px + var(--font-step)); --fs-zh-solo: calc(18px + var(--font-step)); }
  .toc-item { min-height: 46px; }
  .field input { font-size: 16px; }
}
@media (max-width: 600px) {
  .topbar { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 6px 8px; }
  #btn-toc { grid-area: 1 / 1; }
  .topbar h2 { grid-area: 1 / 2; }
  #btn-notes { grid-area: 1 / 3; justify-self: end; }
  #mode-ctl { grid-area: 2 / 1 / 3 / 3; justify-self: start; }
  .topbar .tool-group { grid-area: 2 / 3; padding-left: 0; }
  .topbar .tool-group .icon-btn { width: 34px; }
  .seg-ctl button { padding-inline: 11px; }
  .doc { padding: 30px max(20px, env(safe-area-inset-right)) max(64px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); }
  .chap-head { margin-bottom: 34px; }
  .chap-en { font-size: 27px; }
  .pair > .p-zh, .reading-list li > .p-zh { padding-left: 0.75em; }
  .reading-list .p-en, .reading-list .p-zh { grid-template-columns: 1.6em minmax(0, 1fr); column-gap: 0.2em; }
  .p-zh { text-align: left; }
  .chap-nav { gap: 8px; }
  .chap-nav .btn { padding: 12px; font-size: 14px; }
  .modal-mask { padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)); }
  .modal { border-radius: 14px; }
  .modal-head { padding: 10px 10px 0 14px; }
  .modal-body { padding: 12px 14px 0; }
  .modal-quote { margin-inline: 14px; max-height: 5.5em; }
  .modal-foot { padding: 12px 14px; }
  .vis-row { flex-direction: column; }
  .tts-bar { padding: 8px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left)); }
  .tts-btn { flex: 1 0 auto; padding-inline: 10px; }
  .tts-rate-label { margin-left: 0; }
  #tts-rate { font-size: 16px; }
}
@media (max-width: 360px) {
  .topbar { gap: 6px; }
  .seg-ctl button { padding-inline: 9px; }
  .icon-btn { width: 36px; }
  .doc { padding-inline: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
@media print {
  .side, .topbar, .tts-bar, .progress-rail, .notes-panel, .chap-nav { display: none !important; }
  body.reader, .app, .scroll { height: auto; overflow: visible; display: block; }
}
