/* ============================================================
   基础排版与页面骨架
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { max-width: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }

h1, h2, h3, h4 { color: var(--text-strong); font-weight: 700; line-height: var(--lh-tight); margin: 0; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); margin-top: var(--sp-8); margin-bottom: var(--sp-4); padding-bottom: var(--sp-3); border-bottom: 1px solid var(--border); }
h3 { font-size: var(--fs-lg); margin-top: var(--sp-6); margin-bottom: var(--sp-3); }
h4 { font-size: var(--fs-md); margin-top: var(--sp-5); margin-bottom: var(--sp-2); }
p { margin: 0 0 var(--sp-4); }
strong { color: var(--text-strong); font-weight: 650; }
code { font-family: var(--font-mono); font-size: 0.875em; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 0.1em 0.36em; }
ul, ol { margin: 0 0 var(--sp-4); padding-left: 1.5em; }
li { margin-bottom: var(--sp-2); }
li > ul, li > ol { margin-top: var(--sp-2); }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-7) 0; }
small { font-size: var(--fs-sm); color: var(--text-muted); }

/* 英文术语行内标注 */
.en { font-family: var(--font-sans); color: var(--text-muted); font-weight: 400; font-size: 0.9em; }
.term { font-weight: 650; color: var(--text-strong); }
.term .en { font-weight: 400; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  display: flex; align-items: center; gap: var(--sp-4);
  padding: 0 var(--sp-5);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar__brand { display: flex; align-items: center; gap: var(--sp-3); font-weight: 700; color: var(--text-strong); font-size: 0.95rem; letter-spacing: -0.01em; }
.topbar__brand:hover { text-decoration: none; }
.topbar__brand > span:not(.topbar__ver) { white-space: nowrap; }
.topbar__mark { width: 26px; height: 26px; flex: none; }
.topbar__ver { font-size: var(--fs-xs); font-weight: 600; color: var(--accent); background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: var(--r-full); padding: 1px 8px; letter-spacing: 0; }
.topbar__spacer { flex: 1; }
.topbar__btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  cursor: pointer; font-family: inherit;
}
.topbar__btn:hover { color: var(--text-strong); border-color: var(--border-strong); text-decoration: none; }
.menu-toggle { display: none; }

/* ---------- 主布局 ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); align-items: start; }

.sidebar {
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto; overscroll-behavior: contain;
  padding: var(--sp-5) var(--sp-3) var(--sp-8) var(--sp-5);
  border-right: 1px solid var(--border);
  font-size: var(--fs-sm);
}
.sidebar__title { font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); margin: var(--sp-5) 0 var(--sp-2); }
.sidebar__title:first-child { margin-top: 0; }
.nav-ch { margin-bottom: 2px; }
.nav-ch__link {
  display: flex; align-items: baseline; gap: 8px;
  padding: 6px 10px; border-radius: var(--r-md);
  color: var(--text); font-weight: 600; line-height: 1.4;
}
.nav-ch__link:hover { background: var(--surface-2); text-decoration: none; }
.nav-ch__link.is-active { background: var(--accent-soft); color: var(--accent); }
.nav-ch__num { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-faint); flex: none; width: 2.1em; }
.nav-ch__link.is-active .nav-ch__num { color: var(--accent); }
.nav-sec { list-style: none; margin: 2px 0 var(--sp-3); padding-left: calc(10px + 2.1em + 8px); }
.nav-sec li { margin: 0; }
.nav-sec a { display: block; padding: 4px 10px; border-radius: var(--r-sm); color: var(--text-muted); line-height: 1.45; }
.nav-sec a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-sec a.is-active { color: var(--accent); font-weight: 600; background: var(--accent-soft); }
.nav-sec .is-todo { color: var(--text-faint); cursor: default; opacity: 0.65; }
.nav-sec .is-todo::after { content: "建设中"; font-size: 10px; margin-left: 6px; padding: 0 5px; border: 1px dashed var(--border-strong); border-radius: var(--r-full); }

.main { min-width: 0; }
.page { max-width: var(--reading-w); margin: 0 auto; padding: var(--sp-7) var(--sp-6) var(--sp-9); }
.page--wide { max-width: 1120px; }

/* 面包屑 */
.crumbs { font-size: var(--fs-sm); color: var(--text-faint); margin-bottom: var(--sp-4); }
.crumbs a { color: var(--text-muted); }
.crumbs span { margin: 0 6px; }

/* 页眉区 */
.page-head { margin-bottom: var(--sp-7); }
.page-head__kicker { font-size: var(--fs-sm); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); margin-bottom: var(--sp-2); }
.page-head__title { font-size: var(--fs-2xl); }
.page-head__en { font-size: var(--fs-md); color: var(--text-muted); font-weight: 400; margin-top: var(--sp-2); }
.page-head__lede { font-size: var(--fs-md); color: var(--text-muted); margin-top: var(--sp-4); line-height: 1.7; }

/* 上一页/下一页 */
.pager { display: flex; gap: var(--sp-4); margin-top: var(--sp-8); padding-top: var(--sp-5); border-top: 1px solid var(--border); }
.pager a { flex: 1; padding: var(--sp-4); border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
.pager a:hover { border-color: var(--accent-line); text-decoration: none; }
.pager__dir { display: block; font-size: var(--fs-xs); color: var(--text-faint); margin-bottom: 2px; }
.pager__name { color: var(--text-strong); font-weight: 600; font-size: var(--fs-sm); }
.pager--next { text-align: right; }

/* ---------- 响应式 ---------- */
@media (max-width: 1040px) {
  .layout { grid-template-columns: 1fr; }
  .menu-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; top: var(--header-h); left: 0; z-index: 45;
    width: min(320px, 86vw); background: var(--bg-elevated);
    box-shadow: var(--shadow-lg);
    transform: translateX(-102%); transition: transform 0.22s ease;
  }
  .sidebar.is-open { transform: none; }
  .page { padding: var(--sp-6) var(--sp-5) var(--sp-8); }
}
@media (max-width: 560px) {
  :root { --fs-base: 1rem; --fs-2xl: 1.75rem; --fs-3xl: 2rem; --fs-xl: 1.45rem; }
  .page { padding: var(--sp-5) var(--sp-4) var(--sp-7); }
  .topbar { padding: 0 var(--sp-4); }
  /* 窄屏隐藏站名，保留标识与版本，避免顶栏折行 */
  .topbar__brand > span:not(.topbar__ver) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
