:root {
  --bg-main: #090d16;
  --bg-panel: #111827;
  --bg-card: #161f33;
  --bg-card-hover: #1e2942;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(245, 158, 11, 0.45);
  --text-main: #f8fafc;
  --text-sub: #94a3b8;
  --text-muted: #64748b;
  --accent-gold: #f59e0b;
  --accent-gold-hover: #fbbf24;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-purple: #8b5cf6;
  --shadow-lg: 0 12px 32px -8px rgba(0, 0, 0, 0.6);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

/* 书香羊皮纸日间主题 */
body.theme-sepia {
  --bg-main: #f5efe6;
  --bg-panel: #ece3d5;
  --bg-card: #fcf8f2;
  --bg-card-hover: #fffdf9;
  --border-color: rgba(120, 90, 60, 0.16);
  --border-highlight: rgba(180, 83, 9, 0.5);
  --text-main: #271c15;
  --text-sub: #5c4938;
  --text-muted: #8a735e;
  --accent-gold: #b45309;
  --accent-gold-hover: #d97706;
  --shadow-lg: 0 10px 25px -6px rgba(92, 73, 56, 0.15);
}

/* Kindle 墨水屏黑白极简高对比模式 */
body.theme-eink,
body.theme-eink * {
  transition: none !important;
  animation: none !important;
  backdrop-filter: none !important;
  box-shadow: none !important;
}
body.theme-eink {
  --bg-main: #ffffff;
  --bg-panel: #f4f4f4;
  --bg-card: #ffffff;
  --bg-card-hover: #eeeeee;
  --border-color: #000000;
  --border-highlight: #000000;
  --text-main: #000000;
  --text-sub: #111111;
  --text-muted: #333333;
  --accent-gold: #000000;
  --accent-cyan: #000000;
  --accent-emerald: #000000;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* 顶部生态互联导航栏 */
.top-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  padding: 0.65rem 1.25rem;
}
body.theme-sepia .top-header {
  background: rgba(236, 227, 213, 0.92);
}
body.theme-eink .top-header {
  background: #ffffff;
  border-bottom: 2px solid #000;
}

.header-inner {
  max-width: 1560px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-main);
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  object-fit: contain;
  background: radial-gradient(circle, rgba(245,158,11,0.2) 0%, transparent 70%);
  border: 1px solid rgba(245, 158, 11, 0.35);
  padding: 2px;
}

.brand-titles h1 {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.brand-badge {
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 99px;
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  color: #fff;
  font-weight: 700;
}
body.theme-eink .brand-badge {
  background: #000;
  color: #fff;
}

.brand-titles p {
  font-size: 0.74rem;
  color: var(--text-sub);
}

/* 搜索框总成 */
.search-bar-wrap {
  flex: 1;
  max-width: 540px;
  min-width: 240px;
  position: relative;
  display: flex;
  align-items: center;
}

.search-input {
  width: 100%;
  padding: 0.62rem 5.5rem 0.62rem 2.4rem;
  border-radius: 99px;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
body.theme-sepia .search-input {
  background: #fff;
}
body.theme-eink .search-input {
  background: #fff;
  border: 2px solid #000;
}
.search-input:focus {
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
}

.search-icon {
  position: absolute;
  left: 0.9rem;
  color: var(--text-muted);
  pointer-events: none;
}

.search-clear-btn {
  position: absolute;
  right: 0.5rem;
  background: var(--accent-gold);
  color: #fff;
  border: none;
  border-radius: 99px;
  padding: 0.28rem 0.75rem;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}

/* 顶部快捷工具按钮组 */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.action-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.8rem;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.18s;
  white-space: nowrap;
}
body.theme-sepia .action-pill {
  background: rgba(255, 255, 255, 0.7);
}
body.theme-eink .action-pill {
  border: 1.5px solid #000;
  background: #fff;
}
.action-pill:hover {
  border-color: var(--accent-gold);
  transform: translateY(-1px);
}
.action-pill.primary {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  border-color: transparent;
}
body.theme-eink .action-pill.primary {
  background: #000;
  color: #fff;
}

/* 主体双栏 Calibre-Web 布局 */
.main-layout {
  max-width: 1560px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 1.5rem;
  padding: 1.25rem;
}

/* 左侧书房导航栏 */
.sidebar {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem;
  height: fit-content;
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}

.sidebar-section-title {
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 700;
  margin: 0.9rem 0 0.45rem 0.5rem;
}
.sidebar-section-title:first-child {
  margin-top: 0.2rem;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.58rem 0.75rem;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-sub);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
  margin-bottom: 2px;
}
.nav-item:hover {
  background: rgba(245, 158, 11, 0.1);
  color: var(--text-main);
}
.nav-item.active {
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.22), rgba(245, 158, 11, 0.05));
  color: var(--accent-gold);
  border-left: 3px solid var(--accent-gold);
}
body.theme-eink .nav-item.active {
  background: #000;
  color: #fff;
}

.nav-count {
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-muted);
}
.nav-item.active .nav-count {
  background: var(--accent-gold);
  color: #fff;
}

/* 热门分类胶囊墙 */
.category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.38rem;
  margin-top: 0.4rem;
}

.cat-chip {
  font-size: 0.75rem;
  padding: 0.26rem 0.58rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-sub);
  cursor: pointer;
  transition: all 0.15s;
}
.cat-chip:hover,
.cat-chip.active {
  background: var(--accent-gold);
  color: #fff;
  border-color: var(--accent-gold);
}

/* 右侧内容主区 */
.content-area {
  min-width: 0;
}

/* 顶部 Hero 橫幅：iPhone / iPad / Kindle 专属生态舱 */
.hero-banner {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.92) 0%, rgba(15, 23, 42, 0.96) 100%);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-lg);
  padding: 1.35rem 1.5rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  flex-wrap: wrap;
  position: relative;
  overflow: hidden;
}
body.theme-sepia .hero-banner {
  background: linear-gradient(135deg, #efe5d4 0%, #e4d5be 100%);
}
body.theme-eink .hero-banner {
  background: #ffffff;
  border: 2px solid #000;
}

.hero-left {
  max-width: 720px;
}

.hero-left h2 {
  font-size: 1.35rem;
  font-weight: 800;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.hero-left p {
  font-size: 0.88rem;
  color: var(--text-sub);
  margin-bottom: 0.85rem;
}

.device-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.device-badge {
  font-size: 0.76rem;
  padding: 0.32rem 0.7rem;
  border-radius: 8px;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: var(--accent-gold);
  font-weight: 600;
  cursor: pointer;
}
body.theme-eink .device-badge {
  background: #fff;
  border: 1px solid #000;
  color: #000;
}

.hero-stats {
  display: flex;
  gap: 0.9rem;
  flex-wrap: wrap;
}

.stat-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.1rem;
  text-align: center;
  min-width: 108px;
}
.stat-num {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--accent-gold);
}
.stat-label {
  font-size: 0.72rem;
  color: var(--text-sub);
}

/* 正在阅读进度横条 */
.continue-reading-bar {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.1rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

/* 分区标题栏 */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 1.2rem 0 0.9rem;
  flex-wrap: wrap;
}
.section-header h3 {
  font-size: 1.12rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.section-sub {
  font-size: 0.8rem;
  color: var(--text-sub);
}

/* 拟真书架网格 (Calibre-Web / Apple Books 风格) */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
  gap: 1.1rem;
}

.book-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.95rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.75rem;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  position: relative;
}
.book-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-highlight);
  box-shadow: var(--shadow-lg);
}

.book-top {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
}

/* 拟真 3D 精装封面 */
.book-cover {
  width: 68px;
  height: 96px;
  border-radius: 4px 8px 8px 4px;
  flex-shrink: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.45rem 0.38rem;
  color: #fff;
  box-shadow: -3px 0 0 rgba(255,255,255,0.22) inset, 4px 6px 14px rgba(0,0,0,0.45);
  overflow: hidden;
  cursor: pointer;
}
.book-cover::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(0, 0, 0, 0.28);
}
body.theme-eink .book-cover {
  background: #ffffff !important;
  color: #000000 !important;
  border: 2px solid #000000;
}

.cover-cat {
  font-size: 0.56rem;
  opacity: 0.9;
  background: rgba(0, 0, 0, 0.28);
  padding: 1px 4px;
  border-radius: 3px;
  width: fit-content;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
body.theme-eink .cover-cat {
  background: #000;
  color: #fff;
}

.cover-title {
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.22;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.cover-author {
  font-size: 0.55rem;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-info {
  flex: 1;
  min-width: 0;
}

.book-badge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.3rem;
  margin-bottom: 0.25rem;
}

.source-tag {
  font-size: 0.66rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(245, 158, 11, 0.16);
  color: var(--accent-gold);
}
.source-tag.direct {
  background: rgba(16, 185, 129, 0.16);
  color: var(--accent-emerald);
}
body.theme-eink .source-tag {
  background: #eee;
  color: #000;
  border: 1px solid #000;
}

.fav-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text-muted);
  padding: 2px;
}
.fav-btn.active {
  color: #f59e0b;
}

.book-title {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.35;
  margin-bottom: 0.25rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-author {
  font-size: 0.78rem;
  color: var(--text-sub);
  margin-bottom: 0.35rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.format-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.fmt-pill {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-sub);
  border: 1px solid var(--border-color);
}

.book-desc {
  font-size: 0.76rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 卡片底部操作按钮 */
.book-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border-color);
}

.btn-card {
  flex: 1;
  min-width: 72px;
  padding: 0.42rem 0.5rem;
  border-radius: 7px;
  font-size: 0.76rem;
  font-weight: 700;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  transition: all 0.15s;
}
.btn-card:hover {
  border-color: var(--accent-gold);
  background: rgba(245, 158, 11, 0.14);
}
.btn-card.btn-read {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  border-color: transparent;
}
.btn-card.btn-dl {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  border-color: transparent;
}
body.theme-eink .btn-card.btn-read,
body.theme-eink .btn-card.btn-dl {
  background: #000;
  color: #fff;
}

/* 全网影子书库矩阵穿透条 */
.shadow-matrix-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.2rem;
  margin-bottom: 1.25rem;
}
.shadow-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.65rem;
}

/* 加载更多分页按钮 */
.load-more-wrap {
  text-align: center;
  margin: 1.8rem 0;
}
.btn-load-more {
  padding: 0.68rem 2.2rem;
  border-radius: 99px;
  background: var(--bg-panel);
  border: 1px solid var(--accent-gold);
  color: var(--accent-gold);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-load-more:hover {
  background: var(--accent-gold);
  color: #fff;
}

/* ==========================================
   内置全屏 Calibre-Web 级 EPUB/TXT 阅读器 Modal
   ========================================== */
.reader-modal {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: #0f172a;
  display: none;
  flex-direction: column;
}
.reader-modal.open {
  display: flex;
}
.reader-modal.r-sepia {
  background: #f4ecd8;
  color: #2c221e;
}
.reader-modal.r-light {
  background: #ffffff;
  color: #111827;
}
.reader-modal.r-eink {
  background: #ffffff;
  color: #000000;
}

.reader-toolbar {
  height: 54px;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  gap: 0.5rem;
  flex-shrink: 0;
}

.reader-book-title {
  font-size: 0.92rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42vw;
}

.reader-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.r-btn {
  padding: 0.35rem 0.68rem;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.r-btn:hover {
  border-color: #f59e0b;
}

.reader-stage-wrap {
  flex: 1;
  position: relative;
  display: flex;
  overflow: hidden;
}

.reader-toc-drawer {
  width: 280px;
  border-right: 1px solid rgba(148, 163, 184, 0.2);
  overflow-y: auto;
  padding: 0.85rem;
  display: none;
  background: inherit;
  z-index: 10;
}
.reader-toc-drawer.open {
  display: block;
}
.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.6rem;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 0.84rem;
  border-radius: 6px;
  cursor: pointer;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}
.toc-item:hover {
  background: rgba(245, 158, 11, 0.15);
}

#epubViewer {
  flex: 1;
  height: 100%;
  width: 100%;
  overflow-y: auto;
  position: relative;
}

.reader-footer {
  height: 46px;
  padding: 0 1.25rem;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  flex-shrink: 0;
}

/* 通用弹窗 Modal (Kindle 推送指南 & 书籍详情) */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.dialog-backdrop.open {
  display: flex;
}

.dialog-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-lg);
  max-width: 640px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 1.5rem;
  color: var(--text-main);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.guide-step {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  margin-bottom: 0.75rem;
}
.guide-step h4 {
  color: var(--accent-gold);
  margin-bottom: 0.35rem;
  font-size: 0.92rem;
}
.guide-step p {
  font-size: 0.83rem;
  color: var(--text-sub);
}

/* Toast 提示 */
.toast-msg {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  color: #fff;
  padding: 0.65rem 1.35rem;
  border-radius: 99px;
  font-size: 0.86rem;
  font-weight: 700;
  box-shadow: 0 10px 25px rgba(0,0,0,0.45);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s;
  z-index: 2000;
}
.toast-msg.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* 移动端 iPhone / iPad 响应式适配 */
@media (max-width: 960px) {
  .main-layout {
    grid-template-columns: 1fr;
    padding: 0.85rem;
  }
  .sidebar {
    position: static;
    max-height: none;
  }
  .books-grid {
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    gap: 0.75rem;
  }
  .book-top {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .book-cover {
    width: 82px;
    height: 114px;
  }
  .book-badge-row,
  .format-pills {
    justify-content: center;
  }
}
