*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--palette-bg);
  color: var(--text);
  font-family: var(--ui-font);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  transition: background-color .22s var(--ease), color .22s var(--ease);
}

button, input {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

button:active {
  transform: scale(.98);
}

button:focus-visible, a:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--p1) 55%, transparent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* 整体骨架 */
.shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* 极简顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 54px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--palette-bg);
  border-bottom: 1px solid var(--line);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: var(--muted);
  flex: none;
  transition: background .18s var(--ease), color .18s var(--ease);
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* 三段式纯色切换 */
.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface-2);
  gap: 2px;
  flex: none;
}

.seg button {
  padding: 6px 14px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  transition: background .18s var(--ease), color .18s var(--ease), box-shadow .18s var(--ease);
}

.seg button:hover {
  color: var(--text);
}

.seg button.on {
  background: var(--surface);
  color: var(--brand);
  box-shadow: var(--shadow-sm);
}

.spacer {
  flex: 1;
}

/* 极简即时搜索 */
.search-box {
  position: relative;
  flex: 0 1 240px;
}

.search-box svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--faint);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 33px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 14px;
  outline: none;
  transition: border-color .18s var(--ease);
}

.search-box input:focus {
  border-color: color-mix(in srgb, var(--p1) 55%, var(--line));
}

.search-results {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: min(440px, calc(100vw - 24px));
  max-height: 64vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 6px;
  display: none;
  z-index: 60;
}

.search-results.open {
  display: block;
}

.sr-item {
  width: 100%;
  display: block;
  text-align: left;
  padding: 9px 12px;
  border-radius: 11px;
  transition: background .15s var(--ease);
}

.sr-item:hover {
  background: var(--wash-1);
}

.sr-meta {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--brand);
  margin-bottom: 2px;
}

.sr-text {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text);
}

.sr-empty {
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

mark.hl {
  background: var(--wash-1);
  color: var(--brand);
  border-radius: 4px;
  padding: 0 2px;
}

/* 主体两栏工作区 */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* 左侧极简目录 */
.sidebar {
  width: 264px;
  flex: none;
  background: var(--well);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 54px;
  height: calc(100dvh - 54px);
  overflow-y: auto;
  padding: 14px 10px 48px;
  overscroll-behavior: contain;
  transition: margin-left .24s var(--ease), transform .24s var(--ease);
}

.shell.pure .sidebar {
  margin-left: -264px;
}

.vol-label {
  padding: 14px 12px 6px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--muted);
}

.vol-label:first-child {
  padding-top: 4px;
}

.chap-row {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  text-align: left;
  font-size: 13.5px;
  color: var(--text);
  transition: background .16s var(--ease), color .16s var(--ease);
}

.chap-row:hover {
  background: var(--surface-2);
}

.chap-row.on {
  background: var(--wash-1);
  color: var(--brand);
  font-weight: 600;
}

.chap-row.on::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--p1);
}

.chap-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chap-num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
  flex: none;
}

.chap-row.on .chap-num {
  color: var(--brand);
}

/* 阅读画布 */
.stage {
  flex: 1;
  min-width: 0;
  padding: 28px 32px 88px;
}

.sheet {
  --c: var(--p1);
  max-width: 1220px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 36px 44px 44px;
  transition: max-width .24s var(--ease);
}

.sheet.single {
  max-width: 780px;
  padding: 40px 50px 48px;
}

.sheet[data-tone="p1"] { --c: var(--p1); }
.sheet[data-tone="p2"] { --c: var(--p2); }
.sheet[data-tone="p3"] { --c: var(--p3); }

/* 章头艺术版式（纯色柔线，无多余装饰） */
.sheet-head {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding-bottom: 14px;
  margin-bottom: 26px;
  border-bottom: 2px solid color-mix(in srgb, var(--c) 38%, var(--line));
}

.sheet-num {
  font-family: var(--font-display);
  font-size: 46px;
  line-height: .88;
  font-weight: 400;
  color: color-mix(in srgb, var(--c) 76%, var(--brand));
  font-variant-numeric: lining-nums;
  flex: none;
}

.sheet-title {
  margin: 0;
  font-family: var(--read-font);
  font-size: 25px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text-head);
}

/* 舒展双栏 / 单栏阅读流 */
.cols {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 48px;
  align-items: start;
}

.sheet.single .cols {
  grid-template-columns: 1fr;
}

.entry {
  padding: 18px 0 20px;
  border-top: 1px solid var(--line);
  font-family: var(--read-font);
  font-size: calc(var(--base-size) * var(--font-scale));
  line-height: var(--read-lh);
  color: var(--text);
  break-inside: avoid;
  scroll-margin-top: 76px;
  border-radius: 6px;
  transition: background-color .35s var(--ease);
}

.cols .entry:first-child,
.sheet:not(.single) .cols .entry:nth-child(2) {
  border-top: 0;
  padding-top: 0;
}

.entry.flash {
  background: var(--wash-1);
}

.entry p,
.p-body {
  margin: 0 0 10px;
  text-align: justify;
}

.entry p:last-child,
.p-body:last-child {
  margin-bottom: 0;
}

.entry strong {
  font-weight: 600;
  color: var(--text-strong);
}

/* 原文引语（纯淡色平涂 + 细竖线） */
.p-quote {
  margin: 8px 0 12px;
  padding: 11px 15px;
  border-radius: 12px;
  background: var(--wash-2);
  border-left: 3px solid var(--p2);
  font-family: var(--font-serif);
  font-size: 0.96em;
  line-height: 1.82;
  color: var(--text);
}

/* 亲笔批注（整段淡粉平涂 + 左竖线，无角标无印章） */
.p-note {
  margin: 10px 0 12px;
  padding: 11px 15px;
  border-radius: 12px;
  background: var(--wash-1);
  border-left: 3px solid var(--p1);
  color: var(--text-strong);
}

.p-bullet {
  margin: 6px 0;
  padding-left: 16px;
  position: relative;
}

.b-mark {
  position: absolute;
  left: 3px;
  color: var(--brand);
  font-weight: 600;
}

.p-cite {
  margin-top: 8px;
  text-align: right;
  font-size: 0.84em;
  color: var(--muted);
}

/* 长文正文排版 */
.essay-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.essay-toc a {
  text-decoration: none;
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 13px;
  background: var(--wash-1);
  color: var(--brand);
  transition: background .16s var(--ease);
}

.essay-toc a:hover {
  background: var(--brand-wash);
}

.essay-prose {
  font-family: var(--read-font);
  font-size: calc(var(--base-size) * var(--font-scale));
  line-height: var(--read-lh);
  color: var(--text);
}

.essay-prose h1,
.essay-prose h2,
.essay-prose h3 {
  font-family: var(--read-font);
  font-weight: 600;
  color: var(--text-head);
  margin: 1.5em 0 0.6em;
  line-height: 1.4;
  scroll-margin-top: 76px;
}

.essay-prose h2 {
  font-size: 1.24em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.essay-prose h3 {
  font-size: 1.08em;
  color: var(--brand);
}

.essay-prose blockquote {
  margin: 12px 0;
  padding: 11px 15px;
  border-radius: 12px;
  background: var(--wash-1);
  border-left: 3px solid var(--p1);
}

.essay-prose hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 24px 0;
}

.essay-prose ul,
.essay-prose ol {
  padding-left: 22px;
}

.essay-prose li {
  margin: 5px 0;
}

/* 章末极简翻页 */
.pager {
  max-width: 1220px;
  margin: 18px auto 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.pager.single {
  max-width: 780px;
}

.pager-btn {
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  background: var(--wash-1);
  color: var(--brand);
  transition: background .16s var(--ease);
}

.pager-btn:hover {
  background: var(--brand-wash);
}

.pager-btn:disabled {
  opacity: .32;
  cursor: default;
}

/* 外观设置浮层（零说明文案） */
.popover {
  position: fixed;
  top: 62px;
  right: 18px;
  width: 296px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 16px;
  z-index: 70;
  display: none;
}

.popover.open {
  display: block;
}

.pop-group {
  margin-bottom: 14px;
}

.pop-group:last-child {
  margin-bottom: 0;
}

.pop-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: transform .15s var(--ease);
}

.swatch:hover {
  transform: scale(1.1);
}

.swatch.on {
  border-color: var(--text);
}

.opt-row {
  display: flex;
  gap: 6px;
}

.opt-btn {
  flex: 1;
  padding: 7px 6px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text);
  text-align: center;
}

.opt-btn.on {
  background: var(--wash-1);
  color: var(--brand);
  font-weight: 600;
}

/* 移动端抽屉遮罩 */
.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 24, .34);
  z-index: 45;
}

.scrim.open {
  display: block;
}

@media (max-width: 900px) {
  .cols {
    grid-template-columns: 1fr;
  }
  .cols .entry:nth-child(2) {
    border-top: 1px solid var(--line);
    padding-top: 18px;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100dvh;
    z-index: 50;
    transform: translateX(-100%);
    margin-left: 0 !important;
    box-shadow: var(--shadow-md);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .stage {
    padding: 14px 12px 56px;
  }
  .sheet,
  .sheet.single {
    padding: 22px 18px 28px;
  }
  .sheet-num {
    font-size: 36px;
  }
  .sheet-title {
    font-size: 21px;
  }
}

@media (max-width: 600px) {
  .topbar {
    padding: 0 12px;
    gap: 8px;
  }
  .seg button {
    padding: 6px 10px;
    font-size: 13px;
  }
  .search-box {
    flex: 1 1 auto;
    min-width: 0;
  }
  .search-box input {
    font-size: 16px;
  }
  .popover {
    left: 12px;
    right: 12px;
    width: auto;
  }
}

@media print {
  .topbar, .sidebar, .pager, .popover, .scrim {
    display: none !important;
  }
  .stage {
    padding: 0;
  }
  .sheet {
    border: 0;
    box-shadow: none;
    max-width: 100%;
  }
}
