:root {
  --bg: #fbfaf6;
  --bg-soft: #f3f1e9;
  --ink: #1a1a1a;
  --ink-soft: #4a4a4a;
  --rule: #d9d4c3;
  --accent: #8a6a3b;
  --accent-soft: #c7a76a;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", serif;
  --sans: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Helvetica Neue", system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg: #161413;
  --bg-soft: #1f1c1a;
  --ink: #e8e3d6;
  --ink-soft: #a8a194;
  --rule: #3a3530;
  --accent: #d3b07a;
  --accent-soft: #8a6a3b;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: var(--reader-size, 18px);
  line-height: 1.85;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  background: rgba(251, 250, 246, 0.92);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
}

[data-theme="dark"] .topbar {
  background: rgba(22, 20, 19, 0.92);
}

.topbar .title {
  flex: 1;
  font-size: 14px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .title a {
  color: inherit;
  text-decoration: none;
}

.topbar .title .sep {
  opacity: 0.65;
}

.topbar button {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 13px;
}

.topbar button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.topbar .group {
  display: inline-flex;
  gap: 4px;
}

.progress {
  height: 3px;
  background: var(--bg-soft);
  position: sticky;
  top: 49px;
  z-index: 49;
}

.progress .bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.15s;
}

.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 80;
}

.drawer-mask.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(340px, 86vw);
  background: var(--bg);
  border-right: 1px solid var(--rule);
  transform: translateX(-100%);
  transition: transform 0.25s;
  z-index: 90;
  overflow-y: auto;
  padding: 22px 22px 60px;
  font-family: var(--sans);
  box-shadow: var(--shadow);
}

.drawer.open {
  transform: translateX(0);
}

.drawer h3 {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 500;
  letter-spacing: 0.08em;
}

.drawer .book {
  font-family: var(--serif);
  font-size: 20px;
  margin: 0 0 18px;
}

.drawer .book a {
  text-decoration: none;
}

.drawer .group-label {
  margin: 18px 0 6px;
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 0.1em;
}

.drawer ol {
  list-style: none;
  padding: 0;
  margin: 0;
}

.drawer ol li {
  margin: 2px 0;
}

.drawer ol a,
.drawer .placeholder {
  display: block;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
}

.drawer .placeholder {
  color: var(--ink-soft);
  opacity: 0.7;
}

.drawer ol a:hover {
  background: var(--bg-soft);
  color: var(--accent);
}

.drawer ol a.current {
  background: var(--bg-soft);
  color: var(--accent);
  font-weight: 600;
}

.drawer details {
  margin: 2px 0;
}

.drawer details > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--ink);
  user-select: none;
}

.drawer details > summary::-webkit-details-marker {
  display: none;
}

.drawer details > summary::before {
  content: "›";
  display: inline-block;
  width: 12px;
  color: var(--ink-soft);
  transition: transform 0.15s;
  font-size: 14px;
  transform: translateY(-1px);
}

.drawer details[open] > summary::before {
  transform: rotate(90deg);
}

.drawer details > summary:hover {
  background: var(--bg-soft);
  color: var(--accent);
}

.drawer details.current > summary {
  background: var(--bg-soft);
  color: var(--accent);
  font-weight: 600;
}

.drawer details > summary .summary-link {
  flex: 1;
  color: inherit;
  text-decoration: none;
}

.drawer ol.sub {
  padding: 2px 0 6px 22px;
  border-left: 1px dashed var(--rule);
  margin-left: 14px;
}

.drawer ol.sub a {
  padding: 5px 10px;
  font-size: 13px;
  color: var(--ink-soft);
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.drawer ol.sub a .sub-num {
  color: var(--accent);
  font-family: var(--sans);
  font-size: 11px;
  min-width: 2.8em;
  letter-spacing: 0.03em;
}

.drawer ol.sub a:hover,
.drawer ol.sub a.current {
  color: var(--accent);
  background: var(--bg-soft);
}

.reader {
  max-width: 36em;
  margin: 0 auto;
  padding: 48px 24px 120px;
}

.reader .eyebrow {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.25em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 12px;
}

.reader h1 {
  font-size: 1.9em;
  line-height: 1.35;
  margin: 0 0 8px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.reader h2 {
  font-size: 1.25em;
  line-height: 1.4;
  margin: 2em 0 0.8em;
  font-family: var(--sans);
  font-weight: 600;
  color: var(--ink);
}

.reader .section-cluster {
  margin: 1.4em 0 1.8em;
  padding: 0.8em 1em;
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 10px;
}

.reader .section-cluster h2 {
  margin: 0;
  padding: 0.35em 0;
  font-size: 1.05em;
  font-weight: 500;
  border-bottom: 1px dashed var(--rule);
}

.reader .section-cluster h2:last-child {
  border-bottom: 0;
}

.reader .lead {
  color: var(--ink-soft);
  margin: 0 0 36px;
  border-left: 3px solid var(--accent-soft);
  padding-left: 14px;
}

.reader h3 {
  margin: 2.4em 0 0.8em;
  font-size: 1.15em;
  line-height: 1.5;
  font-family: var(--sans);
  font-weight: 600;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.35em;
}

.reader h3 .sec-num {
  display: inline-block;
  color: var(--accent);
  margin-right: 0.5em;
  font-feature-settings: "tnum";
}

.reader p {
  margin: 0 0 1.1em;
  text-indent: 2em;
  text-align: justify;
  hyphens: auto;
}

.reader p.no-indent,
.reader .verse p {
  text-indent: 0;
}

.page-marker {
  margin: 26px 0 18px;
  padding-top: 20px;
  border-top: 1px dashed var(--rule);
  color: var(--ink-soft);
  font-size: 0.88rem;
  letter-spacing: 0.04em;
  font-family: var(--sans);
}

.verse {
  margin: 18px 0;
  padding: 16px 20px;
  background: rgba(138, 106, 59, 0.05);
  border: 1px solid var(--rule);
  border-radius: 10px;
}

.reader blockquote {
  margin: 1.8em auto;
  padding: 1em 1.4em;
  max-width: 28em;
  border: 1px solid var(--rule);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--ink-soft);
  font-style: italic;
  text-align: center;
  box-shadow: var(--shadow);
}

.reader blockquote p {
  text-indent: 0;
  text-align: center;
  margin: 0.35em 0;
}

.reader blockquote p:first-child {
  margin-top: 0;
}

.reader blockquote p:last-child {
  margin-bottom: 0;
}

.reader hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 2.4em 0;
}

.reader a {
  color: var(--accent);
}

.nav-foot {
  max-width: 36em;
  margin: 0 auto 80px;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  font-family: var(--sans);
}

.nav-foot a,
.nav-foot span {
  display: block;
  padding: 14px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  text-decoration: none;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
  background: var(--bg-soft);
}

.nav-foot a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.nav-foot .label {
  display: block;
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}

.nav-foot .center {
  text-align: center;
}

.nav-foot .right {
  text-align: right;
}

.nav-foot .disabled {
  opacity: 0.4;
}

.home {
  max-width: 42em;
  margin: 0 auto;
  padding: 80px 24px 120px;
}

.home .cover {
  text-align: center;
  margin-bottom: 56px;
  padding: 48px 24px;
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 10px;
}

.home .cover .sub {
  font-family: var(--sans);
  letter-spacing: 0.25em;
  color: var(--accent);
  font-size: 12px;
}

.home .cover h1 {
  font-size: 2.6em;
  margin: 18px 0 8px;
  line-height: 1.25;
}

.home .cover .en {
  color: var(--ink-soft);
  font-style: italic;
}

.home .cover .author {
  margin-top: 18px;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink-soft);
}

.home .cta {
  display: inline-block;
  margin-top: 28px;
  padding: 12px 28px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  text-decoration: none;
  font-family: var(--sans);
  font-size: 14px;
  letter-spacing: 0.1em;
}

.home .cta:hover {
  background: var(--ink);
}

.home h2 {
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.2em;
  color: var(--ink-soft);
  margin: 48px 0 14px;
  font-weight: 500;
}

.home .toc {
  list-style: none;
  padding: 0;
  margin: 0;
}

.home .toc li {
  border-bottom: 1px dashed var(--rule);
}

.home .toc a {
  display: flex;
  gap: 16px;
  align-items: baseline;
  padding: 16px 6px;
  text-decoration: none;
  color: var(--ink);
}

.home .toc a:hover {
  color: var(--accent);
  background: var(--bg-soft);
}

.home .toc .num {
  font-family: var(--sans);
  color: var(--accent);
  font-size: 13px;
  min-width: 3.2em;
  letter-spacing: 0.05em;
}

.home .toc .t {
  flex: 1;
  font-size: 1.05em;
}

.home .toc .meta {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-soft);
}

.home .stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.home .chip {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(138, 106, 59, 0.08);
  border: 1px solid rgba(138, 106, 59, 0.18);
  font-family: var(--sans);
  font-size: 13px;
}

.home .note-box {
  margin-top: 18px;
  padding: 18px 20px;
  background: rgba(138, 106, 59, 0.05);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
}

.home .note-box ul {
  margin: 10px 0 0 18px;
  padding: 0;
}

.home .note-box li {
  margin: 4px 0;
}

.home p {
  text-align: justify;
}

.home p.no-indent {
  text-indent: 0;
}

.chapter-grid {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.chapter-card a {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 14px 16px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  text-decoration: none;
  color: var(--ink);
  background: var(--bg-soft);
  transition: border-color 0.15s, color 0.15s;
}

.chapter-card a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chapter-card .ch-num {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.chapter-card .ch-title {
  flex: 1;
  font-size: 1.05em;
}

@media (max-width: 720px) {
  body {
    font-size: var(--reader-size, 17px);
  }

  .topbar {
    padding: 8px 12px;
    gap: 8px;
  }

  .topbar button {
    padding: 5px 8px;
    font-size: 12px;
  }

  .topbar .title {
    font-size: 12px;
  }

  .progress {
    top: 41px;
  }

  .reader {
    padding: 28px 18px 60px;
  }

  .reader h1 {
    font-size: 1.5em;
    line-height: 1.3;
  }

  .reader h3 {
    font-size: 1.05em;
    margin: 1.8em 0 0.6em;
  }

  .reader p {
    text-indent: 2em;
  }

  .home {
    padding: 40px 16px 60px;
  }

  .home .cover {
    padding: 32px 16px;
    margin-bottom: 36px;
  }

  .home .cover h1 {
    font-size: 1.8em;
  }

  .home .cover .en {
    font-size: 0.9em;
  }

  .home .toc a {
    padding: 14px 4px;
    gap: 10px;
  }

  .home .toc .num {
    min-width: 2.8em;
    font-size: 12px;
  }

  .home .toc .t {
    font-size: 1em;
  }

  .nav-foot {
    grid-template-columns: 1fr;
    gap: 8px;
    margin: 0 auto 60px;
  }

  .nav-foot a,
  .nav-foot span {
    padding: 12px 14px;
  }

  .nav-foot .right {
    text-align: left;
  }

  .drawer {
    width: min(320px, 88vw);
    padding: 18px 16px 60px;
  }
}

@media (max-width: 380px) {
  .topbar .title .book-title {
    display: none;
  }

  .topbar button {
    padding: 4px 6px;
    font-size: 11px;
  }
}

@media (hover: none) {
  .topbar button:hover,
  .drawer ol a:hover,
  .nav-foot a:hover,
  .home .toc a:hover,
  .home .cta:hover {
    color: inherit;
    border-color: var(--rule);
    background: inherit;
  }

  .home .cta:hover {
    color: #fff;
    background: var(--accent);
  }
}
