:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --primary: #4a90e2;
  --primary-dark: #357abd;
  --primary-soft: rgba(74, 144, 226, 0.1);
  --text: #1a1a1a;
  --text-secondary: #6b7280;
  --border: #e5e8ee;
  --shadow: 0 2px 10px rgba(16, 40, 80, 0.07);
  --radius: 10px;
  --reader-bg: #fdfdf7;
  --reader-fg: #222222;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

.muted { color: var(--text-secondary); font-size: 12px; }

/* ===== 登录页 ===== */
#auth-screen { justify-content: center; align-items: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.auth-container { width: 100%; padding: 20px; }
.auth-box { max-width: 380px; margin: 0 auto; background: var(--surface); border-radius: 18px; padding: 36px 30px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28); }
.logo { text-align: center; font-size: 44px; margin-bottom: 6px; }
.tagline { text-align: center; color: var(--text-secondary); margin-bottom: 28px; font-size: 14px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 13px; color: #374151; }
.form-group input, .form-group textarea {
  width: 100%; padding: 11px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 16px; font-family: inherit; background: #fbfcfe; transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus, .form-group textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ===== 按钮 ===== */
.btn { padding: 12px 22px; border: none; border-radius: var(--radius); font-size: 15px; font-family: inherit; cursor: pointer; transition: all 0.15s; width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-sm { padding: 7px 14px; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); cursor: pointer; font-size: 13px; font-family: inherit; }
.btn-sm:hover { border-color: var(--primary); color: var(--primary); }
.btn-icon { padding: 6px 10px; border: none; background: transparent; font-size: 19px; cursor: pointer; border-radius: var(--radius); line-height: 1; }
.btn-icon:hover { background: var(--primary-soft); }
.switch-auth { text-align: center; margin-top: 18px; color: var(--text-secondary); font-size: 14px; }
.switch-auth a { color: var(--primary); text-decoration: none; }

/* ===== 顶栏 ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 22px; background: rgba(255, 255, 255, 0.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.logo-small { font-size: 24px; }
.site-name { font-size: 18px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.search-box { padding: 8px 14px; border: 1px solid var(--border); border-radius: 20px; width: 200px; font-size: 14px; background: #fbfcfe; }
.search-box:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.user-info { color: var(--text-secondary); font-size: 13px; white-space: nowrap; }

/* ===== 内容区 ===== */
.content { flex: 1; padding: 22px; max-width: 1400px; margin: 0 auto; width: 100%; }

.category-tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.tab { padding: 7px 18px; border: 1px solid var(--border); background: var(--surface); border-radius: 20px; cursor: pointer; font-size: 13px; font-family: inherit; transition: all 0.15s; }
.tab:hover { border-color: var(--primary); color: var(--primary); }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== 书籍网格 ===== */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 20px; }
.book-card { background: var(--surface); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); transition: transform 0.15s, box-shadow 0.15s; }
.book-card:hover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(16, 40, 80, 0.13); }
.book-cover {
  position: relative; width: 100%; aspect-ratio: 2 / 3; cursor: pointer; overflow: hidden;
  background: linear-gradient(135deg, #eef3fa 0%, #d6e2f2 100%);
}
.cover-fallback { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 44px; }
.book-cover img { position: relative; z-index: 1; width: 100%; height: 100%; object-fit: cover; }
.cover-badge {
  position: absolute; z-index: 2; right: 8px; bottom: 8px; background: rgba(0, 0, 0, 0.62); color: #fff;
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
}
.book-info { padding: 10px 12px; cursor: pointer; }
.book-title { font-weight: 600; font-size: 13.5px; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-author { color: var(--text-secondary); font-size: 12px; margin-bottom: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-meta { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--text-secondary); }
.book-format { background: var(--primary-soft); color: var(--primary-dark); padding: 2px 7px; border-radius: 4px; font-weight: 600; }
.book-actions { display: flex; gap: 6px; padding: 0 12px 12px; }
.book-actions button { flex: 1; padding: 6px 2px; border: 1px solid var(--border); background: #fbfcfe; border-radius: 6px; font-size: 12px; font-family: inherit; cursor: pointer; }
.book-actions button:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.book-actions button.danger:hover { background: #e5484d; border-color: #e5484d; }

.empty-state { text-align: center; padding: 70px 20px; color: var(--text-secondary); }
.empty-icon { font-size: 60px; margin-bottom: 14px; }
.empty-state h3 { margin-bottom: 8px; color: var(--text); font-size: 16px; }

/* ===== 模态框（毛玻璃） ===== */
.modal { display: none; position: fixed; inset: 0; z-index: 1000; justify-content: center; align-items: center; padding: 20px;
  background: rgba(20, 30, 50, 0.35); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.modal.active { display: flex; }
.modal-content { background: var(--surface); border-radius: 16px; max-width: 480px; width: 100%; max-height: 88vh; overflow: auto; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3); }
.modal-large { max-width: 780px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal-header h2 { font-size: 17px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-secondary); line-height: 1; }
.modal-body { padding: 20px 22px; }

/* ===== 上传 ===== */
.upload-zone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 32px 20px; text-align: center; cursor: pointer; transition: all 0.15s; }
.upload-zone:hover, .upload-zone.dragging { border-color: var(--primary); background: var(--primary-soft); }
.upload-icon { font-size: 42px; margin-bottom: 10px; }
.upload-zone p { font-size: 14px; }
.upload-progress { margin-top: 16px; }
.progress-bar { height: 7px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); width: 0%; transition: width 0.2s; }
.upload-progress p { margin-top: 7px; color: var(--text-secondary); font-size: 13px; }
.meta-panel { margin: 16px 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.meta-panel-head { display: flex; justify-content: space-between; align-items: center; padding: 11px 14px; cursor: pointer; font-size: 13.5px; font-weight: 500; background: #fbfcfe; }
.meta-panel-head:hover { color: var(--primary); }
#upload-meta-fields { padding: 14px 14px 2px; }

/* ===== 书源 ===== */
.source-search { display: flex; gap: 10px; margin-bottom: 12px; }
.source-search input { flex: 1; padding: 11px 14px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 15px; font-family: inherit; }
.source-search input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.source-search .btn { width: auto; padding: 11px 22px; }
.hint-sm { font-size: 12px; color: var(--text-secondary); margin-bottom: 14px; line-height: 1.6; }
.source-results { max-height: 52vh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.source-item { display: flex; gap: 14px; padding: 14px; border-bottom: 1px solid var(--border); align-items: center; }
.source-item:last-child { border-bottom: none; }
.source-item:hover { background: #fbfcfe; }
.source-cover { width: 52px; height: 72px; border-radius: 4px; object-fit: cover; background: linear-gradient(135deg, #eef3fa, #d6e2f2); flex-shrink: 0; }
.source-info { flex: 1; min-width: 0; }
.source-title { font-weight: 600; margin-bottom: 3px; font-size: 14px; }
.source-author { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 5px; }
.source-meta { font-size: 11.5px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; }
.source-btn { padding: 7px 12px; border: 1px solid var(--primary); background: transparent; color: var(--primary); border-radius: var(--radius); cursor: pointer; font-size: 12.5px; font-family: inherit; white-space: nowrap; }
.source-btn:hover { background: var(--primary); color: #fff; }
.source-btn.solid { background: var(--primary); color: #fff; }
.source-btn.solid:hover { background: var(--primary-dark); }
.source-btn.done { background: #12a15b; border-color: #12a15b; color: #fff; cursor: default; }
.source-btn:disabled { opacity: 0.75; cursor: progress; }
.src-badge { display: inline-block; padding: 1px 6px; border-radius: 4px; background: #eef1f6; color: #55607a; font-size: 11px; margin-right: 4px; }
.src-badge.ok { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.hint { text-align: center; color: var(--text-secondary); padding: 36px 20px; font-size: 13.5px; }

/* ===== 阅读器 ===== */
.reader-screen { display: none; position: fixed; inset: 0; z-index: 900; flex-direction: column; background: var(--reader-bg); }
.reader-screen.active { display: flex; }
.reader-screen.reader-dark { --reader-bg: #1b1b1b; --reader-fg: #cfcfcf; background: var(--reader-bg); }
.reader-topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
}
.reader-dark .reader-topbar { background: rgba(27, 27, 27, 0.92); border-bottom-color: #2c2c2c; }
.btn-back { background: none; border: none; font-size: 15px; cursor: pointer; color: var(--primary); padding: 6px 4px; font-family: inherit; white-space: nowrap; }
.reader-title { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--reader-fg); }
.reader-actions { display: flex; align-items: center; gap: 4px; }
.reader-pct { font-size: 12px; color: var(--text-secondary); margin-right: 6px; }
.btn-ghost { background: none; border: 1px solid transparent; border-radius: 6px; cursor: pointer; font-size: 13px; padding: 5px 8px; color: var(--reader-fg); font-family: inherit; }
.btn-ghost:hover { background: rgba(127, 127, 127, 0.15); }
.reader-body { position: relative; flex: 1; min-height: 0; display: flex; }
.reader-view { display: none; position: absolute; inset: 0; width: 100%; height: 100%; border: none; }
.txt-view {
  overflow-y: auto; background: var(--reader-bg); color: var(--reader-fg);
  padding: 36px 20px 80px; font-size: 17px; line-height: 1.85; -webkit-overflow-scrolling: touch;
}
.txt-view p { max-width: 38em; margin: 0 auto 0.85em; text-indent: 2em; word-break: break-word; }
.txt-view p.blank { height: 0.6em; }
.reader-fallback { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 30px; color: var(--reader-fg); }
.reader-fallback h3 { margin: 14px 0 8px; font-size: 17px; }
.reader-fallback p { color: var(--text-secondary); font-size: 13.5px; margin-bottom: 20px; max-width: 30em; }
.reader-fallback .btn { width: auto; padding: 10px 26px; }
.fallback-icon { font-size: 56px; }
.reader-nav {
  display: none; position: absolute; top: 50%; transform: translateY(-50%); z-index: 5;
  width: 44px; height: 68px; border: none; background: rgba(127, 127, 127, 0.12); color: var(--reader-fg);
  font-size: 26px; line-height: 1; cursor: pointer; border-radius: 8px; align-items: center; justify-content: center;
}
.reader-nav:hover { background: rgba(127, 127, 127, 0.26); }
.reader-prev { left: 6px; }
.reader-next { right: 6px; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translate(-50%, 20px); z-index: 2000;
  background: rgba(24, 32, 48, 0.94); color: #fff; padding: 11px 20px; border-radius: 10px;
  font-size: 13.5px; opacity: 0; pointer-events: none; transition: all 0.22s; max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .topbar { padding: 10px 14px; flex-wrap: wrap; }
  .topbar-right { width: 100%; order: 3; }
  .search-box { flex: 1; width: auto; }
  .user-info { display: none; }
  .content { padding: 14px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); gap: 13px; }
  .book-actions button { font-size: 11px; padding: 6px 0; }
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-content { border-radius: 18px 18px 0 0; max-height: 92vh; }
  .source-item { padding: 11px; gap: 10px; }
  .source-cover { width: 44px; height: 62px; }
  .source-btn { padding: 6px 9px; font-size: 11.5px; }
  .reader-topbar { flex-wrap: wrap; padding: 8px 12px; }
  .reader-title { font-size: 13px; }
  .reader-nav { width: 36px; height: 56px; }
  .txt-view { padding: 22px 16px 70px; font-size: 16.5px; line-height: 1.9; }
  .txt-view p { text-indent: 1.6em; }
}
