:root {
  color-scheme: light;
  --ink: #18231f;
  --muted: #5d6b65;
  --paper: #f7f4ec;
  --panel: #fffdf7;
  --line: #c8d1cb;
  --accent: #1d6755;
  --accent-soft: #e2eee8;
  --warm: #9b5b2e;
  --warm-soft: #f4e7d4;
  --code: #edf2ef;
  --shadow: 0 18px 45px rgb(24 35 31 / 8%);
  --reading-width: 76rem;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--paper);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.65;
}

body {
  margin: 0;
  min-height: 100vh;
  background-image:
    linear-gradient(rgb(29 103 85 / 4%) 1px, transparent 1px),
    linear-gradient(90deg, rgb(29 103 85 / 4%) 1px, transparent 1px);
  background-size: 28px 28px;
}

a {
  color: var(--accent);
  text-decoration-color: rgb(29 103 85 / 35%);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

a:hover {
  text-decoration-color: currentColor;
}

a:focus-visible {
  border-radius: 0.18rem;
  outline: 3px solid rgb(155 91 46 / 35%);
  outline-offset: 3px;
}

.site-header {
  align-items: center;
  backdrop-filter: blur(12px);
  background: rgb(247 244 236 / 92%);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 1.5rem;
  justify-content: space-between;
  padding: 0.9rem clamp(1rem, 4vw, 3.5rem);
  position: sticky;
  top: 0;
  z-index: 10;
}

.site-header .brand {
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
  font-weight: 700;
  text-decoration: none;
}

.site-header nav {
  display: flex;
  flex-wrap: wrap;
  font-size: 0.82rem;
  gap: 0.35rem 1rem;
}

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

.site-header nav a[aria-current="page"] {
  color: var(--accent);
  font-weight: 700;
}

.page {
  background: var(--panel);
  border: 1px solid rgb(200 209 203 / 80%);
  box-shadow: var(--shadow);
  margin: clamp(1.25rem, 4vw, 4rem) auto;
  max-width: var(--reading-width);
  padding: clamp(1.4rem, 5vw, 5rem);
  width: calc(100% - clamp(1.25rem, 5vw, 5rem));
}

.eyebrow {
  color: var(--warm);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  margin: 0 0 0.6rem;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.18;
  text-wrap: balance;
}

h1 {
  font-size: clamp(2.3rem, 6vw, 5.2rem);
  letter-spacing: -0.045em;
  margin: 0 0 1.25rem;
  max-width: 15ch;
}

h2 {
  border-top: 1px solid var(--line);
  font-size: clamp(1.55rem, 3vw, 2.35rem);
  margin: 3.5rem 0 1rem;
  padding-top: 1.25rem;
}

h3 {
  font-size: 1.3rem;
  margin: 2.2rem 0 0.6rem;
}

.lede {
  color: #36453f;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.15rem, 2vw, 1.45rem);
  line-height: 1.55;
  max-width: 58ch;
}

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

code {
  background: var(--code);
  border: 1px solid #d8e1dc;
  border-radius: 0.22rem;
  color: #29483e;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.84em;
  padding: 0.08em 0.3em;
}

.reading-path {
  counter-reset: layer;
  display: grid;
  gap: 0.75rem;
  list-style: none;
  margin: 1.5rem 0;
  padding: 0;
}

.reading-path li {
  align-items: baseline;
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  display: grid;
  gap: 0.8rem;
  grid-template-columns: 2rem 1fr;
  max-width: none;
  padding: 0.8rem 1rem;
}

.reading-path li::before {
  color: var(--accent);
  content: counter(layer, decimal-leading-zero);
  counter-increment: layer;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 800;
}

.callout {
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
}

.callout.inference {
  background: var(--warm-soft);
  border-left-color: var(--warm);
}

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

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

.term-list {
  display: grid;
  gap: 0;
  grid-template-columns: minmax(10rem, 0.32fr) 1fr;
}

.term-list dt,
.term-list dd {
  border-top: 1px solid var(--line);
  margin: 0;
  padding: 0.9rem 0;
}

.term-list dt {
  font-weight: 800;
  padding-right: 1.5rem;
}

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

table {
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 42rem;
  width: 100%;
}

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

th {
  background: var(--accent-soft);
  color: #28473e;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.mermaid {
  background: #fbfaf5;
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  margin: 1.5rem 0;
  overflow-x: auto;
  padding: clamp(0.75rem, 2vw, 1.5rem);
  text-align: center;
}

.mermaid svg {
  height: auto;
  max-width: 100%;
}

.page-nav {
  border-top: 1px solid var(--line);
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-top: 4rem;
  padding-top: 1.25rem;
}

.page-nav a {
  font-weight: 700;
  text-decoration: none;
}

.page-nav a:last-child {
  margin-left: auto;
  text-align: right;
}

small,
.muted {
  color: var(--muted);
}

@media (max-width: 720px) {
  html {
    font-size: 16px;
  }

  .site-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.5rem;
    position: static;
  }

  .page {
    border-left: 0;
    border-right: 0;
    margin: 0;
    padding: 2rem 1.1rem 3rem;
    width: 100%;
  }

  .term-list {
    display: block;
  }

  .term-list dt {
    padding-bottom: 0.2rem;
  }

  .term-list dd {
    border-top: 0;
    padding-top: 0;
  }

  .page-nav {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-nav a:last-child {
    margin-left: 0;
    text-align: left;
  }
}

@media print {
  body {
    background: white;
  }

  .site-header {
    display: none;
  }

  .page {
    border: 0;
    box-shadow: none;
    margin: 0;
    max-width: none;
    padding: 0;
    width: 100%;
  }
}
