:root {
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-2: #f1f3ee;
  --surface-3: #e8ece5;
  --text: #18201b;
  --muted: #667069;
  --line: #dce2dc;
  --line-strong: #c8d1c9;
  --brand: #166534;
  --brand-strong: #0d4f27;
  --brand-soft: #e2f4e8;
  --code-bg: #111a14;
  --code-text: #e5f1e8;
  --shadow: 0 18px 50px rgba(25, 43, 32, 0.12);
  --header-height: 68px;
  --sidebar-width: 286px;
  --toc-width: 244px;
  --content-width: 790px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #101512;
  --surface: #171d19;
  --surface-2: #1d2520;
  --surface-3: #28322b;
  --text: #e9efe9;
  --muted: #a2aea5;
  --line: #2b362f;
  --line-strong: #3a473e;
  --brand: #62c989;
  --brand-strong: #9be3b5;
  --brand-soft: #193d27;
  --code-bg: #090d0a;
  --code-text: #dce9df;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.42);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-height) + 22px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
a { color: var(--brand); text-underline-offset: 3px; }
a:hover { color: var(--brand-strong); }

.skip-link {
  position: fixed; top: 8px; left: 8px; z-index: 100;
  transform: translateY(-150%); padding: 9px 14px; border-radius: 8px;
  background: var(--text); color: var(--surface); text-decoration: none;
}
.skip-link:focus { transform: none; }

.topbar {
  position: fixed; inset: 0 0 auto; z-index: 40; height: var(--header-height);
  display: flex; align-items: center; gap: 18px; padding: 0 24px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border-bottom: 1px solid var(--line); backdrop-filter: blur(18px);
}
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--text); text-decoration: none; min-width: 0; }
.brand img { width: 38px; height: 38px; object-fit: contain; border-radius: 9px; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand strong { font-size: 14px; letter-spacing: -.01em; }
.brand small { color: var(--muted); font-size: 11px; margin-top: 3px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.icon-button, .search-button {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 10px; cursor: pointer; transition: border-color .15s, background .15s, transform .15s;
}
.icon-button:hover, .search-button:hover { border-color: var(--line-strong); background: var(--surface-2); }
.icon-button:active, .search-button:active { transform: translateY(1px); }
.icon-button { width: 40px; height: 40px; display: grid; place-items: center; font-size: 18px; }
.search-button { height: 40px; display: flex; align-items: center; gap: 9px; padding: 0 10px 0 13px; color: var(--muted); }
.search-button > span:first-child { font-size: 21px; line-height: 1; color: var(--text); }
kbd {
  font-family: inherit; font-size: 11px; line-height: 1; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--line); border-bottom-color: var(--line-strong);
  border-radius: 5px; padding: 4px 6px; box-shadow: 0 1px 0 var(--line);
}
.mobile-menu-button { display: none; }

.app-shell {
  display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--toc-width);
  min-height: 100vh; padding-top: var(--header-height);
}
.sidebar, .page-toc { position: sticky; top: var(--header-height); height: calc(100vh - var(--header-height)); }
.sidebar { border-right: 1px solid var(--line); background: var(--surface); }
.sidebar-scroll { height: 100%; overflow: auto; padding: 28px 18px 22px; display: flex; flex-direction: column; }
.eyebrow {
  margin: 0 10px 12px; color: var(--muted); font-size: 11px; font-weight: 750;
  line-height: 1.3; letter-spacing: .1em; text-transform: uppercase;
}
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
  position: relative; display: grid; grid-template-columns: 28px 1fr; gap: 9px; align-items: start;
  padding: 10px 11px; border-radius: 10px; color: var(--muted); text-decoration: none;
  font-size: 13px; font-weight: 580; line-height: 1.38; transition: color .15s, background .15s;
}
.nav-link:hover { color: var(--text); background: var(--surface-2); }
.nav-link.is-current { color: var(--brand-strong); background: var(--brand-soft); }
.nav-link.is-current::before { content: ""; position: absolute; left: -18px; top: 9px; bottom: 9px; width: 3px; background: var(--brand); border-radius: 0 3px 3px 0; }
.nav-index { color: var(--muted); font: 650 10px/1.9 ui-monospace, SFMono-Regular, Menlo, monospace; opacity: .72; }
.source-note {
  display: flex; align-items: center; gap: 10px; margin: auto 7px 0; padding: 14px 11px 0;
  border-top: 1px solid var(--line); line-height: 1.2;
}
.source-note div { display: flex; flex-direction: column; }
.source-note strong { font-size: 11px; }
.source-note small { color: var(--muted); font-size: 10px; margin-top: 4px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #22a655; box-shadow: 0 0 0 4px color-mix(in srgb, #22a655 14%, transparent); }

.main-content { min-width: 0; padding: 52px 42px 80px; }
.article { width: min(100%, var(--content-width)); margin: 0 auto; }
.article > h1:first-child {
  margin: 0 0 30px; font-size: clamp(34px, 5vw, 52px); line-height: 1.08;
  letter-spacing: -.045em; font-weight: 760;
}
.article h2 { margin: 2.2em 0 .75em; font-size: 29px; line-height: 1.22; letter-spacing: -.025em; }
.article h3 { margin: 2em 0 .65em; font-size: 22px; line-height: 1.3; letter-spacing: -.018em; }
.article h4 { margin: 1.8em 0 .6em; font-size: 18px; line-height: 1.35; }
.article :is(h1, h2, h3, h4) { scroll-margin-top: calc(var(--header-height) + 22px); }
.heading-anchor { margin-left: .35em; color: var(--line-strong); text-decoration: none; opacity: 0; font-weight: 500; }
.article :is(h1, h2, h3, h4):hover .heading-anchor, .heading-anchor:focus { opacity: 1; }
.article p { margin: 0 0 1.05em; }
.article strong { font-weight: 700; }
.article ul, .article ol { padding-left: 1.45em; margin: .8em 0 1.2em; }
.article li { padding-left: .22em; margin: .3em 0; }
.article li::marker { color: var(--brand); font-weight: 700; }
.article hr { border: 0; border-top: 1px solid var(--line); margin: 42px 0; }
.article blockquote {
  margin: 1.4em 0; padding: 4px 0 4px 20px; border-left: 3px solid var(--brand);
  color: var(--muted); font-size: 15px;
}
.article :not(pre) > code {
  padding: .14em .38em; color: var(--brand-strong); background: var(--brand-soft);
  border: 1px solid color-mix(in srgb, var(--brand) 14%, transparent); border-radius: 5px;
  font: 500 .88em/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}

.article figure { margin: 28px 0 34px; }
.article figure img, .article > p > img, .article .footnotes img {
  display: block; max-width: 100%; height: auto; border: 1px solid var(--line);
  border-radius: 12px; background: var(--surface); box-shadow: 0 10px 28px rgba(17, 32, 22, .08);
}
.zoomable-image { cursor: zoom-in; }
.zoomable-image:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 4px; }
.article figcaption { margin-top: 9px; color: var(--muted); text-align: center; font-size: 12px; }
.article figcaption p { margin: 0; }

.local-video {
  overflow: hidden; margin: 28px 0 34px; border: 1px solid var(--line); border-radius: 12px;
  background: #070a08; box-shadow: 0 12px 32px rgba(10, 20, 13, .18);
}
.local-video video { display: block; width: 100%; max-height: 76vh; background: #000; }
.local-video figcaption {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0;
  padding: 10px 13px; color: #c7d0ca; background: #111713; text-align: left;
}
.local-video figcaption strong { font-size: 12px; }
.local-video figcaption span { color: #8f9a92; font: 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }

.code-frame {
  position: relative; margin: 20px 0 26px; overflow: hidden; border: 1px solid #29352d;
  border-radius: 12px; background: var(--code-bg); box-shadow: 0 9px 24px rgba(0, 0, 0, .12);
}
.code-title {
  display: flex; align-items: center; min-height: 40px; box-sizing: border-box;
  padding: 9px 54px 9px 15px; color: #b7c8bc; border-bottom: 1px solid #29352d;
  font: 600 11px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.code-frame pre {
  margin: 0; padding: 18px 54px 18px 17px; overflow: auto; color: var(--code-text); background: transparent;
  white-space: pre; tab-size: 4; font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.code-frame pre code { color: inherit; font: inherit; }
.code-frame strong { color: #99e2b4; font-weight: 650; }
.copy-code {
  position: absolute; z-index: 2; top: 6px; right: 7px; display: grid; place-items: center;
  width: 28px; height: 28px; padding: 0; border: 1px solid #3a493f;
  border-radius: 7px; background: #1b261e; color: #b8c6bc; cursor: pointer;
  transition: color .15s, border-color .15s, background .15s, transform .15s;
}
.copy-code__icon {
  width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.copy-code:hover { color: #fff; border-color: #617066; background: #243228; }
.copy-code:active { transform: scale(.94); }
.copy-code:focus-visible { outline: 2px solid #58a6ff; outline-offset: 2px; }
.copy-code.is-copied { color: #8ee2aa; border-color: #477a57; background: #183622; }

.hint {
  display: grid; grid-template-columns: 25px 1fr; gap: 12px; margin: 22px 0; padding: 17px 18px;
  border: 1px solid var(--line); border-left-width: 4px; border-radius: 10px; background: var(--surface);
}
.hint__icon { display: grid; place-items: center; width: 23px; height: 23px; border-radius: 50%; font: 750 13px/1 sans-serif; }
.hint__body > :last-child { margin-bottom: 0; }
.hint--info { border-left-color: #2e78c2; background: color-mix(in srgb, #2e78c2 7%, var(--surface)); }
.hint--info .hint__icon { color: #fff; background: #2e78c2; }
.hint--warning { border-left-color: #d18a16; background: color-mix(in srgb, #d18a16 8%, var(--surface)); }
.hint--warning .hint__icon { color: #342006; background: #f5b642; }
.hint--danger { border-left-color: #c94545; background: color-mix(in srgb, #c94545 7%, var(--surface)); }
.hint--danger .hint__icon { color: #fff; background: #c94545; }
.hint--success { border-left-color: #249357; background: color-mix(in srgb, #249357 7%, var(--surface)); }
.hint--success .hint__icon { color: #fff; background: #249357; }

.video-card {
  display: grid; grid-template-columns: 42px 1fr auto; gap: 13px; align-items: center; margin: 22px 0;
  padding: 16px 18px; color: var(--text); text-decoration: none; border: 1px solid var(--line);
  border-radius: 12px; background: var(--surface); transition: border-color .15s, transform .15s, box-shadow .15s;
}
.video-card:hover { color: var(--text); border-color: var(--line-strong); transform: translateY(-1px); box-shadow: var(--shadow); }
.video-card__icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; color: #fff; background: #d13939; font-size: 13px; }
.video-card > span:nth-child(2) { min-width: 0; display: flex; flex-direction: column; }
.video-card small { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.video-card__arrow { color: var(--muted); }

.article table { width: 100%; margin: 22px 0; border-collapse: collapse; font-size: 14px; }
.article th, .article td { padding: 10px 12px; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.article th { background: var(--surface-2); font-weight: 700; }
.details-card { margin: 20px 0; padding: 13px 15px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.details-card summary { cursor: pointer; font-weight: 700; }
.footnotes { display: none; }
.footnote-ref { display: none; }

.pager { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 60px 0 28px; }
.pager-card { display: flex; flex-direction: column; min-height: 96px; padding: 16px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--text); text-decoration: none; }
.pager-card:hover { color: var(--brand-strong); border-color: var(--line-strong); }
.pager-card small { color: var(--muted); font-size: 11px; }
.pager-card span { margin-top: auto; font-size: 13px; font-weight: 650; line-height: 1.35; }
.pager-card--next { grid-column: 2; text-align: right; }
.article-footer { padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }

.page-toc { padding: 36px 24px 28px 10px; overflow: auto; border-left: 1px solid transparent; }
.page-toc nav { display: flex; flex-direction: column; gap: 2px; }
.toc-link { padding: 5px 9px; border-left: 1px solid var(--line); color: var(--muted); text-decoration: none; font-size: 11px; line-height: 1.45; }
.toc-link:hover, .toc-link.is-active { color: var(--brand-strong); border-left-color: var(--brand); }
.toc-link--3 { padding-left: 19px; }
.toc-empty { color: var(--muted); font-size: 11px; }
.back-to-top { display: inline-block; margin: 20px 10px; color: var(--muted); font-size: 11px; text-decoration: none; }

.search-dialog {
  width: min(680px, calc(100% - 32px)); max-height: min(720px, calc(100vh - 48px)); padding: 0;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.search-dialog::backdrop { background: rgba(11, 17, 13, .58); backdrop-filter: blur(3px); }
.search-panel { display: flex; flex-direction: column; max-height: min(720px, calc(100vh - 48px)); }
.search-head { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.search-head > span { color: var(--muted); font-size: 24px; }
.search-head input { min-width: 0; padding: 8px 0; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 17px; }
.search-head button { width: 32px; height: 32px; border: 0; border-radius: 7px; color: var(--muted); background: var(--surface-2); cursor: pointer; font-size: 20px; }
.search-results { min-height: 250px; overflow: auto; padding: 8px; }
.search-empty { display: flex; min-height: 230px; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-align: center; }
.search-empty strong { color: var(--text); font-size: 14px; }
.search-empty span { margin-top: 5px; font-size: 12px; }
.search-result { display: block; padding: 11px 12px; border-radius: 9px; color: var(--text); text-decoration: none; }
.search-result:hover, .search-result.is-selected { color: var(--text); background: var(--surface-2); }
.search-result strong { display: block; font-size: 13px; }
.search-result small { color: var(--muted); font-size: 10px; }
.search-result p { display: -webkit-box; overflow: hidden; margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.search-result mark { color: inherit; background: #f0cf62; border-radius: 2px; }
.search-help { display: flex; gap: 18px; padding: 9px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.search-help span { display: flex; align-items: center; gap: 4px; }

.image-lightbox, .reference-dialog {
  max-width: calc(100vw - 28px); max-height: calc(100vh - 28px); padding: 0;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
}
.image-lightbox::backdrop, .reference-dialog::backdrop { background: rgba(6, 10, 7, .82); backdrop-filter: blur(4px); }
.image-lightbox__frame { position: relative; display: flex; flex-direction: column; align-items: center; padding: 14px; }
.image-lightbox__frame img {
  display: block; width: auto; max-width: calc(100vw - 58px); height: auto; max-height: calc(100vh - 92px);
  object-fit: contain; border-radius: 8px; background: #fff;
}
.image-lightbox__caption { max-width: 820px; margin: 9px 42px 0; color: var(--muted); font-size: 12px; text-align: center; }
.dialog-close {
  position: absolute; z-index: 2; top: 8px; right: 8px; display: grid; place-items: center;
  width: 34px; height: 34px; padding: 0; border: 1px solid rgba(255,255,255,.22); border-radius: 8px;
  color: #fff; background: rgba(0,0,0,.62); cursor: pointer;
}
.dialog-close__icon {
  display: block; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.dialog-close:hover { background: rgba(0,0,0,.76); }
.dialog-close:focus-visible { outline: 2px solid #58a6ff; outline-offset: 2px; }
.reference-dialog { width: min(680px, calc(100vw - 28px)); }
.reference-dialog__frame { position: relative; padding: 28px 24px 20px; }
.reference-dialog__frame .dialog-close { color: var(--text); background: var(--surface-2); border-color: var(--line); }
.reference-dialog__body { padding-top: 12px; font-size: 14px; }
.reference-dialog__body img { display: block; max-width: 100%; height: auto; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
  .page-toc { display: none; }
}

@media (max-width: 820px) {
  :root { --header-height: 60px; }
  .topbar { padding: 0 14px; gap: 10px; }
  .brand img { width: 34px; height: 34px; }
  .brand small, .search-button > span:nth-child(2), .search-button kbd { display: none; }
  .search-button { width: 40px; padding: 0; justify-content: center; }
  .mobile-menu-button { display: grid; }
  .app-shell { display: block; }
  .sidebar {
    position: fixed; z-index: 35; top: var(--header-height); bottom: 0; left: 0; width: min(320px, calc(100vw - 44px)); height: auto;
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  body.sidebar-open { overflow: hidden; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; z-index: 34; inset: var(--header-height) 0 0; background: rgba(7, 11, 8, .48); }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .main-content { padding: 38px 22px 64px; }
  .article > h1:first-child { font-size: 38px; }
}

@media (max-width: 520px) {
  .brand strong { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .main-content { padding: 30px 17px 54px; }
  .article > h1:first-child { margin-bottom: 24px; font-size: 32px; }
  .article h2 { font-size: 25px; }
  .article h3 { font-size: 20px; }
  .code-frame { margin-left: -6px; margin-right: -6px; border-radius: 9px; }
  .code-frame pre { padding: 16px 14px; font-size: 12px; }
  .hint { grid-template-columns: 22px 1fr; gap: 9px; padding: 14px; }
  .pager { grid-template-columns: 1fr; }
  .pager-card--next { grid-column: 1; }
  .search-help { display: none; }
}

@media print {
  :root { --bg: #fff; --surface: #fff; --text: #111; --muted: #555; --line: #ddd; }
  .topbar, .sidebar, .page-toc, .pager, .article-footer, .copy-code, .heading-anchor { display: none !important; }
  .app-shell { display: block; padding: 0; }
  .main-content { padding: 0; }
  .article { width: 100%; max-width: none; }
  .article a { color: inherit; }
  .article figure, .code-frame, .hint { break-inside: avoid; }
}

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