/* =========================================================
   yc6n · 纸感阅读版式（样例）
   移植自 SpringWait · 算法讲义阅读版式，主色改为蓝色系
   ========================================================= */

/* 自托管中文等宽字体：Maple Mono CN Regular（OFL-1.1）
   228 个 woff2 分片通过 unicode-range 按需加载，浏览器只拉页面实际用到的
   字形分片，通常几百 KB。许可证见 /licenses.html 与 fonts/maple-mono-cn/OFL.txt */
/* 字体 CSS 改为在 HTML 里用 <link> 引入（见各页 <head>），
   不再用 @import：@import 会造成串行瀑布，且无法给文件加内容哈希。
   字体许可证见 /licenses.html 与 fonts/maple-mono-cn/OFL.txt */

:root {
  /* ---- 纸面中性色 ---- */
  --paper: #fbf8f3;
  --paper-2: #f4efe6;
  --card: #fffdf9;
  --ink: #22262b;
  --ink-soft: #454c54;
  --muted: #7d858c;
  --line: #e5dfd4;
  --line-strong: #d3cabb;

  /* ---- 主色：蓝色系（原为青绿 #0f6f6c）---- */
  --accent: #2563eb;
  --accent-soft: #dbe7fe;
  --accent-ink: #1d4ed8;

  /* ---- 次要强调 ---- */
  --warn: #b4531a;
  --warn-soft: #fbe9dc;

  --violet: #6a4fa3;
  --violet-soft: #ece6f7;

  --code-bg: #1c212b;
  --code-bg-2: #242a36;

  /* 行内代码：中性纸灰，不用主色（避免长文满屏蓝） */
  --code-inline-bg: #f2ede4;
  --code-inline-ink: #4a4033;
  --code-inline-line: #e2d9cb;

  --shadow-sm: 0 1px 2px rgba(30, 26, 18, .05);
  --shadow: 0 2px 8px rgba(30, 26, 18, .06), 0 12px 32px -18px rgba(30, 26, 18, .28);

  --radius: 14px;
  --radius-sm: 9px;

  --readw: 768px;
  --sidew: 252px;
  --rail-gap: 48px;
  --railw: 0px;
  /* 三列合成宽度。用 min() 兜底，避免窄屏下 calc 出负值把正文列压扁 */
  --track: min(100vw, calc(var(--sidew) + var(--readw) + var(--railw) + var(--rail-gap) * 2));

  --font-sans: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei",
               "Source Han Sans SC", "Noto Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  /* 等宽字体栈：首选项是自托管的 Maple Mono CN Regular。
     它基于资源圆体（圆润中文）+ Maple Mono 西文，通过加宽中文间距实现
     中英 2:1 对齐，所以代码块里的中文注释不会把代码推歪，
     风格也与西文统一，不会出现"字体退化"的割裂感。
     后续回退项供字体加载失败时兜底。 */
  --font-mono: "Maple Mono CN", "Sarasa Mono SC", "Sarasa Fixed SC",
               "Source Han Sans HW SC", "Noto Sans Mono CJK SC",
               "Cascadia Mono", "Cascadia Code",
               ui-monospace, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;
}

html[data-theme="dark"] {
  --paper: #14161a;
  --paper-2: #1a1d22;
  --card: #1b1e24;
  --ink: #e7e4de;
  --ink-soft: #b9b6b0;
  --muted: #8b8f96;
  --line: #2b2f36;
  --line-strong: #3a3f47;

  --accent: #6ea8fe;
  --accent-soft: #16243d;
  --accent-ink: #93c5fd;

  --warn: #e39463;
  --warn-soft: #33220f;

  --violet: #a993e0;
  --violet-soft: #241d38;

  --code-bg: #0f1217;
  --code-bg-2: #161a21;

  /* 行内代码：深色模式下的中性灰 */
  --code-inline-bg: #23262d;
  --code-inline-ink: #d8d2c6;
  --code-inline-line: #33373f;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 2px 10px rgba(0, 0, 0, .45), 0 18px 40px -24px rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }

/* 允许块级尺寸在 0 与 auto 之间过渡（details 展开动画的前提） */
:root { interpolate-size: allow-keywords; }

/* =========================================================
   基础重置：彻底切断浏览器默认样式
   
   浏览器 UA 样式表会给 <a> 上纯饱和蓝 #0000EE、访问过的 #551A8B、
   再加一条下划线；给 button/input/select/textarea 上 Arial 字体。
   站点此前没有兜底规则，于是任何没被单独定义颜色的链接、
   任何没写 font-family 的按钮，都会退回这些默认值 ——
   在纸感主题的暖灰底色上显得又蓝又突兀。
   
   这里统一兜底：链接默认用站点主色、无下划线（需要墨色的导航/卡片
   链接用具体规则覆盖，如 .topbar-nav a / .archive-link）；
   表单控件强制继承字体。新增元素也不会再漏。
   ========================================================= */

a {
  color: var(--accent);
  text-decoration: none;
}

/* 访问过的链接不许变成默认的紫色 #551A8B */
a:visited { color: var(--accent); }

/* 表单控件默认不继承 font-family，必须显式 inherit */
button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  color: var(--ink);
}

/* 纸感主题下按钮统一手型光标（UA 默认是 default） */
button:not(:disabled) { cursor: pointer; }

/* [hidden] 兜底（全站通用）
   浏览器 UA 样式表里 [hidden] 只有 display:none，优先级极低。
   只要作者样式给同类元素写过 display（img{display:block}、
   .badge{display:inline-block} 等），[hidden] 就会失效。
   与其每个组件单独补，不如在这里统一兜一次。
   注：这是最后一道防线，具体组件里该补的仍然补了。 */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.92;
  letter-spacing: .012em;
  font-feature-settings: "kern" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* 纸面纹理：极淡的径向渐变，主色改为蓝色 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(circle at 18% -8%, rgba(37, 99, 235, .07), transparent 42%),
    radial-gradient(circle at 88% 4%, rgba(180, 83, 26, .05), transparent 38%);
}
html[data-theme="dark"] body::before {
  background-image:
    radial-gradient(circle at 18% -8%, rgba(110, 168, 254, .10), transparent 42%),
    radial-gradient(circle at 88% 4%, rgba(227, 148, 99, .06), transparent 38%);
}

/* ---------- 阅读进度 ---------- */
#progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0%;
  z-index: 90;
  background: linear-gradient(90deg, var(--accent), var(--violet));
  transition: width .08s linear;
}

/* ---------- 顶部工具条 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 16px;
  /* 固定高度 + 垂直居中，保证 yc6n 与右侧按钮的基线严格对齐 */
  height: 60px;
  padding: 0 max(24px, calc((100vw - var(--track)) / 2));
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

/* 品牌字标 yc6n
   中英视觉对齐（依据实测字体度量）：
   - 汉字墨迹高度 ≈ 0.822em，拉丁小写 x-height ≈ 0.526em，大写 cap ≈ 0.705em
   - yc6n 全是小写字母，视觉高度只有旁边中文导航的 64%
     所以同字号下会显得"小一号"，需要放大字号而非平移
   - 取 17px（中文导航 14.5px）：17 × 0.526 ≈ 8.94px 小写墨迹，
     接近 14.5 × 0.822 ≈ 11.9px 汉字墨迹的 75%，配合 800 字重达到视觉等重
   - 不用 translateY 硬凑，靠字号与字重解决，跨字体一致 */
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  line-height: 1;
  height: 22px;
  font-weight: 800;
  font-size: 19px;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -.02em;
}
.brand:hover { color: var(--accent); text-decoration: none; }

.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  flex: 0 0 9px;
  /* 视觉重心微调，让它与文字 x-height 居中 */
  position: relative;
  top: -0.5px;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-left: 8px;
  line-height: 1;
}
.topbar-nav a {
  color: var(--muted);
  font-size: 14.5px;
  font-weight: 600;
  text-decoration: none;
}
.topbar-nav a:hover { color: var(--accent); }

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

.btn-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  line-height: 1;
  cursor: pointer;
  transition: all .15s;
  box-shadow: var(--shadow-sm);
}
.btn-tool:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

/* ---------- 头部 Hero ---------- */
/* hero 现在是 .prose 内的第一个块，不再是独立的全宽容器。
   这样标题与正文天然同列，且目录无需任何负 margin 就能与之顶对齐。 */
.hero {
  position: relative;
  margin: 0 0 40px;
  padding: 0;
  width: auto;
  max-width: none;
}

.hero-kicker::before {
  content: "";
  width: 38px;
  height: 1px;
  background: var(--line-strong);
}

.hero-title {
  margin: 0 0 26px;
  font-size: clamp(34px, 5vw, 54px);
  line-height: 1.16;
  font-weight: 800;
  letter-spacing: -.022em;
  color: var(--ink);
}

.hero-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 14px;
  color: var(--muted);
}

.hero-tag {
  display: inline-block;
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 12.5px;
  font-weight: 700;
}

/* 「更新于 …」：比发布时间更轻，不抢视线，但字形上能区分开 */
.hero-updated {
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- 主体布局 ---------- */
/* 居中策略：用 width + margin:auto 居中，水平内距只保留安全边距。
   绝不能把 (100vw - track)/2 放进 padding —— 那会和 max-width 重复扣减，
   把正文列挤成 12px（踩过的坑）。 */
.layout {
  position: relative;
  z-index: 1;
  width: var(--track);
  max-width: calc(100vw - 48px);
  margin: 0 auto;
  /* 顶部留白由 layout 统一提供，hero 不再是独立的全宽容器 */
  padding: 56px 0 100px;
  display: grid;
  grid-template-columns: var(--sidew) minmax(0, var(--readw));
  gap: var(--rail-gap);
  align-items: start;
}

/* 文章没有 h2/h3 时（paper.js 会隐藏目录并给 .layout 加 .no-toc）。
   必须把网格一起塌成单列，否则空的目录列仍然占 252px，
   正文会被挤进那一列里 —— 这就是"正文跑到目录位置"的原因。 */
.layout.no-toc {
  grid-template-columns: minmax(0, var(--readw));
  justify-content: center;
}

/* ---------- 目录 ---------- */
/* 目录与正文同处 grid 首行，天生顶端对齐，无需负 margin。
   sticky 起点 = 顶栏高度(60) + 一点呼吸空间。 */
.toc {
  position: sticky;
  top: 84px;
  align-self: start;
  max-height: calc(100vh - 108px);
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: 14px;
  padding-right: 4px;
  scrollbar-width: thin;
}

.toc::-webkit-scrollbar { width: 4px; }
.toc::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 2px;
}
.toc::-webkit-scrollbar-track { background: transparent; }

.toc-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}

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

.toc li { margin: 0; }

.toc a {
  display: block;
  padding: 5px 0 5px 14px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--muted);
  text-decoration: none;
  line-height: 1.5;
  transition: color .15s, border-color .15s;
}
.toc a:hover { color: var(--ink); }

.toc a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 700;
}

.toc .toc-h3 a {
  padding-left: 28px;
  font-size: 13.5px;
}

.toc-backdrop { display: none; }

/* ---------- 正文 ---------- */
.prose {
  min-width: 0;
  font-size: 17px;
  line-height: 1.92;
}

.prose > *:first-child { margin-top: 0; }

.prose p { margin: 0 0 22px; }

.prose h2 {
  position: relative;
  margin: 56px 0 20px;
  padding-bottom: 0;
  font-size: 28px;
  line-height: 1.3;
  font-weight: 800;
  letter-spacing: -.015em;
}
/* 去掉下划线装饰：靠字号/字重/留白区分层级即可，线是多余的视觉噪音 */

.prose h3 {
  margin: 38px 0 14px;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -.01em;
}

.prose strong { font-weight: 700; color: var(--ink); }

.prose a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.prose a:hover { border-bottom-color: var(--accent); }

.prose ul, .prose ol { margin: 0 0 22px; padding-left: 26px; }
.prose li { margin-bottom: 9px; }
.prose li::marker { color: var(--accent); }

/* 行内代码
   之所以把中文字体排在等宽英文字体之前：等宽英文字体没有中文字形，
   遇到「脱水」这类中文时浏览器会回退到系统默认中文字体，
   导致字重/字宽突变（视觉上像"字体退化"）。

   配色用中性灰而不是主色胶囊：技术文章里 `INT_MAX`、`memcpy` 这类
   标识符密度极高，一篇文章能出现近百个。全用 accent-soft 蓝底 +
   accent-ink 蓝字时，整页像刷了一层蓝漆，正文反而被淹掉。
   灰底只承担"这是代码"的区分功能，不参与强调。 */
.prose :not(pre) > code {
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--code-inline-bg);
  color: var(--code-inline-ink);
  font-family: var(--font-sans);
  font-size: .92em;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  border: 1px solid var(--code-inline-line);
}

/* 纯英文/符号的行内代码保持等宽（CJK 字符不参与，避免回退） */
.prose :not(pre) > code code {
  font-family: var(--font-mono);
}

/* 重点标记（Markdown 里写 ==文字==）
   这里才是该用主色的地方：由作者主动挑出来的少数句子。
   有主色底、主色字，和中性灰的行内代码形成明确区分。 */
.prose mark {
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
  /* 去掉浏览器默认的黄色荧光笔底色 */
  -webkit-text-fill-color: currentColor;
}

/* 代码块内的 mark 不适用（保留语法高亮原色） */
.prose pre mark {
  background: none;
  color: inherit;
  padding: 0;
}

/* ---------- 图片 ---------- */
/* Markdown 写 ![说明](路径)。
   图片放在 /img/ 下（构建时不处理，原样上传）。

   要点：
   - max-width:100% + height:auto 保证不溢出正文列（默认会按原始像素撑破布局）
   - 用 border-radius 与卡片语言统一
   - 说明文字走 figcaption，比裸 img 的 alt 更可读
   - 深色模式下轻微降亮，避免纯白截图刺眼 */
.prose figure:not(.figure) {
  margin: 30px 0;
  text-align: center;
}

.prose figure:not(.figure) img,
.prose > img,
.prose p > img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-2);
  box-shadow: var(--shadow-sm);
}

.prose figcaption {
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
  text-align: center;
}

/* 图片本身可点开看原图（点击放大由 paper.js 处理） */
.prose figure:not(.figure) img { cursor: zoom-in; }

/* 深色模式：纯白截图压一点亮度，避免局部过曝 */
html[data-theme="dark"] .prose figure:not(.figure) img,
html[data-theme="dark"] .prose p > img {
  filter: brightness(.92) contrast(1.02);
}
@media (prefers-color-scheme: dark) {
  html[data-theme-auto] .prose figure:not(.figure) img,
  html[data-theme-auto] .prose p > img {
    filter: brightness(.92) contrast(1.02);
  }
}

/* ---------- 引用块 ---------- */
.prose blockquote {
  margin: 26px 0;
  padding: 16px 22px;
  border-left: 3px solid var(--violet);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--violet-soft);
  color: var(--ink-soft);
}
.prose blockquote p { margin: 0; }
.prose blockquote p + p { margin-top: 12px; }

/* ---------- 表格 ---------- */
.table-wrap {
  margin: 26px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.prose thead th {
  padding: 12px 16px;
  background: var(--paper-2);
  text-align: left;
  font-weight: 700;
  font-size: 13.5px;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--line);
}

.prose tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.prose tbody tr:last-child td { border-bottom: none; }
.prose tbody tr:nth-child(even) { background: color-mix(in srgb, var(--paper-2) 55%, transparent); }

/* ---------- 代码块 ---------- */
.figure {
  position: relative;
  margin: 26px 0;
  border-radius: var(--radius);
  background: var(--code-bg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.figure-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 16px;
  background: var(--code-bg-2);
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}

.figure-dots {
  display: flex;
  gap: 6px;
  margin-right: 6px;
}
.figure-dots i {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: block;
}
.figure-dots i:nth-child(1) { background: #ff6b5e; }
.figure-dots i:nth-child(2) { background: #ffc14d; }
.figure-dots i:nth-child(3) { background: #4fcf70; }

.figure-lang {
  font-family: var(--font-mono);
  font-size: 12px;
  color: #8b95a5;
  letter-spacing: .04em;
}

.figure-copy {
  margin-left: auto;
  padding: 4px 11px;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 6px;
  background: rgba(255, 255, 255, .05);
  color: #a8b3c2;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
}
.figure-copy:hover {
  background: rgba(255, 255, 255, .12);
  color: #fff;
  border-color: rgba(255, 255, 255, .28);
}
.figure-copy.done {
  color: #6ee7a0;
  border-color: rgba(110, 231, 160, .4);
}

.figure pre {
  margin: 0;
  padding: 18px 20px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.72;
  color: #c4ccd9;
  tab-size: 4;
}

.figure pre code {
  font-family: inherit;
  background: none;
  padding: 0;
  color: inherit;
  white-space: pre;
}

/* 极简语法着色（highlight.js 的 scope 重映射到这套语义色）
   配色取自 GitHub Dark，和代码块自身的深色底配套。
   新增 tok-* 类时务必同步 tools/highlight.js 的 CLASS_MAP，
   否则会出现"定义了却永远不生成"或"生成了却没样式"的悬空类。 */
.tok-key  { color: #ff7b72; }   /* 关键字：指令名 / 控制流 */
.tok-reg  { color: #ffa657; }   /* 寄存器：汇编的 eax / xmm0 / rax */
.tok-str  { color: #a5d6ff; }
.tok-num  { color: #79c0ff; }
.tok-com  { color: #8b949e; font-style: italic; }
.tok-fn   { color: #d2a8ff; }
.tok-del  { color: #ffa198; text-decoration: line-through; }
.tok-em   { font-style: italic; }
.tok-strong { font-weight: 700; }
.tok-plain { color: inherit; }

/* ---------- 文末 ---------- */
/* 去掉顶部分隔线，改用留白 + 次级文字色，避免与正文形成突兀的"分界感" */
.article-end {
  /* 版权块在前，这里只需要一点收尾间距，不再需要 72px 大留白 */
  margin-top: 28px;
  padding-top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 13.5px;
  color: var(--muted);
  letter-spacing: .01em;
}

/* ---------- 文末版权声明 ---------- */
/* 位置：评论之上、文末导航之下。
   视觉上要"存在但不打扰"：左边一道细线 + 略小的字号，
   不喧宾夺主，但确实在读者看完正文时能扫到。 */
.article-copyright {
  margin-top: 48px;
  padding: 18px 20px;
  border-left: 2px solid var(--line-strong);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: color-mix(in srgb, var(--paper-2) 60%, transparent);
  font-size: 13px;
  line-height: 1.85;
  color: var(--muted);
}

.article-copyright p {
  margin: 0;
}

.article-copyright p + p {
  margin-top: 6px;
}

.article-copyright-line {
  font-weight: 600;
  color: var(--ink-soft);
}

.article-copyright-mark {
  margin-right: 2px;
  font-weight: 700;
}

.article-copyright-year {
  font-variant-numeric: tabular-nums;
}

.article-copyright a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.article-copyright a:hover {
  border-bottom-color: var(--accent);
}

/* 原文链接：等宽字体，长 URL 自动断行不撑破布局 */
.article-copyright-url {
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
}

.article-end a { color: inherit; text-decoration: none; }
.article-end a:hover { color: var(--accent); text-decoration: underline; }

/* 返回按钮：去掉边框胶囊，改成文字箭头，与文末排版融为一体 */
.back-home {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  transition: color .15s, gap .18s;
}
.back-home:hover {
  color: var(--accent);
  text-decoration: none;
  gap: 10px;
}

/* ---------- 可折叠区块（details）---------- */
.prose details {
  margin: 26px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  overflow: hidden;
  transition: box-shadow .2s;
}
.prose details[open] { box-shadow: var(--shadow-sm); }

.prose summary {
  padding: 13px 18px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 9px;
  user-select: none;
  transition: color .15s, background .15s;
}
.prose summary::-webkit-details-marker { display: none; }
.prose summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform .22s cubic-bezier(.4, 0, .2, 1);
  flex: 0 0 auto;
}
.prose details[open] summary::before { transform: rotate(90deg); }
.prose summary:hover { color: var(--accent); background: var(--paper-2); }
.prose details[open] > summary { border-bottom: 1px solid var(--line); }

/* 展开动画：用 ::details-content + interpolate-size 实现双向高度过渡。
   这是目前唯一能同时让"展开"和"收起"都平滑的原生方案（2025 Baseline）。
   - block-size: 0 → auto 负责高度
   - content-visibility ... allow-discrete 让收起的瞬间内容不被立即移除
   旧浏览器不认识这些规则会直接忽略，details 仍能正常开合（只是无动画）。 */
.prose details::details-content {
  block-size: 0;
  overflow: clip;
  transition:
    block-size 320ms cubic-bezier(.4, 0, .2, 1),
    content-visibility 320ms allow-discrete,
    opacity 260ms ease;
  opacity: 0;
}
.prose details[open]::details-content {
  block-size: auto;
  opacity: 1;
}

/* details 内部的代码块去掉外框重复边距 */
.prose details .figure { margin: 16px 18px 18px; }

/* ---------- 回到顶部 ---------- */
#toTop {
  position: fixed;
  right: 28px;
  bottom: 30px;
  z-index: 70;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--ink-soft);
  box-shadow: var(--shadow);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: all .22s;
  font-size: 17px;
}
#toTop.show {
  opacity: 1;
  visibility: visible;
  transform: none;
}
#toTop:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- 打印 ---------- */
@media print {
  #progress, .topbar-actions, #toTop, .toc, .figure-copy { display: none !important; }
  body { background: #fff; font-size: 12pt; }
  body::before { display: none; }
  .layout { display: block; max-width: none; padding: 0; }
  .figure { box-shadow: none; border: 1px solid #ddd; }
  .prose h2 { break-after: avoid; }
  .prose h2, .prose h3 { break-inside: avoid; }
  .figure, .table-wrap { break-inside: avoid; }
}

/* ---------- 移动端 ---------- */
@media (max-width: 980px) {
  .layout {
    display: block;
    width: auto;
    max-width: none;
    padding: 28px 20px 80px;
  }
  /* hero 在移动端是正文内区块，只留底部间距 */
  .hero { margin-bottom: 28px; padding: 0; }

  .toc {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 82vw;
    max-height: none;
    z-index: 95;
    padding: 24px 20px;
    background: var(--paper);
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow);
    transform: translateX(-100%);
    transition: transform .26s cubic-bezier(.4, 0, .2, 1);
    overflow-y: auto;
  }
  .toc.open { transform: none; }

  .toc-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 94;
    background: rgba(20, 22, 26, .38);
    opacity: 0;
    visibility: hidden;
    transition: opacity .26s, visibility .26s;
  }
  .toc-backdrop.show { opacity: 1; visibility: visible; }

  .topbar-nav { display: none; }
  .hero-title { font-size: 32px; }
  .prose { font-size: 16.5px; }
  .prose h2 { font-size: 23px; }
  .prose h3 { font-size: 18.5px; }
  #toTop { right: 16px; bottom: 18px; }
}

@media (max-width: 520px) {
  .btn-tool .label { display: none; }
  .btn-tool { padding: 7px 11px; }
  .hero-meta { font-size: 13px; gap: 10px; }
  .prose table { font-size: 14px; }
  .prose thead th, .prose tbody td { padding: 10px 12px; }
}
