/* Harness Engineering 中文版 · 全站样式
   视觉语言模仿 Pi Agent 官网（pi.dev）：深蓝灰底、Plantin 系衬线正文（标题一律常规字重）、
   钢蓝链接、方括号 CTA、等宽小标签、代码区常驻 Gruvbox 终端风、无阴影无卡片、发丝线分隔。
   深浅双主题：变量在 :root（浅色·纸面）与下方两处深色块中各定义一遍；
   dark 生效路径有两条——显式 :root[data-theme="dark"] 与 auto 跟随系统的
   @media (prefers-color-scheme: dark)。默认 dark（Pi 即深色站），三态切换见 theme.mjs。 */

:root {
  /* 浅色 = Pi 的「纸面」变体：暖米底、墨色正文 */
  --bg: #f7f4ee;
  --card: #fffdf8;
  --text: #2c3038;
  --muted: #5a616c;
  --faint: #8f939c;
  --line: #e0dbd0;
  --line-soft: #ebe7dd;
  --accent: #3a6d99;
  --accent-deep: #2f5a80;
  --accent-tint: rgba(58, 109, 153, 0.08);
  --heading-dim: #4a4f59;
  /* 论文容器配色：观察 钢蓝 / 建议 苔绿 / 注记 灰（取自 Pi 终端色板） */
  --ob: #458588;
  --ob-bg: rgba(69, 133, 136, 0.07);
  --rec: #4e7a45;
  --rec-bg: rgba(78, 122, 69, 0.08);
  --ok: #4e7a45;
  --ok-bg: rgba(78, 122, 69, 0.08);
  --fu: #3a6d99;
  --fu-bg: rgba(58, 109, 153, 0.07);
  --warn: #b72538;
  --warn-bg: rgba(183, 37, 56, 0.07);
  --gold: #835f03;
  --gold-bg: rgba(131, 95, 3, 0.07);
  --slate: #57606a;
  --slate-bg: rgba(87, 96, 106, 0.06);
  --inline-code: #2f5a80;
  --sel-bg: rgba(58, 109, 153, 0.22);
  --term-bg: #282828;   /* 代码区常驻终端（两种主题一致，同 Pi 的终端演示） */
  --term-fg: #fbf1c7;
  --term-line: rgba(251, 241, 199, 0.1);
  /* highlight.js token 配色（Gruvbox Dark，衬 --term-bg） */
  --hl-comment: #928374;
  --hl-keyword: #fb4934;
  --hl-string: #b8bb26;
  --hl-number: #d3869b;
  --hl-title: #83a598;
  --hl-attr: #fabd2f;
  --hl-type: #8ec07c;
  --radius: 10px;
  --radius-sm: 6px;
  --serif: "Plantin MT Pro", "Plantin MT Std", Plantin, Georgia, "Times New Roman",
    "Songti SC", "Noto Serif SC", "Source Han Serif SC", "SimSun", serif;
  --mono: "Commit Mono", "Departure Mono", "Maple Mono CN", ui-monospace,
    "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  /* 深色 = pi.dev 原味：#161d27 底 + 暖白文字 + 钢蓝链接 */
  --bg: #161d27;
  --card: #1c2433;
  --text: #d5d8db;
  --muted: #98a0ab;
  --faint: #6d7480;
  --line: rgba(213, 216, 219, 0.14);
  --line-soft: rgba(213, 216, 219, 0.08);
  --accent: #6a9fcc;
  --accent-deep: #8fb8dc;
  --accent-tint: rgba(106, 159, 204, 0.1);
  --heading-dim: rgba(213, 216, 219, 0.78);
  --ob: #83a598;
  --ob-bg: rgba(131, 165, 152, 0.08);
  --rec: #8ec07c;
  --rec-bg: rgba(142, 192, 124, 0.07);
  --ok: #8ec07c;
  --ok-bg: rgba(142, 192, 124, 0.07);
  --fu: #6a9fcc;
  --fu-bg: rgba(106, 159, 204, 0.08);
  --warn: #fb4934;
  --warn-bg: rgba(251, 73, 52, 0.08);
  --gold: #fabd2f;
  --gold-bg: rgba(250, 189, 47, 0.08);
  --slate: #98a0ab;
  --slate-bg: rgba(152, 160, 171, 0.07);
  --inline-code: #8fb8dc;
  --sel-bg: rgba(106, 159, 204, 0.3);
}

/* auto 模式：未显式选浅色时跟随系统（显式 light 由上面的属性选择器排除） */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161d27;
    --card: #1c2433;
    --text: #d5d8db;
    --muted: #98a0ab;
    --faint: #6d7480;
    --line: rgba(213, 216, 219, 0.14);
    --line-soft: rgba(213, 216, 219, 0.08);
    --accent: #6a9fcc;
    --accent-deep: #8fb8dc;
    --accent-tint: rgba(106, 159, 204, 0.1);
    --heading-dim: rgba(213, 216, 219, 0.78);
    --ob: #83a598;
    --ob-bg: rgba(131, 165, 152, 0.08);
    --rec: #8ec07c;
    --rec-bg: rgba(142, 192, 124, 0.07);
    --ok: #8ec07c;
    --ok-bg: rgba(142, 192, 124, 0.07);
    --fu: #6a9fcc;
    --fu-bg: rgba(106, 159, 204, 0.08);
    --warn: #fb4934;
    --warn-bg: rgba(251, 73, 52, 0.08);
    --gold: #fabd2f;
    --gold-bg: rgba(250, 189, 47, 0.08);
    --slate: #98a0ab;
    --slate-bg: rgba(152, 160, 171, 0.07);
    --inline-code: #8fb8dc;
    --sel-bg: rgba(106, 159, 204, 0.3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.8;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.35; font-weight: 400; letter-spacing: -0.01em; }
p { margin: 0.8em 0; }
::selection { background: var(--sel-bg); }

/* ── 顶部导航：透明、无模糊、发丝线（pi.dev 的 sticky-nav） ── */
.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: baseline;
  gap: 18px;
  padding: 16px clamp(16px, 4vw, 40px) 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topnav .brand {
  font-family: var(--serif);
  font-size: 18px;
  color: var(--text);
  white-space: nowrap;
}
.topnav .brand:hover { text-decoration: none; color: var(--accent); }
.topnav .crumb {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topnav .nav-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}
.topnav .nav-actions .nav-home { margin-left: 0; }
.topnav .nav-home {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}
.topnav .nav-home::before { content: "[ "; color: var(--faint); }
.topnav .nav-home::after { content: " ]"; color: var(--faint); }
.topnav .nav-home:hover { color: var(--accent); text-decoration: none; }

/* ── 深浅色切换按钮（三态：浅色 / 深色 / 跟随系统，见 theme.mjs） ── */
.theme-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  background: none;
  color: var(--faint);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--accent); }
.theme-toggle svg { display: none; width: 15px; height: 15px; }
[data-theme="light"] .theme-toggle .i-light { display: block; }
[data-theme="dark"] .theme-toggle .i-dark { display: block; }
[data-theme="auto"] .theme-toggle .i-auto { display: block; }

/* ── 布局容器 ── */
.container {
  max-width: 820px;
  margin: 0 auto;
  padding: 30px clamp(16px, 4vw, 40px) 80px;
  overflow-wrap: break-word; /* 长英文/斜杠串（如 SKILL.md、MCP/ACP）放不下时折行 */
}
.subtitle { color: var(--muted); font-size: 15px; }
.footer-note { text-align: center; margin-top: 52px; font-family: var(--mono); font-size: 12px; color: var(--faint); }
.loading { text-align: center; margin-top: 120px; }

/* ── 封面 hero（论文题录） ── */
.paper-hero { padding: 44px 0 12px; }
.hero-kicker {
  font-family: var(--mono);
  color: var(--faint);
  font-size: 12px;
  letter-spacing: 2px;
  margin: 0 0 14px;
}
.paper-hero h1 {
  margin: 0 0 10px;
  font-size: clamp(28px, 4.6vw, 40px);
  font-weight: 400;
  letter-spacing: -0.015em;
  color: var(--text);
}
.hero-subtitle {
  color: var(--muted);
  font-size: clamp(16px, 2.2vw, 19px);
  font-style: italic;
  margin: 0 0 14px;
}
.hero-meta {
  font-family: var(--mono);
  color: var(--faint);
  font-size: 12.5px;
  line-height: 1.9;
  margin: 0 0 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.hero-actions { margin: 26px 0 6px; }
.hero-btn {
  font-family: var(--mono);
  font-size: 14.5px;
  color: var(--accent);
}
.hero-btn::before { content: "[ "; color: var(--faint); }
.hero-btn::after { content: " ]"; color: var(--faint); }
.hero-btn:hover { text-decoration: none; color: var(--accent-deep); }
.hero-btn:hover::before, .hero-btn:hover::after { color: var(--accent); }

/* ── 返回条（pi.dev 式纯文本链接，非胶囊） ── */
.back-bar {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
}
.back-bar:hover { color: var(--accent); text-decoration: none; }
.back-arrow svg { display: inline-block; height: 0.9em; width: 0.5em; }
.back-label { font-weight: 400; }
.back-ctx { color: var(--faint); }
.back-ctx::before { content: " · "; }
.back-bar-end { margin: 34px 0 0; }

/* ── 章节目录列表：发丝线行、无卡片 ── */
.sec-list { list-style: none; margin: 24px 0; padding: 0; }
.sec-item {
  display: block;
  padding: 14px 2px;
  border-bottom: 1px solid var(--line);
  color: inherit;
  transition: padding-left 0.15s ease;
}
.sec-item:hover { text-decoration: none; padding-left: 10px; }
.sec-line { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.sec-line .num {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--faint);
}
.sec-title { font-size: 16.5px; color: var(--text); flex: 1; min-width: 200px; }
.sec-item:hover .sec-title { color: var(--accent); }
.sec-en {
  margin: 2px 0 0;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--faint);
  font-style: italic;
}
.sec-summary { margin: 5px 0 0; font-size: 14px; color: var(--muted); line-height: 1.7; }

/* ── 章节页 chips：等宽小标签 ── */
.sec-chips { display: flex; align-items: center; gap: 14px; margin: 2px 0 12px; }
.chip-plain {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--faint);
  letter-spacing: 0.5px;
}

/* ── 翻页：方括号链接 ── */
.pager {
  display: flex;
  gap: 28px;
  margin: 30px 0;
}
.pager a {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 2px;
  border-top: 1px solid var(--line);
  color: var(--text);
  font-size: 15px;
  min-width: 0;
}
.pager a:last-child { text-align: right; align-items: flex-end; }
.pager a:hover { text-decoration: none; color: var(--accent); }
.pager a:hover .dir { color: var(--accent); }
.pager .dir { font-family: var(--mono); font-size: 11.5px; color: var(--faint); font-weight: 400; }
.pager .dir::before { content: "[ "; }
.pager .dir::after { content: " ]"; }
.pager a span:not(.dir) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

/* ── 正文排版 ── */
.container > h1 { font-size: clamp(24px, 3.6vw, 31px); margin: 12px 0 8px; }
.sec-en-title {
  color: var(--faint);
  font-family: var(--mono);
  font-style: italic;
  font-size: 13px;
  margin: 0 0 10px;
}
.content-body h2, .container h2 {
  font-size: 24px;
  margin: 2.3em 0 0.7em;
  color: var(--heading-dim);
}
.content-body h3, .container h3 { font-size: 19px; margin: 1.8em 0 0.5em; color: var(--text); }
.container h4 { font-size: 16.5px; margin: 1.5em 0 0.4em; color: var(--text); }
.container ul, .container ol { padding-left: 1.6em; }
.container li { margin: 0.3em 0; }
.container blockquote {
  margin: 1.2em 0;
  padding: 2px 20px;
  border-left: 2px solid var(--line);
  color: var(--muted);
  font-style: italic;
}
code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--accent-tint);
  color: var(--inline-code);
  padding: 1px 5px;
  border-radius: 4px;
}
/* 代码区 = 终端：Gruvbox 暗底常驻（浅色主题下同样是终端，同 pi.dev 的演示区） */
pre {
  background: var(--term-bg);
  color: var(--term-fg);
  border: 1px solid var(--term-line);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  overflow-x: auto;
  font-family: var(--mono);
  line-height: 1.65;
  font-size: 13.5px;
  margin: 1.2em 0;
}
pre code { background: none; padding: 0; color: inherit; font-size: inherit; border-radius: 0; }
.table-wrap { margin: 1.2em 0; overflow-x: auto; }
.container table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  border: none;
}
.container th, .container td {
  border-bottom: 1px solid var(--line);
  padding: 9px 14px 9px 0;
  text-align: left;
  vertical-align: top;
}
.container tr:last-child td { border-bottom: 1px solid var(--line); }
.container th {
  font-family: var(--mono);
  font-weight: 400;
  font-size: 11.5px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--faint);
  white-space: nowrap;
}
.formula {
  margin: 1.2em 0;
  padding: 6px 8px;
  overflow-x: auto;
  text-align: center;
  font-size: 1.05em;
}

/* ── 论文图（figure 容器 + 图注；点击灯箱放大） ── */
figure.paper-figure {
  margin: 1.8em 0;
  text-align: center;
}
figure.paper-figure img {
  max-width: 100%;
  height: auto;
  cursor: zoom-in;
  /* 论文 SVG 是黑字 + 粉彩底、且文字经 foreignObject 继承页面黑色，
     深色主题下必须衬固定白底，否则文字与深色背景同色不可见 */
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
}
figure.paper-figure figcaption {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--faint);
  line-height: 1.7;
  text-align: center;
}

/* ── 脚注 ── */
sup.fn-ref { font-size: 0.72em; line-height: 0; }
sup.fn-ref a { text-decoration: none; margin-left: 1px; }
section.footnotes {
  margin-top: 2.6em;
  padding-top: 1.1em;
  border-top: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
}
section.footnotes h3 {
  font-family: var(--mono);
  font-weight: 400;
  font-size: 11.5px;
  color: var(--faint);
  letter-spacing: 2px;
  margin: 0 0 0.6em;
}
section.footnotes ol { padding-left: 1.4em; }
section.footnotes li { margin: 0.35em 0; }
section.footnotes .fn-no {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
}

/* ── 论文容器（box）：细左线 + 极淡底，无卡片感 ── */
.box {
  margin: 18px 0;
  padding: 10px 16px 10px 18px;
  border-left: 3px solid var(--line);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--slate-bg);
}
.box > .box-body > p:first-child, .box > p:first-child { margin-top: 2px; }
.box .box-tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1px;
  padding: 0;
  margin-bottom: 6px;
  color: var(--faint);
}
.box .box-tag::before { content: "[ "; }
.box .box-tag::after { content: " ]"; }

/* 观察框（Observation）：钢蓝 */
.box-observation { background: var(--ob-bg); border-left-color: var(--ob); }
.box-observation .box-tag { color: var(--ob); }

/* 建议框（Recommendation）：苔绿 */
.box-recommendation { background: var(--rec-bg); border-left-color: var(--rec); }
.box-recommendation .box-tag { color: var(--rec); }

/* 注记框（译者注等）：灰 */
.box-note { background: var(--slate-bg); border-left-color: var(--faint); }
.box-note .box-tag { color: var(--muted); }

/* 章首速览（折叠） */
details.box-summary {
  background: var(--fu-bg);
  border-left: 3px solid var(--fu);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
details.box-summary > summary {
  cursor: pointer;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 12.5px;
  letter-spacing: 1px;
  color: var(--accent);
  padding: 4px 2px;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
details.box-summary > summary::before {
  content: "▸";
  font-size: 11px;
  color: var(--faint);
  transition: transform 0.15s ease;
}
details.box-summary[open] > summary::before { transform: rotate(90deg); }
details.box-summary .box-body { margin-top: 4px; }

/* 未知容器兜底 */
.box-callout { background: var(--line-soft); }

/* ── 参考文献列表（渲染器识别「条目以字面 [n] 开头」的列表并挂 .ref-list） ── */
.container ul.ref-list {
  list-style: none;
  margin: 1.2em 0;
  padding-left: 0;
}
.container ul.ref-list li {
  padding-left: 3.4em;
  text-indent: -3.4em;
  margin: 0.6em 0;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.75;
}
.container ul.ref-list li .ref-no {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
}

/* highlight.js token 配色（Gruvbox Dark） */
.hljs-comment, .hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-deletion { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-addition { color: var(--hl-string); }
.hljs-number, .hljs-literal, .hljs-built_in, .hljs-symbol, .hljs-link { color: var(--hl-number); }
.hljs-title, .hljs-section, .hljs-name, .hljs-selector-id, .hljs-selector-class { color: var(--hl-title); }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable, .hljs-property, .hljs-params { color: var(--hl-attr); }
.hljs-type, .hljs-title.class_, .hljs-class .hljs-title { color: var(--hl-type); }
.hljs-meta { color: #928374; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

/* ── 页内目录（宽屏右侧浮动） ── */
.page-toc {
  position: fixed;
  top: 84px;
  right: max(28px, calc((100vw - 820px) / 2 - 224px));
  width: 208px;
  max-height: calc(100vh - 130px);
  overflow-y: auto;
  border-left: 1px solid var(--line);
  padding: 4px 0 4px 16px;
  font-size: 12px;
  z-index: 30;
  scrollbar-width: thin;
}
.page-toc-title {
  font-family: var(--mono);
  font-weight: 400;
  color: var(--faint);
  font-size: 10.5px;
  letter-spacing: 2px;
  padding: 0 0 8px;
  margin-bottom: 6px;
}
.page-toc button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  padding: 3px 0;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.page-toc button:hover { color: var(--accent); }
.page-toc button.t-sub { padding-left: 14px; font-size: 11.5px; color: var(--faint); }

/* ── 回到顶部 ── */
#back-top {
  position: fixed;
  right: 22px;
  bottom: 26px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 15px;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  z-index: 40;
}
#back-top.show { opacity: 1; visibility: visible; transform: none; }
#back-top:hover { color: var(--accent); border-color: var(--accent); }

/* ── 错误卡片 ── */
.error {
  background: var(--warn-bg);
  border-left: 3px solid var(--warn);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 18px 22px;
  margin-top: 40px;
}
.error b { color: var(--warn); font-size: 17px; }
.error code { background: none; }

/* ── 图片灯箱 ── */
.diagram-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 13, 20, 0.88);
  display: none;
}
.diagram-lightbox.open { display: block; }
.lb-canvas { position: absolute; inset: 0 0 56px 0; overflow: hidden; cursor: zoom-in; }
.lb-paper {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  cursor: grab;
  background: #fff; /* 与 figure.paper-figure img 同理：SVG 黑字必须衬白底 */
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  padding: 6px;
}
.lb-paper.dragging { cursor: grabbing; }
.lb-paper img { display: block; }
.lb-bar {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 999px;
  padding: 4px 8px;
}
.lb-bar button {
  border: none;
  background: none;
  color: var(--muted);
  border-radius: 999px;
  min-width: 30px;
  height: 28px;
  padding: 0 10px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 13px;
}
.lb-bar button:hover { color: var(--accent); }
.lb-scale {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--faint);
  min-width: 44px;
  text-align: center;
}

/* ── 响应式 ── */
@media (max-width: 1359px) {
  .page-toc { display: none; }
}
@media (max-width: 720px) {
  body { font-size: 16px; }
  .pager { flex-direction: column; gap: 14px; }
  .pager a:last-child { text-align: left; align-items: flex-start; }
  .sec-title { min-width: 140px; }
  .topnav { flex-wrap: wrap; }
}

/* 强调沿用衬线字重语义（Songti/Georgia 自带 bold，无需 MiSans 可变字重调校） */
b, strong { font-weight: 700; }
