:root {
  --bg: #eee8dc;
  --bg-deep: #e2d8c7;
  --surface: #fbf8f1;
  --surface-strong: #fffdf8;
  --surface-soft: #f4eee3;
  --text: #272a2d;
  --muted: #7c7469;
  --muted-2: #a49b8e;
  --border: rgba(74, 61, 46, .13);
  --border-strong: rgba(74, 61, 46, .23);
  --accent: #ae5b3d;
  --accent-deep: #83432f;
  --accent-soft: #f2dfd4;
  --green: #597363;
  --danger: #a74242;
  --shadow-sm: 0 5px 16px rgba(72, 54, 37, .07);
  --shadow-md: 0 18px 50px rgba(72, 54, 37, .12);
  --radius-sm: 10px;
  --radius-md: 18px;
  --radius-lg: 28px;
  --reader-bg: #f4efe5;
  --reader-surface: #fbf8f1;
  --reader-text: #292723;
  --reader-muted: #81786b;
  --reader-border: rgba(71, 59, 46, .14);
  --reader-font: "Noto Serif CJK SC", "Source Han Serif SC", "Noto Serif SC", "Songti SC", SimSun, serif;
  --reader-font-size: 19px;
  --reader-line-height: 1.85;
  --reader-width: 760px;
  --reader-indent: 2em;
  color-scheme: light;
}

[data-reader-theme="sepia"] {
  --reader-bg: #eadcc2;
  --reader-surface: #f2e6ce;
  --reader-text: #3f3325;
  --reader-muted: #7d6c55;
  --reader-border: rgba(80, 60, 36, .17);
}

[data-reader-theme="dark"] {
  --reader-bg: #202528;
  --reader-surface: #282e32;
  --reader-text: #dce0dc;
  --reader-muted: #98a19f;
  --reader-border: rgba(224, 232, 228, .12);
  color-scheme: dark;
}

[data-reader-theme="black"] {
  --reader-bg: #090a0b;
  --reader-surface: #101213;
  --reader-text: #d5d7d4;
  --reader-muted: #929693;
  --reader-border: rgba(226, 231, 228, .11);
  color-scheme: dark;
}

[data-reader-font="sans"] {
  --reader-font: "Noto Sans CJK SC", "Source Han Sans SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

[data-reader-font="system"] {
  --reader-font: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: "Noto Sans CJK SC", "Source Han Sans SC", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select { font: inherit; }
button { color: inherit; }
button, select { cursor: pointer; }
svg { width: 1.2em; height: 1.2em; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
.visually-hidden { position: fixed !important; width: 1px !important; height: 1px !important; overflow: hidden !important; clip: rect(0 0 0 0) !important; white-space: nowrap !important; }
.toolbar-spacer { flex: 1; }

.view { min-height: 100dvh; }
.shelf-view {
  background:
    radial-gradient(circle at 12% 8%, rgba(255,255,255,.75), transparent 31%),
    radial-gradient(circle at 88% 20%, rgba(190, 148, 111, .14), transparent 28%),
    linear-gradient(180deg, #f0eadf 0%, #eae1d4 100%);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 84px;
  padding: 15px max(22px, calc((100vw - 1500px) / 2));
  background: rgba(244, 239, 230, .88);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.brand, .header-actions, .brand-mark, .privacy-pill, .button, .icon-button,
.search-field, .compact-field, .segmented, .panel-header, .modal-header,
.setting-title-row, .switch-row, .toolbar-spacer, .reader-heading,
.reader-progress-text, .panel-footer, .chapter-nav, .detail-stats { display: flex; align-items: center; }

.brand { gap: 13px; min-width: 0; }
.brand-mark {
  justify-content: center;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  color: var(--accent);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 15px;
  box-shadow: var(--shadow-sm);
}
.brand-mark svg { width: 31px; height: 31px; stroke-width: 1.6; }
.brand h1 { margin: 0; font-family: var(--reader-font); font-size: 21px; letter-spacing: .04em; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.header-actions { gap: 11px; margin-left: auto; }

.privacy-pill {
  gap: 6px;
  padding: 8px 11px;
  color: var(--green);
  background: rgba(89, 115, 99, .09);
  border: 1px solid rgba(89, 115, 99, .15);
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}
.privacy-pill svg { width: 15px; height: 15px; }

.button, .icon-button, .text-button {
  border: 0;
  background: none;
  transition: transform .16s ease, background .16s ease, color .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.button {
  justify-content: center;
  gap: 8px;
  min-height: 43px;
  padding: 10px 17px;
  border-radius: 12px;
  font-weight: 650;
  font-size: 14px;
  white-space: nowrap;
}
.button svg { width: 18px; height: 18px; }
.button:hover, .icon-button:hover { transform: translateY(-1px); }
.button:active, .icon-button:active { transform: translateY(0); }
.button.primary { color: #fffaf5; background: var(--accent); box-shadow: 0 8px 19px rgba(174, 91, 61, .2); }
.button.primary:hover { background: var(--accent-deep); }
.button.secondary { color: var(--text); background: var(--surface-strong); border: 1px solid var(--border-strong); }
.button.secondary:hover { background: var(--surface-soft); }
.button.danger { color: var(--danger); background: rgba(167, 66, 66, .08); border: 1px solid rgba(167, 66, 66, .16); }
.button.danger:hover { color: #fff; background: var(--danger); }
.button[disabled] { opacity: .42; cursor: not-allowed; transform: none; }
.icon-button {
  justify-content: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 12px;
  color: var(--muted);
}
.icon-button:hover { background: rgba(84, 68, 51, .08); color: var(--text); }
.icon-button svg { width: 20px; height: 20px; }
.text-button { padding: 3px 0; color: var(--accent); font-size: 13px; font-weight: 650; }
.text-button:hover { color: var(--accent-deep); text-decoration: underline; }

.shelf-main { width: min(1500px, calc(100% - 44px)); margin: 0 auto; padding: 42px 0 80px; }
.library-hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 40px;
  padding: 35px 38px;
  overflow: hidden;
  position: relative;
  background: linear-gradient(125deg, rgba(255,253,248,.92), rgba(245,235,222,.82));
  border: 1px solid rgba(87, 68, 49, .11);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.library-hero::after {
  content: "";
  position: absolute;
  width: 300px;
  height: 300px;
  right: -90px;
  top: -150px;
  border: 42px solid rgba(174, 91, 61, .055);
  border-radius: 50%;
  pointer-events: none;
}
.eyebrow { color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
.library-hero h2 { max-width: 670px; margin: 9px 0 9px; font-family: var(--reader-font); font-size: clamp(25px, 3vw, 39px); line-height: 1.35; letter-spacing: .01em; }
.library-hero p { max-width: 700px; margin: 0; color: var(--muted); font-size: 14px; line-height: 1.8; }
.hero-stats { display: flex; gap: 28px; padding-bottom: 4px; }
.hero-stats div { min-width: 67px; text-align: center; }
.hero-stats strong { display: block; font-family: var(--reader-font); font-size: 29px; font-weight: 700; }
.hero-stats span { color: var(--muted); font-size: 11px; }

.shelf-toolbar { display: flex; align-items: center; gap: 12px; margin: 30px 0 18px; }
.search-field, .toc-search {
  gap: 8px;
  min-width: 240px;
  padding: 0 13px;
  background: rgba(255,253,248,.77);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.search-field:focus-within, .toc-search:focus-within { background: var(--surface-strong); border-color: rgba(174, 91, 61, .42); box-shadow: 0 0 0 3px rgba(174, 91, 61, .08); }
.search-field svg, .toc-search svg { width: 17px; height: 17px; color: var(--muted-2); flex: 0 0 auto; }
.search-field input, .toc-search input { width: 100%; height: 43px; border: 0; outline: 0; background: none; color: var(--text); }
.compact-field { gap: 7px; padding: 0 10px; height: 43px; color: var(--muted); background: rgba(255,253,248,.65); border: 1px solid var(--border); border-radius: 12px; font-size: 12px; }
.compact-field select { border: 0; outline: 0; color: var(--text); background: transparent; font-size: 13px; }
.segmented { gap: 3px; padding: 4px; background: rgba(255,253,248,.66); border: 1px solid var(--border); border-radius: 12px; }
.segmented button { display: flex; align-items: center; justify-content: center; min-width: 34px; height: 33px; padding: 0 8px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; font-size: 13px; }
.segmented button.active { color: var(--text); background: var(--surface-strong); box-shadow: 0 2px 7px rgba(71, 54, 37, .09); }
.segmented svg { width: 16px; height: 16px; }

.drop-zone { position: relative; min-height: 330px; border-radius: var(--radius-md); transition: background .18s ease, outline .18s ease; }
.drop-zone.dragover { background: rgba(174, 91, 61, .065); outline: 2px dashed rgba(174, 91, 61, .5); outline-offset: 12px; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 22px; }
.book-grid.list-mode { grid-template-columns: 1fr; gap: 11px; }

.book-card {
  position: relative;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255,253,248,.76);
  box-shadow: 0 8px 25px rgba(70, 52, 35, .05);
  cursor: pointer;
  overflow: hidden;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease, background .2s ease;
}
.book-card:hover { transform: translateY(-4px); border-color: rgba(174, 91, 61, .27); box-shadow: var(--shadow-md); background: var(--surface-strong); }
.book-cover { position: relative; aspect-ratio: 3 / 4.15; overflow: hidden; background: linear-gradient(145deg, var(--cover-a, #c77856), var(--cover-b, #6d635c)); }
.book-cover::before { content: ""; position: absolute; inset: 0; background: linear-gradient(110deg, rgba(255,255,255,.2), transparent 34%, rgba(0,0,0,.12)); }
.book-cover::after { content: ""; position: absolute; inset: 16px; border: 1px solid rgba(255,255,255,.3); border-radius: 8px; }
.book-cover-inner { position: relative; z-index: 1; display: flex; height: 100%; flex-direction: column; justify-content: space-between; padding: 42px 28px 27px; color: #fff; }
.book-cover .book-title { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 4; font-family: var(--reader-font); font-size: clamp(18px, 2vw, 27px); font-weight: 700; line-height: 1.45; text-shadow: 0 2px 12px rgba(0,0,0,.18); }
.book-cover .book-author { overflow: hidden; color: rgba(255,255,255,.76); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.book-cover .spine { position: absolute; left: 10px; top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,.24); }
.book-cover .cover-mark { position: absolute; right: 25px; bottom: 24px; opacity: .3; font-family: var(--reader-font); font-size: 52px; font-weight: 800; }
.book-card-body { padding: 14px 15px 15px; }
.book-card-title { overflow: hidden; margin: 0; font-size: 15px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.book-card-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 7px; color: var(--muted); font-size: 11px; }
.book-progress { height: 4px; margin-top: 12px; overflow: hidden; background: rgba(90, 72, 54, .1); border-radius: 99px; }
.book-progress span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; }
.book-actions { position: absolute; z-index: 2; top: 10px; right: 10px; display: flex; gap: 5px; opacity: 0; transform: translateY(-4px); transition: .18s ease; }
.book-card:hover .book-actions, .book-card:focus-within .book-actions { opacity: 1; transform: none; }
.book-actions .icon-button { width: 34px; height: 34px; flex-basis: 34px; color: #fff; background: rgba(25, 22, 19, .5); backdrop-filter: blur(7px); }
.book-actions .icon-button:hover { color: #fff; background: rgba(25, 22, 19, .72); }
.book-actions svg { width: 16px; height: 16px; }

.book-grid.list-mode .book-card { display: grid; grid-template-columns: 82px 1fr; min-height: 105px; }
.book-grid.list-mode .book-cover { aspect-ratio: auto; min-height: 105px; }
.book-grid.list-mode .book-cover-inner { padding: 20px 13px; }
.book-grid.list-mode .book-title { -webkit-line-clamp: 2; font-size: 14px; }
.book-grid.list-mode .book-author, .book-grid.list-mode .cover-mark { display: none; }
.book-grid.list-mode .book-card-body { display: flex; flex-direction: column; justify-content: center; padding: 18px 22px; }
.book-grid.list-mode .book-card-title { font-size: 17px; }
.book-grid.list-mode .book-progress { max-width: 330px; }

.empty-state { min-height: 330px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px; text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--radius-md); }
.empty-illustration { width: min(260px, 70vw); color: var(--accent); }
.empty-illustration svg { width: 100%; height: auto; stroke-width: 2.2; }
.empty-illustration .shelf-line { stroke: var(--border-strong); }
.empty-illustration .spark { color: #c99445; }
.empty-state h3 { margin: 13px 0 6px; font-family: var(--reader-font); font-size: 23px; }
.empty-state p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }

.reader-view { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; background: var(--reader-bg); color: var(--reader-text); }
.reader-header { z-index: 10; display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 8px 18px; color: var(--reader-text); background: color-mix(in srgb, var(--reader-surface) 91%, transparent); border-bottom: 1px solid var(--reader-border); backdrop-filter: blur(15px); }
.reader-header .icon-button { color: var(--reader-muted); }
.reader-header .icon-button:hover { color: var(--reader-text); background: color-mix(in srgb, var(--reader-text) 8%, transparent); }
.reader-heading { min-width: 0; flex-direction: column; align-items: flex-start; gap: 2px; }
.reader-heading strong { max-width: min(45vw, 560px); overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.reader-heading span { max-width: min(45vw, 560px); overflow: hidden; color: var(--reader-muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.reader-progress-text { margin-left: auto; color: var(--reader-muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.reader-progress-track { z-index: 12; height: 2px; background: transparent; }
.reader-progress-track div { height: 100%; width: 0; background: var(--accent); transition: width .16s linear; }
.reader-layout { position: relative; display: flex; min-height: 0; flex: 1; }
.reading-pane { min-width: 0; flex: 1; overflow: auto; scroll-behavior: auto; overscroll-behavior: contain; }
.chapter-article { width: min(var(--reader-width), calc(100% - 64px)); margin: 0 auto; padding: clamp(48px, 8vh, 96px) 0 110px; }
.chapter-article > h1 { margin: 0 0 3.1em; color: var(--reader-text); font-family: var(--reader-font); font-size: clamp(25px, 3vw, 36px); font-weight: 700; line-height: 1.45; text-align: center; letter-spacing: .035em; }
.chapter-article > h1::after { content: ""; display: block; width: 54px; height: 2px; margin: 22px auto 0; background: var(--accent); opacity: .7; }
.chapter-body { color: var(--reader-text); font-family: var(--reader-font); font-size: var(--reader-font-size); line-height: var(--reader-line-height); text-align: justify; overflow-wrap: break-word; }
.chapter-body p { margin: 0 0 .92em; text-indent: var(--reader-indent); }
.chapter-body p.separator { margin: 1.4em 0 1.6em; color: var(--reader-muted); text-align: center; text-indent: 0; letter-spacing: .5em; }
.chapter-body p.lead { text-indent: 0; }
.chapter-end { margin-top: 5em; padding-top: 28px; color: var(--reader-muted); border-top: 1px solid var(--reader-border); text-align: center; font-size: 12px; }
.chapter-nav { justify-content: center; gap: 12px; margin-top: 17px; }
.chapter-nav .button { min-width: 110px; }

.toc-panel, .settings-panel { z-index: 7; display: flex; width: 300px; flex: 0 0 300px; flex-direction: column; min-height: 0; color: var(--reader-text); background: var(--reader-surface); border-right: 1px solid var(--reader-border); transition: margin-left .22s ease; }
.settings-panel { position: absolute; right: 0; top: 0; bottom: 0; margin-right: -301px; border-right: 0; border-left: 1px solid var(--reader-border); box-shadow: -12px 0 35px rgba(30, 24, 18, .08); }
.settings-panel.open { margin-right: 0; }
.toc-panel { position: relative; margin-left: 0; }
.toc-panel.closed { margin-left: -301px; }
.panel-header { min-height: 66px; justify-content: space-between; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--reader-border); }
.panel-header .eyebrow { font-size: 9px; }
.panel-header h2 { margin: 3px 0 0; font-size: 17px; }
.panel-header .icon-button { width: 36px; height: 36px; flex-basis: 36px; }
.toc-search { margin: 12px 14px 9px; background: color-mix(in srgb, var(--reader-text) 4%, transparent); border-color: var(--reader-border); }
.toc-search input { height: 38px; color: var(--reader-text); }
.toc-list { min-height: 0; flex: 1; overflow: auto; padding: 4px 9px 14px; }
.toc-volume { padding: 16px 10px 7px; color: var(--reader-muted); font-size: 10px; font-weight: 800; letter-spacing: .12em; }
.toc-item { display: block; width: 100%; padding: 9px 10px; overflow: hidden; border: 0; border-radius: 9px; color: var(--reader-text); background: transparent; font-size: 12.5px; line-height: 1.35; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.toc-item:hover { background: color-mix(in srgb, var(--reader-text) 6%, transparent); }
.toc-item.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 11%, transparent); font-weight: 700; }
.panel-footer { display: flex; align-items: center; justify-content: space-between; padding: 12px 15px; color: var(--reader-muted); border-top: 1px solid var(--reader-border); font-size: 11px; }
.settings-panel .panel-header { padding-right: 13px; }
.setting-group { padding: 17px 17px 9px; }
.setting-group > label, .setting-title-row label { color: var(--reader-text); font-size: 13px; font-weight: 650; }
.setting-title-row { justify-content: space-between; margin-bottom: 13px; }
.setting-title-row output { color: var(--reader-muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.setting-group input[type="range"] { width: 100%; accent-color: var(--accent); }
.theme-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 11px; }
.theme-swatch { display: flex; align-items: center; gap: 7px; padding: 9px; border: 1px solid var(--reader-border); border-radius: 10px; color: var(--reader-text); background: transparent; font-size: 12px; }
.theme-swatch span { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(0,0,0,.12); }
.theme-swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 12%, transparent); }
.theme-paper span { background: #f4efe5; } .theme-sepia span { background: #eadcc2; } .theme-dark span { background: #202528; } .theme-black span { background: #090a0b; }
.setting-segmented { display: grid; grid-template-columns: 1fr 1fr 1fr; margin-top: 10px; }
.setting-segmented button { min-width: 0; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding-top: 14px; padding-bottom: 17px; }
.switch-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.setting-hint { margin: auto 17px 20px; padding: 12px; color: var(--reader-muted); background: color-mix(in srgb, var(--reader-text) 4%, transparent); border-radius: 11px; font-size: 11px; line-height: 1.65; }
.panel-scrim { display: none; position: absolute; z-index: 6; inset: 0; background: rgba(12, 11, 10, .35); opacity: 0; transition: opacity .2s ease; }

.modal-overlay { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(35, 29, 23, .35); backdrop-filter: blur(7px); }
.modal { width: min(520px, 100%); color: var(--text); background: var(--surface-strong); border: 1px solid var(--border); border-radius: 22px; box-shadow: 0 28px 80px rgba(33, 24, 17, .24); }
.import-modal { padding: 34px; text-align: center; }
.modal-icon { display: grid; place-items: center; width: 58px; height: 58px; margin: 0 auto 17px; color: var(--accent); background: var(--accent-soft); border-radius: 18px; }
.modal-icon svg { width: 28px; height: 28px; }
.import-modal h2, .detail-modal h2 { margin: 0; font-family: var(--reader-font); }
.import-modal p { margin: 10px 0 20px; color: var(--muted); font-size: 13px; }
.import-progress { height: 7px; overflow: hidden; background: rgba(92, 73, 56, .11); border-radius: 99px; }
.import-progress div { height: 100%; width: 4%; background: var(--accent); border-radius: inherit; transition: width .2s ease; }
.detail-modal { padding: 25px; }
.modal-header { justify-content: space-between; gap: 14px; margin-bottom: 21px; }
.detail-modal label { display: block; margin: 15px 0 0; color: var(--muted); font-size: 12px; }
.detail-modal input { width: 100%; height: 44px; margin-top: 7px; padding: 0 12px; outline: 0; color: var(--text); background: var(--surface-soft); border: 1px solid var(--border); border-radius: 11px; }
.detail-modal input:focus { border-color: rgba(174, 91, 61, .45); box-shadow: 0 0 0 3px rgba(174, 91, 61, .08); }
.detail-stats { flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.detail-stats span { padding: 6px 9px; color: var(--muted); background: var(--surface-soft); border-radius: 8px; font-size: 11px; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 25px; }

.toast { position: fixed; z-index: 200; left: 50%; bottom: 26px; max-width: min(520px, calc(100vw - 32px)); padding: 11px 16px; color: #fff; background: rgba(35, 31, 27, .92); border-radius: 12px; box-shadow: 0 12px 35px rgba(0,0,0,.18); opacity: 0; transform: translate(-50%, 14px); pointer-events: none; transition: .22s ease; font-size: 13px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.mobile-only { display: none; }

@media (max-width: 980px) {
  .app-header { padding: 13px 18px; }
  .privacy-pill { display: none; }
  .shelf-main { width: min(100% - 28px, 1500px); padding-top: 25px; }
  .library-hero { align-items: flex-start; flex-direction: column; padding: 28px 25px; }
  .hero-stats { width: 100%; justify-content: space-around; }
  .toc-panel { position: absolute; top: 0; bottom: 0; left: 0; box-shadow: 12px 0 35px rgba(30,24,18,.12); }
  .mobile-only { display: flex; }
  .panel-scrim.show { display: block; opacity: 1; }
  .chapter-article { width: min(var(--reader-width), calc(100% - 38px)); padding-top: 52px; }
}

@media (max-width: 680px) {
  .brand-mark { width: 43px; height: 43px; flex-basis: 43px; }
  .brand h1 { font-size: 18px; }
  .brand p { display: none; }
  .header-actions .button { min-height: 40px; padding: 9px 12px; }
  .library-hero h2 { font-size: 25px; }
  .hero-stats { gap: 12px; }
  .shelf-toolbar { flex-wrap: wrap; }
  .search-field { width: 100%; min-width: 0; }
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
  .book-cover-inner { padding: 28px 18px 20px; }
  .book-cover .book-title { font-size: 18px; }
  .book-cover::after { inset: 11px; }
  .book-card-body { padding: 12px; }
  .book-card-title { font-size: 13px; }
  .book-card-meta { font-size: 10px; }
  .reader-heading strong, .reader-heading span { max-width: 35vw; }
  .reader-progress-text { display: none; }
  .toc-panel, .settings-panel { width: min(86vw, 330px); flex-basis: min(86vw, 330px); }
  .settings-panel { margin-right: min(-86vw, -331px); }
  .chapter-article { width: calc(100% - 30px); padding-bottom: 70px; }
  .chapter-article > h1 { margin-bottom: 2.3em; font-size: 25px; }
  .chapter-nav { flex-direction: column; }
  .chapter-nav .button { width: 100%; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .toolbar-spacer { display: none; }
}

/* Mobile sync additions */
.button.ghost-header {
  color: var(--text);
  background: rgba(255, 253, 248, .6);
  border: 1px solid var(--border);
}
.button.ghost-header:hover { background: var(--surface-strong); }
.sync-pill { gap: 7px; }
.sync-dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: #c99445; box-shadow: 0 0 0 3px rgba(201,148,69,.12); }
.sync-pill.online { color: var(--green); background: rgba(89,115,99,.09); border-color: rgba(89,115,99,.15); }
.sync-pill.online .sync-dot { background: #5b8b6a; box-shadow: 0 0 0 3px rgba(91,139,106,.13); }
.sync-pill.offline { color: var(--danger); background: rgba(167,66,66,.07); border-color: rgba(167,66,66,.13); }
.sync-pill.offline .sync-dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(167,66,66,.11); }
.access-modal { width: min(440px, 100%); padding: 32px; text-align: center; }
.access-modal h2 { margin: 7px 0 8px; font-family: var(--reader-font); font-size: 25px; }
.access-modal > p { margin: 0 0 20px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.access-modal label { display: block; color: var(--muted); font-size: 12px; text-align: left; }
.access-modal input { width: 100%; height: 48px; margin: 8px 0 15px; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: 12px; outline: 0; color: var(--text); background: var(--surface-soft); text-align: center; font-size: 18px; letter-spacing: .08em; }
.access-modal input:focus { border-color: rgba(174,91,61,.5); box-shadow: 0 0 0 3px rgba(174,91,61,.09); }
.full-button { width: 100%; min-height: 46px; }
.access-error { min-height: 20px; margin: 12px 0 0 !important; color: var(--danger) !important; }
.connection-modal { padding: 25px; }
.connection-lead { margin: 0 0 18px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.connection-urls { display: grid; gap: 9px; }
.connection-url { display: block; padding: 11px 12px; overflow-wrap: anywhere; color: var(--text); background: var(--surface-soft); border: 1px solid var(--border); border-radius: 11px; text-decoration: none; font-size: 13px; }
.connection-url:hover { border-color: rgba(174,91,61,.34); color: var(--accent); }
.access-code-box { display: flex; align-items: center; gap: 10px; margin-top: 15px; padding: 12px; background: var(--surface-soft); border: 1px solid var(--border); border-radius: 11px; }
.access-code-box span { color: var(--muted); font-size: 12px; }
.access-code-box strong { margin-left: auto; font-size: 17px; letter-spacing: .08em; }
.install-guide { display: grid; gap: 5px; margin-top: 17px; padding: 13px; color: var(--muted); background: rgba(89,115,99,.07); border-radius: 11px; font-size: 11px; line-height: 1.6; }
.install-guide strong { color: var(--green); font-size: 12px; }
@media (max-width: 760px) {
  #connectionButton { display: none; }
  .sync-pill { padding: 7px 9px; }
  .sync-pill span:last-child { display: none; }
}

.connection-group-title { margin: 12px 0 -2px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .12em; }
.connection-note { margin-top: 12px; padding: 11px 12px; color: var(--muted); background: rgba(201,148,69,.08); border-radius: 10px; font-size: 11px; line-height: 1.65; }

.apk-download { margin-top: 18px; text-decoration: none; }

.android-apk-banner { display: none; align-items: center; gap: 12px; margin-bottom: 18px; padding: 13px 14px; color: #fffaf5; background: linear-gradient(135deg, #a95337, #83432f); border-radius: 14px; box-shadow: 0 10px 24px rgba(131,67,47,.2); text-decoration: none; }
.android-apk-banner svg { width: 28px; height: 28px; flex: 0 0 28px; }
.android-apk-banner span { display: flex; min-width: 0; flex: 1; flex-direction: column; }
.android-apk-banner strong { font-size: 14px; }
.android-apk-banner small { margin-top: 2px; color: rgba(255,255,255,.72); font-size: 10px; }
.android-apk-banner b { padding: 7px 11px; background: rgba(255,255,255,.16); border-radius: 9px; font-size: 12px; }
@media (max-width: 980px) { .android-apk-banner { display: flex; } }

/* Bookmarks */
.panel-tabs { display: flex; gap: 4px; padding: 10px 12px 0; }
.panel-tab { flex: 1; padding: 9px 8px; border: 0; border-bottom: 2px solid transparent; color: var(--reader-muted); background: transparent; font-size: 12px; font-weight: 700; }
.panel-tab.active { color: var(--reader-text); border-bottom-color: var(--accent); }
.tab-count { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; margin-left: 3px; padding: 0 5px; color: var(--reader-muted); background: color-mix(in srgb, var(--reader-text) 8%, transparent); border-radius: 99px; font-size: 10px; }
.panel-tab.active .tab-count { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.panel-section { display: flex; min-height: 0; flex: 1; flex-direction: column; }
.bookmark-list { min-height: 0; flex: 1; overflow: auto; padding: 11px 10px 18px; }
.bookmark-card { margin-bottom: 9px; padding: 11px; border: 1px solid var(--reader-border); border-radius: 12px; background: color-mix(in srgb, var(--reader-text) 3%, transparent); }
.bookmark-card-main { display: block; width: 100%; padding: 0; border: 0; color: var(--reader-text); background: transparent; text-align: left; }
.bookmark-card-main:hover .bookmark-card-title { color: var(--accent); }
.bookmark-card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 750; line-height: 1.4; }
.bookmark-card-title span:last-child { flex: 0 0 auto; color: var(--reader-muted); font-size: 9px; font-weight: 500; }
.bookmark-card-note { display: -webkit-box; overflow: hidden; margin: 7px 0 0; color: var(--reader-text); -webkit-box-orient: vertical; -webkit-line-clamp: 4; font-size: 12px; line-height: 1.55; white-space: pre-wrap; }
.bookmark-card-context { display: -webkit-box; overflow: hidden; margin: 7px 0 0; color: var(--reader-muted); -webkit-box-orient: vertical; -webkit-line-clamp: 2; font-size: 10px; line-height: 1.45; }
.bookmark-card-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.bookmark-card-actions button { padding: 0; border: 0; color: var(--reader-muted); background: transparent; font-size: 10px; }
.bookmark-card-actions button:hover { color: var(--accent); }
.bookmark-empty { padding: 34px 18px; color: var(--reader-muted); text-align: center; font-size: 12px; line-height: 1.65; }
.bookmark-location { margin-bottom: 9px; padding: 10px 12px; color: var(--accent); background: var(--surface-soft); border-radius: 10px; font-size: 12px; font-weight: 700; }
.bookmark-context { display: -webkit-box; overflow: hidden; margin-bottom: 16px; padding: 10px 12px; color: var(--muted); background: rgba(89, 115, 99, .07); border-radius: 10px; -webkit-box-orient: vertical; -webkit-line-clamp: 3; font-size: 11px; line-height: 1.6; }
.bookmark-modal { width: min(560px, 100%); padding: 25px; }
.bookmark-modal label { display: block; color: var(--muted); font-size: 12px; }
.bookmark-modal textarea { width: 100%; min-height: 120px; margin-top: 8px; padding: 12px; resize: vertical; outline: 0; color: var(--text); background: var(--surface-soft); border: 1px solid var(--border); border-radius: 11px; font: inherit; line-height: 1.6; }
.bookmark-modal textarea:focus { border-color: rgba(174, 91, 61, .45); box-shadow: 0 0 0 3px rgba(174, 91, 61, .08); }

/* Mobile reader action bar */
.mobile-reader-actions { display: none; }
@media (max-width: 980px) {
  #tocButton, #bookmarkButton, #bookmarksButton, #settingsButton { display: none !important; }
  .mobile-reader-actions {
    position: absolute;
    z-index: 5;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 2px;
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--reader-surface) 96%, transparent);
    border-top: 1px solid var(--reader-border);
    box-shadow: 0 -8px 24px rgba(28, 23, 18, .08);
    backdrop-filter: blur(16px);
  }
  .mobile-reader-actions button {
    display: flex;
    min-width: 0;
    min-height: 51px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 3px;
    padding: 5px 2px;
    border: 0;
    border-radius: 11px;
    color: var(--reader-muted);
    background: transparent;
  }
  .mobile-reader-actions button:active { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
  .mobile-reader-actions svg { width: 21px; height: 21px; }
  .mobile-reader-actions span { overflow: hidden; max-width: 100%; font-size: 10px; line-height: 1; text-overflow: ellipsis; white-space: nowrap; }
  .chapter-article { padding-bottom: calc(130px + env(safe-area-inset-bottom, 0px)); }
}
@media (min-width: 981px) {
  .mobile-reader-actions { display: none !important; }
}

/* mobile action no overlap fix */
@media (max-width: 980px) {
  .mobile-reader-actions {
    position: relative;
    inset: auto;
    z-index: auto;
    flex: 0 0 auto;
    padding-bottom: calc(10px + max(env(safe-area-inset-bottom, 0px), 8px));
  }
  .chapter-article { padding-bottom: 72px; }
}

.chapter-loading { padding: 22vh 0; color: var(--reader-muted); text-align: center; text-indent: 0; font-size: 13px; letter-spacing: .08em; }
