/* ===== 基础变量 ===== */
:root {
  --bg-page: #f5f0e8;
  --cover: #c4a580;
  --text-primary: #333;
  --text-secondary: #666;
  --text-muted: #999;
}

/* ===== 主页 ===== */
.shelf-page {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  min-height: 100vh;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color: var(--text-primary);
}

.shelf-header {
  text-align: center;
  padding: 64px 20px 40px;
}

.shelf-title {
  font-size: 32px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 4px;
  position: relative;
  display: inline-block;
}

.shelf-title::after {
  content: '';
  display: block;
  width: 50%;
  height: 2px;
  background: var(--cover);
  margin: 10px auto 0;
  border-radius: 1px;
}

/* 卡片网格 */
.card-grid {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 20px 60px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 28px 20px;
  justify-items: center;
}

/* 书本卡片 */
.book-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: inherit;
  transition: transform 0.25s ease;
}

.book-card:hover {
  transform: translateY(-6px);
}

.book-card:hover .book-cover {
  box-shadow: 0 10px 28px rgba(0,0,0,0.22);
}

.book-cover {
  width: 150px;
  height: 190px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.25s ease;
  background-image:
    repeating-linear-gradient(
      0deg, transparent, transparent 3px,
      rgba(0,0,0,0.03) 3px, rgba(0,0,0,0.03) 5px
    ),
    radial-gradient(ellipse at 40% 25%, rgba(255,255,255,0.18) 0%, transparent 55%);
  border: 1px solid rgba(0,0,0,0.06);
}

/* 书脊 */
.book-cover::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: rgba(0,0,0,0.1);
  border-radius: 6px 0 0 6px;
}

.book-cover-img {
  width: 52%;
  height: 52%;
  object-fit: contain;
}

.book-cover-text {
  font-size: 20px;
  font-weight: 700;
  color: #4a3525;
  letter-spacing: 2px;
  text-align: center;
  padding: 12px;
}

.book-name {
  margin-top: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.book-sub {
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ===== 响应式（主页） ===== */
@media (max-width: 480px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 20px 12px;
    padding: 0 12px 40px;
  }

  .book-cover {
    width: 130px;
    height: 170px;
  }
}

/* ===== 分类内页 ===== */
.category-page {
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-page);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color: var(--text-primary);
}

.page-container {
  max-width: 90%;
  width: 100%;
  height: calc(100vh - 48px);
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 0 30px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
  height: 48px;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
}

.tb-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--text-secondary);
  border-radius: 4px;
  line-height: 1;
  display: none;
}

.tb-btn:hover {
  background: #f0f0f0;
  color: var(--text-primary);
}

.tb-back {
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 16px;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
}

.tb-back:hover {
  background: #f0f0f0;
  color: var(--text-primary);
}

.tb-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tb-count {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* 主体区域 */
.main-area {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* 文件树 */
.file-tree {
  width: 22%;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 16px 0;
  border-right: 1px solid #eee;
  background: #fafafa;
  transition: transform 0.25s ease;
}

.file-tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.file-tree-chapter {
  margin-bottom: 4px;
}

.chapter-title {
  padding: 6px 20px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.post-item a {
  display: block;
  padding: 5px 20px 5px 28px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-tree-chapter .post-item a {
  padding-left: 36px;
}

.post-item a:hover {
  color: var(--text-primary);
  background: #f0f0f0;
}

.post-item.active a {
  color: #b8783b;
  background: #fdf5e6;
  border-left-color: #b8783b;
  font-weight: 600;
}

/* 文章区 */
.post-area {
  flex: 1;
  overflow-y: auto;
  padding: 36px 44px;
  min-width: 0;
}

.post-article {
  visibility: hidden;
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  max-width: 720px;
  line-height: 1.85;
  font-size: 15px;
}

.post-article.active {
  visibility: visible;
  position: static;
  pointer-events: auto;
}

.post-article h2 {
  font-size: 22px;
  margin: 32px 0 12px;
  padding-bottom: 6px;
  border-bottom: 2px solid #eee;
}

.post-article h3 {
  font-size: 18px;
  margin: 24px 0 8px;
  color: var(--text-secondary);
}

.post-article h4 {
  font-size: 16px;
  margin: 20px 0 8px;
}

.post-article p {
  margin: 10px 0;
}

.post-article code {
  background: #f0ebe0;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.9em;
  font-family: "Fira Code", "Cascadia Code", "Consolas", monospace;
}

.post-article pre.hljs {
  background: #2d2d2d;
  color: #f8f8f2;
  padding: 16px 20px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.6;
  margin: 16px 0;
}

.post-article pre.hljs code {
  background: none;
  padding: 0;
  font-size: inherit;
}

.post-article img {
  max-width: 100%;
  border-radius: 4px;
}

.post-article .mermaid {
  margin: 16px 0;
  padding: 16px;
  background: #fafafa;
  border-radius: 8px;
  border: 1px solid #eee;
  overflow-x: auto;
  text-align: center;
}

.post-article table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
}

.post-article th, .post-article td {
  border: 1px solid #ddd;
  padding: 8px 12px;
  text-align: left;
}

.post-article th {
  background: #f5f0e8;
}

.post-article blockquote {
  margin: 12px 0;
  padding: 8px 16px;
  border-left: 4px solid #d4a76a;
  background: #fdf5e6;
  color: var(--text-secondary);
}

.post-article a {
  color: #b8783b;
}

/* 上一篇/下一篇 */
/* 右侧大纲（桌面端） */
.outline-sidebar {
  width: 18%;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 16px 0;
  border-left: 1px solid #eee;
  background: #fafafa;
}

.ol-sidebar-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0 16px 8px;
  letter-spacing: 1px;
}

.outline-sidebar .ol-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.outline-sidebar .ol-item a {
  display: block;
  padding: 4px 16px;
  font-size: 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.outline-sidebar .ol-item a:hover {
  color: var(--text-primary);
  background: #f0f0f0;
}

.outline-sidebar .ol-h3 a {
  padding-left: 28px;
  font-size: 11px;
}

@media (max-width: 900px) {
  .outline-sidebar { display: none; }
  #btn-outline { display: flex; }
  .outline-popup { right: 16px; bottom: 92px; width: 240px; max-height: 300px; }
}

/* 右侧大纲 */
.outline-sidebar {
  width: 18%;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 16px 0;
  border-left: 1px solid #eee;
  background: #fafafa;
}

.ol-sidebar-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0 16px 8px;
  letter-spacing: 1px;
}

.outline-sidebar .ol-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.outline-sidebar .ol-item a {
  display: block;
  padding: 4px 16px;
  font-size: 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.outline-sidebar .ol-item a:hover {
  color: var(--text-primary);
  background: #f0f0f0;
}

.outline-sidebar .ol-h3 a {
  padding-left: 28px;
  font-size: 11px;
}

/* 上一篇/下一篇 */
.post-prev-next {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 48px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

.pn-link {
  color: #b8783b;
  text-decoration: none;
  font-size: 14px;
  max-width: 48%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pn-link:first-child {
  text-align: left;
}

.pn-link:last-child {
  text-align: right;
}

.pn-link:hover {
  text-decoration: underline;
}

.pn-link.disabled {
  color: var(--text-muted);
  pointer-events: none;
  max-width: none;
}

/* 浮动按钮组 */
.float-btns {
  position: fixed;
  bottom: 28px;
  right: 28px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.fb-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid #ddd;
  background: #fff;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-secondary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.fb-btn:hover {
  background: #f5f5f5;
  color: var(--text-primary);
  box-shadow: 0 4px 14px rgba(0,0,0,0.15);
}

@media (min-width: 901px) { #btn-outline { display: none; } }

/* 大纲 popup */
.outline-popup {
  position: fixed;
  bottom: 100px;
  right: 28px;
  width: 260px;
  max-height: 360px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
  display: none;
  z-index: 200;
}

.outline-popup.show { display: block; }

.ol-popup-inner { padding: 12px 0; }

.outline-popup .ol-list { list-style: none; margin: 0; padding: 0; }

.outline-popup .ol-item a {
  display: block;
  padding: 5px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.outline-popup .ol-item a:hover { background: #f5f5f5; }
.outline-popup .ol-h3 a { padding-left: 28px; font-size: 12px; }

/* 大纲 popup */
.outline-popup {
  position: fixed;
  bottom: 108px;
  right: 28px;
  width: 260px;
  max-height: 360px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
  display: none;
  z-index: 200;
}

.outline-popup.show {
  display: block;
}

.ol-popup-inner {
  padding: 12px 0;
}

.ol-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ol-item {
  margin-bottom: 1px;
}

.ol-item a {
  display: block;
  padding: 5px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ol-item a:hover {
  color: var(--text-primary);
  background: #f5f5f5;
}

.ol-h3 a {
  padding-left: 28px;
  font-size: 12px;
}

/* 移动端遮罩 */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 150;
}

.overlay.show {
  display: block;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .category-page {
    height: auto;
    overflow: visible;
    display: block;
  }

  .page-container {
    max-width: 100%;
    height: auto;
    box-shadow: none;
    border-radius: 0;
  }

  .tb-btn {
    display: block;
  }

  .file-tree {
    position: fixed;
    left: 0;
    top: 48px;
    bottom: 0;
    z-index: 160;
    transform: translateX(-100%);
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
  }

  .file-tree.open {
    transform: translateX(0);
  }

  .post-area {
    padding: 20px 20px 32px;
  }

  .float-btns {
    bottom: 20px;
    right: 16px;
  }

  .outline-popup {
    right: 16px;
    bottom: 100px;
    width: 240px;
    max-height: 300px;
  }

  .post-prev-next {
    flex-direction: column;
    gap: 8px;
    margin-top: 32px;
  }

  .pn-link {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 20px 12px;
    padding: 0 12px 40px;
  }

  .book-cover {
    width: 130px;
    height: 170px;
  }
}
