:root {
  --bg: #fdfcfa;
  --fg: #1d1d1f;
  --muted: #5f6368;
  --rule: #e4e1da;
  --code-bg: #f3f1ec;
  --link: #0b57d0;
  --accent: #8a4b08;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151517;
    --fg: #e8e6e3;
    --muted: #a3a3a8;
    --rule: #2f2f33;
    --code-bg: #1f1f23;
    --link: #8ab4f8;
    --accent: #f0b878;
  }
}

* { box-sizing: border-box; }

html { scroll-padding-top: 1rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.65 Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--link); text-underline-offset: 0.15em; }

header.site, footer.site {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
}

header.site {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  align-items: baseline;
  justify-content: space-between;
  max-width: 76rem;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--rule);
}

header.site .brand {
  color: var(--fg);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  text-decoration: none;
}

header.site nav { display: flex; flex-wrap: wrap; gap: 1.25rem; }
header.site nav a { color: var(--muted); text-decoration: none; }
header.site nav a:hover { color: var(--fg); }

.layout {
  max-width: 76rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

main { max-width: 46rem; margin: 0 auto; padding: 1.5rem 0 4rem; min-width: 0; }

.layout.with-toc {
  display: grid;
  grid-template-columns: 16rem minmax(0, 46rem);
  gap: 3rem;
  justify-content: center;
}

.layout.with-toc main { margin: 0; }

.toc {
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100vh;
  overflow-y: auto;
  padding: 1.75rem 0 2rem;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.toc p { margin: 0 0 0.5rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-size: 12px; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0.2rem 0; }
.toc li.l3 { padding-left: 1rem; font-size: 13px; }
.toc a { color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--fg); }

@media (max-width: 64rem) {
  .layout.with-toc { display: block; }
  .toc { display: none; }
}

h1, h2, h3, h4 {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.25;
  font-weight: 650;
}

h1 { font-size: 2rem; margin: 1rem 0 0.75rem; }
h2 { font-size: 1.4rem; margin: 2.75rem 0 0.75rem; padding-top: 0.5rem; border-top: 1px solid var(--rule); }
h3 { font-size: 1.12rem; margin: 2rem 0 0.5rem; }

h1 + p { color: var(--accent); font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 15px; }

.anchor {
  margin-left: 0.4rem;
  color: var(--muted);
  text-decoration: none;
  opacity: 0;
  font-weight: 400;
}
h2:hover .anchor, h3:hover .anchor, .anchor:focus { opacity: 1; }

code, pre {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.86em;
}

code { background: var(--code-bg); padding: 0.1em 0.3em; border-radius: 4px; overflow-wrap: break-word; }

pre {
  background: var(--code-bg);
  padding: 0.9rem 1rem;
  border-radius: 6px;
  overflow-x: auto;
  line-height: 1.45;
}

pre code { background: none; padding: 0; overflow-wrap: normal; font-size: 1em; }

.table-wrap { overflow-x: auto; margin: 1rem 0; }

table { border-collapse: collapse; font-size: 0.92em; width: 100%; }
th, td { border-bottom: 1px solid var(--rule); padding: 0.45rem 0.6rem; text-align: left; vertical-align: top; }
th { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-weight: 600; }

figure { margin: 2rem 0; }
figure img { display: block; width: 100%; height: auto; }
figure > a { display: block; overflow-x: auto; }
@media (max-width: 40rem) { figure img { min-width: 36rem; } }
figcaption { margin-top: 0.6rem; color: var(--muted); font-size: 0.9em; font-style: italic; }

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

footer.site {
  max-width: 76rem;
  margin: 0 auto;
  padding: 1.5rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
}

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