/* ========== 四库全书 全局样式 ========== */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap');

:root {
  --bg: #faf8f4;
  --bg-card: #ffffff;
  --bg-sidebar: #161b2e;
  --bg-sidebar-hover: #1f2740;
  --bg-sidebar-active: #283352;
  --text: #2c3e50;
  --text-secondary: #6b7280;
  --text-sidebar: #c9cdd4;
  --text-sidebar-active: #ffffff;
  --border: #e5e1d8;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 4px 10px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 50px rgba(0,0,0,0.1);
  --radius: 10px;
  --radius-lg: 16px;
  --sidebar-width: 272px;
  --header-height: 60px;
  --max-content: 860px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

  /* Category colors */
  --c-jing: #1e40af;
  --c-shi: #7c3aed;
  --c-zi: #dc2626;
  --c-ji: #059669;
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: "Noto Serif SC", "Source Han Serif SC", "SimSun", serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c4bfb5; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a09a8f; }

/* ========== Layout ========== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ========== Sidebar ========== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  transition: transform var(--transition), width var(--transition);
  display: flex;
  flex-direction: column;
}

/* 折叠状态（桌面） */
.sidebar.collapsed {
  width: 52px;
}
.sidebar.collapsed .sidebar-header {
  padding: 16px 8px 12px;
  justify-content: center;
}
.sidebar.collapsed .sidebar-brand {
  justify-content: center;
}
.sidebar.collapsed .sidebar-brand > div {
  display: none;
}
.sidebar.collapsed .sidebar-search {
  padding: 8px;
}
.sidebar.collapsed .sidebar-search input {
  display: none;
}
.sidebar.collapsed .sidebar-cat-header {
  padding: 8px 0;
  justify-content: center;
  gap: 0;
}
.sidebar.collapsed .sidebar-cat-header span:not(.cat-dot) {
  display: none;
}
.sidebar.collapsed .sidebar-book-list {
  display: none;
}
.sidebar.collapsed .sidebar-nav {
  display: none;
}

/* 侧边栏折叠按钮 */
.sidebar-collapse-btn {
  position: absolute;
  top: 50%;
  right: -14px;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  background: var(--bg-sidebar);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 50%;
  color: #8892a4;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 101;
  transition: all var(--transition);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.sidebar-collapse-btn:hover {
  color: #fff;
  background: var(--bg-sidebar-hover);
}
.sidebar.collapsed .sidebar-collapse-btn {
  right: -14px;
}

.sidebar-header {
  padding: 20px 20px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
}

.sidebar-brand-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #c0392b, #e74c3c);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-brand-text {
  font-family: "Noto Sans SC", sans-serif;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 2px;
}

.sidebar-brand-sub {
  font-size: 11px;
  color: #8892a4;
  font-weight: 300;
  letter-spacing: 0;
}

.sidebar-search {
  padding: 12px 16px;
  flex-shrink: 0;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  outline: none;
  transition: all var(--transition);
  font-family: "Noto Sans SC", sans-serif;
}

.sidebar-search input::placeholder { color: #6b7a90; }
.sidebar-search input:focus {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.2);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.sidebar-cat {
  margin-bottom: 4px;
}

.sidebar-cat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  cursor: pointer;
  font-family: "Noto Sans SC", sans-serif;
  font-weight: 500;
  font-size: 13px;
  color: #8892a4;
  text-transform: uppercase;
  letter-spacing: 1px;
  user-select: none;
  transition: color var(--transition);
}

.sidebar-cat-header:hover { color: #c9cdd4; }

.sidebar-cat-header .cat-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-cat-header .cat-count {
  margin-left: auto;
  font-size: 11px;
  opacity: 0.6;
  font-weight: 400;
}

.sidebar-cat-header .arrow {
  font-size: 10px;
  transition: transform var(--transition);
  opacity: 0.5;
}

.sidebar-cat.collapsed .arrow { transform: rotate(-90deg); }
.sidebar-cat.collapsed .sidebar-book-list { display: none; }

.sidebar-book-list {
  list-style: none;
  padding: 2px 0;
}

.sidebar-book-item a {
  display: block;
  padding: 5px 20px 5px 38px;
  color: var(--text-sidebar);
  text-decoration: none;
  font-size: 13.5px;
  transition: all var(--transition);
  border-left: 2px solid transparent;
  line-height: 1.5;
}

.sidebar-book-item a:hover {
  background: var(--bg-sidebar-hover);
  color: #fff;
}

.sidebar-book-item.active a {
  background: var(--bg-sidebar-active);
  color: var(--text-sidebar-active);
  border-left-color: #e74c3c;
}

/* ========== Main Content ========== */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition);
}
.main-content.sidebar-collapsed {
  margin-left: 52px;
}

.content-header {
  position: sticky;
  top: 0;
  background: rgba(250, 248, 244, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 32px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: "Noto Sans SC", sans-serif;
  font-size: 13px;
  color: var(--text-secondary);
}

.breadcrumb a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition);
}

.breadcrumb a:hover { color: var(--text); }
.breadcrumb .sep { opacity: 0.4; }
.breadcrumb .current { color: var(--text); font-weight: 500; }

.content-search {
  margin-left: auto;
  position: relative;
}

.content-search input {
  width: 200px;
  padding: 6px 12px 6px 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  background: #fff;
  transition: all var(--transition);
  font-family: "Noto Sans SC", sans-serif;
}

.content-search input:focus {
  width: 260px;
  border-color: #c0392b;
  box-shadow: 0 0 0 3px rgba(192,57,43,0.1);
}

.content-search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
  font-size: 13px;
}

.search-count {
  font-size: 12px;
  color: #9ca3af;
  margin-left: 8px;
  font-family: "Noto Sans SC", sans-serif;
}

/* ========== Book Content ========== */
.book-layout {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 32px 80px;
  flex: 1;
  gap: 0;
}

.book-content {
  flex: 1;
  min-width: 0;
  padding-right: 24px;
}

.book-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: #1a1a1a;
  letter-spacing: 2px;
}

.section-title {
  font-size: 1.4rem;
  font-weight: 600;
  margin: 40px 0 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border);
  color: #333;
}

.chapter-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 32px 0 16px;
  color: #444;
  position: relative;
  padding-left: 14px;
}

.chapter-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: #c0392b;
  border-radius: 2px;
}

.book-content p {
  margin: 12px 0;
  text-indent: 2em;
  line-height: 2;
  color: #333;
}

.book-content blockquote.quote {
  margin: 16px 0;
  padding: 12px 20px;
  border-left: 3px solid #d4a853;
  background: #fdf8ee;
  border-radius: 0 8px 8px 0;
  color: #6b5b3a;
}

.book-content hr.divider {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  margin: 32px 0;
}

.book-content pre.code-block {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 16px 20px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 16px 0;
  font-size: 13.5px;
  line-height: 1.6;
}

.book-content code.inline-code {
  background: #f3f0e8;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  color: #c0392b;
}

.book-content ul, .book-content ol {
  margin: 12px 0 12px 2em;
}

.book-content li {
  margin: 4px 0;
}

/* Highlight for search — 不改变文字大小和间距 */
mark.search-hl {
  background: #fef08a;
  color: inherit;
  padding: 0;
  border-radius: 2px;
  font-weight: inherit;
  font-size: inherit;
  line-height: inherit;
}

mark.search-hl-current {
  background: #f97316;
  color: #fff;
  padding: 0;
  border-radius: 2px;
  font-weight: inherit;
  font-size: inherit;
  line-height: inherit;
}

/* ========== Back to Top ========== */
.back-to-top {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 44px;
  height: 44px;
  background: #c0392b;
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  transition: all var(--transition);
  z-index: 80;
}

.back-to-top:hover {
  background: #a93226;
  transform: translateY(-2px);
}

.back-to-top.visible { display: flex; }

/* ========== Mobile Toggle ========== */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 40px; height: 40px;
  background: var(--bg-sidebar);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 90;
}

/* ========== Responsive ========== */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-toggle {
    display: flex;
  }
  .sidebar-overlay.open {
    display: block;
  }
  .sidebar-collapse-btn {
    display: none !important;
  }
  .main-content {
    margin-left: 0;
  }
  .main-content.sidebar-collapsed {
    margin-left: 0;
  }
  .book-content {
    padding: 24px 16px 60px;
  }
}

@media (max-width: 640px) {
  .book-title { font-size: 1.5rem; }
  .section-title { font-size: 1.2rem; }
  .chapter-title { font-size: 1.05rem; }
  .content-header { padding: 10px 16px; }
  .content-search input { width: 140px; }
  .content-search input:focus { width: 180px; }
}
