:root {
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --panel: #ffffff;
  --text: #18181b;
  --text-2: #71717a;
  --text-3: #a1a1aa;
  --border: #e4e4e7;
  --code-bg: #fafafa;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, .08);
  --radius: 12px;
  --header-h: 56px;
}

html.dark {
  --bg: #09090b;
  --bg-soft: #111113;
  --panel: #0f0f11;
  --text: #fafafa;
  --text-2: #a1a1aa;
  --text-3: #71717a;
  --border: #27272a;
  --code-bg: #131316;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, .5);
}

/* 七个阶段的主题色 */
.c-blue      { --c: #3b82f6; }
.c-emerald   { --c: #10b981; }
.c-purple    { --c: #a855f7; }
.c-amber     { --c: #f59e0b; }
.c-fuchsia   { --c: #ec4899; }

.c-cyan      { --c: #06b6d4; }
.c-red       { --c: #ef4444; }

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

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

a { color: inherit; text-decoration: none; }

code, pre, .mono {
  font-family: "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono",
    Menlo, monospace;
}

/* ---------------- header ---------------- */
.hdr {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
}

.hdr-in {
  max-width: 1280px;
  margin: 0 auto;
  height: 100%;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: flex; align-items: baseline; gap: 10px; font-weight: 700; font-size: 17px; white-space: nowrap; min-width: 0; }

.brand span { font-weight: 400; font-size: 12px; color: var(--text-3); }

.nav { display: flex; align-items: center; gap: 4px; }

.nav a {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  transition: background .15s, color .15s;
}

.nav a:hover { background: var(--bg-soft); color: var(--text); }
.nav a.on { background: var(--text); color: var(--bg); }

/* 图标按钮：同时用于 <button>（主题切换）和 <a>（GitHub 入口），
   因此要用 .nav 前缀提权，压掉 .nav a 的 padding。 */
.icon-btn,
.nav a.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  font-size: 15px;
  font-family: inherit;
  transition: background .15s, color .15s, border-color .15s;
}

.icon-btn:hover,
.nav a.icon-btn:hover {
  background: var(--bg-soft);
  color: var(--text);
  border-color: var(--text-3);
}

.icon-btn svg { display: block; }


/* ---------------- layout ---------------- */
.wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 24px 96px;
  display: flex;
  gap: 40px;
}

.side { width: 232px; flex: 0 0 232px; }

.side-in {
  position: sticky;
  top: calc(var(--header-h) + 32px);
  max-height: calc(100vh - var(--header-h) - 64px);
  overflow-y: auto;
  padding-right: 4px;
}

.side-in::-webkit-scrollbar { width: 4px; }
.side-in::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.grp { margin-bottom: 22px; }

.grp-h {
  display: flex;
  align-items: center;
  gap: 7px;
  padding-bottom: 7px;
}

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: 0 0 auto; }
.dot-lg { width: 11px; height: 11px; }

.grp-h b {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-3);
}

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

.grp li a {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 13.5px;
  color: var(--text-2);
  transition: background .15s, color .15s;
}

.grp li a:hover { background: var(--bg-soft); color: var(--text); }
.grp li a.on { background: var(--bg-soft); color: var(--text); font-weight: 600; }
.grp li a i { font-style: normal; font-size: 11px; font-family: var(--mono); color: var(--text-3); }
.grp li a.on i { color: var(--c); }

.main { flex: 1 1 auto; min-width: 0; }

/* ---------------- page head ---------------- */
.ph { margin-bottom: 32px; }
.ph h1 { margin: 0; font-size: 30px; line-height: 1.25; letter-spacing: -.02em; }
.ph p { margin: 8px 0 0; color: var(--text-2); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding: 14px 16px;
  margin-bottom: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
}

.legend h3 {
  width: 100%;
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.legend div { display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 500; }
.legend em { font-style: normal; color: var(--text-3); font-weight: 400; }

/* ---------------- timeline ---------------- */
.tl { position: relative; }

.row { display: flex; gap: 20px; padding-bottom: 28px; }

.rail { display: flex; flex-direction: column; align-items: center; flex: 0 0 40px; }

.node {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--c);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 0 0 4px var(--bg);
  transition: transform .18s;
}

.row:hover .node { transform: scale(1.08); }

.line { width: 2px; flex: 1 1 auto; margin-top: 4px; background: color-mix(in srgb, var(--c) 28%, transparent); }

.row:last-child .line { display: none; }

.card {
  flex: 1 1 auto;
  min-width: 0;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  cursor: pointer;
  opacity: 0;
  transform: translateX(24px);
  transition: border-color .18s, box-shadow .18s, transform .18s;
}

.card.in { opacity: 1; transform: none; }

.card:hover {
  border-color: color-mix(in srgb, var(--c) 55%, var(--border));
  box-shadow: var(--shadow-lg);
}

.card-top { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

.badge {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .03em;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 13%, transparent);
}

.card-top em { font-style: normal; font-size: 12.5px; color: var(--text-2); }

.card h3 { margin: 10px 0 0; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.motto {

  margin: 14px 0 0;
  padding-left: 12px;
  border-left: 2px solid color-mix(in srgb, var(--c) 40%, transparent);
  font-size: 13.5px;
  font-style: italic;
  color: var(--text-2);
}

.more {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 14px;
  font-size: 13.5px;
  font-weight: 600;
}

.more:hover { text-decoration: underline; }

.pill {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
}

/* ---------------- lesson detail ---------------- */
.detail-shell {
  display: grid;
  grid-template-columns: minmax(0, 860px) 176px;
  align-items: start;
  gap: 34px;
}

@media (min-width: 1401px) {
  .wrap.lesson-wrap {
    max-width: 1680px;
    gap: 32px;
  }

  .lesson-wrap .detail-shell {
    grid-template-columns: minmax(0, 1040px) 184px;
    column-gap: 40px;
    justify-content: space-between;
  }
}

.detail { min-width: 0; }

.reading-progress {
  position: sticky;
  top: var(--header-h);
  z-index: 25;
  height: 3px;
  margin-bottom: 18px;
  background: var(--bg-soft);
  overflow: hidden;
}

.reading-progress i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--c);
  transition: width .12s linear;
}

.crumb { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; font-size: 13px; color: var(--text-2); }
.crumb a:hover { color: var(--text); text-decoration: underline; }

.d-head { padding-bottom: 22px; margin-bottom: 26px; border-bottom: 1px solid var(--border); }
.d-head h1 { margin: 12px 0 0; font-size: 28px; line-height: 1.3; letter-spacing: -.02em; }

.lesson-meta { margin: 8px 0 0; color: var(--text-3); font-size: 12.5px; }

.d-motto {
  margin: 16px 0 0;
  padding: 14px 18px;
  border-left: 3px solid var(--c);
  border-radius: 0 8px 8px 0;
  background: color-mix(in srgb, var(--c) 7%, transparent);
  font-size: 15px;
  font-weight: 500;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.tabs button {
  padding: 9px 16px;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}

.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--text); border-bottom-color: var(--c); font-weight: 600; }

.md { font-size: 14.8px; }
.md h2 { margin: 0 0 12px; font-size: 19px; letter-spacing: -.01em; }
.md h2:first-child { margin-top: 0; }
.md h3 { margin: 24px 0 10px; font-size: 16px; }
.md p { margin: 12px 0; }
.md ul, .md ol { margin: 12px 0; padding-left: 22px; }
.md li { margin: 5px 0; }
.md strong { font-weight: 650; }
.md blockquote {
  margin: 16px 0;
  padding: 2px 16px;
  border-left: 3px solid var(--border);
  color: var(--text-2);
}
.md code {
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  font-size: .88em;
}
.md pre {
  margin: 16px 0;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--code-bg);
  overflow-x: auto;
  line-height: 1.6;
}
.md pre code { padding: 0; border: 0; background: none; font-size: 13px; }
.md table {
  width: 100%;
  margin: 18px 0;
  border-collapse: collapse;
  font-size: 13.5px;
  display: block;
  overflow-x: auto;
}
.md th, .md td {
  padding: 9px 12px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.md th { background: var(--bg-soft); font-weight: 600; }
.md a { color: #3b82f6; }
.md a:hover { text-decoration: underline; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 28px 0; }

.lesson-section {
  scroll-margin-top: calc(var(--header-h) + 24px);
  padding: 30px 0 8px;
  border-top: 1px solid var(--border);
}

.lesson-section:first-child { padding-top: 0; border-top: 0; }

.lesson-toc {
  position: sticky;
  top: calc(var(--header-h) + 32px);
  padding-left: 15px;
  border-left: 1px solid var(--border);
}

.lesson-toc > small {
  display: block;
  margin-bottom: 8px;
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .08em;
}

.lesson-toc ol { list-style: none; margin: 0; padding: 0; }

.lesson-toc button {
  display: flex;
  align-items: baseline;
  gap: 7px;
  width: 100%;
  padding: 5px 0;
  border: 0;
  background: transparent;
  color: var(--text-3);
  text-align: left;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}

.lesson-toc button i { font-style: normal; font-size: 9px; font-variant-numeric: tabular-nums; }
.lesson-toc button:hover, .lesson-toc button.active { color: var(--text); }
.lesson-toc button.active i { color: var(--c); font-weight: 700; }

/* ---------------- teaching components ---------------- */
.teach {
  margin: 20px 0 26px;
  border: 1px solid var(--border);
  background: var(--panel);
  overflow: hidden;
}

.teach-head {
  min-height: 62px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.teach-kicker {
  color: var(--text-3);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .08em;
}

.teach-title { margin: 3px 0 0 !important; font-size: 15px !important; font-weight: 600; }

.step-controls { display: flex; gap: 6px; }
.step-controls button,
.lesson-complete button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text-2);
  font-family: inherit;
  font-size: 11.5px;
  cursor: pointer;
}
.step-controls button:hover:not(:disabled) { border-color: var(--c); color: var(--text); }
.step-controls button:disabled { opacity: .4; cursor: default; }

.step-status {
  padding: 10px 14px 0;
  color: var(--text-3);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  letter-spacing: .08em;
}

.step-track {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 14px;
  background: var(--bg-soft);
  overflow-x: auto;
}

.step-track.has-loop { padding-bottom: 54px; }

.step-loop-arrow {
  position: absolute;
  z-index: 2;
  border-left: 2px solid var(--c);
  border-right: 2px solid var(--c);
  border-bottom: 2px solid var(--c);
  border-radius: 0 0 8px 8px;
  pointer-events: none;
}

.step-loop-arrow::before {
  content: "▲";
  position: absolute;
  left: -6px;
  top: -13px;
  color: var(--c);
  font-size: 10px;
  line-height: 1;
}

.step-loop-arrow i {
  position: absolute;
  left: 50%;
  bottom: -12px;
  padding: 0 7px;
  background: var(--bg-soft);
  color: var(--c);
  font-style: normal;
  font-size: 9.5px;
  white-space: nowrap;
  transform: translateX(-50%);
}

.step-loop-arrow.vertical {
  border-top: 2px solid var(--c);
  border-right: 0;
  border-bottom: 2px solid var(--c);
  border-radius: 8px 0 0 8px;
}

.step-loop-arrow.vertical::before {
  content: "▶";
  left: auto;
  right: -7px;
  top: -5px;
}

.step-loop-arrow.vertical i {
  left: 4px;
  bottom: 50%;
  padding: 5px 2px;
  writing-mode: vertical-rl;
  transform: translate(-50%, 50%);
}

.step-card {
  position: relative;
  min-width: 116px;
  min-height: 76px;
  flex: 1 0 116px;
  padding: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.step-card small, .flow-node small { display: block; color: var(--text-3); font-size: 9px; }
.step-card strong, .flow-node strong { display: block; margin-top: 15px; font-size: 12px; font-weight: 600; }
.step-card::after {
  content: "";
  position: absolute;
  top: 9px;
  right: 9px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--border);
}
.step-card.done::after, .step-card.active::after { background: var(--c); }
.step-card.active { border-color: var(--c); background: color-mix(in srgb, var(--c) 7%, var(--panel)); }
.step-arrow { flex: 0 0 auto; color: var(--c); font-size: 17px; }

.step-detail,
.flow-detail {
  display: grid;
  grid-template-columns: 68px 150px 1fr;
  gap: 10px;
  align-items: baseline;
  min-height: 62px;
  padding: 13px 14px;
  border-top: 1px solid var(--border);
}
.step-detail small, .flow-detail small { color: var(--text-3); font-size: 9px; }
.step-detail strong, .flow-detail strong { font-size: 12.5px; }
.step-detail p, .flow-detail p { margin: 0; color: var(--text-2); font-size: 12.5px; }

.flow-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
  padding: 14px;
  background: var(--bg-soft);
}

.flow-node {
  min-height: 118px;
  padding: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  text-align: left;
  font-family: inherit;
  cursor: pointer;
}
.flow-node:hover, .flow-node.active { border-color: var(--c); }
.flow-node.active { box-shadow: inset 3px 0 var(--c); }
.flow-next { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 12px; }
.flow-next i {
  padding: 2px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-2);
  font-style: normal;
  font-size: 9px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.flow-map-hint {
  margin: 0;
  color: var(--text-3);
  font-size: 10.5px;
}

.flow-map-scroll {
  padding: 20px 16px;
  overflow-x: auto;
  background: var(--bg-soft);
}

.flow-map {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--map-cols), 138px);
  grid-template-rows: repeat(var(--map-rows), 92px);
  column-gap: 58px;
  row-gap: 52px;
  align-items: stretch;
  justify-content: center;
  padding: 8px;
}

.flow-map canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.flow-map-node {
  position: relative;
  z-index: 2;
  min-height: 92px;
  padding: 13px;
  border-radius: 9px;
  box-shadow: 0 1px 0 rgba(16, 24, 40, .03);
}

.flow-map-node strong { margin-top: 16px; font-size: 12px; line-height: 1.35; }
.flow-map-node.active { box-shadow: inset 0 0 0 1px var(--c), inset 4px 0 var(--c); }
.flow-map-node.is-decision { border-style: dashed; background: color-mix(in srgb, var(--c) 5%, var(--panel)); }
.flow-map-node.is-state {
  border-color: color-mix(in srgb, var(--c) 45%, var(--border));
  border-radius: 999px;
  background: color-mix(in srgb, var(--c) 8%, var(--panel));
  text-align: center;
}
.flow-map-node.is-terminal { border-color: color-mix(in srgb, var(--text-3) 55%, var(--border)); }
.flow-map-node.is-boundary { border-width: 2px; }
.teach-flow-map .flow-detail { background: var(--panel); }

/* L01: the loop revolves around shared message history, not a fixed step list. */
.agent-loop-hint {
  margin: 0;
  color: var(--text-3);
  font-size: 10.5px;
}

.agent-loop-scroll {
  padding: 18px 14px;
  overflow-x: auto;
  background: var(--bg-soft);
}

.agent-loop-map {
  display: grid;
  grid-template-columns: minmax(104px, 1fr) 42px minmax(110px, .9fr) 42px minmax(112px, 1fr) 42px minmax(126px, 1.08fr) 42px minmax(108px, 1fr);
  grid-template-rows: minmax(92px, auto) 58px minmax(92px, auto);
  align-items: stretch;
  min-width: 800px;
}

.agent-loop-node {
  position: relative;
  min-height: 92px;
  padding: 14px;
  border-radius: 9px;
  z-index: 2;
}

.agent-loop-node strong { margin-top: 18px; font-size: 12.5px; }
.agent-loop-node.active { box-shadow: inset 0 0 0 1px var(--c), inset 4px 0 var(--c); }
.node-input { grid-column: 1; grid-row: 1; }
.node-model { grid-column: 5; grid-row: 1; }
.node-decide { grid-column: 7; grid-row: 1; border-style: dashed; }
.node-done { grid-column: 9; grid-row: 1; }
.node-tool { grid-column: 7; grid-row: 3; }
.node-observe { grid-column: 3; grid-row: 3; }

.agent-loop-memory {
  grid-column: 3;
  grid-row: 1;
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--c) 45%, var(--border));
  border-radius: 999px;
  background: color-mix(in srgb, var(--c) 8%, var(--panel));
  text-align: center;
}

.agent-loop-memory small {
  color: var(--c);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 8.5px;
  letter-spacing: .08em;
}
.agent-loop-memory strong { margin-top: 5px; font-size: 13px; }
.agent-loop-memory span { margin-top: 3px; color: var(--text-3); font-size: 9.5px; }

.agent-loop-link {
  position: relative;
  z-index: 1;
  color: var(--c);
  pointer-events: none;
}

.agent-loop-link i {
  position: absolute;
  z-index: 2;
  padding: 1px 5px;
  background: var(--bg-soft);
  color: var(--text-3);
  font-style: normal;
  font-size: 8.5px;
  white-space: nowrap;
}

.link-input-history { grid-column: 2; grid-row: 1; }
.link-history-model { grid-column: 4; grid-row: 1; }
.link-model-decision { grid-column: 6; grid-row: 1; }
.link-decision-done { grid-column: 8; grid-row: 1; }
.link-input-history::before,
.link-history-model::before,
.link-model-decision::before,
.link-decision-done::before,
.link-tool-observe::before {
  content: "";
  position: absolute;
  left: 0;
  right: 7px;
  top: 50%;
  border-top: 2px solid var(--c);
}
.link-input-history::after,
.link-history-model::after,
.link-model-decision::after,
.link-decision-done::after {
  content: "";
  position: absolute;
  right: 0;
  top: calc(50% - 4px);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid var(--c);
}
.link-input-history i,
.link-history-model i,
.link-decision-done i { left: 50%; top: calc(50% - 19px); transform: translateX(-50%); }

.link-decision-tool { grid-column: 7; grid-row: 2; }
.link-decision-tool::before,
.link-observe-history::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 7px;
  border-left: 2px solid var(--c);
}
.link-decision-tool::after {
  content: "";
  position: absolute;
  left: calc(50% - 4px);
  bottom: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid var(--c);
}
.link-decision-tool i { left: calc(50% + 7px); top: 18px; }

.link-tool-observe { grid-column: 4 / 7; grid-row: 3; }
.link-tool-observe::after {
  content: "";
  position: absolute;
  left: 0;
  top: calc(50% - 4px);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-right: 7px solid var(--c);
}
.link-tool-observe i { left: 50%; top: calc(50% - 19px); transform: translateX(-50%); }

.link-observe-history { grid-column: 3; grid-row: 2; }
.link-observe-history::after {
  content: "";
  position: absolute;
  left: calc(50% - 4px);
  top: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 7px solid var(--c);
}
.link-observe-history i { left: calc(50% + 7px); top: 17px; }

.teach-agent-loop .flow-detail { background: var(--panel); }

.structure-tree { padding: 18px; background: var(--bg-soft); overflow-x: auto; }
.structure-tree ul { position: relative; list-style: none; margin: 0; padding-left: 26px; }
.structure-tree > ul { padding-left: 0; }
.structure-tree ul ul { margin-left: 14px; border-left: 1px solid var(--border); }
.structure-tree li { position: relative; margin: 10px 0; }
.structure-tree ul ul > li::before {
  content: "";
  position: absolute;
  left: -26px;
  top: 22px;
  width: 26px;
  border-top: 1px solid var(--border);
}
.structure-node {
  display: inline-block;
  min-width: 210px;
  max-width: 520px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--panel);
}
.structure-node strong { font-size: 12.5px; }
.structure-node p { margin: 3px 0 0; color: var(--text-2); font-size: 11.5px; }

.compare-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1px;
  background: var(--border);
}
.compare-card { min-height: 130px; padding: 16px; background: var(--panel); }
.compare-card small { display: block; color: var(--c); font-size: 9px; font-weight: 700; }
.compare-card strong { display: block; margin-top: 14px; font-size: 13px; }
.compare-card p { margin: 6px 0 0; color: var(--text-2); font-size: 11.5px; }

.code-focus-grid { display: grid; grid-template-columns: 3fr 2fr; }
.code-focus-grid pre {
  min-width: 0;
  margin: 0;
  padding: 16px 0;
  border: 0;
  border-radius: 0;
  background: #151515;
  color: #f5f5f5;
  overflow-x: auto;
}
.focus-line { display: flex; min-width: max-content; padding: 1px 16px; }
.focus-line i { width: 30px; flex: 0 0 30px; color: #737373; font-style: normal; font-weight: 400; }
.focus-line b { font-weight: 400; white-space: pre; }
.focus-line.active { background: color-mix(in srgb, var(--c) 22%, #151515); }
.focus-notes { list-style: none; margin: 0 !important; padding: 0 !important; background: var(--bg-soft); }
.focus-notes li { margin: 0 !important; border-bottom: 1px solid var(--border); }
.focus-notes li:last-child { border-bottom: 0; }
.focus-notes button {
  display: flex;
  gap: 10px;
  width: 100%;
  min-height: 72px;
  padding: 12px;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-family: inherit;
  cursor: pointer;
}
.focus-notes button.active { border-left-color: var(--c); background: var(--panel); }
.focus-notes button > i {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  font-style: normal;
  font-size: 9px;
}
.focus-notes span { display: block; }
.focus-notes strong { display: block; font-size: 12px; }
.focus-notes small { display: block; margin-top: 3px; color: var(--text-2); font-size: 10.5px; line-height: 1.5; }

/* Runtime X-Ray：一边单步执行，一边观察事实、投影与继续判定。 */
.teach-trace { overflow: hidden; }
.trace-rail {
  display: flex;
  gap: 0;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  overflow-x: auto;
}
.trace-rail button {
  position: relative;
  min-width: 118px;
  flex: 1 0 118px;
  padding: 10px 12px 12px;
  border: 0;
  border-bottom: 2px solid var(--border);
  background: transparent;
  color: var(--text-2);
  text-align: left;
  font-family: inherit;
  cursor: pointer;
}
.trace-rail button::after {
  content: "";
  position: absolute;
  right: -4px;
  bottom: -5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
}
.trace-rail button:last-child::after { right: 0; }
.trace-rail button small { display: block; color: var(--text-3); font-size: 9px; }
.trace-rail button strong { display: block; margin-top: 5px; font-size: 11.5px; }
.trace-rail button.done,
.trace-rail button.active { border-bottom-color: var(--c); color: var(--text); }
.trace-rail button.done::after,
.trace-rail button.active::after { background: var(--c); }
.trace-rail button.active { background: color-mix(in srgb, var(--c) 7%, transparent); }
.trace-now {
  display: grid;
  grid-template-columns: 78px minmax(180px, .7fr) minmax(260px, 1.3fr);
  gap: 12px;
  align-items: baseline;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}
.trace-now span { color: var(--text-3); font-size: 9px; letter-spacing: .06em; }
.trace-now code { color: var(--c); font-size: 11px; }
.trace-now p { margin: 0; color: var(--text-2); font-size: 12px; }
.trace-state {
  display: grid;
  grid-template-columns: repeat(var(--trace-cols), minmax(0, 1fr));
  background: var(--border);
  gap: 1px;
}
.trace-state article { min-width: 0; padding: 15px 16px; background: var(--panel); }
.trace-state article small {
  display: block;
  margin-bottom: 9px;
  color: var(--text-3);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 8.5px;
  letter-spacing: .06em;
}
.trace-state pre {
  min-height: 100px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--code-bg);
  color: var(--text-2);
  font-size: 10.5px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.trace-state .trace-emphasis {
  background: color-mix(in srgb, var(--c) 6%, var(--panel));
}
.trace-state .trace-emphasis small { color: var(--c); }

/* 源码带读：说明执行路径，再展示由构建器从 main.py 实时截取的真实代码。 */
.walkthrough-source { margin: 0; color: var(--text-3); font-size: 10.5px; }
.walkthrough-list { border-top: 1px solid var(--border); }
.walkthrough-pass {
  display: grid;
  grid-template-columns: minmax(250px, .9fr) minmax(0, 1.35fr);
  border-bottom: 1px solid var(--border);
}
.walkthrough-pass:last-child { border-bottom: 0; }
.walkthrough-guide { padding: 22px 20px; background: var(--panel); }
.walkthrough-guide > small {
  color: var(--c);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  letter-spacing: .07em;
}
.walkthrough-guide h4 { margin: 9px 0 8px; font-size: 15px; line-height: 1.35; }
.walkthrough-guide > p { margin: 0; color: var(--text-2); font-size: 12.5px; line-height: 1.7; }
.walkthrough-why {
  margin-top: 16px;
  padding: 11px 12px;
  border-left: 2px solid var(--c);
  background: color-mix(in srgb, var(--c) 6%, var(--bg-soft));
}
.walkthrough-why b,
.walkthrough-why span { display: block; }
.walkthrough-why b { color: var(--c); font-size: 9px; letter-spacing: .04em; }
.walkthrough-why span { margin-top: 4px; color: var(--text-2); font-size: 11.5px; line-height: 1.6; }
.walkthrough-pass pre {
  min-width: 0;
  margin: 0;
  padding: 18px 0;
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 0;
  background: #151515;
  color: #f5f5f5;
  overflow-x: auto;
  font-size: 11px;
  line-height: 1.65;
}
.walkthrough-line { display: flex; min-width: max-content; padding: 0 16px; }
.walkthrough-line i {
  width: 36px;
  flex: 0 0 36px;
  color: #737373;
  font-style: normal;
  user-select: none;
}
.walkthrough-line b { font-weight: 400; white-space: pre; }

.lesson-complete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 38px;
  padding: 17px 18px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--c);
  background: var(--bg-soft);
}
.lesson-complete small { display: block; color: var(--text-3); font-size: 10px; }
.lesson-complete strong { display: block; margin-top: 2px; font-size: 13px; }
.lesson-complete button[aria-pressed="true"] { border-color: var(--c); color: var(--c); }

.resume-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -12px 0 24px;
  padding: 13px 16px;
  border: 1px solid color-mix(in srgb, var(--c) 38%, var(--border));
  background: color-mix(in srgb, var(--c) 5%, var(--panel));
}
.resume-card small, .resume-card strong { display: block; }
.resume-card small { color: var(--text-3); font-size: 10px; }
.resume-card strong { margin-top: 2px; font-size: 13px; }
.resume-card i { color: var(--c); font-style: normal; font-size: 20px; }
.complete-mark { margin-left: auto; color: var(--c); font-size: 10.5px; font-weight: 600; }
.card.completed { border-color: color-mix(in srgb, var(--c) 34%, var(--border)); }

.codebox { position: relative; }

.codebox pre {
  max-height: 74vh;
  overflow: auto;
  margin: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--code-bg);
  font-size: 13px;
  line-height: 1.65;
}

.copy {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text-2);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}

.copy:hover { color: var(--text); }

.runline {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg-soft);
  font-size: 13px;
}

.runline code { font-size: 12.5px; color: var(--text); }

.pager {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 44px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}

.pager a {
  flex: 1 1 0;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13.5px;
  transition: border-color .15s, background .15s;
}

.pager a:hover { background: var(--bg-soft); }
.pager a small { display: block; color: var(--text-3); font-size: 11.5px; margin-bottom: 3px; }
.pager a.nxt { text-align: right; }

/* ---------------- layers page ---------------- */
.lcard {
  padding: 20px 22px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--c);
  border-radius: var(--radius);
  background: var(--panel);
}

.lcard h3 { display: flex; align-items: center; gap: 9px; margin: 0; font-size: 17px; }
.lcard p { margin: 6px 0 14px; font-size: 13.5px; color: var(--text-2); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  background: var(--bg);
  transition: border-color .15s, background .15s;
}

.chip:hover { border-color: var(--c); background: var(--bg-soft); }
.chip i { font-style: normal; font-size: 11px; color: var(--c); font-weight: 700; }

/* ---------------- search ---------------- */
.searchbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  padding: 11px 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-soft);
}

.searchbar input {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.searchbar input::placeholder { color: var(--text-3); }

.empty { padding: 60px 0; text-align: center; color: var(--text-3); }

/* ---------------- responsive ---------------- */
@media (max-width: 900px) {
  .wrap { flex-direction: column; gap: 0; padding: 24px 18px 72px; }
  .side { width: auto; flex: none; margin-bottom: 28px; }
  .side-in { position: static; max-height: none; }
  .side.lesson-side .grp:not(.current) { display: none; }
  .side.lesson-side .grp.current { margin-bottom: 0; }
  .side.lesson-side .grp.current ul {
    display: flex;
    gap: 5px;
    padding-bottom: 4px;
    overflow-x: auto;
  }
  .side.lesson-side .grp.current li { flex: 0 0 auto; }
  .side.lesson-side .grp.current li a { border: 1px solid var(--border); }
  .nav a { padding: 6px 9px; font-size: 13px; }
  .ph h1 { font-size: 25px; }
  .row { gap: 14px; }
  .rail { flex-basis: 34px; }
  .node { width: 34px; height: 34px; font-size: 11px; }
  .detail-shell { grid-template-columns: minmax(0, 1fr); }
  .lesson-toc {
    position: sticky;
    top: var(--header-h);
    z-index: 20;
    grid-row: 1;
    padding: 8px 0;
    border-left: 0;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    overflow-x: auto;
  }
  .lesson-toc > small { display: none; }
  .lesson-toc ol { display: flex; min-width: max-content; gap: 6px; }
  .lesson-toc li { flex: 0 0 auto; }
  .lesson-toc button { padding: 5px 8px; border-radius: 6px; }
  .lesson-toc button.active { background: var(--bg-soft); }
}

@media (max-width: 1400px) and (min-width: 901px) {
  .detail-shell { grid-template-columns: minmax(0, 1fr); }
  .lesson-toc {
    position: sticky;
    top: var(--header-h);
    z-index: 20;
    grid-row: 1;
    padding: 8px 0;
    border-left: 0;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    overflow-x: auto;
  }
  .lesson-toc > small { display: none; }
  .lesson-toc ol { display: flex; min-width: max-content; gap: 6px; }
  .lesson-toc li { flex: 0 0 auto; }
  .lesson-toc button { padding: 5px 8px; border-radius: 6px; }
  .lesson-toc button.active { background: var(--bg-soft); }
}

@media (max-width: 560px) {
  .brand span { display: none; }
  .card { padding: 15px 16px; }
  .teach-head { align-items: flex-start; flex-direction: column; }
  .step-controls { width: 100%; }
  .step-controls button { flex: 1; }
  .step-track { align-items: stretch; flex-direction: column; overflow: visible; }
  .step-track.has-loop { padding-left: 46px; padding-bottom: 14px; }
  .step-card { width: 100%; min-width: 0; min-height: 62px; flex: none; }
  .step-card strong { margin-top: 8px; }
  .step-arrow { align-self: center; transform: rotate(90deg); }
  .step-detail, .flow-detail { grid-template-columns: 1fr; gap: 3px; }
  .flow-grid { grid-template-columns: 1fr; }
  .code-focus-grid { grid-template-columns: 1fr; }
  .walkthrough-pass { grid-template-columns: 1fr; }
  .walkthrough-pass pre { border-left: 0; border-top: 1px solid var(--border); }
  .trace-now { grid-template-columns: 1fr; gap: 3px; }
  .trace-state { grid-template-columns: 1fr; }
  .lesson-complete { align-items: stretch; flex-direction: column; }
}

@media (max-width: 760px) and (min-width: 561px) {
  .step-track { align-items: stretch; flex-direction: column; overflow: visible; }
  .step-track.has-loop { padding-left: 46px; padding-bottom: 14px; }
  .step-card { width: 100%; min-width: 0; min-height: 68px; flex: none; }
  .step-card strong { margin-top: 8px; }
  .step-arrow { align-self: center; transform: rotate(90deg); }
}

@media (max-width: 900px) and (min-width: 561px) {
  .trace-state { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
