/* 所有页面共用的样式：配色变量（跟随系统明暗）、导航、页码、翻页、灯箱、页脚。
   每页独有的设计写在各自 HTML 的 <style> 里。 */
:root {
  /* 颜色：低饱和极简，跟随系统明暗（浅色为默认，深色见下方 media query） */
  --bg: #fbfbfa;          /* 页面背景 */
  --surface: #f2f2f0;     /* 代码框、图片底等表面 */
  --fg: #1c1c1e;          /* 正文 */
  --fg-soft: #6e6e73;     /* 次要文字 */
  --rule: #e3e3e0;        /* 分隔线 */
  --accent: #3a5fb0;      /* 唯一强调色：链接、悬停 */
  --mech: #3d6fa8;        /* 关键词：机器（中英对应着色） */
  --bio: #3f8a5f;         /* 关键词：生物 */
  color-scheme: light dark;
  --serif: "Noto Serif SC", "Songti SC", "STSong", serif;
  --latin: "Cormorant Garamond", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --gutter: clamp(16px, 5vw, 64px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141516;
    --surface: #1c1d1f;
    --fg: #e6e6e3;
    --fg-soft: #98989d;
    --rule: #2c2d30;
    --accent: #8eaee8;
    --mech: #86aedb;
    --bio: #86c29f;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--serif); line-height: 1.75; overflow-x: hidden; }
img { max-width: 100%; display: block; }
a { color: inherit; }

/* ---------- 顶部导航 ---------- */
.nav {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px var(--gutter); padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.nav .brand { font-weight: 900; font-size: 16px; text-decoration: none; white-space: nowrap; }
.nav .brand [lang="en"] { font-family: var(--latin); font-weight: 700; }
.nav .where { display: flex; align-items: center; gap: 8px; min-width: 0; font-family: var(--mono); font-size: 12px; }
.nav .where .cur { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .75; }
.nav .where .cur b { font-family: var(--serif); font-weight: 600; }
@media (max-width: 560px) { .nav .where .cur { display: none; } }

/* ---------- 语言模式：html[data-lang] = zh | en | bi ----------
   文案由 site.js 从 i18n.js 渲染为 <span lang="en"> + <span lang="zh">，这里按模式隐藏。 */
html[data-lang="zh"] body [lang="en"],
html[data-lang="en"] body [lang="zh"] { display: none !important; }
html[data-lang="bi"] [data-t]:not(.stack) > [lang="zh"] { margin-left: .4em; }   /* 行内对照：英文 中文 */
.stack > [lang] { display: block; }                                              /* 上下对照：英文在上，中文在下 */

/* ---------- 右上角语言切换 ---------- */
.lang { position: relative; flex: none; }
.lang-btn {
  display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 10px; cursor: pointer;
  background: none; color: inherit; border: 1px solid currentColor; border-radius: 999px;
  font-family: var(--mono); font-size: 12px;
}
.lang-ic { position: relative; width: 22px; height: 30px; flex: none; }
.lang-ic img { position: absolute; top: 0; left: 0; width: 22px; height: 30px; object-fit: cover; border-radius: 2px; box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.lang-ic.bi { width: 34px; }
.lang-ic.bi img.en { transform: rotate(-8deg); }
.lang-ic.bi img.zh { left: 12px; transform: rotate(6deg); }
.lang-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; padding: 6px; display: none;
  background: var(--bg); color: var(--fg); border: 1px solid var(--rule); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.14);
}
.lang.open .lang-menu { display: block; }
.lang-menu button {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 10px; cursor: pointer;
  background: none; color: inherit; border: 0; border-radius: 8px; font: inherit; font-size: 14px; text-align: left; white-space: nowrap;
}
.lang-menu button:hover { background: color-mix(in srgb, currentColor 8%, transparent); }
.lang-menu button .ck { margin-left: auto; opacity: 0; }
.lang-menu button[aria-checked="true"] { font-weight: 600; }
.lang-menu button[aria-checked="true"] .ck { opacity: 1; }

.page { position: relative; padding: 48px var(--gutter) 64px; }
.wrap { max-width: 1180px; margin: 0 auto; }
.page-no {
  font-family: var(--mono); font-size: 12px; letter-spacing: .15em; text-transform: uppercase;
  display: flex; align-items: center; gap: 12px; margin-bottom: 28px; opacity: .7;
}
.page-no::after { content: ""; flex: 1; height: 1px; background: currentColor; opacity: .3; }

/* ---------- 代码框 + 复制按钮（如提示词）：每种语言一个框，对照模式上下排列 ---------- */
.codeboxes { display: grid; gap: 12px; }
.codebox { border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; background: var(--surface); }
.codebox-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 10px 8px 14px;
  border-bottom: 1px solid var(--rule); font-family: var(--mono); font-size: 12px; letter-spacing: .06em; color: var(--fg-soft);
}
.codebox pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.codebox code { font-family: var(--mono); font-size: 13.5px; line-height: 1.75; white-space: pre-wrap; word-break: break-word; }
.copy-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; cursor: pointer;
  background: none; color: inherit; border: 1px solid currentColor; border-radius: 6px; font-family: var(--mono); font-size: 12px;
}
.copy-btn:hover { background: color-mix(in srgb, currentColor 12%, transparent); }
.copy-btn.done { color: var(--bio); }

/* ---------- 可放大的图片 ---------- */
.shot {
  position: relative; display: block; width: 100%; aspect-ratio: 9 / 16; border-radius: 10px; overflow: hidden; cursor: zoom-in;
  border: 1px solid var(--rule); background: var(--surface); padding: 0;
}
.shot img { width: 100%; height: 100%; object-fit: cover; transition: transform .6s ease; }
.shot:hover img { transform: scale(1.04); }
.shot .zoom { position: absolute; right: 8px; bottom: 8px; font-family: var(--mono); font-size: 11px; color: #fff; background: rgba(0,0,0,.55); padding: 3px 8px; border-radius: 999px; }

/* ---------- 手机端单列对比表：标签切换 + 横向滑动；上图下文，介绍区独立滚动 ---------- */
.mcmp { display: none; }
.mcmp-tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border-bottom: 1px solid var(--rule); }
.mcmp-tab {
  display: flex; justify-content: center; padding: 10px 4px 9px; cursor: pointer; min-width: 0;
  background: none; color: inherit; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; opacity: .55;
}
.mcmp-tab[aria-selected="true"] { opacity: 1; border-bottom-color: currentColor; }
.mcmp-tab .plat { gap: 6px; min-width: 0; }
.mcmp-tab .name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mcmp-tab .logo { width: 18px; height: 18px; }
.mcmp-tab .plat { align-items: center; }
.mcmp-tab .name > [lang] { display: block; margin-left: 0 !important; line-height: 1.25; }   /* 对照模式标签名上下两行 */
.mcmp-track {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
  overscroll-behavior-x: contain;                       /* 横向滑到头不触发浏览器返回 */
}
.mcmp-track::-webkit-scrollbar { display: none; }
.mcmp-col { flex: 0 0 100%; min-width: 0; scroll-snap-align: start; scroll-snap-stop: always; padding-top: 12px; }
/* 一列（图 + 介绍）正好放进顶部导航与底部导航之间：可用高度 ≈ 100svh − 约 230px（两条导航 + 标签栏 + 间距），图占 55%，介绍占 45% */
.mcmp { --avail: calc(100svh - 230px); }
.mcmp-col .shot { aspect-ratio: auto; height: calc(var(--avail) * .55); min-height: 240px; }
.mcmp-col .shot img { object-position: center 30%; }
/* 介绍区：固定高度、独立纵向滚动；overscroll-behavior-y 保持默认，滚到头后继续滚动整页 */
.mcmp-info {
  max-height: calc(var(--avail) * .45); min-height: 160px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  margin-top: 10px; padding: 0 2px 0 0; outline: none;
  -webkit-mask-image: linear-gradient(#000 calc(100% - 24px), transparent);   /* 底部渐隐，提示可滚动 */
          mask-image: linear-gradient(#000 calc(100% - 24px), transparent);
}
.mcmp-info dl { margin: 0; padding-bottom: 20px; }
.mcmp-row { display: grid; grid-template-columns: 6.5em minmax(0, 1fr); gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.mcmp-row dt { font-family: var(--mono); font-size: 11px; letter-spacing: .04em; line-height: 1.6; opacity: .65; }
.mcmp-row dd { margin: 0; font-size: 14px; line-height: 1.65; }

.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(10,10,12,.94); display: none; align-items: center; justify-content: center; padding: 24px 16px; }
.lightbox.open { display: flex; }
.lightbox figure { margin: 0; max-height: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.lightbox img { max-height: calc(100vh - 110px); max-width: 100%; width: auto; border-radius: 8px; }
.lightbox figcaption { font-family: var(--mono); font-size: 12px; color: #a8a8ad; text-align: center; }
.lightbox figcaption a { color: #f2f2f0; }
.lightbox button { position: absolute; top: max(14px, env(safe-area-inset-top)); right: 16px; background: none; border: 1px solid #3a3b3f; color: #f2f2f0; font-family: var(--mono); font-size: 13px; padding: 6px 12px; border-radius: 999px; cursor: pointer; }

footer { font-family: var(--mono); font-size: 12px; text-align: center; padding: 28px var(--gutter) max(28px, env(safe-area-inset-bottom)); border-top: 1px solid var(--rule); color: var(--fg-soft); }

/* ---------- 底部固定导航 ---------- */
body.has-bnav { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: stretch;
  padding: 0 var(--gutter) env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--rule);
}
.bottom-nav a { text-decoration: none; }
.bn-side { display: flex; flex-direction: column; justify-content: center; min-height: 54px; min-width: 0; padding: 8px 4px; }
.bn-side.next { text-align: right; align-items: flex-end; }
.bn-side.off { opacity: .3; }
.bn-dir { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; opacity: .65; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.bn-t { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
/* 层级路径：总目录 › 章 › 节 › 当前页 */
.bn-crumbs {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; min-width: 0;
  padding: 7px 0 5px; border-bottom: 1px dashed var(--rule); font-size: 12px; white-space: nowrap;
}
.bn-crumbs .crumb { min-width: 0; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; opacity: .7; }
.bn-crumbs a.crumb:hover { opacity: 1; text-decoration: underline; text-underline-offset: 3px; }
.bn-crumbs .crumb:first-child { flex-shrink: 0; }
.bn-crumbs .crumb.cur { opacity: 1; font-weight: 600; flex-shrink: 0; max-width: 55%; }
.bn-crumbs .sep { opacity: .4; flex: none; }
a.bn-side:hover .bn-t { text-decoration: underline; text-underline-offset: 4px; }
.bn-toc {
  align-self: center; display: inline-flex; align-items: center; gap: 6px; margin: 0 12px;
  font-family: var(--mono); font-size: 12px; padding: 7px 14px; border: 1px solid currentColor; border-radius: 999px;
}
.bn-toc.on, .bn-toc:hover { background: var(--fg); color: var(--bg); border-color: var(--fg); }
@media (max-width: 480px) { .bn-t { font-size: 13px; } .bn-toc { margin: 0 8px; padding: 7px 11px; } }
