:root {
  color-scheme: dark;
  --bg: #101111;
  --surface: #181a19;
  --surface-raised: #222422;
  --line: rgba(255, 255, 255, 0.11);
  --text: #f2f1ec;
  --muted: #9c9e99;
  --accent: #df4d36;
  --accent-strong: #f05a41;
  --paper: #e9e6dc;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --page-gap: 0px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
html, body, .reader-library-list { scrollbar-width: none; -ms-overflow-style: none; }
html::-webkit-scrollbar, body::-webkit-scrollbar, .reader-library-list::-webkit-scrollbar { display: none; width: 0; height: 0; }
body { min-width: 320px; letter-spacing: 0; -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; letter-spacing: 0; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
[hidden] { display: none !important; }

.app-shell { min-height: 100dvh; background: var(--bg); }
.library-header { height: calc(68px + var(--safe-top)); padding: calc(12px + var(--safe-top)) clamp(18px, 4vw, 48px) 10px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; background: rgba(16, 17, 17, 0.93); backdrop-filter: blur(18px); }
.library-heading { display: flex; align-items: center; gap: 12px; }
.library-actions { display: flex; align-items: center; gap: 4px; }
.library-heading > div { display: grid; gap: 2px; }
.library-heading h1 { margin: 0; font: 700 22px Georgia, "Songti SC", serif; }
.library-heading > div > span { color: var(--muted); font-size: 10px; }
.brand-lockup { display: flex; align-items: center; gap: 11px; }
.brand-lockup > div { display: grid; gap: 2px; }
.brand-lockup strong { font-family: Georgia, "Songti SC", serif; font-size: 17px; font-weight: 700; }
.brand-lockup span:not(.brand-mark) { color: var(--muted); font-size: 10px; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; background: var(--text); color: var(--bg); font-family: Georgia, "Songti SC", serif; font-weight: 800; }
.icon-button { width: 42px; height: 42px; border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; border-radius: 6px; }
.icon-button:hover { background: var(--surface-raised); }
.icon-button svg { width: 20px; height: 20px; stroke-width: 1.8; }

.library-view { max-width: 1160px; margin: 0 auto; }
.library-screen { padding: 34px clamp(20px, 6vw, 72px) 80px; }
.library-section-heading h2 { margin: 5px 0 0; font: 700 24px Georgia, "Songti SC", serif; }
.comic-grid { margin-top: 28px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 28px 18px; }
.library-card { min-width: 0; padding: 0; border: 0; background: transparent; display: grid; grid-template-rows: auto auto auto; gap: 7px; text-align: left; cursor: pointer; }
.library-card:active .library-cover { transform: scale(.985); }
.library-cover { width: 100%; aspect-ratio: 2 / 3; overflow: hidden; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line); color: #666963; font: 700 18px Georgia, "Songti SC", serif; transition: transform 120ms ease; }
.library-cover img { width: 100%; height: 100%; display: block; object-fit: cover; }
.library-card > strong { display: -webkit-box; min-height: 2.7em; overflow: hidden; font-size: 13px; line-height: 1.35; font-weight: 650; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.library-card > span:last-child { color: var(--muted); font-size: 10px; }
.library-card.is-unavailable .library-cover { filter: saturate(.55); }
.library-card.is-unavailable > span:last-child { color: var(--accent-strong); }
.detail-nav { padding: 16px clamp(20px, 6vw, 72px) 0; }
.text-icon-button, .secondary-button { border: 0; background: transparent; display: inline-flex; align-items: center; justify-content: center; gap: 7px; cursor: pointer; }
.text-icon-button { min-height: 40px; padding: 0 4px 0 0; color: var(--muted); font-size: 12px; }
.text-icon-button svg, .secondary-button svg { width: 17px; }
.secondary-button { min-height: 44px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }
.secondary-button:disabled { opacity: 0.4; cursor: wait; }
.comic-detail { min-height: min(580px, calc(100dvh - 68px)); padding: clamp(34px, 8vw, 88px) clamp(20px, 6vw, 72px); display: grid; grid-template-columns: minmax(190px, 310px) minmax(0, 580px); align-items: center; gap: clamp(32px, 7vw, 92px); }
.cover-frame { position: relative; width: 100%; aspect-ratio: 2 / 3; overflow: hidden; background: #292b29; box-shadow: 0 28px 70px rgba(0, 0, 0, 0.42); }
.cover-frame img { position: relative; z-index: 2; width: 100%; height: 100%; display: block; object-fit: cover; }
.cover-frame img:not([src]), .cover-frame img.is-error { opacity: 0; }
.cover-fallback { position: absolute; inset: 0; display: grid; place-items: center; color: #666963; font: 700 30px Georgia, "Songti SC", serif; border: 1px solid var(--line); }
.status-line, .section-kicker, .empty-kicker { color: var(--accent-strong); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.comic-copy { min-width: 0; }
.comic-copy h1 { max-width: 12em; margin: 13px 0 12px; overflow-wrap: anywhere; font-family: Georgia, "Songti SC", serif; font-size: clamp(32px, 5vw, 58px); line-height: 1.08; font-weight: 700; }
.comic-author { margin: 0 0 24px; color: var(--muted); font-size: 13px; }
.comic-description { display: -webkit-box; max-width: 54ch; margin: 0 0 30px; overflow: hidden; color: #c2c3bd; font-size: 14px; line-height: 1.8; -webkit-box-orient: vertical; -webkit-line-clamp: 4; }
.primary-button { min-height: 48px; padding: 0 19px; border: 0; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; background: var(--accent); color: white; font-weight: 750; cursor: pointer; }
.primary-button:hover { background: var(--accent-strong); }
.primary-button:disabled { opacity: 0.4; cursor: wait; }
.primary-button svg { width: 18px; }
.comic-actions { max-width: 420px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.comic-actions .secondary-button { padding: 0 14px; }

.chapter-section { padding: 42px clamp(20px, 6vw, 72px) 90px; border-top: 1px solid var(--line); }
.section-heading, .sheet-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.section-heading h2, .sheet-heading h2 { margin: 5px 0 0; font: 700 23px Georgia, "Songti SC", serif; }
.chapter-order-button { min-width: 72px; height: 36px; padding: 0 11px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); display: inline-flex; align-items: center; justify-content: center; gap: 7px; color: var(--muted); font-size: 11px; cursor: pointer; }
.chapter-order-button:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.24); }
.chapter-order-button svg { width: 14px; height: 14px; }
.chapter-list { margin-top: 25px; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 5px; }
.chapter-item { position: relative; width: 100%; min-width: 0; min-height: 42px; padding: 5px 7px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); display: flex; align-items: center; justify-content: center; text-align: center; cursor: pointer; }
.chapter-item:hover { border-color: rgba(255, 255, 255, 0.24); background: var(--surface-raised); }
.chapter-item:active { transform: translateY(1px); }
.chapter-name { width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 650; text-align: center; }
.chapter-progress { position: absolute; top: 2px; right: 3px; color: var(--muted); font-size: 7px; }
.chapter-item.is-read { background: transparent; }
.chapter-item.is-read .chapter-name { color: var(--muted); font-weight: 500; }
.chapter-item.is-volume .chapter-name,
.chapter-item.is-volume.is-read .chapter-name { color: var(--accent); font-weight: 750; }

.empty-state { min-height: calc(100dvh - 68px); padding: 80px 24px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; max-width: 640px; margin: auto; }
.empty-state h1 { margin: 12px 0; font: 700 clamp(34px, 8vw, 64px)/1.08 Georgia, "Songti SC", serif; }
.empty-state p { color: var(--muted); line-height: 1.7; margin: 0 0 28px; }

.reader-view { position: fixed; inset: 0; z-index: 50; background: #111212; color: #f5f4ef; overflow: hidden; }
.reader-view.theme-black { background: #000; }
.reader-view.theme-paper { background: #d9d6cd; }
.reader-toolbar { position: absolute; z-index: 20; left: 0; right: 0; display: flex; align-items: center; background: rgba(12, 13, 13, 0.88); backdrop-filter: blur(18px); transition: opacity 180ms ease, transform 180ms ease; }
.reader-topbar { top: 0; min-height: calc(58px + var(--safe-top)); padding: var(--safe-top) 10px 0; display: grid; grid-template-columns: 44px minmax(0, 1fr) 88px; border-bottom: 1px solid rgba(255,255,255,.1); }
.offline-reader-topbar { grid-template-columns: 44px minmax(0, 1fr) 44px; }
.reader-bottombar { bottom: 0; min-height: calc(58px + var(--safe-bottom)); padding: 0 12px var(--safe-bottom); justify-content: space-between; border-top: 1px solid rgba(255,255,255,.1); }
.offline-reader-bottombar { justify-content: center; }
.reader-icon { flex: 0 0 44px; }
.reader-toolbar-actions { display: flex; align-items: center; }
.reader-title { min-width: 0; flex: 1; padding: 5px 8px; border: 0; background: transparent; text-align: center; display: grid; gap: 2px; cursor: pointer; }
.reader-title strong, .reader-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-title strong { font-size: 12px; }
.reader-title span { color: #a7a9a4; font-size: 10px; }
.reader-view.chrome-hidden .reader-topbar { opacity: 0; transform: translateY(-100%); pointer-events: none; }
.reader-view.chrome-hidden .reader-bottombar { opacity: 0; transform: translateY(100%); pointer-events: none; }
.chapter-nav-button { height: 42px; min-width: 84px; padding: 0 8px; border: 0; background: transparent; display: flex; align-items: center; gap: 6px; font-size: 11px; cursor: pointer; }
.chapter-nav-button:disabled { color: #555; }
.chapter-nav-button svg { width: 16px; }
.page-progress { display: flex; align-items: baseline; gap: 4px; font-size: 10px; color: #92948f; }
.page-progress strong { color: white; font: 700 18px Georgia, serif; }

.pages-viewport { position: absolute; inset: 0; overflow: auto; overscroll-behavior: contain; scrollbar-width: none; }
.pages-viewport::-webkit-scrollbar { display: none; }
.pages { min-height: 100%; }
.mode-paged { overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scroll-snap-type: none; direction: rtl; touch-action: pinch-zoom; display: flex; align-items: center; }
.mode-paged.mode-click { overflow-x: hidden; }
.mode-paged .pages { flex: 0 0 auto; width: max-content; min-width: 100%; min-height: 0; height: var(--horizontal-page-height, 70vh); display: flex; flex-direction: row; align-items: stretch; gap: var(--page-gap); }
.mode-paged .comic-page { flex: 0 0 auto; height: 100%; aspect-ratio: var(--page-aspect, 2 / 3); display: grid; place-items: center; direction: ltr; }
.mode-paged .comic-page img { display: block; width: 100%; height: 100%; max-width: none; max-height: none; object-fit: contain; }
.mode-paged .tap-zone { touch-action: pinch-zoom; }
.mode-vertical { scroll-snap-type: none; direction: ltr; }
.mode-vertical .pages { width: min(100%, 1100px); margin: 0 auto; padding: 0; }
.mode-vertical .comic-page { min-height: 30vh; margin-bottom: var(--page-gap); display: grid; place-items: center; }
.mode-vertical .comic-page img { display: block; width: 100%; height: auto; }
.comic-page { position: relative; margin: 0; }
.page-placeholder { width: 46px; height: 46px; border: 2px solid rgba(255,255,255,.16); border-top-color: var(--accent); border-radius: 50%; animation: spin 800ms linear infinite; }
.comic-page.is-loaded .page-placeholder { display: none; }
.comic-page.is-error::after { content: "图片载入失败\A点按重试"; white-space: pre; color: #999; text-align: center; font-size: 12px; line-height: 1.8; }
.comic-page.is-error .page-placeholder { display: none; }
.tap-zone { position: fixed; z-index: 8; border: 0; background: transparent; padding: 0; }
.tap-zone-forward { left: 0; top: 18%; bottom: 18%; width: 32%; }
.tap-zone-back { right: 0; top: 18%; bottom: 18%; width: 32%; }
.tap-zone-center { left: 34%; right: 34%; top: 20%; bottom: 20%; }
.mode-vertical .tap-zone-forward, .mode-vertical .tap-zone-back { display: none; }

.scrim { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.58); backdrop-filter: blur(3px); }
.bottom-sheet { position: fixed; z-index: 90; left: 0; right: 0; bottom: 0; max-width: 620px; margin: auto; padding: 9px 22px calc(24px + var(--safe-bottom)); background: #1b1d1c; border-top: 1px solid var(--line); box-shadow: 0 -24px 70px rgba(0,0,0,.4); }
.sheet-handle { width: 38px; height: 4px; margin: 0 auto 17px; border-radius: 2px; background: #4f514e; }
.sheet-heading { margin-bottom: 26px; }
.sheet-close { margin-right: -10px; }
form label, .setting-label { display: block; color: #c5c6c1; font-size: 12px; font-weight: 650; }
.url-field { height: 52px; margin: 9px 0 7px; padding: 0 14px; border: 1px solid var(--line); border-radius: 6px; display: flex; align-items: center; gap: 10px; background: #101111; }
.url-field:focus-within { border-color: var(--accent); }
.url-field svg { width: 18px; color: var(--muted); }
.url-field input { width: 100%; min-width: 0; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 14px; }
.form-error { min-height: 20px; margin: 0 0 10px; color: #ff8b78; font-size: 11px; }
.full-width { width: 100%; }
.library-switcher-sheet { max-height: min(72dvh, 640px); }
.reader-library-list { max-height: min(48dvh, 430px); margin: -6px 0 14px; overflow-y: auto; border-top: 1px solid var(--line); }
.reader-library-item { width: 100%; min-height: 70px; padding: 8px 2px; border: 0; border-bottom: 1px solid var(--line); background: transparent; display: grid; grid-template-columns: 38px minmax(0, 1fr) 24px; align-items: center; gap: 11px; text-align: left; cursor: pointer; }
.reader-library-item.is-active { color: var(--accent-strong); }
.reader-library-thumb { width: 38px; aspect-ratio: 2 / 3; overflow: hidden; display: block; background: var(--surface-raised); }
.reader-library-thumb img { width: 100%; height: 100%; display: block; object-fit: cover; }
.reader-library-copy { min-width: 0; display: grid; gap: 4px; }
.reader-library-copy strong, .reader-library-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-library-copy strong { color: var(--text); font-size: 12px; }
.reader-library-copy span { color: var(--muted); font-size: 9px; }
.reader-library-item > svg { width: 15px; justify-self: end; }
.setting-group { padding: 17px 0; border-top: 1px solid var(--line); }
.setting-group:last-child { padding-bottom: 0; }
.setting-row { display: flex; justify-content: space-between; align-items: center; }
.setting-row output { color: var(--muted); font-size: 11px; }
.auto-speed-row { margin-top: 18px; }
.segmented-control { height: 44px; margin-top: 11px; padding: 3px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); background: #101111; border-radius: 6px; }
.segmented-control button { border: 0; border-radius: 4px; background: transparent; display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 12px; cursor: pointer; }
.segmented-control button[aria-pressed="true"] { background: #333633; }
.segmented-control svg { width: 16px; }
@media (max-width: 430px) {
  .segmented-control button { gap: 5px; font-size: 11px; }
  .segmented-control svg { width: 15px; }
}
.range-control { width: 100%; margin: 16px 0 0; accent-color: var(--accent); }
.range-control:disabled { opacity: .35; }
.switch-control { -webkit-appearance: none; appearance: none; width: 42px; height: 24px; margin: 0; padding: 2px; border: 1px solid var(--line); border-radius: 12px; background: #101111; cursor: pointer; transition: background 160ms ease, border-color 160ms ease; }
.switch-control::before { content: ""; display: block; width: 18px; height: 18px; border-radius: 50%; background: #d8d8d3; transition: transform 160ms ease; }
.switch-control:checked { border-color: var(--accent); background: var(--accent); }
.switch-control:checked::before { transform: translateX(17px); background: #fff; }
.switch-control:disabled { opacity: .35; cursor: default; }
.swatch-control { display: flex; gap: 12px; margin-top: 13px; }
.swatch { width: 38px; height: 38px; border: 2px solid transparent; border-radius: 50%; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(255,255,255,.15); }
.swatch[aria-pressed="true"] { border-color: var(--accent-strong); }
.swatch.ink { background: #111212; }.swatch.black { background: #000; }.swatch.paper { background: #d9d6cd; }

.loading-overlay { position: fixed; inset: 0; z-index: 120; display: grid; place-content: center; justify-items: center; gap: 14px; background: rgba(10,11,11,.84); backdrop-filter: blur(10px); }
.loading-overlay strong { font-size: 12px; }
.loading-spinner { width: 34px; height: 34px; border: 2px solid rgba(255,255,255,.18); border-top-color: var(--accent); border-radius: 50%; animation: spin 800ms linear infinite; }
.toast { position: fixed; z-index: 130; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 11px 15px; border-radius: 6px; background: #f0efe9; color: #171817; box-shadow: 0 12px 36px rgba(0,0,0,.35); font-size: 12px; text-align: center; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 680px) {
  .library-screen { padding: 28px 16px 64px; }
  .comic-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px 12px; }
  .library-card > strong { font-size: 12px; }
  .detail-nav { padding: 10px 20px 0; }
  .comic-detail { min-height: auto; padding: 32px 20px 42px; grid-template-columns: minmax(118px, 38vw) minmax(0, 1fr); align-items: end; gap: 20px; }
  .comic-copy h1 { margin-top: 8px; font-size: 25px; line-height: 1.16; }
  .comic-author { margin-bottom: 18px; }
  .comic-description { grid-column: 1 / -1; display: none; }
  .comic-actions { width: 100%; gap: 5px; }
  .comic-actions .primary-button, .comic-actions .secondary-button { width: 100%; min-height: 44px; padding: 0 6px; font-size: 10px; }
  .chapter-section { padding: 30px 20px 70px; }
  .chapter-list { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  .chapter-item { min-height: 38px; padding: 4px 5px; }
  .chapter-name { font-size: 10px; }
  .bottom-sheet { border-radius: 8px 8px 0 0; }
}

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