:root {
  color-scheme: light;
  --accent: #d75837;
  --ink: #24211e;
  --muted: #77716b;
  --surface: #f4f1eb;
  --paper: #fffefa;
  --line: rgba(55, 48, 41, 0.1);
  --reader-font-size: 20px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; margin: 0; }
body { background: var(--surface); color: var(--ink); }
button, input { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.library-view { min-height: 100vh; max-width: 1180px; margin: 0 auto; padding: 38px 48px 80px; }
.library-header { display: flex; align-items: center; margin-bottom: 44px; }
.search-box { display: flex; align-items: center; width: min(100%, 420px); height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.65); box-shadow: 0 1px 0 rgba(255,255,255,.8) inset; }
.search-box svg { width: 19px; fill: none; stroke: var(--muted); stroke-linecap: round; stroke-width: 1.8; }
.search-box input, .toc-search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }
.search-box input { padding: 0 10px; font-size: 16px; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; border-bottom: 1px solid var(--line); }
.section-heading h1 { margin: 0 0 12px; font-family: Georgia, "Songti SC", serif; font-size: 22px; font-weight: 600; }
.section-heading span { color: var(--muted); font-size: 14px; }
.book-grid { display: grid; padding-top: 28px; grid-template-columns: repeat(auto-fill, 132px); justify-content: start; gap: 34px 28px; }
.book-card { display: flex; min-width: 0; padding: 0; border: 0; background: transparent; text-align: left; flex-direction: column; cursor: pointer; }
.book-card:hover .book-cover { transform: translateY(-6px) rotate(-.35deg); box-shadow: 0 24px 45px rgba(57, 42, 31, .22), 0 4px 10px rgba(57, 42, 31, .14); }
.book-cover { position: relative; width: 100%; aspect-ratio: 2 / 3; margin-bottom: 14px; overflow: hidden; border-radius: 4px 9px 9px 4px; background: linear-gradient(145deg, #772f24, #c16b4e); box-shadow: 0 11px 22px rgba(57, 42, 31, .15), 0 2px 5px rgba(57, 42, 31, .1); color: white; transition: transform .25s ease, box-shadow .25s ease; }
.book-cover::after { position: absolute; inset: 0 auto 0 0; width: 7px; content: ""; background: linear-gradient(90deg, rgba(0,0,0,.24), transparent); }
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.cover-progress { position: absolute; right: 0; bottom: 0; left: 0; height: 4px; background: rgba(0,0,0,.18); }
.cover-progress i { display: block; height: 100%; background: #ff6a45; }
.book-card > strong { overflow: hidden; margin-bottom: 4px; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.book-card > span, .book-card > small { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.book-card > small { margin-top: 6px; color: #9a938c; }
.empty-state, .error-state { grid-column: 1 / -1; padding: 72px 20px; text-align: center; color: var(--muted); }
.empty-icon { display: grid; width: 72px; height: 72px; margin: 0 auto 18px; place-items: center; border-radius: 22px; background: white; box-shadow: 0 12px 24px rgba(0,0,0,.08); color: var(--accent); font-family: Georgia, serif; font-size: 28px; }

.reader-view { position: fixed; inset: 0; background: var(--paper); }
.reader-toolbar { position: relative; z-index: 20; display: grid; height: 60px; padding: 0 18px; align-items: center; grid-template-columns: 1fr auto 1fr; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(18px); }
.icon-button, .appearance-button { display: inline-flex; align-items: center; border: 0; background: transparent; cursor: pointer; }
.icon-button svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.back-button { width: max-content; padding: 7px 8px 7px 0; color: var(--accent); gap: 2px; }
.reader-book-meta { display: flex; max-width: 440px; text-align: center; flex-direction: column; }
.reader-book-meta strong { overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.reader-book-meta span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.toolbar-actions { display: flex; justify-content: flex-end; gap: 4px; }
.appearance-button { padding: 8px 9px; border-radius: 10px; color: var(--accent); font-family: Georgia, serif; font-size: 17px; font-weight: 700; }
.appearance-button:hover, .icon-button:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.reading-progress { position: absolute; z-index: 21; top: 59px; right: 0; left: 0; height: 2px; }
.reading-progress span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .35s ease; }
.reader-layout { display: grid; height: calc(100vh - 60px); grid-template-columns: 320px minmax(0, 1fr); }
.toc-panel { overflow: hidden; border-right: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 75%, var(--paper)); }
.toc-header { display: flex; height: 54px; padding: 0 22px; align-items: center; justify-content: space-between; font-size: 18px; font-weight: 700; }
.toc-search { display: block; margin: 0 16px 12px; padding: 9px 12px; border-radius: 10px; background: color-mix(in srgb, var(--ink) 5%, transparent); }
.toc-search input { font-size: 13px; }
.toc-list { height: calc(100% - 110px); padding: 3px 12px 32px; overflow-y: auto; }
.toc-group + .toc-group { margin-top: 7px; }
.toc-group-row { display: grid; min-height: 38px; align-items: center; grid-template-columns: 28px minmax(0, 1fr); }
.toc-toggle { display: grid; width: 28px; height: 32px; padding: 0; place-items: center; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }
.toc-toggle:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.toc-toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; transition: transform .18s ease; }
.toc-toggle[aria-expanded="false"] svg { transform: rotate(-90deg); }
.toc-group-link, .toc-group-label { width: 100%; padding: 8px 8px 8px 3px; overflow: hidden; border: 0; border-radius: 8px; background: transparent; color: var(--ink); font-size: 13px; font-weight: 700; line-height: 1.42; text-align: left; text-overflow: ellipsis; cursor: pointer; }
.toc-group-link:hover, .toc-group-label:hover { color: var(--accent); }
.toc-group-link.active { color: var(--accent); }
.toc-group-children { position: relative; margin: 1px 0 5px 13px; padding: 2px 0 3px 14px; border-left: 1px solid color-mix(in srgb, var(--ink) 14%, transparent); }
.toc-item { border: 0; background: transparent; cursor: pointer; }
.toc-leaf { position: relative; display: grid; width: 100%; min-height: 37px; padding: 8px 8px 8px 10px; align-items: start; grid-template-columns: 26px minmax(0, 1fr); border-radius: 8px; color: var(--ink); text-align: left; }
.toc-leaf::before { position: absolute; top: 18px; left: -14px; width: 11px; height: 1px; content: ""; background: color-mix(in srgb, var(--ink) 14%, transparent); }
.toc-leaf span { padding-top: 2px; color: var(--muted); font-size: 9px; font-variant-numeric: tabular-nums; }
.toc-leaf .toc-leaf-dot::before { display: block; width: 5px; height: 5px; margin-top: 2px; border: 1px solid color-mix(in srgb, var(--ink) 30%, transparent); border-radius: 50%; content: ""; background: var(--paper); }
.toc-leaf strong { font-size: 12.5px; font-weight: 500; line-height: 1.55; }
.toc-leaf:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.toc-leaf.active { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.toc-leaf.active span { color: var(--accent); }
.toc-leaf.active::before { background: color-mix(in srgb, var(--accent) 55%, transparent); }
.reading-scroll { overflow-y: auto; scroll-behavior: smooth; }
.chapter-content, .chapter-navigation { width: min(100% - 64px, 720px); margin-right: auto; margin-left: auto; }
.chapter-content { min-height: calc(100vh - 120px); padding: clamp(62px, 9vh, 112px) 0 80px; font-family: Georgia, "Songti SC", "STSong", serif; font-size: var(--reader-font-size); line-height: 1.92; letter-spacing: .025em; }
.chapter-content.loading { opacity: .35; }
.chapter-label { margin-bottom: 12px; color: var(--accent); font-family: -apple-system, "PingFang SC", sans-serif; font-size: 12px; font-weight: 700; letter-spacing: .12em; }
.chapter-content h1 { margin: 0 0 2.1em; font-size: clamp(34px, 5vw, 52px); line-height: 1.25; letter-spacing: -.035em; }
.chapter-content h2, .chapter-content h3, .chapter-content h4 { margin: 2.2em 0 .8em; line-height: 1.45; }
.chapter-content h2 { font-size: 1.35em; }
.chapter-content h3, .chapter-content h4 { font-size: 1.1em; }
.chapter-content p { margin: 0 0 1.25em; text-align: justify; }
.chapter-content li { margin: 0 0 .8em 1.2em; }
.chapter-content blockquote { margin: 1.8em 0; padding: .25em 0 .25em 1.3em; border-left: 3px solid var(--accent); color: var(--muted); }
.chapter-content pre { padding: 18px; overflow-x: auto; border-radius: 8px; background: color-mix(in srgb, var(--ink) 6%, transparent); font-size: .8em; }
.chapter-content figure { margin: 2.4em 0; text-align: center; }
.chapter-content figure img { max-width: 100%; max-height: 72vh; border-radius: 3px; }
.chapter-content figcaption { margin-top: 8px; color: var(--muted); font-family: -apple-system, sans-serif; font-size: 12px; }
.chapter-navigation { display: grid; padding: 36px 0 90px; grid-template-columns: 1fr 1fr; gap: 14px; border-top: 1px solid var(--line); }
.chapter-nav-button { display: flex; min-height: 92px; padding: 17px 19px; justify-content: center; border: 1px solid var(--line); border-radius: 14px; background: transparent; text-align: left; flex-direction: column; cursor: pointer; }
.chapter-nav-button.next { text-align: right; }
.chapter-nav-button span { margin-bottom: 6px; color: var(--accent); font-size: 11px; font-weight: 700; }
.chapter-nav-button strong { font-family: Georgia, "Songti SC", serif; font-size: 14px; font-weight: 500; line-height: 1.4; }
.chapter-nav-button:hover:not(:disabled) { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.chapter-nav-button:disabled { opacity: .4; cursor: default; }
.appearance-panel { position: fixed; z-index: 50; top: 53px; right: 15px; width: 220px; padding: 13px; border: 1px solid var(--line); border-radius: 16px; background: color-mix(in srgb, var(--paper) 94%, transparent); box-shadow: 0 18px 48px rgba(0,0,0,.18); backdrop-filter: blur(22px); }
.font-controls { display: grid; margin-bottom: 12px; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 10px; }
.font-controls button { height: 40px; border: 0; background: transparent; cursor: pointer; }
.font-controls button:first-child { border-right: 1px solid var(--line); font-size: 13px; }
.font-controls button:last-child { font-size: 20px; }
.theme-controls { display: flex; justify-content: space-around; }
.theme-swatch { width: 36px; height: 36px; border: 2px solid transparent; border-radius: 50%; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.theme-swatch.paper { background: #fffefa; }
.theme-swatch.sepia { background: #f2e7cf; }
.theme-swatch.night { background: #202124; }
.mobile-only { display: none; }

body[data-theme="sepia"] { --ink: #3f3327; --muted: #807161; --surface: #e7d8ba; --paper: #f2e7cf; --line: rgba(76,58,39,.13); }
body[data-theme="night"] { color-scheme: dark; --accent: #ff7656; --ink: #e8e6e1; --muted: #a6a39d; --surface: #17181a; --paper: #202124; --line: rgba(255,255,255,.1); }
.scrim { position: fixed; z-index: 28; inset: 60px 0 0; background: rgba(0,0,0,.28); backdrop-filter: blur(2px); }

@media (max-width: 760px) {
  .library-view { padding: 22px 20px 60px; }
  .library-header { margin-bottom: 34px; }
  .search-box { width: 100%; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(108px, 126px)); gap: 30px 22px; }
  .reader-toolbar { grid-template-columns: 1fr minmax(0, 1.4fr) 1fr; padding: 0 10px; }
  .back-button span { display: none; }
  .mobile-only { display: inline-flex; }
  .reader-layout { display: block; }
  .toc-panel { position: fixed; z-index: 30; top: 60px; bottom: 0; left: 0; width: min(88vw, 340px); border-right: 0; box-shadow: 18px 0 40px rgba(0,0,0,.14); transform: translateX(-105%); transition: transform .25s ease; }
  .toc-panel.open { transform: translateX(0); }
  .reading-scroll { height: calc(100vh - 60px); }
  .chapter-content, .chapter-navigation { width: min(100% - 38px, 680px); }
  .chapter-content { padding-top: 52px; line-height: 1.85; }
  .chapter-content h1 { margin-bottom: 1.5em; font-size: 34px; }
  .chapter-navigation { padding-bottom: 55px; }
  .chapter-nav-button { min-height: 80px; padding: 13px; }
}
