:root {
  color-scheme: light;
  --bg: #f6f8fc;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-soft: #eaf2ff;
  --accent: #06b6d4;
  --success: #10b981;
  --danger: #dc2626;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
  --topbar-height: 68px;
  --sidebar-width: 270px;
  --toc-width: 220px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #111827;
  --surface-muted: #172033;
  --text: #f1f5f9;
  --muted: #a8b3c5;
  --faint: #7b8799;
  --line: #273449;
  --line-strong: #3a4960;
  --primary: #60a5fa;
  --primary-strong: #93c5fd;
  --primary-soft: #162a48;
  --accent: #22d3ee;
  --success: #34d399;
  --danger: #f87171;
  --code-bg: #020617;
  --code-text: #e2e8f0;
  --shadow: 0 16px 38px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-height) + 24px); }
body { margin: 0; color: var(--text); background: var(--bg); font-family: "Aptos", "Segoe UI Variable", "Segoe UI", sans-serif; font-size: 15px; line-height: 1.65; }
body.drawer-open { overflow: hidden; }
button, input { font: inherit; }
a { color: var(--primary); }
img { max-width: 100%; height: auto; }

.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 200; padding: 10px 14px; border-radius: 10px; color: #fff; background: var(--primary); transform: translateY(-160%); }
.skip-link:focus { transform: translateY(0); }
:focus-visible { outline: 3px solid rgba(37, 99, 235, 0.45); outline-offset: 3px; }

.topbar { position: sticky; top: 0; z-index: 100; display: flex; height: var(--topbar-height); align-items: center; gap: 18px; padding: 0 24px; border-bottom: 1px solid var(--line); background: var(--surface); backdrop-filter: blur(16px); }
.brand { display: inline-flex; align-items: center; flex: 0 0 auto; gap: 10px; color: var(--text); text-decoration: none; }
.brand img { width: 38px; height: 38px; }
.brand span { display: grid; line-height: 1.05; }
.brand strong { font: 700 17px "Bahnschrift", "Aptos Display", sans-serif; letter-spacing: -.02em; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.top-links { display: flex; align-items: center; gap: 4px; }
.top-links a { min-height: 40px; padding: 9px 11px; border-radius: 9px; color: var(--muted); font-size: 13px; font-weight: 650; text-decoration: none; }
.top-links a:hover { color: var(--text); background: var(--surface-muted); }
.back-link { display: inline-flex; min-height: 40px; align-items: center; justify-content: center; padding: 8px 13px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: var(--surface); font-size: 12px; font-weight: 700; text-decoration: none; white-space: nowrap; }
.back-link:hover { border-color: var(--primary); color: var(--primary); }

.search { position: relative; max-width: 330px; min-width: 190px; flex: 1 1 290px; margin-left: auto; }
.search input { width: 100%; height: 40px; padding: 0 42px 0 36px; border: 1px solid var(--line); border-radius: 11px; color: var(--text); background: var(--surface-muted); outline: none; }
.search input:focus { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14); }
.search-icon { position: absolute; top: 8px; left: 12px; z-index: 1; color: var(--muted); font-size: 18px; }
.search kbd { position: absolute; top: 9px; right: 10px; padding: 1px 7px; border: 1px solid var(--line-strong); border-radius: 6px; color: var(--faint); background: var(--surface); font-size: 11px; }
.search-results { position: absolute; top: 48px; right: 0; left: 0; z-index: 130; max-height: min(520px, calc(100vh - 90px)); overflow-y: auto; padding: 7px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.search-results a { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px; border-radius: 9px; color: var(--text); text-decoration: none; }
.search-results a:hover, .search-results a:focus { background: var(--primary-soft); }
.search-results strong { font-size: 13px; }
.search-results span { color: var(--primary); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.search-results p { grid-column: 1 / -1; margin: 2px 0 0; color: var(--muted); font-size: 11px; line-height: 1.35; }
.search-message { padding: 14px; color: var(--muted); font-size: 12px; text-align: center; }

.theme-button, .icon-button { display: inline-flex; min-width: 40px; min-height: 40px; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: var(--surface); cursor: pointer; }
.theme-button { gap: 6px; padding: 8px 11px; font-size: 12px; font-weight: 700; }
.theme-button:hover, .icon-button:hover { border-color: var(--primary); color: var(--primary); }
.theme-symbol { font-size: 17px; }
.menu-button, .mobile-sidebar-header, .mobile-back { display: none; }

.docs-layout { display: grid; max-width: 1540px; min-height: calc(100vh - var(--topbar-height)); grid-template-columns: var(--sidebar-width) minmax(0, 820px) var(--toc-width); justify-content: center; gap: 46px; margin: 0 auto; padding: 32px 28px 80px; }
.sidebar { position: sticky; top: calc(var(--topbar-height) + 24px); align-self: start; max-height: calc(100vh - var(--topbar-height) - 48px); overflow-y: auto; padding: 0 12px 20px 0; scrollbar-width: thin; }
.nav-section + .nav-section { margin-top: 24px; }
.nav-section h2 { margin: 0 0 7px 12px; color: var(--faint); font-size: 10px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.nav-section a { display: flex; min-height: 38px; align-items: center; margin: 2px 0; padding: 7px 12px; border-radius: 9px; color: var(--muted); font-size: 13px; font-weight: 600; text-decoration: none; }
.nav-section a:hover { color: var(--text); background: var(--surface-muted); }
.nav-section a.is-active { color: var(--primary-strong); background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.sidebar-note { display: grid; gap: 4px; margin: 28px 6px 0; padding: 13px; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); background: var(--surface-muted); font-size: 11px; }
.sidebar-note strong { color: var(--text); font-size: 12px; }

.main-column { min-width: 0; }
.breadcrumbs { display: flex; min-height: 30px; align-items: center; gap: 8px; margin-bottom: 16px; overflow: hidden; color: var(--faint); font-size: 11px; white-space: nowrap; }
.breadcrumbs a { color: var(--muted); text-decoration: none; }
.breadcrumbs strong { overflow: hidden; color: var(--text); text-overflow: ellipsis; }
.doc-content { min-height: 560px; padding: 42px 48px 52px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.doc-content > :first-child { margin-top: 0; }
.doc-content h1, .doc-content h2, .doc-content h3, .doc-content h4 { position: relative; color: var(--text); font-family: "Bahnschrift", "Aptos Display", sans-serif; line-height: 1.25; letter-spacing: -.025em; scroll-margin-top: calc(var(--topbar-height) + 24px); }
.doc-content h1 { margin: 0 0 28px; padding-bottom: 22px; border-bottom: 1px solid var(--line); font-size: clamp(30px, 4vw, 42px); }
.doc-content h2 { margin: 44px 0 16px; padding-top: 4px; font-size: 25px; }
.doc-content h3 { margin: 30px 0 12px; font-size: 19px; }
.doc-content h4 { margin: 24px 0 10px; font-size: 16px; }
.heading-anchor { margin-left: 8px; color: transparent; font-size: .7em; text-decoration: none; }
.doc-content h2:hover .heading-anchor, .doc-content h3:hover .heading-anchor, .heading-anchor:focus { color: var(--primary); }
.doc-content p { margin: 0 0 17px; color: var(--muted); }
.doc-content strong { color: var(--text); }
.doc-content a { color: var(--primary); text-underline-offset: 3px; }
.doc-content ul, .doc-content ol { margin: 0 0 20px; padding-left: 24px; color: var(--muted); }
.doc-content li { margin: 7px 0; padding-left: 3px; }
.doc-content li::marker { color: var(--primary); font-weight: 700; }
.doc-content input[type="checkbox"] { width: 15px; height: 15px; margin: 0 6px 0 0; accent-color: var(--primary); vertical-align: -2px; }
.doc-content code { padding: 2px 6px; border: 1px solid var(--line); border-radius: 6px; color: var(--primary-strong); background: var(--primary-soft); font: 12px "Cascadia Code", "SFMono-Regular", Consolas, monospace; }
.doc-content pre { max-width: 100%; margin: 22px 0; overflow: auto; padding: 18px 20px; border: 1px solid #273449; border-radius: 13px; background: var(--code-bg); }
.doc-content pre code { padding: 0; border: 0; color: var(--code-text); background: transparent; font-size: 12px; line-height: 1.65; }
.doc-content blockquote { margin: 22px 0; padding: 13px 18px; border-left: 4px solid var(--accent); border-radius: 0 10px 10px 0; color: var(--muted); background: var(--surface-muted); }
.doc-content hr { height: 1px; margin: 36px 0; border: 0; background: var(--line); }
.table-wrap { max-width: 100%; margin: 22px 0; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 13px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--text); background: var(--surface-muted); font-size: 11px; letter-spacing: .03em; text-transform: uppercase; }
td { color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }

.toc-column { position: sticky; top: calc(var(--topbar-height) + 30px); align-self: start; }
.toc-card { padding-left: 16px; border-left: 1px solid var(--line); }
.toc-card > strong { display: block; margin-bottom: 10px; color: var(--text); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.toc-card nav { display: grid; gap: 3px; }
.toc-card a { padding: 4px 7px; border-radius: 6px; color: var(--muted); font-size: 11px; line-height: 1.35; text-decoration: none; }
.toc-card a:hover { color: var(--primary); background: var(--primary-soft); }
.toc-level-3 { margin-left: 10px; }
.toc-empty { color: var(--faint); font-size: 11px; }

.page-navigation { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.page-navigation a { display: grid; min-height: 78px; align-content: center; padding: 13px 16px; border: 1px solid var(--line); border-radius: 13px; color: var(--text); background: var(--surface); text-decoration: none; }
.page-navigation a:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.page-navigation span { color: var(--faint); font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.page-navigation strong { margin-top: 3px; color: var(--primary); font-size: 13px; }
.next-page { text-align: right; }

.loading-state, .error-state { display: grid; min-height: 400px; place-content: center; justify-items: center; color: var(--muted); text-align: center; }
.loading-state span { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
.error-state strong { color: var(--danger); font-size: 18px; }
.error-state button { min-height: 42px; padding: 8px 16px; border: 0; border-radius: 10px; color: #fff; background: var(--primary); cursor: pointer; }
.drawer-overlay { position: fixed; inset: var(--topbar-height) 0 0; z-index: 80; background: rgba(2, 6, 23, .52); }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1240px) {
  .top-links { display: none; }
  .docs-layout { grid-template-columns: var(--sidebar-width) minmax(0, 820px); gap: 34px; }
  .toc-column { display: none; }
}

@media (max-width: 820px) {
  :root { --topbar-height: 62px; }
  .topbar { gap: 10px; padding: 0 14px; }
  .menu-button { display: inline-flex; }
  .brand small, .theme-button #themeLabel, .desktop-back, .search kbd { display: none; }
  .brand img { width: 34px; height: 34px; }
  .brand strong { font-size: 15px; }
  .search { min-width: 0; flex-basis: auto; }
  .search input { height: 42px; }
  .theme-button { min-width: 42px; padding: 0; }
  .docs-layout { display: block; padding: 18px 14px 56px; }
  .sidebar { position: fixed; top: var(--topbar-height); bottom: 0; left: 0; z-index: 90; width: min(88vw, 320px); max-height: none; padding: 14px 16px 30px; border-right: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); transform: translateX(-105%); transition: transform .2s ease; }
  .sidebar.is-open { transform: translateX(0); }
  .mobile-sidebar-header { display: flex; min-height: 48px; align-items: center; justify-content: space-between; margin-bottom: 8px; }
  .mobile-back { display: flex; min-height: 46px; margin-bottom: 20px; }
  .nav-section a { min-height: 44px; }
  .breadcrumbs { margin: 0 4px 12px; }
  .doc-content { min-height: 480px; padding: 30px 24px 40px; border-radius: 15px; }
  .doc-content h1 { font-size: 30px; }
  .doc-content h2 { font-size: 22px; }
}

@media (max-width: 520px) {
  .brand span { display: none; }
  .search { flex: 1 1 auto; }
  .doc-content { padding: 26px 18px 34px; }
  .page-navigation { grid-template-columns: 1fr; }
  .page-navigation a { min-height: 68px; }
  .next-page { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
