:root {
  color-scheme: light;
  --canvas: #f7f7f4;
  --surface: #ffffff;
  --ink: #1b1c1a;
  --muted: #777972;
  --quiet: #a5a69f;
  --line: #dedfd9;
  --soft-line: #e9eae5;
  --code: #efefe9;
  --accent: #3155d9;
  --accent-wash: color-mix(in srgb, var(--accent) 7%, transparent);
  --sans: "Switzer", sans-serif;
  --serif: "Sentient", serif;
  --mono: "Fragment Mono", monospace;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --text-scale: 1;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #171816;
  --surface: #1b1c1a;
  --ink: #ecece7;
  --muted: #a2a49d;
  --quiet: #777972;
  --line: #383a35;
  --soft-line: #2b2d29;
  --code: #272925;
  --accent: #91a8ff;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 100px;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  font-size: calc(17px * var(--text-scale));
  line-height: 1.7;
  text-rendering: optimizeLegibility;
  transition:
    background 180ms var(--ease),
    color 180ms var(--ease);
}

button,
summary {
  color: inherit;
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

::selection {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
}

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

.topbar {
  position: sticky;
  z-index: 50;
  top: 0;
  height: 60px;
  border-bottom: 1px solid var(--line);
  background: var(--canvas);
}

.topbar-inner {
  display: grid;
  grid-template-columns: 1fr minmax(0, 520px) 1fr;
  align-items: center;
  max-width: 1360px;
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
}

.brand {
  display: inline-flex;
  align-items: baseline;
  width: max-content;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.045em;
  line-height: 1;
  text-decoration: none;
}

.brand-dot {
  color: var(--accent);
}

.brand-page {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.025em;
}

.brand-progress {
  min-width: 31px;
  margin-left: 9px;
  padding-left: 9px;
  border-left: 1px solid var(--line);
  color: var(--quiet);
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 400;
  letter-spacing: -0.04em;
  line-height: 1;
}

.topbar-title {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions {
  position: relative;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.action {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  transition:
    background 180ms var(--ease),
    color 180ms var(--ease);
}

.action:hover,
.action[aria-expanded="true"] {
  background: var(--accent-wash);
  color: var(--accent);
}

.action svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
}

.settings {
  position: absolute;
  top: 42px;
  right: 0;
  display: none;
  width: 230px;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 16px 48px rgba(20, 22, 18, 0.12);
}

.settings.open {
  display: block;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.segmented {
  display: flex;
  border: 1px solid var(--line);
}

.segmented button {
  min-width: 34px;
  height: 28px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  font-size: 12px;
}

.segmented button + button {
  border-left: 1px solid var(--line);
}

.segmented button:hover {
  background: var(--code);
}

.reader {
  display: grid;
  grid-template-columns: 190px minmax(0, 860px);
  gap: 72px;
  max-width: 1186px;
  margin: 0 auto;
  padding: 66px 32px 120px;
}

.toc {
  position: sticky;
  top: 108px;
  align-self: start;
  min-width: 0;
}

.toc-label {
  display: block;
  margin-bottom: 18px;
  color: color-mix(in srgb, var(--muted) 78%, transparent);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.toc-links {
  position: relative;
  padding-left: 15px;
  border-left: 1px solid var(--soft-line);
}

.toc-marker {
  position: absolute;
  top: 0;
  left: -1px;
  width: 2px;
  height: 16px;
  background: var(--accent);
  transform: translateY(0);
  transition:
    transform 220ms var(--ease),
    height 220ms var(--ease);
}

.toc a {
  display: block;
  margin: 0 0 13px;
  color: var(--muted);
  font-size: 12.25px;
  font-weight: 500;
  line-height: 1.35;
  text-decoration: none;
  transition: color 180ms var(--ease);
}

.toc a:hover,
.toc a.active {
  color: var(--ink);
}

.toc-meta {
  margin-top: 30px;
  padding-top: 16px;
  border-top: 1px solid var(--soft-line);
  color: color-mix(in srgb, var(--muted) 78%, transparent);
  font-family: var(--mono);
  font-size: 9.5px;
  line-height: 1.7;
  text-transform: uppercase;
}

.mobile-toc {
  display: none;
}

.document {
  min-width: 0;
}

.document h1,
.document h2 {
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: -0.035em;
}

.document h1 {
  max-width: none;
  margin: 0 0 28px;
  font-size: clamp(44px, 4.2vw, 54px);
  line-height: 1.02;
}

.document h2 {
  position: relative;
  margin: 74px 0 23px;
  padding-top: 29px;
  font-size: 34px;
  line-height: 1.15;
  scroll-margin-top: 76px;
}

.document h2::before {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 1px;
  background: linear-gradient(to right, var(--accent) 26px, var(--line) 26px);
  content: "";
}

.document > p:first-of-type {
  margin: 0 0 56px;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1.52;
}

.document p,
.document li,
.document td,
.document th {
  font-family: var(--sans);
}

.document p {
  margin: 0 0 1.45em;
}

.document strong {
  font-weight: 600;
}

.document em {
  font-family: var(--serif);
}

.document code {
  padding: 0.08em 0.22em;
  background: var(--code);
  font-family: var(--mono);
  font-size: 0.76em;
  letter-spacing: -0.03em;
  white-space: nowrap;
}

.document a {
  text-decoration-color: var(--quiet);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition:
    color 180ms var(--ease),
    text-decoration-color 180ms var(--ease);
}

.document a:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

.document ul,
.document ol {
  margin: 0 0 1.6em;
  padding-left: 1.25em;
}

.document li {
  margin-bottom: 0.48em;
  padding-left: 0.25em;
}

.document li::marker {
  color: var(--quiet);
}

.document blockquote {
  hanging-punctuation: first;
}

.table-wrap {
  max-width: 100%;
  margin: 28px 0 32px;
  overflow-x: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.55;
}

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

th:first-child,
td:first-child {
  padding-left: 0;
}

th:last-child,
td:last-child {
  padding-right: 0;
}

th {
  color: var(--muted);
  font-family: var(--mono) !important;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.035em;
  text-transform: uppercase;
}

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

.table-wrap code {
  font-size: 0.88em;
}

.document code.wrap-code {
  white-space: normal;
  overflow-wrap: anywhere;
}

.document-end {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 72px;
  color: var(--quiet);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.document-end::before,
.document-end::after {
  flex: 1;
  height: 1px;
  background: var(--soft-line);
  content: "";
}

.footer {
  border-top: 1px solid var(--line);
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1186px;
  min-height: 82px;
  margin: 0 auto;
  padding: 0 32px;
  color: var(--muted);
  font-size: 11px;
}

.footer a {
  text-underline-offset: 3px;
}

.copy-feedback {
  opacity: 0;
  transition: opacity 0.15s ease;
}

.copy-feedback.show {
  opacity: 1;
}

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

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 1180px) {
  .topbar-inner {
    grid-template-columns: 1fr auto;
  }

  .topbar-title {
    display: none;
  }

  .reader {
    display: block;
    max-width: 860px;
    padding-top: 46px;
  }

  .toc {
    display: none;
  }

  .mobile-toc {
    display: block;
    margin: 0 0 34px;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .mobile-toc summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    list-style: none;
    cursor: pointer;
  }

  .mobile-toc summary::-webkit-details-marker {
    display: none;
  }

  .mobile-toc summary::after {
    width: 7px;
    height: 7px;
    margin-right: 3px;
    border-right: 1px solid var(--muted);
    border-bottom: 1px solid var(--muted);
    content: "";
    transform: rotate(45deg) translateY(-2px);
    transition: transform 180ms var(--ease);
  }

  .mobile-toc[open] summary::after {
    transform: rotate(225deg) translate(-2px, -2px);
  }

  .mobile-toc nav {
    padding: 0 0 16px;
  }

  .mobile-toc a {
    display: block;
    padding: 5px 0;
    color: var(--muted);
    font-size: 13px;
    text-decoration: none;
  }
}

@media (max-width: 560px) {
  .topbar-inner {
    padding: 0 16px;
  }

  .reader {
    padding: 38px 20px 86px;
  }

  .document .header-anchor {
    display: none;
  }

  .document h1 {
    font-size: 39px;
    line-height: 1.04;
  }

  .document > p:first-of-type {
    margin-bottom: 42px;
    font-size: 20px;
  }

  .document h2 {
    margin-top: 58px;
    padding-top: 24px;
    font-size: 30px;
  }

  .document p,
  .document li {
    line-height: 1.67;
  }

  .document code {
    font-size: 0.73em;
  }

  .table-wrap {
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  .document .table-wrap code {
    font-size: 0.86em;
  }

  .footer-inner {
    min-height: 74px;
    padding: 0 20px;
  }

  .footer-inner > span:last-child {
    display: none;
  }
}

body {
  min-height: 100vh;
}

button {
  -webkit-appearance: none;
  appearance: none;
}

.reader-without-toc {
  grid-template-columns: minmax(0, 860px);
  max-width: 924px;
}

.theme-sun,
html[data-theme="dark"] .theme-moon {
  display: none;
}

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

.toc-marker {
  opacity: 0;
}

.toc-marker.visible {
  opacity: 1;
}

.toc-context {
  display: block;
  margin: -4px 0 18px;
  color: var(--ink) !important;
  font-family: var(--serif);
  font-size: 16px !important;
  font-weight: 500;
  line-height: 1.25 !important;
}

.toc-link[data-level="h3"] {
  padding-left: 12px;
  font-size: 11.5px;
}

.mobile-toc .toc-link[data-level="h3"] {
  padding-left: 14px;
}

.document h1:first-child {
  margin-top: 0;
}

.document h3,
.document h4,
.document h5,
.document h6 {
  margin: 44px 0 17px;
  font-family: var(--sans);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.25;
  scroll-margin-top: 82px;
}

.document h3 {
  font-size: 23px;
}

.document h4 {
  font-size: 18px;
}

.document h5,
.document h6 {
  font-size: 15px;
}

.document :is(h1, h2, h3, h4, h5, h6) {
  position: relative;
}

.document .header-anchor {
  position: absolute;
  right: 100%;
  margin-right: 0.3em;
  color: var(--quiet);
  font-family: var(--sans);
  font-size: 0.55em;
  font-weight: 400;
  text-decoration: none;
  opacity: 0;
  transition:
    color 180ms var(--ease),
    opacity 180ms var(--ease);
}

.document :is(h1, h2, h3, h4):hover .header-anchor,
.document .header-anchor:focus-visible {
  opacity: 1;
}

.document hr {
  height: 1px;
  margin: 54px 0;
  border: 0;
  background: var(--line);
}

.document blockquote {
  margin: 32px 0;
  padding: 3px 0 3px 22px;
  border-left: 2px solid var(--accent);
  color: var(--muted);
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.55;
}

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

.document dl {
  margin: 0 0 1.6em;
}

.document dt {
  margin-top: 1em;
  font-weight: 600;
}

.document dd {
  margin: 0.35em 0 0 1.25em;
  color: var(--muted);
}

.document .contains-task-list {
  padding-left: 0;
  list-style: none;
}

.document .task-list-item {
  position: relative;
  padding-left: 1.65em;
}

.document .task-list-item input {
  position: absolute;
  top: 0.45em;
  left: 0;
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--accent);
}

.document img:not(.lightbox-image) {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 34px auto;
  border: 1px solid var(--line);
  cursor: zoom-in;
}

.code-block {
  margin: 30px 0 36px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #20211f;
  color: #ecece7;
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  padding: 0 12px 0 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #a9aaa4;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.copy-code-btn {
  padding: 7px 5px;
  border: 0;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
}

.copy-code-btn:hover {
  color: #fff;
}

.code-content {
  max-width: 100%;
  overflow: auto;
}

.code-content pre,
.document pre {
  margin: 0;
  padding: 20px;
  overflow: auto;
  background: #20211f !important;
  color: #ecece7;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.65;
  tab-size: 2;
}

.document pre code,
.code-content code {
  padding: 0;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  letter-spacing: 0;
  white-space: pre;
}

.asterism {
  margin: 48px 0;
  color: var(--quiet);
  font-family: var(--serif);
  font-size: 22px;
  text-align: center;
  letter-spacing: 0.35em;
}

.mermaid {
  margin: 34px 0;
  overflow-x: auto;
  text-align: center;
}

.katex-display {
  margin: 30px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.lightbox {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 52px;
  background: rgba(10, 11, 9, 0.9);
}

.lightbox[hidden] {
  display: none;
}

.lightbox-image {
  max-width: min(1200px, 92vw);
  max-height: 88vh;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 18px;
  right: 22px;
  width: 38px;
  height: 38px;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 30px;
  font-weight: 300;
  line-height: 1;
}

body.lightbox-open {
  overflow: hidden;
}

.lucid-chapters {
  margin: 34px 0;
  padding: 0;
  border-top: 1px solid var(--ink);
  list-style: none;
}

.lucid-chapters li {
  margin: 0;
  padding: 0;
  border-bottom: 1px solid var(--soft-line);
}

.lucid-chapters a {
  display: block;
  padding: 15px 0;
  font-weight: 500;
  text-decoration: none;
}

.chapter-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin-top: 72px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.chapter-nav-link {
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-decoration: none;
}

.chapter-nav-link span {
  color: var(--quiet);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.chapter-nav-link strong {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
}

.chapter-nav-next {
  text-align: right;
}

@media (max-width: 560px) {
  .lightbox {
    padding: 22px;
  }

  .code-content pre,
  .document pre {
    padding: 16px;
    font-size: 12px;
  }

  .chapter-nav {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .chapter-nav-next {
    text-align: left;
  }
}

@media print {
  .topbar,
  .toc,
  .mobile-toc,
  .footer,
  .copy-code-btn {
    display: none !important;
  }

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

  .reader,
  .reader-without-toc {
    display: block;
    max-width: none;
    padding: 0;
  }
}
