/* ===== AI Agent 课程 · 学习版样式 ===== */
:root {
  --fs: 17px;
  --bg: #faf9f7;
  --bg-soft: #f1efeb;
  --panel: #ffffff;
  --ink: #2b2b33;
  --ink-soft: #6b6b76;
  --line: #e4e1da;
  --accent: #3b5bdb;
  --accent-soft: #eef1fc;
  --mark: #b8860b;
  --code-bg: #f4f2ee;
  --code-ink: #40404a;
  --quote-bg: #f6f4ef;
  --quote-bar: #c9b98a;
  --table-head: #f3f1ec;
  --table-stripe: #faf8f4;
  --shadow: 0 1px 3px rgba(30, 30, 40, .07);
  --hl-comment: #8a8a94; --hl-kw: #a626a4; --hl-str: #50a14f; --hl-num: #986801;
  --hl-title: #4078f2; --hl-attr: #e45649; --hl-built: #c18401;
}
:root[data-theme="dark"] {
  --bg: #15171c;
  --bg-soft: #1b1e24;
  --panel: #1d2026;
  --ink: #d6d6dc;
  --ink-soft: #8f8f9a;
  --line: #2c2f37;
  --accent: #7b96f0;
  --accent-soft: #232a3d;
  --mark: #d4a843;
  --code-bg: #22252c;
  --code-ink: #c8c8d0;
  --quote-bg: #1e2128;
  --quote-bar: #7a6a3f;
  --table-head: #22252c;
  --table-stripe: #1a1d23;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  --hl-comment: #7d8799; --hl-kw: #c678dd; --hl-str: #98c379; --hl-num: #d19a66;
  --hl-title: #61afef; --hl-attr: #e06c75; --hl-built: #e5c07b;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: var(--fs);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  line-height: 1.9;
  -webkit-font-smoothing: antialiased;
}

/* ---- top bar ---- */
#progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: var(--accent); z-index: 60; transition: width .1s linear;
}
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 10px;
  height: 52px; padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--ink); text-decoration: none; white-space: nowrap; }
.topbar-title {
  color: var(--ink-soft); font-size: .85em; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.topbar-spacer { flex: 1; }
.icon-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; min-width: 34px; height: 32px; padding: 0 8px;
  cursor: pointer; font-size: 14px; line-height: 1;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
#menu-btn { display: none; }

/* ---- layout ---- */
.layout { display: flex; max-width: 1200px; margin: 0 auto; }
#sidebar {
  width: 280px; flex: none;
  position: sticky; top: 52px; height: calc(100vh - 52px);
  overflow-y: auto; padding: 20px 8px 40px 16px;
  border-right: 1px solid var(--line);
  font-size: .82em; line-height: 1.6;
  scrollbar-width: thin;
}
.sidebar-label {
  font-weight: 700; color: var(--ink-soft); letter-spacing: .1em;
  font-size: .85em; margin: 4px 0 10px 4px;
}
.toc, .toc ul { list-style: none; margin: 0; padding: 0; }
.toc ul { margin: 2px 0 6px 0; padding-left: 14px; border-left: 1px solid var(--line); }
.toc a {
  display: block; padding: 4px 8px; border-radius: 6px;
  color: var(--ink-soft); text-decoration: none;
}
.toc a:hover { color: var(--accent); background: var(--accent-soft); }
.toc a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.allbook { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 12px; }
.allbook summary {
  cursor: pointer; font-weight: 700; color: var(--ink-soft);
  letter-spacing: .1em; font-size: .85em; padding-left: 4px;
}
.book-nav { list-style: none; margin: 10px 0 0; padding: 0; }
.book-nav a {
  display: block; padding: 5px 8px; border-radius: 6px;
  color: var(--ink-soft); text-decoration: none;
}
.book-nav a:hover { color: var(--accent); background: var(--accent-soft); }
.book-nav .current a { color: var(--accent); font-weight: 600; }
.bn-kicker { display: inline-block; min-width: 4.2em; color: var(--ink-soft); font-size: .9em; }

.main { flex: 1; min-width: 0; }
.content {
  max-width: 780px; margin: 0 auto; padding: 32px 28px 60px;
  text-align: justify;
}

/* ---- typography ---- */
.page-meta {
  display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center;
  color: var(--ink-soft); font-size: .82em; margin-bottom: 4px;
}
.page-meta .kicker {
  color: var(--accent); font-weight: 700; letter-spacing: .15em;
  border: 1px solid var(--accent); border-radius: 999px; padding: 0 12px;
}
h1 { font-size: 1.9em; line-height: 1.4; margin: .5em 0 .8em; letter-spacing: .01em; }
h2 {
  font-size: 1.45em; line-height: 1.5; margin: 2.2em 0 .8em;
  padding-bottom: .35em; border-bottom: 1px solid var(--line);
}
h3 { font-size: 1.18em; margin: 1.8em 0 .6em; }
h4 { font-size: 1.02em; margin: 1.5em 0 .5em; }
.secnum { color: var(--accent); font-weight: 800; margin-right: .35em; }
.hanchor {
  margin-left: .4em; color: var(--line); text-decoration: none;
  opacity: 0; transition: opacity .15s; font-weight: 400;
}
h1:hover .hanchor, h2:hover .hanchor, h3:hover .hanchor, h4:hover .hanchor { opacity: 1; }
.hanchor:hover { color: var(--accent); }
h2 code, h3 code {
  font-size: .62em; vertical-align: .2em; background: var(--accent-soft);
  color: var(--accent); border: none; padding: 2px 8px; border-radius: 999px;
}
p { margin: 1em 0; }
a { color: var(--accent); }
strong { color: color-mix(in srgb, var(--ink) 80%, var(--accent)); }
li { margin: .35em 0; }
ul, ol { padding-left: 1.6em; }
hr { border: none; border-top: 1px solid var(--line); margin: 2.5em 0; }
::selection { background: color-mix(in srgb, var(--accent) 25%, transparent); }

sup a { text-decoration: none; font-weight: 600; padding: 0 2px; }

/* ---- inline & block code ---- */
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "JetBrains Mono",
    "Cascadia Code", monospace;
  font-size: .86em;
  background: var(--code-bg); color: var(--code-ink);
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px;
}
.codeblock { position: relative; margin: 1.2em 0; }
.code-lang {
  position: absolute; top: 8px; right: 12px;
  font-size: .72em; color: var(--ink-soft); text-transform: uppercase;
  letter-spacing: .08em; user-select: none;
}
.codeblock pre {
  margin: 0; background: var(--code-bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 16px; overflow-x: auto;
  line-height: 1.65; text-align: left;
}
.codeblock pre code { background: none; border: none; padding: 0; font-size: .85em; }
.hljs-comment, .hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal { color: var(--hl-kw); }
.hljs-string, .hljs-regexp { color: var(--hl-str); }
.hljs-number, .hljs-meta { color: var(--hl-num); }
.hljs-title, .hljs-name, .hljs-section { color: var(--hl-title); }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable { color: var(--hl-attr); }
.hljs-built_in, .hljs-type, .hljs-params { color: var(--hl-built); }

/* ---- callouts (blockquotes) ---- */
blockquote {
  margin: 1.4em 0; padding: 10px 20px;
  background: var(--quote-bg);
  border-left: 4px solid var(--quote-bar);
  border-radius: 0 10px 10px 0;
  color: color-mix(in srgb, var(--ink) 90%, var(--ink-soft));
}
blockquote > p:first-child > strong:first-child { color: var(--mark); }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; margin: 1.4em 0; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: .88em; line-height: 1.7; }
th, td { padding: 9px 13px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
td:not(:last-child), th:not(:last-child) { border-right: 1px solid var(--line); }
thead th { background: var(--table-head); font-weight: 700; white-space: nowrap; position: sticky; top: 0; }
tbody tr:nth-child(even) { background: var(--table-stripe); }
tbody tr:last-child td { border-bottom: none; }

/* ---- figures ---- */
.fig { margin: 1.6em 0; text-align: center; }
.fig img {
  max-width: 100%; height: auto;
  background: #ffffff; /* 插图按白底设计，深色模式下保持可读 */
  border: 1px solid var(--line); border-radius: 12px;
  padding: 8px; box-shadow: var(--shadow);
}
.fig-frame {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  border: 1.5px dashed var(--line); border-radius: 12px;
  background: var(--bg-soft); color: var(--ink-soft);
  padding: 26px 16px; font-size: .85em;
}
.fig-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.fig figcaption { margin-top: .5em; color: var(--ink-soft); font-size: .85em; }

/* ---- math ---- */
.math-display { display: block; text-align: center; margin: 1.2em 0; overflow-x: auto; }
math { font-size: 1.08em; }

/* ---- footnotes ---- */
.footnotes { margin-top: 3em; border-top: 1px solid var(--line); font-size: .85em; color: var(--ink-soft); }
.footnotes-title { font-size: 1.1em; border: none; margin-top: 1.2em; }
.footnotes p { margin: .3em 0; }

/* ---- answers link ---- */
.answers-link { margin: .8em 0 1.2em; }
.answers-link a {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  padding: 6px 16px; border-radius: 999px; text-decoration: none; font-size: .9em;
}
.answers-link a:hover { filter: brightness(1.05); }

/* ---- pager ---- */
.pager {
  max-width: 780px; margin: 0 auto; padding: 0 28px 70px;
  display: flex; gap: 12px; align-items: stretch; justify-content: space-between;
}
.pager a {
  flex: 1; max-width: 44%; text-decoration: none;
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px;
  background: var(--panel); box-shadow: var(--shadow);
  color: var(--ink-soft); font-size: .82em; line-height: 1.6;
}
.pager a b { display: block; color: var(--ink); font-size: 1.05em; margin-top: 2px; }
.pager a:hover { border-color: var(--accent); }
.pager a:hover b { color: var(--accent); }
.pager-next { text-align: right; }
.mark-read {
  align-self: center; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--ink-soft); padding: 8px 16px;
  cursor: pointer; font-size: .82em; white-space: nowrap;
}
.mark-read.done { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* ---- index page ---- */
.index { max-width: 900px; }
.hero { text-align: center; padding: 30px 0 10px; }
.hero h1 { font-size: 2.2em; margin-bottom: .2em; }
.hero-formula {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  color: var(--accent); font-size: 1.05em; letter-spacing: .05em; margin: .2em 0 1em;
}
.hero-sub { color: var(--ink-soft); max-width: 620px; margin: 0 auto; font-size: .92em; text-align: center; }
.hero-progress { color: var(--mark); font-size: .85em; min-height: 1.5em; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-top: 26px; }
.card {
  display: flex; flex-direction: column; gap: 6px; text-decoration: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px 18px 14px; color: var(--ink);
  box-shadow: var(--shadow); transition: transform .12s, border-color .12s;
  text-align: left;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card-kicker {
  display: flex; justify-content: space-between; align-items: center;
  color: var(--accent); font-weight: 700; font-size: .78em; letter-spacing: .12em;
}
.read-badge {
  display: none; color: var(--mark); border: 1px solid var(--mark);
  border-radius: 999px; padding: 0 8px; letter-spacing: 0; font-weight: 600;
}
.card.is-read .read-badge { display: inline-block; }
.card.is-read { opacity: .82; }
.card-title { font-weight: 700; font-size: 1.06em; line-height: 1.5; }
.card-excerpt {
  margin: 0; color: var(--ink-soft); font-size: .82em; line-height: 1.75;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { margin-top: auto; padding-top: 8px; color: var(--ink-soft); font-size: .75em; }

/* ---- back to top ---- */
#totop {
  position: fixed; right: 22px; bottom: 26px; width: 42px; height: 42px;
  border-radius: 50%; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink-soft); font-size: 18px; cursor: pointer; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40;
}
#totop.show { opacity: 1; pointer-events: auto; }
#totop:hover { color: var(--accent); border-color: var(--accent); }

/* ---- anchors under sticky bar ---- */
h1[id], h2[id], h3[id], h4[id] { scroll-margin-top: 70px; }

/* ---- responsive ---- */
@media (max-width: 960px) {
  #menu-btn { display: block; }
  #sidebar {
    position: fixed; left: 0; top: 52px; bottom: 0; height: auto;
    background: var(--bg); z-index: 55; width: 300px; max-width: 85vw;
    transform: translateX(-102%); transition: transform .2s ease;
    border-right: 1px solid var(--line); box-shadow: var(--shadow);
  }
  body.sidebar-open #sidebar { transform: none; }
  #overlay {
    display: none; position: fixed; inset: 52px 0 0 0;
    background: rgba(0, 0, 0, .35); z-index: 54;
  }
  body.sidebar-open #overlay { display: block; }
  .content { padding: 24px 18px 50px; }
  .pager { flex-wrap: wrap; padding: 0 18px 60px; }
  .pager a { max-width: none; min-width: 45%; }
  .topbar-title { display: none; }
}

/* ---- print ---- */
@media print {
  .topbar, #sidebar, #overlay, .pager, #totop, #progress, .hanchor, .answers-link { display: none !important; }
  body { background: #fff; color: #000; }
  .content { max-width: none; padding: 0; }
  .codeblock pre { border: 1px solid #ccc; }
}
