/* ========== 主题变量：白天/黑夜 ========== */
:root {
  --bg: #f5f5f7;
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --border: #e5e5e7;
  --accent: #3478f6;
  --accent-hover: #2962cc;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-hover: 0 6px 20px rgba(0,0,0,.12);
  --radius: 12px;
}
:root[data-theme="dark"] {
  --bg: #1a1a1c;
  --bg-card: #2a2a2e;
  --bg-elevated: #323236;
  --text: #f0f0f2;
  --text-secondary: #a0a0a8;
  --border: #3a3a3e;
  --accent: #5e9eff;
  --accent-hover: #4a8ae0;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-hover: 0 6px 20px rgba(0,0,0,.4);
}

/* ========== 基础重置 ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background .25s, color .25s;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 14px; }

/* ========== 顶栏 ========== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: 56px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow);
}
.topbar .brand {
  font-size: 18px; font-weight: 600;
  color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.topbar .brand svg { width: 22px; height: 22px; color: var(--accent); }
.topbar .spacer { flex: 1; }
.topbar .actions { display: flex; align-items: center; gap: 8px; }

/* 图标按钮 */
.icon-btn {
  width: 38px; height: 38px;
  border: none; background: transparent;
  color: var(--text-secondary);
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-elevated); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

/* 主要按钮 */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 8px;
  font-size: 14px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--bg); }
.btn-primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn svg { width: 16px; height: 16px; }

/* ========== 容器 ========== */
.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px; }

/* ========== 卡片网格（书架） ========== */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 20px;
}
.book-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
  border: 1px solid var(--border);
}
.book-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-hover); }
.book-cover {
  width: 100%; aspect-ratio: 3/4;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 16px; font-weight: 600;
  text-align: center; padding: 12px;
  overflow: hidden;
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-info { padding: 10px 12px; }
.book-title { font-size: 14px; font-weight: 500; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-meta { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* ========== 排序栏 ========== */
.sort-bar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.sort-bar label { font-size: 14px; color: var(--text-secondary); }
.sort-bar select {
  padding: 6px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg-card); color: var(--text);
}

/* ========== 空状态 ========== */
.empty {
  text-align: center; padding: 80px 20px; color: var(--text-secondary);
}
.empty svg { width: 64px; height: 64px; opacity: .4; margin-bottom: 16px; }

/* ========== 详情页 ========== */
.detail-wrap { display: flex; gap: 32px; flex-wrap: wrap; }
.detail-cover {
  width: 220px; flex-shrink: 0;
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow);
}
.detail-cover img { width: 100%; display: block; }
.detail-info { flex: 1; min-width: 280px; }
.detail-title { font-size: 28px; font-weight: 700; margin-bottom: 12px; }
.detail-meta { color: var(--text-secondary); font-size: 14px; margin-bottom: 20px; }
.section-title { font-size: 18px; font-weight: 600; margin: 24px 0 10px; }
.section-text { white-space: pre-wrap; line-height: 1.8; color: var(--text); }
.markdown-body { line-height: 1.8; }
.markdown-body h1,.markdown-body h2,.markdown-body h3 { margin: 20px 0 10px; font-weight: 600; }
.markdown-body h1 { font-size: 20px; }
.markdown-body h2 { font-size: 18px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.markdown-body h3 { font-size: 16px; }
.markdown-body p { margin: 8px 0; }
.markdown-body ul { margin: 8px 0; padding-left: 22px; }
.markdown-body li { margin: 4px 0; }
.markdown-body blockquote {
  margin: 10px 0; padding: 10px 16px;
  border-left: 3px solid var(--accent);
  background: var(--bg); border-radius: 0 6px 6px 0;
  color: var(--text-secondary);
}
.markdown-body blockquote p { margin: 4px 0; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.markdown-body strong { font-weight: 600; color: var(--text); }

/* ========== 阅读器 ========== */
.reader-layout { display: flex; height: calc(100vh - 56px); }
.reader-sidebar {
  width: 260px; flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 0;
}
.reader-sidebar .chapter-item {
  padding: 10px 16px; cursor: pointer; font-size: 14px;
  border-left: 3px solid transparent;
  transition: background .12s;
}
.reader-sidebar .chapter-item:hover { background: var(--bg); }
.reader-sidebar .chapter-item.active { border-left-color: var(--accent); color: var(--accent); font-weight: 500; }
.reader-content {
  flex: 1; overflow-y: auto; padding: 24px 8%;
  transition: background .2s, color .2s;
}
.reader-content .chapter-title { font-size: 22px; font-weight: 700; margin-bottom: 20px; text-align: center; }
.reader-content p { margin: 0 0 1.2em; text-indent: 2em; }
.reader-nav { display: flex; justify-content: space-between; margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--border); }
.reader-nav .btn { min-width: 100px; justify-content: center; }

/* 阅读器底部工具条 */
.reader-toolbar {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 24px; padding: 8px 12px;
  display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-hover); z-index: 40;
}
.reader-toolbar .group { display: flex; align-items: center; gap: 4px; }
.reader-toolbar .divider { width: 1px; height: 20px; background: var(--border); }
.reader-toolbar select, .reader-toolbar input[type="range"] { font-size: 12px; }

/* 移动端阅读器抽屉 */
@media (max-width: 768px) {
  .reader-sidebar { position: fixed; left: 0; top: 56px; bottom: 0; z-index: 45; transform: translateX(-100%); transition: transform .25s; box-shadow: var(--shadow-hover); }
  .reader-sidebar.open { transform: translateX(0); }
  .reader-content { padding: 20px 16px; }
}

/* ========== 登录页 ========== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: 100%; max-width: 360px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px;
  box-shadow: var(--shadow);
}
.login-card .logo { text-align: center; margin-bottom: 24px; }
.login-card .logo svg { width: 48px; height: 48px; color: var(--accent); }
.login-card h2 { text-align: center; margin-bottom: 20px; font-size: 20px; }
.login-card input {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); margin-bottom: 12px;
}
.login-card .btn-primary { width: 100%; justify-content: center; padding: 12px; }
.login-error { color: #e74c3c; font-size: 13px; margin-bottom: 8px; min-height: 18px; }

/* ========== 后台页 ========== */
.admin-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 24px; overflow-x: auto; }
.admin-tab { padding: 10px 16px; border: none; background: none; color: var(--text-secondary); font-size: 14px; border-bottom: 2px solid transparent; white-space: nowrap; }
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.admin-panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 16px; }
.admin-panel h3 { margin-bottom: 12px; font-size: 16px; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text-secondary); }
.form-row input, .form-row textarea, .form-row select {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text);
}
.form-row textarea { min-height: 90px; resize: vertical; line-height: 1.6; }
.form-row input[type="file"] { padding: 6px; }
.upload-zone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 32px; text-align: center; color: var(--text-secondary); transition: border-color .15s; }
.upload-zone:hover { border-color: var(--accent); }
.upload-zone svg { width: 40px; height: 40px; margin-bottom: 8px; opacity: .6; }

/* ========== 通知 toast ========== */
.toast {
  position: fixed; top: 72px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elevated); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 20px; box-shadow: var(--shadow-hover);
  z-index: 100; font-size: 14px;
  opacity: 0; transition: opacity .25s, top .25s; pointer-events: none;
}
.toast.show { opacity: 1; top: 80px; }
.toast.error { border-color: #e74c3c; color: #e74c3c; }

/* ========== 响应式 ========== */
@media (max-width: 600px) {
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
  .detail-wrap { flex-direction: column; }
  .detail-cover { width: 160px; }
  .container { padding: 16px 12px; }
}
