/* ------------------------------------------------------------------ tokens */
:root {
  --bg: #ffffff;
  --surface: #f6f8fa;
  --surface-2: #eef1f4;
  --border: #e1e5ea;
  --border-strong: #cdd3db;
  --text: #17202e;
  --muted: #586274;
  --accent: #0f766e;
  --accent-strong: #0b5f58;
  --accent-soft: #e4f3f1;
  --on-accent: #ffffff;
  --code-bg: #f5f7f9;
  --code-border: #e3e7ec;
  --out-bg: #eef6f4;
  --out-text: #17342f;
  --warn: #9a5b00;
  --warn-bg: #fff6e5;
  --warn-border: #f2d9a6;
  --info: #0b5f8a;
  --info-bg: #eaf5fc;
  --info-border: #bcdcf0;
  --tip: #0f766e;
  --tip-bg: #e7f5f2;
  --tip-border: #b6e0d9;

  --syn-keyword: #7c3aed;
  --syn-string: #15803d;
  --syn-number: #b45309;
  --syn-comment: #6b7686;
  --syn-type: #0369a1;
  --syn-fn: #0f766e;
  --syn-prop: #0369a1;
  --syn-tag: #be185d;
  --syn-attr: #b45309;

  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 4px 16px rgba(15, 23, 42, 0.06);
  --sidebar-w: 288px;
  --topbar-h: 56px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #141a22;
  --surface-2: #1b232d;
  --border: #242d39;
  --border-strong: #324051;
  --text: #e5e9ef;
  --muted: #98a3b5;
  --accent: #2dd4bf;
  --accent-strong: #5eead4;
  --accent-soft: rgba(45, 212, 191, 0.12);
  --on-accent: #06211d;
  --code-bg: #111821;
  --code-border: #232d3a;
  --out-bg: #0f1d1c;
  --out-text: #c9ece6;
  --warn: #f5c26b;
  --warn-bg: rgba(245, 194, 107, 0.09);
  --warn-border: rgba(245, 194, 107, 0.3);
  --info: #7cc4ee;
  --info-bg: rgba(124, 196, 238, 0.09);
  --info-border: rgba(124, 196, 238, 0.28);
  --tip: #5eead4;
  --tip-bg: rgba(94, 234, 212, 0.08);
  --tip-border: rgba(94, 234, 212, 0.26);

  --syn-keyword: #c4b5fd;
  --syn-string: #86efac;
  --syn-number: #fdba74;
  --syn-comment: #7d8798;
  --syn-type: #7dd3fc;
  --syn-fn: #5eead4;
  --syn-prop: #7dd3fc;
  --syn-tag: #f9a8d4;
  --syn-attr: #fdba74;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

/* ------------------------------------------------------------------ base */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition: none !important; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

code, pre, kbd { font-family: var(--mono); }
code { font-size: 0.875em; }
p code, li code, td code, dd code, h1 code, h2 code, h3 code, .lead code, .callout code {
  background: var(--surface-2);
  border: 1px solid var(--code-border);
  padding: 0.08em 0.38em;
  border-radius: 5px;
  white-space: normal;
  word-break: break-word;
}
a code { color: inherit; }

.skip {
  position: absolute; left: -999px; top: 8px; z-index: 100;
  background: var(--accent); color: var(--on-accent); padding: 8px 14px; border-radius: 8px;
}
.skip:focus { left: 8px; text-decoration: none; }

/* ------------------------------------------------------------------ topbar */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 40;
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-spacer { flex: 1; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.logo { color: var(--accent); flex: none; }
.version {
  font-size: 12px; font-weight: 600; color: var(--accent-strong);
  background: var(--accent-soft); padding: 2px 8px; border-radius: 999px;
}
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  background: transparent; border: 0; border-radius: 10px; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.menu-btn { display: none; margin-left: -8px; }
#themeBtn .i-sun { display: none; }
:root[data-theme="dark"] #themeBtn .i-sun { display: block; }
:root[data-theme="dark"] #themeBtn .i-moon { display: none; }

.search-btn {
  display: inline-flex; align-items: center; gap: 10px; min-width: 260px; height: 38px; padding: 0 10px 0 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  color: var(--muted); font: inherit; font-size: 14px; cursor: pointer;
}
.search-btn:hover { border-color: var(--border-strong); color: var(--text); }
.search-label { flex: 1; text-align: left; }
.kbd {
  font-size: 11px; line-height: 1; padding: 4px 6px; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 6px;
}

/* ------------------------------------------------------------------ layout */
.layout { padding-top: var(--topbar-h); display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: var(--topbar-h); align-self: start;
  height: calc(100vh - var(--topbar-h)); overflow-y: auto; overscroll-behavior: contain;
  padding: 20px 14px 40px 18px; border-right: 1px solid var(--border); background: var(--bg);
  scrollbar-width: thin;
}
.main { min-width: 0; outline: none; }
.page {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 56px;
  max-width: 1120px; margin: 0 auto; padding: 40px 32px 80px;
}
.article { min-width: 0; max-width: 780px; }
.toc { display: none; }

@media (min-width: 1240px) {
  .page { grid-template-columns: minmax(0, 1fr) 210px; }
  .toc {
    display: block; position: sticky; top: calc(var(--topbar-h) + 28px); align-self: start;
    max-height: calc(100vh - var(--topbar-h) - 56px); overflow-y: auto; scrollbar-width: thin;
  }
}

/* ------------------------------------------------------------------ sidebar */
.nav-section { margin-bottom: 22px; }
.nav-section h4 {
  margin: 0 0 6px; padding: 0 10px; font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}
.nav-link {
  display: block; padding: 6px 10px; margin: 1px 0; border-radius: 8px;
  color: var(--text); font-size: 14.5px; line-height: 1.4;
}
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.nav-class code { font-size: 14px; background: none; border: 0; padding: 0; }
.nav-methods { margin: 2px 0 8px 12px; padding-left: 10px; border-left: 1px solid var(--border); }
.nav-group { margin: 10px 0 2px; padding: 0 10px; font-size: 12px; font-weight: 600; color: var(--muted); }
.nav-method { font-family: var(--mono); font-size: 13px; padding: 3px 10px; }

.scrim { display: none; }

/* ------------------------------------------------------------------ article text */
.eyebrow { font-size: 13px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em; margin: 0 0 6px; }
.article h1 { font-size: 2.15rem; line-height: 1.2; letter-spacing: -0.02em; margin: 0 0 12px; }
.lead { font-size: 1.15rem; color: var(--muted); margin: 0 0 8px; line-height: 1.6; }
.article h2 {
  font-size: 1.5rem; line-height: 1.3; letter-spacing: -0.01em; margin: 48px 0 12px; padding-top: 8px;
  border-top: 1px solid var(--border); scroll-margin-top: 80px;
}
.article h3 { font-size: 1.15rem; margin: 30px 0 8px; scroll-margin-top: 80px; }
.article p { margin: 0 0 14px; }
.article ul, .article ol { margin: 0 0 16px; padding-left: 22px; }
.article li { margin: 4px 0; }
.article li::marker { color: var(--muted); }
.heading-anchor {
  margin-left: 8px; font-size: 0.7em; font-weight: 500; color: var(--muted); opacity: 0; text-decoration: none !important;
}
h2:hover .heading-anchor, h3:hover .heading-anchor, .heading-anchor:focus { opacity: 1; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; margin: 0 0 20px; border: 1px solid var(--border); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
th, td { text-align: left; padding: 9px 14px; vertical-align: top; border-bottom: 1px solid var(--border); }
th { background: var(--surface); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td code { font-size: 0.84em; }
th code { text-transform: none; letter-spacing: 0; font-size: 0.95em; background: none; border: 0; padding: 0; }

/* ------------------------------------------------------------------ callouts */
.callout {
  margin: 0 0 20px; padding: 12px 16px; border-radius: 10px; border: 1px solid; font-size: 15px;
}
.callout > :last-child { margin-bottom: 0; }
.callout-title { font-size: 12px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; margin: 0 0 4px; }
.callout.tip { background: var(--tip-bg); border-color: var(--tip-border); }
.callout.tip .callout-title { color: var(--tip); }
.callout.info { background: var(--info-bg); border-color: var(--info-border); }
.callout.info .callout-title { color: var(--info); }
.callout.warn { background: var(--warn-bg); border-color: var(--warn-border); }
.callout.warn .callout-title { color: var(--warn); }
.callout ul { margin: 0; padding-left: 20px; }

/* ------------------------------------------------------------------ code */
.code { margin: 0 0 22px; border: 1px solid var(--code-border); border-radius: 12px; background: var(--code-bg); overflow: hidden; }
.code-head {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 14px;
  border-bottom: 1px solid var(--code-border); font-size: 12px; color: var(--muted);
}
.code-head .lang { font-family: var(--mono); font-weight: 600; text-transform: lowercase; }
.chip {
  font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); white-space: nowrap;
}
a.chip:hover { text-decoration: none; filter: brightness(0.96); }
.code-head .spacer { flex: 1; }
.copy {
  font: inherit; font-size: 12px; color: var(--muted); background: transparent; border: 1px solid transparent;
  padding: 3px 9px; border-radius: 7px; cursor: pointer;
}
.copy:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.copy.done { color: var(--accent-strong); }
pre { margin: 0; }
.code pre { overflow-x: auto; padding: 14px 16px; font-size: 13.5px; line-height: 1.6; tab-size: 4; }
.code pre code { background: none; border: 0; padding: 0; font-size: inherit; white-space: pre; color: var(--text); }

.out { border-top: 1px dashed var(--code-border); background: var(--out-bg); }
.out-head { padding: 6px 16px 0; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.out pre { padding: 4px 16px 12px; color: var(--out-text); font-size: 13.5px; line-height: 1.55; overflow-x: auto; }

.t-kw { color: var(--syn-keyword); }
.t-str { color: var(--syn-string); }
.t-num { color: var(--syn-number); }
.t-com { color: var(--syn-comment); font-style: italic; }
.t-type { color: var(--syn-type); }
.t-fn { color: var(--syn-fn); }
.t-prop { color: var(--syn-prop); }
.t-tag { color: var(--syn-tag); }
.t-attr { color: var(--syn-attr); }
.t-ann { color: var(--syn-attr); }

/* ------------------------------------------------------------------ API pages */
.api-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 18px; }
.api-meta .pill {
  font-family: var(--mono); font-size: 12.5px; color: var(--muted); background: var(--surface);
  border: 1px solid var(--border); padding: 3px 10px; border-radius: 999px;
}
.points { margin: 0 0 8px; }

.group-title { display: flex; align-items: baseline; gap: 12px; }
.group-intro { color: var(--muted); }

.method {
  margin: 0 0 32px; padding: 20px 22px 6px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--bg); box-shadow: var(--shadow); scroll-margin-top: 80px;
}
.method-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 12px; }
.method-name { margin: 0 !important; padding: 0 !important; border: 0 !important; font-size: 1.3rem !important; font-family: var(--mono); font-weight: 700; letter-spacing: -0.01em; }
.method-name a { color: var(--text); }
.method-name .heading-anchor { font-family: var(--font); }
.badge { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }

.overload { margin: 0 0 18px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.overload:last-of-type { border-bottom: 0; }
.sig { margin: 0 0 10px; padding: 10px 14px; background: var(--code-bg); border: 1px solid var(--code-border); border-radius: 10px; overflow-x: auto; font-size: 13.5px; line-height: 1.5; }
.sig code { background: none; border: 0; padding: 0; font-size: inherit; white-space: pre; }
.overload > p { margin: 0 0 10px; }
.spec { margin: 0; display: grid; gap: 8px; }
.spec-row { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 12px; align-items: baseline; font-size: 14.5px; }
.spec dt { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.spec dd { margin: 0; min-width: 0; }
.mini { width: 100%; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.mini td { padding: 6px 12px; }
.mini td:first-child { white-space: nowrap; width: 1%; }
.mini td:first-child code { white-space: nowrap; word-break: normal; }
.mini tr:last-child td { border-bottom: 0; }

.notes { margin: 6px 0 16px; padding: 10px 16px 10px 16px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 10px 10px 0; font-size: 14.5px; }
.notes ul { margin: 0; padding-left: 18px; }
.notes li { margin: 3px 0; }

.examples-title { font-size: 12px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); margin: 18px 0 8px; }
.example { margin: 0 0 4px; }
.example-title { font-size: 14px; font-weight: 600; margin: 12px 0 6px; }
.see { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 0 16px; font-size: 13.5px; color: var(--muted); }
.see a { padding: 2px 10px; border: 1px solid var(--border); border-radius: 999px; color: var(--text); background: var(--surface); }
.see a:hover { border-color: var(--accent); text-decoration: none; color: var(--accent-strong); }
.see a code { background: none; border: 0; padding: 0; font-size: 12.5px; }

.overview td:first-child { white-space: nowrap; }
.overview td:first-child a { font-family: var(--mono); font-size: 13.5px; font-weight: 600; }
.overview td { font-size: 14.5px; }

/* ------------------------------------------------------------------ toc */
.toc-title { font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.toc a { display: block; padding: 3px 0 3px 12px; border-left: 2px solid var(--border); font-size: 13.5px; line-height: 1.4; color: var(--muted); }
.toc a:hover { color: var(--text); text-decoration: none; }
.toc a.active { color: var(--accent-strong); border-left-color: var(--accent); font-weight: 600; }
.toc a.l3 { padding-left: 24px; }
.toc a.l3.mono { font-family: var(--mono); font-size: 12.5px; }
.toc .toc-group { margin-top: 10px; font-weight: 600; color: var(--text); }

/* ------------------------------------------------------------------ pager + footer */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 56px 0 28px; }
.pager a {
  display: block; padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; color: var(--text); background: var(--bg);
}
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager .dir { display: block; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.pager .ttl { font-weight: 600; color: var(--accent-strong); }
.pager .next { text-align: right; grid-column: 2; }
.pager .prev { grid-column: 1; }
.foot { font-size: 13.5px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 18px; }
.foot a { color: var(--muted); text-decoration: underline; }
.nojs { padding: 40px; }

/* ------------------------------------------------------------------ search */
.search-modal { position: fixed; inset: 0; z-index: 80; display: grid; justify-items: center; align-items: start; padding: 10vh 16px 16px; }
.search-modal[hidden] { display: none; }
.search-backdrop { position: absolute; inset: 0; background: rgba(8, 12, 18, 0.55); backdrop-filter: blur(2px); }
.search-dialog {
  position: relative; width: min(640px, 100%); max-height: 70vh; display: flex; flex-direction: column;
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); overflow: hidden;
}
.search-input-row { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--muted); }
.search-input-row input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 16px; }
.search-results { list-style: none; margin: 0; padding: 8px; overflow-y: auto; }
.search-results li a {
  display: flex; align-items: baseline; gap: 10px; padding: 9px 12px; border-radius: 9px; color: var(--text);
}
.search-results li a:hover { text-decoration: none; }
.search-results li.sel a, .search-results li a:hover { background: var(--accent-soft); }
.search-results .r-title { font-weight: 600; }
.search-results .r-title.mono { font-family: var(--mono); font-size: 14px; }
.search-results .r-sub { color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.search-results .r-kind { font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); padding: 1px 7px; border-radius: 999px; flex: none; }
.search-empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.search-foot { display: flex; gap: 18px; padding: 8px 16px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-grid; }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: min(320px, 86vw); height: auto; z-index: 60;
    transform: translateX(-102%); transition: transform 0.2s ease; box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(8, 12, 18, 0.5); z-index: 50; }
  body.nav-open { overflow: hidden; }
  .page { padding: 28px 20px 64px; }
}
@media (max-width: 680px) {
  .search-btn { min-width: 0; width: 38px; padding: 0; justify-content: center; }
  .search-label, #searchKbd { display: none; }
  .version { display: none; }
  .article h1 { font-size: 1.75rem; }
  .article h2 { font-size: 1.3rem; }
  .method { padding: 16px 14px 4px; border-radius: 12px; }
  .spec-row { grid-template-columns: 1fr; gap: 2px; }
  .pager { grid-template-columns: 1fr; }
  .pager .next, .pager .prev { grid-column: 1; text-align: left; }
  .code pre, .out pre { font-size: 12.5px; }
}
