:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --panel: #f8fafc;
  --code-bg: #0f172a;
  --code-fg: #e2e8f0;
  --code-inline-bg: #f0fdf4;
  --code-inline-fg: #166534;
  --accent: #15803d;
  --accent-fg: #ffffff;
  --accent-soft: rgba(21, 128, 61, 0.1);
  --row-hover: #f8fafc;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 28px rgba(15, 23, 42, 0.07);
  --max: 820px;
  --wide: 1120px;
  --reading: 760px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17;
    --fg: #e5e7eb;
    --muted: #94a3b8;
    --line: #1f2937;
    --panel: #111827;
    --code-bg: #020617;
    --code-fg: #e2e8f0;
    --code-inline-bg: #052e16;
    --code-inline-fg: #86efac;
    --accent: #4ade80;
    --accent-fg: #0b0f17;
    --accent-soft: rgba(74, 222, 128, 0.14);
    --row-hover: #111827;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family:
    ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16.5px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent);
  text-underline-offset: 0.16em;
}

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

code,
pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

code {
  padding: 0.12em 0.4em;
  border-radius: 5px;
  background: var(--code-inline-bg);
  color: var(--code-inline-fg);
  font-size: 0.88em;
}

pre {
  position: relative;
  margin: 1.2rem 0;
  padding: 1.1rem 1.2rem;
  overflow-x: auto;
  background: var(--code-bg);
  color: var(--code-fg);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

pre code {
  padding: 0;
  background: none;
  color: inherit;
  font-size: 0.86rem;
  line-height: 1.6;
}

.site-header,
main,
footer {
  width: min(100% - 2.5rem, var(--max));
  margin-inline: auto;
}

.site-header.wide,
main.wide,
footer.wide {
  width: min(100% - 2.5rem, var(--wide));
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.9rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

@supports (backdrop-filter: blur(1px)) {
  .site-header {
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: blur(12px);
  }
}

.brand {
  font-weight: 700;
  letter-spacing: 0.01em;
  text-decoration: none;
  color: var(--fg);
}

.site-header nav {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  font-size: 0.95rem;
}

.site-header nav a {
  color: var(--muted);
  text-decoration: none;
  transition: color 120ms ease;
}

.site-header nav a:hover,
.links a:hover {
  color: var(--fg);
  text-decoration: underline;
}

.hero {
  position: relative;
  isolation: isolate;
  border-top: 0;
  padding-block: clamp(3.5rem, 8vw, 6rem) clamp(2rem, 4vw, 3rem);
}

.hero::before {
  content: "";
  position: absolute;
  inset: -10% 0 auto 0;
  height: min(520px, 90%);
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(55% 60% at 50% 0%, var(--accent-soft), transparent 70%);
}

.eyebrow {
  margin: 0 0 0.85rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 1.1rem;
  max-width: 18ch;
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

h2 {
  margin: 0 0 1rem;
  font-size: clamp(1.5rem, 3vw, 1.9rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

h3 {
  margin: 0 0 0.5rem;
  font-size: 1.12rem;
  letter-spacing: -0.01em;
}

section > h3 {
  margin-top: 1.8rem;
}

section[id],
h3[id] {
  scroll-margin-top: 5rem;
}

p {
  margin: 0 0 1.1rem;
}

.lead {
  color: var(--muted);
  font-size: clamp(1.05rem, 2vw, 1.25rem);
  max-width: 46rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin: 1.7rem 0 1rem;
}

.button {
  display: inline-flex;
  align-items: center;
  padding: 0.6rem 1.05rem;
  border-radius: 9px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
  text-decoration: none;
  transition: transform 120ms ease, filter 120ms ease;
}

.button.ghost {
  background: transparent;
  color: var(--accent);
}

.button:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.note {
  color: var(--muted);
  font-size: 0.9rem;
}

section {
  padding-block: clamp(1.8rem, 4vw, 2.6rem);
  border-top: 1px solid var(--line);
}

.layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: clamp(2rem, 5vw, 4rem);
  align-items: start;
  padding-block: 1rem 2rem;
}

.sidebar {
  position: sticky;
  top: 4.5rem;
  align-self: start;
  max-height: calc(100vh - 5.5rem);
  overflow: auto;
  padding-block: 0.5rem;
}

.content {
  min-width: 0;
  max-width: var(--reading);
}

.content > section:first-child {
  border-top: 0;
  padding-top: 0.5rem;
}

.toc-title {
  margin: 0 0 0.6rem;
  padding-inline: 0.65rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.toc ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.toc li {
  margin: 0;
}

.toc a {
  display: block;
  padding: 0.4rem 0.65rem;
  border-left: 2px solid transparent;
  border-radius: 0 7px 7px 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
  text-decoration: none;
  transition: color 120ms ease, background 120ms ease, border-color 120ms ease;
}

.toc a:hover {
  color: var(--fg);
  background: var(--panel);
}

.toc a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 500;
}

.toc .toc-sub a {
  padding-left: 1.4rem;
  font-size: 0.85rem;
}

ul,
ol {
  padding-left: 1.25rem;
  margin: 0 0 1.1rem;
}

li + li {
  margin-top: 0.45rem;
}

.table-wrap {
  margin: 1.2rem 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
}

th,
td {
  padding: 0.6rem 0.8rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

thead th {
  background: var(--panel);
  font-weight: 600;
}

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

tbody tr:hover {
  background: var(--row-hover);
}

th.num,
td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.grid {
  display: grid;
  gap: 1rem;
}

.grid.three {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.grid.two {
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.grid article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.1rem 1.2rem;
}

.grid article.wide {
  grid-column: 1 / -1;
}

.grid article p:last-child,
.grid article ul:last-child {
  margin-bottom: 0;
}

.links {
  list-style: none;
  padding: 0;
}

.links li {
  margin: 0;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
}

.links em {
  color: var(--muted);
  font-style: normal;
  font-size: 0.85rem;
}

.copy {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  padding: 0.25rem 0.55rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.6);
  color: #cbd5e1;
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 150ms ease, background 150ms ease;
}

pre:hover .copy,
.copy:focus-visible {
  opacity: 1;
}

.copy:hover {
  background: rgba(15, 23, 42, 0.85);
}

footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  padding-block: 2rem 3rem;
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .sidebar {
    position: static;
    max-height: none;
    overflow: visible;
    padding: 0;
    border-bottom: 1px solid var(--line);
  }

  .toc ol {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.3rem 0.5rem;
    padding-bottom: 0.9rem;
  }

  .toc a {
    padding: 0.3rem 0.6rem;
    border-left: 0;
    border-radius: 7px;
    background: var(--panel);
  }

  .toc a.active {
    border-left: 0;
  }

  .content {
    max-width: none;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 16px;
  }

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

  .copy {
    opacity: 1;
  }

  h1 {
    max-width: none;
  }
}

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

  .button,
  .toc a,
  .copy,
  .site-header nav a {
    transition: none;
  }
}
