/* ---------- theme tokens for code ---------- */
:root, :root[data-theme='dark'] {
  --code-bg: #101016;
  --code-head: #17161d;
  --hl-text: #d6d3e0; --hl-comment: #6e6a80; --hl-keyword: #f06a8d; --hl-string: #9fe0a8;
  --hl-number: #fba66a; --hl-title: #7cc4ff; --hl-type: #f5cf6b; --hl-attr: #c4a6ff;
}
:root[data-theme='light'] {
  --code-bg: #fafafc;
  --code-head: #f1f1f6;
  --hl-text: #2b2a35; --hl-comment: #8a869a; --hl-keyword: #cf1d57; --hl-string: #17874f;
  --hl-number: #c4560f; --hl-title: #1d63b8; --hl-type: #9a6a00; --hl-attr: #7240c9;
}

/* ---------- docs header ---------- */
.dh {
  position: sticky; top: 0; z-index: 30; height: 64px; display: flex; align-items: center; gap: 12px;
  padding: 0 20px; background: var(--nav-bg); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.dh .brand { letter-spacing: .08em; margin-right: 6px; }
.brand-tag { font-style: normal; font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; }
.dh-menu { display: none; }
.search-trigger {
  flex: 0 1 460px; margin-inline: auto; display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 12px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; color: var(--muted); font: inherit; font-size: 14px; cursor: pointer; text-align: left;
}
.search-trigger:hover { border-color: color-mix(in srgb, var(--pink) 55%, var(--line)); color: var(--text); }
.search-trigger span { flex: 1; }
.dh-links { display: flex; gap: 20px; margin-left: 8px; }
.dh-links a { color: var(--muted); font-size: 14px; font-weight: 500; }
.dh-links a:hover { color: var(--text); text-decoration: none; }

/* ---------- 3 column shell ---------- */
.docs-page main { flex: none; }
.dshell { display: grid; grid-template-columns: 290px minmax(0, 1fr) 250px; max-width: 1480px; margin: 0 auto; width: 100%; flex: 1; }
.dside {
  position: sticky; top: 64px; align-self: start; height: calc(100vh - 64px); overflow-y: auto;
  padding: 24px 12px 40px 20px; border-right: 1px solid var(--line); scrollbar-width: thin;
}
.dmain { min-width: 0; padding: 40px 56px 80px; }
.dart { max-width: 780px; margin: 0 auto; }
.dtoc { position: sticky; top: 64px; align-self: start; max-height: calc(100vh - 64px); overflow-y: auto; padding: 40px 20px 40px 0; font-size: 13.5px; }

/* sidebar nav */
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list > li { margin: 2px 0; }
.nav-row { display: flex; align-items: center; border-radius: 10px; position: relative; }
.nav-row a { flex: 1; min-width: 0; padding: 7px 12px; color: var(--muted); font-size: 14.5px; font-weight: 500; border-radius: 10px; overflow: hidden; text-overflow: ellipsis; }
.nav-row:hover { background: var(--bg-2); }
.nav-row:hover a { color: var(--text); text-decoration: none; }
.nav-row.parent a { color: var(--text); }
.nav-row.current { background: color-mix(in srgb, var(--pink) 13%, transparent); }
.nav-row.current a { color: var(--link); font-weight: 600; }
.chev { display: grid; place-items: center; width: 26px; height: 26px; margin-right: 4px; border: 0; background: none; color: var(--muted); border-radius: 6px; cursor: pointer; transition: transform .15s; }
.chev:hover { background: var(--bg-3); color: var(--text); }
.has-sub.open > .nav-row .chev { transform: rotate(90deg); }
.nav-sub { margin: 2px 0 4px 18px; padding-left: 8px; border-left: 1px solid var(--line); display: none; }
.has-sub.open > .nav-sub { display: block; }

/* breadcrumbs + title */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 18px; }
.crumbs a { color: var(--muted); font-weight: 500; }
.crumbs a:hover { color: var(--text); }
.crumbs svg { opacity: .6; }
.dtitle h1 { font-size: 40px; line-height: 1.15; letter-spacing: -.02em; margin: 0 0 12px; }
.ddesc { font-size: 18px; color: var(--muted); margin: 0 0 8px; line-height: 1.55; }
.dtitle { padding-bottom: 8px; margin-bottom: 28px; border-bottom: 1px solid var(--line); }
.dtitle:not(:has(.ddesc)) { border-bottom: 0; margin-bottom: 8px; }

/* footer of article */
.dfoot { margin-top: 64px; }
.dmeta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); padding-bottom: 20px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.dmeta a { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.dmeta a:hover { color: var(--text); }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.pager a { display: flex; align-items: center; gap: 14px; border: 1px solid var(--line); border-radius: 14px; padding: 16px 20px; color: var(--text); font-weight: 600; transition: border-color .15s, transform .15s; }
.pager a:hover { border-color: var(--pink); text-decoration: none; transform: translateY(-1px); }
.pager a.next { justify-content: space-between; text-align: right; }
.pager small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.pager svg { color: var(--muted); flex: none; }

/* table of contents */
.toc-title { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.dtoc nav { display: flex; flex-direction: column; border-left: 1px solid var(--line); }
.dtoc a { color: var(--muted); padding: 4px 0 4px 14px; margin-left: -1px; border-left: 2px solid transparent; line-height: 1.4; }
.dtoc a.l3 { padding-left: 28px; font-size: 13px; }
.dtoc a:hover { color: var(--text); text-decoration: none; }
.dtoc a.on { color: var(--link); border-left-color: var(--pink); font-weight: 500; }

/* mobile drawer */
.scrim { display: none; }

/* ---------- search modal ---------- */
.search-modal { position: fixed; inset: 0; z-index: 100; display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; background: rgba(8, 6, 14, .6); backdrop-filter: blur(3px); }
.search-modal[hidden] { display: none; }
.search-box { width: min(640px, 100%); max-height: 70vh; display: flex; flex-direction: column; background: var(--bg); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.search-input { display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--line); color: var(--muted); }
.search-input input { flex: 1; border: 0; background: none; padding: 16px 0; font-size: 16px; outline: none; border-radius: 0; }
.search-input input:focus { outline: none; }
.search-results { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.search-results li a { display: block; padding: 10px 12px; border-radius: 10px; color: var(--text); }
.search-results li a:hover { text-decoration: none; }
.search-results li.on a, .search-results li a:hover { background: color-mix(in srgb, var(--pink) 12%, var(--bg-2)); }
.sr-title { font-weight: 600; font-size: 14.5px; }
.sr-crumb { font-size: 12px; color: var(--muted); margin-left: 6px; font-weight: 400; }
.sr-snip { font-size: 13px; color: var(--muted); margin-top: 2px; line-height: 1.5; }
.search-results mark { background: color-mix(in srgb, var(--orange) 35%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.search-empty { padding: 28px; text-align: center; color: var(--muted); font-size: 14px; }
.search-foot { display: flex; gap: 18px; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); background: var(--bg-2); }
.search-foot kbd { margin-right: 4px; }

/* ---------- prose ---------- */
.prose { font-size: 16px; line-height: 1.75; overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose h1 { font-size: 34px; line-height: 1.2; letter-spacing: -.02em; margin: 40px 0 16px; }
.prose h2 { font-size: 27px; line-height: 1.3; letter-spacing: -.015em; margin: 2.2em 0 .6em; }
.prose h3 { font-size: 21px; line-height: 1.35; margin: 1.9em 0 .5em; }
.prose h4 { font-size: 17px; margin: 1.6em 0 .4em; }
.prose h2, .prose h3 { position: relative; }
.prose .anchor { position: absolute; left: -1.1em; opacity: 0; color: var(--muted); font-weight: 400; transition: opacity .12s; }
.prose h2:hover .anchor, .prose h3:hover .anchor, .prose .anchor:focus { opacity: 1; text-decoration: none; }
.prose p, .prose ul, .prose ol { margin: 0 0 1.1em; }
.prose ul, .prose ol { padding-left: 1.5em; }
.prose li { margin: .35em 0; }
.prose li::marker { color: var(--muted); }
.prose a { text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--link) 40%, transparent); text-underline-offset: 3px; }
.prose a:hover { text-decoration-color: var(--link); }
.prose a.ext::after { content: '↗'; font-size: .8em; margin-left: 2px; opacity: .7; }
.prose strong { font-weight: 650; }
.prose code { font-family: var(--mono); font-size: .86em; background: var(--bg-3); border: 1px solid var(--line); padding: .12em .38em; border-radius: 6px; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.4em 0; }
.prose img { border-radius: 12px; border: 1px solid var(--line); }
.prose figure { margin: 1.4em 0; }
.prose figcaption { text-align: center; font-size: 13px; color: var(--muted); margin-top: 8px; }
.prose input[type=checkbox] { width: auto; margin-right: 8px; accent-color: var(--pink); }
.prose ul:has(input[type=checkbox]) { list-style: none; padding-left: 4px; }

/* quotes */
.prose blockquote { margin: 0 0 1.2em; padding: 4px 0 4px 18px; border-left: 3px solid var(--line); color: var(--muted); }
.prose blockquote p:last-child { margin-bottom: 0; }

/* callouts */
.prose blockquote.callout {
  --c: #7cc4ff; position: relative; padding: 14px 18px 14px 50px; color: var(--text); border: 1px solid color-mix(in srgb, var(--c) 40%, var(--line));
  border-radius: 12px; background: color-mix(in srgb, var(--c) 9%, var(--bg));
}
.callout-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.prose blockquote.callout::before {
  content: ''; position: absolute; left: 17px; top: 17px; width: 20px; height: 20px; background: var(--c);
  -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat;
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4M12 8h.01'/%3E%3C/svg%3E");
}
.prose blockquote.callout.note { --c: #a98bff; }
.prose blockquote.callout.info { --c: #4da3ff; }
.prose blockquote.callout.tip, .prose blockquote.callout.success { --c: #2fbf79; }
.prose blockquote.callout.warning { --c: #e5a50a; }
.prose blockquote.callout.danger { --c: #f0476a; }
.prose blockquote.callout.tip::before, .prose blockquote.callout.success::before {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='m8 12 3 3 5-6'/%3E%3C/svg%3E");
}
.prose blockquote.callout.warning::before {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0zM12 9v4M12 17h.01'/%3E%3C/svg%3E");
}
.prose blockquote.callout.danger::before {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7.9 2h8.2L22 7.9v8.2L16.1 22H7.9L2 16.1V7.9zM15 9l-6 6M9 9l6 6'/%3E%3C/svg%3E");
}

/* tables */
.table-wrap { overflow-x: auto; margin: 0 0 1.4em; border: 1px solid var(--line); border-radius: 12px; }
.prose table { border-collapse: collapse; width: 100%; font-size: 15px; }
.prose th, .prose td { padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--line); }
.prose tr:last-child td { border-bottom: 0; }
.prose th { background: var(--bg-2); font-weight: 600; font-size: 13.5px; white-space: nowrap; }

/* code blocks */
.codebox { margin: 1.4em 0; border: 1px solid var(--line); border-radius: 12px; background: var(--code-bg); overflow: hidden; }
.code-head { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 5px 8px 5px 16px; background: var(--code-head); border-bottom: 1px solid var(--line); font-size: 12.5px; }
.code-title { flex: 1; min-width: 0; font-family: var(--mono); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-lang { font: 600 11px var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.copy { display: inline-flex; align-items: center; gap: 6px; font: 500 12px 'Inter', sans-serif; color: var(--muted); background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 5px 10px; cursor: pointer; }
.copy:hover { background: var(--bg-3); color: var(--text); }
.copy.done { color: #2fbf79; }
.codebox pre { margin: 0; padding: 16px 18px; max-height: 440px; overflow: auto; scrollbar-width: thin; }
.prose pre code { display: block; background: none; border: 0; padding: 0; font-size: 13.5px; line-height: 1.65; white-space: pre; width: max-content; min-width: 100%; }
.hljs { color: var(--hl-text); }
.hljs-comment, .hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-doctag, .hljs-tag, .hljs-name, .hljs-selector-class, .hljs-selector-id, .hljs-deletion { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-addition { color: var(--hl-string); }
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-variable, .hljs-template-variable { color: var(--hl-number); }
.hljs-title, .hljs-section, .hljs-title.function_ { color: var(--hl-title); }
.hljs-built_in, .hljs-type, .hljs-title.class_ { color: var(--hl-type); }
.hljs-attr, .hljs-attribute, .hljs-property { color: var(--hl-attr); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

/* tabs */
.tabs { margin: 1.4em 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg); }
.tab-list { display: flex; gap: 2px; padding: 6px 8px 0; background: var(--code-head); border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tab-btn { font: 500 13.5px 'Inter', sans-serif; color: var(--muted); background: none; border: 0; padding: 8px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab-btn:hover { color: var(--text); }
.tab-btn.on { color: var(--link); border-bottom-color: var(--pink); }
.tab-panel { display: none; padding: 4px 18px 0; }
.tab-panel.on { display: block; }
.tab-panel .codebox { margin: 14px 0; }
.tab-panel > :last-child { margin-bottom: 16px; }
.tab-panel > :first-child { margin-top: 14px; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin: 1.4em 0; }
.prose a.card-link { display: flex; flex-direction: column; gap: 4px; padding: 18px 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg-2); color: var(--text); text-decoration: none; transition: border-color .15s, transform .15s; }
.prose a.card-link:hover { border-color: var(--pink); transform: translateY(-2px); }
.card-link strong { font-size: 16px; }
.card-link span { font-size: 14px; color: var(--muted); line-height: 1.5; }

/* expandable */
.expand { margin: 1.2em 0; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-2); }
.expand summary { cursor: pointer; padding: 12px 18px; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 10px; }
.expand summary::-webkit-details-marker { display: none; }
.expand summary::before { content: '›'; font-size: 20px; line-height: 1; color: var(--muted); transition: transform .15s; }
.expand[open] summary::before { transform: rotate(90deg); }
.expand-body { padding: 0 18px 4px; border-top: 1px solid var(--line); padding-top: 14px; }
.expand-body > :last-child { margin-bottom: 12px; }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .dshell { grid-template-columns: 270px minmax(0, 1fr); }
  .dtoc { display: none; }
  .dmain { padding-inline: 40px; }
}
@media (max-width: 860px) {
  .dh { padding: 0 12px; gap: 8px; }
  .dh-menu { display: inline-grid; }
  .dh-links, .dh-cta, .brand-tag { display: none; }
  .search-trigger { flex: 1; margin-inline: 0; }
  .search-trigger kbd { display: none; }
  .dshell { grid-template-columns: 1fr; }
  .dside {
    position: fixed; z-index: 50; top: 0; left: 0; bottom: 0; width: min(310px, 86vw); height: auto; padding-top: 80px;
    background: var(--bg); transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow);
  }
  body.side-open .dside { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 40; background: rgba(8, 6, 14, .55); }
  body.side-open .scrim { display: block; }
  .dh { z-index: 60; }
  .dmain { padding: 28px 18px 64px; }
  .dtitle h1 { font-size: 32px; }
  .pager { grid-template-columns: 1fr; }
  .prose .anchor { display: none; }
}

/* {placeholder} tokens in plain code blocks */
.hljs-placeholder { color: var(--text); font-weight: 600; }

/* sidebar section headings (groups) */
.nav-list > li.group { margin: 0; }
.group-label { padding: 20px 12px 6px; font-size: 11.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.nav-list > li.group:first-child .group-label { padding-top: 4px; }

/* images: position (left / right / center / full) and width come from the URL fragment */
.prose .img { display: inline-block; max-width: 100%; vertical-align: top; }
.prose .img img { display: block; max-width: 100%; height: auto; cursor: zoom-in; }
.prose .img[style] img { width: 100%; }
.prose .img.center { display: block; width: fit-content; margin: 1.4em auto; }
.prose .img.full { display: block; width: 100%; margin: 1.4em 0; }
.prose .img.left { float: left; max-width: 55%; margin: .3em 1.6em 1em 0; }
.prose .img.right { float: right; max-width: 55%; margin: .3em 0 1em 1.6em; }
.prose .cap { display: block; margin-top: 8px; font-size: 13px; color: var(--muted); text-align: center; }
.prose h2, .prose h3, .prose h4, .prose hr { clear: both; }
.prose::after { content: ''; display: block; clear: both; }
@media (max-width: 640px) { .prose .img.left, .prose .img.right { float: none; display: block; max-width: 100%; margin: 1.2em 0; } }

/* image lightbox */
.lightbox { position: fixed; inset: 0; z-index: 120; display: grid; place-items: center; padding: 24px; background: rgba(8, 6, 14, .85); cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; box-shadow: var(--shadow); }
