:root {
  --main: #5b3fa0;
  --main-light: #8b76c2;
  --background: #ffffff;
  --text: #2f3238;
  --text-light: #6b6f78;
  --text-headings: #15171c;
  --link: #5b3fa0;
  --border: #e4e5ea;
  --sidebar-background: #f4f4f7;
  --sidebar-text: #3d4048;
  --sidebar-border: #e2e3e8;
  --sidebar-hover: rgba(91, 63, 160, 0.08);
  --sidebar-active-background: rgba(91, 63, 160, 0.1);
  --input-background: #ffffff;
  --code-background: #f4f4f7;
  --code-border: #e4e5ea;
  --detail-background: #f4f3f9;
  --warning-background: #fff6e0;
  --warning-border: #d99a00;
  --internal-background: #efeaf7;
  --internal-border: #8b76c2;
  --deprecated-background: #fdecec;
  --deprecated-border: #c0392b;
  --environment-background: #e2f4ef;
  --environment-border: #0f7a66;
  --badge-background-saturation: 40%;
  --badge-background-lightness: 92%;
  --badge-text-saturation: 45%;
  --badge-text-lightness: 34%;
  --realm-server: #2f6bd8;
  --realm-server-background: #e6eefc;
  --realm-server-text: #1f4fa8;
  --realm-client: #e07b14;
  --realm-client-background: #fdeedd;
  --realm-client-text: #a14f08;
  --realm-shared-background: #913591;
  --realm-shared-text: #fbe6f6;
  --hl-k: #a626a4;
  --hl-s: #50a14f;
  --hl-c: #9a9ca3;
  --hl-n: #986801;
  --hl-f: #4078f2;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", "Fira Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --sidebar-width: 300px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --main: #a78bfa;
    --main-light: #8b76c2;
    --background: #0f1116;
    --text: #d4d6dc;
    --text-light: #8f939c;
    --text-headings: #f3f4f6;
    --link: #b7a4fb;
    --border: #262a33;
    --sidebar-background: #171a21;
    --sidebar-text: #c9ccd3;
    --sidebar-border: #262a33;
    --sidebar-hover: rgba(167, 139, 250, 0.1);
    --sidebar-active-background: rgba(167, 139, 250, 0.14);
    --input-background: #171a21;
    --code-background: #171a21;
    --code-border: #262a33;
    --detail-background: #181b23;
    --warning-background: #2e2817;
    --warning-border: #d99a00;
    --internal-background: #221d33;
    --internal-border: #8b76c2;
    --deprecated-background: #301c1c;
    --deprecated-border: #e06c5c;
    --environment-background: #142b27;
    --environment-border: #3cc4a6;
    --badge-background-saturation: 28%;
    --badge-background-lightness: 20%;
    --badge-text-saturation: 80%;
    --badge-text-lightness: 85%;
    --realm-server: #5b9cff;
    --realm-server-background: #16243d;
    --realm-server-text: #a9c8ff;
    --realm-client: #f39a3d;
    --realm-client-background: #33220f;
    --realm-client-text: #ffc58a;
    --realm-shared-background: #5e2060;
    --realm-shared-text: #f0cfea;
    --hl-k: #c678dd;
    --hl-s: #98c379;
    --hl-c: #6f7480;
    --hl-n: #d19a66;
    --hl-f: #61afef;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --main: #a78bfa;
  --main-light: #8b76c2;
  --background: #0f1116;
  --text: #d4d6dc;
  --text-light: #8f939c;
  --text-headings: #f3f4f6;
  --link: #b7a4fb;
  --border: #262a33;
  --sidebar-background: #171a21;
  --sidebar-text: #c9ccd3;
  --sidebar-border: #262a33;
  --sidebar-hover: rgba(167, 139, 250, 0.1);
  --sidebar-active-background: rgba(167, 139, 250, 0.14);
  --input-background: #171a21;
  --code-background: #171a21;
  --code-border: #262a33;
  --detail-background: #181b23;
  --warning-background: #2e2817;
  --warning-border: #d99a00;
  --internal-background: #221d33;
  --internal-border: #8b76c2;
  --deprecated-background: #301c1c;
  --deprecated-border: #e06c5c;
  --environment-background: #142b27;
  --environment-border: #3cc4a6;
  --badge-background-saturation: 28%;
  --badge-background-lightness: 20%;
  --badge-text-saturation: 80%;
  --badge-text-lightness: 85%;
  --realm-server: #5b9cff;
  --realm-server-background: #16243d;
  --realm-server-text: #a9c8ff;
  --realm-client: #f39a3d;
  --realm-client-background: #33220f;
  --realm-client-text: #ffc58a;
  --realm-shared-background: #5e2060;
  --realm-shared-text: #f0cfea;
  --hl-k: #c678dd;
  --hl-s: #98c379;
  --hl-c: #6f7480;
  --hl-n: #d19a66;
  --hl-f: #61afef;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.65;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4, h5, h6 { color: var(--text-headings); font-weight: 700; line-height: 1.25; }
h1 { font-size: 2.1em; margin: 0.3em 0 0.6em; }
h2 { font-size: 1.6em; margin: 2.2em 0 0.8em; }
h3 { font-size: 1.25em; margin: 1.6em 0 0.6em; }
h4 { font-size: 0.8em; margin: 1.4em 0 0.4em; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-light); }
p { margin: 0 0 1em; }
ul, ol { padding-left: 1.5em; }
li { margin: 0.2em 0; }

code, pre, kbd { font-family: var(--mono); }
code { font-size: 0.88em; background: var(--code-background); border: 1px solid var(--code-border); border-radius: 4px; padding: 0.05em 0.35em; }
pre {
  background: var(--code-background);
  border: 1px solid var(--code-border);
  border-radius: 6px;
  padding: 1em 1.2em;
  overflow-x: auto;
  font-size: 0.875em;
  line-height: 1.55;
  margin: 1em 0;
}
pre code { background: none; border: none; padding: 0; font-size: 1em; }
.hl-k { color: var(--hl-k); }
.hl-s { color: var(--hl-s); }
.hl-c { color: var(--hl-c); font-style: italic; }
.hl-n { color: var(--hl-n); }
.hl-f { color: var(--hl-f); }

table { border-collapse: collapse; margin: 1em 0; }
th, td { border: 1px solid var(--border); padding: 0.4em 0.8em; text-align: left; }
th { background: var(--code-background); }

/* Progress bar for in-page navigation */
.progress { position: fixed; top: 0; left: 0; height: 2px; width: 0; background: var(--main); z-index: 100; opacity: 0; transition: width 0.25s ease, opacity 0.2s; }
.progress.active { opacity: 1; width: 70%; }
.progress.done { width: 100%; opacity: 0; transition: width 0.15s ease, opacity 0.4s 0.15s; }

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-background);
  border-right: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  font-size: 0.95em;
  z-index: 20;
}
.sidebar-header { padding: 1.1em 1.2em 0.7em; }
.sidebar-project { color: var(--text-headings); font-weight: 700; font-size: 1.25em; line-height: 1.2; display: block; }
.sidebar-project:hover { text-decoration: none; color: var(--main); }
.sidebar-project-version { display: block; font-weight: 400; color: var(--text-light); font-size: 0.72em; margin-top: 0.15em; }

.sidebar-tabs { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--sidebar-border); padding: 0 0.6em; }
.sidebar-tabs button {
  background: none; border: none; cursor: pointer; white-space: nowrap;
  font: inherit; font-size: 0.78em; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-light); padding: 0.7em 0.6em; margin-bottom: -1px;
  border-bottom: 2px solid transparent;
}
.sidebar-tabs button:hover { color: var(--text-headings); }
.sidebar-tabs button.active { color: var(--text-headings); border-bottom-color: var(--main); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 0.6em 0 2em; scrollbar-width: thin; scrollbar-color: var(--sidebar-border) transparent; }
.sidebar-nav ul { list-style: none; margin: 0; padding: 0; }
.sidebar-row { display: flex; align-items: center; }
.sidebar-row > a {
  flex: 1; min-width: 0; display: block; padding: 0.3em 0 0.3em 1.2em; color: var(--sidebar-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-row > a:hover { color: var(--main); text-decoration: none; }
.sidebar-row.active > a { color: var(--main); font-weight: 600; }
.sidebar-row > a.active { color: var(--main); font-weight: 600; }
.chevron {
  background: none; border: none; cursor: pointer; color: var(--text-light);
  width: 2.4em; height: 2.1em; display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.chevron::before {
  content: ""; border: solid currentColor; border-width: 0 1.5px 1.5px 0; padding: 2.5px;
  transform: rotate(45deg); transition: transform 0.15s; margin-top: -3px;
}
.chevron:hover { color: var(--text-headings); }
.sidebar-item.open > .sidebar-row > .chevron::before { transform: rotate(-135deg); margin-top: 3px; }
.sidebar-item > ul { display: none; }
.sidebar-item.open > ul { display: block; }
.sidebar-group > ul > li > .sidebar-row > a { padding-left: 2.2em; }
.sidebar-group > ul > li > ul .sidebar-row > a { padding-left: 3.2em; }

.sidebar-functions { margin: 0.1em 0 0.6em; }
.sidebar-functions > li > .sidebar-row > a { padding-left: 2.2em; font-size: 0.95em; }
.sidebar-group .sidebar-functions > li > .sidebar-row > a { padding-left: 3.2em; }
.sidebar-functions .plus { width: 2.4em; }
.sidebar-functions .plus::before { content: "+"; border: none; padding: 0; transform: none; margin: 0; font-size: 1.1em; line-height: 1; }
.sidebar-functions li.open > .sidebar-row > .plus::before { content: "–"; }
.sidebar-functions ul a { font-family: var(--mono); font-size: 0.86em; padding-left: 3.3em !important; font-weight: 400 !important; color: var(--sidebar-text) !important; }
.sidebar-group .sidebar-functions ul a { padding-left: 4.3em !important; }
.sidebar-functions ul a:hover { color: var(--main) !important; }
.sidebar-heading {
  display: flex; align-items: center; gap: 0.5em; margin: 1em 1em 0.25em 1.2em; padding: 0;
  cursor: default; user-select: none;
}
.sidebar-nav > ul > .sidebar-heading:first-child, .sidebar-group > ul > .sidebar-heading:first-child { margin-top: 0.3em; }
.sidebar-group > ul > .sidebar-heading { margin-left: 2.2em; }
.sidebar-heading-label {
  font-size: 0.74em; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; line-height: 1.5;
  padding: 0.1em 0.65em; margin-left: -0.65em; border-radius: 999px;
  color: var(--main); background: var(--sidebar-active-background);
}
.sidebar-heading-count { font-size: 0.72em; color: var(--text-light); font-variant-numeric: tabular-nums; opacity: 0.85; }
.sidebar-section-title { padding: 1.2em 1.2em 0.3em; font-size: 0.74em; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-light); font-weight: 600; }
.sidebar-noscript { padding: 0.5em 1.4em; }

.sidebar-toggle { display: none; position: fixed; top: 0.55em; left: 0.6em; z-index: 25; background: var(--background); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 0.3em; cursor: pointer; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 15; }

/* Content column */
.content { margin-left: var(--sidebar-width); min-height: 100vh; min-width: 0; }
.topbar { max-width: 1040px; margin: 0 auto; padding: 1.3em 3.5em 0; display: flex; align-items: center; gap: 0.8em; }
.search { position: relative; flex: 1; margin: 0; }
.search input {
  width: 100%; font: inherit; font-size: 1em; padding: 0.6em 1em;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--input-background); color: var(--text);
}
.search input:focus { outline: 2px solid var(--main-light); outline-offset: -1px; }
.search input::placeholder { color: var(--text-light); }
.search-suggestions {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 0.3em 0; list-style: none;
  background: var(--background); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25); z-index: 30; max-height: 60vh; overflow-y: auto;
}
.search-suggestions li { margin: 0; }
.search-suggestions li a { display: block; padding: 0.4em 1em; color: var(--text); }
.search-suggestions li a:hover, .search-suggestions li.selected a { background: var(--sidebar-hover); text-decoration: none; }
.search-suggestions .suggestion-title { font-family: var(--mono); font-size: 0.9em; }
.search-suggestions .suggestion-kind { float: right; color: var(--text-light); font-size: 0.75em; margin-left: 0.6em; }
.search-suggestions .suggestion-kind .realm { margin: 0 0.5em 0 0; font-size: 0.62rem; }
.search-results .result-meta .realm { margin-left: 0.2em; font-size: 0.62rem; }
.theme-toggle { background: none; border: 1px solid var(--border); color: var(--text-light); cursor: pointer; padding: 0.55em; border-radius: 6px; display: inline-flex; flex: none; }
.theme-toggle:hover { color: var(--main); border-color: var(--main-light); }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: inline; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

.content-inner { max-width: 1040px; margin: 0 auto; padding: 1.5em 3.5em 3em; }
.content-inner.loading { opacity: 0.6; transition: opacity 0.15s; }

.page-header .subtitle { color: var(--text-light); margin: -0.4em 0 0.6em; }
.lead { font-size: 1.1em; color: var(--text-light); }
.stats, .muted { color: var(--text-light); }
.version { font-size: 0.5em; font-weight: 400; color: var(--text-light); vertical-align: middle; }

.badge {
  --badge-hue: 262;
  display: inline-block; font-size: 0.68rem; font-weight: 600; vertical-align: middle;
  padding: 0.1em 0.55em; border-radius: 999px;
  background: hsl(var(--badge-hue) var(--badge-background-saturation) var(--badge-background-lightness));
  color: hsl(var(--badge-hue) var(--badge-text-saturation) var(--badge-text-lightness));
  text-transform: uppercase; letter-spacing: 0.04em; margin-left: 0.3em;
}
h1 .badge, h1 .realm, h1 .flag { font-size: 0.75rem; }
.badge-class { --badge-hue: 262; }
.badge-library { --badge-hue: 190; }
.badge-object { --badge-hue: 320; }
.badge-hooks { --badge-hue: 140; }
.badge-handlers { --badge-hue: 240; }
.badge-gamemode { --badge-hue: 0; }
.badge-plugin { --badge-hue: 85; }
.badge-schema { --badge-hue: 48; }
.badge-globals { background: var(--code-background); color: var(--text-light); box-shadow: inset 0 0 0 1px var(--code-border); }

/* Realm markers: orange for the client, blue for the server, split for shared code */
.realm {
  --realm-dot: var(--text-light);
  display: inline-flex; align-items: center; gap: 0.4em; vertical-align: middle;
  font-family: var(--sans); font-size: 0.68rem; font-weight: 600; line-height: 1.6;
  padding: 0 0.6em 0 0.5em; border-radius: 999px; margin-left: 0.5em; white-space: nowrap;
  text-transform: uppercase; letter-spacing: 0.04em; cursor: default;
}
.realm::before { content: ""; flex: none; width: 0.85em; height: 0.85em; border-radius: 50%; background: var(--realm-dot); }
.realm-server { --realm-dot: var(--realm-server); background: var(--realm-server-background); color: var(--realm-server-text); }
.realm-client { --realm-dot: var(--realm-client); background: var(--realm-client-background); color: var(--realm-client-text); }
.realm-shared { background: var(--realm-shared-background); color: var(--realm-shared-text); }
.realm-shared::before, .realm-dot-shared { background: linear-gradient(90deg, var(--realm-client) 50%, var(--realm-server) 50%); }
.realm-dot { display: inline-block; flex: none; width: 0.75em; height: 0.75em; border-radius: 50%; margin-right: 0.55em; vertical-align: 0.08em; }
.realm-dot-server { background: var(--realm-server); }
.realm-dot-client { background: var(--realm-client); }
.flag {
  display: inline-block; font-size: 0.68em; font-weight: 600; padding: 0.05em 0.5em; border-radius: 3px;
  margin-left: 0.5em; vertical-align: middle; text-transform: uppercase; letter-spacing: 0.04em;
}
.flag-deprecated { background: var(--deprecated-background); color: var(--deprecated-border); }
.flag-internal { background: var(--internal-background); color: var(--internal-border); }
.flag-environment { background: var(--environment-background); color: var(--environment-border); cursor: default; }

.summary-row { padding: 0.5em 0; border-bottom: 1px solid var(--border); }
.summary-row:last-child { border-bottom: none; }
.summary-signature { font-family: var(--mono); font-size: 0.92em; overflow-wrap: anywhere; }
.summary-signature .badge, .summary-signature .flag, .summary-signature .muted { font-family: var(--sans); }
.summary-synopsis { color: var(--text-light); padding-left: 1.5em; font-size: 0.97em; }
.summary-synopsis p { margin: 0; }
.summary-group h3 { margin-top: 1.4em; }

.detail { margin: 2.6em 0 0; scroll-margin-top: 1em; }
.detail:target .detail-header { outline: 2px solid var(--main-light); outline-offset: 2px; }
.detail-header {
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.6em;
  margin: 0 0 1.2em; padding: 0.75em 1em;
  background: var(--detail-background); border-left: 3px solid var(--main); border-radius: 0 6px 6px 0;
}
.detail-header > * { min-width: 0; }
.detail-header .realm, .detail-header .flag { margin-left: 0; }
.detail-header .signature { margin: 0; font-family: var(--mono); font-size: 1.05em; font-weight: 500; color: var(--text-headings); overflow-wrap: anywhere; }
.detail-header .signature .owner, .detail-header .signature .params { color: var(--text-light); font-weight: 400; }
.detail-link { color: var(--text-light); opacity: 0; display: inline-flex; }
.detail-header:hover .detail-link, .detail-link:focus { opacity: 1; }
.source-link { margin-left: auto; font-size: 0.75em; color: var(--text-light); font-family: var(--mono); }
.docstring { padding: 0 0 0 1.2em; }
.hook-info { color: var(--text-light); margin: -0.4em 0 1em; }
.hook-info .sep { color: var(--border); }
.realm-doc { border-left: 3px solid var(--realm-dot); padding: 0.1em 0 0.1em 1em; margin: 0 0 1.4em; }
.realm-doc > :last-child { margin-bottom: 0; }
.realm-doc-server { --realm-dot: var(--realm-server); }
.realm-doc-client { --realm-dot: var(--realm-client); }
.realm-doc-shared { --realm-dot: var(--main-light); }
.realm-doc-title { font-weight: 700; color: var(--text-headings); margin: 0 0 0.5em; }
.otherwise { border-left: 3px solid var(--border); padding: 0.1em 0 0.1em 1em; margin: 0 0 1.4em; }
.otherwise > :last-child { margin-bottom: 0; }
.otherwise-title { font-weight: 700; color: var(--text-headings); margin: 0 0 0.5em; }
.otherwise-title .source-link { margin-left: 0.6em; font-weight: 400; }

.admonition { padding: 0.8em 1em; margin: 1em 0; border-radius: 6px; border-left: 3px solid var(--warning-border); background: var(--warning-background); }
.admonition p { margin: 0; }
.admonition p + p { margin-top: 0.4em; }
.admonition-title { font-weight: 700; }
.admonition.internal { background: var(--internal-background); border-color: var(--internal-border); }
.admonition.deprecated { background: var(--deprecated-background); border-color: var(--deprecated-border); }
.admonition.environment { background: var(--environment-background); border-color: var(--environment-border); }

.params, .returns, .aliases, .see-also, .variants, .callers, .source-list { list-style: none; padding: 0; margin: 0 0 1em; }
.source-list .source-link { margin: 0; font-size: 0.85em; }
.arguments li { padding-top: 0.1em; padding-bottom: 0.1em; }
.source-list .realm { margin-left: 0.4em; }
.params li, .returns li, .variants li { padding: 0.3em 0 0.3em 1em; border-left: 2px solid var(--code-border); margin: 0.3em 0; }
.param-name { font-family: var(--mono); font-weight: 600; color: var(--text-headings); }
.type { font-family: var(--mono); font-size: 0.9em; color: var(--main); }
.default { color: var(--text-light); font-size: 0.9em; }
.variants li p { margin: 0.3em 0; }
.variants .params { margin-bottom: 0; }
.variants .params li, .variants .returns li { border-color: transparent; padding-top: 0.1em; padding-bottom: 0.1em; }
.variants .returns { margin-bottom: 0; }
.variants h5 { font-size: 0.72em; margin: 0.5em 0 0.1em; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-light); }
.variant-signature { font-weight: 600; }
.sources ul { padding-left: 1.2em; }
.sources .source-link { margin: 0; font-size: 0.9em; }

.search-results .result { padding: 0.8em 0; border-bottom: 1px solid var(--border); }
.search-results .result-title { font-family: var(--mono); }
.search-results .result-meta { color: var(--text-light); font-size: 0.85em; }
.search-results .result-desc { margin: 0.3em 0 0; color: var(--text-light); }
.search-results mark { background: var(--warning-background); color: inherit; padding: 0; }

.footer { margin-top: 4em; padding-top: 1em; border-top: 1px solid var(--border); color: var(--text-light); font-size: 0.85em; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s; }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .sidebar-toggle { display: inline-flex; }
  .content { margin-left: 0; }
  .topbar { padding: 0.8em 1em 0 3.6em; }
  .content-inner { padding: 1em 1em 2em; }
  .docstring { padding-left: 0; }
}
