/* ============================================================
   Ebook Reader — 魔方设计系统
   颜色/圆角/阴影/动效 均参考 Mofang DESIGN.md
   ============================================================ */

/* --- CSS 变量 (Light Mode) --- */
:root {
  /* Brand */
  --primary: #667eea;
  --primary-light: #764ba2;
  --primary-hover: #7c8ff5;
  --primary-active: #5a7de0;
  --brand-gradient: linear-gradient(135deg, #667eea, #764ba2);

  /* Success / Warning / Error */
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;

  /* Surfaces */
  --container: #ffffff;
  --layout-bg: #e3e7f0;
  --alt-bg: #f7f8fa;
  --soft-bg: #f7f8fa;
  --border: rgba(0, 0, 0, 0.10);
  --border-secondary: rgba(0, 0, 0, 0.06);
  --border-light: rgba(0, 0, 0, 0.12);

  /* Text */
  --text-primary: #1a1a2e;
  --text-secondary: rgba(40, 55, 100, 0.75);
  --text-tertiary: rgba(100, 116, 139, 0.75);
  --text-quaternary: rgba(100, 116, 139, 0.50);

  /* Shadows (Mofang 三层软阴影) */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.05), 0 2px 6px rgba(0,0,0,0.04), 0 0 1px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.05), 0 0 1px rgba(0,0,0,0.04);
  --shadow-glass: 0 8px 32px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.08);

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Spacing */
  --header-h: 60px;
  --footer-h: 60px;

  /* 过渡 */
  --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* --- Dark Mode --- */
[data-theme="dark"] {
  --container: #222222;
  --layout-bg: #1b1b1f;
  --alt-bg: #282828;
  --soft-bg: #2a2a2a;
  --border: rgba(255, 255, 255, 0.10);
  --border-secondary: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.12);
  --text-primary: rgba(255, 255, 245, 0.92);
  --text-secondary: rgba(235, 235, 245, 0.65);
  --text-tertiary: rgba(235, 235, 245, 0.45);
  --text-quaternary: rgba(235, 235, 245, 0.30);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.30), 0 1px 2px rgba(0,0,0,0.20);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.30), 0 2px 6px rgba(0,0,0,0.20);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.40), 0 4px 12px rgba(0,0,0,0.25);
  --shadow-glass: 0 8px 32px rgba(0,0,0,0.50), 0 2px 8px rgba(0,0,0,0.30);
}

/* --- 全局重置 --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: 'Noto Sans SC', 'Microsoft YaHei', -apple-system, sans-serif;
  background-color: var(--layout-bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100dvh;
  overflow-x: hidden;
  /* 魔方同款 wavy 纹理背景 */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Cpath d='M0 50 Q25 30 50 50 T100 50' fill='none' stroke='%23d0d5e0' stroke-width='0.5' opacity='0.4'/%3E%3Cpath d='M0 70 Q25 50 50 70 T100 70' fill='none' stroke='%23d0d5e0' stroke-width='0.5' opacity='0.3'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

[data-theme="dark"] body {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Cpath d='M0 50 Q25 30 50 50 T100 50' fill='none' stroke='%23282830' stroke-width='0.5' opacity='0.4'/%3E%3Cpath d='M0 70 Q25 50 50 70 T100 70' fill='none' stroke='%23282830' stroke-width='0.5' opacity='0.3'/%3E%3C/svg%3E");
}

/* 全局滚动条 */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-quaternary); }

/* --- 通用组件 --- */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--brand-gradient);
  color: #fff;
  border: none;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.35);
  font-family: inherit;
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.45);
  filter: brightness(1.05);
}
.btn-primary:active { transform: translateY(0); filter: brightness(0.97); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  font-size: 16px;
}
.icon-btn:hover {
  background: var(--soft-bg);
  color: var(--primary);
}
.icon-btn:active { transform: scale(0.95); }

/* --- 视图容器 --- */
#app {
  min-height: 100dvh;
}

.view {
  min-height: 100dvh;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   书架视图
   ============================================================ */
.shelf-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(227, 231, 240, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-secondary);
}

[data-theme="dark"] .shelf-header {
  background: rgba(27, 27, 31, 0.85);
}

.shelf-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: var(--header-h);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}
.logo i { color: var(--primary); font-size: 22px; }

.header-actions { display: flex; align-items: center; gap: 4px; }

.shelf-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

/* Section Title */
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.section-title i { color: var(--primary); font-size: 13px; }

/* 最近阅读 */
.recent-section { margin-bottom: 40px; }

.recent-scroll {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 12px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.recent-scroll::-webkit-scrollbar { height: 3px; }

.recent-card {
  flex: 0 0 120px;
  scroll-snap-align: start;
  cursor: pointer;
  transition: var(--transition);
}
.recent-card:hover { transform: translateY(-3px); }
.recent-card:hover .recent-cover {
  box-shadow: var(--shadow-lg);
}
.recent-cover {
  width: 120px;
  height: 160px;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
  background: linear-gradient(135deg, #667eea22, #764ba222);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}
.recent-cover-placeholder {
  color: var(--primary);
  font-size: 36px;
  opacity: 0.6;
}
.recent-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.recent-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.recent-chapter {
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 书籍网格 */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 20px;
}

.book-card {
  position: relative;
  cursor: pointer;
  transition: var(--transition);
  border-radius: var(--radius-md);
  overflow: visible;
}
.book-card:hover { transform: translateY(-4px); }

.book-cover {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  aspect-ratio: 3/4;
  background: linear-gradient(135deg, #667eea18, #764ba218);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.book-card:hover .book-cover { box-shadow: var(--shadow-lg); }

.book-cover-placeholder {
  color: var(--primary);
  font-size: 48px;
  opacity: 0.5;
}
.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-info {
  padding: 10px 4px 4px;
}
.book-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.book-chapters-count {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}
.book-progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 4px;
}
.book-progress-fill {
  height: 100%;
  background: var(--brand-gradient);
  border-radius: 2px;
  transition: width 0.4s ease;
  width: 0%;
}
.book-progress-text {
  font-size: 10px;
  color: var(--text-quaternary);
}

/* 书籍卡片悬浮层 */
.book-card-overlay {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-md);
  background: rgba(102, 126, 234, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
  backdrop-filter: blur(4px);
}
.book-card:hover .book-card-overlay { opacity: 1; pointer-events: auto; }

.overlay-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: rgba(255,255,255,0.20);
  border: 1.5px solid rgba(255,255,255,0.40);
  border-radius: var(--radius-full);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: var(--transition);
}
.overlay-btn:hover { background: rgba(255,255,255,0.30); transform: scale(1.05); }

/* ============================================================
   书籍详情视图
   ============================================================ */
.book-detail-view { background: var(--layout-bg); }

.detail-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--header-h);
  background: rgba(227, 231, 240, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-secondary);
}
[data-theme="dark"] .detail-header { background: rgba(27, 27, 31, 0.88); }

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.back-btn:hover { background: var(--soft-bg); color: var(--primary); }

.detail-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

.detail-hero {
  display: flex;
  gap: 28px;
  margin-bottom: 36px;
  align-items: flex-start;
}

.detail-cover {
  flex: 0 0 160px;
  width: 160px;
  height: 213px;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: linear-gradient(135deg, #667eea22, #764ba222);
  display: flex;
  align-items: center;
  justify-content: center;
}
.detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.detail-cover-placeholder { color: var(--primary); font-size: 48px; opacity: 0.5; }

.detail-info { flex: 1; min-width: 0; }
.detail-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  line-height: 1.3;
}
.detail-meta {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-bottom: 16px;
}
.detail-actions { margin-bottom: 20px; }

.detail-progress-wrap { display: flex; align-items: center; gap: 12px; }
.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--brand-gradient);
  border-radius: 3px;
  transition: width 0.5s ease;
  width: 0%;
}
.progress-text { font-size: 12px; color: var(--text-tertiary); white-space: nowrap; }

/* TOC */
.detail-toc .section-title { margin-bottom: 12px; }
.toc-list { display: flex; flex-direction: column; gap: 4px; }

.toc-item { border-radius: var(--radius-sm); overflow: hidden; }
.toc-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  user-select: none;
}
.toc-item-header:hover { background: var(--soft-bg); }
.toc-item.active > .toc-item-header {
  background: linear-gradient(135deg, rgba(102,126,234,0.12), rgba(118,75,162,0.10));
}
.toc-item.read > .toc-item-header .toc-item-title { color: var(--text-secondary); }
.toc-item.read > .toc-item-header .toc-item-check { opacity: 1; color: var(--success); }
.toc-item-check { opacity: 0; transition: var(--transition); font-size: 12px; }
.toc-item-title {
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
}
.toc-expand-icon {
  color: var(--text-quaternary);
  font-size: 10px;
  transition: transform 0.2s ease;
  width: 16px;
  text-align: center;
}
.toc-item.open > .toc-item-header .toc-expand-icon { transform: rotate(90deg); }
.toc-item-children {
  display: none;
  padding-left: 24px;
}
.toc-item.open > .toc-item-children { display: block; }
.toc-item-children .toc-item-header { padding: 8px 12px; }
.toc-item-children .toc-item-title { font-size: 13px; font-weight: 400; }

/* ============================================================
   阅读器视图
   ============================================================ */
.reader-view {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--container);
}

.reader-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: var(--header-h);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-secondary);
  transition: var(--transition);
}
[data-theme="dark"] .reader-header { background: rgba(34, 34, 34, 0.92); }
.reader-header.hidden { transform: translateY(-100%); }

.reader-chapter-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  justify-content: center;
  min-width: 0;
}
.reader-chapter-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}
.nav-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: var(--transition);
  display: flex;
  align-items: center;
}
.nav-btn:hover { color: var(--primary); background: var(--soft-bg); }
.nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.reader-header-right { display: flex; align-items: center; gap: 2px; }

/* 阅读进度条 */
.reader-progress-bar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: 0;
  z-index: 199;
  height: 4px;
  background: var(--border);
  overflow: hidden;
}
.reader-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
  transition: width 0.3s ease;
  width: 0%;
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.5);
  position: relative;
}
/* 进度条头部高光（发光点） */
.reader-progress-fill::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  width: 8px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6));
  border-radius: 50%;
  filter: blur(1px);
}
/* 进度条 100% 满时闪光 */
.reader-progress-bar.complete .reader-progress-fill {
  animation: progress-flash 0.6s ease-out;
}
@keyframes progress-flash {
  0% { box-shadow: 0 0 0 rgba(34, 197, 94, 0); }
  50% { box-shadow: 0 0 24px rgba(34, 197, 94, 0.8); }
  100% { box-shadow: 0 0 8px rgba(139, 92, 246, 0.5); }
}

/* ===========================
   进度胶囊 pill (X / N · 35%)
   嵌在 header 右上角，与按钮并排
   =========================== */
.reader-progress-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary, #6b7280);
  background: var(--soft-bg, rgba(255, 255, 255, 0.7));
  border: 1px solid var(--border-secondary, rgba(0,0,0,0.06));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity 0.3s ease, background 0.2s;
  margin-right: 4px;
  user-select: none;
  pointer-events: none;
}
.reader-progress-pill:hover {
  background: var(--soft-bg-hover, rgba(255, 255, 255, 0.9));
}

.reader-progress-counter {
  display: inline-flex;
  align-items: center;
  gap: 1px;
}
.reader-progress-counter .counter-current {
  color: var(--primary, #3b82f6);
  font-weight: 600;
}
.reader-progress-counter .counter-sep {
  margin: 0 2px;
  color: var(--text-tertiary, #9ca3af);
  opacity: 0.6;
}
.reader-progress-counter .counter-total {
  color: var(--text-tertiary, #9ca3af);
  font-weight: 500;
}

.reader-progress-sep {
  color: var(--text-tertiary, #9ca3af);
  opacity: 0.5;
  font-weight: 400;
}

.reader-progress-text {
  color: var(--text-primary, #1f2937);
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* 深色模式 */
[data-theme="dark"] .reader-progress-pill {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .reader-progress-text {
  color: rgba(255, 255, 255, 0.92);
}

/* 原有 .reader-chapter-counter 保留作 idempotent （隐藏） */
.reader-chapter-counter {
  position: fixed;
  top: calc(var(--header-h) + 8px);
  right: 16px;
  z-index: 199;
  font-size: 12px;
  color: var(--text-secondary, #6b7280);
  background: var(--soft-bg, rgba(255, 255, 255, 0.85));
  padding: 3px 10px;
  border-radius: 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.reader-chapter-counter.hidden { opacity: 0; }
.counter-current { color: var(--primary, #3b82f6); font-weight: 600; }
.counter-sep { margin: 0 2px; opacity: 0.5; }
.counter-total { font-weight: 500; }

/* 内容区 */
.reader-content-wrap {
  flex: 1;
  margin-top: var(--header-h);
  margin-bottom: var(--footer-h);
  overflow-y: auto;
  background: var(--container);
}

.reader-iframe {
  display: block;
  width: 100%;
  max-width: none !important;
  height: 100%;
  min-height: calc(100dvh - var(--header-h) - var(--footer-h));
  border: none;
  background: #fff;
}
[data-theme="dark"] .reader-iframe { background: #1a1a1a; }

/* 底部工具栏 */
.reader-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--footer-h);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-secondary);
  transition: var(--transition);
}
[data-theme="dark"] .reader-footer { background: rgba(34, 34, 34, 0.92); }
.reader-footer.hidden { transform: translateY(100%); }

.footer-left, .footer-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.font-size-display {
  font-size: 12px;
  color: var(--text-tertiary);
  min-width: 36px;
  text-align: center;
}
.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 12px;
  min-width: 44px;
  min-height: 44px;
  background: var(--soft-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-size: 12px;
  flex-shrink: 0;  /* P0-iPhone fix: 防止 footer 被挤导致圆形变长条 */
  cursor: pointer;
  font-family: inherit;
  transition: var(--transition);
}
.tool-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.tool-btn:active { transform: scale(0.95); }

/* 目录抽屉 */
.toc-drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 299;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(2px);
}
.toc-drawer-overlay.open { opacity: 1; pointer-events: auto; }

.toc-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 300;
  width: min(320px, 85vw);
  background: var(--container);
  box-shadow: var(--shadow-glass);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  display: flex;
  flex-direction: column;
}
.toc-drawer.open { transform: translateX(0); }

.toc-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border-secondary);
  flex-shrink: 0;
}
.toc-drawer-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}
.toc-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px 80px;
}

/* ============================================================
   设置面板 & 搜索面板
   ============================================================ */
.settings-overlay,
.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  backdrop-filter: blur(3px);
}
.settings-overlay.open,
.search-overlay.open,
#manage-overlay.open,
#upload-overlay.open { opacity: 1; pointer-events: auto; }

.settings-panel,
.search-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  z-index: 401;
  width: min(480px, 92vw);
  background: var(--container);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glass);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  overflow: hidden;
}
.settings-overlay.open .settings-panel,
.search-overlay.open .search-panel {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.settings-header,
.search-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  border-bottom: 1px solid var(--border-secondary);
}
.settings-header h3,
.search-header h3 {
  font-size: 16px;
  font-weight: 600;
}
.settings-body { padding: 20px; display: flex; flex-direction: column; gap: 20px; }

.settings-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.settings-label { font-size: 14px; color: var(--text-primary); font-weight: 500; }

/* Toggle Switch */
.toggle-input { display: none; }
.toggle-label {
  display: block;
  width: 44px;
  height: 24px;
  background: var(--border-light);
  border-radius: 12px;
  cursor: pointer;
  position: relative;
  transition: var(--transition);
}
.toggle-label .toggle-slider {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: var(--transition);
}
.toggle-input:checked + .toggle-label {
  background: var(--primary);
}
.toggle-input:checked + .toggle-label .toggle-slider {
  transform: translateX(20px);
}

.font-size-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* 搜索面板 */
.search-panel { width: min(580px, 96vw); }

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  background: var(--soft-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 0 16px;
  height: 40px;
}
.search-input-wrap i { color: var(--text-tertiary); }
.search-input-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  font-family: inherit;
}
.search-input-wrap input::placeholder { color: var(--text-quaternary); }

.search-results {
  padding: 16px 20px 20px;
  max-height: 360px;
  overflow-y: auto;
}
.search-hint {
  font-size: 13px;
  color: var(--text-quaternary);
  text-align: center;
  padding: 24px 0;
}
.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}
.search-result-item:hover { background: var(--soft-bg); }
.search-result-item i { color: var(--primary); font-size: 18px; }
.search-result-info { flex: 1; min-width: 0; }
.search-result-title { font-size: 13px; font-weight: 500; color: var(--text-primary); }
.search-result-meta { font-size: 11px; color: var(--text-tertiary); }

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 640px) {
  .shelf-header-inner { padding: 0 16px; }
  .shelf-main { padding: 20px 16px 60px; }
  .books-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; }
  .detail-hero { flex-direction: column; align-items: center; text-align: center; }
  .detail-cover { flex: 0 0 auto; width: 140px; height: 187px; }
  .detail-progress-wrap { flex-direction: column; align-items: stretch; }
  .detail-progress-wrap .progress-text { text-align: center; }
  .reader-chapter-title { max-width: 160px; font-size: 13px; }
  .logo span { display: none; }
  .header-actions .icon-btn span { display: none; }
}

@media (min-width: 1024px) {
  .books-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .reader-chapter-title { max-width: 400px; }
}

/* ============================================================
   管理面板 & 上传弹窗
   ============================================================ */
.manage-panel,
.upload-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 401;
  width: min(680px, 94vw);
  max-height: 85vh;
  background: var(--container);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glass);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.manage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  border-bottom: 1px solid var(--border-secondary);
  flex-shrink: 0;
}
.manage-header h3 { font-size: 16px; font-weight: 600; }
.manage-header-actions { display: flex; align-items: center; gap: 8px; }

.manage-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.manage-book-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.manage-book-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  transition: var(--transition);
}
.manage-book-item:hover {
  background: var(--soft-bg);
  border-color: var(--border-light);
}

.manage-book-cover {
  width: 48px;
  height: 64px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: linear-gradient(135deg, #667eea18, #764ba218);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 20px;
  color: var(--primary);
}
.manage-book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.manage-book-info { flex: 1; min-width: 0; }
.manage-book-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.manage-book-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.manage-delete-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-quaternary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  font-size: 14px;
  flex-shrink: 0;
}
.manage-delete-btn:hover {
  background: rgba(239, 68, 68, 0.10);
  color: var(--error);
}
.manage-delete-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.manage-loading,
.manage-empty,
.manage-error {
  text-align: center;
  padding: 40px 20px;
  font-size: 13px;
  color: var(--text-tertiary);
}
.manage-error { color: var(--error); }

.manage-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-secondary);
  flex-shrink: 0;
}
.manage-tip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-quaternary);
}
.manage-tip i { color: var(--primary); }

/* 上传弹窗 */
.upload-modal { width: min(480px, 94vw); }
.upload-modal-header {
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-secondary);
}
.upload-modal-header h3 { font-size: 15px; font-weight: 600; }
.upload-modal-body { padding: 20px; }
.upload-modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-secondary);
  display: flex;
  justify-content: flex-end;
}

.upload-dropzone {
  border: 2px dashed var(--border-light);
  border-radius: var(--radius-md);
  padding: 40px 20px;
  text-align: center;
  transition: var(--transition);
  cursor: pointer;
}
.upload-dropzone:hover,
.upload-dropzone.drag-over {
  border-color: var(--primary);
  background: rgba(102, 126, 234, 0.05);
}
.upload-dropzone i {
  font-size: 40px;
  color: var(--primary);
  margin-bottom: 12px;
}
.upload-dropzone p {
  font-size: 13px;
  color: var(--text-secondary);
}
.upload-hint {
  margin: 8px 0;
  color: var(--text-quaternary) !important;
}

.upload-progress-wrap { margin-top: 16px; }
.upload-file-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.upload-progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.upload-progress-fill {
  height: 100%;
  background: var(--brand-gradient);
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}
.upload-status {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 8px;
  text-align: center;
}

.btn-sm {
  padding: 7px 14px;
  font-size: 12px;
}
.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: var(--transition);
}
.btn-ghost:hover {
  background: var(--soft-bg);
  border-color: var(--border-light);
}

/* mark 搜索高亮 */
mark {
  background: rgba(102, 126, 234, 0.2);
  color: var(--primary);
  border-radius: 2px;
  padding: 0 2px;
}

/* =============================================
   Toast 提示系统（大厂标准微交互）
   ============================================= */
.toast-notification {
  position: fixed;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(28, 28, 32, 0.92);
  color: #fff;
  padding: 8px 20px;
  border-radius: 22px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.3px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
}
.toast-notification.toast-top {
  top: 80px;
}
.toast-notification.toast-bottom {
  bottom: 80px;
}
.toast-notification.toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
[data-theme="dark"] .toast-notification {
  background: rgba(245, 245, 245, 0.92);
  color: #1a1a1a;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* =============================================
   搜索面板增强（P0-2 全文搜索）
   ============================================= */
.search-input-wrap {
  position: relative;
}
.search-shortcut-hint {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.2s;
}
.search-shortcut-hint:hover { opacity: 1; }
.search-shortcut-hint kbd {
  display: inline-block;
  padding: 2px 6px;
  font-size: 11px;
  font-family: inherit;
  background: var(--soft-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-tertiary);
}

.search-history {
  padding: 12px 20px 8px;
  border-bottom: 1px solid var(--border);
}
.search-history-label {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}
.search-history-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.search-history-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  background: var(--soft-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}
.search-history-chip:hover {
  background: var(--bg);
  color: var(--text-primary);
}
.search-history-remove {
  font-size: 10px;
  opacity: 0.5;
  cursor: pointer;
  padding: 2px;
}
.search-history-remove:hover { opacity: 1; }

.search-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-tertiary);
  gap: 12px;
}
.search-state i {
  font-size: 36px;
  opacity: 0.4;
}
.search-state p {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
}
.search-state small {
  font-size: 12px;
  color: var(--text-tertiary);
}

.search-results-summary {
  padding: 10px 20px 6px;
  font-size: 12px;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border-light);
}
.search-book-group {
  margin-bottom: 18px;
}
.search-book-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--soft-bg);
}
.search-book-header i { color: var(--primary, #3b82f6); }
.search-book-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 400;
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 10px;
}
.search-match-list { padding: 4px 0; }
.search-match-item {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.15s ease;
}
.search-match-item:hover { background: var(--soft-bg); }
.search-match-item:last-child { border-bottom: none; }
.search-match-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
  margin-bottom: 6px;
}
.search-match-title i {
  color: var(--text-tertiary);
  font-size: 12px;
}
.search-match-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--primary, #3b82f6);
  background: rgba(59, 130, 246, 0.1);
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 500;
}
.search-match-snippet {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-secondary);
  padding-left: 20px;
  word-break: break-word;
}
.search-match-snippet mark {
  background: rgba(250, 204, 21, 0.55);
  color: var(--text-primary);
  padding: 1px 3px;
  border-radius: 3px;
  font-weight: 500;
}

/* =============================================
   进度条右侧 X% 文字
   ============================================= */
.reader-progress-text {
  /* 已重构：百分比现在嵌在 .reader-progress-pill 胶囊里，不再 fixed 定位 */
  color: var(--text-primary, #1f2937);
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

/* =============================================
   选区浮动工具栏（划线 / 笔记 / 复制）
   ============================================= */
.selection-toolbar {
  position: fixed;  /* 改 fixed：不嵌在 wrap 内，避免 X5 iframe reflow 触发滚动冻结 + header/footer 覆盖 */
  display: flex;
  gap: 2px;
  padding: 4px;
  background: rgba(28, 28, 32, 0.95);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  /* 删 backdrop-filter：X5 微信内置浏览器实现不一致，会触发重绘导致 wrap reflow + scroll 冻结 */
  z-index: 250;
  animation: sel-toolbar-in 0.15s ease-out;
}
@keyframes sel-toolbar-in {
  from { opacity: 0; }
  to { opacity: 1; }
  /* 删 transform: X5 iframe + animation 合成层有 bug，会触发 wrap reflow */
}
.selection-toolbar .sel-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background 0.15s;
}
.selection-toolbar .sel-btn:hover { background: rgba(255, 255, 255, 0.15); }
.selection-toolbar .sel-btn:active { background: rgba(255, 255, 255, 0.25); transform: scale(0.95); }

/* P2-3 选区工具栏颜色 picker */
.sel-color-picker {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 6px;
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  border-right: 1px solid rgba(255, 255, 255, 0.12);
}
.sel-color-swatch {
  width: 20px;
  height: 20px;
  border: 2px solid transparent;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.18s;
  /* 重要：让背景填到 box 而非 content-box，让 border 包裹圆 */
  background-clip: padding-box;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
  position: relative;
}
.sel-color-swatch:hover {
  transform: scale(1.18);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25), 0 0 6px var(--swatch-glow, rgba(255, 255, 255, 0.4));
}
.sel-color-swatch.selected {
  /* 双层环：外白实环 + 内圈透明贴合圈背景颜色看得见 */
  border-color: #ffffff;
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.55),
    0 0 0 4px var(--swatch-glow, rgba(255, 255, 255, 0.85)),
    0 0 10px var(--swatch-glow, rgba(255, 255, 255, 0.6));
  transform: scale(1.2);
  animation: swatch-pop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.sel-color-swatch.selected::after {
  /* 中心打勾（用伪元素） */
  content: "✓";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.7);
  line-height: 1;
  pointer-events: none;
}
@keyframes swatch-pop {
  0%   { transform: scale(0.85); }
  60%  { transform: scale(1.32); }
  100% { transform: scale(1.2);  }
}

/* P2-3 笔记 modal：颜色 picker + 标签 chip */
.note-modal-meta-row {
  margin: 12px 0 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.note-modal-colors {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.meta-label {
  font-size: 12px;
  color: var(--text-secondary, #6b7280);
  font-weight: 500;
  flex-shrink: 0;
}
.modal-color-swatch {
  width: 26px;
  height: 26px;
  border: 2px solid transparent;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  background-clip: content-box;
}
.modal-color-swatch:hover { transform: scale(1.12); }
.modal-color-swatch.selected {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}
.note-modal-tags .tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  flex: 1;
}
.tag-chip {
  border: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-tertiary, #f3f4f6);
  color: var(--text-secondary, #4b5563);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.tag-chip:hover { background: var(--bg-secondary, #e5e7eb); }
.tag-chip.selected {
  background: #3b82f6;
  color: #fff;
  border-color: #3b82f6;
}
.tag-chip-add {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.note-modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.note-modal-footer-right { display: flex; gap: 8px; }
.note-modal-hint {
  font-size: 11px;
  color: var(--text-secondary, #9ca3af);
}

/* P2-3 drawer 颜色筛选 Tab */
.notes-drawer-filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 16px 10px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.notes-color-tabs {
  display: flex;
  gap: 4px;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: none;
}
.notes-color-tabs::-webkit-scrollbar { display: none; }
.notes-color-tab {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 9px;
  border: 1px solid var(--border-color, #e5e7eb);
  background: transparent;
  border-radius: 14px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  color: var(--text-secondary, #4b5563);
  white-space: nowrap;
}
.notes-color-tab:hover { background: var(--bg-tertiary, #f3f4f6); }
.notes-color-tab.active {
  background: var(--bg-secondary, #e5e7eb);
  border-color: var(--text-secondary, #9ca3af);
  font-weight: 600;
}
.tab-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.tab-dot-all {
  background: linear-gradient(135deg, #fde68a 0%, #fde68a 50%, #bfdbfe 50%, #bfdbfe 100%);
}
.tab-label {
  font-size: 11px;
}
.tab-count {
  font-size: 11px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 8px;
  padding: 0 5px;
  min-width: 18px;
  text-align: center;
  color: var(--text-secondary, #6b7280);
}
.notes-color-tab.active .tab-count { background: rgba(0, 0, 0, 0.18); font-weight: 600; }

/* P2-3 标签筛选 chip */
.notes-tag-filter {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.notes-tag-chip-filter {
  padding: 3px 8px;
  border: 1px solid var(--border-color, #e5e7eb);
  background: transparent;
  border-radius: 10px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text-secondary, #4b5563);
  transition: all 0.15s;
}
.notes-tag-chip-filter:hover { background: var(--bg-tertiary, #f3f4f6); }
.notes-tag-chip-filter.active {
  background: #3b82f6;
  color: #fff;
  border-color: #3b82f6;
}

/* P2-3 笔记项内的 tag 显示 */
.note-item-tag {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 6px;
  color: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(0, 0, 0, 0.1);
}
/* 划线 mark（在 iframe 内部） */
mark.ebook-highlight {
  background: #fde68a;
  color: inherit;
  padding: 1px 2px;
  border-radius: 2px;
  cursor: pointer;
  transition: box-shadow 0.3s;
}
[data-theme="dark"] mark.ebook-highlight {
  background: rgba(253, 230, 138, 0.35);
}

/* =============================================
   笔记 / 划线 drawer
   ============================================= */
.notes-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 299;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.notes-drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.notes-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 90vw);
  background: var(--container);
  z-index: 300;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
}
.notes-drawer.open { transform: translateX(0); }
.notes-drawer-header {
  display: flex;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.notes-drawer-header h3 { margin: 0; font-size: 16px; font-weight: 600; flex: 1; }
.notes-drawer-actions { display: flex; gap: 4px; }
.notes-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
.notes-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-tertiary);
  text-align: center;
}
.notes-empty i { font-size: 36px; opacity: 0.4; margin-bottom: 12px; }
.notes-empty p { margin: 0; font-size: 14px; color: var(--text-secondary); }
.notes-empty small { font-size: 12px; color: var(--text-tertiary); }

.notes-list { display: flex; flex-direction: column; gap: 10px; }
.note-item {
  background: var(--soft-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  transition: border-color 0.15s;
}
.note-item:hover { border-color: var(--primary, #3b82f6); }
.note-item-chapter {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: 6px;
  font-weight: 500;
}
.note-item-quote {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: 8px;
  word-break: break-word;
}
.note-item-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-primary);
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 6px;
  margin-bottom: 8px;
  border-left: 3px solid #f59e0b;
  white-space: pre-wrap;
  word-break: break-word;
}
.note-item-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.note-item-date { font-size: 11px; color: var(--text-tertiary); }
.note-item-actions { display: flex; gap: 4px; }
.note-act-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
}
.note-act-btn:hover { background: var(--bg); color: var(--primary); }
.note-act-btn[data-act="delete"]:hover { color: #ef4444; }

/* =============================================
   笔记输入 modal
   ============================================= */
.note-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modal-fade-in 0.2s ease-out;
}
@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.note-modal {
  background: var(--container);
  border-radius: 12px;
  width: min(480px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: modal-scale-in 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes modal-scale-in {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}
.note-modal-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.note-modal-header h3 { margin: 0; font-size: 15px; font-weight: 600; flex: 1; }
.note-modal-body {
  padding: 16px 20px;
  flex: 1;
  overflow-y: auto;
}
.note-modal-quote {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  background: var(--soft-bg);
  padding: 10px 14px;
  border-left: 3px solid #f59e0b;
  border-radius: 4px;
  margin-bottom: 12px;
  word-break: break-word;
}
.note-modal-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text-primary);
  resize: vertical;
  min-height: 100px;
  box-sizing: border-box;
  line-height: 1.6;
}
.note-modal-textarea:focus {
  outline: none;
  border-color: var(--primary, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.note-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

/* ===========================
   P1-2 字体/行距/主题色
   =========================== */

/* 默认字体变量 (sans 默认) */
:root {
  --reader-font: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
  --reader-line: 1.6;
  --reader-bg: #fdf6e3;
  --reader-text: #1f2937;
  --reader-text-secondary: #6b7280;
  --reader-border: rgba(0, 0, 0, 0.08);
}

/* 字体 */
[data-font="sans"] { --reader-font: 'Noto Sans SC', -apple-system, sans-serif; }
[data-font="serif"] { --reader-font: 'Noto Serif SC', 'Source Han Serif SC', serif; }
[data-font="kai"] { --reader-font: 'KaiTi', 'STKaiti', 'Noto Serif CJK TC', serif; }
[data-font="system"] { --reader-font: system-ui, -apple-system, sans-serif; }

/* 行距 */
[data-line="1.4"] { --reader-line: 1.4; }
[data-line="1.6"] { --reader-line: 1.6; }
[data-line="1.8"] { --reader-line: 1.8; }
[data-line="2.0"] { --reader-line: 2.0; }

/* 主题色 (日间) */
[data-bg="cream"] { --reader-bg: #fdf6e3; --reader-text: #1f2937; --reader-text-secondary: #6b7280; }
[data-bg="green"] { --reader-bg: #e8f5e9; --reader-text: #1a2e1a; --reader-text-secondary: #5a6e5a; }
[data-bg="parchment"] { --reader-bg: #f5ebd6; --reader-text: #3a2e1a; --reader-text-secondary: #7a6e5a; }
[data-bg="white"] { --reader-bg: #ffffff; --reader-text: #1f2937; --reader-text-secondary: #6b7280; }

/* 主题色 (深色 — 覆盖主题背景，保留字体/行距) */
[data-theme="dark"][data-bg="cream"] { --reader-bg: #1a1814; --reader-text: #e8e6e3; --reader-text-secondary: rgba(232, 230, 227, 0.65); }
[data-theme="dark"][data-bg="green"] { --reader-bg: #131613; --reader-text: #d4e0d4; --reader-text-secondary: rgba(212, 224, 212, 0.6); }
[data-theme="dark"][data-bg="parchment"] { --reader-bg: #1c1814; --reader-text: #e8dec8; --reader-text-secondary: rgba(232, 222, 200, 0.6); }
[data-theme="dark"][data-bg="white"] { --reader-bg: #0d0d0d; --reader-text: #e8e8e8; --reader-text-secondary: #8a8a8a; }

/* 应用到 reader-content-wrap */
.reader-content-wrap { background: var(--reader-bg); }
.reader-content-wrap iframe { background: var(--reader-bg); }

/* 设置面板：选项按钮 */
.option-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.option-btn {
  flex: 1;
  min-width: 60px;
  padding: 8px 12px;
  border: 1px solid var(--border, rgba(0,0,0,0.1));
  border-radius: 8px;
  background: var(--container, #fff);
  color: var(--text-secondary, #6b7280);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.option-btn:hover {
  background: var(--soft-bg, rgba(0,0,0,0.04));
  color: var(--text-primary, #1f2937);
}
.option-btn.active {
  background: var(--primary, #3b82f6);
  color: #fff;
  border-color: var(--primary, #3b82f6);
  box-shadow: 0 1px 3px rgba(59, 130, 246, 0.3);
}
.option-color {
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
}
.option-color .color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: block;
  border: 1px solid rgba(0,0,0,0.1);
}

/* 翻页动画 */
@keyframes page-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes page-slide-in-right {
  from { transform: translateX(30px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes page-slide-in-left {
  from { transform: translateX(-30px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.reader-content-wrap.anim-fade-in { animation: page-fade-in 0.3s ease-out; }
.reader-content-wrap.anim-slide-next { animation: page-slide-in-right 0.2s ease-out; }
.reader-content-wrap.anim-slide-prev { animation: page-slide-in-left 0.2s ease-out; }

/* 深色模式下选项按钮 */
[data-theme="dark"] .option-btn {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.7);
  border-color: rgba(255, 255, 255, 0.1);
}
[data-theme="dark"] .option-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}
[data-theme="dark"] .option-btn.active {
  background: #fcd34d;
  color: #1a1814;
  border-color: #fcd34d;
  box-shadow: 0 1px 3px rgba(252, 211, 77, 0.3);
}

/* ===========================
   P1-3 阅读统计弹窗
   =========================== */
.stats-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.stats-modal-overlay.open { opacity: 1; }

.stats-modal {
  background: #fdf6e3;
  border-radius: 20px;
  width: min(720px, 94vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  transform: scale(0.95) translateY(20px);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}
.stats-modal-overlay.open .stats-modal { transform: scale(1) translateY(0); }

.stats-modal-header {
  display: flex;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  gap: 12px;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
}
.stats-modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  flex: 1;
  color: #1f2937;
  display: flex;
  align-items: center;
  gap: 8px;
}

.stats-modal-body {
  padding: 20px 24px 24px;
  overflow-y: auto;
  background: #fdf6e3;
}

/* 顶部 4 卡片 */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}
.stats-card {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 1px solid rgba(245, 158, 11, 0.2);
  border-radius: 14px;
  padding: 14px 12px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.1);
  transition: transform 0.2s;
}
.stats-card:hover { transform: translateY(-2px); }
.stats-card-icon {
  font-size: 16px;
  color: #f59e0b;
  margin-bottom: 4px;
}
.stats-card-value {
  font-size: 24px;
  font-weight: 700;
  color: #1f2937;
  line-height: 1.2;
  background: linear-gradient(135deg, #1f2937 0%, #f59e0b 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.stats-card-label {
  font-size: 11px;
  color: #6b7280;
  margin-top: 2px;
}
.stats-unit { font-size: 12px; color: #6b7280; font-weight: 500; -webkit-text-fill-color: #6b7280; }

/* 块区 */
.stats-section { margin-bottom: 24px; }
.stats-section:last-child { margin-bottom: 0; }
.stats-section h4 {
  margin: 0 0 12px 0;
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
  display: flex;
  align-items: center;
  gap: 8px;
}
.stats-section h4 i { color: #f59e0b; }

/* 7 天柱状图 */
.week-chart {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  height: 180px;
  padding: 0 4px;
}
.week-day {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.week-bar-wrap {
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.week-bar {
  width: 75%;
  background: linear-gradient(to top, #d1d5db 0%, #e5e7eb 100%);
  border-radius: 6px 6px 0 0;
  min-height: 4px;
  position: relative;
  transition: all 0.3s;
  cursor: default;
}
.week-bar:hover { transform: scaleY(1.05); transform-origin: bottom; }
.week-day.is-today .week-bar {
  background: linear-gradient(to top, #f59e0b 0%, #fcd34d 100%);
  box-shadow: 0 0 12px rgba(252, 211, 77, 0.4);
}
.week-bar-label {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: #6b7280;
  white-space: nowrap;
  font-weight: 500;
}
.week-day.is-today .week-bar-label { color: #f59e0b; font-weight: 600; }
.week-label {
  font-size: 12px;
  color: #6b7280;
  font-weight: 500;
}
.week-day.is-today .week-label { color: #f59e0b; font-weight: 600; }

/* 成就 */
.stats-achievements {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}
.achievement {
  position: relative;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 14px;
  padding: 14px 8px;
  text-align: center;
  transition: all 0.2s;
}
.achievement.unlocked {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-color: rgba(245, 158, 11, 0.3);
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.15);
}
.achievement.locked { opacity: 0.5; filter: grayscale(0.5); }
.achievement-icon {
  font-size: 32px;
  margin-bottom: 6px;
  display: block;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}
.achievement-name {
  font-size: 12px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 2px;
}
.achievement-desc {
  font-size: 10px;
  color: #6b7280;
  line-height: 1.3;
}
.achievement-check, .achievement-lock {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
}
.achievement-check {
  background: #10b981;
  color: #fff;
}
.achievement-lock {
  background: rgba(0, 0, 0, 0.2);
  color: #6b7280;
}

/* 设置面板上的"查看统计"按钮 */
.tool-btn-block {
  width: 100%;
  padding: 10px 16px;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  color: #92400e;
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.tool-btn-block:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.2);
}

/* 深色模式适配 */
[data-theme="dark"] .stats-modal { background: #1a1814; }
[data-theme="dark"] .stats-modal-body { background: #1a1814; }
[data-theme="dark"] .stats-modal-header {
  background: linear-gradient(135deg, #252220 0%, #2d2a25 100%);
  border-bottom-color: rgba(255, 255, 255, 0.05);
}
[data-theme="dark"] .stats-modal-header h3 { color: #e8e6e3; }
[data-theme="dark"] .stats-card {
  background: linear-gradient(135deg, #252220 0%, #2d2a25 100%);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
[data-theme="dark"] .stats-card-value {
  background: linear-gradient(135deg, #e8e6e3 0%, #fcd34d 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
[data-theme="dark"] .stats-card-label { color: rgba(232, 230, 227, 0.6); }
[data-theme="dark"] .stats-card-icon { color: #fcd34d; }
[data-theme="dark"] .stats-unit { color: rgba(232, 230, 227, 0.6); -webkit-text-fill-color: rgba(232, 230, 227, 0.6); }
[data-theme="dark"] .stats-section h4 { color: #e8e6e3; }
[data-theme="dark"] .week-bar { background: linear-gradient(to top, #3a3530 0%, #4a4540 100%); }
[data-theme="dark"] .week-day.is-today .week-bar {
  background: linear-gradient(to top, #f59e0b 0%, #fcd34d 100%);
}
[data-theme="dark"] .week-label { color: rgba(232, 230, 227, 0.6); }
[data-theme="dark"] .week-day.is-today .week-label { color: #fcd34d; }
[data-theme="dark"] .week-bar-label { color: rgba(232, 230, 227, 0.6); }
[data-theme="dark"] .week-day.is-today .week-bar-label { color: #fcd34d; }
[data-theme="dark"] .achievement {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .achievement.unlocked {
  background: linear-gradient(135deg, #2d2a25 0%, #3a3530 100%);
  border-color: rgba(252, 211, 77, 0.3);
  box-shadow: 0 2px 12px rgba(252, 211, 77, 0.15);
}
[data-theme="dark"] .achievement-name { color: #e8e6e3; }
[data-theme="dark"] .achievement-desc { color: rgba(232, 230, 227, 0.6); }
[data-theme="dark"] .tool-btn-block {
  background: linear-gradient(135deg, #2d2a25 0%, #3a3530 100%);
  color: #fcd34d;
  border-color: rgba(252, 211, 77, 0.3);
}

/* ===========================
   P1-4 移动端响应式 + iPad 适配
   =========================== */

/* 移动端菜单按钮默认隐藏 (桌面) */
.mobile-menu-btn { display: none; }

/* iPad 触摸设备 (1025-1366px 触摸) — 保持桌面布局但加大触摸目标 */
@media (min-width: 1025px) and (max-width: 1366px) and (hover: none) and (pointer: coarse) {
  .icon-btn { width: 44px; height: 44px; }
  .tool-btn { min-height: 44px; padding: 10px 14px; }
  .option-btn { min-height: 44px; }
  .nav-btn { width: 44px; height: 44px; }
  .toc-drawer { width: 320px; }
}

/* 紧凑 / iPad 竖屏 (640-1024px) */
@media (max-width: 1024px) {
  .reader-header .reader-chapter-info { max-width: 50%; }
  .mobile-menu-btn { display: flex; }
  .toc-drawer { width: 320px; }
}

/* 手机 (< 640px) */
@media (max-width: 640px) {
  :root { --header-h: 56px; --footer-h: 56px; }

  /* 顶栏精简：隐藏左右章按钮，隐藏进度胶囊 (移动端在底部 action sheet 显示) */
  .reader-header .reader-chapter-info { display: none; }
  .reader-header .reader-header-right { display: none; }

  /* 顶栏：返回 + 章节标题 + 菜单 */
  .reader-header {
    padding: 0 12px;
    gap: 8px;
  }
  .reader-header .reader-back { width: 44px; height: 44px; }
  .reader-chapter-title { font-size: 14px; }
  .mobile-menu-btn { display: flex; width: 44px; height: 44px; }

  /* 底栏精简：隐藏字号 + 上下章单独大按钮 */
  .reader-footer { padding: 8px 12px; flex-wrap: wrap; gap: 6px; }
  .reader-footer .footer-left { display: none; }
  .reader-footer .footer-right { flex-wrap: wrap; gap: 6px; justify-content: center; }
  .reader-footer .tool-btn {
    padding: 0;  /* 移动端只留圆形 icon */
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    gap: 0;
    flex-shrink: 0;
  }
  .reader-footer .tool-btn > i {
    font-size: 18px;  /* 移动端 icon 可见 */
    line-height: 1;
    font-weight: 900;  /* font-awesome solid 需要 900（iPhone 上 body 重量为 400） */
  }
  /* 所有 footer 的 i 包括 modal 等需要 solid 900 */
  .reader-footer .fa-solid, .reader-footer .fas { font-weight: 900; }
  .reader-footer .fa-regular, .reader-footer .far { font-weight: 400; }
  .reader-footer .tool-btn span:not(.fa) { display: none; }

  /* 笔记 drawer → 底部抽屉 */
  .notes-drawer {
    top: auto !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 60vh !important;
    max-height: 60vh !important;
    border-radius: 16px 16px 0 0 !important;
    transform: translateY(100%);
  }
  .notes-drawer.open { transform: translateY(0) !important; }

  /* 设置/笔记/搜索/统计弹窗 → 底部全屏 */
  .settings-panel,
  .stats-modal,
  .note-modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 90vh !important;
    height: auto !important;
    border-radius: 16px 16px 0 0 !important;
    margin: 0 !important;
    align-self: flex-end !important;
  }
  .settings-overlay,
  .stats-modal-overlay,
  .note-modal-overlay {
    align-items: flex-end !important;
  }

  /* 笔记 toolbar → 底部 sheet */
  .selection-toolbar {
    position: fixed !important;
    bottom: calc(var(--footer-h) + 16px) !important;
    top: auto !important;
    left: 16px !important;
    right: 16px !important;
    width: auto !important;
    justify-content: center !important;
    border-radius: 12px !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3) !important;
  }
  .selection-toolbar .sel-btn { width: 48px; height: 48px; }

  /* 进度条加粗 */
  .reader-progress-bar { height: 4px; }

  /* 弹窗 header padding */
  .stats-modal-header,
  .settings-header { padding: 16px 20px; }
}

/* ===========================
   移动端底部 action sheet
   =========================== */
.mobile-action-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.mobile-action-sheet-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.mobile-action-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999;
  background: var(--container, #fff);
  border-radius: 16px 16px 0 0;
  padding: 12px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
  display: none; /* 默认隐藏，> 1024px 永不显示 */
}
@media (max-width: 1024px) {
  .mobile-action-sheet { display: block; }
}
.mobile-action-sheet.open {
  transform: translateY(0);
}

.mobile-sheet-handle {
  width: 36px;
  height: 4px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.mobile-progress-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  color: #92400e;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
}
.mobile-progress-pill i { color: #f59e0b; }

.mobile-menu-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.mobile-menu-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 8px;
  border: 1px solid var(--border, rgba(0,0,0,0.08));
  border-radius: 12px;
  background: var(--soft-bg, rgba(0,0,0,0.02));
  color: var(--text-primary, #1f2937);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  min-height: 80px;
  transition: all 0.15s;
}
.mobile-menu-item:hover, .mobile-menu-item:active {
  background: var(--soft-bg-hover, rgba(0,0,0,0.06));
  transform: translateY(-1px);
}
.mobile-menu-item i {
  font-size: 20px;
  color: var(--primary, #f59e0b);
}

[data-theme="dark"] .mobile-action-sheet {
  background: #1a1814;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .mobile-sheet-handle { background: rgba(255, 255, 255, 0.2); }
[data-theme="dark"] .mobile-progress-pill {
  background: linear-gradient(135deg, #2d2a25 0%, #3a3530 100%);
  color: #fcd34d;
}
[data-theme="dark"] .mobile-menu-item {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
  color: #e8e6e3;
}
[data-theme="dark"] .mobile-menu-item:hover, [data-theme="dark"] .mobile-menu-item:active {
  background: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .mobile-menu-item i { color: #fcd34d; }

/* ===========================
   P1-5 云同步 (登录页 + 用户菜单)
   =========================== */

/* 同步状态点 */
.sync-status-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  width: 18px;
  height: 18px;
  cursor: default;
  animation: sync-pulse 2s ease-in-out infinite;
}
.sync-status-dot.synced { animation: none; }
@keyframes sync-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* 登录页 */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: auth-fade-in 0.3s ease-out;
}
@keyframes auth-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.auth-panel {
  background: #fdf6e3;
  border-radius: 20px;
  width: min(420px, 100%);
  padding: 32px 28px 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: auth-scale-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes auth-scale-in {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}
.auth-header {
  text-align: center;
  margin-bottom: 24px;
}
.auth-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #f59e0b;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.2);
}
.auth-header h3 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 600;
  color: #1f2937;
}
.auth-subtitle {
  margin: 0;
  font-size: 13px;
  color: #6b7280;
}
.auth-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  color: #6b7280;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.auth-tab.active {
  background: #fff;
  color: #1f2937;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.auth-body { display: flex; flex-direction: column; gap: 12px; }
.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-field label {
  font-size: 12px;
  color: #6b7280;
  font-weight: 500;
}
.auth-field input {
  padding: 12px 14px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 10px;
  background: #fff;
  color: #1f2937;
  font-size: 14px;
  transition: all 0.15s;
  font-family: inherit;
}
.auth-field input:focus {
  outline: none;
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}
.auth-error {
  padding: 10px 12px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #b91c1c;
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
}
.auth-submit {
  margin-top: 8px;
  padding: 12px;
  background: linear-gradient(135deg, #f59e0b 0%, #fcd34d 100%);
  color: #1f2937;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.auth-submit:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.3);
}
.auth-submit:disabled { opacity: 0.6; cursor: not-allowed; }
.auth-skip {
  padding: 10px;
  background: transparent;
  color: #6b7280;
  border: none;
  font-size: 13px;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.15s;
}
.auth-skip:hover { background: rgba(0, 0, 0, 0.04); color: #1f2937; }

/* 用户菜单 */
.user-menu {
  position: fixed;
  top: 56px;
  right: 12px;
  z-index: 250;
  background: #fdf6e3;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  min-width: 240px;
  opacity: 0;
  transform: translateY(-8px);
  transition: all 0.2s ease-out;
}
.user-menu.open { opacity: 1; transform: translateY(0); }
.user-menu-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
.user-avatar {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #f59e0b;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name {
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-status {
  font-size: 11px;
  color: #10b981;
  margin-top: 2px;
}
.user-menu-items { padding: 4px; }
.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: #1f2937;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.user-menu-item:hover { background: rgba(0, 0, 0, 0.05); }
.user-menu-item i { color: #f59e0b; width: 16px; text-align: center; }

/* 深色模式 */
[data-theme="dark"] .auth-panel { background: #1a1814; }
[data-theme="dark"] .auth-header h3 { color: #e8e6e3; }
[data-theme="dark"] .auth-subtitle { color: rgba(232, 230, 227, 0.6); }
[data-theme="dark"] .auth-tab { color: rgba(232, 230, 227, 0.6); }
[data-theme="dark"] .auth-tab.active {
  background: rgba(255, 255, 255, 0.08);
  color: #e8e6e3;
}
[data-theme="dark"] .auth-field input {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.1);
  color: #e8e6e3;
}
[data-theme="dark"] .auth-field input:focus {
  border-color: #fcd34d;
  box-shadow: 0 0 0 3px rgba(252, 211, 77, 0.15);
}
[data-theme="dark"] .auth-field label { color: rgba(232, 230, 227, 0.6); }
[data-theme="dark"] .auth-error {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}
[data-theme="dark"] .user-menu { background: #1a1814; border: 1px solid rgba(255, 255, 255, 0.08); }
[data-theme="dark"] .user-menu-header { border-bottom-color: rgba(255, 255, 255, 0.08); }
[data-theme="dark"] .user-name { color: #e8e6e3; }
[data-theme="dark"] .user-menu-item { color: #e8e6e3; }
[data-theme="dark"] .user-menu-item:hover { background: rgba(255, 255, 255, 0.08); }

/* 移动端: 同步状态点小一些 */
@media (max-width: 640px) {
  .sync-status-dot { width: 14px; height: 14px; font-size: 8px; }
  .user-menu { right: 8px; min-width: 220px; }
}

/* ===========================
   P2-1 听书 TTS + 音频上传
   =========================== */

/* TTS 句子高亮（iframe 内） */
mark.ebook-tts-sentence {
  background: linear-gradient(120deg, #fcd34d 0%, #fbbf24 100%) !important;
  color: #1a1814 !important;
  padding: 2px 4px;
  border-radius: 4px;
  font-weight: 600;
  box-shadow: 0 0 12px rgba(252, 211, 77, 0.4);
}

/* 听书面板 */
.tts-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: tts-fade-in 0.3s ease-out;
}
@keyframes tts-fade-in { from { opacity: 0; } to { opacity: 1; } }

.tts-panel {
  background: linear-gradient(135deg, #1a1814 0%, #2d2a25 100%);
  color: #e8e6e3;
  border-radius: 20px;
  width: min(560px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: tts-scale-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}
@keyframes tts-scale-in {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.tts-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  gap: 12px;
}
.tts-header .icon-btn { color: rgba(255, 255, 255, 0.7); }
.tts-header .icon-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.tts-title {
  font-size: 16px;
  font-weight: 600;
  color: #fcd34d;
  flex: 1;
}
.tts-chapter {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.tts-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.tts-tab {
  flex: 1;
  padding: 12px 8px;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.tts-tab:hover { color: rgba(255, 255, 255, 0.8); }
.tts-tab.active {
  color: #fcd34d;
  background: rgba(252, 211, 77, 0.08);
  border-bottom: 2px solid #fcd34d;
}

.tts-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
.tts-tab-pane { display: none; }
.tts-tab-pane.active { display: block; }

.tts-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
}
.tts-status i { color: #fcd34d; }

.tts-current-sentence {
  min-height: 60px;
  padding: 16px;
  background: linear-gradient(135deg, rgba(252, 211, 77, 0.12) 0%, rgba(251, 191, 36, 0.08) 100%);
  border: 1px solid rgba(252, 211, 77, 0.2);
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  color: #f5ebd6;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  text-align: center;
  font-style: italic;
}

.tts-progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.tts-progress-text {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  font-variant-numeric: tabular-nums;
  min-width: 50px;
  text-align: right;
}
.tts-progress-bar {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
}
.tts-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #f59e0b 0%, #fcd34d 100%);
  border-radius: 2px;
  transition: width 0.3s;
  width: 0%;
}

.tts-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
}
.tts-btn {
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tts-btn:hover { background: rgba(255, 255, 255, 0.1); transform: scale(1.05); }
.tts-btn-play {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, #f59e0b 0%, #fcd34d 100%);
  color: #1a1814;
  border: none;
  font-size: 22px;
  box-shadow: 0 4px 16px rgba(252, 211, 77, 0.3);
}
.tts-btn-play:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(252, 211, 77, 0.4); }

.tts-settings { display: flex; flex-direction: column; gap: 14px; }
.tts-setting-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.tts-setting-row label {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  min-width: 56px;
}
.tts-rate-row {
  flex: 1;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.tts-rate-btn {
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.tts-rate-btn:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.tts-rate-btn.active {
  background: #fcd34d;
  color: #1a1814;
  border-color: #fcd34d;
  font-weight: 600;
}
.tts-voice-select {
  flex: 1;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #e8e6e3;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}

/* 音频列表 */
.tts-audio-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tts-audio-empty {
  text-align: center;
  padding: 40px 20px;
  color: rgba(255, 255, 255, 0.4);
}
.tts-audio-empty i { font-size: 48px; color: rgba(255, 255, 255, 0.2); margin-bottom: 12px; }
.tts-audio-empty p { margin: 0 0 4px; font-size: 14px; }
.tts-audio-empty small { font-size: 12px; color: rgba(255, 255, 255, 0.3); }

.tts-audio-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
}
.tts-audio-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #f59e0b 0%, #fcd34d 100%);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #1a1814;
  font-size: 14px;
  flex-shrink: 0;
}
.tts-audio-info { flex: 1; min-width: 0; }
.tts-audio-name {
  font-size: 13px;
  color: #e8e6e3;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tts-audio-meta {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 2px;
}
.tts-audio-play,
.tts-audio-delete {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: none;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
}
.tts-audio-play:hover { background: #fcd34d; color: #1a1814; }
.tts-audio-delete:hover { background: #ef4444; color: #fff; }

/* 上传区 */
.tts-upload-section h4 {
  margin: 0 0 8px;
  font-size: 14px;
  color: #fcd34d;
}
.tts-current-file {
  margin: 0 0 12px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  font-family: monospace;
}
.tts-upload-zone {
  padding: 32px 16px;
  border: 2px dashed rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  text-align: center;
  color: rgba(255, 255, 255, 0.6);
  transition: all 0.2s;
  cursor: pointer;
}
.tts-upload-zone:hover, .tts-upload-zone.dragging {
  border-color: #fcd34d;
  background: rgba(252, 211, 77, 0.05);
  color: #fcd34d;
}
.tts-upload-zone i { font-size: 32px; margin-bottom: 8px; color: #fcd34d; }
.tts-upload-zone p { margin: 0 0 4px; font-size: 14px; }
.tts-upload-zone small { font-size: 12px; color: rgba(255, 255, 255, 0.4); }
.tts-upload-zone .btn-primary {
  margin-top: 12px;
  padding: 8px 16px;
  background: linear-gradient(135deg, #f59e0b 0%, #fcd34d 100%);
  color: #1a1814;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.tts-upload-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tts-upload-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  font-size: 12px;
}
.tts-upload-item.uploading { color: #fcd34d; }
.tts-upload-item.done { color: #10b981; }
.tts-upload-item.error { color: #ef4444; }
.tts-upload-item .tts-audio-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tts-progress-pct {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  text-align: right;
}

/* 移动端 */
@media (max-width: 640px) {
  .tts-panel { max-height: 95vh; }
  .tts-btn { width: 44px; height: 44px; }
  .tts-btn-play { width: 56px; height: 56px; }
  .tts-rate-btn { padding: 5px 8px; font-size: 11px; }
}



/* ===========================
   P2-1 自定义音频播放器 (A-pro)
   =========================== */
.audio-player {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 380px;
  background: linear-gradient(135deg, #1a1814 0%, #2d2a25 100%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  z-index: 997;
  color: #e8e6e3;
  user-select: none;
  transition: opacity 0.2s, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.audio-player[data-minimized="true"] {
  bottom: 20px;
  right: 20px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  padding: 0;
  overflow: hidden;             /* 兑底：子元素溢出隐藏 */
  background: linear-gradient(135deg, #f59e0b 0%, #fcd34d 100%);
  color: #1a1814;
  box-shadow: 0 4px 16px rgba(252, 211, 77, 0.4);
}
.audio-player[data-minimized="true"] .audio-player-progress-row,
.audio-player[data-minimized="true"] .audio-player-controls,
.audio-player[data-minimized="true"] .audio-player-queue-panel,
.audio-player[data-minimized="true"] .audio-player-btn:not(#btn-audio-close),
.audio-player[data-minimized="true"] .audio-player-info,
.audio-player[data-minimized="true"] .audio-player-row-2 {
  display: none !important;
}
.audio-player[data-minimized="true"] .audio-player-drag-handle {
  display: flex;
  padding: 0;
  margin: 0;
  gap: 0;                       /* 默认 gap:12px 会在 56px 圆内撑出空间，minimized 须重置 */
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  background: transparent;
  cursor: grab;
  position: relative;
}
.audio-player[data-minimized="true"] .audio-player-info { display: none; }
.audio-player[data-minimized="true"] .audio-player-cover {
  width: 56px;
  height: 56px;
  font-size: 26px;
  background: transparent;
  box-shadow: none;
  color: #1a1814;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.audio-player[data-minimized="true"] #btn-audio-close {
  display: flex !important;          /* minimized 状态唯一可见的按钮 */
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  min-width: 20px;
  border-radius: 50%;
  background: rgba(26, 24, 20, 0.85);
  color: #fcd34d;
  font-size: 11px;
  padding: 0;
  margin: 0;
  z-index: 2;
  border: none;
  cursor: pointer;
}
.audio-player[data-minimized="true"] #btn-audio-close:hover {
  background: rgba(26, 24, 20, 1);
  transform: scale(1.1);
}
.audio-player[data-minimized="true"]::after {
  content: '';
}
.audio-player-drag-handle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px 8px;
  cursor: grab;
}
.audio-player-drag-handle:active { cursor: grabbing; }
.audio-player-cover {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #f59e0b 0%, #fcd34d 100%);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #1a1814;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(252, 211, 77, 0.3);
}
.audio-player-info {
  flex: 1;
  min-width: 0;
}
.audio-player-title {
  font-size: 14px;
  font-weight: 600;
  color: #f5ebd6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.audio-player-time-row {
  font-size: 11px;
  color: rgba(232, 230, 227, 0.5);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
  font-variant-numeric: tabular-nums;
}
.audio-player-source {
  margin-left: 4px;
  color: rgba(252, 211, 77, 0.7);
}
.audio-player-btn {
  width: 28px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(232, 230, 227, 0.8);
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  transition: all 0.15s;
  flex-shrink: 0;
}
.audio-player-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}
.audio-player-progress-row {
  padding: 6px 14px 4px;
}
.audio-player-progress {
  height: 5px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  position: relative;
  cursor: pointer;
  touch-action: none;
}
.audio-player-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #f59e0b 0%, #fcd34d 100%);
  border-radius: 3px;
  width: 0%;
  pointer-events: none;
  transition: width 0.1s linear;
  box-shadow: 0 0 8px rgba(252, 211, 77, 0.4);
}
.audio-player-progress-handle {
  position: absolute;
  top: 50%;
  left: 0;
  width: 12px;
  height: 12px;
  background: #fcd34d;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow: 0 0 8px rgba(252, 211, 77, 0.6);
  opacity: 1;
  transition: opacity 0.2s;
}
.audio-player-progress:hover .audio-player-progress-handle { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
.audio-player-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px 8px;
  flex-wrap: wrap;
  row-gap: 8px;
}
.audio-player-row-2 {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px 10px;
}
.audio-player-btn-play {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #f59e0b 0%, #fcd34d 100%);
  color: #1a1814;
  border: none;
  font-size: 16px;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(252, 211, 77, 0.3);
}
.audio-player-btn-play:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(252, 211, 77, 0.4);
}
.audio-btn-label {
  font-size: 9px;
  margin-left: 1px;
}
.audio-player-rate-group {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  padding: 2px;
  margin-left: auto;
  flex-shrink: 0;
}
.audio-player-rate-btn {
  width: auto;
  height: 28px;
  padding: 0 8px;
  background: transparent;
  color: rgba(232, 230, 227, 0.6);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  border: none;
  cursor: pointer;
}
.audio-player-rate-btn.active {
  background: #fcd34d;
  color: #1a1814;
}
.audio-player-volume {
  display: none; /* 现在独立在 row-2 */
}
.audio-player-volume i { font-size: 11px; }
.audio-player-volume-slider {
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(to right, #f59e0b 0%, #fcd34d var(--vol, 80%), rgba(255, 255, 255, 0.15) var(--vol, 80%));
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  flex: 1;
}
.audio-player-volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  background: #fcd34d;
  border-radius: 50%;
  cursor: pointer;
}
.audio-player-volume-slider::-moz-range-thumb {
  width: 10px;
  height: 10px;
  background: #fcd34d;
  border-radius: 50%;
  border: none;
  cursor: pointer;
}
/* 队列面板 */
.audio-player-queue-panel {
  position: absolute;
  bottom: 100%;
  right: 0;
  left: 0;
  margin-bottom: 8px;
  background: #1a1814;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  max-height: 280px;
  overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.audio-queue-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  color: rgba(232, 230, 227, 0.6);
  font-weight: 600;
}
.audio-queue-clear {
  background: transparent;
  border: none;
  color: rgba(252, 211, 77, 0.7);
  font-size: 11px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.audio-queue-clear:hover { background: rgba(255, 255, 255, 0.06); }
.audio-queue-list {
  padding: 4px;
}
.audio-queue-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: rgba(232, 230, 227, 0.7);
  transition: all 0.15s;
}
.audio-queue-item:hover { background: rgba(255, 255, 255, 0.06); }
.audio-queue-item.active {
  background: rgba(252, 211, 77, 0.15);
  color: #fcd34d;
}
.audio-queue-item i { color: #fcd34d; width: 14px; }
.audio-queue-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.audio-queue-source { font-size: 14px; }

/* 移动端 / iPad */
@media (max-width: 640px) {
  .audio-player {
    width: calc(100vw - 24px);
    right: 12px;
    left: 12px;
    bottom: 12px;
  }
  .audio-player[data-minimized="true"] {
    width: 40px;
    height: 40px;
    left: auto;
    font-size: 18px;
  }
  .audio-player-volume { display: none; }
}
@media (min-width: 641px) and (max-width: 1024px) {
  .audio-player { width: 360px; }
}

/* =============================================
   P2-3-E2 书籍合集 Tabs
   ============================================= */
.collections-section { padding: 12px 24px 8px; }
.collections-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 4px;
}
.collections-tabs::-webkit-scrollbar { display: none; }
.collection-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1.5px solid var(--border-color, #e5e7eb);
  background: var(--bg-primary, #fff);
  border-radius: 18px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  color: var(--text-secondary, #4b5563);
  transition: all 0.18s;
  white-space: nowrap;
  position: relative;
}
.collection-tab i { font-size: 12px; }
.collection-tab:hover { border-color: var(--col-color, var(--text-secondary, #9ca3af)); color: var(--col-color, var(--text-secondary, #4b5563)); }
.collection-tab.active {
  background: var(--col-color, #3b82f6);
  border-color: var(--col-color, #3b82f6);
  color: #fff;
  font-weight: 600;
}
.collection-tab.active .collection-count { background: rgba(255, 255, 255, 0.28); color: #fff; }
.collection-count {
  font-size: 10px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 8px;
  padding: 1px 6px;
  min-width: 16px;
  text-align: center;
  color: var(--text-secondary, #9ca3af);
}
.collection-tab.collection-add {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  justify-content: center;
  color: var(--text-secondary, #9ca3af);
}
.collection-edit-hint {
  margin-left: 4px;
  font-size: 11px;
  opacity: 0.8;
  cursor: pointer;
}
.books-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 48px 16px;
  color: var(--text-secondary, #9ca3af);
}
.books-empty i { font-size: 36px; opacity: 0.4; }
.books-empty p { margin: 12px 0 4px; }
.books-empty small { font-size: 12px; }

/* 合集管理 modal */
.collection-manage-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: modal-fade-in 0.2s ease-out;
}
.collection-manage-modal {
  background: var(--bg-primary, #fff);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  animation: modal-scale-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.collection-manage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.collection-manage-header h3 { margin: 0; font-size: 16px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.collection-manage-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.cm-section { margin-bottom: 18px; }
.cm-label {
  font-size: 11px;
  color: var(--text-secondary, #6b7280);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 8px;
}
.cm-book-list {
  background: var(--bg-tertiary, #f3f4f6);
  border-radius: 8px;
  padding: 8px;
  min-height: 40px;
}
.cm-empty { padding: 12px; text-align: center; color: var(--text-secondary, #9ca3af); font-size: 12px; }
.cm-book {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-primary, #fff);
  border-radius: 6px;
  margin-bottom: 4px;
}
.cm-book:last-child { margin-bottom: 0; }
.cm-book-title { font-size: 13px; }
.cm-remove, .cm-add {
  border: none;
  background: transparent;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  font-family: inherit;
}
.cm-remove { color: #ef4444; }
.cm-remove:hover { background: rgba(239, 68, 68, 0.08); }
.cm-add { color: #10b981; }
.cm-add:hover { background: rgba(16, 185, 129, 0.08); }
.collection-manage-footer {
  display: flex;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--border-color, #e5e7eb);
}
.btn-danger { color: #ef4444; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.08); }

/* =============================================
   P2-3-E3 章末复习 Modal
   ============================================= */
.review-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: modal-fade-in 0.2s ease-out;
}
.review-modal {
  background: var(--bg-primary, #fff);
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  animation: modal-scale-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.review-header {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.review-header-main h3 { margin: 0 0 4px; font-size: 16px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; color: #f59e0b; }
.review-sub { margin: 0; font-size: 12px; color: var(--text-secondary, #6b7280); }
.review-stats {
  display: flex;
  gap: 0;
  padding: 12px 20px;
  background: var(--bg-tertiary, #f3f4f6);
}
.rv-stat {
  flex: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.rv-stat strong { font-size: 22px; font-weight: 700; color: var(--text-primary, #111827); line-height: 1; }
.rv-stat span { font-size: 11px; color: var(--text-secondary, #6b7280); margin-top: 4px; }
.review-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.rv-empty { text-align: center; padding: 36px 16px; color: var(--text-secondary, #9ca3af); }
.rv-empty i { font-size: 36px; opacity: 0.4; }
.rv-empty p { margin: 12px 0 4px; }
.rv-empty small { font-size: 12px; }
.rv-group { margin-bottom: 16px; }
.rv-group-title { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.rv-group-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
}
.rv-group-tag-none { background: #9ca3af; }
.rv-group-count { font-size: 12px; color: var(--text-secondary, #9ca3af); }
.rv-item {
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--bg-secondary, #fafafa);
}
.rv-item-quote {
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 6px;
  color: rgba(0, 0, 0, 0.85);
}
.rv-item-note {
  font-size: 13px;
  color: var(--text-primary, #111827);
  padding: 6px 10px;
  border-left: 3px solid #f59e0b;
  background: rgba(245, 158, 11, 0.08);
  border-radius: 0 6px 6px 0;
  margin-top: 4px;
  white-space: pre-wrap;
}
.review-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border-color, #e5e7eb);
}

/* =============================================
   P2-3-E4 快捷键面板（VSCode 风格）
   ============================================= */
.shortcuts-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 9999;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 80px 24px 24px;
  animation: modal-fade-in 0.2s ease-out;
  backdrop-filter: blur(4px);
}
.shortcuts-modal {
  background: var(--bg-primary, #fff);
  border-radius: 14px;
  width: 100%;
  max-width: 540px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
  animation: modal-scale-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}
.shortcuts-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.shortcuts-header h3 { margin: 0; font-size: 16px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.shortcuts-header h3 i { color: #6366f1; }
.shortcuts-body { padding: 16px 20px; max-height: 60vh; overflow-y: auto; }
.shortcuts-section { margin-bottom: 16px; }
.shortcuts-section h4 {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary, #6b7280);
}
.shortcuts-rows { display: flex; flex-direction: column; gap: 6px; }
.shortcuts-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-radius: 6px;
}
.shortcuts-row:hover { background: var(--bg-tertiary, #f3f4f6); }
.shortcuts-row kbd {
  display: inline-block;
  background: var(--bg-secondary, #f9fafb);
  border: 1px solid var(--border-color, #d1d5db);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 2px 7px;
  font-size: 11px;
  font-family: 'SF Mono', Menlo, monospace;
  color: var(--text-primary, #111827);
  white-space: nowrap;
  margin-right: 4px;
}
.shortcuts-row span { font-size: 13px; color: var(--text-secondary, #4b5563); }
.shortcuts-footer {
  padding: 10px 20px 14px;
  border-top: 1px solid var(--border-color, #e5e7eb);
  color: var(--text-secondary, #9ca3af);
}

/* =============================================
   P0-B 阅读统计：目标环 / 热力图 / 洞察卡片
   ============================================= */

/* 目标环（双层 SVG circle） */
.goal-rings-wrap {
  display: flex;
  gap: 18px;
  align-items: center;
  padding: 18px 14px;
  background: linear-gradient(135deg, #fafbfc 0%, #f3f4f6 100%);
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.04);
}
.goal-ring-svg-wrap {
  width: 130px;
  height: 130px;
  flex-shrink: 0;
}
.goal-ring-svg { width: 100%; height: 100%; }
.goal-ring-progress {
  transition: stroke-dashoffset 1.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.goal-ring-num {
  font-size: 26px;
  font-weight: 700;
  fill: #111827;
}
.goal-ring-unit {
  font-size: 9px;
  fill: #6b7280;
}
.goal-ring-tiny {
  font-size: 9px;
  fill: #9ca3af;
}
.goal-legend {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.goal-legend-item {
  display: grid;
  grid-template-columns: 12px 1fr auto auto;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
}
.goal-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.goal-label { color: var(--text-secondary, #6b7280); font-weight: 500; }
.goal-val {
  color: var(--text-primary, #111827);
  font-weight: 600;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.goal-pct {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary, #6b7280);
  min-width: 30px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.goal-edit-btn {
  margin-top: 4px;
  background: rgba(99, 102, 241, 0.08);
  color: #6366f1;
  border: 1px dashed #6366f1;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.goal-edit-btn:hover {
  background: #6366f1;
  color: #fff;
}

/* 热力图（30 天） */
.heatmap-wrap {
  padding: 14px;
  background: linear-gradient(135deg, #fafbfc 0%, #f3f4f6 100%);
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.04);
}
.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 4px;
  margin-bottom: 12px;
}
.hm-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  background: #e5e7eb;
  transition: transform 0.15s;
  cursor: default;
}
.hm-cell:hover { transform: scale(1.18); }
.hm-l0 { background: #ebedf0; }
.hm-l1 { background: #9be9a8; }
.hm-l2 { background: #40c463; }
.hm-l3 { background: #30a14e; }
.hm-l4 { background: #216e39; box-shadow: 0 0 8px rgba(33, 110, 57, 0.4); }
.hm-today {
  outline: 2px solid #6366f1;
  outline-offset: 1px;
  position: relative;
  animation: hm-today-pulse 2.4s ease-in-out infinite;
}
.hm-today-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 14px;
  height: 14px;
  background: #6366f1;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(99, 102, 241, 0.5);
  z-index: 2;
  pointer-events: none;
  line-height: 1;
}
@keyframes hm-today-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4); }
  50%      { box-shadow: 0 0 0 5px rgba(99, 102, 241, 0); }
}
.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-secondary, #6b7280);
  margin-bottom: 8px;
  justify-content: flex-end;
}
.heatmap-legend .hm-cell {
  width: 12px;
  height: 12px;
  aspect-ratio: auto;
  border-radius: 3px;
}
.heatmap-stats {
  font-size: 12px;
  color: var(--text-secondary, #6b7280);
  text-align: center;
}
.heatmap-stats strong {
  color: var(--text-primary, #111827);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 0 2px;
}

/* 节奏洞察卡片 */
.insights-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.insight-card {
  background: linear-gradient(135deg, #ffffff 0%, #fafbfc 100%);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
.insight-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.06);
}
.insight-icon {
  font-size: 24px;
  margin-bottom: 4px;
}
.insight-val {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary, #111827);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  margin-bottom: 2px;
}
.insight-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.insight-desc {
  font-size: 11px;
  color: var(--text-secondary, #9ca3af);
  margin-top: 4px;
}

/* 移动端 */
@media (max-width: 640px) {
  .goal-rings-wrap { flex-direction: column; padding: 14px 12px; }
  .goal-ring-svg-wrap { width: 110px; height: 110px; }
  .heatmap-grid { grid-template-columns: repeat(15, 1fr); gap: 3px; }
  .insights-grid { grid-template-columns: 1fr; }
}

/* dark mode */
[data-theme="dark"] .goal-rings-wrap,
[data-theme="dark"] .heatmap-wrap {
  background: linear-gradient(135deg, #252220 0%, #2d2a25 100%);
  border-color: rgba(255, 255, 255, 0.06);
}
[data-theme="dark"] .goal-legend-item { background: rgba(255, 255, 255, 0.06); }
[data-theme="dark"] .goal-ring-num { fill: #e8e6e3; }
[data-theme="dark"] .goal-ring-unit, [data-theme="dark"] .goal-ring-tiny { fill: rgba(232, 230, 227, 0.5); }
[data-theme="dark"] .hm-l0 { background: #2d2a25; }
[data-theme="dark"] .hm-l1 { background: rgba(155, 233, 168, 0.4); }
[data-theme="dark"] .hm-l2 { background: rgba(64, 196, 99, 0.6); }
[data-theme="dark"] .hm-l3 { background: rgba(48, 161, 78, 0.8); }
[data-theme="dark"] .hm-l4 { background: #40c463; }
[data-theme="dark"] .hm-today {
  animation: hm-today-pulse-dark 2.4s ease-in-out infinite;
}
@keyframes hm-today-pulse-dark {
  0%, 100% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0.4); }
  50%      { box-shadow: 0 0 0 5px rgba(167, 139, 250, 0); }
}
[data-theme="dark"] .insight-card {
  background: linear-gradient(135deg, #252220 0%, #2d2a25 100%);
  border-color: rgba(255, 255, 255, 0.06);
}
[data-theme="dark"] .insight-val { color: #e8e6e3; }
[data-theme="dark"] .heatmap-stats strong { color: #e8e6e3; }

/* =============================================
   P1 番茄钟 / 阅读计划
   ============================================= */

/* 书架顶部 banner — 大厂重设计 */
.pomo-banner {
  margin: 12px 0 0;
  padding: 14px 20px;
  background: linear-gradient(110deg, #fef3c7 0%, #fde68a 35%, #ffffff 100%);
  border: 1px solid #fcd34d;
  border-radius: 16px;
  box-shadow: 0 4px 16px rgba(245, 158, 11, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  position: relative;
  overflow: hidden;
}
.pomo-banner::before {
  /* 顶部扫光动效 */
  content: '';
  position: absolute;
  top: 0; left: -40%;
  width: 30%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  animation: pomo-banner-shimmer 5s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}
.pomo-banner::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 100% 0%, rgba(255, 255, 255, 0.45), transparent 50%);
  pointer-events: none;
  z-index: 0;
}
@keyframes pomo-banner-shimmer {
  0%, 100% { transform: translateX(0); opacity: 0; }
  20%      { opacity: 1; }
  50%      { transform: translateX(380%); opacity: 1; }
  80%, 100%{ transform: translateX(380%); opacity: 0; }
}
.pomo-banner-empty {
  background: linear-gradient(110deg, #f3f4f6 0%, #e5e7eb 35%, #ffffff 100%);
  border-color: #d1d5db;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.pomo-banner-empty::before { display: none; }
.pomo-banner-inner {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 18px;
}
.pomo-banner-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.pomo-tomato-mini {
  font-size: 36px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(239, 68, 68, 0.3));
  animation: pomo-tomato-wobble 4s ease-in-out infinite;
}
@keyframes pomo-tomato-wobble {
  0%, 100% { transform: rotate(0deg); }
  25%      { transform: rotate(-4deg) scale(1.05); }
  50%      { transform: rotate(0deg) scale(1); }
  75%      { transform: rotate(4deg) scale(1.05); }
}
.pomo-banner-time {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.05;
}
.pomo-banner-time-main {
  font-size: 22px;
  font-weight: 700;
  color: #111827;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}
.pomo-banner-time-sub {
  font-size: 11px;
  color: #92400e;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-top: 2px;
}
.pomo-banner-divider {
  width: 1px;
  height: 38px;
  background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1), transparent);
}
.pomo-banner-mid {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.pomo-banner-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #4b5563;
}
.pomo-banner-row i { font-size: 12px; color: #b45309; opacity: 0.8; }
.pomo-banner-row strong {
  color: #111827;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.pomo-banner-ring-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #6b7280;
}
.pomo-banner-ring {
  flex: 1;
  height: 6px;
  background: rgba(120, 53, 15, 0.1);
  border-radius: 3px;
  overflow: hidden;
  min-width: 80px;
  max-width: 240px;
}
.pomo-banner-fill {
  height: 100%;
  background: linear-gradient(90deg, #fbbf24, #f97316, #ef4444);
  border-radius: 3px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}
.pomo-banner-pct {
  font-weight: 700;
  color: #ef4444;
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  text-align: right;
}
.pomo-banner-open {
  flex-shrink: 0;
  background: linear-gradient(135deg, #ef4444, #f97316);
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.18s;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.2px;
}
.pomo-banner-open:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);
}
.pomo-banner-open:active { transform: translateY(0); }
.pomo-banner-empty-text {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #6b7280;
  flex: 1;
}
.pomo-banner-empty-text i { color: #9ca3af; }
.pomo-banner-cta {
  flex-shrink: 0;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
  transition: all 0.18s;
}
.pomo-banner-cta:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4); }

/* 番茄钟主面板（右下 floating） */
.pomodoro-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  transition: opacity 0.2s;
  backdrop-filter: blur(4px);
}
.pomodoro-overlay.open { opacity: 1; }
.pomodoro-panel {
  background: var(--bg-primary, #fff);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  animation: modal-scale-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}
.pomodoro-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  position: relative;
}
.pomo-tab {
  border: none;
  background: transparent;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.pomo-tab:hover { background: var(--bg-tertiary, #f3f4f6); }
.pomo-tab.active { background: var(--bg-tertiary, #f3f4f6); color: var(--text-primary, #111827); font-weight: 600; }
.pomo-close { margin-left: auto; }
.pomodoro-body { padding: 16px; overflow-y: auto; }

/* Timer 标签 */
.pomo-timer-pane { text-align: center; }
.pomo-circle-wrap {
  width: 280px;
  height: 280px;
  margin: 8px auto 14px;
  position: relative;
}
.pomo-circle-svg { width: 100%; height: 100%; filter: drop-shadow(0 4px 12px rgba(0,0,0,0.06)); }
.pomo-progress { transition: stroke-dashoffset 1s linear; }
.pomo-time { font-size: 56px; font-weight: 700; fill: #111827; font-variant-numeric: tabular-nums; }
.pomo-time-label { font-size: 14px; fill: #6b7280; font-weight: 500; }
.pomo-cycle-text { font-size: 11px; fill: #9ca3af; }
.pomo-plan-link {
  font-size: 12px;
  color: var(--text-secondary, #6b7280);
  padding: 8px 12px;
  background: var(--bg-tertiary, #f3f4f6);
  border-radius: 8px;
  margin-bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.pomo-plan-empty { opacity: 0.6; font-style: italic; }
.pomo-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 14px;
}
.pomo-controls button {
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-primary, #fff);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}
.pomo-controls button:hover { background: var(--bg-tertiary, #f3f4f6); }
.pomo-controls .pomo-btn-start {
  background: #ef4444;
  color: #fff;
  border-color: #ef4444;
  font-weight: 600;
}
.pomo-controls .btn-danger { color: #ef4444; border-color: #fecaca; }
.pomo-cycle-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  padding: 8px;
}
.pomo-cycle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-tertiary, #f3f4f6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-secondary, #9ca3af);
  transition: all 0.18s;
}
.pomo-cycle.done { background: linear-gradient(135deg, #fde68a, #fbbf24); color: #fff; }
.pomo-cycle.current {
  background: linear-gradient(135deg, #ef4444, #f87171);
  color: #fff;
  transform: scale(1.15);
  animation: pomo-pulse 1.6s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
}
.pomo-cycle small { font-size: 8px; opacity: 0.8; }
@keyframes pomo-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

/* Plans 标签 */
.pomo-plans-pane { display: flex; flex-direction: column; gap: 12px; }
.pomo-plans-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.pomo-plans-count {
  font-size: 13px;
  color: var(--text-secondary, #6b7280);
}
.pomo-plans-count strong { color: #ef4444; font-size: 16px; }
.pomo-plans-empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-secondary, #9ca3af);
}
.pomo-plans-empty i { font-size: 36px; opacity: 0.4; }
.pomo-plans-empty p { margin: 12px 0 4px; }
.pomo-plans-empty small { font-size: 12px; }
.pomo-plan-card {
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--bg-secondary, #fafbfc);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.pomo-plan-card:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04); }
.pomo-plan-card.status-completed { opacity: 0.6; background: linear-gradient(135deg, #ecfdf5, #f0fdfa); border-color: #6ee7b7; }
.pomo-plan-card.status-abandoned { opacity: 0.5; }
.pomo-plan-row1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pomo-plan-type {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--bg-tertiary, #f3f4f6);
  border-radius: 10px;
  color: var(--text-secondary, #4b5563);
}
.pomo-plan-title { font-size: 14px; flex: 1; min-width: 0; }
.pomo-plan-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
}
.pomo-plan-status.active { background: #fef3c7; color: #92400e; }
.pomo-plan-status.completed { background: #d1fae5; color: #065f46; }
.pomo-plan-status.abandoned { background: #f3f4f6; color: #6b7280; }
.pomo-plan-row2 {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary, #6b7280);
}
.pomo-plan-book { display: inline-flex; align-items: center; gap: 6px; }
.pomo-plan-days.overdue { color: #ef4444; font-weight: 600; }
.pomo-plan-progress { display: flex; flex-direction: column; gap: 4px; }
.pomo-plan-bar { width: 100%; height: 8px; background: var(--bg-tertiary, #f3f4f6); border-radius: 4px; overflow: hidden; }
.pomo-plan-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #6366f1);
  border-radius: 4px;
  transition: width 0.5s ease;
}
.pomo-plan-meta { font-size: 11px; color: var(--text-secondary, #6b7280); font-variant-numeric: tabular-nums; }
.pomo-plan-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.pomo-plan-actions button {
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-family: inherit;
  border: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-primary, #fff);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}
.pomo-plan-actions button:hover { background: var(--bg-tertiary, #f3f4f6); }
.pomo-plan-actions .pomo-plan-start { background: #ef4444; color: #fff; border-color: #ef4444; font-weight: 600; }
.pomo-plan-actions .btn-danger { color: #ef4444; }

/* Settings 标签 */
.pomo-settings { display: flex; flex-direction: column; gap: 12px; }
.pomo-setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-tertiary, #f3f4f6);
  border-radius: 10px;
}
.pomo-setting-row label { font-size: 13px; color: var(--text-secondary, #4b5563); font-weight: 500; }
.pomo-stepper { display: flex; align-items: center; gap: 8px; }
.pomo-stepper button {
  width: 28px; height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border-color, #d1d5db);
  background: var(--bg-primary, #fff);
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
}
.pomo-stepper button:hover { background: var(--bg-tertiary, #f3f4f6); }
.pomo-stepper span {
  min-width: 36px;
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.pomo-save-settings {
  margin-top: 8px;
  padding: 8px 14px;
  background: #6366f1;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* 计划创建 modal */
.plan-create-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  transition: opacity 0.2s;
}
.plan-create-overlay.open { opacity: 1; }
.plan-create-modal {
  background: var(--bg-primary, #fff);
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  animation: modal-scale-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.plan-create-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.plan-create-header h3 { margin: 0; font-size: 16px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.plan-create-header h3 i { color: #ef4444; }
.plan-create-body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.plan-form-row { display: flex; flex-direction: column; gap: 4px; }
.plan-form-row label { font-size: 12px; font-weight: 600; color: var(--text-secondary, #6b7280); text-transform: uppercase; letter-spacing: 0.3px; }
.plan-form-row select, .plan-form-row input[type=number], .plan-form-row input[type=date] {
  padding: 8px 10px;
  border: 1px solid var(--border-color, #d1d5db);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg-primary, #fff);
  color: inherit;
}
.plan-radio-group { display: flex; gap: 16px; }
.plan-radio-group label {
  font-size: 13px;
  color: var(--text-primary, #111827);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
}
.plan-create-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border-color, #e5e7eb);
}
.plan-create-footer button {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-primary, #fff);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.plan-create-footer .btn-primary { background: #ef4444; color: #fff; border-color: #ef4444; font-weight: 600; }

/* confetti canvas */
.confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99999;
}

/* 移动端 */
@media (max-width: 640px) {
  .pomodoro-panel { max-width: 100%; }
  .pomo-circle-wrap { width: 220px; height: 220px; }
  .pomo-time { font-size: 44px; }
  .pomo-banner-inner { gap: 12px; flex-wrap: wrap; }
  .pomo-banner-mid { gap: 4px; }
  .pomo-tomato-mini { font-size: 28px; }
  .pomo-banner-time-main { font-size: 18px; }
  .pomo-banner-open { padding: 7px 14px; font-size: 12px; }
  .pomo-banner-divider { display: none; }
  .pomo-banner-ring { max-width: 100px; }
}

/* dark mode */
[data-theme="dark"] .pomodoro-panel, [data-theme="dark"] .plan-create-modal {
  background: var(--bg-primary, #1f1d1a);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
[data-theme="dark"] .pomo-banner {
  background: linear-gradient(110deg, #78350f 0%, #92400e 35%, #1f1d1a 100%);
  border-color: #b45309;
  color: #fef3c7;
}
[data-theme="dark"] .pomo-banner-row { color: rgba(254, 243, 199, 0.7); }
[data-theme="dark"] .pomo-banner-row i { color: #fbbf24; }
[data-theme="dark"] .pomo-banner-time-main { color: #fef3c7; }
[data-theme="dark"] .pomo-banner-ring { background: rgba(254, 243, 199, 0.1); }
[data-theme="dark"] .pomo-banner-divider { background: linear-gradient(to bottom, transparent, rgba(254, 243, 199, 0.15), transparent); }
[data-theme="dark"] .pomo-time { fill: #e8e6e3; }
[data-theme="dark"] .pomo-time-label { fill: rgba(232, 230, 227, 0.6); }
[data-theme="dark"] .pomo-cycle-text { fill: rgba(232, 230, 227, 0.4); }
[data-theme="dark"] .pomo-banner-empty {
  background: linear-gradient(110deg, #2d2a25 0%, #252220 35%, #1f1d1a 100%);
  border-color: rgba(255, 255, 255, 0.08);
  color: rgba(232, 230, 227, 0.7);
}
[data-theme="dark"] .pomo-banner-empty-text { color: rgba(232, 230, 227, 0.7); }
[data-theme="dark"] .pomo-banner-open { background: linear-gradient(135deg, #b91c1c, #c2410c); box-shadow: 0 4px 12px rgba(185, 28, 28, 0.4); }
[data-theme="dark"] .pomo-plan-card { background: linear-gradient(135deg, #252220, #2d2a25); border-color: rgba(255, 255, 255, 0.08); }
[data-theme="dark"] .pomo-plan-card.status-completed { background: linear-gradient(135deg, rgba(6, 95, 70, 0.3), rgba(8, 47, 73, 0.3)); }
[data-theme="dark"] .pomo-plan-actions button { background: rgba(255, 255, 255, 0.05); border-color: rgba(255, 255, 255, 0.08); color: #e8e6e3; }
[data-theme="dark"] .pomo-plan-actions button:hover { background: rgba(255, 255, 255, 0.1); }
[data-theme="dark"] .pomo-plan-actions .pomo-plan-start { background: #7c2d12; border-color: #b45309; }
[data-theme="dark"] .pomo-plans-count { color: rgba(232, 230, 227, 0.6); }
[data-theme="dark"] .pomo-setting-row { background: rgba(255, 255, 255, 0.05); }
[data-theme="dark"] .pomo-stepper button { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.12); color: #e8e6e3; }
[data-theme="dark"] .pomodoro-tabs { border-bottom-color: rgba(255, 255, 255, 0.06); }
[data-theme="dark"] .pomo-tab { color: rgba(232, 230, 227, 0.6); }
[data-theme="dark"] .pomo-tab.active { background: rgba(255, 255, 255, 0.08); color: #fef3c7; }
[data-theme="dark"] .pomo-plan-link { background: rgba(255, 255, 255, 0.05); color: rgba(232, 230, 227, 0.85); }
[data-theme="dark"] .pomo-cycle { background: rgba(255, 255, 255, 0.06); color: rgba(232, 230, 227, 0.5); }
[data-theme="dark"] .pomo-controls button { background: rgba(255, 255, 255, 0.05); border-color: rgba(255, 255, 255, 0.08); color: #e8e6e3; }
[data-theme="dark"] .pomo-controls .btn-primary { background: #b91c1c; border-color: #b91c1c; }
[data-theme="dark"] .plan-form-row select, [data-theme="dark"] .plan-form-row input { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.08); color: #e8e6e3; }

/* =============================================
   P0-C 大厂级主题快选 flyout
   ============================================= */
.theme-flyout-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 9998;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 16px;
  padding-top: 56px;
  padding-right: 24px;
  opacity: 0;
  transition: opacity 0.2s;
  backdrop-filter: blur(2px);
}
.theme-flyout-overlay.open { opacity: 1; }
.theme-flyout {
  width: 380px;
  max-width: calc(100vw - 32px);
  max-height: calc(100 * var(--vh) - 80px);
  background: var(--bg-primary, #fff);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18), 0 4px 12px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.04);
  transform: translateX(20px);
  opacity: 0;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s;
}
.theme-flyout-overlay.open .theme-flyout {
  transform: translateX(0);
  opacity: 1;
}
.flyout-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.06), transparent);
}
.flyout-title { font-size: 16px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.flyout-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.flyout-section { display: flex; flex-direction: column; gap: 8px; }
.flyout-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary, #6b7280);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.flyout-label i { color: #6366f1; opacity: 0.8; }
.flyout-label small {
  margin-left: auto;
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary, #9ca3af);
  background: var(--bg-tertiary, #f3f4f6);
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: none;
  letter-spacing: normal;
}
.flyout-font-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.flyout-font-card {
  padding: 14px 12px;
  border: 2px solid var(--border-color, #e5e7eb);
  border-radius: 10px;
  background: var(--bg-secondary, #fafbfc);
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: all 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-family: inherit;
}
.flyout-font-card:hover {
  border-color: #6366f1;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.12);
}
.flyout-font-card.active {
  border-color: #6366f1;
  background: rgba(99, 102, 241, 0.06);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.flyout-font-preview {
  font-size: 16px;
  color: var(--text-primary, #111827);
  line-height: 1.3;
}
.flyout-font-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary, #6b7280);
}
.flyout-font-card.active .flyout-font-name { color: #6366f1; }

.flyout-line-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.flyout-line-chip {
  padding: 10px 8px;
  border: 2px solid var(--border-color, #e5e7eb);
  background: var(--bg-secondary, #fafbfc);
  color: var(--text-secondary, #4b5563);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  transition: all 0.15s;
}
.flyout-line-chip:hover {
  border-color: #6366f1;
  background: rgba(99, 102, 241, 0.05);
}
.flyout-line-chip.active {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border-color: #6366f1;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.flyout-bg-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.flyout-bg-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 2px solid var(--border-color, #e5e7eb);
  background: var(--bg-secondary, #fafbfc);
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: all 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.flyout-bg-card:hover {
  border-color: #6366f1;
  transform: translateY(-1px);
}
.flyout-bg-card.active {
  border-color: #6366f1;
  background: rgba(99, 102, 241, 0.06);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.flyout-bg-swatch {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}
.flyout-bg-meta { display: flex; flex-direction: column; min-width: 0; }
.flyout-bg-name { font-size: 13px; font-weight: 600; color: var(--text-primary, #111827); }
.flyout-bg-desc { font-size: 11px; color: var(--text-secondary, #6b7280); }

.flyout-anim-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.flyout-anim-chip {
  padding: 12px 8px;
  border: 2px solid var(--border-color, #e5e7eb);
  background: var(--bg-secondary, #fafbfc);
  color: var(--text-secondary, #4b5563);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}
.flyout-anim-chip i { font-size: 16px; }
.flyout-anim-chip:hover {
  border-color: #6366f1;
  transform: translateY(-1px);
}
.flyout-anim-chip.active {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border-color: #6366f1;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.flyout-footer {
  display: flex;
  justify-content: space-between;
  padding: 12px 18px;
  border-top: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-tertiary, #f9fafb);
}
.flyout-footer button {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-primary, #fff);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  transition: all 0.15s;
}
.flyout-footer .btn-primary { background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; border-color: #6366f1; }

/* 移动端 */
@media (max-width: 640px) {
  .theme-flyout-overlay { padding: 0; padding-top: 50px; }
  .theme-flyout { width: calc(100vw - 24px); }
  .flyout-font-grid, .flyout-bg-grid { grid-template-columns: repeat(2, 1fr); }
}

/* dark mode */
[data-theme="dark"] .theme-flyout {
  background: var(--bg-primary, #1f1d1a);
  border-color: rgba(255, 255, 255, 0.06);
}
[data-theme="dark"] .flyout-header {
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.08), transparent);
  border-bottom-color: rgba(255, 255, 255, 0.06);
}
[data-theme="dark"] .flyout-font-card,
[data-theme="dark"] .flyout-line-chip,
[data-theme="dark"] .flyout-bg-card,
[data-theme="dark"] .flyout-anim-chip {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
  color: rgba(232, 230, 227, 0.85);
}
[data-theme="dark"] .flyout-font-card:hover,
[data-theme="dark"] .flyout-line-chip:hover,
[data-theme="dark"] .flyout-bg-card:hover,
[data-theme="dark"] .flyout-anim-chip:hover {
  background: rgba(167, 139, 250, 0.1);
  border-color: #a78bfa;
}
[data-theme="dark"] .flyout-font-card.active,
[data-theme="dark"] .flyout-line-chip.active,
[data-theme="dark"] .flyout-bg-card.active,
[data-theme="dark"] .flyout-anim-chip.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(139, 92, 246, 0.2));
  border-color: #a78bfa;
  color: #fef3c7;
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.15);
}
[data-theme="dark"] .flyout-footer {
  background: rgba(255, 255, 255, 0.04);
  border-top-color: rgba(255, 255, 255, 0.06);
}
[data-theme="dark"] .flyout-footer button {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
  color: #e8e6e3;
}
[data-theme="dark"] .flyout-label { color: rgba(232, 230, 227, 0.6); }
[data-theme="dark"] .flyout-label small { background: rgba(255, 255, 255, 0.06); color: rgba(232, 230, 227, 0.7); }

/* =============================================
   iPad / 移动端 v3 全套兼容性 + 适配
   ============================================= */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --touch-min: 44px;  /* iPad 友好热区 */
  --vh: 1vh;          /* 移动端 100dvh 配合使用 */
}
@supports (height: 100dvh) {
  :root { --vh: 1dvh; }
}

/* 全局：Safari 工具栏不会让 100vh 算错 */
.reader-content-wrap { min-height: calc(100 * var(--vh)); }
.shelf-main { min-height: calc(100 * var(--vh)); }

/* 全局：iPad 横屏安全区 */
@supports (padding: max(0px)) {
  body { padding-left: max(0px, var(--safe-left)); padding-right: max(0px, var(--safe-right)); }
}

/* 热区目标尺寸达标：所有 icon-btn 触控增强 */
.icon-btn { min-width: var(--touch-min); min-height: var(--touch-min); }
.tool-btn { min-width: var(--touch-min); min-height: var(--touch-min); }
.option-btn { min-height: var(--touch-min); }
button[class*="btn"] { -webkit-tap-highlight-color: transparent; }

/* 标题/导航类 */
.reader-header { padding-top: max(8px, var(--safe-top)); padding-right: max(8px, var(--safe-right)); padding-left: max(8px, var(--safe-left)); }
.reader-footer { padding-bottom: max(8px, var(--safe-bottom)); padding-left: max(8px, var(--safe-left)); padding-right: max(8px, var(--safe-right)); }

/* iPad OS / iOS Safari：消除默认触摸高亮 + 双击缩放 */
* { -webkit-tap-highlight-color: transparent; }
html { touch-action: manipulation; }

/* 翻页 slide 防 Safari 左右滑手势冲突 */
.reader-content-wrap { overscroll-behavior-x: contain; }

/* =============================================
   iPad 专属断点
   ============================================= */

/* iPad mini / iPhone 大屏 (640-1024) */
@media (min-width: 641px) and (max-width: 1024px) {
  /* flyout 固定宽度 */
  .theme-flyout { width: 420px; }
  /* flyout 圆角字号变大 */
  .flyout-font-preview { font-size: 18px; }
  .flyout-line-chip { padding: 12px 8px; font-size: 15px; }
  .flyout-anim-chip { padding: 14px 10px; font-size: 14px; }
  .flyout-bg-card { padding: 10px 12px; }
  .flyout-bg-swatch { width: 36px; height: 36px; font-size: 16px; }
  /* 番茄钟面板上抬下边距减小 */
  .pomodoro-panel { max-height: calc(100 * var(--vh) - 32px); }
  /* 计划 grid 改 2 列 */
  .pomo-plans-pane { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .pomo-plans-header { grid-column: span 2; }
}

/* iPad 横屏 1024-1366 */
@media (min-width: 1025px) and (max-width: 1366px) {
  .theme-flyout { width: 460px; }
  .flyout-font-preview { font-size: 20px; }
  /* 番茄钟圆环放大 */
  .pomo-circle-wrap { width: 320px; height: 320px; }
  .pomo-time { font-size: 64px; }
  /* 计划 grid 2 列 */
  .pomo-plans-pane { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .pomo-plans-header { grid-column: span 2; }
}

/* iPad Pro 12.9 大屏 (1024-1366) */
@media (min-width: 1025px) {
  .pomodoro-panel { max-width: 560px; }
  .plan-create-modal { max-width: 520px; }
}

/* =============================================
   统一 iPad touch 兼容：去掉 hover-only 行为，改 :hover or :active
   ============================================= */

/* iPad 没有 mouseenter — flyout 字体选中态给 :active 一份 */
@media (hover: none) {
  /* 移除 pointer hover，改 focus-within / :active 永久可见 */
  .flyout-font-card:active,
  .flyout-line-chip:active,
  .flyout-bg-card:active,
  .flyout-anim-chip:active { transform: scale(0.96); }
  /* 笔记 drawer / TOC drawer 在 iPad 上首次点击不打开，再点才打开：直接绑 onclick 即可 */
}

/* =============================================
   现有断点扩展：增强 iPad 上的尺寸
   ============================================= */

/* iPad 横屏小（mini 8.3"）：768 单独 */
@media (width: 768px), (width: 820px), (width: 834px), (width: 1024px) {
  /* 番茄钟圆环适中 */
  .pomo-circle-wrap { width: 280px; height: 280px; }
}

/* iPhone Pro Max 等小屏 + 横屏 */
@media (max-height: 500px) and (orientation: landscape) {
  .pomodoro-panel { max-height: 90vh; }
  .pomo-circle-wrap { width: 160px; height: 160px; }
  .pomo-time { font-size: 32px; }
  .pomo-cycle-row { display: none; }
}

/* 番茄 panel 在 iPad mini / iPhone 上保持单列 */
@media (max-width: 1024px) {
  .pomo-plans-pane { display: flex; flex-direction: column; }
}

/* iPad 触控增强：color swatch 增加可点区 */
@media (hover: none) {
  /* iPad / iOS */
  .sel-color-swatch {
    /* 视觉 20px 保持，点区 ≥ 32px */
    position: relative;
  }
  .sel-color-swatch::before {
    content: '';
    position: absolute;
    top: -6px; left: -6px; right: -6px; bottom: -6px;
    border-radius: 50%;
    z-index: -1;
  }
  .sel-btn { min-width: 44px; min-height: 44px; }
  /* drawer header 的 icon-btn：保证手指精度 */
  .notes-drawer-header .icon-btn,
  .toc-drawer-header .icon-btn { width: 44px; height: 44px; }
}

/* =============================================
   iPad / 移动端浮动圆菜单 (FAB)
   ============================================= */
.ipad-fab {
  position: fixed;
  right: 16px;
  bottom: calc(96px + var(--safe-bottom, 0px));
  z-index: 998;
  display: none;  /* 默认隐藏，iPad / 手机通过 .show-ipad-fab body class 打开 */
}
.show-ipad-fab .ipad-fab { display: block; }

.ipad-fab-main {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-size: 22px;
  border: none;
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4), 0 2px 6px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.18s;
  -webkit-tap-highlight-color: transparent;
}
.ipad-fab-main:active { transform: scale(0.92); }
.ipad-fab-main.open { transform: rotate(45deg); background: linear-gradient(135deg, #ef4444, #f97316); }

.ipad-fab-menu {
  position: absolute;
  right: 0;
  bottom: 72px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(10px) scale(0.9);
  transition: opacity 0.2s, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.ipad-fab-menu.open {
  pointer-events: auto;
  opacity: 1;
  transform: translateY(0) scale(1);
}
.ipad-fab-item {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-primary, #fff);
  color: var(--text-secondary, #4b5563);
  font-size: 16px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  -webkit-tap-highlight-color: transparent;
  opacity: 0;
  transform: scale(0.5);
}
.ipad-fab-menu.open .ipad-fab-item {
  opacity: 1;
  transform: scale(1);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s;
}
.ipad-fab-menu.open .ipad-fab-item:nth-child(1) { transition-delay: 0.04s; }
.ipad-fab-menu.open .ipad-fab-item:nth-child(2) { transition-delay: 0.08s; }
.ipad-fab-menu.open .ipad-fab-item:nth-child(3) { transition-delay: 0.12s; }
.ipad-fab-menu.open .ipad-fab-item:nth-child(4) { transition-delay: 0.16s; }
.ipad-fab-menu.open .ipad-fab-item:nth-child(5) { transition-delay: 0.20s; }
.ipad-fab-item:active { transform: scale(0.9); }

/* dark mode */
[data-theme="dark"] .ipad-fab-item {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(232, 230, 227, 0.85);
  border-color: rgba(255, 255, 255, 0.08);
}

/* 桌面 ≥ 1280px 永远隐藏 */
@media (min-width: 1280px) {
  .ipad-fab { display: none !important; }
}

/* 修复：font-awesome solid 在 iOS Safari 需要 font-weight 900 */
.fa-solid, .fas { font-weight: 900; }
.fa-regular, .far { font-weight: 400; }
.fa-brands, .fab { font-weight: 400; }

/* =============================================
   A2 笔记双向链接 [[章名]] / [[书名]]
   ============================================= */
/* 双链在笔记文本中的样式 */
.bi-link {
  display: inline;
  padding: 1px 4px;
  margin: 0 1px;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.12);
  color: #2563eb;
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px solid rgba(59, 130, 246, 0.3);
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.bi-link:hover {
  background: rgba(59, 130, 246, 0.18);
  border-bottom-style: solid;
  border-bottom-width: 2px;
}
.bi-link.unresolved {
  background: rgba(239, 68, 68, 0.08);
  color: #ef4444;
  border-bottom-color: rgba(239, 68, 68, 0.3);
}
[data-theme="dark"] .bi-link {
  background: rgba(96, 165, 250, 0.16);
  color: #93c5fd;
  border-bottom-color: rgba(96, 165, 250, 0.4);
}
[data-theme="dark"] .bi-link.unresolved {
  background: rgba(248, 113, 113, 0.12);
  color: #fca5a5;
  border-bottom-color: rgba(248, 113, 113, 0.4);
}

/* 笔记 modal 里 live preview 区域 */
.note-modal-preview {
  padding: 8px 12px;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-secondary, #6b7280);
  min-height: 24px;
  max-height: 96px;
  overflow-y: auto;
  border: 1px dashed var(--border-color, #e5e7eb);
  border-radius: 6px;
  background: var(--bg-secondary, #fafafa);
  opacity: 0.6;
  white-space: pre-wrap;
  word-break: break-word;
  transition: opacity 0.15s;
}
.note-modal-preview.has-content { opacity: 1; }
.note-modal-preview .bi-link { font-size: 13px; }

/* autocomplete 弹层 */
.note-modal-bilink-pop {
  position: absolute;
  z-index: 10001;
  background: var(--bg-primary, #fff);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  max-height: 240px;
  overflow-y: auto;
  min-width: 240px;
  padding: 4px;
  font-size: 13px;
}
.bilink-pop-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
}
.bilink-pop-item:hover,
.bilink-pop-item.selected { background: rgba(59, 130, 246, 0.08); }
.bilink-pop-kind { font-size: 14px; }
.bilink-pop-label { flex: 1; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bilink-pop-sub { font-size: 11px; color: var(--text-secondary, #9ca3af); flex-shrink: 0; }
[data-theme="dark"] .note-modal-preview { background: rgba(255, 255, 255, 0.04); }
[data-theme="dark"] .note-modal-bilink-pop { background: var(--bg-primary, #1f1d1a); border-color: rgba(255, 255, 255, 0.08); }
[data-theme="dark"] .bilink-pop-item:hover,
[data-theme="dark"] .bilink-pop-item.selected { background: rgba(96, 165, 250, 0.16); }

/* drawer tabs: 笔记 / 反链 */
.notes-drawer-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 0;
}
.notes-drawer-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.notes-drawer-tab {
  border: none;
  background: transparent;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.notes-drawer-tab:hover { color: var(--text-primary, #111827); }
.notes-drawer-tab.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
  font-weight: 600;
}
.ndt-count {
  display: inline-block;
  font-size: 10px;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 8px;
  min-width: 18px;
  text-align: center;
}
.notes-drawer-tab.active .ndt-count {
  background: rgba(37, 99, 235, 0.12);
  color: #2563eb;
}
[data-theme="dark"] .notes-drawer-tab.active { color: #93c5fd; border-bottom-color: #93c5fd; }
[data-theme="dark"] .notes-drawer-tab.active .ndt-count { background: rgba(96, 165, 250, 0.16); color: #93c5fd; }

/* 反向链接小标 */
.backlink-item { border-left: 3px solid #2563eb; }
.backlink-item .bilink-goto { background: rgba(59, 130, 246, 0.12); color: #2563eb; border: none; }

/* 移动端：小屏 drawer tabs 压缩 */
@media (max-width: 640px) {
  .notes-drawer-tabs { gap: 2px; }
  .notes-drawer-tab { padding: 6px 8px; font-size: 11px; }
}

/* =============================================
   P1-A1 PWA 离线阅读 UI
   ============================================= */
/* 顶栏 badge */
.pwa-badge { position: relative; }
.pwa-badge.offline { color: #f59e0b; }
.pwa-badge.online  { color: #10b981; }
.pwa-badge .pwa-badge-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  border: 1.5px solid var(--bg-primary, #fff);
}
.pwa-badge.offline .pwa-badge-dot { background: #f59e0b; }

/* 封面异步缓存徽章 */
.book-cache-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(16, 185, 129, 0.92);
  color: #fff;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  z-index: 2;
  backdrop-filter: blur(4px);
}

/* 书架书卡片缓存按钮 */
.book-cache-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #6366f1;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  z-index: 2;
  backdrop-filter: blur(4px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  transition: transform 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.book-cache-btn:hover { background: #6366f1; color: #fff; transform: scale(1.1); }
.book-card { position: relative; }

/* 缓存状态弹窗 */
.cache-status-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  transition: opacity 0.2s;
}
.cache-status-overlay.open { opacity: 1; }
.cache-status-modal {
  background: var(--bg-primary, #fff);
  border-radius: 14px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  animation: modal-scale-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}
.cache-status-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.cache-status-header h3 { margin: 0; font-size: 16px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.cache-status-header h3 i { color: #6366f1; }
.cache-status-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.cs-online-state {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
}
.cs-online-state.online { background: rgba(16, 185, 129, 0.1); color: #047857; }
.cs-online-state.offline { background: rgba(245, 158, 11, 0.1); color: #b45309; }
.cs-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cs-stat { padding: 10px 12px; background: var(--bg-tertiary, #f3f4f6); border-radius: 8px; display: flex; flex-direction: column; gap: 4px; }
.cs-stat span { font-size: 11px; color: var(--text-secondary, #6b7280); text-transform: uppercase; letter-spacing: 0.3px; }
.cs-stat strong { font-size: 16px; font-weight: 700; color: var(--text-primary, #111827); font-variant-numeric: tabular-nums; }
.cs-tip { font-size: 12px; color: var(--text-secondary, #6b7280); padding: 8px 12px; background: var(--bg-tertiary, #f3f4f6); border-radius: 8px; display: flex; align-items: flex-start; gap: 6px; line-height: 1.5; }
.cs-tip i { color: #6366f1; margin-top: 2px; }
.cache-status-footer {
  display: flex;
  justify-content: space-between;
  padding: 12px 18px;
  border-top: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-tertiary, #f9fafb);
}
.cache-status-footer button {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-primary, #fff);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.cache-status-footer .btn-primary { background: #6366f1; color: #fff; border-color: #6366f1; }
.cache-status-footer .btn-danger { color: #ef4444; }

[data-theme="dark"] .cs-stat { background: rgba(255, 255, 255, 0.05); }
[data-theme="dark"] .cs-tip { background: rgba(255, 255, 255, 0.05); }
[data-theme="dark"] .cache-status-footer { background: rgba(255, 255, 255, 0.04); border-top-color: rgba(255, 255, 255, 0.06); }
[data-theme="dark"] .cache-status-footer button { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.08); color: #e8e6e3; }
@media (max-width: 640px) {
  .cache-status-modal { max-width: calc(100vw - 24px); }
}

/* =============================================
   P1-B1 365 天阅读热力图
   ============================================= */
.hm-yearly-wrap {
  background: linear-gradient(135deg, #fafbfc 0%, #f3f4f6 100%);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.hm-year-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
}
.hm-year-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary, #111827);
  letter-spacing: -0.2px;
}
.hm-year-nav { display: flex; align-items: center; gap: 4px; }
.hm-year-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-primary, #fff);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-secondary, #6b7280);
  transition: all 0.15s;
}
.hm-year-btn:hover:not([disabled]) {
  border-color: #6366f1;
  color: #6366f1;
}
.hm-year-btn[disabled] { opacity: 0.3; cursor: not-allowed; }
.hm-year-select {
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  background: var(--bg-primary, #fff);
  color: var(--text-primary, #111827);
  cursor: pointer;
}
.hm-calendar {
  display: grid;
  grid-template-columns: 24px 1fr;
  grid-template-rows: auto auto auto;
  column-gap: 6px;
  row-gap: 4px;
  overflow-x: auto;
  scrollbar-width: thin;
  padding-bottom: 4px;
  min-height: 110px;  /* 防止 grid-row 塌缩 */
  align-items: start;
}
.hm-month-track { grid-column: 1 / span 2; grid-row: 3; min-height: 14px; position: relative; }
.hm-week-col { grid-column: 1; grid-row: 1; align-self: start; }
.hm-day-grid { grid-column: 2; grid-row: 1; }
.hm-week-col {
  display: grid;
  grid-template-rows: repeat(7, 1fr);
  gap: 3px;
  font-size: 9px;
  color: var(--text-secondary, #9ca3af);
  padding-top: 2px;
  text-align: center;
  font-weight: 500;
}
.hm-week-col .hm-week-label { line-height: 11px; }
.hm-day-grid {
  display: grid;
  grid-template-rows: repeat(7, 11px);
  grid-auto-columns: 11px;
  grid-auto-flow: column;
  gap: 3px;
  min-width: 0;
  min-height: 95px;  /* 7 行 × 11px + 6 × 3px gap = 95px —— 防止容器坍缩 */
}
.hm-cell {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  background: #ebedf0;
  transition: transform 0.12s;
  cursor: pointer;
  position: relative;
}
.hm-cell:hover { transform: scale(1.4); z-index: 5; box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.4); }
.hm-cell.hm-future { opacity: 0.25; cursor: default; }
.hm-cell.hm-future:hover { transform: none; box-shadow: none; }
.hm-l0 { background: #ebedf0; }
.hm-l1 { background: #b7e4c7; }
.hm-l2 { background: #6fcf97; }
.hm-l3 { background: #2eb872; }
.hm-l4 {
  background: linear-gradient(135deg, #1a9850, #057d4f);
  box-shadow: 0 0 4px rgba(7, 125, 79, 0.4);
}
.hm-peak {
  outline: 1.5px solid #fbbf24;
  outline-offset: -1px;
  animation: hm-peak-pulse 2s ease-in-out infinite;
}
.hm-peak-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  font-size: 7px;
  color: #fbbf24;
  pointer-events: none;
  line-height: 1;
  font-weight: 700;
}
@keyframes hm-peak-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.55); }
  50%      { box-shadow: 0 0 0 4px rgba(251, 191, 36, 0); }
}
.hm-today { outline: 2px solid #6366f1; outline-offset: -2px; }
.hm-today-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #6366f1;
  color: #fff;
  font-size: 8px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  pointer-events: none;
  line-height: 1;
}
.hm-month-row {
  display: grid;
  grid-auto-flow: column;
  gap: 3px;
  font-size: 10px;
  color: var(--text-secondary, #6b7280);
}
.hm-month-label { position: absolute; line-height: 1; padding-left: 1px; top: 0; }
.hm-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-secondary, #6b7280);
  justify-content: flex-end;
  padding-top: 6px;
}
.hm-legend .hm-cell { cursor: default; }
.hm-legend .hm-cell:hover { transform: none; box-shadow: none; }
.hm-legend-peak { color: #fbbf24; font-weight: 700; }
.hm-year-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px 10px 0;
  border-top: 1px dashed var(--border-color, #e5e7eb);
  font-size: 12px;
  color: var(--text-secondary, #6b7280);
}
.hm-year-stats strong {
  color: var(--text-primary, #111827);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-right: 2px;
}

/* 移动端 */
@media (max-width: 640px) {
  .hm-cell { width: 9px; height: 9px; }
  .hm-year-stats { font-size: 11px; gap: 8px; }
  .hm-week-col { font-size: 8px; }
  .hm-calendar { gap: 4px; }
  .hm-day-grid, .hm-month-row { gap: 2px; }
}

/* dark mode */
[data-theme="dark"] .hm-yearly-wrap { background: linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)); border-color: rgba(255, 255, 255, 0.08); }
[data-theme="dark"] .hm-year-title { color: #e8e6e3; }
[data-theme="dark"] .hm-year-btn { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.1); color: rgba(232, 230, 227, 0.7); }
[data-theme="dark"] .hm-year-select { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.1); color: #e8e6e3; }
[data-theme="dark"] .hm-month-row, [data-theme="dark"] .hm-week-col { color: rgba(232, 230, 227, 0.5); }
[data-theme="dark"] .hm-year-stats { color: rgba(232, 230, 227, 0.7); border-top-color: rgba(255, 255, 255, 0.08); }
[data-theme="dark"] .hm-year-stats strong { color: #e8e6e3; }
[data-theme="dark"] .hm-l0 { background: rgba(255, 255, 255, 0.05); }
[data-theme="dark"] .hm-l1 { background: rgba(101, 184, 137, 0.4); }
[data-theme="dark"] .hm-l2 { background: rgba(64, 167, 96, 0.7); }
[data-theme="dark"] .hm-l3 { background: rgba(46, 184, 114, 0.85); }
[data-theme="dark"] .hm-l4 { background: linear-gradient(135deg, #1a9850, #057d4f); }

/* =============================================
   P1-B1 三级阅读热力图 (年/月/周)
   ============================================= */
.hm-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 顶栏 segmented control 切换 3 视图 */
.hm-view-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary, #f3f4f6);
  border-radius: 12px;
  padding: 4px;
  position: relative;
}
.hm-view-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 13px;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-weight: 500;
}
.hm-view-tab:hover { color: var(--text-primary, #111827); }
.hm-view-tab.active {
  background: var(--bg-primary, #fff);
  color: #6366f1;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}
.hm-view-label {
  font-size: 11px;
  color: var(--text-secondary, #9ca3af);
  padding: 0 8px;
  font-variant-numeric: tabular-nums;
}

/* 年视图 (升级) */
.hm-year-wrap, .hm-month-wrap, .hm-week-wrap {
  background: linear-gradient(135deg, #fafbfc 0%, #f3f4f6 100%);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.hm-year-controls, .hm-month-controls, .hm-week-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}
.hm-year-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-primary, #fff);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-secondary, #6b7280);
  transition: all 0.15s;
}
.hm-year-btn:hover:not([disabled]) {
  border-color: #6366f1;
  color: #6366f1;
}
.hm-year-btn[disabled] { opacity: 0.3; cursor: not-allowed; }
.hm-year-display, .hm-month-display, .hm-week-display {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary, #111827);
  letter-spacing: -0.3px;
  min-width: 110px;
  text-align: center;
}
.hm-today-jump {
  border: 1px dashed #6366f1;
  background: transparent;
  color: #6366f1;
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
  margin-left: auto;
}
.hm-today-jump:hover {
  background: #6366f1;
  color: #fff;
}
.hm-week-range {
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary, #9ca3af);
  margin-bottom: -4px;
  font-variant-numeric: tabular-nums;
}

/* 月视图日历 */
.hm-month-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
}
.hm-month-wk {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary, #9ca3af);
}
.hm-month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.hm-month-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1.5px solid transparent;
}
.hm-month-cell:hover {
  transform: translateY(-2px) scale(1.04);
  z-index: 2;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}
.hm-month-empty { aspect-ratio: 1; }
.hm-month-cell.hm-month-today {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.hm-month-d {
  font-size: 14px;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.85);
  line-height: 1;
}
.hm-month-m {
  font-size: 10px;
  color: rgba(0, 0, 0, 0.65);
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* 月视图 / 周视图继承 5 级色 (复用 hm-l0..4) */
.hm-month-cell.hm-l0, .hm-week-cell.hm-l0 { background: rgba(0, 0, 0, 0.04); }
.hm-month-cell.hm-l1, .hm-week-cell.hm-l1 { background: #b7e4c7; }
.hm-month-cell.hm-l2, .hm-week-cell.hm-l2 { background: #6fcf97; }
.hm-month-cell.hm-l3, .hm-week-cell.hm-l3 { background: #2eb872; }
.hm-month-cell.hm-l4, .hm-week-cell.hm-l4 {
  background: linear-gradient(135deg, #1a9850, #057d4f);
  box-shadow: 0 0 8px rgba(7, 125, 79, 0.3);
}

/* 周视图 */
.hm-week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.hm-week-cell {
  position: relative;
  border-radius: 10px;
  padding: 10px 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1.5px solid transparent;
  min-height: 88px;
}
.hm-week-cell:hover {
  transform: translateY(-2px) scale(1.04);
  z-index: 2;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}
.hm-week-cell.hm-week-today {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.hm-week-cell.hm-future { opacity: 0.45; }
.hm-week-wk {
  font-size: 10px;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.55);
  text-transform: uppercase;
}
.hm-week-date {
  font-size: 11px;
  color: rgba(0, 0, 0, 0.7);
  font-variant-numeric: tabular-nums;
}
.hm-week-time {
  font-size: 13px;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.9);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.hm-week-cell.hm-l0 .hm-week-wk,
.hm-week-cell.hm-l0 .hm-week-date,
.hm-week-cell.hm-l0 .hm-week-time {
  color: var(--text-secondary, #9ca3af);
}
.hm-week-cell.hm-l3 .hm-week-wk,
.hm-week-cell.hm-l3 .hm-week-date,
.hm-week-cell.hm-l3 .hm-week-time,
.hm-week-cell.hm-l4 .hm-week-wk,
.hm-week-cell.hm-l4 .hm-week-date,
.hm-week-cell.hm-l4 .hm-week-time {
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

/* 移动端 */
@media (max-width: 640px) {
  .hm-view-tab { padding: 7px 4px; font-size: 12px; }
  .hm-view-tab span { font-size: 11px; }
  .hm-month-cell { padding: 4px; border-radius: 6px; }
  .hm-month-d { font-size: 12px; }
  .hm-month-m { font-size: 9px; }
  .hm-week-cell { padding: 6px 4px; min-height: 70px; }
  .hm-week-wk { font-size: 9px; }
  .hm-week-time { font-size: 11px; }
}

/* dark mode */
[data-theme="dark"] .hm-year-wrap,
[data-theme="dark"] .hm-month-wrap,
[data-theme="dark"] .hm-week-wrap {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02));
  border-color: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .hm-view-switcher { background: rgba(255, 255, 255, 0.06); }
[data-theme="dark"] .hm-view-tab.active { background: rgba(99, 102, 241, 0.25); color: #c7d2fe; }
[data-theme="dark"] .hm-view-label { color: rgba(232, 230, 227, 0.5); }
[data-theme="dark"] .hm-year-btn { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.1); color: rgba(232, 230, 227, 0.7); }
[data-theme="dark"] .hm-year-display,
[data-theme="dark"] .hm-month-display,
[data-theme="dark"] .hm-week-display { color: #e8e6e3; }
[data-theme="dark"] .hm-today-jump { border-color: #a78bfa; color: #a78bfa; }
[data-theme="dark"] .hm-today-jump:hover { background: #a78bfa; color: #1f1d1a; }
[data-theme="dark"] .hm-month-wk,
[data-theme="dark"] .hm-week-wk { color: rgba(232, 230, 227, 0.55); }
[data-theme="dark"] .hm-week-range { color: rgba(232, 230, 227, 0.5); }
[data-theme="dark"] .hm-month-cell.hm-l0,
[data-theme="dark"] .hm-week-cell.hm-l0 { background: rgba(255, 255, 255, 0.05); }
[data-theme="dark"] .hm-month-cell.hm-l0 .hm-month-d,
[data-theme="dark"] .hm-month-cell.hm-l0 .hm-month-m { color: rgba(232, 230, 227, 0.45); }
[data-theme="dark"] .hm-month-cell.hm-l1, [data-theme="dark"] .hm-week-cell.hm-l1 { background: rgba(101, 184, 137, 0.35); }
[data-theme="dark"] .hm-month-cell.hm-l2, [data-theme="dark"] .hm-week-cell.hm-l2 { background: rgba(64, 167, 96, 0.6); }
[data-theme="dark"] .hm-month-cell.hm-l3, [data-theme="dark"] .hm-week-cell.hm-l3 { background: rgba(46, 184, 114, 0.8); }
[data-theme="dark"] .hm-month-cell.hm-l4, [data-theme="dark"] .hm-week-cell.hm-l4 { background: linear-gradient(135deg, #1a9850, #057d4f); }
[data-theme="dark"] .hm-week-cell.hm-l0 .hm-week-date,
[data-theme="dark"] .hm-week-cell.hm-l0 .hm-week-time { color: rgba(232, 230, 227, 0.45); }
[data-theme="dark"] .hm-month-cell .hm-month-d,
[data-theme="dark"] .hm-month-cell .hm-month-m { color: rgba(255, 255, 255, 0.9); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); }

/* =============================================
   P3 移动端 header 减法 + ⋯ 菜单 + 自定义工具栏
   ============================================= */

/* 默认桌面上不显示 ⋯ 按钮 */
.shelf-more { display: none !important; }

/* 移动端 ≤1024px：只保留 logo + 搜索 + ⋯ */
@media (max-width: 1024px) {
  .shelf-header { padding: 0 12px !important; }
  .shelf-header-inner { gap: 8px; }
  .logo {
    font-size: 13px !important;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .logo i { display: none; }  /* 隐藏 logo icon，只留文字 */
  .header-actions { gap: 4px; }
  /* 移动端隐藏所有 .shelf-tool 默认由 JS 控制 */
  .shelf-tool { display: none !important; }
  /* ⋯ 按钮显示 */
  .shelf-more { display: flex !important; }
}

/* ⋯ 弹出菜单 */
.shelf-more-menu {
  position: fixed;
  z-index: 9998;
  min-width: 220px;
  background: var(--bg-primary, #fff);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border-color, #e5e7eb);
  padding: 6px;
  opacity: 0;
  transform: translateY(-8px) scale(0.95);
  transition: opacity 0.18s, transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  -webkit-tap-highlight-color: transparent;
}
.shelf-more-menu.open {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.shelf-more-arrow {
  position: absolute;
  top: -6px;
  right: 18px;
  width: 12px;
  height: 12px;
  background: var(--bg-primary, #fff);
  border-left: 1px solid var(--border-color, #e5e7eb);
  border-top: 1px solid var(--border-color, #e5e7eb);
  transform: rotate(45deg);
}
.shelf-more-list { display: flex; flex-direction: column; gap: 2px; }
.shelf-more-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-primary, #111827);
  cursor: pointer;
  font-family: inherit;
  width: 100%;
  text-align: left;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.shelf-more-item:hover,
.shelf-more-item:active { background: var(--bg-tertiary, #f3f4f6); }
.shelf-more-item i {
  width: 18px;
  text-align: center;
  color: var(--text-secondary, #6b7280);
}
.shelf-more-item.is-hidden { opacity: 0.55; }
.shelf-more-item.is-hidden i { color: #9ca3af; }
.shelf-more-tag {
  margin-left: auto;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 8px;
  background: var(--bg-tertiary, #f3f4f6);
  color: var(--text-secondary, #9ca3af);
}

/* 自定义工具栏 modal */
.toolbar-customize-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  transition: opacity 0.2s;
}
.toolbar-customize-overlay.open { opacity: 1; }
.toolbar-customize-modal {
  background: var(--bg-primary, #fff);
  border-radius: 16px;
  width: 100%;
  max-width: 460px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  animation: modal-scale-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.tcm-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.tcm-header h3 { margin: 0; font-size: 16px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.tcm-header h3 i { color: #6366f1; }
.tcm-body { padding: 16px 20px; overflow-y: auto; }
.tcm-hint {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--text-secondary, #6b7280);
  line-height: 1.6;
}
.tcm-hint b { color: var(--text-primary, #111827); }
.tcm-list { display: flex; flex-direction: column; gap: 6px; }
.tcm-item {
  display: grid;
  grid-template-columns: 32px 1fr 44px 44px;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-secondary, #fafbfc);
  border-radius: 10px;
  border: 1px solid var(--border-color, #e5e7eb);
}
.tcm-item-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(99, 102, 241, 0.05));
  color: #6366f1;
  border-radius: 8px;
}
.tcm-item-name { font-size: 13px; font-weight: 500; }
.tcm-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
}
.tcm-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.tcm-toggle span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 28px;
  border-radius: 8px;
  font-size: 14px;
  border: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-primary, #fff);
  color: var(--text-secondary, #9ca3af);
  transition: all 0.15s;
}
.tcm-toggle input:checked + span {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.3);
}
.tcm-footer {
  display: flex;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-tertiary, #f9fafb);
}
.tcm-footer button {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-primary, #fff);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tcm-footer .btn-primary {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border-color: #6366f1;
}

/* 移动端 modal */
@media (max-width: 640px) {
  .toolbar-customize-overlay { padding: 16px; }
  .toolbar-customize-modal { max-width: 100%; }
  .tcm-item { grid-template-columns: 28px 1fr 40px 40px; padding: 8px 10px; gap: 8px; }
  .tcm-item-name { font-size: 12px; }
}

/* dark mode */
[data-theme="dark"] .shelf-more-menu,
[data-theme="dark"] .toolbar-customize-modal { background: var(--bg-primary, #1f1d1a); border-color: rgba(255, 255, 255, 0.08); }
[data-theme="dark"] .shelf-more-arrow { background: var(--bg-primary, #1f1d1a); border-color: rgba(255, 255, 255, 0.08); }
[data-theme="dark"] .shelf-more-item:hover,
[data-theme="dark"] .shelf-more-item:active { background: rgba(255, 255, 255, 0.06); }
[data-theme="dark"] .shelf-more-item { color: #e8e6e3; }
[data-theme="dark"] .shelf-more-tag { background: rgba(255, 255, 255, 0.06); color: rgba(232, 230, 227, 0.7); }
[data-theme="dark"] .tcm-item { background: rgba(255, 255, 255, 0.04); border-color: rgba(255, 255, 255, 0.08); }
[data-theme="dark"] .tcm-item-name { color: #e8e6e3; }
[data-theme="dark"] .tcm-hint { color: rgba(232, 230, 227, 0.65); }
[data-theme="dark"] .tcm-toggle span { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.1); }
[data-theme="dark"] .tcm-footer { background: rgba(255, 255, 255, 0.04); border-top-color: rgba(255, 255, 255, 0.06); }
[data-theme="dark"] .tcm-footer button { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.1); color: #e8e6e3; }
