:root {
  --bg: #f5f6f8;
  --bg-card: #ffffff;
  --bg-side: #ffffff;
  --border: #e6e8eb;
  --text: #1f2329;
  --text-2: #5b6470;
  --text-3: #8a919b;
  --primary: #2f6bff;
  --primary-soft: #eaf0ff;
  --accent: #f0f4ff;
  --code-bg: #1f242e;
  --code-text: #e6edf3;
  --red: #e5484d;
  --green: #2e9e5b;
  --amber: #b7791f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.10);
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; height: 100vh; overflow: hidden; }

/* ===== 侧边栏 ===== */
.sidebar {
  width: 288px;
  min-width: 288px;
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding-bottom: 20px;
}

.brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-side);
  z-index: 2;
}
.brand-title {
  display: block;
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.5px;
}
.brand-sub {
  display: block;
  font-size: 12px;
  color: var(--text-3);
  margin-top: 3px;
}

.side-section { padding: 8px 10px 0; }
.side-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 10px 4px;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  text-align: left;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.side-link:hover { background: var(--accent); color: var(--text); }
.side-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.side-link .ico { width: 18px; text-align: center; font-size: 13px; }

.side-link.chapter-num {
  font-size: 11px;
  color: var(--text-3);
  width: 26px;
  min-width: 26px;
  font-variant-numeric: tabular-nums;
}

/* 分类折叠 */
.cat-group { margin-bottom: 2px; }
.cat-head {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
  text-align: left;
}
.cat-head:hover { background: var(--accent); }
.cat-head .arrow { transition: transform 0.15s; font-size: 10px; color: var(--text-3); }
.cat-head.open .arrow { transform: rotate(90deg); }
.cat-head .cnt { margin-left: auto; font-size: 11px; color: var(--text-3); font-weight: 400; }

.cat-body { display: none; padding-left: 8px; }
.cat-body.open { display: block; }
.cat-body .side-link { padding: 6px 10px; font-size: 13.5px; }

/* ===== 主区 ===== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  max-width: 640px;
  transition: border 0.15s, box-shadow 0.15s;
}
.search-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search-ico { color: var(--text-3); font-size: 16px; }
.search-box input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  color: var(--text);
}
.clear-btn {
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  display: none;
}
.clear-btn.show { display: block; }
.clear-btn:hover { color: var(--text); }

.topbar-meta { font-size: 13px; color: var(--text-3); white-space: nowrap; }

.content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px 60px;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
}

/* ===== 概览页 ===== */
.page-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: 0.3px;
}
.page-desc { color: var(--text-2); font-size: 14px; margin-bottom: 24px; }

.hero {
  background: linear-gradient(135deg, #2f6bff 0%, #4f8bff 100%);
  color: #fff;
  border-radius: 14px;
  padding: 26px 28px;
  margin-bottom: 28px;
}
.hero h2 { font-size: 19px; font-weight: 700; margin-bottom: 8px; }
.hero p { font-size: 14px; opacity: 0.92; line-height: 1.7; }

.matrix { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; margin-bottom: 28px; }
.matrix-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border 0.15s;
}
.matrix-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: #c9d6ff; }
.matrix-card .topic { font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.matrix-card .note { color: var(--text-2); font-size: 13px; margin-bottom: 10px; }
.matrix-card .chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-block;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 500;
}

/* ===== 章节卡片（概览网格） ===== */
.section-heading {
  font-size: 17px;
  font-weight: 700;
  margin: 28px 0 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}
.chapter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.chapter-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border 0.15s;
}
.chapter-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: #c9d6ff; }
.chapter-card .card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.chapter-card .num {
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
}
.chapter-card .title { font-size: 15px; font-weight: 700; }
.chapter-card .eng { font-size: 12px; color: var(--text-3); }
.chapter-card .one { font-size: 13px; color: var(--text-2); line-height: 1.6; }
.chapter-card .tags { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-size: 11px;
  background: var(--bg);
  color: var(--text-3);
  padding: 2px 8px;
  border-radius: 12px;
}

/* ===== 详情页 ===== */
.detail-head {
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 13.5px;
  cursor: pointer;
  padding: 4px 0;
  margin-bottom: 14px;
}
.back-btn:hover { text-decoration: underline; }
.detail-title-row { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.detail-title { font-size: 26px; font-weight: 700; }
.detail-eng { font-size: 15px; color: var(--text-3); }
.detail-meta { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.badge-cat { background: var(--primary); color: #fff; font-size: 12px; padding: 3px 12px; border-radius: 20px; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 6px; }

.one-liner {
  background: var(--primary-soft);
  border-left: 4px solid var(--primary);
  padding: 14px 18px;
  border-radius: 8px;
  margin-bottom: 24px;
  font-size: 15px;
  color: var(--text);
}
.one-liner .lbl { font-weight: 700; color: var(--primary); margin-right: 6px; }

.block { margin-bottom: 26px; }
.block-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.block-title::before {
  content: "";
  width: 4px;
  height: 18px;
  background: var(--primary);
  border-radius: 2px;
}

.list { list-style: none; }
.list li {
  position: relative;
  padding-left: 20px;
  margin-bottom: 8px;
  color: var(--text-2);
  font-size: 14px;
}
.list li::before {
  content: "▸";
  position: absolute;
  left: 4px;
  color: var(--primary);
}

.steps { counter-reset: step; list-style: none; }
.steps li {
  position: relative;
  padding-left: 34px;
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--text-2);
}
.steps li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 1px;
  width: 22px;
  height: 22px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 12px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 公式 */
.formula-list { display: flex; flex-direction: column; gap: 12px; }
.formula-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
}
.formula-item .fname { font-weight: 600; font-size: 13.5px; margin-bottom: 4px; }
.formula-item .fbody {
  font-family: "Cambria Math", "Times New Roman", "STIX Two Math", serif;
  font-size: 15px;
  color: var(--text);
  background: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  overflow-x: auto;
  white-space: nowrap;
}
.formula-item .fnote { font-size: 12.5px; color: var(--text-3); margin-top: 6px; }

/* 代码块 */
.code-block {
  background: var(--code-bg);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}
.code-block .code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.code-block .code-lang { font-size: 11px; color: #9aa4b2; letter-spacing: 0.5px; text-transform: uppercase; }
.copy-btn {
  border: none;
  background: rgba(255,255,255,0.1);
  color: #c9d4e0;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.copy-btn:hover { background: rgba(255,255,255,0.2); }
.copy-btn.copied { background: var(--green); color: #fff; }
.code-block pre {
  padding: 16px 18px;
  overflow-x: auto;
  margin: 0;
}
.code-block code {
  font-family: "SFMono-Regular", "Consolas", "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--code-text);
  white-space: pre;
}

/* 相关章节 */
.related-row { display: flex; flex-wrap: wrap; gap: 8px; }
.related-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--primary);
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s, border 0.15s;
}
.related-chip:hover { background: var(--primary-soft); border-color: #c9d6ff; }

/* 搜索结果 */
.search-result-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-3);
}
.search-result-empty .big { font-size: 40px; margin-bottom: 12px; }

/* 空状态 */
.empty { text-align: center; padding: 60px 20px; color: var(--text-3); }

/* 响应式 */
.mobile-toggle {
  display: none;
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 20;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  font-size: 20px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
}

.backdrop { display: none; }

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.25s;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 25; }
  .mobile-toggle { display: block; }
  .content { padding: 20px 16px 80px; }
  .matrix { grid-template-columns: 1fr; }
  .chapter-grid { grid-template-columns: 1fr; }
}

/* 滚动条 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #cdd2d9; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #b3bac3; }
::-webkit-scrollbar-track { background: transparent; }
