/* ═══════════════════════════════════════════════════════════
 * Xisound · 视觉修复补丁（v1.2）
 * 加载顺序：xiyin-brand.css → xiyin-extra.css → xiyin-patch.css
 * v1.2 修复：
 *   - 回退 H1 修改（保留 extra.css 原 grid 布局，只修 Hero 内）
 *   - 表格顶线/侧线同长（顶线延伸到圆角外并加圆角匹配）
 *   - Tab 激活底线改为玫瑰金（覆盖 Material 默认 accent）
 *   - 彗星粒子 + Hero grid 两行（v1.1 留存）
 *   - Mermaid 容器配色改为 XiStudio canvas 深夜蓝
 * ═══════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────── */
/*  1. L1A Hero 排版（v1.1 · grid 两行布局 · 保留）              */
/* ─────────────────────────────────────────────────────────── */

/* 同时兼容 body.level-l1a 和 html[data-xy-level="l1a"] 两种来源 */
body.level-l1a .md-typeset .xy-hero,
html[data-xy-level="l1a"] .md-typeset .xy-hero {
  min-height: 80vh;
  padding: 70px 40px 40px;
  display: grid;
  grid-template-rows: 1fr auto;
  grid-auto-rows: 0;       /* 任何意外多出的 grid row 强制 0 高（如 .xy-comets 动态追加） */
  grid-row-gap: 40px;
  align-items: stretch;
  justify-items: center;
}

/* .xy-hero-main：所有 hero_* 文字元素的容器，flex 列紧凑堆叠居中 */
.md-typeset .xy-hero .xy-hero-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
  z-index: 10;
  position: relative;
  gap: 8px;
}
/* 压缩 main 内部元素的默认 margin，避免"依次展开"视觉 */
.md-typeset .xy-hero .xy-hero-main > * {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

/* L1A：main 在 grid row 1，stats 在 row 2 */
body.level-l1a .md-typeset .xy-hero .xy-hero-main,
html[data-xy-level="l1a"] .md-typeset .xy-hero .xy-hero-main {
  grid-row: 1;
  align-self: center;
}

body.level-l1a .md-typeset .xy-hero-stats,
html[data-xy-level="l1a"] .md-typeset .xy-hero-stats {
  position: static;
  transform: none;
  grid-row: 2;
  align-self: end;
  width: 100%;
  max-width: 900px;
  margin: 0;
  z-index: 10;
}

/* hero_meta 单行居中 */
.md-typeset .xy-hero .xy-hero-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0 18px;
  text-align: center;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--pearl-mute);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin: 10px auto 0;
  max-width: 720px;
}

body.level-l1a .md-typeset .xy-hero h1,
html[data-xy-level="l1a"] .md-typeset .xy-hero h1 {
  font-size: 48px !important;
  margin-bottom: 18px !important;
  line-height: 1.2 !important;
  white-space: nowrap !important;
  max-width: 100% !important;
  overflow: visible !important;
}
body.level-l1a .md-typeset .xy-hero .xy-hero-sub,
html[data-xy-level="l1a"] .md-typeset .xy-hero .xy-hero-sub {
  font-size: 18px;
  margin-bottom: 14px;
}
body.level-l1a .md-typeset .xy-hero .xy-hero-tagline,
html[data-xy-level="l1a"] .md-typeset .xy-hero .xy-hero-tagline {
  font-size: 15px;
  margin: 20px auto 0;
}

@media screen and (max-width: 900px) {
  body.level-l1a .md-typeset .xy-hero,
  html[data-xy-level="l1a"] .md-typeset .xy-hero {
    min-height: auto;
    padding: 50px 22px 32px;
    display: block;
  }
  body.level-l1a .md-typeset .xy-hero-stats,
  html[data-xy-level="l1a"] .md-typeset .xy-hero-stats {
    margin-top: 32px;
  }
  body.level-l1a .md-typeset .xy-hero h1,
  html[data-xy-level="l1a"] .md-typeset .xy-hero h1 { font-size: 38px; }
}

/* L1B Hero */
body.level-l1b .md-typeset .xy-hero,
html[data-xy-level="l1b"] .md-typeset .xy-hero {
  min-height: 42vh;
  padding: 70px 40px 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
body.level-l1b .md-typeset .xy-hero h1,
html[data-xy-level="l1b"] .md-typeset .xy-hero h1 {
  font-size: 44px !important;
  white-space: nowrap !important;
  max-width: 100% !important;
  line-height: 1.2 !important;
}

/* ─────────────────────────────────────────────────────────── */
/*  2. H1 修复（v1.2 回退）                                      */
/*     - 正文 H1 保留 extra.css 的 grid 三列 domain 卡样式        */
/*     - 只对 Hero 内 H1 用 !important 保证大字渐变               */
/*     （取消 v1.1 的无条件 block 改写，那个改动导致文本拉散）    */
/* ─────────────────────────────────────────────────────────── */

.md-typeset .xy-hero h1 {
  display: block !important;
  text-align: center !important;
  padding: 0 !important;
  grid-template-columns: none !important;
  background: var(--gradient-brand-name) !important;
  -webkit-background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  background-clip: text !important;
  border: none !important;
  border-radius: 0 !important;
  margin: 0 0 14px !important;
}

/* ─────────────────────────────────────────────────────────── */
/*  2b. 正文 H1 修复（v1.8）                                    */
/*     - Hero 开启时：正文第一个 H1 与 frontmatter.title 重复 → 隐藏   */
/*     - Hero 未开启时：H1 从 grid 三列改为简洁 block，避免文字堆叠   */
/* ─────────────────────────────────────────────────────────── */

/* Hero 存在时，紧跟 Hero 的第一个 H1 会与 hero_title 重复，隐藏之 */
.md-typeset .xy-hero + h1,
.md-typeset .xy-hero ~ h1:first-of-type,
article > .md-typeset > .xy-hero + h1,
.xy-hero + .md-content h1:first-child {
  display: none !important;
}
/* 更稳妥：Hero section 之后 article 首个 H1 直接隐藏（用 JS 辅助见 wrap.js） */
.md-typeset h1.xy-hidden-dup {
  display: none !important;
}

/* 正文 H1：grid 三列 → block，文字正常排布（Hero 内 H1 已由上面规则用 !important 保护大字渐变） */
.md-typeset h1 {
  display: block !important;
  grid-template-columns: none !important;
  gap: 0 !important;
  padding: 22px 30px !important;
  text-align: left !important;
  font-size: 26px !important;
  line-height: 1.35 !important;
}
/* Hero 内 H1 重新恢复为居中大字渐变样式（优先级 > 上面通用规则） */
.md-typeset .xy-hero h1 {
  display: block !important;
  text-align: center !important;
  padding: 0 !important;
  font-size: 48px !important;
  line-height: 1.2 !important;
  white-space: nowrap !important;
}

/* ─────────────────────────────────────────────────────────── */
/*  3. 三色彗星粒子（v1.5.1 · 强制 absolute 不占 grid cell）      */
/* ─────────────────────────────────────────────────────────── */

.xy-hero .xy-comets,
.xy-comets {
  position: absolute !important;
  inset: 0 !important;
  pointer-events: none !important;
  z-index: 2 !important;
  overflow: hidden !important;
  width: auto !important;
  height: auto !important;
}

.xy-comet {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle,
    var(--comet-color) 0%,
    var(--comet-color) 40%,
    transparent 70%);
  box-shadow:
    0 0 12px var(--comet-glow),
    0 0 24px var(--comet-glow);
  transform:
    translate(-50%, -30%)
    rotate(var(--comet-angle))
    translateX(420px);
  opacity: 0;
  animation: xy-comet-fly 4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.xy-comet::before {
  content: '';
  position: absolute;
  right: 50%;
  top: 50%;
  width: 60px;
  height: 2px;
  transform: translateY(-50%);
  background: linear-gradient(270deg, var(--comet-color), transparent);
  opacity: 0.9;
  filter: blur(0.5px);
}

@keyframes xy-comet-fly {
  0%   { opacity: 0; transform: translate(-50%, -30%) rotate(var(--comet-angle)) translateX(420px) scale(0.6); }
  20%  { opacity: 1; transform: translate(-50%, -30%) rotate(var(--comet-angle)) translateX(320px) scale(1); }
  90%  { opacity: 1; transform: translate(-50%, -30%) rotate(var(--comet-angle)) translateX(20px) scale(1.2); }
  95%  { opacity: 1; transform: translate(-50%, -30%) rotate(var(--comet-angle)) translateX(0) scale(2); }
  100% { opacity: 0; transform: translate(-50%, -30%) rotate(var(--comet-angle)) translateX(0) scale(0); }
}

/* ─────────────────────────────────────────────────────────── */
/*  4. 代码块顶线对齐（v1.0 留存）                                */
/* ─────────────────────────────────────────────────────────── */

.md-typeset .highlight,
.md-typeset .highlighttable {
  margin: 20px 0 !important;
  border-radius: 6px;
  overflow: hidden;
  isolation: isolate;
}

.md-typeset .highlight::before,
.md-typeset .highlighttable::before {
  left: 0 !important;
  right: 0 !important;
  height: 3px !important;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
  z-index: 3;
}

.md-typeset .highlight pre {
  margin: 0 !important;
  padding: 14px 18px !important;
}
.md-typeset .highlighttable .highlight pre {
  padding: 14px 18px !important;
}
.md-typeset .highlighttable .linenos {
  padding: 14px 10px !important;
}

/* ─────────────────────────────────────────────────────────── */
/*  5. 表格（v2.1 · 直接给 .md-typeset__table wrapper 加外框）    */
/*     v8 诊断关键发现：                                           */
/*       - Material 9.7 其实给 table 套了 .md-typeset__table       */
/*         wrapper (display: inline-block)                          */
/*       - wrapper 宽度比 table 宽 36px → 用户看到外框超出          */
/*       - 我之前给 table 本身加 border 的方案被 Material 覆盖      */
/*     → v2.1 直接利用现有 .md-typeset__table wrapper：             */
/*       - wrapper 的 inline-block 自然贴合 table 宽度（只是多 36px 的 margin）*/
/*       - 强力覆盖 Material 默认样式，加玫瑰金左竖条+三色顶线     */
/* ─────────────────────────────────────────────────────────── */

/* ⭐ v2.2：我们自己的 .xy-tbox 容器（由 xiyin-wrap.js 替换 Material 的 .md-typeset__table）
   - display: block + width: fit-content 贴合 table 宽度同时保持块级流
   - Material JS 不会碰我们自己的 class，样式永不被覆写 */
.xy-tbox {
  display: block;
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
  position: relative;
  border-radius: 6px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--yin-color);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  margin: 20px 0;
  padding: 0;
  isolation: isolate;
}
.xy-tbox > table {
  margin: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  width: auto;
}

/* 三色顶线：画在 .xy-tbox 的 ::before 上 */
.xy-tbox::before {
  content: '';
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg,
    var(--xi-color), var(--yin-color), var(--sheng-color));
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
  z-index: 2;
  pointer-events: none;
}

/* Material 的 .md-typeset__table 兜底透明化（防止 JS 没跑时也不会出现多余外框） */
.md-typeset__table {
  all: unset;
  display: contents;
}
.md-typeset__table::before {
  display: none !important;
  content: none !important;
}

/* ⭐ Material JS 延迟注入的 .md-typeset__scrollwrap（DevTools 勘测发现这是真凶） */
/*    用户报告"1-2 秒后表格偏左"就是因为这个外层 scrollwrap 在 DOMContentLoaded 后才出现 */
.md-typeset__scrollwrap {
  all: unset;
  display: contents;
}
.md-typeset__scrollwrap::before,
.md-typeset__scrollwrap::after {
  display: none !important;
  content: none !important;
}

/* 残留的旧 .xy-table-wrap 同样透明化 */
.xy-table-wrap {
  all: unset;
  display: contents;
}
.xy-table-wrap::before {
  display: none !important;
  content: none !important;
}

/* 暗色模式 */
[data-md-color-scheme="xiyin-dark"] .xy-tbox {
  border-color: rgba(212,165,116,0.2);
  border-left-color: var(--yin-color);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ─────────────────────────────────────────────────────────── */
/*  6. ⭐ pymdownx Tabs 激活态（v1.4 · Material 真实机制）          */
/*     根因（v1.2/v1.3 失败）：Material 9.7 的 tabbed-alternate    */
/*     不再用 input:checked + label 的 border-bottom，而是：        */
/*     - label 里包了 <a>（!）                                     */
/*     - 激活指示器是 .tabbed-labels::after 伪元素                  */
/*     - 位置由 CSS 变量 --md-indicator-x / --md-indicator-width   */
/*       控制（切换 Tab 时 JS 滑动）                                */
/*     v1.4 做法：直接覆盖 .tabbed-labels::after 的 background     */
/*     + 用 a[aria-selected=true] / 通用 a 控制文字颜色            */
/* ─────────────────────────────────────────────────────────── */

.md-typeset .tabbed-set {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(212,165,116,0.25);
  margin: 20px 0;
}
.md-typeset .tabbed-set::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--gradient-trinity);
  z-index: 5;
  pointer-events: none;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
}

.md-typeset .tabbed-labels {
  background: rgba(212,165,116,0.06);
  padding-top: 3px;
}
/* ⭐ 强力清除 Material 默认的底部 inset box-shadow（诊断发现是 rgb(184,197,209) 0 -1px 0 0 inset）*/
.md-typeset .tabbed-alternate > .tabbed-labels,
.md-typeset .tabbed-set > .tabbed-labels,
.md-typeset .tabbed-labels,
.md-typeset .tabbed-labels.tabbed-labels--linked {
  box-shadow: none !important;
  border-bottom: none !important;
}
.md-typeset .tabbed-labels::before,
.md-typeset .tabbed-labels::after {
  display: none !important;
  content: none !important;
  box-shadow: none !important;
  border: none !important;
}

/* 所有 Tab 标签默认颜色（包内 <a>） */
.md-typeset .tabbed-labels > label > a,
.md-typeset .tabbed-labels > label {
  font-family: var(--font-sans-mixed);
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--pearl-mute) !important;
  transition: color 0.2s;
}
.md-typeset .tabbed-labels > label:hover > a,
.md-typeset .tabbed-labels > label:hover {
  color: var(--yin-color-deep) !important;
}

/* ⭐ Tab 激活态（v1.5 · JS 运行时打 .xy-tab-active class） */
/*    xiyin-wrap.js 给激活的 label 加 class="xy-tab-active"       */
/*    CSS 直接针对这个 class 写，完全避开 Material 的 :checked 选择器战争 */
.md-typeset .tabbed-labels > label.xy-tab-active,
.md-typeset .tabbed-labels > label.xy-tab-active > a {
  color: var(--yin-color-deep) !important;
  border-bottom: 2px solid var(--yin-color) !important;
}

[data-md-color-scheme="xiyin-dark"] .md-typeset .tabbed-labels > label.xy-tab-active,
[data-md-color-scheme="xiyin-dark"] .md-typeset .tabbed-labels > label.xy-tab-active > a {
  color: var(--yin-color-light) !important;
  border-bottom-color: var(--yin-color-light) !important;
}

/* Tab 内代码块顶线不超出容器 */
.md-typeset .tabbed-content .highlight,
.md-typeset .tabbed-content .highlighttable,
.md-typeset .tabbed-block .highlight,
.md-typeset .tabbed-block .highlighttable {
  margin: 12px 0 !important;
  border-radius: 4px;
}

.md-typeset .tabbed-content .highlight::before,
.md-typeset .tabbed-content .highlighttable::before,
.md-typeset .tabbed-block .highlight::before,
.md-typeset .tabbed-block .highlighttable::before {
  left: 0 !important;
  right: 0 !important;
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}

/* ─────────────────────────────────────────────────────────── */
/*  ⭐ Step 1 · Admonition 八色统一为极光青（v2.5 · 3+1 色系）    */
/*     根因：extra.css 为 note/warning/success/danger 分别定义了  */
/*     不同的 border-left 和 title 背景 → 一页 8 种 Admonition     */
/*     出现 8 种颜色，视觉花乱。                                   */
/*     方案：统一用 --sheng-color 极光青作为唯一标识色，           */
/*     8 种类型仅通过 Material 自带的 icon + title 文字区分。      */
/* ─────────────────────────────────────────────────────────── */

/* 统一所有 Admonition 变体的左竖条为极光青 */
.md-typeset .admonition,
.md-typeset .admonition.note,
.md-typeset .admonition.info,
.md-typeset .admonition.tip,
.md-typeset .admonition.success,
.md-typeset .admonition.warning,
.md-typeset .admonition.danger,
.md-typeset .admonition.example,
.md-typeset .admonition.abstract,
.md-typeset .admonition.quote,
.md-typeset .admonition.failure,
.md-typeset .admonition.bug,
.md-typeset .admonition.question,
.md-typeset details,
.md-typeset details.note,
.md-typeset details.info,
.md-typeset details.tip,
.md-typeset details.success,
.md-typeset details.warning,
.md-typeset details.danger,
.md-typeset details.example,
.md-typeset details.abstract,
.md-typeset details.quote {
  border-left-color: var(--sheng-color) !important;
}

/* 统一所有 Admonition title 区域的背景与图标色为极光青 */
.md-typeset .admonition-title,
.md-typeset details > summary,
.md-typeset .admonition.note .admonition-title,
.md-typeset .admonition.info .admonition-title,
.md-typeset .admonition.tip .admonition-title,
.md-typeset .admonition.success .admonition-title,
.md-typeset .admonition.warning .admonition-title,
.md-typeset .admonition.danger .admonition-title,
.md-typeset .admonition.example .admonition-title,
.md-typeset .admonition.abstract .admonition-title,
.md-typeset .admonition.quote .admonition-title,
.md-typeset .admonition.failure .admonition-title,
.md-typeset .admonition.bug .admonition-title,
.md-typeset .admonition.question .admonition-title,
.md-typeset details > summary,
.md-typeset details.note > summary,
.md-typeset details.info > summary,
.md-typeset details.tip > summary,
.md-typeset details.warning > summary {
  background: rgba(93, 222, 207, 0.08) !important;
  color: var(--sheng-color-deep) !important;
}

/* 图标方块颜色统一（Material 的 ::before 是图标） */
.md-typeset .admonition-title::before,
.md-typeset details > summary::before,
.md-typeset .admonition.note .admonition-title::before,
.md-typeset .admonition.info .admonition-title::before,
.md-typeset .admonition.tip .admonition-title::before,
.md-typeset .admonition.success .admonition-title::before,
.md-typeset .admonition.warning .admonition-title::before,
.md-typeset .admonition.danger .admonition-title::before,
.md-typeset .admonition.example .admonition-title::before,
.md-typeset .admonition.abstract .admonition-title::before,
.md-typeset .admonition.quote .admonition-title::before,
.md-typeset .admonition.failure .admonition-title::before,
.md-typeset .admonition.bug .admonition-title::before,
.md-typeset .admonition.question .admonition-title::before,
.md-typeset details.note > summary::before,
.md-typeset details.info > summary::before,
.md-typeset details.tip > summary::before,
.md-typeset details.warning > summary::before {
  background-color: var(--sheng-color) !important;
}

/* 暗色模式下统一用极光青浅色提高对比度 */
[data-md-color-scheme="xiyin-dark"] .md-typeset .admonition-title,
[data-md-color-scheme="xiyin-dark"] .md-typeset details > summary {
  background: rgba(93, 222, 207, 0.12) !important;
  color: var(--sheng-color-light) !important;
}

/* ─────────────────────────────────────────────────────────── */
/*  7. ⭐ Mermaid 容器 · 对齐 XiStudio canvas 配色（v1.2）        */
/*     - 画布底 = Night Deep #0B1C2E（夜蓝）                      */
/*     - 节点边 = 玫瑰金 · 文字 = 珍珠白                           */
/*     - 节点间线 = 曦紫（由 mermaid.js 的 lineColor 控制）       */
/* ─────────────────────────────────────────────────────────── */

.md-typeset .mermaid {
  margin: 20px 0;
  padding: 24px 16px;
  background: linear-gradient(180deg, #0B1C2E, #14283F);
  border-radius: 8px;
  border: 1px solid rgba(212,165,116,0.25);
  border-left: 3px solid var(--yin-color);
  text-align: center;
  overflow-x: auto;
  position: relative;
  isolation: isolate;
}

.md-typeset .mermaid::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--gradient-trinity);
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  z-index: 2;
}

.md-typeset .mermaid svg {
  max-width: 100%;
  height: auto;
}

/* Mermaid 文字在深色画布上反白 */
.md-typeset .mermaid .nodeLabel,
.md-typeset .mermaid .label,
.md-typeset .mermaid foreignObject div {
  color: var(--pearl) !important;
}

[data-md-color-scheme="xiyin-dark"] .md-typeset .mermaid {
  background: linear-gradient(180deg, #050812, #0B1C2E);
}

/* ─────────────────────────────────────────────────────────── */
/*  ⭐ Step 2c · Mermaid 色例图例（L0-L5 层级色标签条）           */
/*     作者可在图后 markdown 写 `<div class="mermaid-legend">`     */
/*     内含 .xy-leg-item 小色块 + 文字，自动水平排列               */
/* ─────────────────────────────────────────────────────────── */

.md-typeset .mermaid-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  margin: -12px 0 20px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--pearl-dim);
  background: rgba(11, 28, 46, 0.6);
  border-left: 3px solid var(--yin-color);
  border-radius: 0 4px 4px 0;
}
.md-typeset .mermaid-legend .xy-leg-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.md-typeset .mermaid-legend .xy-leg-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
  flex-shrink: 0;
}
.md-typeset .mermaid-legend .xy-leg-l0 { background: #2E8D7E; }
.md-typeset .mermaid-legend .xy-leg-l1 { background: #5DDECF; }
.md-typeset .mermaid-legend .xy-leg-l2 { background: #E8C9A0; }
.md-typeset .mermaid-legend .xy-leg-l3 { background: #D4A574; }
.md-typeset .mermaid-legend .xy-leg-l4 { background: #C77DFF; }
.md-typeset .mermaid-legend .xy-leg-l5 { background: #9D4EDD; }
.md-typeset .mermaid-legend .xy-leg-success { background: #5DDECF; }
.md-typeset .mermaid-legend .xy-leg-warn    { background: #D4A574; }
.md-typeset .mermaid-legend .xy-leg-error   { background: #B87A6F; }
.md-typeset .mermaid-legend .xy-leg-end     { background: #14283F; border: 1px solid #9D4EDD; }

/* ─────────────────────────────────────────────────────────── */
/*  ⭐ Step 3 · 代码语法高亮（v2 · 3+1 色系 · 夜蓝底最高对比度）   */
/*     根因（v1 失败）：                                          */
/*       - C 里 printf/malloc 被 Pygments 标为 .nb 或 .n，         */
/*         v1 只给 .nf/.fm/.nc 上色，导致大量函数名回落到          */
/*         Material 默认的 #0066cc（夜蓝底上几乎隐形）             */
/*       - v1 函数名用 #5DDECF 极光青，与字符串香槟金区分度弱       */
/*     v2 方案：                                                   */
/*       1. 给 .md-typeset .highlight pre / code 兜底珍珠白        */
/*          → 任何未被特定 token 类覆盖的文本都不会是黑或蓝         */
/*       2. 函数名（所有 name-like token）统一香槟金 #FFD89E        */
/*          → 在夜蓝底上是对比度最高的色，绝不会"看不清"             */
/*       3. 字符串改回极光青，释放香槟金给函数名                    */
/* ─────────────────────────────────────────────────────────── */

/* ⭐ 兜底：代码块内所有裸文本 → 珍珠白（防止 Material 默认黑色/蓝色穿透） */
.md-typeset .highlight pre,
.md-typeset .highlight code,
.md-typeset .highlighttable pre,
.md-typeset .highlighttable code,
.md-typeset pre > code {
  color: #F0F4F8 !important;
}

/* 关键字 → 浅紫（int / void / return / if / class / def） */
.md-typeset .highlight .k,
.md-typeset .highlight .kc,
.md-typeset .highlight .kd,
.md-typeset .highlight .kn,
.md-typeset .highlight .kp,
.md-typeset .highlight .kr,
.md-typeset .highlight .kt {
  color: #C77DFF !important;
  font-weight: 500;
}

/* ⭐ 函数名 / 类名 / Builtin → 香槟金（最高对比度 · v2 核心修复）
   覆盖 C 的 printf/malloc (.nb) + 自定义函数定义名 (.nf)
   + 函数调用名 (.n 时 Material 有时这么标) + 类名 (.nc) */
.md-typeset .highlight .nf,
.md-typeset .highlight .fm,
.md-typeset .highlight .nc,
.md-typeset .highlight .nb,
.md-typeset .highlight .bp,
.md-typeset .highlight .nn {
  color: #FFD89E !important;
  font-weight: 600;
}

/* 字符串 → 极光青（v2 从香槟金让位给函数名） */
.md-typeset .highlight .s,
.md-typeset .highlight .s1,
.md-typeset .highlight .s2,
.md-typeset .highlight .sb,
.md-typeset .highlight .sc,
.md-typeset .highlight .sd,
.md-typeset .highlight .se,
.md-typeset .highlight .sh,
.md-typeset .highlight .si,
.md-typeset .highlight .sx,
.md-typeset .highlight .sr,
.md-typeset .highlight .ss,
.md-typeset .highlight .dl {
  color: #5DDECF !important;
}

/* 数字 → 玫瑰金 */
.md-typeset .highlight .m,
.md-typeset .highlight .mb,
.md-typeset .highlight .mf,
.md-typeset .highlight .mh,
.md-typeset .highlight .mi,
.md-typeset .highlight .mo,
.md-typeset .highlight .il {
  color: #D4A574 !important;
}

/* 注释 → 灰（斜体 + 提亮可读性） */
.md-typeset .highlight .c,
.md-typeset .highlight .c1,
.md-typeset .highlight .cm,
.md-typeset .highlight .cp,
.md-typeset .highlight .cpf,
.md-typeset .highlight .cs,
.md-typeset .highlight .ch {
  color: #8A99A8 !important;
  font-style: italic;
}

/* 变量名 / 参数 / 属性 / 普通标识符 → 珍珠白 */
.md-typeset .highlight .n,
.md-typeset .highlight .na,
.md-typeset .highlight .nv,
.md-typeset .highlight .nx,
.md-typeset .highlight .nl,
.md-typeset .highlight .no,
.md-typeset .highlight .py,
.md-typeset .highlight .vc,
.md-typeset .highlight .vg,
.md-typeset .highlight .vi,
.md-typeset .highlight .vm {
  color: #F0F4F8 !important;
}

/* 标签 / 装饰器 / 特殊 → 浅紫（与关键字一致，有语法语义） */
.md-typeset .highlight .nd,
.md-typeset .highlight .ni,
.md-typeset .highlight .ne,
.md-typeset .highlight .nt {
  color: #C77DFF !important;
}

/* 操作符 / 标点 → 珍珠白暗（降低视觉权重） */
.md-typeset .highlight .o,
.md-typeset .highlight .p,
.md-typeset .highlight .ow {
  color: #B8C5D1 !important;
}

/* 错误 token → 赤陶（标红，仅此处破例使用非 3+1 色） */
.md-typeset .highlight .err {
  color: #B87A6F !important;
  background: transparent !important;
  border-bottom: 1px dotted #B87A6F !important;
}

/* 高亮行（hl_lines） */
.md-typeset .highlight .hll {
  background: rgba(212, 165, 116, 0.15) !important;
  display: block;
  margin: 0 -18px;
  padding: 0 18px;
  border-left: 2px solid var(--yin-color);
}

/* ─────────────────────────────────────────────────────────── */
/*  ⭐ Step 4 · 代码块单层外框（v3 · 条件化外框承担方案）         */
/*     v2.6 失败：同时给 .highlight 和 .highlighttable 画外框，   */
/*     有行号时会出现两层嵌套边框。                                 */
/*                                                                 */
/*     v3 方案：由外向内"谁是最外层谁画框"，另一层全透明           */
/*       - 有行号（pymdownx 包 .highlighttable > .highlight）：     */
/*         .highlighttable 画外框，内层 .highlight 透明              */
/*       - 无行号（仅 .highlight）：                                */
/*         .highlight 画外框                                         */
/* ─────────────────────────────────────────────────────────── */

/* ───── 情景 A：有行号 → 外框在 .highlighttable 上 ───── */
/*   ⚠️ 关键：必须保留 table 原生 display，否则浏览器首帧会按 block
     重排行号列，出现"闪一下不协调的行号"FOUC。 */
.md-typeset .highlighttable {
  border: 1px solid rgba(212, 165, 116, 0.2) !important;
  border-left: 3px solid var(--yin-color) !important;
  border-radius: 6px !important;
  overflow: hidden !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08) !important;
  background: var(--night-deep) !important;
  position: relative !important;
  margin: 20px 0 !important;
  isolation: isolate;
  border-collapse: separate !important;
  border-spacing: 0 !important;
  /* 不设 display/width，保持 <table> 默认行为 */
}
.md-typeset .highlighttable::before {
  content: '' !important;
  display: block !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  height: 3px !important;
  background: linear-gradient(90deg,
    var(--xi-color), var(--yin-color), var(--sheng-color)) !important;
  border-top-left-radius: 6px !important;
  border-top-right-radius: 6px !important;
  z-index: 3 !important;
  pointer-events: none !important;
}
.md-typeset .highlighttable > tbody,
.md-typeset .highlighttable > tbody > tr {
  background: transparent !important;
  border: none !important;
}
.md-typeset .highlighttable > tbody > tr > td {
  padding: 0 !important;
  border: none !important;
  background: transparent !important;
}

/* 内层 .highlight 透明化（不重画外框、不画顶线） */
.md-typeset .highlighttable .highlight {
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: visible !important;
}
.md-typeset .highlighttable .highlight::before {
  display: none !important;
  content: none !important;
  background: none !important;
}

/* ───── 情景 B：无行号（单独 .highlight） → 外框在 .highlight 上 ───── */
/*   注意：选择器限定为 ":not(.highlighttable .highlight)" 是不可行的 CSS，
     所以这里用通用 .highlight 规则，然后情景 A 的内层规则优先级更高会覆盖。 */
.md-typeset .highlight {
  border: 1px solid rgba(212, 165, 116, 0.2) !important;
  border-left: 3px solid var(--yin-color) !important;
  border-radius: 6px !important;
  overflow: hidden !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08) !important;
  background: var(--night-deep) !important;
  position: relative !important;
  margin: 20px 0 !important;
  isolation: isolate;
}
.md-typeset .highlight::before {
  content: '' !important;
  display: block !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  height: 3px !important;
  background: linear-gradient(90deg,
    var(--xi-color), var(--yin-color), var(--sheng-color)) !important;
  border-top-left-radius: 6px !important;
  border-top-right-radius: 6px !important;
  z-index: 3 !important;
  pointer-events: none !important;
}

/* pre / code 本身 → 无边框、透明底（避免第三层） */
.md-typeset .highlight pre,
.md-typeset .highlighttable .highlight pre,
.md-typeset pre {
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
}

/* ─────────────────────────────────────────────────────────── */
/*  ⭐ Step 4b · 嵌套作用域代码块（Tab / Admonition / details 内）  */
/*     根因：Tab/Admonition 内的代码块有时会同时保留外层容器自己     */
/*     的内边框 + 内层 .highlight 的外框，出现"第二层外框"残影       */
/* ─────────────────────────────────────────────────────────── */

/* Tab 内代码块：.highlighttable 已经承担外框，pre/code 再无外框 */
.md-typeset .tabbed-content .highlighttable,
.md-typeset .tabbed-block .highlighttable {
  margin: 12px 0 !important;
  border-radius: 4px !important;
}
.md-typeset .tabbed-content .highlighttable::before,
.md-typeset .tabbed-block .highlighttable::before {
  border-top-left-radius: 4px !important;
  border-top-right-radius: 4px !important;
}

/* Admonition / details 内代码块不再画自己的三色顶线（避免与 admonition
   本身的顶线叠加产生"双线"视觉错觉） */
.md-typeset .admonition .highlight::before,
.md-typeset .admonition .highlighttable::before,
.md-typeset details .highlight::before,
.md-typeset details .highlighttable::before {
  display: none !important;
  content: none !important;
}
.md-typeset .admonition .highlight,
.md-typeset .admonition .highlighttable,
.md-typeset details .highlight,
.md-typeset details .highlighttable {
  border-radius: 4px !important;
  margin: 10px 0 !important;
}

/* 兜底：任何情境下，若 .highlighttable 和其内层 .highlight 同时存在，
   内层 .highlight 强制透明化（前面已写过，这里做冗余保护） */
.md-typeset .highlighttable .highlight,
.md-typeset .highlighttable .highlight:hover,
.md-typeset .highlighttable .highlight:focus {
  border: none !important;
  border-left: none !important;
  background: transparent !important;
  box-shadow: none !important;
}

/* ⭐ 行号列 FOUC 防抖：给 .linenos 固定宽度 + 垂直上边对齐
   避免 JS 异步加载时行号列宽度跳变 */
.md-typeset .highlighttable .linenos {
  width: 3.5em;
  min-width: 3.5em;
  max-width: 3.5em;
  vertical-align: top;
  text-align: right;
  user-select: none;
  background: rgba(11, 28, 46, 0.6) !important;
  color: rgba(184, 197, 209, 0.55) !important;
  border-right: 1px solid rgba(212, 165, 116, 0.12) !important;
  padding: 14px 10px !important;
  font-family: var(--font-mono) !important;
  font-size: 13px;
  line-height: 1.55;
}
.md-typeset .highlighttable .linenos pre,
.md-typeset .highlighttable .linenodiv pre {
  color: inherit !important;
  margin: 0 !important;
  padding: 0 !important;
  background: transparent !important;
  border: none !important;
}
.md-typeset .highlighttable .code {
  vertical-align: top;
}
