/* ============ Tokens ============ */
:root{
  --maxw: 1120px;
  --reader-maxw: 720px;
  --radius: 6px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.06);
  --t-fast: .18s ease;
  --t: .28s ease;
  --serif: "Songti SC","STSong","SimSun","Source Han Serif SC","Noto Serif CJK SC",Georgia,serif;
  --sans: -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Hiragino Sans GB","Microsoft YaHei",sans-serif;
}

/* Light (米白墨绿) */
:root, [data-theme="light"]{
  --bg: #efe7d6;
  --bg-soft: #f6efde;
  --bg-card: #fbf6e7;
  --paper: #f8f1dd;
  --ink: #1f1b16;
  --ink-soft: #4a4339;
  --muted: #7a7163;
  --line: #c9bfa6;
  --line-soft: #ddd2b6;
  --accent: #355c4a;
  --accent-ink: #efe7d6;
  --accent-soft: rgba(53,92,74,.08);
  --selection: #c9a96a;
}

/* Dark (炭黑柔白) */
[data-theme="dark"]{
  --bg: #14110d;
  --bg-soft: #1c1813;
  --bg-card: #221d17;
  --paper: #1a1611;
  --ink: #ece4d4;
  --ink-soft: #c8bfae;
  --muted: #8a8270;
  --line: #3a332a;
  --line-soft: #2c2620;
  --accent: #a8c4a3;
  --accent-ink: #14110d;
  --accent-soft: rgba(168,196,163,.1);
  --selection: #b8a06a;
}

/* ============ Reset ============ */
*,*::before,*::after{ box-sizing:border-box; }
html,body{ margin:0; padding:0; }
html{ -webkit-text-size-adjust:100%; scroll-behavior:smooth; }
body{
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background var(--t), color var(--t);
}
img,svg{ display:block; max-width:100%; }
button{ font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input,select{ font: inherit; color: inherit; }
::selection{ background: var(--selection); color: var(--ink); }

.skip{
  position:absolute; left:-9999px; top:0;
  background: var(--accent); color: var(--accent-ink);
  padding: .5rem .75rem; border-radius: var(--radius-sm);
}
.skip:focus{ left: .5rem; top: .5rem; z-index: 100; }

.wrap{ max-width: var(--maxw); margin: 0 auto; padding: 0 1.25rem; }
.muted{ color: var(--muted); }
.small{ font-size: .875rem; }

/* ============ Header ============ */
.site-header{
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line-soft);
  position: sticky; top:0; z-index: 20;
  backdrop-filter: saturate(1.1);
}
.header-row{
  display:flex; align-items:center; justify-content:space-between;
  padding: .85rem 1.25rem;
}
.brand{
  display:inline-flex; align-items:center; gap:.6rem;
  text-decoration:none; color: var(--accent);
  font-family: var(--serif);
}
.brand-mark{ width: 28px; height: 28px; }
.brand-text{ font-size: 1.15rem; letter-spacing: .08em; font-weight: 600; }

.primary-nav{ display:flex; align-items:center; gap: .25rem; }
.nav-btn{
  padding: .45rem .8rem;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-size: .92rem;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-btn:hover{ background: var(--accent-soft); color: var(--accent); }
.nav-btn:focus-visible{ outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-btn{ display:inline-flex; align-items:center; }
.theme-btn svg{ width:18px; height:18px; }

/* ============ Main / Views ============ */
.main{ padding: 1.5rem 1.25rem 3rem; }
.view{ animation: fade .35s ease both; }
@keyframes fade{ from{ opacity:0; transform: translateY(4px);} to{ opacity:1; transform:none;} }

/* ============ Home ============ */
.hero{
  display:grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}
@media (min-width: 820px){
  .hero{ grid-template-columns: 1.1fr 1fr; align-items:center; }
}
.hero-title{
  font-family: var(--serif);
  font-size: clamp(2rem, 4.5vw, 3rem);
  margin: 0 0 .25rem;
  letter-spacing: .12em;
  color: var(--accent);
}
.hero-tagline{
  font-family: var(--serif);
  font-size: clamp(1.1rem, 2vw, 1.35rem);
  margin: .25rem 0 .9rem;
  color: var(--ink);
  letter-spacing: .04em;
}
.hero-summary{
  color: var(--ink-soft);
  margin: 0 0 1.25rem;
  max-width: 46ch;
}
.hero-actions{ display:flex; gap:.6rem; flex-wrap:wrap; }
.hero-art{
  color: var(--accent);
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: .75rem;
  display:flex; align-items:center; justify-content:center;
}
.hero-art svg{ width:100%; height:auto; max-height: 520px; }

.btn{
  display:inline-flex; align-items:center; justify-content:center;
  padding: .55rem 1rem;
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--ink);
  border-radius: var(--radius-sm);
  font-size: .95rem;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.btn:hover{ background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn:active{ transform: translateY(1px); }
.btn:focus-visible{ outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary{
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}
.btn-primary:hover{ filter: brightness(1.05); background: var(--accent); color: var(--accent-ink); }
.btn-ghost{ border-color: transparent; background: transparent; }
.btn[disabled]{ opacity:.5; cursor: not-allowed; pointer-events:none; }

.stats{
  margin-top: 1.25rem;
  display:grid; grid-template-columns: repeat(3, 1fr);
  gap: .75rem;
}
.stat{
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: .9rem 1rem;
  display:flex; flex-direction:column; gap:.25rem;
}
.stat-label{ font-size: .8rem; color: var(--muted); }
.stat-value{
  font-family: var(--serif);
  font-size: 1.4rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ============ TOC ============ */
.view-head{ margin: .5rem 0 1rem; }
.view-head h2{
  font-family: var(--serif);
  margin: 0 0 .25rem;
  letter-spacing: .08em;
  color: var(--accent);
}
.toc-tools{
  display:flex; gap:.75rem; flex-wrap:wrap;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  margin-bottom: 1rem;
}
.field{ display:flex; flex-direction:column; gap:.25rem; min-width: 160px; }
.field-grow{ flex:1 1 220px; }
.field-label{ font-size: .8rem; color: var(--muted); }
.field select, .field input{
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .45rem .6rem;
  color: var(--ink);
}
.field select:focus, .field input:focus{
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}

.toc-list{ display:flex; flex-direction:column; gap:.75rem; }
.toc-volume{
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  overflow:hidden;
}
.toc-volume-head{
  display:flex; align-items:center; justify-content:space-between;
  padding: .75rem 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--line-soft);
}
.toc-volume-title{
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--accent);
  letter-spacing: .05em;
}
.toc-volume-status{
  font-size: .78rem;
  padding: .15rem .55rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.toc-volume-status[data-status="accepted"]{ color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.toc-volume-status[data-status="pending"]{ color: var(--muted); }

.toc-chapters{ list-style:none; margin:0; padding:.4rem 0; }
.toc-chapter-item{ display:flex; }
.toc-chapter-link{
  flex:1;
  display:flex; align-items:baseline; justify-content:space-between; gap:1rem;
  padding: .55rem 1rem;
  color: var(--ink);
  text-decoration:none;
  border-radius: var(--radius-sm);
  transition: background var(--t-fast), color var(--t-fast);
}
.toc-chapter-link:hover{ background: var(--accent-soft); color: var(--accent); }
.toc-chapter-link:focus-visible{ outline: 2px solid var(--accent); outline-offset: 1px; }
.toc-chapter-title{ font-family: var(--serif); }
.toc-chapter-count{ color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }

.empty{
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 2rem 1rem;
  text-align:center;
  color: var(--muted);
}

/* ============ Reader ============ */
.reader-head{
  display:flex; align-items:flex-start; gap: 1rem;
  margin-bottom: .75rem;
}
.reader-title{ flex:1; min-width:0; }
.reader-title h2{
  font-family: var(--serif);
  margin: .15rem 0 0;
  font-size: clamp(1.4rem, 2.4vw, 1.8rem);
  color: var(--ink);
  letter-spacing: .04em;
}
.progress{
  height: 3px;
  background: var(--line-soft);
  border-radius: 999px;
  overflow:hidden;
  margin-bottom: 1.25rem;
}
.progress-bar{
  height:100%; width: 0%;
  background: var(--accent);
  transition: width var(--t-fast);
}

.reader-body{
  max-width: var(--reader-maxw);
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 1.5rem 1.25rem;
  font-family: var(--serif);
  font-size: clamp(1rem, 1.2vw + .8rem, 1.18rem); /* 16 ~ ~20 */
  line-height: 1.95;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
@media (min-width: 640px){
  .reader-body{ padding: 2.25rem 2.25rem; font-size: clamp(1.05rem, .9vw + .85rem, 1.25rem); }
}
.reader-body p{
  margin: 0 0 1.1em;
  text-indent: 2em;
  text-align: justify;
  word-break: break-word;
}
.reader-body p:first-child::first-letter{
  font-size: 1.1em;
  color: var(--accent);
}

.reader-nav{
  max-width: var(--reader-maxw);
  margin: 1rem auto 0;
  display:flex; justify-content:space-between; gap:.75rem;
}

/* ============ Footer ============ */
.site-footer{
  border-top: 1px solid var(--line-soft);
  background: var(--bg-soft);
  padding: 1.25rem 0;
  margin-top: 2rem;
  text-align:center;
}
.site-footer code{
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  padding: .05rem .35rem;
  border-radius: 3px;
  font-size: .85em;
}

/* ============ Error ============ */
.error-box{
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem;
  text-align:center;
  box-shadow: var(--shadow-sm);
}

/* ============ Reduced motion ============ */
@media (prefers-reduced-motion: reduce){
  *,*::before,*::after{
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

[hidden]{display:none!important}
.font-tools{display:flex;align-items:center;justify-content:center;gap:16px;padding:20px;font-size:14px;color:var(--muted)}
.font-tools input{accent-color:var(--accent);width:140px}
#statVersion{font:12px monospace;overflow-wrap:anywhere}

.speech-tools{display:flex;align-items:center;justify-content:center;flex-wrap:wrap;gap:12px;margin:0 auto 24px;max-width:760px;padding:18px;border:1px solid var(--line);border-radius:12px}
.speech-tools p{flex-basis:100%;margin:0;text-align:center;font-size:13px;color:var(--muted)}
.speech-tools select{padding:8px;border:1px solid var(--line);border-radius:6px;background:var(--bg-card)}

/* Keep chapter navigation within thumb reach on mobile readers. */
@media (max-width: 639px){
  .view-reader{padding-bottom:calc(88px + env(safe-area-inset-bottom, 0px));}
  .view-reader .reader-nav{
    position:fixed;
    inset:auto 0 0;
    z-index:30;
    max-width:none;
    margin:0;
    padding:12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    background:var(--bg-card);
    border-top:1px solid var(--line);
    box-shadow:0 -4px 18px rgba(0,0,0,.08);
  }
  .view-reader .reader-nav .btn{flex:1;min-height:44px;justify-content:center;}
  .view-reader[hidden] .reader-nav{display:none;}
}

.reader-body h1{font-size:1.4em;text-align:center;margin:0 0 1.5em}
.chapter-text-link{text-indent:0!important;border-top:1px solid var(--line);padding-top:1em}
.chapter-text-link a{color:var(--accent);text-decoration:underline}

.reader-nav a[aria-disabled="true"]{opacity:.4;cursor:default}
