:root {
  --bg: #f6f2ea; --paper: #fffdf8; --ink: #22201c; --muted: #6d665b; --line: #e3dccd;
  --accent: #a8322d; --accent-soft: #f3e1dc; --chip: #efe8da; --bar: #c98a5e;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 20px rgba(60, 40, 20, .05);
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a18; --paper: #242220; --ink: #ece6da; --muted: #a79f92; --line: #3a3733;
    --accent: #e0736b; --accent-soft: #3d2826; --chip: #312e2a; --bar: #c98a5e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
  --bg: #1b1a18; --paper: #242220; --ink: #ece6da; --muted: #a79f92; --line: #3a3733;
  --accent: #e0736b; --accent-soft: #3d2826; --chip: #312e2a; --bar: #c98a5e; --shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.7 var(--sans); overflow-x: hidden; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.3; margin: 0; font-weight: 700; }
button, input { font: inherit; color: inherit; }
main { max-width: 1120px; margin: 0 auto; padding: 0 16px 48px; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px; padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--serif); font-weight: 700; font-size: 18px; white-space: nowrap; }
.seal { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 6px; background: var(--accent); color: #fff; font-size: 17px; }
.topnav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a { padding: 5px 10px; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: 14px; white-space: nowrap; }
.topnav a:hover { color: var(--ink); background: var(--chip); }
.topnav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

.hero { padding: 48px 0 28px; }
.eyebrow, .cat { margin: 0; color: var(--accent); font-size: 13px; letter-spacing: .08em; }
.hero h1 { font-size: clamp(30px, 6vw, 46px); margin: 6px 0 12px; }
.lede { max-width: 680px; color: var(--muted); font-size: 17px; margin: 0; }
.totals { display: flex; flex-wrap: wrap; gap: 12px 36px; margin: 28px 0 0; }
.totals div { display: flex; flex-direction: column-reverse; }
.totals dt { color: var(--muted); font-size: 13px; }
.totals dd { margin: 0; font: 700 28px/1.2 var(--serif); font-variant-numeric: tabular-nums; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card { position: relative; display: flex; flex-direction: column; gap: 12px; padding: 20px; background: var(--paper);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); transition: transform .15s, border-color .15s; }
.card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.card-link { position: absolute; inset: 0; border-radius: inherit; z-index: 1; }
.card-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card-head { display: flex; gap: 14px; align-items: center; }
.card h2 { font-size: 20px; }
.mark { flex: none; display: grid; place-items: center; width: 46px; height: 46px; border-radius: 10px; background: var(--accent-soft);
  color: var(--accent); font: 700 22px/1 var(--serif); }
.mark[data-len="3"] { font: 700 14px/1 var(--sans); letter-spacing: .02em; }
.mark.big { width: 64px; height: 64px; font-size: 30px; border-radius: 14px; }
.mark.big[data-len="3"] { font-size: 18px; }
.tag { margin: 0; color: var(--muted); font-size: 15px; flex: 1; }
.facts { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.facts li { display: flex; flex-direction: column; }
.facts b { font: 700 16px/1.3 var(--serif); font-variant-numeric: tabular-nums; }
.facts span { font-size: 12px; color: var(--muted); }
.facts.stacked { flex-direction: column; gap: 12px; }
.facts.stacked li { flex-direction: row; justify-content: space-between; align-items: baseline; gap: 12px; border-bottom: 1px dashed var(--line); padding-bottom: 8px; }
.facts.stacked li:last-child { border: 0; padding: 0; }
.facts.stacked span { font-size: 14px; order: -1; }
.facts.stacked b { text-align: right; }
.card-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.views { font-size: 13px; color: var(--muted); white-space: nowrap; }
.views b { color: var(--ink); font-variant-numeric: tabular-nums; }
.spark { display: block; width: 100%; max-width: 140px; height: 28px; fill: var(--bar); }
.stats .spark { max-width: none; height: 48px; margin-top: 16px; }

.project-hero .back, .reader .back { display: inline-block; color: var(--muted); text-decoration: none; font-size: 14px; margin-bottom: 18px; }
.back:hover { color: var(--accent); }
.project-title { display: flex; align-items: center; gap: 16px; }
.project-title h1 { margin: 2px 0 0; }
.project-hero .lede { margin-top: 14px; }
.cta { display: inline-flex; align-items: center; gap: 8px; margin-top: 22px; padding: 11px 22px; border-radius: 999px; background: var(--accent);
  color: #fff; text-decoration: none; font-weight: 600; }
.cta:hover { filter: brightness(1.08); }
.project-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.side { display: grid; gap: 16px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 22px; box-shadow: var(--shadow); }
.panel + .panel, .project-grid + .panel { margin-top: 16px; }
.panel h2 { font-size: 19px; margin-bottom: 12px; }
.panel h3 { font-size: 16px; margin: 20px 0 8px; }
.intro p { margin: 0 0 10px; }
.features { margin: 0; padding-left: 1.2em; }
.features li { margin: 4px 0; }
.features li::marker { color: var(--accent); }
.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 0; }
.statgrid div { display: flex; flex-direction: column-reverse; }
.statgrid dt { font-size: 13px; color: var(--muted); }
.statgrid dd { margin: 0; font: 700 24px/1.2 var(--serif); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; margin: 6px 0 0; }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips li, .chips button { padding: 4px 12px; border-radius: 999px; background: var(--chip); font-size: 14px; border: 1px solid transparent; }
.chips button { cursor: pointer; }
.chips button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }

.browse-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.browse-head h2 { margin: 0; }
.browse-head input { flex: 1 1 240px; max-width: 360px; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); }
.filters { display: grid; gap: 12px; margin-bottom: 8px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs button { flex: none; padding: 8px 14px; background: none; border: 0; border-bottom: 2px solid transparent; cursor: pointer; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.group { font-size: 15px; margin: 22px 0 8px; color: var(--muted); font-family: var(--sans); font-weight: 600; }
.book-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.book { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  text-decoration: none; background: var(--bg); height: 100%; }
.book:hover { border-color: var(--accent); }
.bt { font-size: 15px; min-width: 0; overflow-wrap: anywhere; }
.bp { flex: none; font-size: 12px; color: var(--muted); }

.reader-body main { max-width: 1000px; }
.reader-bar { padding: 22px 0 14px; }
.reader .back { margin-bottom: 8px; }
.crumbs { margin: 0; color: var(--muted); font-size: 13px; }
.reader-title h1 { font-size: clamp(20px, 4vw, 28px); margin-top: 4px; }
.stage { position: relative; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-height: 60vh; overflow: auto;
  box-shadow: var(--shadow); display: flex; justify-content: center; align-items: flex-start; }
.stage canvas { display: block; max-width: 100%; height: auto; border-radius: 4px; background: #fff; }
.stage.zoomed { justify-content: flex-start; }
.stage.zoomed canvas { max-width: none; width: 160%; }
.loading { position: absolute; top: 40%; left: 0; right: 0; text-align: center; color: var(--muted); margin: 0; }
.pager { position: sticky; bottom: 0; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; padding: 12px 0;
  background: linear-gradient(transparent, var(--bg) 30%); }
.pager button { padding: 8px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); cursor: pointer; }
.pager button:disabled { opacity: .4; cursor: default; }
.pager button:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }
.jump { display: flex; align-items: center; gap: 6px; color: var(--muted); font-variant-numeric: tabular-nums; }
.jump input { width: 72px; padding: 7px 8px; text-align: center; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); }

.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 16px 36px; border-top: 1px solid var(--line); }
.foot p { margin: 0; }

@media (max-width: 820px) {
  .project-grid { grid-template-columns: 1fr; }
  .topbar { gap: 12px; }
  .brand span:last-child { display: none; }
}
@media (max-width: 480px) {
  .hero { padding: 32px 0 20px; }
  .cards { grid-template-columns: 1fr; }
  .panel { padding: 18px; }
  .stage { padding: 6px; min-height: 50vh; }
  .pager button { padding: 8px 12px; }
}
