:root {
  --bg: #101512;
  --card: #151c18;
  --card-2: #1a231d;
  --line: #27332c;
  --text: #f3f4f6;
  --muted: #8f9d95;
  --accent: #5cb595;
  --blue: #60a5fa;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --purple: #a78bfa;
  --cyan: #22d3ee;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 10px 30px rgba(0,0,0,.32);
}
[data-theme="light"] {
  --bg: #f4f4f6;
  --card: #ffffff;
  --card-2: #efede8;
  --line: #e4e6e9;
  --text: #111827;
  --muted: #4b5563;
  --accent: #146b54;
  --blue: #2563eb;
  --green: #059669;
  --amber: #b45309;
  --red: #dc2626;
  --purple: #7c3aed;
  --cyan: #0891b2;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 10px 30px rgba(16,24,40,.07);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.7;
  display: flex; flex-direction: column; overflow: hidden;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
::selection { background: rgba(92,181,149,.32); }
code {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: .88em; background: var(--card-2); border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 6px; color: var(--text);
}

/* 滚动条 */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ===== 顶栏 ===== */
.topbar {
  height: 60px; flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: var(--card); border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(0,0,0,.08);
}
.menu-btn, .icon-btn {
  width: 38px; height: 38px; flex: none; border: 1px solid transparent; border-radius: 10px;
  background: transparent; color: var(--muted); cursor: pointer; font-size: 17px; line-height: 1;
  display: flex; align-items: center; justify-content: center; transition: .15s;
}
.menu-btn:hover, .icon-btn:hover { background: var(--card-2); color: var(--text); border-color: var(--line); }
.menu-btn svg, .icon-btn svg { width: 19px; height: 19px; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand .logo {
  width: 34px; height: 34px; flex: none; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  display: flex; align-items: center; justify-content: center; font-size: 17px; font-weight: 800; color: #fff;
  box-shadow: 0 3px 10px rgba(92,181,149,.35);
}
.brand .bt { display: flex; flex-direction: column; min-width: 0; }
.brand .bt b { font-size: 15px; line-height: 1.2; white-space: nowrap; }
.brand .bt span { font-size: 11px; color: var(--muted); white-space: nowrap; }
.spacer { flex: 1; }
.theme-btn svg { width: 18px; height: 18px; }
.theme-btn .ico-moon { display: none; }
[data-theme="light"] .theme-btn .ico-sun { display: none; }
[data-theme="light"] .theme-btn .ico-moon { display: block; }

/* ===== 布局：目录 + 内容 ===== */
.body { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 304px; flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--card); border-right: 1px solid var(--line);
}
.side-head {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 16px 16px 4px;
}
.side-comp { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 800; color: var(--text); }
.side-comp .comp-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(92,181,149,.18); }
.side-meta { font-size: 11px; color: var(--muted); }

.search-wrap { flex: none; padding: 14px 14px 10px; }
.search-box {
  display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; transition: .15s;
}
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(92,181,149,.18); }
.search-box input {
  flex: 1; min-width: 0; background: none; border: none; outline: none; color: var(--text); font-size: 13px;
}
.search-box input::placeholder { color: var(--muted); }
.search-box .s-ico { color: var(--muted); font-size: 14px; }
.side-tools { flex: none; display: flex; gap: 4px; padding: 0 14px 8px; }
.st-btn {
  width: 28px; height: 26px; flex: none; border: 1px solid var(--line); border-radius: 7px;
  background: var(--card-2); color: var(--muted); font-size: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; transition: .15s;
  padding: 0;
}
.st-btn:hover { color: var(--text); border-color: var(--accent); }
.st-btn svg { width: 15px; height: 15px; display: block; }
.nav { flex: 1; overflow-y: auto; padding: 4px 10px 18px; }

.tp { margin-bottom: 2px; }
.tp-head {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 9px 10px; cursor: pointer;
  background: none; border: none; color: var(--text); font-size: 13.5px; font-weight: 700;
  border-radius: 9px; text-align: left; transition: .12s;
}
.tp-head:hover { background: var(--card-2); }
.tp-head .tp-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp-head .tp-count {
  font-size: 11px; color: var(--muted); background: var(--card-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 0 8px; line-height: 17px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.tp-head .tp-arrow { font-size: 11px; color: var(--muted); transition: transform .15s; }
.tp.closed .tp-arrow { transform: rotate(-90deg); }
.tp.closed .tp-items { display: none; }
.tp-items { display: flex; flex-direction: column; padding: 1px 0 7px; }
.tp-item {
  position: relative; display: flex; align-items: center; gap: 6px; padding: 7px 12px 7px 24px;
  border-radius: 8px; font-size: 13px; color: var(--muted); transition: .12s;
}
.tp-item .tp-t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tp-item .tp-done { display: none; color: var(--accent); font-weight: 800; font-size: 12px; flex: none; }
.tp-item.done .tp-done { display: inline; }
.tp-item::before {
  content: ''; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px;
  border-radius: 3px; background: transparent; transition: .12s;
}
.tp-item:hover { background: var(--card-2); color: var(--text); }
.tp-item.active { background: rgba(92,181,149,.15); color: var(--text); font-weight: 600; }
.tp-item.active::before { background: var(--accent); }
.empty { display: none; padding: 24px 16px; text-align: center; color: var(--muted); font-size: 13px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.content { flex: 1; overflow-y: auto; padding: 4px 32px 40px; }

/* ===== 主题块 ===== */
section.topic { padding: 0; max-width: 1080px; margin-left: auto; margin-right: auto; }
section.topic:first-of-type { padding-top: 0; }
.topic-head { display: none; }
.topic-head h2 { margin: 0 0 5px; font-size: 1.75rem; line-height: 1.3; color: var(--text); letter-spacing: -0.02em; font-weight: 700; }
.topic-head p { color: var(--muted); margin: 0; font-size: 14.5px; }

/* ===== 知识点卡片 ===== */
article.pt { display: none; }
article.pt.active { display: block; padding: 10px 2px 24px; }
.pt-title { margin: 0 0 8px; font-size: 1.62rem; line-height: 1.35; color: var(--text); letter-spacing: -0.01em; font-weight: 700; }
.pt-sub { color: var(--muted); margin: 0 0 22px; font-size: 14.5px; }

/* 知识点内的步骤（扁平，不分卡片） */
article.pt > section { background: none; border: none; border-radius: 0; padding: 0; margin: 0 0 18px; }
article.pt > section + section { border-top: 1px dashed var(--line); padding-top: 18px; }
article.pt > section > h2 { margin: 0 0 6px; font-size: 1.08rem; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
article.pt > section > h2 .num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 8px; background: var(--accent);
  color: #fff; font-size: 12.5px; flex: none; font-weight: 700;
}
article.pt > section > h2 .num.g { background: var(--purple); }
article.pt > section > h2 .num.a { background: var(--amber); color: #1a1205; }
article.pt > section > h2 .num.r { background: var(--red); }
article.pt > section .sub { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }

/* ===== 内容组件 ===== */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; margin: 2px 3px; }
.badge.red { background: rgba(248,113,113,.15); color: var(--red); }
.badge.star { background: rgba(251,191,36,.15); color: var(--amber); }

.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.legend span {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px;
  background: var(--card-2); border: 1px solid var(--line); font-size: 12.5px; color: var(--muted);
}
.lg-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.lg-box { display: inline-block; width: 11px; height: 11px; border-radius: 3px; }

.casetable { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 14px; }
.casetable th, .casetable td { padding: 8px 11px; border: 1px solid var(--line); text-align: left; }
.casetable th { background: var(--card-2); color: var(--text); font-weight: 600; }
.casetable td { color: var(--muted); }
.casetable tbody tr:nth-child(even) td { background: rgba(255,255,255,.018); }
[data-theme="light"] .casetable tbody tr:nth-child(even) td { background: rgba(16,24,40,.02); }
.casetable td b { color: var(--text); }
.c-blue { color: var(--blue); font-weight: 600; }
.c-green { color: var(--green); font-weight: 600; }
.c-purple { color: var(--purple); font-weight: 600; }
.c-amber { color: var(--amber); font-weight: 600; }
.c-gray { color: var(--muted); }
.c-red { color: var(--red); font-weight: 600; }
.tag-row { font-size: 12px; color: var(--muted); margin-bottom: 6px; }

.steps { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
@media (max-width: 860px) { .steps { grid-template-columns: 1fr; } }
.step { background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.step .step-title { font-size: 13px; font-weight: 700; color: var(--accent); margin-bottom: 9px; display: flex; align-items: center; gap: 6px; }
.step .step-title .tag { background: var(--accent); color: #fff; font-size: 11px; padding: 1px 8px; border-radius: 999px; font-weight: 600; }
.step .step-title .tag.g { background: var(--green); }
.step .step-title .tag.a { background: var(--amber); color: #1a1205; }
.step .step-title .tag.p { background: var(--purple); }
.step .step-title .tag.r { background: var(--red); }
.step svg { display: block; width: 100%; height: auto; }
.step .note { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

.fig { background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 18px; overflow-x: auto; margin-bottom: 14px; }
.fig svg { display: block; width: 100%; height: auto; min-width: 560px; }
.fig .cap { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.fig .fbox { fill: rgba(92,181,149,.10); stroke: var(--accent); stroke-width: 1.5; }
.fig .ft { fill: var(--text); font-size: 12.5px; font-weight: 700; }
.fig .fs { fill: var(--muted); font-size: 10.5px; }
.fig .fline { stroke: var(--accent); stroke-width: 2; }
.fig .fm { fill: var(--accent); }

.output {
  background: #0b101b; border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; font-family: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12.5px; color: #c9d4ee; white-space: pre-wrap; margin: 0 0 14px; line-height: 1.7;
}
.o-blue { color: var(--blue); }
.o-green { color: var(--green); }
.o-amber { color: var(--amber); }
.o-red { color: var(--red); }
.o-muted { color: var(--muted); }

.explain { font-size: 14.5px; margin-bottom: 12px; }
.explain b { color: var(--text); }
.explain .key { color: var(--accent); font-weight: 600; }
ul.points { margin: 0 0 12px; padding-left: 20px; }
ul.points li { margin-bottom: 6px; font-size: 14.5px; color: var(--text); }
ul.points li b { color: var(--accent); }

pre {
  background: #0b101b; border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; overflow-x: auto; font-size: 13px; line-height: 1.7; tab-size: 2;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace; color: #c9d4ee; margin: 0 0 14px;
  position: relative;
}
pre .c { color: #7d8f84; }
pre .kw { color: #a78bfa; }
pre .fn { color: #22d3ee; }
pre .str { color: #34d399; }
pre .num { color: #fbbf24; }
pre .type { color: #22d3ee; }
pre .anno { color: #fb923c; }
pre[data-lang] { padding-top: 36px; }
pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute; top: 8px; right: 12px;
  font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  color: var(--muted); background: rgba(255,255,255,.05);
  border: 1px solid var(--line); border-radius: 6px; padding: 1px 8px;
}

.talk {
  background: rgba(52,211,153,.07); border: 1px solid rgba(52,211,153,.35);
  border-radius: 10px; padding: 12px 16px; font-size: 14px; margin-top: 14px;
}
.talk b { color: var(--green); }

/* ===== 底部翻页 ===== */
.footnav {
  flex: none; display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--card); border-top: 1px solid var(--line);
}
.fn {
  flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card-2);
  cursor: pointer; text-align: left; transition: .15s; max-width: 100%;
}
.fn:hover { border-color: var(--accent); background: var(--card-2); transform: translateY(-1px); }
.fn.disabled { opacity: .35; pointer-events: none; }
.fn .fn-label { font-size: 11px; color: var(--muted); }
.fn .fn-name { font-size: 12.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fn.prev { text-align: right; align-items: flex-end; }
.fn.next { align-items: flex-start; }
.pos { flex: none; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 13px; }

/* ===== 浅色主题下 SVG 内嵌颜色修正 ===== */
[data-theme="light"] svg [fill="#e6ecf7"] { fill: #1f2937; }
[data-theme="light"] svg [fill="#8b98b8"] { fill: #5b6472; }
[data-theme="light"] svg [fill="#5b6b8c"] { fill: #6b7280; }
[data-theme="light"] svg [fill="#c9d4ee"] { fill: #1f2937; }
[data-theme="light"] svg [fill="#34d399"] { fill: #059669; }
[data-theme="light"] svg [fill="#4c8dff"] { fill: #2563eb; }
[data-theme="light"] svg [fill="#fbbf24"] { fill: #b45309; }
[data-theme="light"] svg [fill="#f87171"] { fill: #dc2626; }
[data-theme="light"] svg [fill="#a78bfa"] { fill: #7c3aed; }
[data-theme="light"] svg [fill="#22d3ee"] { fill: #0891b2; }
[data-theme="light"] svg [stroke="#33406a"] { stroke: #cbd5e1; }
[data-theme="light"] svg [stroke="#8b98b8"] { stroke: #9ca3af; }
[data-theme="light"] svg [stroke="#2a3550"] { stroke: #d1d5db; }
[data-theme="light"] svg [stroke="#34d399"] { stroke: #059669; }
[data-theme="light"] svg [stroke="#4c8dff"] { stroke: #2563eb; }
[data-theme="light"] svg [stroke="#fbbf24"] { stroke: #b45309; }
[data-theme="light"] svg [stroke="#a78bfa"] { stroke: #7c3aed; }
[data-theme="light"] svg [stroke="#f87171"] { stroke: #dc2626; }

/* ===== 响应式 ===== */
@media (max-width: 860px) {
  .sidebar {
    position: absolute; top: 60px; bottom: 0; left: 0; z-index: 40;
    transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: 8px 0 30px rgba(0,0,0,.45); width: 300px;
  }
  body.sb-open .sidebar { transform: translateX(0); }
  .brand .bt span { display: none; }
  .content { padding: 8px 16px 40px; }
  article.pt { padding: 20px 18px; border-radius: 14px; }
}
@media (min-width: 861px) {
  body.sb-hidden .sidebar { display: none; }
}


/* 顶部进度 */
.prog { display: flex; align-items: center; gap: 8px; }
.prog-text { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.prog-bar { width: 96px; height: 6px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); overflow: hidden; }
.prog-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--green)); border-radius: 999px; transition: width .25s; }

/* 面包屑 */
.crumb {
  flex: none; display: flex; align-items: center; gap: 8px; width: 100%; max-width: 1080px;
  margin: 0 auto; padding: 12px 32px 0; min-width: 0;
}
.crumb .crumb-topic { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.crumb .crumb-sep { color: var(--muted); font-size: 12.5px; }
.crumb .crumb-title { color: var(--text); font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb .crumb-pos { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* 学会了按钮 */
.learned-btn {
  flex: none; min-width: 150px; height: 44px; border: 1px solid var(--accent); border-radius: 12px;
  background: rgba(92,181,149,.12); color: var(--accent); cursor: pointer; font-size: 14.5px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 8px; transition: .15s; padding: 0 18px;
}
.learned-btn:hover { background: rgba(92,181,149,.2); }
.learned-btn .face { display: flex; align-items: center; gap: 8px; }
.learned-btn .face-undo { display: none; }
.learned-btn.is-learned { background: var(--card-2); border-color: var(--line); color: var(--muted); font-weight: 600; }
.learned-btn.is-learned .face-main { display: none; }
.learned-btn.is-learned .face-undo { display: flex; }
.learned-btn .lb-check {
  width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: #06281c;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800;
}
.star-btn {
  flex: none; height: 44px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card-2); color: var(--muted); cursor: pointer; font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 6px; transition: .15s; padding: 0 14px;
}
.star-btn:hover { color: var(--amber); border-color: var(--amber); }
.star-btn .face-undo { display: none; }
.star-btn.is-starred { background: rgba(251,191,36,.12); border-color: var(--amber); color: var(--amber); }
.star-btn.is-starred .face-main { display: none; }
.star-btn.is-starred .face-undo { display: flex; }
.tp-item.starred::after {
  content: '★'; position: absolute; right: 10px; color: var(--amber); font-size: 11px;
}

/* ===== 组件分组（3 级目录：组件 → 主题 → 知识点） ===== */
.cg { margin-bottom: 4px; }
.cg-head {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 9px 10px; cursor: pointer;
  background: none; border: none; color: var(--text); font-size: 14px; font-weight: 800;
  border-radius: 9px; text-align: left; transition: .12s;
}
.cg-head:hover { background: var(--card-2); }
.cg-head .cg-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; box-shadow: 0 0 0 3px rgba(92,181,149,.15); }
.cg-head .cg-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cg-head .cg-count { font-size: 11px; color: var(--muted); background: var(--card-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; line-height: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.cg-head .cg-arrow { font-size: 11px; color: var(--muted); transition: transform .15s; }
.cg.closed .cg-arrow { transform: rotate(-90deg); }
.cg.closed .cg-body { display: none; }
.cg-body { padding-left: 8px; }
.crumb .crumb-comp { color: var(--muted); font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.cat { margin-bottom: 6px; }
.cat-head {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer;
  background: none; border: none; color: var(--muted); font-size: 12px; font-weight: 700;
  letter-spacing: 1px; text-align: left; transition: .12s; text-transform: uppercase;
}
.cat-head:hover { color: var(--text); }
.cat-head .cat-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-head .cat-arrow { font-size: 11px; color: var(--muted); transition: transform .15s; }
.cat.closed .cat-arrow { transform: rotate(-90deg); }
.cat.closed .cat-body { display: none; }
