/* ==========================================================================
   Astro Kid · Grid CSS 样式库
   --------------------------------------------------------------------------
   站点自有的布局基础设施，全部由原生 CSS Grid 驱动：
   1. 设计令牌（颜色 / 间距 / 圆角 / 阴影 / 字体）
   2. 基础重置
   3. 原子工具类
   4. 容器
   5. 12 列栅格引擎（.grid / .g2 / .g3 / .g4 / .span-*）
   6. 页面骨架（.layout / .stack）
   7. 行式栅格（.row 及修饰类）
   8. 响应式断点

   说明：Grid 是二维布局工具，一维「换行簇」用 flex-wrap 表达更准确，
   因此 .cluster 是刻意保留的唯一 flex 基础类，用于标签、工具条等流式内容。
   ========================================================================== */

/* ---------- 0. 本地字体 ---------- */
@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/JetBrainsMono/JetBrainsMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/JetBrainsMono/JetBrainsMono-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/JetBrainsMono/JetBrainsMono-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/JetBrainsMono/JetBrainsMono-ExtraBold.woff2") format("woff2");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Noto Sans SC";
  src: url("../fonts/NotoSansSC/NotoSansSC-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
/* 仅供衬线排版中强制西文走 --sans：限定 Unicode 范围，不影响中文衬线 */
@font-face {
  font-family: "AK Latin Sans";
  src: url("../fonts/NotoSansSC/NotoSansSC-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0041-005A, U+0061-007A, U+00C0-024F;
}

/* ---------- 1. 设计令牌 ---------- */
:root {
  /* 底色：近乎白纸的冷灰，不用渐变 */
  --bg: #F4F6F9;
  --bg-grad: none;
  --surface: #ffffff;
  /* 共用令牌见 tokens.css（--brand / --text / --line / --ak-sp-* 等） */
  --surface-3: #eceef2;
  --brand-2: var(--brand);
  --brand-3: var(--brand);
  --brand-hover: color-mix(in srgb, var(--brand) 85%, #000);
  --brand-line: color-mix(in srgb, var(--brand) 20%, #fff);
  --brand-soft: color-mix(in srgb, var(--brand) 8%, #fff);
  --warn: #b42318;
  --info: #0b6ea8;
  /* 足迹页天空色：标题区与火车场景共用，深色主题在下方覆盖 */
  --fp-sky: #a5cdff;
  --fp-scene-bg: #a5cdff;
  /* 阴影只用于浮层，卡片靠 1px 描边区分层级 */
  --shadow-sm: 0 1px 1px rgba(16, 18, 23, .03);
  --shadow-lg: 0 18px 44px -20px rgba(16, 18, 23, .28);
  --radius-sm: 0;
  --radius-lg: 0;
  /* 响应式断点事实源：560（手机）/768（平板）/1020（窄桌面）/1280（宽桌面）。
     个别功能页因自身内容密度使用 360/480/640/720/800/860/900/1000/1080/1240，
     新增页面一律优先使用上述四档，不要再造新宽度。CSS 媒体查询不支持 var()，
     因此这里只作为约定清单，不能写成变量。 */
  /* 间距令牌见 tokens.css；>40px 的结构性偏移保留字面量 */
  --gap: var(--ak-sp-15);
  --gutter: var(--ak-sp-20);
  --col: 12;
   /* 数字走 --mono 同源的 JetBrains Mono 子集（只含数字/标点）；
      英文走 AK Latin Sans（Noto Sans SC 的拉丁子集，即 --sans 的西文部分）；
      中文恢复原站点字体栈，不被 Noto Sans SC 顶掉。
      AK Latin Sans 必须保留为独立 @font-face：它带 unicode-range 仅匹配拉丁。
      若把 --font/--serif 里的名字直接改成 Noto Sans SC（其 @font-face 无 unicode-range），
      中文会被它接管：--font 由 PingFang SC 栈变为 Noto Sans SC，
      --serif 由 Songti SC 变为 Noto Sans SC，诗词与引用排版随之改变。 */
  --mono-digits: "JetBrains Mono";
  --sans: "Noto Sans SC", system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --cn: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font: var(--mono-digits), "AK Latin Sans", var(--cn);
  --serif: var(--mono-digits), "AK Latin Sans", "Songti SC", "Noto Serif SC", "Source Han Serif SC", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --nav-h: 60px;
}
html[data-theme="dark"] {
  --bg: #0c0d10;
  --bg-grad: none;
  --surface: #131418;
  --surface-2: #191b20;
  --surface-3: #21242b;
  --text: #eceef2;
  --text-2: #b8bcc5;
  --muted: #878c96;
  --line: #262a31;
  /* 兜底暗色品牌色；实际值由布局内联按同一品牌色提亮后覆盖 */
  --brand: #8b95f7;
  --brand-2: var(--brand);
  --brand-3: var(--brand);
  --brand-hover: color-mix(in srgb, var(--brand) 70%, #fff);
  --brand-line: color-mix(in srgb, var(--brand) 45%, #000);
  --brand-soft: color-mix(in srgb, var(--brand) 25%, #000);
  --accent: #d3a35a;
  --ok: #45c99a;
  --warn: #f08174;
  --info: #5fb8e6;
  --fp-sky: #16213d;
  --fp-scene-bg: linear-gradient(180deg, #131c34 0%, #27395f 100%);
  --shadow-sm: 0 1px 1px rgba(0, 0, 0, .3);
  --shadow: 0 2px 10px rgba(0, 0, 0, .35);
  --shadow-lg: 0 18px 44px -20px rgba(0, 0, 0, .75);
  /* 深色模式媒体统一降亮值：img 的 filter 与背景图 backdrop-filter 共用 */
  --ak-media-filter: brightness(.8) contrast(1.1);
}

/* ---------- 2. 基础重置 ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  background-color: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.65;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font-family: inherit; border: none;}
::selection { background: color-mix(in srgb, var(--brand) 25%, transparent); }

/* ---------- 3. 原子工具类 ---------- */
.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 12px; top: 12px; z-index: 999; background: var(--surface); padding: var(--ak-sp-8) var(--ak-sp-15); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.en { font-family: var(--sans); }
.serif { font-family: var(--serif); }
.divider { height: 1px; background: var(--line); border: 0; margin: var(--ak-sp-20) 0; }
.link { color: var(--brand); font-weight: 600; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.hidden { display: none !important; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.clamp-1 { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- 4. 容器 ---------- */
.container { width: min(1180px, 100% - 40px); margin-inline: auto; }
.narrow { width: min(860px, 100% - 40px); margin-inline: auto; }

/* ---------- 5. 12 列栅格引擎 ---------- */
.grid { display: grid; grid-template-columns: repeat(var(--col), minmax(0, 1fr)); gap: var(--gap); }
.g2 > * { grid-column: span 6; }
.g3 > * { grid-column: span 4; }
.g4 > * { grid-column: span 3; }

.span-12 { grid-column: span 12; }

/* 自适应网格：不依赖固定列数，按最小宽度自动重排 */
.auto-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
  gap: var(--gap);
}

/* ---------- 6. 页面骨架 ---------- */
/* 主体 + 侧栏：宽窄与 DOM 顺序解耦，aside 永远落在窄列 */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 318px);
  gap: var(--ak-sp-20);
  align-items: start;
}
.layout > aside { order: 2; }
.layout > :not(aside) { order: 1; min-width: 0; }
/* 侧栏偏窄的骨架（文档树 / 目录类页面） */
.layout.slim { grid-template-columns: minmax(0, 1fr) minmax(0, 268px); }
/* 纯正文骨架（无侧栏） */
.layout.solo { grid-template-columns: minmax(0, 1fr); }
/* 纵向流 */
.stack { display: grid; gap: var(--gap); align-content: start; }

/* ---------- 7. 行式栅格 ---------- */
/* 默认：一维行，轨道按内容收缩 */
.row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  align-items: center;
  justify-content: start;
  gap: var(--ak-sp-10);
}
.row.between { justify-content: space-between; }
/* 两端对齐使用 flex：子项可收缩，长标题不会撑出卡片 */
.row.between {
  display: flex;
  flex-wrap: nowrap;
  min-width: 0;
}
.row.between > * { min-width: 0; }
/* 侧栏窄列里的单行标题：用 ellipsis 而不是 line-clamp，
   避免 -webkit-box 在 flex 项里失效导致文字顶出卡片 */
.row.between .clamp-1 {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* 两栏：固定内容 + 自适应主体（用于头像 / 封面 / 日期 + 文本） */
.row.text {
  grid-auto-flow: row;
  grid-template-columns: max-content minmax(0, 1fr);
  grid-auto-columns: auto;
}
/* 两栏：自适应主体 + 固定尾部（用于搜索框 + 按钮） */
.row.fill {
  grid-auto-flow: row;
  grid-template-columns: minmax(0, 1fr) max-content;
  grid-auto-columns: auto;
}
/* 等分两栏（用于并排输入框） */
.row.split {
  grid-auto-flow: row;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-columns: auto;
}
.row.top { align-items: start; }
.row.text > *,
.row.fill > *,
.row.split > * { min-width: 0; }
/* Grid 轨道已承担占位，行内 spacer 一律隐藏 */
.row > .spacer { display: none; }

/* ---------- 8. 一维流式簇（刻意保留 flex） ---------- */
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ak-sp-8);
}

/* ---------- 9. 响应式 ---------- */
@media (max-width: 1020px) {
  .layout, .layout.slim, .layout.solo { grid-template-columns: 1fr; }
  /* 单列时恢复文档顺序（导航类目录在前，正文侧栏在后） */
  .layout > aside, .layout > :not(aside) { order: 0; }
  .g4 > * { grid-column: span 6; }
}
@media (max-width: 768px) {
  .container, .narrow { width: calc(100% - 28px); }
  .g2 > *, .g3 > *, .g4 > * { grid-column: span 12; }
  .span-12 { grid-column: span 12; }
}
@media (max-width: 560px) {
  .row { gap: var(--ak-sp-8); }
  .row.split { grid-template-columns: 1fr; }
}
