/* ===== 全局样式 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --border: #e8e4dc;
  --text: #2c2825;
  --text-muted: #7a7068;
  --accent: #1a6b4a;
  --accent-light: #e8f4ef;
  --accent-hover: #145c3e;
  --highlight: #f5f0e8;
  --code-bg: #f0ede6;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --radius: 8px;
  --font-body: 'Noto Serif SC', 'Source Han Serif CN', Georgia, serif;
  --font-ui: 'Noto Sans SC', 'PingFang SC', system-ui, sans-serif;
  --font-code: 'Fira Code', 'Courier New', monospace;
  --max-width: 760px;
  --sidebar-width: 260px;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.9;
  min-height: 100vh;
}

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

/* ===== 侧边栏 ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--accent);
  color: white;
}

.sidebar-header .book-title {
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.4;
  font-family: var(--font-ui);
}

.sidebar-header .book-subtitle {
  font-size: 0.72rem;
  opacity: 0.8;
  margin-top: 4px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.sidebar-nav a {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 20px;
  text-decoration: none;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  line-height: 1.4;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-left-color: var(--accent);
}

.sidebar-nav a.active {
  background: var(--accent-light);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

.sidebar-nav .nav-num {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  background: var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  margin-top: 1px;
}

.sidebar-nav a.active .nav-num,
.sidebar-nav a:hover .nav-num {
  background: var(--accent);
  color: white;
}

/* ===== 主内容 ===== */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
}

.content-wrapper {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 48px 40px 80px;
}

/* ===== 排版 ===== */
h1 {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1.3;
  color: var(--text);
  margin-bottom: 0.5em;
  letter-spacing: -0.5px;
}

h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  margin: 2.5em 0 0.8em;
  padding-bottom: 0.4em;
  border-bottom: 2px solid var(--border);
}

h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  margin: 1.8em 0 0.6em;
}

h4 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin: 1.4em 0 0.4em;
}

p {
  margin-bottom: 1.2em;
  text-align: justify;
  hyphens: auto;
}

/* ===== 引用块 ===== */
blockquote {
  border-left: 4px solid var(--accent);
  background: var(--accent-light);
  padding: 16px 20px;
  margin: 1.5em 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
  color: var(--text-muted);
}

blockquote p { margin: 0; }

/* ===== 列表 ===== */
ul, ol {
  margin: 0.8em 0 1.2em 1.4em;
}

li {
  margin-bottom: 0.4em;
}

li > ul, li > ol {
  margin-top: 0.3em;
  margin-bottom: 0.3em;
}

/* ===== 表格 ===== */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5em 0;
  font-family: var(--font-ui);
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  overflow: hidden;
}

thead { background: var(--accent); color: white; }

th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  letter-spacing: 0.3px;
}

td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

tr:last-child td { border-bottom: none; }

tbody tr:nth-child(even) { background: var(--highlight); }

tbody tr:hover { background: var(--accent-light); }

/* ===== 代码 ===== */
code {
  font-family: var(--font-code);
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--accent-hover);
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  overflow-x: auto;
  margin: 1.5em 0;
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.85rem;
  color: var(--text);
}

/* ===== 水平线 ===== */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5em 0;
}

/* ===== 章节标题区域 ===== */
.chapter-hero {
  background: linear-gradient(135deg, var(--accent) 0%, #2d9e6e 100%);
  color: white;
  padding: 40px 40px 36px;
  margin: -48px -40px 40px;
  border-radius: 0 0 16px 16px;
}

.chapter-hero .chapter-num {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.8;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.chapter-hero h1 {
  color: white;
  font-size: 1.8rem;
  margin-bottom: 0;
}

/* ===== 要点卡片 ===== */
.key-points {
  background: var(--highlight);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin: 1.5em 0 2em;
}

.key-points-title {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
}

.key-points ul {
  margin: 0;
  padding-left: 1.2em;
}

.key-points li {
  font-size: 0.95rem;
  margin-bottom: 6px;
}

/* ===== 导航按钮 ===== */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 3em;
  padding-top: 2em;
  border-top: 1px solid var(--border);
}

.chapter-nav a {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.chapter-nav a:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.chapter-nav a.prev { text-align: left; }
.chapter-nav a.next { text-align: right; justify-content: flex-end; }

.chapter-nav .nav-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.chapter-nav .nav-title {
  font-weight: 600;
  display: block;
}

/* ===== 汉堡按钮（移动端） ===== */
.hamburger {
  display: none;
  position: fixed;
  top: 16px; left: 16px;
  z-index: 200;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  width: 40px; height: 40px;
  cursor: pointer;
  font-size: 1.2rem;
  box-shadow: var(--shadow);
}

/* ===== 强调文字 ===== */
strong { color: var(--text); font-weight: 700; }

/* ===== 响应式 ===== */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .hamburger { display: flex; align-items: center; justify-content: center; }
  .content-wrapper { padding: 60px 20px 60px; }
  .chapter-hero { margin: -60px -20px 32px; padding: 60px 20px 28px; }
  h1 { font-size: 1.6rem; }
}

/* ===== 首页特殊样式 ===== */
.home-hero {
  text-align: center;
  padding: 60px 20px 40px;
  background: linear-gradient(160deg, var(--accent) 0%, #2d9e6e 60%, #3db87a 100%);
  color: white;
  margin: -48px -40px 48px;
  border-radius: 0 0 24px 24px;
}

.home-hero h1 {
  color: white;
  font-size: 2.2rem;
  margin-bottom: 12px;
}

.home-hero .subtitle {
  font-family: var(--font-ui);
  font-size: 1rem;
  opacity: 0.88;
  max-width: 480px;
  margin: 0 auto;
}

.toc-grid {
  display: grid;
  gap: 12px;
  margin: 2em 0;
}

.toc-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.toc-item:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: translateX(4px);
}

.toc-item .toc-num {
  flex-shrink: 0;
  width: 36px; height: 36px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.85rem;
}

.toc-item .toc-info { flex: 1; }

.toc-item .toc-title {
  font-weight: 700;
  display: block;
  font-size: 0.95rem;
}

.toc-item .toc-desc {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

.toc-item .toc-arrow {
  color: var(--text-muted);
  font-size: 1.1rem;
}

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
