/* ═══════════════════════════════════════════════════════════════
   1. 变量（Variables）—— 浅色默认 + 深色覆盖
   ═══════════════════════════════════════════════════════════════ */
:root {
  --bg: #f7f9fc;
  --surface: #ffffff;
  --surface-soft: #eff6ff;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #dbeafe;
  --text: #0f172a;
  --text-muted: #475569;
  --border: #e2e8f0;

  --warning-bg: #fffbeb;
  --warning-accent: #d97706;
  --caution-bg: #fef2f2;
  --caution-accent: #dc2626;
  --ok-text: #166534;

  --code-bg: #f1f5f9;
  --code-text: #1e293b;
  --line-num: #94a3b8;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 16px rgba(37, 99, 235, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);

  --radius: 8px;
  --radius-lg: 16px;

  --text-base: 16px;
  --h3: 20px;
  --h2: 25px;
  --h1: 31px;
  --line-height: 1.7;

  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;

  --sidebar-w: 260px;
  --subnav-w: 220px;
  --reading-w: 720px;
  --header-h: 60px;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111a2e;
  --surface-soft: #1e293b;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-soft: #1e3a8a;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;

  --warning-bg: #451a03;
  --warning-accent: #fbbf24;
  --caution-bg: #450a0a;
  --caution-accent: #f87171;
  --ok-text: #4ade80;

  --code-bg: #0b1220;
  --code-text: #e2e8f0;
  --line-num: #475569;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
}

/* ═══════════════════════════════════════════════════════════════
   2. 基础（Base）
   ═══════════════════════════════════════════════════════════════ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 12px);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--line-height);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  color: var(--text);
  line-height: 1.35;
  margin: 0 0 0.5em;
  letter-spacing: -0.01em;
}

h1 {
  font-size: var(--h1);
  font-weight: 750;
}

h2 {
  font-size: var(--h2);
}

h3 {
  font-size: var(--h3);
  margin-top: 1.6em;
  scroll-margin-top: calc(var(--header-h) + 12px);
}

p {
  margin: 0 0 1em;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 150ms ease;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}

ul,
ol {
  padding-left: 1.4em;
  margin: 0 0 1em;
}

li {
  margin-bottom: 0.35em;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface-soft);
  color: var(--accent-hover);
  padding: 0.12em 0.4em;
  border-radius: 5px;
  white-space: nowrap;
}

[data-theme="dark"] code {
  color: var(--accent-hover);
}

button {
  font-family: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

img,
svg {
  vertical-align: middle;
}

/* ═══════════════════════════════════════════════════════════════
   3. 组件（Components）
   ═══════════════════════════════════════════════════════════════ */

/* —— 顶部进度条 —— */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #60a5fa);
  z-index: 1000;
  border-radius: 0 3px 3px 0;
  transition: width 80ms linear;
}

/* —— 页头 —— */
.site-header {
  position: sticky;
  top: 0;
  z-index: 900;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  height: var(--header-h);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  min-width: 0;
}

.site-logo:hover {
  color: var(--text);
  text-decoration: none;
}

.logo-mark {
  width: 28px;
  height: 28px;
  color: var(--accent);
  flex: none;
}

.site-title {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.site-sub {
  font-size: 12.5px;
  color: var(--text-muted);
  border-left: 1px solid var(--border);
  padding-left: 10px;
  white-space: nowrap;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius);
  transition: color 150ms ease, border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

.icon-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.icon-btn svg {
  width: 19px;
  height: 19px;
}

.drawer-toggle {
  display: none;
}

.icon-sun {
  display: none;
}

[data-theme="dark"] .icon-sun {
  display: block;
}

[data-theme="dark"] .icon-moon {
  display: none;
}

.gh-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 14px;
  transition: color 150ms ease, border-color 150ms ease;
}

.gh-link:hover {
  color: var(--accent);
  border-color: var(--accent);
  text-decoration: none;
}

.gh-link svg {
  width: 16px;
  height: 16px;
}

/* —— 三栏布局 —— */
.layout {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 20px 60px;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--subnav-w);
  gap: 40px;
  align-items: start;
}

/* —— 侧边栏目录 —— */
.sidebar {
  position: sticky;
  top: calc(var(--header-h) + 24px);
  max-height: calc(100vh - var(--header-h) - 48px);
  overflow-y: auto;
  padding-right: 4px;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.sidebar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 6px;
}

.sidebar-label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.sidebar-progress {
  font-size: 13px;
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 4px;
  background: var(--surface-soft);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 10px;
}

.progress-track span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #60a5fa);
  border-radius: 2px;
  transition: width 200ms ease;
}

.mark-all {
  width: 100%;
  padding: 6px 0;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--accent);
  background: var(--surface-soft);
  border: 1px dashed var(--accent-soft);
  border-radius: var(--radius);
  transition: background 150ms ease, border-color 150ms ease;
}

.mark-all:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.toc {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 14px;
}

.toc-item + .toc-item {
  margin-top: 4px;
}

.toc-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chapter-check {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  padding: 0;
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease, transform 150ms ease;
}

.chapter-check svg {
  width: 12px;
  height: 12px;
}

.chapter-check:hover {
  border-color: var(--accent);
}

.chapter-check[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.toc a {
  display: block;
  color: var(--text);
  padding: 5px 8px;
  border-radius: 6px;
  line-height: 1.45;
  transition: background 150ms ease, color 150ms ease;
  border-left: 2px solid transparent;
}

.toc a:hover {
  color: var(--accent);
  background: var(--surface-soft);
  text-decoration: none;
}

.toc a.active {
  color: var(--accent);
  background: var(--surface-soft);
  border-left-color: var(--accent);
  font-weight: 600;
}

.toc-sub {
  list-style: none;
  margin: 2px 0 6px 28px;
  padding: 0;
  border-left: 1px dashed var(--border);
  font-size: 13px;
}

.toc-sub a {
  padding: 3px 8px;
  color: var(--text-muted);
}

/* —— 内容列 —— */
.content {
  min-width: 0;
  max-width: var(--reading-w);
  width: 100%;
}

.doc-kicker {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
}

.doc-lead {
  font-size: 17px;
  color: var(--text-muted);
  margin: 6px 0 22px;
}

/* 元信息条 */
.meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 26px;
}

.meta-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface-soft);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius);
  padding: 10px 16px;
  min-width: 96px;
}

.meta-card .meta-label {
  font-size: 12px;
  color: var(--text-muted);
}

.meta-card strong {
  font-size: 15px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Learning outcomes */
.outcomes {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 44px;
  box-shadow: var(--shadow-sm);
}

.outcomes h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

.outcomes ul {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
}

.outcomes li {
  padding: 4px 0 4px 28px;
  position: relative;
}

.outcomes li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 4px;
  color: var(--accent);
  font-weight: 800;
}

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  border: none;
  transition: background 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

.btn svg {
  width: 17px;
  height: 17px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  color: #fff;
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-download {
  margin: 8px 0 24px;
}

/* —— 章节卡片 —— */
.chapter {
  margin-bottom: 20px;
  scroll-margin-top: calc(var(--header-h) + 12px);
}

.faq,
.resources {
  scroll-margin-top: calc(var(--header-h) + 12px);
}

.chapter-card {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  background: linear-gradient(135deg, #eff6ff 0%, var(--surface) 55%, #dbeafe 100%);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius-lg);
  padding: 26px 28px;
  margin-bottom: 22px;
  position: relative;
  overflow: hidden;
}

[data-theme="dark"] .chapter-card {
  background: linear-gradient(135deg, #1e3a8a 0%, #111a2e 55%, #111a2e 100%);
  border-color: #1e3a8a;
}

.chapter-num {
  font-size: 44px;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  opacity: 0.9;
}

.chapter-card h2 {
  margin: 0 0 6px;
  font-size: 24px;
}

.chapter-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 15px;
}

/* —— 代码块 —— */
.code-block {
  margin: 18px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--code-bg);
  box-shadow: var(--shadow-sm);
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 14px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 60%, transparent);
}

.code-lang {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #1d4ed8;
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 4px;
}

[data-theme="dark"] .code-lang {
  color: #93c5fd;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 5px;
  padding: 4px 8px;
  transition: color 150ms ease, background 150ms ease;
}

.copy-btn:hover {
  color: var(--accent);
  background: var(--surface-soft);
}

.copy-btn svg {
  width: 14px;
  height: 14px;
}

.copy-btn.copied {
  color: var(--ok-text);
}

.code-scroll {
  overflow-x: auto;
}

.code-body {
  display: flex;
  width: max-content;
  min-width: 100%;
}

/* 行号 gutter（JS 生成，sticky 左钉） */
.code-gutter {
  position: sticky;
  left: 0;
  flex: none;
  width: 2.6em;
  padding: 14px 0.8em 14px 0;
  margin-right: 0.9em;
  text-align: right;
  color: var(--line-num);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.65;
  background: var(--code-bg);
  border-right: 1px solid var(--border);
  user-select: none;
  -webkit-user-select: none;
  white-space: pre;
}

.code-scroll pre {
  margin: 0;
  padding: 14px 16px;
  background: transparent;
}

.code-scroll code {
  display: block;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.65;
  color: var(--code-text);
  background: transparent;
  white-space: pre;
}

/* 重点行高亮（JS 依据 data-highlight 注入背景条） */
.code-block code[data-lines-done] {
  background-clip: content-box;
}

/* highlight.js 兼容（浅色主题配色，深色下变量覆盖） */
.hljs {
  background: transparent !important;
  padding: 0 !important;
}

/* —— callout —— */
.callout {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 18px 0;
  border-left: 4px solid var(--accent);
  background: var(--surface-soft);
}

.callout strong {
  display: block;
  margin-bottom: 2px;
  font-size: 14px;
}

.callout p {
  margin: 0;
  font-size: 14.5px;
  color: var(--text);
}

.callout-icon {
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  color: var(--accent);
}

.callout-tip {
  border-left-color: var(--accent);
  background: var(--surface-soft);
}

.callout-tip .callout-icon {
  color: var(--accent);
}

.callout-warning {
  border-left-color: var(--warning-accent);
  background: var(--warning-bg);
}

.callout-warning .callout-icon {
  color: var(--warning-accent);
}

.callout-caution {
  border-left-color: var(--caution-accent);
  background: var(--caution-bg);
}

.callout-caution .callout-icon {
  color: var(--caution-accent);
}

/* —— 表格 —— */
.table-wrap {
  overflow-x: auto;
  margin: 18px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.table-wrap table {
  border-collapse: collapse;
  width: 100%;
  min-width: 480px;
  font-size: 14px;
}

.table-wrap caption {
  text-align: left;
  font-weight: 700;
  font-size: 13.5px;
  color: var(--text-muted);
  padding: 10px 14px 4px;
}

.table-wrap th {
  background: var(--surface-soft);
  color: var(--accent-hover);
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table-wrap td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table-wrap tbody tr:last-child td {
  border-bottom: none;
}

.table-wrap tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--surface-soft) 55%, transparent);
}

.table-wrap tbody tr {
  transition: background 150ms ease;
}

.table-wrap tbody tr:hover {
  background: var(--accent-soft);
}

.table-wrap td:first-child {
  font-weight: 600;
  white-space: nowrap;
}

.table-wrap code {
  background: transparent;
  padding: 0;
  font-size: 0.92em;
}

/* —— quiz —— */
.quiz {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px 18px;
  margin: 20px 0;
  box-shadow: var(--shadow-sm);
}

.quiz-question {
  font-weight: 700;
  margin-bottom: 12px;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quiz-options button {
  text-align: left;
  padding: 9px 14px;
  font-size: 14.5px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease;
}

.quiz-options button:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--surface-soft);
}

.quiz-options button:disabled {
  cursor: not-allowed;
}

.quiz-options button.correct {
  border-color: #16a34a;
  background: #f0fdf4;
  color: #166534;
}

[data-theme="dark"] .quiz-options button.correct {
  background: #052e16;
  color: #86efac;
}

.quiz-options button.wrong {
  border-color: var(--caution-accent);
  background: var(--caution-bg);
  color: #b91c1c;
}

[data-theme="dark"] .quiz-options button.wrong {
  color: var(--caution-accent);
}

.quiz-feedback {
  margin: 12px 0 0;
  font-size: 14px;
  min-height: 1.4em;
  font-weight: 600;
}

.quiz-feedback.ok {
  color: var(--ok-text);
}

.quiz-feedback.bad {
  color: #b91c1c;
}

[data-theme="dark"] .quiz-feedback.bad {
  color: var(--caution-accent);
}

.quiz-progress {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.quiz-reset {
  font-size: 12.5px;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 10px;
  transition: border-color 150ms ease, color 150ms ease;
}

.quiz-reset:hover {
  border-color: var(--accent);
}

.quiz-explanation {
  margin: 10px 0 0;
  padding: 10px 12px;
  background: var(--surface-soft);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 13.5px;
  color: var(--text);
}

/* —— 动手任务 —— */
.task {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 20px 0;
}

.task h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.task > p {
  font-size: 14.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.task-checks {
  list-style: none;
  padding: 0;
  margin: 0;
}

.task-checks li {
  position: relative;
  padding: 4px 0 4px 28px;
  font-size: 14.5px;
}

.task-checks li::before {
  content: "☐";
  position: absolute;
  left: 0;
  top: 4px;
  color: var(--accent);
  font-weight: 800;
}

/* —— 章末小结 —— */
.summary {
  background: var(--surface-soft);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 22px 0;
}

.summary h4 {
  margin: 0 0 8px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.summary ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.summary li {
  position: relative;
  padding: 3px 0 3px 22px;
  font-size: 14.5px;
}

.summary li::before {
  content: "→";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 700;
}

/* —— 右侧章内目录 —— */
.subnav {
  position: sticky;
  top: calc(var(--header-h) + 24px);
  font-size: 13px;
}

.subnav-label {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.subnav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--border);
}

.subnav li a {
  display: block;
  padding: 5px 12px;
  color: var(--text-muted);
  border-left: 2px solid transparent;
  margin-left: -1px;
  line-height: 1.45;
  transition: color 150ms ease, border-color 150ms ease;
}

.subnav li a:hover {
  color: var(--accent);
  text-decoration: none;
}

.subnav li a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* —— 翻页 —— */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 40px 0 24px;
}

.pager-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 14.5px;
  transition: border-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.pager-btn svg {
  width: 17px;
  height: 17px;
}

.pager-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
  transform: translateY(-1px);
}

.pager-btn[aria-disabled="true"] {
  opacity: 0.4;
  pointer-events: none;
}

.pager-mid {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* —— FAQ —— */
.faq {
  margin: 44px 0 36px;
}

.faq h2 {
  font-size: 22px;
  margin-bottom: 16px;
}

.faq-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 10px;
  overflow: hidden;
}

.faq-item summary {
  cursor: pointer;
  padding: 14px 18px;
  font-weight: 600;
  font-size: 15px;
  list-style: none;
  position: relative;
  padding-right: 40px;
  transition: background 150ms ease, color 150ms ease;
}

.faq-item summary::-webkit-details-marker {
  display: none;
}

.faq-item summary::after {
  content: "+";
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 20px;
  font-weight: 400;
  color: var(--accent);
  transition: transform 150ms ease;
}

.faq-item[open] summary {
  color: var(--accent);
  background: var(--surface-soft);
}

.faq-item[open] summary::after {
  transform: translateY(-50%) rotate(45deg);
}

.faq-item p {
  margin: 0;
  padding: 4px 18px 16px;
  font-size: 14.5px;
  color: var(--text);
}

/* —— 资源卡 —— */
.resources {
  margin-bottom: 44px;
}

.resources h2 {
  font-size: 22px;
  margin-bottom: 16px;
}

.resource-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}

.resource-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.resource-card:hover {
  border-color: var(--accent);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.resource-tag {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #1d4ed8;
  background: var(--accent-soft);
  align-self: flex-start;
  padding: 2px 8px;
  border-radius: 4px;
}

[data-theme="dark"] .resource-tag {
  color: #93c5fd;
}

.resource-card h3 {
  margin: 6px 0 0;
  font-size: 15.5px;
}

.resource-card p {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-muted);
}

/* —— 返回顶部 —— */
.back-to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--accent-soft);
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease, background 150ms ease;
  z-index: 950;
}

.back-to-top.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.back-to-top:hover {
  background: var(--accent-hover);
}

.back-to-top svg {
  width: 20px;
  height: 20px;
}

/* —— 抽屉 —— */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 940;
  opacity: 0;
  transition: opacity 200ms ease;
}

.drawer-backdrop.show {
  opacity: 1;
}

/* —— 页脚 —— */
.site-footer {
  background: var(--surface-soft);
  border-top: 1px solid var(--border);
  padding: 28px 20px;
}

.footer-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 24px;
}

.footer-brand {
  font-weight: 700;
  margin: 0;
}

.footer-logo {
  margin-right: 4px;
}

.footer-meta {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-muted);
}

.footer-meta code {
  background: transparent;
  padding: 0;
}

.footer-links {
  margin-left: auto;
  display: flex;
  gap: 18px;
  font-size: 14px;
}

/* ═══════════════════════════════════════════════════════════════
   4. 主题与响应式（Theme & Responsive）
   ═══════════════════════════════════════════════════════════════ */

/* 深色模式：对比度修正（详见 docs/contrast.md） */
[data-theme="dark"] .toc a.active,
[data-theme="dark"] .toc a:hover,
[data-theme="dark"] .subnav li a.active,
[data-theme="dark"] .subnav li a:hover,
[data-theme="dark"] .mark-all,
[data-theme="dark"] .faq-item[open] summary,
[data-theme="dark"] .sidebar-progress {
  color: var(--accent-hover);
}

/* 深色下白色文字填充元素改用更深的蓝底，保证白字对比度 */
[data-theme="dark"] .btn-primary,
[data-theme="dark"] .chapter-check[aria-pressed="true"],
[data-theme="dark"] .back-to-top {
  background: #2563eb;
  border-color: #2563eb;
}

[data-theme="dark"] .btn-primary:hover,
[data-theme="dark"] .back-to-top:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

/* 深色模式下 highlight.js 覆盖 */
[data-theme="dark"] .hljs {
  background: transparent;
}

[data-theme="dark"] .hljs-keyword,
[data-theme="dark"] .hljs-selector-tag,
[data-theme="dark"] .hljs-literal {
  color: #93c5fd;
}

[data-theme="dark"] .hljs-string,
[data-theme="dark"] .hljs-title,
[data-theme="dark"] .hljs-attribute,
[data-theme="dark"] .hljs-template-tag {
  color: #86efac;
}

[data-theme="dark"] .hljs-comment,
[data-theme="dark"] .hljs-quote {
  color: #64748b;
  font-style: italic;
}

[data-theme="dark"] .hljs-number {
  color: #fbbf24;
}

[data-theme="dark"] .hljs-built_in,
[data-theme="dark"] .hljs-class .hljs-title {
  color: #a5b4fc;
}

[data-theme="dark"] .hljs-meta {
  color: #c4b5fd;
}

/* 三档断点 */
@media (max-width: 1023px) {
  .layout {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }

  .subnav {
    display: none;
  }
}

@media (max-width: 767px) {
  :root {
    --h1: 26px;
  }

  .layout {
    display: block;
    padding: 20px 16px 48px;
  }

  .header-inner {
    padding: 0 14px;
  }

  .site-sub {
    display: none;
  }

  .gh-link span {
    display: none;
  }

  .gh-link {
    padding: 0 10px;
  }

  .drawer-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(320px, 88vw);
    max-height: none;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 16px 32px;
    z-index: 960;
    transform: translateX(-105%);
    transition: transform 250ms ease;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  body.drawer-open {
    overflow: hidden;
  }

  .content {
    max-width: 100%;
  }

  .chapter-card {
    padding: 20px 18px;
  }

  .chapter-num {
    font-size: 34px;
  }

  .pager-mid {
    display: none;
  }

  .pager {
    justify-content: space-between;
  }

  .code-scroll {
    -webkit-overflow-scrolling: touch;
  }

  .meta-bar {
    gap: 8px;
  }

  .meta-card {
    padding: 8px 12px;
    min-width: 0;
    flex: 1 1 42%;
  }

  .footer-links {
    margin-left: 0;
  }
}

/* 减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
