:root {
  --primary: #3b82f6;
  --primary-light: #1e3a5f;
  --primary-soft: #1e3a5f;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --accent: #f97316;
  --accent-light: #3d1f0a;
  --green: #10b981;
  --green-light: #0d2e1f;
  --purple: #8b5cf6;
  --purple-light: #2d1f4e;
  --radius: 10px;
  --max-width: 1152px;
}

[data-theme="light"] {
  --primary: #2563eb;
  --primary-light: #eff6ff;
  --primary-soft: #dbeafe;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --bg: #ffffff;
  --surface: #f8fafc;
  --border: #e2e8f0;
  --accent: #ea580c;
  --accent-light: #fff7ed;
  --green: #059669;
  --green-light: #ecfdf5;
  --purple: #7c3aed;
  --purple-light: #f5f3ff;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans CJK SC", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.85;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s, color 0.3s;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

header {
  padding: 80px 0 48px;
  text-align: center;
}

header h1 {
  font-size: 2.4em;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 12px;
}

header .subtitle {
  font-size: 1.1em;
  color: var(--text-muted);
  font-weight: 400;
  max-width: 640px;
  margin: 0 auto;
}

section {
  padding: 32px 0;
  border-bottom: 1px solid var(--border);
  transition: border-color 0.3s;
}

section:last-of-type { border-bottom: none; }

.closing {
  text-align: center;
  margin-top: 32px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

h2 {
  font-size: 1.5em;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}

h2 .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--primary);
  color: white;
  border-radius: 8px;
  font-size: 0.75em;
  font-weight: 700;
  flex-shrink: 0;
}

h2 code {
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 0.62em;
  background: var(--primary-light);
  color: var(--primary);
  padding: 4px 10px;
  border-radius: 6px;
  font-weight: 600;
}

h3 {
  font-size: 1.15em;
  font-weight: 700;
  margin: 24px 0 10px;
  color: var(--text);
}

p {
  margin-bottom: 14px;
  color: var(--text);
}

p.muted {
  color: var(--text-muted);
  font-size: 0.95em;
}

strong { color: var(--accent); font-weight: 700; }

/* em 用来标"学名"术语：强调色底纹胶囊 */
em {
  font-style: normal;
  background: var(--accent-light);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  color: var(--accent);
}

.container a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}
.container a:hover { text-decoration: underline; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin: 20px 0;
}

.card code, li code, p code {
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
}

.diagram-wrap {
  margin: 28px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.diagram-wrap .caption {
  font-size: 0.85em;
  color: var(--text-muted);
  margin-top: 10px;
}

/* ── 图表动画控制条 ── */
.anim-bar {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.anim-btn {
  font-family: inherit;
  font-size: 0.78em;
  padding: 4px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1.6;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}
.anim-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

canvas {
  display: block;
  max-width: 100%;
  margin: 0 auto;
}

ul {
  margin: 10px 0 16px 20px;
}

ul li {
  margin-bottom: 6px;
  color: var(--text);
}

ul.tight li { margin-bottom: 3px; }

/* ── 全文核心公式框 ── */
.formula-box {
  background: linear-gradient(135deg, var(--primary-light), var(--purple-light));
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  margin: 20px 0;
}

.formula-box p {
  font-size: 1.1em;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.04em;
}

.formula-box .big {
  font-size: 1.6em;
  font-weight: 800;
  color: var(--primary);
  display: block;
  margin-top: 8px;
}

footer {
  padding: 48px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9em;
}

/* ── 横向流程胶囊链 ── */
.flow-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
}

.flow-step {
  background: var(--primary-light);
  color: var(--primary);
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.9em;
  white-space: nowrap;
}

.arrow-sep {
  color: var(--text-muted);
  font-weight: 400;
}

/* ── 自问自答 / 读者质疑框 ── */
.callout {
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  padding: 14px 18px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 18px 0;
}

.callout p { margin: 0; }

.callout.blue {
  background: var(--primary-light);
  border-left-color: var(--primary);
}

.end-mark {
  text-align: center;
  font-size: 1.5em;
  color: var(--text-light);
  padding: 24px 0;
  letter-spacing: 0.3em;
}

.diagram-wrap, .callout, .card, .formula-box {
  transition: background-color 0.3s, border-color 0.3s;
}

/* ── 左上角 GitHub Logo 按钮（亮色用黑标，暗色用白标，随 data-theme 切换） ── */
.github-btn {
  position: fixed;
  top: 16px;
  left: 20px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden; /* logo 填满按钮，四角随圆形裁掉 */
  z-index: 100;
  transition: border-color 0.3s, background-color 0.3s;
}
.github-btn:hover { border-color: var(--primary); }
.github-btn .gh { display: none; width: 100%; height: 100%; }
[data-theme="light"] .gh-light { display: block; }
[data-theme="dark"] .gh-dark { display: block; }

/* ── 顶部固定控件（主题 + 语言切换） ── */
.top-controls {
  position: fixed;
  top: 16px;
  right: 20px;
  display: flex;
  gap: 8px;
  z-index: 100;
}
.theme-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1em;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s, border-color 0.3s, color 0.3s;
  line-height: 1;
  padding: 0;
}
.theme-btn:hover {
  border-color: var(--primary);
}
[data-theme="light"] .theme-btn[data-theme="light"],
[data-theme="dark"] .theme-btn[data-theme="dark"] {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.lang-btn {
  height: 36px;
  padding: 0 14px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8em;
  font-weight: 700;
  letter-spacing: 0.05em;
  transition: background 0.3s, border-color 0.3s, color 0.3s;
}
.lang-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

@media (max-width: 600px) {
  header { padding: 48px 0 32px; }
  header h1 { font-size: 1.8em; }
  section { padding: 24px 0; }
  .closing { margin-top: 24px; padding-top: 24px; }
  body { font-size: 16px; }
  h2 { font-size: 1.3em; }
}
