:root {
  --reading-font-size: 19px;
  --max-width: clamp(40rem, 48vw, 48rem);
  --line-height: 1.9;
  --topbar-h: 2.9rem;
  --font-serif: "Songti SC", "STSong", "Source Han Serif SC", "Noto Serif SC", "SimSun", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}
html[data-theme="night"] { --bg:#14110f; --bg-soft:#1d1916; --fg:#d9cfc2; --fg-dim:#9a8f80; --accent:#c9a06a; --rule:#2c2620; --topbar-bg:rgba(20,17,15,.9); }
html[data-theme="day"]   { --bg:#f5efe2; --bg-soft:#efe7d5; --fg:#3a3226; --fg-dim:#7a6f5c; --accent:#9a5b2c; --rule:#e0d6c2; --topbar-bg:rgba(245,239,226,.9); }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--fg); font-family: var(--font-ui); -webkit-font-smoothing: antialiased; }
.progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--accent); z-index: 70; transition: width .1s linear; }
.topbar { position: sticky; top: 0; z-index: 60; min-height: var(--topbar-h); display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; background: var(--topbar-bg); backdrop-filter: blur(8px); border-bottom: 1px solid var(--rule); }
.topbar .spacer { flex: 1; }
.brand, .home-link { color: var(--fg); text-decoration: none; font-weight: 600; }
.icon-btn { background: transparent; border: 1px solid var(--rule); color: var(--fg); border-radius: 8px; padding: .3rem .55rem; font-size: .95rem; cursor: pointer; line-height: 1; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.reader { max-width: var(--max-width); margin: 0 auto; padding: 1.5rem 1.15rem 5rem; }
.book-title { font-family: var(--font-serif); font-size: 1.9rem; text-align: center; margin: 1rem 0 1.5rem; letter-spacing: .02em; }
.epigraph { color: var(--fg-dim); font-family: var(--font-serif); border-left: 2px solid var(--rule); margin: 0 0 2rem; padding: .25rem 0 .25rem 1rem; font-size: .98rem; }
#article { font-family: var(--font-serif); font-size: var(--reading-font-size); line-height: var(--line-height); }
#article h2 { font-size: 1.3rem; margin: 2.6rem 0 1.1rem; padding-top: .6rem; border-top: 1px solid var(--rule); scroll-margin-top: 3.5rem; }
#article p { margin: 0 0 1.15rem; text-align: justify; }
#article hr { border: 0; border-top: 1px solid var(--rule); margin: 2rem auto; width: 40%; }
.chapter-nav { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem; }
.ghost-btn { flex: 1; background: var(--bg-soft); border: 1px solid var(--rule); color: var(--fg); border-radius: 10px; padding: .7rem; cursor: pointer; font-size: .95rem; }
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }
.toc-panel { position: fixed; top: 0; left: 0; height: 100vh; width: 18rem; max-width: 82vw; background: var(--bg-soft); border-right: 1px solid var(--rule); padding: 3.2rem 1rem 1rem; overflow-y: auto; transform: translateX(-102%); transition: transform .25s ease; z-index: 55; }
.toc-panel.open { transform: translateX(0); }
.toc-title { color: var(--fg-dim); font-size: .8rem; letter-spacing: .1em; margin-bottom: .6rem; }
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-list a { display: block; color: var(--fg); text-decoration: none; padding: .5rem .4rem; border-radius: 6px; font-size: .92rem; border-left: 2px solid transparent; }
.toc-list a:hover { background: var(--bg); }
.toc-list a.active { color: var(--accent); border-left-color: var(--accent); }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 54; }
.scrim.show { opacity: 1; pointer-events: auto; }
.to-top { position: fixed; right: 1rem; bottom: 1rem; width: 2.6rem; height: 2.6rem; border-radius: 50%; border: 1px solid var(--rule); background: var(--bg-soft); color: var(--fg); cursor: pointer; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; }
.to-top.show { opacity: 1; pointer-events: auto; }
.resume { position: fixed; left: 50%; transform: translateX(-50%); bottom: 1.2rem; z-index: 45; }
.resume button { background: var(--accent); color: #1a1512; border: 0; border-radius: 999px; padding: .6rem 1.2rem; cursor: pointer; font-size: .9rem; box-shadow: 0 4px 16px rgba(0,0,0,.3); }
.shelf-main { max-width: 62rem; margin: 0 auto; padding: 1.5rem 1.15rem 4rem; }
.shelf-title { font-family: var(--font-serif); font-size: 1.8rem; margin: 1rem 0 1.5rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1rem; }
.card { display: block; background: var(--bg-soft); border: 1px solid var(--rule); border-radius: 14px; padding: 1.1rem 1.15rem; text-decoration: none; color: var(--fg); transition: border-color .2s, transform .1s; }
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card h2 { font-family: var(--font-serif); font-size: 1.2rem; margin: 0 0 .5rem; }
.card .badge { display: inline-block; font-size: .72rem; color: var(--accent); border: 1px solid var(--accent); border-radius: 999px; padding: .05rem .5rem; margin-bottom: .5rem; }
.card .blurb { color: var(--fg-dim); font-size: .9rem; line-height: 1.6; margin: 0; }
/* Wide screens: center the whole [sidebar + reading column] group.
   Shell = 18rem sidebar + 2rem gap + 40rem text = 60rem; --pad is the equal
   outer margin so the group sits centered on ultra-wide monitors. */
@media (min-width: 60rem) {
  .book { --pad: max(0px, calc((100vw - 20rem - var(--max-width)) / 2)); }
  .book .reader { margin-left: calc(var(--pad) + 18rem + 2rem); }
  .book .toc-panel { transform: translateX(0); left: var(--pad); top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); padding-top: 1rem; }
  .book .scrim { display: none; }
  #toc-toggle { display: none; }
}
