:root {
  --paper: #f4f0e6;
  --paper-raised: #fbf8f1;
  --ink: #1c1915;
  --ink-soft: #5e584e;
  --line: #ddd6c8;
  --accent: #1e4638;
  --accent-soft: #e5efe9;
  --code-bg: #ebe6db;
  --serif: "Source Serif 4", Palatino, "Palatino Linotype", Georgia, serif;
  --sans: "Source Sans 3", "Segoe UI", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --header-h: 3.4rem;
  --shell: 1080px;
}

* { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--header-h) + 1rem); }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.65;
}

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

a:hover { text-decoration-thickness: 2px; }

.skip {
  position: absolute;
  left: 0.75rem;
  top: -3rem;
  background: var(--ink);
  color: var(--paper);
  padding: 0.4rem 0.7rem;
  z-index: 3;
}

.skip:focus { top: 0.75rem; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.site-header .inner,
.shell {
  width: min(var(--shell), calc(100% - 2.5rem));
  margin-inline: auto;
}

.site-header .inner {
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  font-family: var(--sans);
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-decoration: none;
}

.site-header nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.1rem;
  font-family: var(--sans);
  font-size: 0.98rem;
}

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

.site-header nav a[aria-current="page"] {
  color: var(--ink);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.shell { padding: 2.25rem 0 4.5rem; }

.shell.has-sidebar {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  gap: 3rem;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: calc(var(--header-h) + 1.25rem);
  max-height: calc(100vh - var(--header-h) - 2rem);
  overflow: auto;
  font-family: var(--sans);
  font-size: 0.95rem;
  line-height: 1.4;
}

.side-label {
  margin: 0 0 0.7rem;
  color: var(--ink-soft);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.side-subs > li { margin: 0 0 0.85rem; }

.side-subs > li > a {
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

.side-subs > li > a[aria-current] { color: var(--accent); }

.sidebar li ul {
  margin-top: 0.35rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--line);
}

.sidebar li ul a {
  display: block;
  padding: 0.18rem 0;
  color: var(--ink-soft);
  text-decoration: none;
}

.sidebar li ul a[aria-current="page"] {
  color: var(--ink);
}

h1, h2, h3 { line-height: 1.2; font-weight: 600; }

h1 {
  margin: 0.35rem 0 0.8rem;
  font-size: clamp(2rem, 4vw, 2.8rem);
  letter-spacing: -0.02em;
}

.lede {
  margin-top: 0;
  color: var(--ink-soft);
  font-size: 1.2rem;
}

.home { max-width: 40rem; }

.topic-block {
  padding: 1.4rem 0 0.4rem;
  border-top: 1px solid var(--line);
}

.topic-block h2 {
  margin: 0 0 0.25rem;
  font-size: 1.7rem;
  font-weight: 600;
}

.topic-block h2 a { color: var(--ink); text-decoration: none; }
.topic-block h2 a:hover { color: var(--accent); }

.topic-block p { margin: 0.2rem 0 0.7rem; color: var(--ink-soft); }

.sub-links, .subcategory-list, .note-list {
  margin: 0.4rem 0 0;
  padding: 0;
}

.sub-links { list-style: none; display: flex; flex-wrap: wrap; gap: 0.35rem 1.2rem; }
.sub-links a { font-family: var(--sans); }

.subcategory-list { list-style: none; }
.subcategory-list li {
  padding: 1rem 0;
  border-top: 1px solid var(--line);
}
.subcategory-list a {
  font-size: 1.45rem;
  color: var(--ink);
  text-decoration: none;
}
.subcategory-list a:hover { color: var(--accent); }
.subcategory-list p { margin: 0.3rem 0 0; color: var(--ink-soft); }

.meta, .empty {
  font-family: var(--sans);
  font-size: 0.92rem;
  color: var(--ink-soft);
}

.crumbs { margin-bottom: 1.1rem; }
.crumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: var(--sans);
  font-size: 0.92rem;
}
.crumbs li { color: var(--ink-soft); }
.crumbs li + li::before {
  content: "/";
  margin-right: 0.3rem;
  color: var(--line);
}
.crumbs a { color: var(--ink-soft); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }

.prose { max-width: 68ch; }
.prose p { margin: 0.95rem 0; }
.prose h2 { margin: 2rem 0 0.6rem; font-size: 1.4rem; }
.prose h3 { margin: 1.5rem 0 0.4rem; font-size: 1.15rem; }
.prose ul, .prose ol { padding-left: 1.3rem; }
.prose li { margin: 0.3rem 0; }
.prose blockquote {
  margin: 1.2rem 0;
  padding-left: 1rem;
  border-left: 3px solid var(--accent);
  color: var(--ink-soft);
}
.prose a { color: var(--accent); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }
.prose img { max-width: 100%; height: auto; }

.prose :not(pre) > code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--code-bg);
  padding: 0.08em 0.32em;
  border-radius: 0.25rem;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
  margin: 1.2rem 0;
}
.prose th, .prose td {
  text-align: left;
  padding: 0.4rem 0.7rem 0.4rem 0;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.note-list {
  list-style: none;
  counter-reset: note;
  max-width: 40rem;
  margin-top: 1.5rem;
}
.note-list li {
  counter-increment: note;
  border-top: 1px solid var(--line);
}
.note-list a {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr);
  gap: 0.4rem;
  padding: 0.75rem 0;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.2rem;
}
.note-list a::before {
  content: counter(note, decimal-leading-zero);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.85rem;
  padding-top: 0.28rem;
}
.note-list a:hover { color: var(--accent); }

.math-display {
  margin: 1.1rem 0;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
}

mjx-container[display="true"] {
  margin: 1.1rem 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
}

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  max-width: 68ch;
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  font-family: var(--sans);
}
.pager a {
  display: flex;
  flex-direction: column;
  color: var(--ink);
  text-decoration: none;
  line-height: 1.35;
}
.pager span {
  color: var(--ink-soft);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.pager .next { grid-column: 2; text-align: right; }
.pager a:hover { color: var(--accent); }

.highlight {
  background: var(--code-bg);
  border-radius: 0.4rem;
  margin: 1.2rem 0;
}
.highlight pre {
  margin: 0;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.86rem;
  line-height: 1.5;
}
.highlight .k, .highlight .kd, .highlight .kn, .highlight .kr { color: #1e4638; }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sb { color: #8a3d2f; }
.highlight .c, .highlight .c1, .highlight .cm, .highlight .ch { color: #6d675c; font-style: italic; }
.highlight .mi, .highlight .mf, .highlight .mb { color: #1d3f66; }
.highlight .nf, .highlight .nb { color: #1d3f66; }
.highlight .o, .highlight .ow { color: #5e584e; }

@media (max-width: 800px) {
  .shell.has-sidebar { grid-template-columns: 1fr; gap: 1.5rem; }
  .sidebar {
    position: static;
    max-height: none;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--line);
  }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; text-align: left; }
}

@media print {
  .site-header, .sidebar, .pager, .skip { display: none; }
  body { background: white; }
  .shell, .shell.has-sidebar { display: block; width: auto; }
  a { color: inherit; text-decoration: none; }
}
