:root {
  --bg: #f4f2ea;
  --bg-raised: #fbfaf4;
  --fg: #111110;
  --muted: #615e55;
  --line: #111110;
  --line-soft: #d6d1c4;
  --accent: #0b7285;
  --accent-fg: #f4f2ea;
  --inline-code-bg: #e9e9e4;
  --code-bg: #f1f1ee;
  --code-border: #d4d4cf;
  --code-fg: #15262d;
  --code-dim: #5c747c;
  --code-keyword: #0369a1;
  --code-string: #0f766e;
  --code-number: #946200;
  --code-title: #1d4ed8;
  --code-type: #7e22ce;
  --code-builtin: #0f766e;
  --code-comment: #64748b;
  --code-operator: #334155;
  --code-meta: #a21caf;
  --mark-bg: #a5f3fc;
  --mark-fg: #111110;
  --focus: #0b7285;
  --font-sans:
    "IBM Plex Sans", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono:
    "IBM Plex Mono", "JetBrains Mono", ui-monospace, "SFMono-Regular",
    "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0e0f11;
  --bg-raised: #15171a;
  --fg: #ece9df;
  --muted: #9b978b;
  --line: #ece9df;
  --line-soft: #2a2c31;
  --accent: #67e8f9;
  --accent-fg: #0e0f11;
  --inline-code-bg: #1a1c1e;
  --code-bg: #111214;
  --code-border: #2b2d31;
  --code-fg: #dbe9eb;
  --code-dim: #82979d;
  --code-keyword: #67e8f9;
  --code-string: #9be3b8;
  --code-number: #f0d98c;
  --code-title: #7dd3fc;
  --code-type: #c4b5fd;
  --code-builtin: #5eead4;
  --code-comment: #6f8790;
  --code-operator: #cbd5e1;
  --code-meta: #e879f9;
  --mark-bg: #22d3ee;
  --mark-fg: #111110;
  --focus: #67e8f9;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0e0f11;
    --bg-raised: #15171a;
    --fg: #ece9df;
    --muted: #9b978b;
    --line: #ece9df;
    --line-soft: #2a2c31;
    --accent: #67e8f9;
    --accent-fg: #0e0f11;
    --inline-code-bg: #1a1c1e;
    --code-bg: #111214;
    --code-border: #2b2d31;
    --code-fg: #dbe9eb;
    --code-dim: #82979d;
    --code-keyword: #67e8f9;
    --code-string: #9be3b8;
    --code-number: #f0d98c;
    --code-title: #7dd3fc;
    --code-type: #c4b5fd;
    --code-builtin: #5eead4;
    --code-comment: #6f8790;
    --code-operator: #cbd5e1;
    --code-meta: #e879f9;
    --mark-bg: #22d3ee;
    --mark-fg: #111110;
    --focus: #67e8f9;
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 84px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--accent);
  color: var(--accent-fg);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  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: 300;
  padding: 8px 12px;
  background: var(--fg);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-decoration: none;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: none;
}

/* Top bar ---------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(240px, 560px) auto;
  align-items: center;
  gap: 18px;
  height: 64px;
  padding: 0 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  grid-column: 1;
  justify-self: start;
  flex: 0 0 auto;
  color: var(--fg);
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  flex: 0 0 auto;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 0;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--fg);
  color: var(--bg);
}

.icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

.theme-toggle {
  grid-column: 4;
  justify-self: end;
}

.theme-toggle .icon-sun {
  display: none;
}

.theme-toggle .icon-moon {
  display: block;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

.nav-toggle {
  display: none;
}

/* Search ----------------------------------------------------------------- */

.search {
  position: relative;
  grid-column: 3;
  width: 100%;
  max-width: 560px;
  margin: 0;
  justify-self: right;
}

.search input {
  width: 100%;
  height: 38px;
  padding: 0 70px 0 12px;
  background: var(--bg-raised);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  appearance: none;
}

.search input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.search input:focus {
  border-color: var(--line);
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.search input::-webkit-search-cancel-button {
  appearance: none;
}

.search kbd {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  padding: 2px 5px;
  color: var(--muted);
  border: 1px solid var(--line-soft);
  font-family: var(--font-mono);
  font-size: 9px;
  line-height: 1.4;
  letter-spacing: 0.08em;
  pointer-events: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 14px);
  right: 0;
  left: auto;
  z-index: 200;
  width: min(680px, calc(100vw - 48px));
  max-height: min(70vh, 640px);
  overflow: auto;
  background: var(--bg-raised);
  border: 2px solid var(--line);
}

.search-hit {
  display: block;
  padding: 11px 14px;
  color: var(--fg);
  text-decoration: none;
  border-bottom: 1px solid var(--line-soft);
}

.search-hit:last-of-type {
  border-bottom: 0;
}

.search-hit:hover,
.search-hit.active {
  background: var(--fg);
  color: var(--bg);
}

.search-hit-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.4;
  letter-spacing: 0.08em;
}

.search-hit-page {
  font-weight: 700;
}

.search-hit-section {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-hit:hover .search-hit-section,
.search-hit.active .search-hit-section {
  color: var(--bg);
  opacity: 0.72;
}

.search-hit-snippet {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.search-hit:hover .search-hit-snippet,
.search-hit.active .search-hit-snippet {
  color: var(--bg);
  opacity: 0.86;
}

.search-hit mark {
  padding: 0 1px;
  background: var(--mark-bg);
  color: var(--mark-fg);
}

.search-empty {
  padding: 18px 14px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.search-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 14px;
  color: var(--muted);
  border-top: 1px solid var(--line-soft);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.08em;
}

/* Layout ----------------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: 248px minmax(0, 760px) 208px;
  justify-content: center;
  gap: 48px;
  width: 100%;
  max-width: 1340px;
  margin: 0 auto;
  padding: 0 28px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 64px;
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  padding: 30px 22px 48px 0;
  border-right: 1px solid var(--line-soft);
  scrollbar-width: thin;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-group-root {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 22px;
}

.nav-group-title {
  margin: 20px 0 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.13em;
}

.nav-link {
  display: block;
  padding: 4px 0 4px 10px;
  color: var(--fg);
  border-left: 2px solid transparent;
  font-size: 13.5px;
  line-height: 1.45;
  text-decoration: none;
}

.nav-link:hover {
  border-left-color: var(--line);
  background: var(--inline-code-bg);
}

.nav-link.active {
  border-left-color: var(--accent);
  background: var(--fg);
  color: var(--bg);
  font-weight: 600;
}

.nav-backdrop {
  display: none;
}

.nav-backdrop[hidden] {
  display: none;
}

.main {
  min-width: 0;
  padding: 42px 0 72px;
}

.article {
  min-width: 0;
}

/* Page header ------------------------------------------------------------ */

.page-header h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.15rem);
  font-weight: 800;
  line-height: 1.03;
  letter-spacing: -0.045em;
  text-wrap: balance;
}

.lede {
  max-width: 66ch;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 1.03rem;
  line-height: 1.6;
}

/* Prose ------------------------------------------------------------------ */

.article > p,
.article li,
.article dd {
  max-width: 72ch;
}

.article p {
  margin: 1rem 0;
}

.article > p:first-of-type {
  font-size: 1.035rem;
}

.article a {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.article a:hover {
  background: var(--accent);
  color: var(--accent-fg);
  text-decoration-color: transparent;
}

.article a[href^="http"]::after {
  content: " ↗";
  font-size: 0.78em;
  text-decoration: none;
}

.article h1,
.article h2,
.article h3,
.article h4 {
  color: var(--fg);
  font-family: var(--font-sans);
  font-weight: 750;
  line-height: 1.2;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.article h1 {
  margin: 2.4rem 0 1rem;
  font-size: 2rem;
}

.article h2 {
  margin: 3.1rem 0 0.9rem;
  padding-top: 1.05rem;
  border-top: 1px solid var(--line-soft);
  font-size: 1.48rem;
}

.article h3 {
  margin: 2rem 0 0.65rem;
  font-size: 1.14rem;
}

.article h4 {
  margin: 1.6rem 0 0.5rem;
  font-size: 1rem;
}

.heading-anchor {
  margin-left: 0.35em;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.62em;
  font-weight: 400;
  text-decoration: none;
  opacity: 0;
}

.article h2:hover .heading-anchor,
.article h3:hover .heading-anchor,
.article h4:hover .heading-anchor,
.heading-anchor:focus-visible {
  opacity: 1;
}

.article ul,
.article ol {
  padding-left: 1.35rem;
}

.article li {
  margin: 0.32rem 0;
  padding-left: 0.12rem;
}

.article li > ul,
.article li > ol {
  margin: 0.2rem 0;
}

.article strong {
  font-weight: 700;
}

.article blockquote {
  margin: 1.5rem 0;
  padding: 12px 18px;
  background: var(--bg-raised);
  border-left: 4px solid var(--accent);
}

.article blockquote > :first-child {
  margin-top: 0;
}

.article blockquote > :last-child {
  margin-bottom: 0;
}

.article hr {
  height: 0;
  margin: 2.5rem 0;
  border: 0;
  border-top: 2px solid var(--line);
}

/* Tables ----------------------------------------------------------------- */

.table-wrap {
  width: 100%;
  margin: 1.5rem 0;
  overflow-x: auto;
  border: 1px solid var(--line);
}

.article table {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  table-layout: auto;
  font-size: 0.88rem;
  line-height: 1.45;
  text-align: left;
}

.article colgroup {
  display: none;
}

.article th,
.article td {
  padding: 8px 11px;
  vertical-align: top;
  border-bottom: 1px solid var(--line-soft);
  border-right: 1px solid var(--line-soft);
}

.article th:last-child,
.article td:last-child {
  border-right: 0;
}

.article tbody tr:last-child td {
  border-bottom: 0;
}

.article thead th {
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.article tbody tr:hover {
  background: var(--inline-code-bg);
}

.article th code,
.article td code {
  white-space: nowrap;
}

/* Inline code ------------------------------------------------------------ */

.article code {
  padding: 0.08em 0.32em;
  background: var(--inline-code-bg);
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 0.86em;
  overflow-wrap: anywhere;
}

/* Code blocks ------------------------------------------------------------ */

.article pre {
  margin: 1.5rem 0;
  padding: 16px 18px;
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  color: var(--code-fg);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.6;
  tab-size: 4;
}

.article pre code {
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  color: inherit;
  font-size: inherit;
  overflow-wrap: normal;
  white-space: pre;
}

.code-block {
  position: relative;
  margin: 1.5rem 0;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  overflow: hidden;
}

.code-block > pre {
  margin: 0;
  padding: 16px 18px;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.code-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  padding: 2px 6px;
  background: var(--code-bg);
  color: var(--code-dim);
  border: 1px solid var(--code-border);
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  line-height: 1.6;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 100ms ease;
}

.code-block:hover .code-copy,
.code-copy:focus-visible,
.code-copy.copied {
  opacity: 1;
}

.code-copy:hover,
.code-copy:focus-visible {
  color: var(--code-fg);
  border-color: var(--accent);
}

.code-copy.copied {
  color: var(--accent);
  border-color: var(--accent);
}

@media (hover: none) {
  .code-copy {
    opacity: 0.75;
  }
}

.article pre::-webkit-scrollbar,
.search-results::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.article pre::-webkit-scrollbar-thumb {
  background: var(--code-border);
}

.search-results::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
  background: var(--line-soft);
}

.article pre::-webkit-scrollbar-track,
.search-results::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

/* Highlight.js tokens ---------------------------------------------------- */

.hljs-comment,
.hljs-quote {
  color: var(--code-comment);
  font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-subst {
  color: var(--code-keyword);
}

.hljs-string,
.hljs-regexp,
.hljs-addition,
.hljs-attribute,
.hljs-meta .hljs-string {
  color: var(--code-string);
}

.hljs-number,
.hljs-literal,
.hljs-symbol,
.hljs-bullet {
  color: var(--code-number);
}

.hljs-title,
.hljs-title.function,
.hljs-section,
.hljs-name {
  color: var(--code-title);
}

.hljs-type,
.hljs-class .hljs-title {
  color: var(--code-type);
}

.hljs-built_in {
  color: var(--code-builtin);
}

.hljs-variable,
.hljs-template-variable,
.hljs-params {
  color: var(--code-fg);
}

.hljs-attr,
.hljs-selector-attr,
.hljs-selector-pseudo {
  color: var(--code-builtin);
}

.hljs-operator,
.hljs-punctuation {
  color: var(--code-operator);
}

.hljs-meta,
.hljs-deletion {
  color: var(--code-meta);
}

.hljs-emphasis {
  font-style: italic;
}

.hljs-strong {
  font-weight: 700;
}

/* Table of contents ------------------------------------------------------ */

.toc-rail {
  position: sticky;
  top: 64px;
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  padding: 34px 0 48px;
  scrollbar-width: thin;
}

.toc-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-left: 1px solid var(--line-soft);
}

.toc-item {
  margin: 0;
}

.toc-item a {
  display: block;
  padding: 3px 0 3px 11px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -1.5px;
}

.toc-item a:hover {
  color: var(--fg);
  border-left-color: var(--line);
}

.toc-item a.active {
  color: var(--fg);
  border-left-color: var(--accent);
  font-weight: 600;
}

.toc-h3 a {
  padding-left: 22px;
  font-size: 11.5px;
}

.toc-inline {
  display: none;
  margin: 0 0 28px;
  border: 1px solid var(--line);
  background: var(--bg-raised);
}

.toc-inline summary {
  padding: 9px 12px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  cursor: pointer;
}

.toc-inline[open] summary {
  border-bottom: 1px solid var(--line-soft);
}

.toc-inline-list {
  padding: 8px 12px 10px;
}

.toc-inline-list .toc-list {
  border-left: 0;
}

.toc-inline-list .toc-item a {
  padding-left: 0;
  border-left: 0;
}

.toc-inline-list .toc-item a.active {
  color: var(--accent);
}

/* Pager and footer ------------------------------------------------------- */

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 54px;
  padding-top: 26px;
  border-top: 2px solid var(--line);
}

.pager-link {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  color: var(--fg);
  border: 1px solid var(--line);
  text-decoration: none;
}

.pager-link:hover {
  background: var(--fg);
  color: var(--bg);
}

.pager-next {
  text-align: right;
}

.pager-label {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.pager-link:hover .pager-label {
  color: var(--bg);
  opacity: 0.7;
}

.pager-title {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  margin-top: 48px;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.site-footer a {
  color: var(--muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--accent);
}

/* Responsive ------------------------------------------------------------- */

@media (max-width: 1240px) {
  .layout {
    grid-template-columns: 232px minmax(0, 760px);
    gap: 40px;
    max-width: 1100px;
  }

  .toc-rail {
    display: none;
  }

  .toc-inline {
    display: block;
  }
}

@media (max-width: 920px) {
  .topbar {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    gap: 10px;
    padding: 0 14px;
  }

  .nav-toggle {
    display: inline-grid;
    grid-column: 1;
    justify-self: start;
  }

  .brand {
    grid-column: 2;
  }

  .search {
    grid-column: 3;
    max-width: none;
    margin: 0;
    justify-self: stretch;
  }

  .theme-toggle {
    grid-column: 4;
  }

  .search kbd {
    display: none;
  }

  .search input {
    padding-right: 12px;
  }

  .search-results {
    position: fixed;
    top: 70px;
    left: 8px;
    right: 8px;
    width: auto;
    transform: none;
    max-height: calc(100vh - 84px);
  }

  .layout {
    display: block;
    padding: 0 18px;
  }

  .sidebar {
    position: fixed;
    top: 64px;
    left: 0;
    bottom: 0;
    z-index: 150;
    width: min(300px, 84vw);
    max-height: none;
    padding: 20px 22px 40px;
    background: var(--bg);
    border-right: 2px solid var(--line);
    transform: translateX(-102%);
    transition: transform 140ms ease;
  }

  body.nav-open .sidebar {
    transform: none;
  }

  .nav-backdrop {
    position: fixed;
    inset: 64px 0 0;
    z-index: 140;
    display: block;
    background: rgb(0 0 0 / 0.42);
  }

  .main {
    padding: 30px 0 60px;
  }

  .article h2 {
    margin-top: 2.6rem;
  }

  .article table {
    min-width: 600px;
  }
}

@media (max-width: 560px) {
  .page-header h1 {
    font-size: 2rem;
  }

  .lede {
    font-size: 0.98rem;
  }

  .article {
    font-size: 15.5px;
  }

  .pager {
    grid-template-columns: 1fr;
  }

  .pager-spacer {
    display: none;
  }

  .pager-next {
    text-align: left;
  }

  .site-footer {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .sidebar {
    transition: none;
  }
}

@media print {
  .topbar,
  .sidebar,
  .toc-rail,
  .toc-inline,
  .pager,
  .site-footer,
  .heading-anchor {
    display: none !important;
  }

  .layout {
    display: block;
    max-width: none;
    padding: 0;
  }

  .main {
    padding: 0;
  }

  body {
    background: #fff;
    color: #000;
  }

  .article a {
    color: #000;
  }

  .code-block,
  .article pre {
    border: 1px solid #000;
  }
}
