:root {
  color-scheme: dark;
  --bg: #0b0b0f;
  --panel: #12121e;
  --text: #e4e4eb;
  --muted: #8b8b9e;
  --border: rgba(255, 255, 255, 0.07);
  --link: #7db4f5;
  --codebg: rgba(255, 255, 255, 0.05);
  --shadow: rgba(0, 0, 0, 0.4);
  --accent: rgba(125, 180, 245, 0.08);
  --tok-comment: #7c7c93;
  --tok-kw: #c6a0f6;
  --tok-str: #90d3a6;
  --tok-num: #e2a978;
  --tok-fn: #7db4f5;
  --radius: 10px;
  --gutter: 16px;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  --sans: "Geist", -apple-system, system-ui, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f8f8fa;
    --panel: #ffffff;
    --text: #1a1a2e;
    --muted: #64648a;
    --border: rgba(0, 0, 0, 0.08);
    --link: #2563eb;
    --codebg: rgba(0, 0, 0, 0.04);
    --shadow: rgba(0, 0, 0, 0.06);
    --accent: rgba(37, 99, 235, 0.06);
    --tok-comment: #6a6a80;
    --tok-kw: #8250df;
    --tok-str: #0a7d55;
    --tok-num: #b4530a;
    --tok-fn: #2563eb;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f8f8fa;
  --panel: #ffffff;
  --text: #1a1a2e;
  --muted: #64648a;
  --border: rgba(0, 0, 0, 0.08);
  --link: #2563eb;
  --codebg: rgba(0, 0, 0, 0.04);
  --shadow: rgba(0, 0, 0, 0.06);
  --accent: rgba(37, 99, 235, 0.06);
  --tok-comment: #6a6a80;
  --tok-kw: #8250df;
  --tok-str: #0a7d55;
  --tok-num: #b4530a;
  --tok-fn: #2563eb;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

html {
  /* keep tab-focused headings/links clear of the sticky header */
  scroll-padding-top: 64px;
}

/* Accessibility utilities */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 8px 14px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--link);
  border-radius: 6px;
  transform: translateY(-150%);
  transition: transform 0.15s ease;
}
.skip-link:focus {
  transform: translateY(0);
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: inherit;
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

@media (forced-colors: active) {
  .sidebar a.active,
  [aria-current="page"] {
    outline: 2px solid Highlight;
  }
}

body {
  margin: 0;
  font-family: var(--sans);
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* App shell */
.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 var(--gutter);
  height: 48px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  max-width: 100%;
}

.brand {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  letter-spacing: -0.02em;
  white-space: nowrap;
  flex-shrink: 0;
}
.brand:hover {
  text-decoration: none;
  opacity: 0.8;
}

/* Nav — inline in header */
.nav {
  display: flex;
  gap: 2px;
  margin-left: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar {
  display: none;
}

.nav a {
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: color 0.1s, background 0.1s;
}
.nav a:hover {
  color: var(--text);
  background: var(--codebg);
  text-decoration: none;
}
.nav a[aria-current="page"] {
  color: var(--text);
  background: var(--accent);
}

/* Header right */
.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
}

.header-link {
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  color: var(--muted);
  white-space: nowrap;
}
.header-link:hover {
  color: var(--text);
  background: var(--codebg);
  text-decoration: none;
}

/* Theme toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  transition: color 0.15s, border-color 0.15s;
}
.theme-toggle:hover {
  color: var(--text);
  border-color: var(--muted);
}
.theme-toggle .icon-moon {
  display: none;
}
:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: none;
}
:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: block;
}
:root[data-theme="light"] .theme-toggle .icon-sun {
  display: block;
}
:root[data-theme="light"] .theme-toggle .icon-moon {
  display: none;
}

/* Main content */
.main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: var(--gutter);
}

.content {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 28px 32px;
}

/* Docs sidebar (desktop only — a sticky page tree in what would be dead margin) */
.sidebar {
  display: none;
}
.sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.sidebar a {
  display: block;
  padding: 5px 10px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  line-height: 1.45;
}
.sidebar a:hover {
  color: var(--text);
  background: var(--codebg);
}
.sidebar .s-page {
  color: var(--text);
  font-weight: 500;
  margin-top: 3px;
}
/* nested groups indent behind a static tree line (structure, not state) */
.sidebar .s-children,
.sidebar .s-toc {
  margin: 2px 0 8px 13px;
  padding-left: 5px;
  border-left: 1px solid var(--border);
}
.sidebar .s-child {
  font-size: 12.5px;
}
.sidebar .s-toc {
  margin-bottom: 6px;
}
.sidebar .s-toc-link {
  font-size: 12px;
}
.sidebar .s-children .s-toc {
  border-left: none;
  margin-left: 8px;
}
.sidebar .s-toc-sub {
  padding-left: 20px;
}
.sidebar a.active {
  color: var(--link);
  font-weight: 600;
  background: var(--accent);
}
/* collapsible sections: the caret is the toggle, the summary link navigates */
.sidebar details.s-section > summary {
  display: flex;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  list-style: none;
}
.sidebar details.s-section > summary::-webkit-details-marker {
  display: none;
}
.sidebar details.s-section > summary::before {
  content: "";
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  background: currentColor;
  color: var(--muted);
  clip-path: polygon(35% 25%, 70% 50%, 35% 75%);
  transition: transform 0.12s;
}
.sidebar details.s-section[open] > summary::before {
  transform: rotate(90deg);
}
.sidebar details.s-section > summary .s-page {
  flex: 1;
}
/* directory group labels inside a section */
.sidebar .s-dir {
  display: block;
  padding: 4px 10px 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}
.sidebar a.s-dir:hover {
  color: var(--text);
}

@media (min-width: 1024px) {
  .main {
    max-width: 1180px;
    display: grid;
    grid-template-columns: 216px minmax(0, 1fr);
    gap: 36px;
    align-items: start;
  }
  .sidebar {
    display: block;
    position: sticky;
    top: 64px;
    align-self: start;
    max-height: calc(100vh - 84px);
    overflow-y: auto;
    font-size: 13px;
    padding-bottom: 16px;
  }
  .content {
    min-width: 0;
  }
  /* the page tree replaces the header's top nav on desktop */
  .header .nav {
    display: none;
  }
}

/* Footer */
.site-footer {
  padding: 16px var(--gutter);
  text-align: center;
  border-top: 1px solid var(--border);
}

.footer-link {
  font-size: 12px;
  color: var(--muted);
}
.footer-link:hover {
  color: var(--text);
  text-decoration: none;
}

/* Content typography */
.content h1,
.content h2,
.content h3 {
  scroll-margin-top: 64px;
  letter-spacing: -0.01em;
}

.content h1 {
  margin-top: 0;
  font-size: 24px;
  font-weight: 700;
}

.content h2 {
  font-size: 17px;
  font-weight: 600;
  margin-top: 36px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.content h2:first-of-type {
  border-top: none;
  padding-top: 0;
}

.content h3 {
  font-size: 14px;
  font-weight: 600;
  margin-top: 24px;
  color: var(--muted);
}

.content p,
.content li {
  line-height: 1.7;
  font-size: 14px;
}

.content code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--codebg);
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.content pre {
  overflow-x: auto;
  padding: 14px 16px;
  border-radius: 8px;
  background: var(--codebg);
  border: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.6;
}

.content pre code {
  background: transparent;
  padding: 0;
  border: none;
  font-size: inherit;
}

.content .token.comment {
  color: var(--tok-comment);
  font-style: italic;
}
.content .token.keyword,
.content .token.builtin-type {
  color: var(--tok-kw);
}
.content .token.string,
.content .token.char {
  color: var(--tok-str);
}
.content .token.number,
.content .token.boolean {
  color: var(--tok-num);
}
.content .token.builtin,
.content .token.function,
.content .token.class-name {
  color: var(--tok-fn);
}
.content .token.operator,
.content .token.punctuation {
  color: var(--text);
  opacity: 0.7;
}

.content details {
  margin: 12px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.content details summary {
  cursor: pointer;
  padding: 10px 14px;
  font-size: 14px;
  border-radius: 8px;
}

.content details summary:hover {
  background: var(--accent);
}

.content details[open] summary {
  border-bottom: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
}

.content details > :not(summary) {
  padding: 0 14px;
}

.content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}

.content blockquote {
  border-left: 3px solid var(--link);
  margin: 16px 0;
  padding: 4px 16px;
  color: var(--muted);
  background: var(--accent);
  border-radius: 0 6px 6px 0;
}

.content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 16px 0;
}

.content th,
.content td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}

.content th {
  background: var(--codebg);
  font-weight: 600;
}

.empty {
  color: var(--muted);
}

/* Mobile */
@media (max-width: 640px) {
  .header {
    gap: 4px;
    padding: 0 12px;
  }

  .nav {
    margin-left: 8px;
    gap: 0;
  }

  .nav a {
    padding: 6px 8px;
    font-size: 12px;
  }

  .header-link {
    font-size: 12px;
    padding: 5px 8px;
  }

  .main {
    padding: 12px;
  }

  .content {
    padding: 20px 16px;
    border-radius: 8px;
  }

  .content h1 {
    font-size: 20px;
  }

  .content h2 {
    font-size: 16px;
  }

  .content pre {
    font-size: 12px;
    padding: 12px;
  }
}
