:root {
  --brand: #667eea;
  --brand-2: #764ba2;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --mono: 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
  --topbar-h: 4rem;
  --radius: 8px;
  --content-w: 52rem;
}
[data-theme='light'] {
  --bg: #ffffff; --surface: #f6f7fb; --surface-2: #eceef7; --border: #e1e4ee;
  --text: #1a1c26; --muted: #5d6275; --link: #4b5fd0; --link-hover: #3347b8;
  --code-bg: #f6f7fb; --code-head: #eceef7; --shadow: 0 2px 10px rgba(30, 35, 70, 0.08);
  --note: #3b6fd6; --tip: #1f8a5b; --important: #7b4bc7; --warning: #b7791f; --caution: #c0392b;
  color-scheme: light;
}
[data-theme='dark'] {
  --bg: #14151c; --surface: #1c1e29; --surface-2: #262938; --border: #32364a;
  --text: #e8e9f1; --muted: #a3a8be; --link: #8f9dff; --link-hover: #b3bdff;
  --code-bg: #10111a; --code-head: #1c1e29; --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  --note: #6d9bff; --tip: #4fcf98; --important: #b794f4; --warning: #f2b552; --caution: #ff7b6e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar-h) + 1rem); scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.7 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--link); text-underline-offset: 2px; }
a:hover { color: var(--link-hover); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--brand); color: #fff; padding: 0.5rem 1rem; z-index: 100; }
.skip:focus { left: 0.5rem; top: 0.5rem; }
.muted { color: var(--muted); }
kbd { font: 600 0.72rem var(--font); padding: 0.1rem 0.4rem; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--muted); }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 50; height: var(--topbar-h); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; gap: 1rem; height: 100%; max-width: 1480px; margin: 0 auto; padding: 0 1.25rem; }
.brand { display: flex; align-items: center; gap: 0.6rem; text-decoration: none; color: var(--text); font-weight: 700; font-size: 1.1rem; letter-spacing: -0.01em; }
.brand:hover { color: var(--text); }
.logo-mark { flex: none; }
.topnav { display: flex; gap: 0.25rem; margin-left: 1rem; }
.topnav a { padding: 0.45rem 0.75rem; border-radius: 6px; text-decoration: none; color: var(--muted); font-weight: 500; font-size: 0.92rem; }
.topnav a:hover { background: var(--surface); color: var(--text); }
.topnav a[aria-current] { color: var(--text); background: var(--surface); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 2.4rem; height: 2.4rem; border: 0; border-radius: 6px; background: transparent; color: var(--text); cursor: pointer; }
.icon-btn:hover { background: var(--surface); }
.burger { display: none; }
.search-btn { display: inline-flex; align-items: center; gap: 0.5rem; min-width: 12rem; padding: 0.45rem 0.7rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--muted); font: 500 0.9rem var(--font); cursor: pointer; }
.search-btn:hover { border-color: var(--brand); color: var(--text); }
.search-btn kbd { margin-left: auto; }

/* Layout */
.layout { display: grid; grid-template-columns: 17.5rem minmax(0, 1fr) 15rem; max-width: 1480px; margin: 0 auto; gap: 0; align-items: start; }
.sidebar { position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding: 1.5rem 1rem 3rem 1.25rem; border-right: 1px solid var(--border); font-size: 0.93rem; }
.nav-home { display: block; padding: 0.4rem 0.75rem; margin-bottom: 0.5rem; border-radius: 6px; color: var(--text); text-decoration: none; font-weight: 600; }
.nav-group { margin: 0.25rem 0; }
.nav-group summary { cursor: pointer; list-style: none; display: flex; align-items: center; padding: 0.4rem 0.75rem; border-radius: 6px; font-weight: 600; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary::after { content: ''; margin-left: auto; width: 0.45rem; height: 0.45rem; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform 0.15s; }
.nav-group[open] summary::after { transform: rotate(45deg); }
.nav-group summary a, .nav-group li a, .nav-home { color: var(--text); text-decoration: none; }
.nav-group summary a { flex: 1; }
.nav-group ul { list-style: none; margin: 0.15rem 0 0.5rem; padding: 0 0 0 0.75rem; }
.nav-group li a { display: block; padding: 0.4rem 0.75rem; border-radius: 6px; color: var(--muted); border-left: 2px solid transparent; }
.nav-group li a:hover, .nav-home:hover { background: var(--surface); color: var(--text); }
a[aria-current='page'] { color: var(--text) !important; font-weight: 600; }
.nav-group li a[aria-current='page'] { background: var(--surface); border-left-color: var(--brand); }

.content { min-width: 0; padding: 1.75rem 3rem 4rem; }
.crumbs { display: flex; flex-wrap: wrap; gap: 0.5rem; font-size: 0.85rem; color: var(--muted); margin-bottom: 1.5rem; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--text); text-decoration: underline; }
.article { max-width: var(--content-w); }
.article h1 { font-size: 2.5rem; line-height: 1.2; letter-spacing: -0.025em; margin: 0 0 0.75rem; font-weight: 700; }
.meta { color: var(--muted); font-size: 0.88rem; margin: 0 0 2rem; }
.lead { font-size: 1.2rem; color: var(--muted); margin: 0 0 2rem; }
.article h2 { font-size: 1.65rem; letter-spacing: -0.015em; margin: 3rem 0 1rem; padding-top: 0.5rem; border-top: 1px solid var(--border); }
.article h3 { font-size: 1.25rem; margin: 2.25rem 0 0.75rem; }
.article h2, .article h3 { position: relative; }
.anchor { margin-left: 0.5rem; opacity: 0; text-decoration: none; color: var(--muted); font-weight: 400; }
h2:hover .anchor, h3:hover .anchor, .anchor:focus { opacity: 1; }
.article p, .article li { margin: 0.75rem 0; }
.article ul, .article ol { padding-left: 1.5rem; }
.article li > p { margin: 0.35rem 0; }
.article :not(pre) > code { font: 0.88em var(--mono); background: var(--surface-2); padding: 0.15em 0.4em; border-radius: 4px; }
.article strong { font-weight: 600; }
.shot { display: block; max-width: 100%; height: auto; margin: 1rem 0 1.75rem; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); cursor: zoom-in; background: #fff; }
.table-wrap { overflow-x: auto; margin: 1.25rem 0; }
.article table { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
.article th, .article td { border: 1px solid var(--border); padding: 0.55rem 0.8rem; text-align: left; vertical-align: top; }
.article th { background: var(--surface); }
.article blockquote { margin: 1.25rem 0; padding: 0.25rem 1rem; border-left: 3px solid var(--border); color: var(--muted); }

/* Code */
.code { margin: 1.25rem 0 1.75rem; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--code-bg); }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.4rem 0.5rem 0.4rem 1rem; background: var(--code-head); border-bottom: 1px solid var(--border); font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.code-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copy { border: 1px solid var(--border); background: var(--bg); color: var(--text); border-radius: 5px; padding: 0.2rem 0.65rem; font: 600 0.75rem var(--font); cursor: pointer; }
.copy:hover { border-color: var(--brand); }
.code pre { margin: 0; padding: 1rem; overflow-x: auto; }
.code code { font: 0.85rem/1.65 var(--mono); background: none; padding: 0; color: var(--text); white-space: pre; }
.hljs-comment, .hljs-quote { color: var(--muted); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in { color: #c678dd; }
[data-theme='light'] .hljs-keyword, [data-theme='light'] .hljs-built_in { color: #8a3fb0; }
.hljs-string, .hljs-attr { color: #4fa36b; }
.hljs-number, .hljs-literal { color: #d19a66; }
.hljs-title, .hljs-name { color: #4d8dff; }

/* Alerts */
.alert { margin: 1.5rem 0; padding: 0.9rem 1.1rem; border: 1px solid var(--border); border-left: 4px solid var(--note); border-radius: var(--radius); background: var(--surface); }
.alert > :last-child { margin-bottom: 0; }
.alert-title { margin: 0 0 0.35rem !important; font-weight: 700; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--note); }
.alert-tip { border-left-color: var(--tip); } .alert-tip .alert-title { color: var(--tip); }
.alert-important { border-left-color: var(--important); } .alert-important .alert-title { color: var(--important); }
.alert-warning { border-left-color: var(--warning); } .alert-warning .alert-title { color: var(--warning); }
.alert-caution { border-left-color: var(--caution); } .alert-caution .alert-title { color: var(--caution); }

/* Right TOC */
.toc { position: sticky; top: var(--topbar-h); max-height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding: 2rem 1rem 2rem 0.5rem; font-size: 0.86rem; }
.toc-title { margin: 0 0 0.75rem 0.9rem; font-weight: 700; font-size: 0.95rem; }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.toc li a { display: block; padding: 0.25rem 0.5rem 0.25rem 0.9rem; margin-left: -1px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; }
.toc li.d3 a { padding-left: 1.7rem; }
.toc li a:hover { color: var(--text); }
.toc li a.active { color: var(--text); border-left-color: var(--brand); font-weight: 600; }

/* Feedback, pager */
.feedback { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin: 3rem 0 1.5rem; padding: 1rem 0; border-top: 1px solid var(--border); }
.fb-label { font-weight: 600; }
.btn { padding: 0.35rem 1rem; border: 1px solid var(--border); border-radius: 6px; background: transparent; color: var(--text); font: 500 0.9rem var(--font); cursor: pointer; }
.btn:hover { border-color: var(--brand); background: var(--surface); }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
.pager a { display: block; padding: 0.9rem 1.1rem; border: 1px solid var(--border); border-radius: var(--radius); text-decoration: none; color: var(--text); font-weight: 600; }
.pager a span { display: block; font-size: 0.78rem; font-weight: 500; color: var(--muted); }
.pager a:hover { border-color: var(--brand); }
.pager .next { text-align: right; grid-column: 2; }

/* Home + section cards */
.home { min-height: 60vh; }
.hero { padding: 5.5rem 1.25rem 4.5rem; border-bottom: 1px solid var(--border); background: radial-gradient(60rem 26rem at 85% -10%, color-mix(in srgb, var(--brand) 28%, transparent), transparent 70%), radial-gradient(40rem 20rem at 0% 110%, color-mix(in srgb, var(--brand-2) 20%, transparent), transparent 70%); }
.hero-inner, .wrap { max-width: 1100px; margin: 0 auto; }
.wrap { padding: 3.5rem 1.25rem 0; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.78rem; font-weight: 700; color: var(--link); margin: 0 0 0.75rem; }
.hero h1 { font-size: clamp(2.3rem, 5.5vw, 3.8rem); line-height: 1.08; letter-spacing: -0.035em; margin: 0 0 1rem; max-width: 44rem; }
.sub { font-size: 1.2rem; color: var(--muted); max-width: 40rem; margin: 0 0 2rem; }
.hero-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.btn-primary, .btn-ghost { display: inline-block; padding: 0.8rem 1.4rem; border-radius: 8px; font: 600 1rem var(--font); text-decoration: none; cursor: pointer; }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border: 0; }
.btn-primary:hover { color: #fff; filter: brightness(1.08); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--brand); }
.wrap h2 { font-size: 1.8rem; letter-spacing: -0.02em; margin: 0 0 1.25rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 1.1rem; margin: 1.25rem 0; }
.card { display: flex; flex-direction: column; padding: 1.3rem 1.4rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); text-decoration: none; color: var(--text); transition: border-color 0.15s, transform 0.15s; }
.card:hover { border-color: var(--brand); transform: translateY(-2px); color: var(--text); }
.card h3 { margin: 0 0 0.4rem !important; font-size: 1.1rem; }
.card p { margin: 0 0 1rem !important; color: var(--muted); font-size: 0.93rem; flex: 1; }
.more { color: var(--link); font-weight: 600; font-size: 0.9rem; }
.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.list li { display: flex; justify-content: space-between; gap: 1rem; padding: 0.85rem 0; border-bottom: 1px solid var(--border); }
.help { padding: 1.75rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); margin-bottom: 4rem; }
.help h2 { font-size: 1.3rem; margin-bottom: 0.4rem; }
.help p { margin: 0; }

/* Footer */
.footer { border-top: 1px solid var(--border); background: var(--surface); margin-top: 2rem; }
.footer-inner { max-width: 1480px; margin: 0 auto; padding: 2rem 1.25rem; display: grid; grid-template-columns: 1fr auto; gap: 1rem 2rem; font-size: 0.9rem; }
.footer ul { list-style: none; display: flex; gap: 1.25rem; margin: 0; padding: 0; flex-wrap: wrap; align-items: center; }
.footer a { color: var(--muted); text-decoration: none; }
.footer a:hover { color: var(--text); text-decoration: underline; }
.footer p { grid-column: 1 / -1; margin: 0; }

/* Search + lightbox */
.search-modal, .lightbox { position: fixed; inset: 0; z-index: 200; }
.search-modal[hidden], .lightbox[hidden] { display: none; }
.search-modal { background: rgba(8, 9, 14, 0.6); display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; }
.search-panel { width: min(40rem, 92vw); background: var(--bg); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45); overflow: hidden; }
.search-input { width: 100%; padding: 1.1rem 1.25rem; border: 0; border-bottom: 1px solid var(--border); background: transparent; color: var(--text); font: 1.05rem var(--font); outline: none; }
.search-results { list-style: none; margin: 0; padding: 0.4rem; max-height: 50vh; overflow-y: auto; }
.search-results a { display: block; padding: 0.7rem 0.9rem; border-radius: 8px; text-decoration: none; color: var(--text); }
.search-results a[aria-selected='true'], .search-results a:hover { background: var(--surface-2); }
.search-results .r-title { font-weight: 600; }
.search-results .r-sec { font-size: 0.75rem; color: var(--muted); margin-left: 0.5rem; }
.search-results .r-snip { display: block; font-size: 0.85rem; color: var(--muted); margin-top: 0.15rem; }
.search-results mark { background: color-mix(in srgb, var(--brand) 35%, transparent); color: inherit; border-radius: 2px; }
.search-empty { padding: 1.25rem; color: var(--muted); }
.search-hint { margin: 0; padding: 0.6rem 1rem; border-top: 1px solid var(--border); font-size: 0.78rem; color: var(--muted); }
.lightbox { background: rgba(0, 0, 0, 0.88); display: flex; align-items: center; justify-content: center; cursor: zoom-out; padding: 2rem; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; background: #fff; }
.scrim { display: none; }

/* Responsive */
@media (max-width: 1200px) {
  .layout { grid-template-columns: 16.5rem minmax(0, 1fr); }
  .toc { display: none; }
  .content { padding: 1.75rem 2rem 4rem; }
}
@media (max-width: 900px) {
  .burger { display: inline-flex; }
  .topnav, .search-btn span, .search-btn kbd { display: none; }
  .search-btn { min-width: 0; }
  .layout { display: block; }
  .sidebar { position: fixed; z-index: 70; left: 0; top: var(--topbar-h); width: min(20rem, 85vw); background: var(--bg); transform: translateX(-100%); transition: transform 0.2s; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 60; background: rgba(0, 0, 0, 0.5); }
  .content { padding: 1.25rem 1.1rem 3rem; }
  .article h1 { font-size: 2rem; }
  .footer-inner { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
@media print { .topbar, .sidebar, .toc, .feedback, .pager, .footer, .copy { display: none !important; } .layout { display: block; } .content { padding: 0; } }

.not-found { padding-top: 6rem; text-align: center; }
