:root {
  --bg: #f5f5f5;
  --card-bg: rgba(255,255,255,0.75);
  --text: #333;
  --text-secondary: #666;
  --primary: #5b7db1;
  --border: #ddd;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --reader-bg: #faf9f6;
  --reader-text: #333;
  --font-size: 18px;
  --line-height: 1.8;
  --margin: 20px;
  --max-width: 800px;
  --topbar-bg: rgba(250,249,246,0.85);
  --chapter-header-height: 36px;
  --shelf-bg: #f5f5f5;
  --shelf-card-bg: rgba(255,255,255,0.4);
  --shelf-text: #333;
  --shelf-text-secondary: #666;
  --shelf-primary: #5b7db1;
  --shelf-border: #ddd;
  --shelf-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
  --reader-bg: #0f0f1a;
  --reader-text: #d0d0d0;
  --topbar-bg: rgba(15,15,26,0.85);
  --shelf-card-bg: rgba(22,33,62,0.4);
}

[data-theme="sepia"] {
  --reader-bg: #f4ecd8;
  --reader-text: #5b4636;
  --topbar-bg: rgba(244,236,216,0.85);
}

[data-theme="green"] {
  --reader-bg: #c8d9c0;
  --reader-text: #2d3e2b;
  --topbar-bg: rgba(200,217,192,0.85);
}

[data-theme="parchment"] {
  --reader-bg: #f5e6c6;
  --reader-text: #4a3b2c;
  --topbar-bg: rgba(245,230,198,0.85);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  transition: background 0.3s, color 0.3s;
  height: 100vh; overflow: hidden;
  position: relative;
}

/* ===== 书架 ===== */
#shelf-view {
  height: 100vh; display: flex; flex-direction: column;
  padding: 16px; padding-bottom: 80px; overflow-y: auto;
  background: var(--shelf-bg);
  color: var(--shelf-text);
  transition: background 0.3s, color 0.3s;
}
.shelf-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px;
}
.shelf-header h1 { font-size: 24px; }
.view-toggle {
  background: none; border: 1px solid var(--shelf-border); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; color: var(--shelf-text);
}
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 12px;
}
.books-list {
  display: flex; flex-direction: column; gap: 8px;
}
.book-card {
  background: var(--shelf-card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 12px; padding: 8px;
  box-shadow: var(--shelf-shadow); cursor: pointer; transition: transform 0.2s;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  position: relative;
  color: var(--shelf-text);
  border: 1px solid rgba(255,255,255,0.3);
}
.books-list .book-card {
  flex-direction: row; align-items: center; gap: 12px;
  padding: 10px 16px;
}
.books-list .book-cover { width: 48px; height: 64px; margin-bottom: 0; font-size: 24px; }
.books-list .book-title { flex: 1; text-align: left; }
.books-list .book-progress { text-align: right; }
.book-cover {
  width: 100%; height: 120px;
  border-radius: 8px;
  object-fit: cover;
  background: rgba(255,255,255,0.5);
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
  color: #aaa;
  margin-bottom: 4px;
}
.book-title {
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  max-width: 100%;
  display: block;
}
.book-progress { font-size: 11px; color: var(--shelf-text-secondary); margin-top: 2px; }

/* ===== FAB ===== */
.fab-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 20;
  display: flex; flex-direction: column; align-items: flex-end; gap: 12px;
}
.fab {
  width: 56px; height: 56px; background: var(--primary); color: #fff;
  border-radius: 50%; font-size: 28px; border: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3); cursor: pointer;
  transition: transform 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.fab-mini { width: 48px; height: 48px; font-size: 22px; margin-bottom: 8px; }
.fab-menu {
  display: flex; flex-direction: column; align-items: flex-end;
  transform: scale(0); transition: transform 0.2s; transform-origin: bottom right;
}
.fab-menu.show { transform: scale(1); }

/* ===== 模态框 ===== */
.modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5); display: none; justify-content: center;
  align-items: center; z-index: 30;
}
.modal.show { display: flex; }
.modal-content {
  background: var(--card-bg); backdrop-filter: blur(20px);
  border-radius: 16px; padding: 24px;
  width: 90%; max-width: 500px; max-height: 80vh; overflow-y: auto;
}
.modal-content h2 { margin-bottom: 16px; }
.modal-content input, .modal-content textarea {
  width: 100%; padding: 12px; margin: 8px 0;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 16px;
}
.btn-row { display: flex; gap: 12px; margin-top: 16px; justify-content: flex-end; }
.btn {
  padding: 10px 20px; border: none; border-radius: 8px;
  font-size: 16px; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary {
  background: rgba(255,255,255,0.6);
  color: var(--text);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}
.btn-secondary:hover {
  background: rgba(255,255,255,0.8);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.btn-secondary:active {
  transform: scale(0.97);
}

/* ===== 阅读器 ===== */
#reader-view {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: var(--reader-bg); color: var(--reader-text);
  display: none; flex-direction: column; z-index: 25;
}
#reader-view.active { display: flex; }
.reader-topbar {
  display: flex; align-items: center; padding: 8px 16px;
  background: var(--topbar-bg); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); z-index: 5;
  transition: opacity 0.3s; position: relative;
  min-height: 48px;
}
.reader-topbar.hidden { opacity: 0; pointer-events: none; position: absolute; top: 0; left: 0; right: 0; }
.reader-bottom-bar {
  display: flex; justify-content: space-around; align-items: center;
  padding: 12px 16px; background: rgba(255,255,255,0.85);
  backdrop-filter: blur(10px); border-top: 1px solid var(--border);
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 5;
  transition: opacity 0.3s;
}
.reader-bottom-bar.hidden { opacity: 0; pointer-events: none; }
.bar-btn {
  background: none; border: none; color: var(--reader-text);
  cursor: pointer; display: flex; flex-direction: column;
  align-items: center; padding: 8px 12px; font-size: 12px;
  min-width: 56px;
}
.bar-btn svg { width: 24px; height: 24px; margin-bottom: 2px; stroke: currentColor; fill: none; }
.chapter-header {
  position: absolute; top: 0; left: 0; right: 0;
  height: var(--chapter-header-height); line-height: var(--chapter-header-height);
  background: var(--topbar-bg); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); padding: 0 16px;
  font-size: 14px; color: var(--reader-text); z-index: 4;
  transition: opacity 0.3s;
}
.chapter-header.hidden { opacity: 0; }
#reader-content {
  flex: 1; overflow: auto;
  padding: var(--margin); padding-top: calc(var(--chapter-header-height) + 16px); padding-bottom: 80px;
  font-size: var(--font-size); line-height: var(--line-height);
  max-width: var(--max-width); margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}
#reader-content p { text-indent: 2em; margin-bottom: 0.8em; }
#reader-content h1, #reader-content h2, #reader-content h3,
#reader-content h4, #reader-content h5, #reader-content h6 {
  font-weight: bold;
  margin: 0.8em 0 0.4em 0;
}
#reader-content h1 { font-size: 1.6em; }
#reader-content h2 { font-size: 1.4em; }
#reader-content h3 { font-size: 1.2em; }
#reader-content ul, #reader-content ol { margin: 0.5em 0 0.5em 2em; }
#reader-content li { margin: 0.2em 0; }
#reader-content blockquote {
  margin: 0.5em 0;
  padding: 0.5em 1em;
  border-left: 4px solid var(--primary);
  background: rgba(0,0,0,0.03);
}
#reader-content pre {
  background: rgba(0,0,0,0.05);
  padding: 0.5em;
  border-radius: 4px;
  overflow-x: auto;
  font-family: monospace;
  font-size: 0.9em;
}
#reader-content hr {
  margin: 1em 0;
  border: none;
  border-top: 2px solid var(--border);
}

/* ===== 加载遮罩 ===== */
#loading-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
#loading-overlay.show { display: flex; }
.spinner {
  width: 48px; height: 48px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: #fff; margin-top: 16px; font-size: 16px; }

/* ===== 目录（TOC） ===== */
.toc-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.3);
  z-index: 34; display: none;
}
.toc-overlay.show { display: block; }
.toc-panel {
  position: fixed; top: 0; right: -320px;
  width: 300px; height: 100%;
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  padding: 24px;
  z-index: 35;
  transition: right 0.3s;
  overflow-y: auto;
  box-shadow: -2px 0 12px rgba(0,0,0,0.15);
}
.toc-panel.show { right: 0; }
.toc-item {
  display: block; padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  color: var(--text);
  transition: background 0.2s;
}
.toc-item:hover { background: rgba(0,0,0,0.05); }
.toc-item:active { opacity: 0.7; }
.toc-panel h3 { margin-bottom: 16px; }

/* ===== 设置面板 ===== */
.settings-panel, .theme-panel, .shelf-skin-panel {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--card-bg); backdrop-filter: blur(20px);
  padding: 16px;
  border-radius: 16px 16px 0 0; z-index: 40; transition: transform 0.3s;
  transform: translateY(100%); max-height: 70vh; overflow-y: auto;
}
.settings-panel.show, .theme-panel.show, .shelf-skin-panel.show { transform: translateY(0); }
.setting-row { margin: 12px 0; display: flex; align-items: center; justify-content: space-between; }
.setting-row select, .setting-row input[type="range"] { width: 120px; }
.theme-grid, .skin-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 16px 0;
}
.theme-card, .skin-card {
  border: 2px solid transparent; border-radius: 12px; padding: 12px;
  cursor: pointer; text-align: center;
}
.theme-card.active, .skin-card.active { border-color: var(--primary); }
.theme-color, .skin-preview {
  width: 100%; height: 60px; border-radius: 8px; margin-bottom: 8px;
}
.filter-list { margin: 12px 0; }
.filter-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px; background: var(--bg); border-radius: 8px; margin-bottom: 6px;
}

/* ===== 预览区域样式 ===== */
.preview-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  font-family: monospace;
  font-size: 14px;
  line-height: 1.6;
  margin-top: 8px;
}
.encoding-info {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 4px 0;
}
.preview-box.html-preview {
  white-space: normal;
  font-family: inherit;
}

/* 文件选择器美化 */
.file-name {
  font-size: 14px;
  color: var(--text-secondary);
  padding-left: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

/* ===== 下载进度条 ===== */
.progress-bar {
  width: 100%;
  height: 4px;
  background: #eee;
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}
.progress-bar > div {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* 下载中书籍卡片（可选视觉效果） */
.book-card.downloading {
  opacity: 0.9;
  border: 1px solid var(--primary);
}