/* =========================================================
   行者书单阅读器 - Apple iOS 官网风格
   SF Pro 字体 / 大圆角 / 大留白 / 胶囊按钮 / 极淡阴影 / 单蓝点缀
   ========================================================= */

/* ============ 变量与主题 ============ */
:root {
  --bg: #fbfbfd;
  --bg-card: rgba(255, 255, 255, 0.72);
  --bg-card-solid: #ffffff;
  --bg-hover: #f5f5f7;
  --bg-side: rgba(245, 245, 247, 0.85);
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --primary: #0071e3;
  --primary-hover: #0077ed;
  --primary-weak: rgba(0, 113, 227, 0.08);
  --hl: rgba(255, 214, 10, 0.5);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
  --shadow-lift: 0 8px 28px rgba(0, 0, 0, 0.08);
  --reader-bg: #ffffff;
  --reader-text: #1d1d1f;
  --glass-blur: blur(24px) saturate(1.8);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-pill: 980px;
}
body.dark {
  --bg: #000000;
  --bg-card: rgba(28, 28, 30, 0.72);
  --bg-card-solid: #1c1c1e;
  --bg-hover: rgba(44, 44, 46, 0.8);
  --bg-side: rgba(22, 22, 24, 0.9);
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #f5f5f7;
  --text-2: #aeaeb2;
  --text-3: #8e8e93;
  --primary: #0a84ff;
  --primary-hover: #409cff;
  --primary-weak: rgba(10, 132, 255, 0.12);
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.4);
  --shadow-lift: 0 10px 34px rgba(0, 0, 0, 0.55);
  --reader-bg: #0e0e10;
  --reader-text: #e8e8ed;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "SF Pro Display", "SF Pro SC", "PingFang SC",
               "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  transition: background .4s ease, color .3s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}
.hidden { display: none !important; }

/* ============ 背景：极淡快速流动光带 ============ */
#bgGlow { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
#bgGlow::before, #bgGlow::after {
  content: ""; position: absolute; border-radius: 50%;
  filter: blur(100px); opacity: .35;
}
body.dark #bgGlow::before, body.dark #bgGlow::after { opacity: .25; }
#bgGlow::before {
  width: 52vw; height: 52vw; left: -10vw; top: -16vw;
  background: conic-gradient(from 0deg, #0071e3, #5ac8fa, #5e5ce6, #0071e3);
  animation: spin1 5s linear infinite;
}
#bgGlow::after {
  width: 46vw; height: 46vw; right: -8vw; bottom: -14vw;
  background: conic-gradient(from 180deg, #5ac8fa, #0071e3, #34c759, #5ac8fa);
  animation: spin2 6s linear infinite reverse;
}
@keyframes spin1 { to { transform: rotate(360deg); } }
@keyframes spin2 { to { transform: rotate(-360deg); } }

#topbar, .view, .toast { position: relative; z-index: 1; }

/* ============ 顶栏（毛玻璃导航条） ============ */
#topbar {
  height: 52px;
  display: flex; align-items: center; gap: 18px;
  padding: 0 22px;
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.brand-icon {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, #0071e3, #5ac8fa);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
}
.brand-name {
  font-weight: 600; font-size: 17px; letter-spacing: -0.02em; color: var(--text);
}
.view-tabs {
  display: flex; gap: 2px; border-radius: var(--radius-pill); padding: 3px;
  background: var(--bg-hover);
}
.view-tabs .tab {
  border: none; background: transparent; color: var(--text-2);
  padding: 6px 18px; border-radius: var(--radius-pill); cursor: pointer; font-size: 13px;
  font-weight: 500; transition: all .2s ease;
}
.view-tabs .tab.active {
  background: var(--bg-card-solid); color: var(--text); font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
.topbar-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
#searchInput {
  width: 280px; padding: 8px 16px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: var(--bg-card);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  color: var(--text); font-size: 13px; outline: none;
  transition: border-color .2s, box-shadow .2s, width .2s;
}
#searchInput:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-weak);
  width: 320px;
}
#searchInput::placeholder { color: var(--text-3); }

.icon-btn {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border-radius: var(--radius-pill); padding: 7px 14px; cursor: pointer; font-size: 13px;
  font-weight: 500; white-space: nowrap; transition: all .18s ease;
}
.icon-btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }

/* ============ 视图 ============ */
.view { display: none; height: calc(100vh - 52px); overflow: hidden; }
.view.active { display: flex; flex-direction: column; }

/* ============ 书库 ============ */
.filter-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 24px 14px; flex-wrap: wrap;
}
.filter-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--bg-card-solid); color: var(--text-2);
  padding: 7px 16px; border-radius: var(--radius-pill); cursor: pointer; font-size: 13px;
  font-weight: 500; transition: all .18s ease;
}
.chip:hover { color: var(--primary); border-color: var(--primary); }
.chip.active {
  background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600;
}
.stats { margin-left: auto; color: var(--text-3); font-size: 13px; font-weight: 500; }

/* ============ 书单列表（大圆角卡片） ============ */
.book-list {
  flex: 1; overflow-y: auto; padding: 4px 24px 48px;
  display: flex; flex-direction: column; gap: 8px;
}
.book-row {
  display: flex; align-items: center; gap: 16px;
  background: var(--bg-card-solid);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 20px; cursor: pointer;
  transition: transform .2s ease, box-shadow .2s, border-color .2s, background .2s;
}
.book-row:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
  border-color: var(--border-strong);
}
.row-badge {
  flex: none; min-width: 54px; text-align: center;
  font-size: 11px; font-weight: 700; letter-spacing: .5px;
  padding: 6px 10px; border-radius: 8px; color: #fff;
  background: var(--primary);
}
.row-badge[data-ext="pdf"]  { background: #ff6723; }
.row-badge[data-ext="epub"] { background: #0071e3; }
.row-badge[data-ext="xlsx"] { background: #34c759; }
.row-badge[data-ext="png"], .row-badge[data-ext="jpg"], .row-badge[data-ext="jpeg"] { background: #bf5af2; }
/* 封面缩略图 */
.row-cover {
  flex: none; width: 44px; height: 62px; border-radius: 6px;
  overflow: hidden; position: relative;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  display: flex; align-items: center; justify-content: center;
}
.row-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.row-cover-fallback {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; letter-spacing: .3px; color: #fff;
  background: var(--primary); padding: 4px; text-align: center; word-break: break-all;
}
.row-cover-fallback[data-ext="pdf"]  { background: #ff6723; }
.row-cover-fallback[data-ext="epub"] { background: #0071e3; }
.row-cover-fallback[data-ext="xlsx"], .row-cover-fallback[data-ext="csv"] { background: #34c759; }
.row-cover-fallback[data-ext="txt"], .row-cover-fallback[data-ext="md"] { background: #8e8e93; }
.row-cover-fallback[data-ext="png"], .row-cover-fallback[data-ext="jpg"],
.row-cover-fallback[data-ext="jpeg"], .row-cover-fallback[data-ext="webp"],
.row-cover-fallback[data-ext="gif"], .row-cover-fallback[data-ext="bmp"] { background: #bf5af2; }
.row-cover.cover-failed { opacity: .92; }
.row-cover.has-cover { background: transparent; }
.row-main { flex: 1; min-width: 0; }
.row-title {
  font-size: 17px; font-weight: 600; line-height: 1.4; letter-spacing: -0.02em;
  word-break: break-word; white-space: normal; color: var(--text);
}
.book-row:hover .row-title { color: var(--primary); }
.row-sub { display: flex; gap: 14px; margin-top: 4px; color: var(--text-3); font-size: 13px; }
.row-progress {
  flex: none; width: 88px; height: 4px; border-radius: var(--radius-pill);
  background: var(--bg-hover); overflow: hidden;
}
.row-progress > i {
  display: block; height: 100%;
  background: var(--primary); border-radius: var(--radius-pill);
  transition: width .4s ease;
}
@media (max-width: 640px) { .row-progress { display: none; } }

/* ============ 阅读器 ============ */
#reader-view { background: transparent; }
#readerToolbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border);
}
.book-meta { flex: 1; display: flex; align-items: baseline; gap: 12px; overflow: hidden; }
#readerTitle {
  font-weight: 600; font-size: 15px; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text);
}
#readerPos { color: var(--primary); font-size: 13px; white-space: nowrap; font-weight: 500; }
.toolbar-actions { display: flex; gap: 8px; }

#readerBody { flex: 1; display: flex; overflow: hidden; position: relative; }
.side-panel {
  width: 300px; background: var(--bg-side);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--border);
  display: none; flex-direction: column; height: 100%;
}
.side-panel.open { display: flex; }
#notePanel { border-right: none; border-left: 1px solid var(--border); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; font-weight: 600; font-size: 15px; letter-spacing: -0.01em;
  border-bottom: 1px solid var(--border); color: var(--text);
}
.close-panel {
  border: none; font-size: 20px; padding: 2px 8px; background: transparent; color: var(--text-3);
  cursor: pointer; border-radius: 8px; transition: color .15s, background .15s;
}
.close-panel:hover { color: var(--text); background: var(--bg-hover); }

#viewerWrap { flex: 1; display: flex; flex-direction: column; background: var(--reader-bg); position: relative; overflow: hidden; }
#viewer { flex: 1; overflow: auto; position: relative; }
#viewer .epub-container, #viewer .epub-view { background: transparent !important; }
#viewer .text-page {
  padding: 56px 12%; line-height: 1.8; font-size: 18px; color: var(--reader-text);
  letter-spacing: -0.005em;
}
#viewer .text-page h1 { font-size: 1.7em; margin: 1.2em 0 .8em; letter-spacing: -0.02em; }
#viewer .text-page h2 { font-size: 1.35em; margin: 1em 0 .6em; letter-spacing: -0.01em; }
#viewer canvas.pdf-canvas { display: block; margin: 14px auto; box-shadow: var(--shadow-lift); border-radius: 6px; }

#viewerToolbarBottom { position: relative; height: 0; }
#pageJumpBar {
  position: absolute; bottom: -48px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; align-items: center;
  background: var(--bg-card-solid); border: 1px solid var(--border); border-radius: var(--radius-pill);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  padding: 8px 14px; box-shadow: var(--shadow-lift); z-index: 5;
}
#pageInput {
  width: 64px; padding: 5px 8px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-card-solid); color: var(--text);
  text-align: center; font-size: 13px; outline: none;
}
#pageInput:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }
.mini-btn {
  border: none; background: var(--primary); color: #fff; border-radius: var(--radius-pill);
  padding: 6px 14px; cursor: pointer; font-size: 13px; font-weight: 600; transition: filter .15s;
}
.mini-btn:hover { background: var(--primary-hover); }

#selectPopup {
  position: absolute; z-index: 30;
  display: flex; gap: 4px;
  background: var(--bg-card-solid); border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  padding: 5px; box-shadow: var(--shadow-lift);
}
#selectPopup button {
  border: none; background: transparent; color: var(--text);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500;
  transition: background .15s, color .15s;
}
#selectPopup button:hover { background: var(--bg-hover); color: var(--primary); }

/* 目录 */
.toc-list { flex: 1; overflow-y: auto; padding: 8px; }
.toc-item {
  padding: 9px 12px; border-radius: 10px; cursor: pointer; font-size: 14px;
  color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .15s, color .15s;
}
.toc-item:hover { background: var(--bg-hover); color: var(--primary); }
.toc-item.current { color: var(--primary); font-weight: 600; background: var(--primary-weak); }
.toc-item .toc-lv { color: var(--text-3); font-size: 12px; margin-right: 6px; }
.toc-group-title {
  font-size: 12px; color: var(--text-3); padding: 14px 12px 6px; font-weight: 600;
  letter-spacing: 0.02em; text-transform: uppercase;
}

/* ============ 笔记 ============ */
#noteCompose { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
#noteTextarea {
  width: 100%; height: 80px; resize: vertical; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg-card-solid); color: var(--text);
  padding: 10px 12px; font-size: 14px; font-family: inherit; outline: none;
  transition: border-color .2s, box-shadow .2s; line-height: 1.6;
}
#noteTextarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }
.primary-btn {
  border: none; background: var(--primary); color: #fff; border-radius: var(--radius-pill);
  padding: 9px; cursor: pointer; font-size: 14px; font-weight: 600;
  transition: background .15s;
}
.primary-btn:hover { background: var(--primary-hover); }

.note-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
#notes-view .note-list { padding: 0 24px 32px; }
.notes-head { display: flex; align-items: center; gap: 16px; padding: 24px 24px 16px; }
.notes-head h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
#noteSearchInput {
  margin-left: auto; width: 280px; padding: 9px 16px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  font-size: 13px; outline: none; transition: border-color .2s, box-shadow .2s;
}
#noteSearchInput:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }
.note-card {
  background: var(--bg-card-solid); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 16px; display: flex; flex-direction: column; gap: 8px;
  transition: box-shadow .2s, border-color .2s;
}
.note-card:hover { box-shadow: var(--shadow-lift); border-color: var(--border-strong); }
.note-card .note-quote {
  border-left: 3px solid var(--primary); background: var(--primary-weak);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; color: var(--text-2); line-height: 1.6;
}
.note-card .note-text { font-size: 14px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; color: var(--text); }
.note-card .note-foot { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 12px; }
.note-card .note-book { color: var(--primary); cursor: pointer; }
.note-card .note-del { margin-left: auto; border: none; background: transparent; color: #ff3b30; cursor: pointer; font-size: 13px; }
.note-card .note-del:hover { opacity: .7; }

/* epub 高亮样式 */
.epubjs-hl { background: var(--hl) !important; }

/* ============ toast ============ */
.toast {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  background: var(--bg-card-solid); color: var(--text); padding: 11px 22px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill); font-size: 14px; font-weight: 500; z-index: 100;
  box-shadow: var(--shadow-lift);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  transition: opacity .2s;
}

/* ============ 滚动条（极简） ============ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(120, 120, 128, 0.3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(120, 120, 128, 0.5); }

/* 降低动效偏好 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============ 手机端 ============ */
@media (max-width: 720px) {
  html, body { width: 100%; min-height: 100%; }
  body { overscroll-behavior: none; }
  button, input, textarea { font-family: inherit; }
  button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

  #bgGlow::before, #bgGlow::after {
    width: 95vw; height: 95vw; filter: blur(72px); opacity: .2;
    animation-duration: 12s;
  }

  #topbar {
    height: 108px; min-height: 108px;
    padding: max(8px, env(safe-area-inset-top)) 12px 9px;
    flex-wrap: wrap; align-content: center; gap: 8px 10px;
  }
  .brand { gap: 8px; }
  .brand-icon { width: 30px; height: 30px; border-radius: 8px; font-size: 15px; }
  .brand-name { font-size: 16px; }
  .view-tabs { margin-left: auto; }
  .view-tabs .tab { min-height: 34px; padding: 6px 13px; }
  .topbar-right { width: 100%; margin-left: 0; gap: 8px; }
  #searchInput, #searchInput:focus {
    flex: 1; width: auto; min-width: 0; height: 38px; padding: 8px 14px; font-size: 16px;
  }
  #themeBtn { width: 40px; height: 38px; padding: 0; flex: none; }

  .view { height: calc(100vh - 108px); height: calc(100dvh - 108px); }
  body.reader-mode #topbar { display: none; }
  body.reader-mode #reader-view { height: 100vh; height: 100dvh; }

  .filter-bar { padding: 10px 12px 8px; gap: 8px; flex-wrap: nowrap; }
  .filter-chips {
    flex: 1; min-width: 0; gap: 6px; flex-wrap: nowrap; overflow-x: auto;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .filter-chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; min-height: 36px; padding: 7px 13px; }
  .stats { flex: none; margin-left: 0; font-size: 12px; }

  .book-list { padding: 2px 12px calc(24px + env(safe-area-inset-bottom)); gap: 8px; }
  .book-row { gap: 11px; padding: 12px; border-radius: 14px; }
  .book-row:hover { transform: none; box-shadow: none; }
  .row-badge { min-width: 46px; padding: 6px 7px; font-size: 10px; }
  .row-title { font-size: 15px; line-height: 1.35; }
  .row-sub { gap: 10px; margin-top: 5px; font-size: 12px; }
  .row-progress { display: none; }

  #readerToolbar {
    min-height: 100px;
    padding: max(8px, env(safe-area-inset-top)) 10px 8px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "back meta" "actions actions";
    gap: 7px 8px;
  }
  #backBtn { grid-area: back; min-width: 64px; min-height: 38px; padding: 7px 10px; }
  .book-meta { grid-area: meta; min-width: 0; gap: 7px; align-items: center; }
  #readerTitle { font-size: 14px; }
  #readerPos { font-size: 11px; }
  .toolbar-actions { grid-area: actions; width: 100%; gap: 5px; }
  .toolbar-actions .icon-btn {
    flex: 1 1 0; min-width: 0; min-height: 42px; padding: 7px 4px; font-size: 12px;
  }

  #readerBody { min-height: 0; }
  .side-panel {
    position: absolute; inset-block: 0; left: 0; z-index: 40;
    width: min(88vw, 340px); height: 100%;
    box-shadow: 12px 0 32px rgba(0, 0, 0, .18);
  }
  #notePanel {
    left: auto; right: 0;
    border-left: 1px solid var(--border); border-right: none;
    box-shadow: -12px 0 32px rgba(0, 0, 0, .18);
  }
  .panel-head { min-height: 52px; padding: 11px 14px; }
  .close-panel { min-width: 44px; min-height: 44px; }
  #noteTextarea { height: 96px; min-height: 96px; font-size: 16px; }
  .primary-btn { min-height: 44px; }

  #viewer { -webkit-overflow-scrolling: touch; touch-action: pan-y pinch-zoom; }
  #viewer .text-page { padding: 24px 18px 72px; font-size: 17px; line-height: 1.8; }
  #viewer canvas.pdf-canvas { margin: 8px auto 70px; border-radius: 3px; }
  #pageJumpBar {
    position: fixed; left: 50%; bottom: max(12px, env(safe-area-inset-bottom));
    padding: 7px 10px; max-width: calc(100vw - 24px);
  }
  #pageInput { width: 56px; font-size: 16px; }
  #selectPopup { position: fixed; left: 50% !important; top: auto !important; bottom: max(68px, env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: calc(100vw - 16px); }
  #selectPopup button { min-height: 40px; padding: 7px 9px; }

  .notes-head { padding: 16px 12px 10px; flex-direction: column; align-items: stretch; gap: 10px; }
  .notes-head h2 { font-size: 20px; }
  #noteSearchInput { width: 100%; margin-left: 0; min-height: 42px; font-size: 16px; }
  #notes-view .note-list { padding: 0 12px calc(24px + env(safe-area-inset-bottom)); }
  .note-card { padding: 13px; }
  .note-card .note-foot { flex-wrap: wrap; row-gap: 6px; }
  .note-card .note-book { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .note-card .note-del { min-width: 44px; min-height: 36px; }

  .toast {
    top: max(12px, env(safe-area-inset-top));
    width: max-content; max-width: calc(100vw - 24px); text-align: center;
  }
}

@media (max-width: 380px) {
  .brand-name { display: none; }
  .view-tabs .tab { padding-inline: 11px; }
  .toolbar-actions { gap: 3px; }
  .toolbar-actions .icon-btn { font-size: 11px; padding-inline: 2px; }
  #readerPos { display: none; }
}

/* Calm, cover-first library. System fonts and no animated background. */
:root { --bg: #f5f5f7; --reader-bg: #e9e9ed; }
button, input, select, a { -webkit-tap-highlight-color: transparent; font-family: inherit; }
button, a { touch-action: manipulation; }
button:focus-visible, a:focus-visible, .book-row:focus-visible {
  outline: 3px solid var(--primary); outline-offset: 4px;
}
a.icon-btn, .workspace-link { text-decoration: none; }
.workspace-link { display: inline-flex; align-items: center; }
#topbar { padding-inline: max(24px, calc((100vw - 1320px) / 2)); gap: 24px; height: 64px; }
.brand-icon { background: var(--text); color: var(--bg-card-solid); }
.view { height: calc(100dvh - 64px); }
.library-heading, .library-tools, .filter-bar { width: 100%; max-width: 1376px; margin-inline: auto; padding-inline: 28px; flex: none; }
.library-heading { padding-top: 38px; padding-bottom: 24px; display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.eyebrow { color: var(--text-2); font-size: 13px; margin-bottom: 8px; }
.library-heading h1 { font-size: clamp(26px, 3vw, 38px); line-height: 1.15; font-weight: 650; letter-spacing: -.05em; }
#resumeBtn { padding: 11px 22px; flex: none; }
.library-tools { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.shelf-tabs { display: flex; gap: 22px; }
.shelf-tabs button { padding: 12px 0; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--text-2); cursor: pointer; font-size: 14px; white-space: nowrap; }
.shelf-tabs button.active { border-color: var(--text); color: var(--text); font-weight: 600; }
.library-controls { display: flex; align-items: center; gap: 8px; }
.library-controls select { border: none; background: transparent; color: var(--text-2); font-size: 13px; max-width: 120px; padding: 8px; }
.library-controls .icon-btn { background: var(--bg-card-solid); }
.filter-bar { padding-top: 18px; padding-bottom: 18px; }
.filter-chips { gap: 6px; flex-wrap: nowrap; overflow: auto; scrollbar-width: none; }
.chip { font-size: 11px; padding: 6px 12px; flex: none; }
.chip.active { background: var(--text); color: var(--bg-card-solid); border-color: var(--text); }
.book-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); align-content: start; gap: 32px 30px; padding: 12px max(28px, calc((100vw - 1320px) / 2)) 48px; min-height: 0; }
.book-row { display: flex; position: relative; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 12px; padding: 0; border: 0; border-radius: 8px; background: transparent; min-width: 0; transition: transform .18s ease; }
.book-row:hover { transform: translateY(-3px); box-shadow: none; }
.row-cover { width: 100%; height: auto; aspect-ratio: 3 / 4; border-radius: 5px 9px 9px 5px; background: #ececf0; border: 0; box-shadow: 0 5px 12px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.1); }
.row-cover img { object-fit: contain; }
.row-cover.has-cover { background: var(--bg-card-solid); }
.row-cover-fallback { padding: 20px; background: #414f62; flex-direction: column; justify-content: space-between; align-items: flex-start; text-align: left; }
.row-cover-fallback small { font-weight: 400; font-size: 10px; opacity: .7; }
.row-cover-fallback strong { font-size: 17px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.row-cover-fallback[data-ext="pdf"] { background: #5a626b; }
.row-cover-fallback[data-ext="epub"] { background: #647568; }
.row-cover-fallback[data-ext="xlsx"] { background: #52796e; }
.row-title { font-size: 14px; font-weight: 600; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-main { flex: none; padding-right: 23px; }
.row-sub { gap: 6px; flex-wrap: wrap; font-size: 11px; }
.format-label { color: var(--text-2); font-size: 10px; }
.row-progress { width: 100%; height: 3px; display: block; margin-top: auto; }
.favorite-btn { position: absolute; right: -6px; bottom: 14px; width: 34px; height: 40px; border: 0; background: transparent; color: var(--text-3); font-size: 23px; cursor: pointer; }
.favorite-btn.selected { color: #d55465; }
.empty-state { grid-column: 1 / -1; text-align: center; padding: 70px 16px; color: var(--text); }
.empty-state p { font-size: 14px; color: var(--text-2); margin-top: 12px; }
.book-list.list-layout { display: flex; gap: 12px; }
.list-layout .book-row { flex-direction: row; align-items: center; padding: 14px 50px 14px 16px; border-radius: 14px; background: var(--bg-card-solid); gap: 18px; }
.list-layout .row-cover { width: 60px; flex: none; }
.list-layout .row-cover-fallback { padding: 5px; }
.list-layout .row-cover-fallback strong { font-size: 10px; }
.list-layout .row-cover-fallback small { display: none; }
.list-layout .row-main { flex: 1; }
.list-layout .row-progress { width: 85px; margin-top: 0; }
.list-layout .favorite-btn { right: 12px; bottom: calc(50% - 20px); }
#viewer { touch-action: pan-x pan-y pinch-zoom; padding-bottom: 64px; }
#viewer:has(.epub-container) { padding-bottom: 0; }
#viewer canvas.pdf-canvas { max-width: none; border-radius: 2px; margin: 16px auto; }
#pageJumpBar { position: absolute; bottom: 14px; white-space: nowrap; font-size: 12px; }
#viewerWrap, .book-meta { min-width: 0; }

@media (min-width: 1500px) { .book-list:not(.list-layout) { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
@media (max-width: 720px) {
  #topbar { padding: max(8px, env(safe-area-inset-top)) 16px 10px; height: 110px; min-height: 110px; gap: 8px; }
  .brand-name { font-size: 15px; }
  .view-tabs .tab { padding: 7px 9px; font-size: 12px; }
  .view { height: calc(100dvh - 110px); }
  .library-heading, .library-tools, .filter-bar { padding-inline: 18px; }
  .library-heading { padding-top: 24px; padding-bottom: 20px; gap: 10px; }
  .library-heading h1 { font-size: 26px; }
  .eyebrow { font-size: 12px; }
  #resumeBtn { font-size: 12px; min-height: 38px; padding: 8px 12px; }
  .library-tools { flex-wrap: wrap; gap: 8px; }
  .shelf-tabs { gap: 22px; flex: 1; }
  .library-controls { gap: 5px; }
  .library-controls select { max-width: 99px; padding: 6px 0; font-size: 12px; }
  .library-controls .icon-btn { padding: 7px 10px; font-size: 12px; }
  .filter-bar { padding-top: 12px; padding-bottom: 12px; }
  .chip { min-height: 30px; padding: 5px 10px; }
  .book-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 26px 20px; padding: 8px 20px calc(28px + env(safe-area-inset-bottom)); }
  .row-title { font-size: 13px; }
  .row-sub { font-size: 10px; }
  .row-progress { display: block; }
  .list-layout .row-progress { display: none; }
  .list-layout .row-cover { width: 48px; }
  .toolbar-actions { overflow-x: auto; }
  .toolbar-actions .icon-btn { min-width: 36px; font-size: 12px; text-align: center; }
  #viewer canvas.pdf-canvas { margin: 8px auto; }
  #pageJumpBar { bottom: max(12px, env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) { .book-row:hover { transform: none; } }
