:root {
  --bg: #f6f1e8;
  --paper: #fffdf8;
  --paper-strong: #ffffff;
  --ink: rgba(31, 28, 24, 0.96);
  --muted: #766f65;
  --line: rgba(56, 45, 31, 0.12);
  --accent: #8a4b22;
  --accent-strong: #66330f;
  --accent-soft: #fff3e1;
  --shadow: 0 18px 50px rgba(66, 45, 23, 0.10), 0 4px 14px rgba(66, 45, 23, 0.06);
  --topbar-h: 72px;
  --reader-font-size: 18px;
}
* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 217, 155, 0.34), transparent 28rem),
    linear-gradient(180deg, #fbf5eb 0%, var(--bg) 42%, #efe7da 100%);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body.scroll-locked {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
.topbar {
  position: fixed;
  z-index: 30;
  top: 0; left: 0; right: 0;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  background: rgba(255, 253, 248, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}
.icon-button, .close-button, .font-controls button, .chapter-actions button, .selection-toolbar, .comment-panel-actions button {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.7);
  border-radius: 999px;
  min-height: 40px;
  cursor: pointer;
}
.icon-button { width: 42px; display: inline-flex; flex-direction: column; justify-content: center; align-items: center; gap: 5px; }
.icon-button span { width: 18px; height: 2px; border-radius: 99px; background: var(--ink); }
.brand-block { min-width: 0; }
.book-title { font-weight: 800; letter-spacing: -0.04em; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chapter-kicker { margin-top: 4px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-controls { display: inline-flex; gap: 5px; align-items: center; }
.font-controls button { min-height: 34px; padding: 0 9px; font-size: 12px; font-weight: 700; }
.font-controls #fontReset { display: none; }
.overlay { position: fixed; inset: 0; z-index: 35; background: rgba(25, 20, 16, 0.28); backdrop-filter: blur(2px); }
.drawer {
  position: fixed;
  z-index: 40;
  left: 0; right: 0; bottom: 0;
  max-height: min(78vh, 680px);
  transform: translateY(102%);
  transition: transform .24s ease;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  background: rgba(255, 253, 248, 0.98);
  border-radius: 24px 24px 0 0;
  border: 1px solid var(--line);
  box-shadow: 0 -20px 60px rgba(45, 31, 18, 0.18);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.drawer.open { transform: translateY(0); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.eyebrow { margin: 0 0 4px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.drawer h2 { margin: 0; font-size: 24px; letter-spacing: -.04em; }
.drawer-desc { margin: 10px 0 16px; color: var(--muted); line-height: 1.6; }
.close-button { width: 40px; font-size: 26px; line-height: 1; }
.toc { display: grid; gap: 10px; }
.toc button {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fffaf1;
  padding: 13px 14px;
  cursor: pointer;
}
.toc button.active { border-color: rgba(138,75,34,.42); background: var(--accent-soft); box-shadow: inset 4px 0 0 var(--accent); }
.toc .toc-number { display: block; color: var(--accent); font-size: 12px; font-weight: 800; margin-bottom: 4px; }
.toc .toc-title { display: block; font-weight: 750; }
.reader-layout { width: min(100%, 980px); margin: 0 auto; padding: calc(var(--topbar-h) + env(safe-area-inset-top) + 16px) 14px 34px; }
.hero-card, .chapter-card {
  background: rgba(255,253,248,.88);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.hero-card { padding: 22px 18px; margin-bottom: 14px; }
.pill { display: inline-flex; padding: 6px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 12px; font-weight: 800; }
.hero-card h1 { margin: 12px 0 8px; font-size: clamp(30px, 9vw, 54px); line-height: .98; letter-spacing: -.08em; }
.hero-card p { margin: 0; color: var(--muted); line-height: 1.7; font-size: 15px; }
.chapter-card { padding: 22px 18px 24px; }
.chapter-meta { color: var(--accent); font-size: 13px; font-weight: 800; letter-spacing: .08em; }
.chapter-title { margin: 8px 0 20px; font-size: clamp(25px, 7vw, 40px); line-height: 1.18; letter-spacing: -.05em; }
.reader-content {
  font-family: "Noto Serif SC", "Songti SC", STSong, serif;
  font-size: var(--reader-font-size);
  line-height: 1.95;
  letter-spacing: .015em;
  color: #2f2922;
  overflow-wrap: anywhere;
}
.reader-content p { margin: 0 0 1.12em; text-align: justify; }
.reader-content .system-line { color: #5c452b; font-weight: 700; background: rgba(138,75,34,.08); padding: 0 4px; border-radius: 6px; }
.comment-highlight {
  color: inherit;
  background: linear-gradient(180deg, transparent 46%, rgba(255, 199, 87, .62) 46%);
  border-radius: 5px;
  cursor: pointer;
  padding: 0 2px;
}
.selection-toolbar {
  position: absolute;
  z-index: 55;
  transform: translateX(-50%);
  padding: 0 16px;
  min-height: 38px;
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 12px 32px rgba(66, 45, 23, .22);
  font-weight: 800;
}
.comment-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(25, 20, 16, .30); backdrop-filter: blur(3px); }
.comment-panel, .comment-thread-panel {
  position: fixed;
  z-index: 65;
  left: 14px;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  max-height: min(78vh, 560px);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 18px;
  background: rgba(255,253,248,.98);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 24px 80px rgba(45, 31, 18, .26);
}
.comment-thread-panel {
  display: grid;
  gap: 14px;
}
.comment-thread-panel[hidden] { display: none; }
.comment-thread-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.comment-thread-head h3 { margin: 0; font-size: 22px; letter-spacing: -.04em; }
.comment-thread-list { display: grid; gap: 12px; }
.thread-comment-item blockquote { display: none; }
.comment-panel blockquote, .comment-thread-panel blockquote, .comment-item blockquote {
  margin: 10px 0 14px;
  padding: 12px 14px;
  color: #5d4b38;
  background: #fff5e4;
  border-left: 4px solid #d4933f;
  border-radius: 14px;
  line-height: 1.65;
}
.comment-panel label { display: grid; gap: 8px; margin-top: 12px; color: var(--muted); font-size: 13px; font-weight: 800; }
.comment-panel textarea, .comment-panel input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 13px;
  background: #fffdf8;
  color: var(--ink);
  font: inherit;
  line-height: 1.6;
}
.comment-panel textarea { resize: vertical; }
.comment-panel-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.comment-panel-actions .primary { background: var(--accent); border-color: var(--accent); color: white; font-weight: 800; }
.comments-section {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.comments-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.comments-head h3 { margin: 0; font-size: 22px; letter-spacing: -.04em; }
.comments-head span { display: inline-flex; padding: 5px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 12px; font-weight: 800; }
.comments-hint, .comments-status, .empty-comments { color: var(--muted); line-height: 1.7; font-size: 14px; }
.comments-list { display: grid; gap: 12px; margin-top: 14px; }
.comment-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,250,241,.72);
  transition: box-shadow .2s ease, transform .2s ease;
}
.comment-item p { margin: 0; line-height: 1.75; }
.comment-item footer { margin-top: 10px; color: var(--muted); font-size: 12px; }
.comment-revision {
  margin-top: 12px;
  border: 1px solid rgba(138,75,34,.16);
  border-radius: 14px;
  background: rgba(255,253,248,.72);
  overflow: hidden;
}
.comment-revision summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  color: #6a5039;
  font-size: 13px;
  font-weight: 800;
  list-style: none;
}
.comment-revision summary::-webkit-details-marker { display: none; }
.comment-revision summary::before {
  content: '›';
  margin-right: 2px;
  transform: rotate(0deg);
  transition: transform .18s ease;
}
.comment-revision[open] summary::before { transform: rotate(90deg); }
.comment-revision summary span:first-child { margin-right: auto; }
.revision-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}
.revision-status-pending { background: #f3eee3; color: #806b4f; }
.revision-status-modified { background: #e8f6ec; color: #24723a; }
.revision-status-skipped { background: #fff0ed; color: #a04432; }
.comment-revision dl {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 10px 12px;
  margin: 0;
  padding: 0 12px 12px;
  border-top: 1px solid rgba(138,75,34,.12);
}
.comment-revision dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.comment-revision dd {
  margin: 0;
  color: #3d3329;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.comment-item.pulse { transform: translateY(-2px); box-shadow: 0 12px 36px rgba(138,75,34,.20); border-color: rgba(138,75,34,.45); }
.chapter-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-top: 28px; position: sticky; bottom: 10px; }
.chapter-actions button { padding: 0 10px; font-weight: 800; background: rgba(255,253,248,.9); box-shadow: 0 8px 24px rgba(68, 45, 20, .08); }
.chapter-actions .primary { background: var(--accent); border-color: var(--accent); color: white; }
.chapter-actions button:disabled { opacity: .42; cursor: not-allowed; }
@media (max-width: 390px) {
  .topbar { grid-template-columns: 40px minmax(0, 1fr) auto; gap: 6px; }
  .font-controls button { padding: 0 7px; font-size: 11px; }
  .chapter-card, .hero-card { border-radius: 20px; }
}
@media (min-width: 760px) {
  :root { --topbar-h: 76px; }
  .app-shell { display: grid; grid-template-columns: 300px minmax(0, 1fr); }
  .topbar { grid-template-columns: minmax(0, 1fr) auto; left: 300px; padding-left: 24px; padding-right: 24px; }
  .menu-toggle { display: none; }
  .font-controls #fontReset { display: inline-block; }
  .drawer { transform: none; top: 0; right: auto; bottom: 0; width: 300px; max-height: none; border-radius: 0; padding: 28px 18px; box-shadow: none; background: rgba(255,253,248,.82); backdrop-filter: blur(18px); }
  .close-button, .overlay { display: none !important; }
  .reader-layout { grid-column: 2; padding: 108px 28px 50px; width: min(100%, 930px); }
  .hero-card { padding: 30px; margin-bottom: 18px; }
  .chapter-card { padding: 40px clamp(34px, 6vw, 72px); }
  .comment-panel, .comment-thread-panel { left: 50%; right: auto; bottom: auto; top: 50%; width: min(620px, calc(100vw - 48px)); transform: translate(-50%, -50%); }
  .chapter-actions { position: static; }
}
@media (min-width: 1120px) {
  .app-shell { grid-template-columns: 340px minmax(0, 1fr); }
  .topbar { left: 340px; }
  .drawer { width: 340px; padding: 34px 24px; }
}

/* 新旧对比页面样式 */
.comparison-intro {
  margin-bottom: 24px;
  line-height: 1.7;
}
.comparison-intro ol {
  padding-left: 1.4em;
}
.comparison-intro li {
  margin-bottom: 4px;
}
.comparison-table {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 0;
}
.comparison-col {
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}
.comparison-col h4 {
  margin: 0;
  padding: 12px 14px;
  background: rgba(255, 253, 248, 0.96);
  border-bottom: 1px solid var(--line);
}
.comparison-original {
  background: #fff8f8;
}
.comparison-optimized {
  background: #f8fff9;
}
.comparison-content {
  padding: 12px;
  max-height: 70vh;
  overflow-y: auto;
}
.comparison-content-full {
  max-height: none;
  overflow-y: visible;
}
.comparison-paragraph {
  padding: 8px 10px;
  border-bottom: 1px dashed rgba(56, 45, 31, 0.08);
  line-height: 1.7;
}
.comparison-paragraph:last-child {
  border-bottom: none;
}
.comparison-footer {
  padding: 16px;
  background: var(--accent-soft);
  border-radius: 16px;
  line-height: 1.7;
}
.comparison-footer code {
  background: rgba(255, 255, 255, 0.6);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.9em;
}
.error-state {
  padding: 24px;
  background: #fff0ed;
  border-radius: 16px;
  color: #a04432;
}
.error-state pre {
  background: rgba(255, 255, 255, 0.6);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
}

@media (max-width: 760px) {
  .comparison-table {
    grid-template-columns: 1fr;
  }
  .comparison-content {
    max-height: 40vh;
  }
}

/* 站点底部备案信息 */
.site-footer {
  padding: 18px 16px 26px;
  text-align: center;
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.6);
}
.site-footer a {
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  transition: color 0.15s ease;
}
.site-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}
