/* ===== Nudge design tokens (consumed by all business styles) ===== */
:root {
  --site-bg: #f6f4ef;
  --site-fg: #1f2933;
  --site-accent: #0f766e;
  --site-on-accent: #ffffff;
  --site-surface: #ffffff;
  --site-muted: #6b7280;
  --site-border: #e3ded4;
  --site-font: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system, "Segoe UI", sans-serif;
  --site-radius: 12px;
  --site-space: 1;
  --site-type: 1;
  --site-motion: 1;

  /* derived */
  --accent-soft: color-mix(in srgb, var(--site-accent) 12%, var(--site-surface));
  --accent-line: color-mix(in srgb, var(--site-accent) 35%, var(--site-border));
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --gap: calc(24px * var(--site-space, 1));
  --topbar-h: 64px;
  --sidebar-w: 288px;
  --toc-w: 232px;
  --content-max: 880px;
  --dur: calc(180ms * var(--site-motion, 1));
}

[data-theme="dark"] {
  --site-bg: #10151c;
  --site-fg: #e6e9ee;
  --site-accent: #2dd4bf;
  --site-on-accent: #06231f;
  --site-surface: #182029;
  --site-muted: #9aa4b2;
  --site-border: #2a3441;
  --accent-soft: color-mix(in srgb, var(--site-accent) 16%, var(--site-surface));
  --accent-line: color-mix(in srgb, var(--site-accent) 40%, var(--site-border));
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 16px); }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
}

body {
  margin: 0;
  font-family: var(--site-font);
  font-size: calc(16px * var(--site-type, 1));
  line-height: 1.8;
  color: var(--site-fg);
  background: var(--site-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--site-accent); text-decoration: none; transition: color var(--dur) ease; }
a:hover { text-decoration: underline; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 200;
  background: var(--site-accent); color: var(--site-on-accent);
  padding: 10px 16px; border-radius: 0 0 var(--site-radius) 0;
}
.skip-link:focus { left: 0; }

/* ===== Topbar ===== */
.topbar {
  position: sticky; top: 0; z-index: 60;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: calc(12px * var(--site-space, 1));
  padding: 0 calc(20px * var(--site-space, 1));
  background: color-mix(in srgb, var(--site-surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--site-border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--site-fg); flex-shrink: 0; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 40px; height: 40px;
  color: var(--site-accent); background: var(--accent-soft);
  border-radius: calc(var(--site-radius) * .8);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; font-weight: 700; font-size: calc(16px * var(--site-type, 1)); }
.brand-text small { font-weight: 400; font-size: calc(11.5px * var(--site-type, 1)); color: var(--site-muted); }

.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px;
  border: 1px solid var(--site-border); background: var(--site-surface);
  color: var(--site-fg); border-radius: calc(var(--site-radius) * .7);
  cursor: pointer; transition: background var(--dur) ease, color var(--dur) ease, border-color var(--dur) ease;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--site-accent); border-color: var(--accent-line); }
.nav-toggle { display: none; }
.theme-toggle .ico-moon { display: none; }
[data-theme="dark"] .theme-toggle .ico-sun { display: none; }
[data-theme="dark"] .theme-toggle .ico-moon { display: block; }

/* ===== Search ===== */
.search { position: relative; flex: 1; max-width: 460px; margin-left: auto; }
.search-ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--site-muted); pointer-events: none; }
#searchInput {
  width: 100%; height: 42px; padding: 0 14px 0 38px;
  font-family: inherit; font-size: calc(14.5px * var(--site-type, 1)); color: var(--site-fg);
  background: var(--site-bg); border: 1px solid var(--site-border);
  border-radius: calc(var(--site-radius) * .8); outline: none;
  transition: border-color var(--dur) ease, box-shadow var(--dur) ease;
}
#searchInput:focus { border-color: var(--site-accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0; z-index: 80;
  max-height: min(60vh, 460px); overflow-y: auto;
  background: var(--site-surface); border: 1px solid var(--site-border);
  border-radius: var(--site-radius); box-shadow: var(--shadow); padding: 6px;
}
.search-result { display: block; padding: 10px 12px; border-radius: calc(var(--site-radius) * .6); color: var(--site-fg); }
.search-result:hover, .search-result.active { background: var(--accent-soft); text-decoration: none; }
.search-result .sr-title { font-weight: 600; font-size: calc(14.5px * var(--site-type, 1)); display: flex; align-items: center; gap: 8px; }
.search-result .sr-group { font-size: calc(11px * var(--site-type, 1)); color: var(--site-accent); background: var(--accent-soft); padding: 1px 7px; border-radius: 999px; font-weight: 500; }
.search-result .sr-snippet { font-size: calc(12.5px * var(--site-type, 1)); color: var(--site-muted); margin-top: 3px; line-height: 1.6; }
.search-result mark { background: color-mix(in srgb, var(--site-accent) 28%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.search-empty { padding: 16px 12px; color: var(--site-muted); font-size: calc(13.5px * var(--site-type, 1)); }

/* ===== Layout ===== */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  gap: 0;
  max-width: 1560px; margin: 0 auto;
  align-items: start;
}

/* ===== Sidebar ===== */
.sidebar {
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h)); overflow-y: auto;
  padding: var(--gap) calc(16px * var(--site-space, 1)) var(--gap) calc(20px * var(--site-space, 1));
  border-right: 1px solid var(--site-border);
}
.nav-group { margin-bottom: calc(20px * var(--site-space, 1)); }
.nav-group-title {
  display: flex; align-items: center; gap: 8px;
  font-size: calc(12px * var(--site-type, 1)); font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--site-muted); margin: 0 0 8px; padding: 0 10px;
}
.nav-group-title a { color: inherit; }
.nav-group-title a:hover { color: var(--site-accent); text-decoration: none; }
.nav-item {
  display: block; padding: 7px 10px; margin: 1px 0;
  font-size: calc(14px * var(--site-type, 1)); color: var(--site-fg);
  border-radius: calc(var(--site-radius) * .6); border-left: 2px solid transparent;
  transition: background var(--dur) ease, color var(--dur) ease;
}
.nav-item:hover { background: var(--accent-soft); text-decoration: none; }
.nav-item.current { background: var(--accent-soft); color: var(--site-accent); font-weight: 600; border-left-color: var(--site-accent); }
.sidebar-backdrop { display: none; }

/* ===== Content ===== */
.content {
  min-width: 0; padding: calc(28px * var(--site-space, 1)) calc(40px * var(--site-space, 1)) 64px;
}
.breadcrumb { font-size: calc(13px * var(--site-type, 1)); color: var(--site-muted); margin-bottom: calc(16px * var(--site-space, 1)); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.breadcrumb a { color: var(--site-muted); }
.breadcrumb a:hover { color: var(--site-accent); }
.crumb-sep { opacity: .5; }
.breadcrumb [aria-current] { color: var(--site-fg); font-weight: 500; }

.markdown { max-width: var(--content-max); }
.markdown > h1 {
  font-size: calc(32px * var(--site-type, 1)); line-height: 1.35; font-weight: 800;
  margin: 0 0 calc(20px * var(--site-space, 1)); letter-spacing: -.01em;
  padding-bottom: calc(14px * var(--site-space, 1)); border-bottom: 2px solid var(--accent-line);
}
.markdown h2 {
  font-size: calc(23px * var(--site-type, 1)); font-weight: 700; line-height: 1.4;
  margin: calc(38px * var(--site-space, 1)) 0 calc(14px * var(--site-space, 1));
  padding-left: 14px; border-left: 4px solid var(--site-accent); scroll-margin-top: calc(var(--topbar-h) + 20px);
}
.markdown h3 { font-size: calc(18.5px * var(--site-type, 1)); font-weight: 700; margin: calc(26px * var(--site-space, 1)) 0 calc(10px * var(--site-space, 1)); scroll-margin-top: calc(var(--topbar-h) + 20px); }
.markdown h4 { font-size: calc(16px * var(--site-type, 1)); font-weight: 700; margin: calc(20px * var(--site-space, 1)) 0 8px; }
.markdown p { margin: 0 0 calc(15px * var(--site-space, 1)); }
.markdown ul, .markdown ol { margin: 0 0 calc(15px * var(--site-space, 1)); padding-left: 1.5em; }
.markdown li { margin: 5px 0; }
.markdown li > ul, .markdown li > ol { margin: 5px 0; }
.markdown strong { font-weight: 700; color: var(--site-fg); }
.markdown hr { border: none; border-top: 1px solid var(--site-border); margin: calc(30px * var(--site-space, 1)) 0; }

.markdown blockquote {
  margin: 0 0 calc(18px * var(--site-space, 1)); padding: calc(14px * var(--site-space, 1)) calc(18px * var(--site-space, 1));
  background: var(--accent-soft); border-left: 4px solid var(--site-accent);
  border-radius: 0 var(--site-radius) var(--site-radius) 0; color: var(--site-fg);
}
.markdown blockquote p:last-child { margin-bottom: 0; }

.markdown code {
  font-family: "SFMono-Regular", "JetBrains Mono", Consolas, "Courier New", monospace;
  font-size: .88em; background: var(--accent-soft); color: var(--site-accent);
  padding: 2px 6px; border-radius: 6px; border: 1px solid var(--accent-line);
}
.markdown pre {
  background: var(--site-surface); border: 1px solid var(--site-border);
  border-radius: var(--site-radius); padding: calc(16px * var(--site-space, 1));
  overflow-x: auto; margin: 0 0 calc(18px * var(--site-space, 1)); box-shadow: var(--shadow);
}
.markdown pre code { background: none; border: none; color: var(--site-fg); padding: 0; font-size: calc(13.5px * var(--site-type, 1)); line-height: 1.7; }

/* ===== Tables ===== */
.markdown table {
  width: 100%; border-collapse: collapse; margin: 0 0 calc(20px * var(--site-space, 1));
  font-size: calc(14px * var(--site-type, 1)); background: var(--site-surface);
  border: 1px solid var(--site-border); border-radius: var(--site-radius); overflow: hidden;
  box-shadow: var(--shadow); display: block; overflow-x: auto;
}
.markdown thead { background: var(--accent-soft); }
.markdown th {
  text-align: left; font-weight: 700; padding: 11px 14px; color: var(--site-fg);
  border-bottom: 2px solid var(--accent-line); white-space: nowrap;
}
.markdown td { padding: 10px 14px; border-bottom: 1px solid var(--site-border); vertical-align: top; line-height: 1.7; }
.markdown tbody tr:nth-child(even) { background: color-mix(in srgb, var(--site-bg) 50%, var(--site-surface)); }
.markdown tbody tr:last-child td { border-bottom: none; }
.markdown tbody tr:hover { background: var(--accent-soft); }

/* ===== Section index cards ===== */
.index-intro { color: var(--site-muted); max-width: var(--content-max); margin-bottom: calc(24px * var(--site-space, 1)); }
.index-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: calc(16px * var(--site-space, 1)); max-width: 1000px; }
.index-card {
  display: flex; flex-direction: column; gap: 8px; padding: calc(18px * var(--site-space, 1));
  background: var(--site-surface); border: 1px solid var(--site-border);
  border-radius: var(--site-radius); color: var(--site-fg); box-shadow: var(--shadow);
  transition: transform var(--dur) ease, border-color var(--dur) ease;
}
.index-card:hover { transform: translateY(-3px); border-color: var(--accent-line); text-decoration: none; }
.index-card-label { font-weight: 700; font-size: calc(16px * var(--site-type, 1)); color: var(--site-accent); }
.index-card-desc { font-size: calc(13px * var(--site-type, 1)); color: var(--site-muted); line-height: 1.7; }

/* ===== Page footer ===== */
.page-foot {
  max-width: var(--content-max); margin-top: calc(48px * var(--site-space, 1));
  padding-top: calc(18px * var(--site-space, 1)); border-top: 1px solid var(--site-border);
  display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center;
  font-size: calc(12.5px * var(--site-type, 1)); color: var(--site-muted);
}

/* ===== TOC ===== */
.toc {
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h)); overflow-y: auto;
  padding: var(--gap) calc(20px * var(--site-space, 1)) var(--gap) 0;
}
.toc:empty { display: none; }
.toc-title { font-size: calc(12px * var(--site-type, 1)); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--site-muted); margin-bottom: 10px; }
.toc-links { display: flex; flex-direction: column; border-left: 1px solid var(--site-border); }
.toc-link {
  padding: 5px 0 5px 14px; margin-left: -1px; font-size: calc(13px * var(--site-type, 1));
  color: var(--site-muted); border-left: 2px solid transparent; line-height: 1.5;
  transition: color var(--dur) ease, border-color var(--dur) ease;
}
.toc-l3 { padding-left: 28px; font-size: calc(12.5px * var(--site-type, 1)); }
.toc-link:hover { color: var(--site-accent); text-decoration: none; }
.toc-link.active { color: var(--site-accent); border-left-color: var(--site-accent); font-weight: 600; }

/* ===== To top ===== */
.to-top {
  position: fixed; right: 24px; bottom: 24px; z-index: 50;
  width: 44px; height: 44px; display: grid; place-items: center;
  background: var(--site-accent); color: var(--site-on-accent); border: none;
  border-radius: 50%; cursor: pointer; box-shadow: var(--shadow);
  transition: opacity var(--dur) ease, transform var(--dur) ease;
}
.to-top:hover { transform: translateY(-3px); }

/* ===== Responsive ===== */
@media (max-width: 1200px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 900px) {
  .nav-toggle { display: grid; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; z-index: 70;
    width: min(86vw, var(--sidebar-w)); height: calc(100vh - var(--topbar-h));
    background: var(--site-surface); border-right: 1px solid var(--site-border);
    transform: translateX(-100%); transition: transform var(--dur) ease; box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop {
    display: block; position: fixed; inset: var(--topbar-h) 0 0; z-index: 65;
    background: rgba(0, 0, 0, .4); opacity: 0; pointer-events: none; transition: opacity var(--dur) ease;
  }
  body.nav-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .content { padding: calc(22px * var(--site-space, 1)) calc(20px * var(--site-space, 1)) 56px; }
  .brand-text small { display: none; }
  .search { max-width: none; }
}
@media (max-width: 560px) {
  .brand-text { font-size: calc(14.5px * var(--site-type, 1)); }
  .markdown > h1 { font-size: calc(26px * var(--site-type, 1)); }
  .markdown h2 { font-size: calc(20px * var(--site-type, 1)); }
  .topbar { gap: 8px; padding: 0 12px; }
  #searchInput::placeholder { color: transparent; }
}