/* Notekeeping — site styles. Tokens first; dark + sepia override them. */
:root {
  --bg: #f7f3ea;
  --surface: #fffdf8;
  --ink: #26221e;
  --ink-2: #574e45;
  --muted: #8a7f73;
  --line: #e7e0d3;
  --accent: #a8322a;
  --accent-ink: #ffffff;
  --shadow: 0 1px 2px rgba(60, 40, 20, .05), 0 6px 20px rgba(60, 40, 20, .06);
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Source Han Sans SC", sans-serif;
  --font-serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "SimSun", serif;
  --font-read: var(--font-sans);
  --read-size: 18px;
  --radius: 12px;
  color-scheme: light;
}
@media (min-width: 768px) { :root { --read-size: 20px; } }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #141311; --surface: #1d1b18; --ink: #e6dfd3; --ink-2: #c3b9ab; --muted: #8e8478;
    --line: #2f2b26; --accent: #d25a4c; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141311; --surface: #1d1b18; --ink: #e6dfd3; --ink-2: #c3b9ab; --muted: #8e8478;
  --line: #2f2b26; --accent: #d25a4c; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
:root[data-theme="sepia"] {
  --bg: #f1e7cf; --surface: #f7efdc; --ink: #3a3024; --ink-2: #5a4d3c; --muted: #8b7b63;
  --line: #e0d2b2; --accent: #a8322a;
}
:root[data-font="serif"] { --font-read: var(--font-serif); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 var(--font-sans);
  -webkit-font-smoothing: antialiased; overflow-wrap: anywhere;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.read-wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }

/* ---------- header / footer ---------- */
.site-header { border-bottom: 1px solid var(--line); background: var(--bg); }
.bar { display: flex; align-items: center; gap: 12px; min-height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: .02em; }
.mark {
  width: 28px; height: 28px; border-radius: 6px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font: 700 15px/1 var(--font-serif);
}
.site-nav { margin-left: auto; display: flex; gap: 4px; }
.site-nav a { padding: 8px 10px; color: var(--ink-2); border-radius: 8px; }
.site-footer { margin-top: 56px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.site-footer .wrap, .site-footer .read-wrap { padding-top: 20px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: 15px; white-space: nowrap; cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); color: var(--accent-ink); }
.btn.disabled { opacity: .45; pointer-events: none; }

/* ---------- cover (thread-bound book) ---------- */
.cover {
  position: relative; display: block; width: 100%; aspect-ratio: 3 / 4;
  border-radius: 3px 6px 6px 3px; overflow: hidden; container-type: inline-size;
  background:
    radial-gradient(120% 80% at 25% 15%, rgba(255, 255, 255, .10), transparent 60%),
    linear-gradient(160deg, var(--c1, #24474a), var(--c2, #14292b));
  box-shadow: inset -3px 0 0 rgba(0, 0, 0, .22), 0 2px 4px rgba(0, 0, 0, .12), 0 10px 24px rgba(0, 0, 0, .14);
}
.cover::before { /* binding fold */
  content: ""; position: absolute; top: 0; bottom: 0; right: 13%; width: 1px; background: rgba(0, 0, 0, .22);
}
.cover::after { /* stitches */
  content: ""; position: absolute; top: 5%; bottom: 5%; right: 6.5%; width: 1.5px;
  background: repeating-linear-gradient(to bottom, rgba(244, 232, 205, .6) 0 7%, transparent 7% 23.5%);
}
.slip {
  position: absolute; top: 7%; left: 10%; width: 25%; height: 60%;
  background: #efe5cc; border: 1px solid rgba(60, 40, 20, .35);
  box-shadow: inset 0 0 0 2px #efe5cc, inset 0 0 0 3px rgba(60, 40, 20, .3);
  display: flex; justify-content: center; padding-top: 9%;
}
.slip-title {
  writing-mode: vertical-rl; font-family: var(--font-serif); font-weight: 700; color: #2a221a;
  font-size: 15px; font-size: min(14cqw, calc(58cqw / var(--n, 3))); letter-spacing: .12em; line-height: 1;
  white-space: nowrap;
}
.seal {
  position: absolute; left: 13.5%; top: 72%; width: 15cqw; height: 15cqw; border-radius: 2px;
  background: #b3362b; color: #f7e9d6; display: grid; place-items: center;
  font: 700 10cqw/1 var(--font-serif); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
}

/* ---------- home ---------- */
.home-head { padding: 28px 0 8px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; }
.home-head h1 { font: 700 28px/1.2 var(--font-serif); }
.home-head p { margin: 0; color: var(--muted); }
.filters { display: grid; gap: 10px; margin: 16px 0 4px; }
.search {
  width: 100%; min-height: 44px; padding: 0 14px 0 40px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface) no-repeat 14px 50% / 16px;
  color: var(--ink); font: inherit;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a7f73' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
}
.search:focus { outline: none; border-color: var(--accent); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-size: 14px;
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.shelf { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 16px; }
@media (min-width: 860px) { .shelf { grid-template-columns: 1fr 1fr; } }
.empty { color: var(--muted); padding: 32px 0; text-align: center; }

.book-card {
  display: grid; grid-template-columns: 96px minmax(0, 1fr);
  grid-template-areas: "cover info" "act act"; gap: 14px 16px;
  padding: 16px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
@media (min-width: 560px) {
  .book-card { grid-template-columns: 124px minmax(0, 1fr); grid-template-areas: "cover info" "cover act"; }
}
.book-card .cover { grid-area: cover; align-self: start; }
.book-card .info { grid-area: info; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.book-card h2 { font: 700 21px/1.25 var(--font-serif); }
.meta { margin: 0; color: var(--muted); font-size: 13.5px; }
.status { color: var(--accent); }
.excerpt {
  margin: 2px 0 0; color: var(--ink-2); font-size: 14px; line-height: 1.65;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
}
.latest, .resume { margin: 0; font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.latest a, .resume a { color: var(--ink-2); }
.resume a { color: var(--accent); }
.actions { grid-area: act; display: flex; gap: 10px; align-self: end; }
.actions .btn { flex: 1; }
@media (min-width: 560px) { .actions .btn { flex: none; } }

/* ---------- book page ---------- */
.crumbs { display: flex; gap: 8px; align-items: center; padding: 16px 0 0; font-size: 14px; color: var(--muted); min-width: 0; }
.crumbs span:last-child { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-head { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 18px; padding: 20px 0 0; align-items: start; }
@media (min-width: 640px) { .book-head { grid-template-columns: 168px minmax(0, 1fr); gap: 28px; } }
.book-info { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.book-info h1 { font: 700 clamp(26px, 6vw, 36px)/1.2 var(--font-serif); }
.tags { list-style: none; margin: 2px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tags li { font-size: 12.5px; padding: 3px 9px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); }
.facts { display: flex; margin: 6px 0 0; }
.facts div { padding: 0 10px; border-left: 1px solid var(--line); white-space: nowrap; }
.facts div:first-child { padding-left: 0; border-left: 0; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0; font: 600 16px/1.4 var(--font-sans); font-variant-numeric: tabular-nums; }
@media (min-width: 640px) { .facts div { padding: 0 16px; } .facts dd { font-size: 18px; } }
.book-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 20px 0 0; }
@media (min-width: 640px) { .book-actions { display: flex; } .book-actions .btn { min-width: 140px; } }
.book-actions .resume { grid-column: 1 / -1; align-self: center; }
.section { margin-top: 32px; }
.section h2 { font: 700 19px/1.3 var(--font-serif); display: flex; align-items: baseline; gap: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.section h2 small { font: 400 13px var(--font-sans); color: var(--muted); }
.intro-text { color: var(--ink-2); font-size: 15.5px; line-height: 1.9; }
.intro-text p { margin: 14px 0 0; }

.vol { border-bottom: 1px solid var(--line); }
.vol summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  min-height: 52px; padding: 8px 0; font-weight: 600;
}
.vol summary::-webkit-details-marker { display: none; }
.vol summary::after {
  content: ""; margin-left: 6px; width: 8px; height: 8px; flex: none;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translateY(-3px); transition: transform .15s;
}
.vol[open] summary::after { transform: rotate(225deg) translateY(-1px); }
.vol-meta { margin-left: auto; font-weight: 400; font-size: 13px; color: var(--muted); white-space: nowrap; }
.ch-list {
  list-style: none; margin: 0 0 12px; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); column-gap: 28px;
}
.ch-list a {
  display: block; padding: 11px 2px; border-bottom: 1px dashed var(--line);
  color: var(--ink-2); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ch-list a:visited { color: var(--muted); }
.ch-list a.is-last { color: var(--accent); font-weight: 600; }
.ch-list a.is-last::after { content: " · 上次读到"; font-size: 12px; font-weight: 400; }

/* ---------- reader ---------- */
.progress { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 60; pointer-events: none; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); }
.reader-bar {
  position: sticky; top: 0; z-index: 40; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(10px); backdrop-filter: saturate(1.4) blur(10px);
}
.reader-bar .bar { min-height: 48px; gap: 8px; }
.reader-bar .back { padding: 10px 8px 10px 0; color: var(--ink-2); white-space: nowrap; }
.reader-bar .book-name { flex: 1; min-width: 0; text-align: center; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aa {
  min-width: 44px; min-height: 40px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); cursor: pointer; font: 600 15px/1 var(--font-serif);
}
.chapter-head { padding: 34px 0 26px; }
.vol-label { margin: 0 0 8px; color: var(--accent); font-size: 13px; letter-spacing: .08em; }
.chapter-head h1 { font: 700 clamp(24px, 6vw, 30px)/1.35 var(--font-serif); }
.ch-meta { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.ch-body p {
  margin: 0 0 .85em; text-indent: 2em; text-align: justify;
  font-family: var(--font-read); font-size: var(--read-size); line-height: 1.9; letter-spacing: .02em;
}
.ch-body strong { font-weight: 700; color: var(--ink); }
.ch-body hr.scene { border: 0; height: 1.6em; margin: .4em 0 1.1em; text-align: center; color: var(--muted); }
.ch-body hr.scene::before { content: "· · ·"; font-size: 15px; letter-spacing: .5em; line-height: 1.6em; }
.ch-body figure { margin: 6px 0 1.4em; }
.ch-body figure img { display: block; width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.ch-body figcaption, .ch-body p.note { margin-top: 8px; color: var(--muted); font-size: 13.5px; text-align: center; text-indent: 0; }
.ch-nav { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; margin: 40px 0 0; }
.ch-nav .btn { padding: 0 12px; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; margin: 0 auto; max-width: 560px;
  background: var(--surface); border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 30px rgba(0, 0, 0, .15);
}
.sheet-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; }
.sheet-row .label { flex: none; width: 34px; color: var(--muted); font-size: 14px; }
.seg { display: flex; flex: 1; gap: 6px; align-items: center; }
.seg button {
  flex: 1; min-height: 40px; padding: 0 4px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); font-size: 14px;
}
.seg button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--surface); font-weight: 600; }
.seg output { min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- 404 ---------- */
.notfound { text-align: center; padding: 72px 0 24px; }
.notfound h1 { font: 700 30px/1.3 var(--font-serif); margin-bottom: 10px; }
.notfound p { color: var(--muted); margin: 0 0 24px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- document pages (outlines, story bibles: book.json "docs") ---------- */
.ch-body.doc { font-family: var(--font-read); font-size: var(--read-size); line-height: 1.85; }
.ch-body.doc p { text-indent: 0; text-align: left; }
.ch-body.doc h2 { font: 700 1.2em/1.4 var(--font-serif); margin: 1.6em 0 .6em; padding-bottom: .35em; border-bottom: 1px solid var(--line); }
.ch-body.doc h3 { font: 700 1.05em/1.45 var(--font-serif); margin: 1.4em 0 .5em; }
.ch-body.doc h4 { font: 700 1em/1.5 var(--font-sans); margin: 1.2em 0 .4em; color: var(--ink-2); }
.ch-body.doc ul, .ch-body.doc ol { margin: 0 0 1em; padding-left: 1.5em; }
.ch-body.doc li { margin: .3em 0; }
.ch-body.doc li::marker { color: var(--muted); }
.ch-body.doc blockquote { margin: 0 0 1.1em; padding: .7em 1em; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 8px 8px 0; color: var(--ink-2); }
.ch-body.doc blockquote p:last-child { margin-bottom: 0; }
.ch-body.doc hr { border: 0; border-top: 1px solid var(--line); margin: 1.6em 0; }
.ch-body.doc code { font: .86em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; padding: .1em .35em; border-radius: 4px; background: var(--surface); border: 1px solid var(--line); }
.ch-body.doc .math, .ch-body.doc .math-block { font-family: "Cambria Math", "STIX Two Math", var(--font-serif); font-style: italic; }
.ch-body.doc .math-block { text-align: center; margin: .6em 0 1.2em; font-size: 1.05em; }
.ch-body.doc .table-wrap { overflow-x: auto; margin: 0 0 1.2em; border: 1px solid var(--line); border-radius: 10px; -webkit-overflow-scrolling: touch; }
.ch-body.doc table { border-collapse: collapse; width: 100%; font-size: 15px; line-height: 1.6; font-family: var(--font-sans); }
.ch-body.doc th, .ch-body.doc td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; min-width: 5em; }
.ch-body.doc th { background: var(--surface); font-weight: 700; white-space: nowrap; }
.ch-body.doc td.r, .ch-body.doc th.r { text-align: right; }
.ch-body.doc tr:last-child td { border-bottom: 0; }
.ch-body.doc .pre-wrap { margin: 0 0 1.2em; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); overflow: hidden; }
.ch-body.doc .pre-label { display: block; padding: 6px 12px; font-size: 12.5px; color: var(--muted); border-bottom: 1px solid var(--line); font-family: var(--font-sans); }
.ch-body.doc pre { margin: 0; padding: 12px; overflow-x: auto; font: 13.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.ch-body.doc pre code { padding: 0; border: 0; background: none; font-size: inherit; }
.ch-body.doc figure img { background: #fff; }

/* books marked "lang": "en" in book.json: Latin fonts first, so quotes and headings aren't drawn by a CJK font */
[lang="en"] {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-serif: Georgia, "Times New Roman", "Songti SC", "SimSun", serif;
  --font-read: var(--font-sans);
  letter-spacing: normal;
}
:root[data-font="serif"] [lang="en"] { --font-read: var(--font-serif); }
[lang="en"] .ch-body { letter-spacing: normal; }

/* book page pictures: "banner" and "gallery" in book.json */
.book-banner { margin: 14px 0 0; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--surface); }
.book-banner img { display: block; width: 100%; height: auto; }
.gallery { list-style: none; margin: 14px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.gallery li { margin: 0; }
.gallery a { display: block; aspect-ratio: 4 / 3; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--surface); }
.gallery img { display: block; width: 100%; height: 100%; object-fit: contain; }
.gallery span { display: block; margin-top: 6px; font-size: 13px; line-height: 1.4; color: var(--muted); text-align: center; }
