@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@500;600;700&family=Source+Sans+3:wght@400;500;600&display=swap');

:root {
  color-scheme: light;
  --paper: #f4f1e9;
  --paper-deep: #e9e5dc;
  --panel: #faf8f2;
  --ink: #222421;
  --muted: #77786f;
  --line: #d9d5cc;
  --accent: #a64837;
  --accent-soft: #efe0da;
  --stage: #343735;
  --stage-deep: #292c2a;
  --white: #fffefb;
  --shadow: 0 20px 58px rgba(10, 12, 10, .24);
  --sidebar: 306px;
  --toolbar: 72px;
}

[data-theme="night"] {
  color-scheme: dark;
  --paper: #1e211f;
  --paper-deep: #171917;
  --panel: #252825;
  --ink: #e9e7df;
  --muted: #9e9f98;
  --line: #393c39;
  --accent: #d17863;
  --accent-soft: #402b27;
  --stage: #171917;
  --stage-deep: #111311;
  --white: #deddd7;
  --shadow: 0 20px 58px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Source Sans 3", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.app-shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); height: 100dvh; }
.library {
  position: relative;
  z-index: 30;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.library-head { min-height: var(--toolbar); padding: 14px 19px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid var(--ink); color: var(--ink); font: 600 19px/1 "Noto Serif SC", serif;
}
.brand strong { display: block; font: 600 16px/1.25 "Noto Serif SC", serif; letter-spacing: .08em; }
.brand small { display: block; margin-top: 4px; color: var(--muted); font-size: 8px; letter-spacing: .18em; }
.library-tools { padding: 16px 16px 12px; }
.search-field {
  display: flex; align-items: center; gap: 9px; height: 40px; padding: 0 11px;
  background: var(--paper); border: 1px solid transparent; transition: border-color .2s, background .2s;
}
.search-field:focus-within { border-color: var(--accent); background: var(--panel); }
.search-field svg { width: 16px; color: var(--muted); }
.search-field input { width: 100%; min-width: 0; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 13px; }
.search-field input::placeholder { color: var(--muted); }
kbd { padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; color: var(--muted); background: var(--panel); font: 10px/1.5 "Source Sans 3", sans-serif; }
.library-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 11px; color: var(--muted); font-size: 11px; }
.text-btn { padding: 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; }
.text-btn:hover { color: var(--accent); }
.recent { margin: 0 16px 12px; padding: 13px; background: var(--accent-soft); border-left: 2px solid var(--accent); }
.section-label { display: block; margin-bottom: 7px; color: var(--accent); font-size: 9px; font-weight: 600; letter-spacing: .16em; }
.recent-book { width: 100%; padding: 0; border: 0; text-align: left; background: transparent; cursor: pointer; }
.recent-book strong { display: block; overflow: hidden; color: var(--ink); font: 600 12px/1.4 "Noto Serif SC", serif; text-overflow: ellipsis; white-space: nowrap; }
.recent-book span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.book-list { flex: 1; overflow: auto; padding: 0 10px 14px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.collection { margin-bottom: 5px; }
.collection-head {
  width: 100%; height: 38px; padding: 0 8px; border: 0; display: flex; align-items: center; gap: 8px;
  color: var(--muted); background: transparent; cursor: pointer; text-align: left;
}
.collection-head:hover { color: var(--ink); }
.collection-head svg { width: 14px; transition: transform .2s; }
.collection.collapsed .collection-head svg { transform: rotate(-90deg); }
.collection-head strong { flex: 1; color: inherit; font-size: 11px; font-weight: 600; letter-spacing: .08em; }
.collection-head span { font-size: 10px; font-variant-numeric: tabular-nums; }
.collection-books { display: grid; }
.collection.collapsed .collection-books { display: none; }
.book-row {
  position: relative; min-width: 0; min-height: 47px; padding: 8px 10px 9px 30px; border: 0;
  display: block; color: var(--ink); background: transparent; cursor: pointer; text-align: left;
}
.book-row::before { content: ""; position: absolute; left: 13px; top: 14px; width: 4px; height: 17px; background: var(--line); }
.book-row:hover { background: var(--paper); }
.book-row.active { background: var(--paper-deep); }
.book-row.active::before { background: var(--accent); }
.book-row strong { display: block; overflow: hidden; font: 500 12px/1.4 "Noto Serif SC", serif; text-overflow: ellipsis; white-space: nowrap; }
.book-row small { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }
.row-progress { position: absolute; left: 30px; right: 10px; bottom: 4px; height: 1px; background: var(--line); }
.row-progress i { display: block; height: 100%; background: var(--accent); }
.empty-list { padding: 36px 18px; color: var(--muted); text-align: center; font-size: 12px; }
.library-foot { min-height: 44px; padding: 0 17px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.library-foot span { display: flex; align-items: center; gap: 6px; }
.library-foot svg { width: 13px; }
.library-foot a { color: inherit; text-decoration: none; }
.library-foot a:hover { color: var(--accent); }

.reader { min-width: 0; height: 100dvh; display: grid; grid-template-rows: var(--toolbar) minmax(0, 1fr) 33px; background: var(--stage); }
.toolbar {
  position: relative; z-index: 20; min-width: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px 0 22px; gap: 20px; background: var(--paper); border-bottom: 1px solid var(--line);
}
.toolbar-start { min-width: 0; display: flex; align-items: center; gap: 10px; }
.book-heading { min-width: 0; }
.book-kicker { display: block; margin-bottom: 2px; color: var(--accent); font-size: 8px; font-weight: 600; letter-spacing: .15em; text-transform: uppercase; }
.book-heading h1 { max-width: 360px; margin: 0; overflow: hidden; font: 600 14px/1.4 "Noto Serif SC", serif; text-overflow: ellipsis; white-space: nowrap; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; }
.control-group { height: 34px; display: flex; align-items: center; border: 1px solid var(--line); background: var(--panel); }
.icon-btn, .zoom-label {
  width: 34px; height: 34px; padding: 0; border: 0; display: inline-grid; place-items: center;
  color: var(--muted); background: transparent; cursor: pointer; transition: color .16s, background .16s;
}
.icon-btn:hover, .zoom-label:hover { color: var(--ink); background: var(--paper-deep); }
.icon-btn.active { color: var(--accent); background: var(--accent-soft); }
.icon-btn:focus-visible, .zoom-label:focus-visible, .book-row:focus-visible, .collection-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.icon-btn svg { width: 15px; height: 15px; stroke-width: 1.7; }
.zoom-label { width: 40px; font-size: 10px; }
.page-counter { height: 100%; padding: 0 8px; display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; }
.page-counter input { width: 31px; padding: 0; border: 0; border-bottom: 1px solid var(--line); outline: 0; color: var(--ink); background: transparent; text-align: center; font-size: 11px; font-variant-numeric: tabular-nums; }
.page-counter span { font-variant-numeric: tabular-nums; }
.mobile-menu, .mobile-close { display: none; }

.reading-stage { position: relative; min-height: 0; overflow: auto; background: radial-gradient(circle at 50% 20%, var(--stage), var(--stage-deep) 78%); scrollbar-width: thin; scrollbar-color: #6a6d68 transparent; }
.reading-stage::before { content: ""; position: fixed; inset: var(--toolbar) 0 33px var(--sidebar); pointer-events: none; opacity: .035; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 96 96'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }
.empty-state, .loading-state, .error-state { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px; color: #cbcfc8; text-align: center; }
.empty-monogram { width: 86px; height: 108px; margin-bottom: 24px; display: grid; place-items: center; border: 1px solid #777b75; font: 500 30px/1 "Noto Serif SC", serif; }
.empty-state p { margin: 0 0 8px; font: 500 17px/1.7 "Noto Serif SC", serif; letter-spacing: .04em; }
.empty-state span { color: #8e938c; font-size: 11px; }
.mobile-pick { display: none !important; }
.loading-state p { margin-top: 14px; font: 500 12px/1.5 "Noto Serif SC", serif; }
.loader { width: 27px; height: 27px; border: 1px solid #71756f; border-top-color: #f1eee7; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-state svg { width: 31px; margin-bottom: 12px; color: #d78a77; }
.error-state strong { font: 600 16px "Noto Serif SC", serif; }
.error-state p { max-width: 420px; margin: 8px 0 18px; color: #999e97; font-size: 11px; }
.primary-btn { min-height: 36px; padding: 0 15px; border: 1px solid #d8dbd5; display: inline-flex; align-items: center; gap: 7px; color: #ecefe9; background: transparent; cursor: pointer; font-size: 11px; }
.primary-btn:hover { color: #fff; border-color: #fff; }
.primary-btn svg { width: 14px; }
.pages { position: relative; min-height: 100%; padding: 34px 32px 48px; }
.pages.single { display: flex; align-items: flex-start; justify-content: center; }
.pages.continuous { display: flex; flex-direction: column; align-items: center; gap: 24px; }
.page-shell { position: relative; flex: 0 0 auto; background: var(--white); box-shadow: var(--shadow); }
.page-shell canvas { display: block; max-width: none; }
.page-shell .page-badge { position: absolute; right: -42px; top: 5px; color: #aaa; font-size: 9px; font-variant-numeric: tabular-nums; }
.page-skeleton { min-width: 560px; aspect-ratio: .707; background: linear-gradient(110deg, #e4e2dc 8%, #f2f0ea 18%, #e4e2dc 33%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position-x: -200%; } }
.reader-footer { min-width: 0; padding: 0 18px; display: grid; grid-template-columns: minmax(100px, 1fr) auto auto; gap: 13px; align-items: center; color: var(--muted); background: var(--paper-deep); border-top: 1px solid var(--line); font-size: 9px; }
.progress-track { height: 2px; overflow: hidden; background: var(--line); }
.progress-track span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .2s; }
.shortcut-hint { white-space: nowrap; }
.shortcut-hint kbd { margin: 0 2px; font-size: 8px; }
.toast { position: fixed; left: 50%; bottom: 50px; z-index: 100; padding: 9px 14px; color: #f7f5ef; background: #202320; border: 1px solid #555952; font-size: 11px; opacity: 0; pointer-events: none; transform: translate(-50%, 8px); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.scrim { display: none; }
[hidden] { display: none !important; }

@media (max-width: 1060px) {
  .zoom-tools, .shortcut-hint { display: none; }
  .book-heading h1 { max-width: 260px; }
}

@media (max-width: 760px) {
  :root { --toolbar: 60px; }
  .app-shell { display: block; }
  .library { position: fixed; inset: 0 auto 0 0; width: min(88vw, 330px); transform: translateX(-102%); transition: transform .25s ease; box-shadow: 18px 0 50px rgba(0, 0, 0, .28); }
  body.library-open .library { transform: translateX(0); }
  .scrim { position: fixed; inset: 0; z-index: 25; display: block; background: rgba(10, 12, 10, .5); opacity: 0; pointer-events: none; transition: opacity .25s; }
  body.library-open .scrim { opacity: 1; pointer-events: auto; }
  .mobile-menu, .mobile-close { display: inline-grid; }
  .reader { grid-template-rows: var(--toolbar) minmax(0, 1fr) 31px; }
  .toolbar { padding: 0 10px; gap: 8px; }
  .toolbar-start { flex: 1; overflow: hidden; }
  .book-kicker { display: none; }
  .book-heading h1 { max-width: 40vw; font-size: 12px; }
  .toolbar-actions { gap: 4px; }
  .toolbar-actions > .control-group:not(.page-nav), .toolbar-actions > #themeToggle, .desktop-only { display: none; }
  .page-nav { border: 0; background: transparent; }
  .page-counter { padding: 0 3px; }
  .pages { padding: 18px 10px 38px; }
  .pages.continuous { gap: 14px; }
  .page-shell .page-badge { display: none; }
  .page-skeleton { min-width: min(90vw, 560px); }
  .reading-stage::before { left: 0; }
  .reader-footer { padding: 0 10px; grid-template-columns: 1fr auto; gap: 9px; }
  .mobile-pick { display: inline-flex !important; margin-top: 24px; }
  .empty-state p { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
