@font-face {
  font-family: "Shelf Serif";
  src: url("./assets/shelf-serif.woff2") format("woff2");
  font-display: swap;
  font-weight: 700;
}

:root {
  --bg: #f6f3eb;
  --surface: #fffdf7;
  --surface-alt: #f3eee4;
  --ink: #292923;
  --muted: #666356;
  --line: #e3dace;
  --accent: #88362c;
  --accent-soft: #f4e5df;
  --shadow: #49342112;
  --serif: "Songti SC", "Noto Serif CJK SC", "Noto Serif SC", SimSun, serif;
  --display: "Shelf Serif", var(--serif);
  --ui: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  color-scheme: light;
}
[data-theme="light"] {
  --bg: #f6f7f7;
  --surface: #fff;
  --surface-alt: #eff1f1;
  --ink: #222625;
  --muted: #5c6462;
  --line: #dce1df;
  --accent: #88362c;
  --accent-soft: #f5e6e1;
}
[data-theme="night"] {
  --bg: #1d211e;
  --surface: #272b26;
  --surface-alt: #30332c;
  --ink: #f2ece1;
  --muted: #bdb7a9;
  --line: #43483f;
  --accent: #e2a28a;
  --accent-soft: #4c342e;
  --shadow: #080e0840;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: 88px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 1rem/1.6 var(--ui); -webkit-font-smoothing: antialiased; }
body:has(dialog[open]) { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: .47; cursor: default; }
a { color: inherit; text-decoration: none; }
p, h1, h2, h3 { margin: 0; }
svg { display: block; flex: none; }
button:focus-visible, a:focus-visible, select:focus-visible, summary:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; white-space: nowrap; clip-path: inset(50%); }
.skip { position: fixed; z-index: 9; left: 12px; top: 10px; transform: translateY(-160%); border-radius: 6px; background: var(--surface); padding: 8px 13px; }
.skip:focus { transform: translateY(0); }
.shell { width: min(100% - 74px, 1230px); margin-inline: auto; }

.masthead { background: var(--surface); border-bottom: 1px solid var(--line); }
.masthead-inner { min-height: 72px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 24px; }
.brand { display: inline-flex; align-items: center; gap: 11px; justify-self: start; white-space: nowrap; line-height: 1.18; }
.brand img { border-radius: 9px; }
.brand strong, .brand small { display: block; }
.brand strong { font: 700 1.21rem/1.2 var(--display); letter-spacing: .045em; }
.brand small { margin-top: 4px; color: var(--muted); font-size: .73rem; letter-spacing: .14em; }
.nav { display: flex; gap: 28px; align-items: stretch; min-height: 72px; font-size: .91rem; font-weight: 650; }
.nav a, .nav button { display: inline-grid; place-items: center; padding: 0 3px; background: none; border: 0; color: var(--muted); position: relative; white-space: nowrap; }
.nav [aria-current], .nav a:hover, .nav button:hover { color: var(--accent); }
.nav [aria-current]::after { content: ""; position: absolute; inset: auto 0 0; height: 2px; background: var(--accent); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 13px; min-height: 41px; border: 1px solid transparent; border-radius: 8px; font-size: .88rem; line-height: 1.3; font-weight: 650; white-space: nowrap; }
.quiet { background: var(--surface); border-color: var(--line); }
.quiet:hover { background: var(--surface-alt); }
.masthead .quiet { justify-self: end; }
#bookmark-count { font-size: .78rem; font-weight: 800; color: var(--accent); }
.primary { background: var(--accent); color: var(--surface); border-color: var(--accent); }
.primary:hover { filter: brightness(.91); }

.library-page { padding-top: 28px; }
.hero { position: relative; isolation: isolate; display: flex; align-items: center; min-height: 376px; overflow: hidden; border-radius: 19px; background: #282821; color: #fff9e9; }
.hero::before, .hero::after { content: ""; position: absolute; inset: 0; z-index: -1; }
.hero::before { left: 30%; background: url("./assets/reading-room.webp") center 52% / cover no-repeat; }
.hero::after { background: linear-gradient(90deg,#282821 0%,#282821 25%,#282821ed 34%,#28282180 51%,transparent 70%); }
.hero-body { padding: 42px clamp(27px, 5.4vw, 85px); z-index: 0; }
.hero-label { color: #e5c591; font-size: .87rem; font-weight: 700; letter-spacing: .18em; }
.hero h1 { font: 700 clamp(2.55rem, 5.6vw, 4.85rem)/1.08 var(--display); letter-spacing: .065em; margin: 12px 0 16px; }
.hero-description { color: #eee5d5; font-size: 1.06rem; line-height: 1.8; }
.hero-search { display: flex; align-items: stretch; gap: 9px; margin-top: 24px; width: min(440px, 100%); background: #fffbf2; color: #292923; border: 1px solid #c7b7a4; min-height: 51px; border-radius: 8px; padding: 4px; }
.search-icon { display: grid; align-self: center; color: #665f52; padding-left: 8px; }
.hero-search input { flex: 1 1 0; min-width: 0; border: 0; background: transparent; outline: 0; padding-inline: 2px; }
.hero-search:focus-within { outline: 2px solid #e5c591; outline-offset: 3px; }
.hero-search button { background: #8f3c31; color: #fff9eb; border: 0; border-radius: 5px; padding: 0 21px; font-weight: 700; white-space: nowrap; }
.hero-search button:hover { background: #733126; }

.books-section, .featured-section { margin-top: 34px; }
.section-top { display: flex; align-items: end; justify-content: space-between; flex-wrap: wrap; gap: 11px; margin-bottom: 16px; }
.section-top h2, .featured-section h2 { font: 700 1.9rem/1.23 var(--display); letter-spacing: .045em; }
.section-top p { margin-top: 5px; color: var(--muted); font-size: .91rem; }
.books-grid, .featured-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.book-card { display: grid; grid-template-columns: 87px minmax(0, 1fr); gap: 14px; align-items: start; padding: 16px; min-height: 214px; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; box-shadow: 0 4px 14px var(--shadow); }
.book-cover { --cover: #4c4e3b; --cover-dark: #31362a; --cover-gold: #e3cb92; display: grid; place-items: center; isolation: isolate; background: repeating-linear-gradient(5deg, #ffffff08 0 1px, transparent 1px 5px), linear-gradient(91deg,var(--cover-dark) 0 7%,var(--cover) 8% 100%); border-radius: 3px 5px 5px 3px; color: var(--cover-gold); position: relative; width: 100%; aspect-ratio: 0.70; box-shadow: 2px 4px 7px #3727223b; }
[data-book="shanghan"] .book-cover { --cover: #723c32; --cover-dark: #482925; --cover-gold: #f0d29b; }
[data-book="bencao"] .book-cover { --cover: #344e55; --cover-dark: #253841; --cover-gold: #e5cea3; }
.book-cover::before { content: ""; position: absolute; inset: 7px 6px 7px 10px; border: 1px solid currentColor; opacity: .45; pointer-events: none; }
.book-cover::after { content: ""; position: absolute; inset: 13% auto 13% 3px; width: 4px; background: repeating-linear-gradient(0deg, transparent 0 19%, #eacba3c0 19% 21%, transparent 21% 31%); }
.book-cover-title { writing-mode: vertical-rl; font: 700 1.46rem/1.1 var(--display); padding: 4px 3px; letter-spacing: .035em; }
.book-info { min-width: 0; display: flex; flex-direction: column; align-items: start; }
.book-category { color: var(--accent); font-size: .81rem; letter-spacing: .04em; font-weight: 700; }
.book-info h3 { font: 700 1.34rem/1.2 var(--display); margin-top: 3px; letter-spacing: .035em; }
.book-meta { color: var(--muted); font-size: .82rem; margin-top: 6px; }
.book-intro { margin-top: 8px; line-height: 1.6; color: var(--muted); font-size: .89rem; }
.book-action { padding: 6px 0 0; margin-top: 7px; color: var(--accent); font-size: .91rem; font-weight: 750; }
.book-action:hover { text-decoration: underline; text-underline-offset: 5px; }
.book-scope { padding-top: 9px; border-top: 1px solid var(--line); grid-column: 1/-1; font-size: .81rem; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.book-scope span:first-child { color: var(--ink); }
.featured-grid { margin-top: 12px; }
.featured-chapter { display: grid; gap: 4px; border-left: 2px solid var(--accent); background: var(--surface-alt); padding: 11px 13px; border-radius: 0 8px 8px 0; }
.featured-chapter:hover { background: var(--accent-soft); }
.featured-chapter span { color: var(--muted); font-size: .84rem; }
.featured-chapter strong { font-weight: 700; }
.notice { margin-top: 13px; padding: 12px 14px; background: var(--surface-alt); border: 1px solid var(--line); border-radius: 8px; color: var(--muted); }

.reading-page { padding-top: 23px; }
.reader-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 0 0 14px; }
.breadcrumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: .91rem; color: var(--muted); }
.breadcrumbs a { color: var(--accent); }
.breadcrumbs a:hover { text-decoration: underline; }
.reader-actions { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
.reader-actions [aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
#toc-toggle, #reader-search { display: none; }
.reader-layout { display: grid; grid-template-columns: minmax(200px, 252px) minmax(0, 1fr); align-items: start; gap: 18px; }
.toc { position: sticky; top: 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); max-height: calc(100vh - 28px); overflow: auto; padding: 13px; scrollbar-color: var(--line) transparent; }
.toc-title { font-size: 1.07rem; font-weight: 750; letter-spacing: .04em; padding: 2px 3px 10px; }
.toc details { border-top: 1px solid var(--line); }
.toc summary { cursor: pointer; padding: 8px 3px; font-size: .9rem; font-weight: 700; }
.toc .toc-volume { margin-left: 9px; }
.toc .toc-volume summary { font-weight: 550; }
.toc ul { margin: 0 0 5px; padding: 0; list-style: none; }
.toc a { display: block; padding: 6px 8px; border-radius: 5px; color: var(--muted); font-size: .87rem; line-height: 1.55; }
.toc a:hover, .toc a[aria-current] { background: var(--accent-soft); color: var(--accent); }
.chapter { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 4px 19px var(--shadow); }
.chapter-inner { width: min(100% - 72px, 710px); margin-inline: auto; padding-block: 33px; }
.chapter-header { padding-bottom: 19px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.chapter-kicker { font-size: .9rem; color: var(--accent); font-weight: 700; }
.chapter h1 { font: 700 clamp(1.95rem, 4.1vw, 3.25rem)/1.23 var(--display); letter-spacing: .035em; margin-block: 7px 9px; }
.chapter-meta { color: var(--muted); font-size: .86rem; }
.chapter-meta a { color: var(--accent); }
.chapter-meta a:hover, .source-attribution a:hover { text-decoration: underline; }
.reading-text { font-size: var(--read-size, 1.28rem); font-family: var(--serif); line-height: var(--read-line-height, 1.9); overflow-wrap: anywhere; }
.reading-text .text-block { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 32px; column-gap: 6px; scroll-margin-top: 16px; border-radius: 5px; }
.reading-text .text-block + .text-block { margin-top: .63em; }
.reading-text .text-block[data-target] { background: var(--accent-soft); outline: 4px solid var(--accent-soft); }
.reading-text p { white-space: pre-line; }
.reading-text h2 { font: 700 1.16em/1.5 var(--serif); margin-block: .55em .12em; color: var(--accent); }
.reading-text mark { color: var(--ink); background: var(--accent-soft); border-bottom: 1px solid var(--accent); }
.paragraph-save { align-self: start; opacity: 0; margin-top: .25em; }
.text-block:hover .paragraph-save, .paragraph-save:focus-visible, .paragraph-save[aria-pressed="true"] { opacity: 1; }
.paragraph-save[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
.chapter-nav { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-top: 23px; padding-top: 18px; border-top: 1px solid var(--line); }
.chapter-nav .next { margin-left: auto; }
.source-attribution { margin-top: 23px; color: var(--muted); font-size: .85rem; }
.source-attribution a { color: var(--accent); }
.advisory { margin-top: 16px; padding: 12px 14px; background: var(--surface-alt); border-radius: 8px; color: var(--muted); font-size: .87rem; }
.footer { display: flex; align-items: center; justify-content: space-between; gap: 12px 23px; flex-wrap: wrap; border-top: 1px solid var(--line); padding: 16px 0 25px; margin-top: 34px; color: var(--muted); font-size: .83rem; }
.footer span, .footer a { white-space: nowrap; }
.footer a { color: var(--accent); }

dialog { color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 0; margin-block: auto; width: min(100% - 24px, 680px); max-height: min(87dvh, 760px); overscroll-behavior: contain; box-shadow: 0 25px 90px #16140c77; }
dialog::backdrop { background: #26221b78; }
.dialog-inner { padding: clamp(16px,4vw,26px); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 13px; }
.dialog-heading h2 { font: 700 1.57rem/1.25 var(--display); }
.dialog-heading form { margin: 0; }
.icon-button { width: 34px; height: 34px; display: inline-grid; place-items: center; color: var(--muted); background: transparent; border: 0; border-radius: 6px; padding: 0; }
.icon-button:hover { background: var(--surface-alt); color: var(--accent); }
.dialog-note { color: var(--muted); font-size: .89rem; margin-bottom: 11px; }
.search-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; align-items: center; }
.search-controls input, .select select { padding: 8px 10px; min-height: 41px; width: 100%; border: 1px solid var(--line); background: var(--surface-alt); border-radius: 7px; }
.select { position: relative; display: inline-flex; align-items: center; }
.select select { appearance: none; padding-right: 29px; }
.select svg { position: absolute; right: 9px; pointer-events: none; }
.result-status { margin-top: 13px; color: var(--muted); font-size: .88rem; }
.results, .bookmark-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; }
.results li, .bookmark-list li { border-bottom: 1px solid var(--line); }
.results a, .bookmark-list a { display: grid; gap: 4px; padding: 9px 4px; margin-bottom: 1px; border-radius: 6px; min-width: 0; }
.results a:hover, .bookmark-list a:hover { background: var(--surface-alt); }
.results a span, .bookmark-list a small { color: var(--muted); font-size: .87rem; overflow-wrap: anywhere; }
.results mark { background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.bookmark-list li { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 8px; }
.empty-state { color: var(--muted); background: var(--surface-alt); border-radius: 8px; padding: 16px; font-size: .92rem; }
.settings-block { display: grid; gap: 12px; }
.settings-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; border-bottom: 1px solid var(--line); padding: 7px 0 10px; }
.settings-row p { font-weight: 700; }
.setting-options { display: flex; flex-wrap: wrap; gap: 6px; }
.setting-options [aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.toast { position: fixed; z-index: 8; bottom: 20px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 24px); border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); box-shadow: 0 5px 24px var(--shadow); padding: 9px 14px; font-size: .9rem; }

@media (max-width: 1060px) {
  .shell { width: calc(100% - 48px); }
  .book-card { grid-template-columns: 65px minmax(0, 1fr); gap: 10px; padding: 12px; }
  .book-cover-title { font-size: 1.24rem; }
}
@media (max-width: 790px) {
  .shell { width: calc(100% - 32px); }
  .masthead-inner { grid-template-columns: 1fr auto; gap: 8px; min-height: 64px; }
  .nav { display: none; }
  .library-page { padding-top: 15px; }
  .hero { min-height: 349px; }
  .hero::before { left: 19%; background-position: 55% center; }
  .hero::after { background: linear-gradient(90deg,#282821 0%,#282821ee 24%,#28282182 64%,#28282133); }
  .section-top h2, .featured-section h2 { font-size: 1.64rem; }
  .books-grid, .featured-grid { grid-template-columns: 1fr; gap: 10px; }
  .book-card { grid-template-columns: 78px minmax(0,1fr); gap: 11px; min-height: auto; }
  .reader-layout { grid-template-columns: 1fr; gap: 10px; }
  .toc { position: static; display: none; max-height: min(55vh, 530px); }
  .toc.open { display: block; }
  #toc-toggle, #reader-search { display: inline-flex; }
  .chapter-inner { width: min(100% - 38px, 710px); padding-block: 24px; }
}
@media (max-width: 480px) {
  .brand strong { font-size: 1.04rem; }
  .brand img { width: 35px; height: 35px; }
  .brand { gap: 8px; }
  .hero { min-height: 360px; border-radius: 13px; align-items: end; }
  .hero::before { left: 0; bottom: 20%; background-position: 62% 34%; }
  .hero::after { background: linear-gradient(0deg,#282821 0%,#282821 23%,#282821d9 50%,#28282120); }
  .hero-body { padding: 113px 17px 23px; width: 100%; }
  .hero h1 { margin-block: 8px 8px; font-size: clamp(2.18rem, 9vw, 2.9rem); }
  .hero-description { font-size: .95rem; }
  .desktop-break { display: none; }
  .hero-search { margin-top: 15px; gap: 5px; }
  .hero-search button { padding-inline: 12px; }
  .hero-search input { font-size: .93rem; }
  .books-section, .featured-section { margin-top: 24px; }
  .reader-bar { flex-wrap: wrap; }
  .reader-actions { width: 100%; }
  .reader-actions .button { min-height: 37px; padding-inline: 9px; }
  .reading-page { padding-top: 13px; }
  .chapter-inner { width: calc(100% - 30px); }
  .reading-text .text-block { grid-template-columns: minmax(0,1fr) 28px; gap: 3px; }
  .paragraph-save { width: 28px; height: 29px; }
  .search-controls { grid-template-columns: 1fr; }
}
@media (hover: none) {
  .paragraph-save { opacity: .8; }
}
@media print {
  .masthead, .reader-bar, .toc, .chapter-nav, .paragraph-save, .footer, dialog { display: none !important; }
  .reader-layout { display: block; }
  .chapter { border: 0; box-shadow: none; }
  .shell { width: 100%; }
}
