:root {
  --bg: #fdfcf8;
  --fg: #1f2328;
  --muted: #6a6f76;
  --accent: #2b5d9b;
  --accent-soft: #e8eff8;
  --border: #d9dde3;
  --knowl-bg: #f4f7fb;
  --knowl-border: #8fb0d8;
  --def: #2e7d5b;
  --thm: #2b5d9b;
  --rem: #7a6a3a;
  --error: #b42318;
  --ok: #1a7f37;
  --code-bg: #f1f1ee;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --fg: #e4e6e9;
    --muted: #9aa0a8;
    --accent: #7fb0ec;
    --accent-soft: #1f2a38;
    --border: #343a42;
    --knowl-bg: #1c222b;
    --knowl-border: #44628a;
    --def: #6cc49b;
    --thm: #7fb0ec;
    --rem: #cbb77d;
    --error: #ff7b72;
    --ok: #56d364;
    --code-bg: #23262b;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  font-size: 18px;
  line-height: 1.6;
}
main { max-width: 46rem; margin: 0 auto; padding: 1rem 16px 3rem; }
main.wide { max-width: 90rem; }
a { color: var(--accent); }
h1 { font-size: 1.7rem; line-height: 1.25; margin: 1rem 0; }
h2 { font-size: 1.2rem; }
code, pre { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 0.85em; }
code { background: var(--code-bg); padding: 0.05em 0.3em; border-radius: 3px; }
pre { background: var(--code-bg); padding: 0.6rem; overflow-x: auto; border-radius: 4px; }
.muted { color: var(--muted); }
.num { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 0.3em; }

.site-header {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: baseline; justify-content: space-between;
  padding: 0.6rem 16px; border-bottom: 1px solid var(--border);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 0.95rem;
}
.site-title { font-weight: 600; color: var(--fg); text-decoration: none; }
.site-header nav a { margin-left: 1rem; }
.site-footer { text-align: center; padding: 2rem 16px; font-size: 0.85rem; color: var(--muted); font-family: system-ui, sans-serif; }
.site-footer a { color: var(--muted); }
.breadcrumb { font-size: 0.9rem; color: var(--muted); font-family: system-ui, sans-serif; margin: 0.5rem 0; }
.lede { color: var(--muted); }

/* table of contents */
.toc ol { list-style: none; padding-left: 0; }
.toc ol ol { padding-left: 1.2rem; }
.toc-chapter { margin: 1.2rem 0; font-weight: 600; }
.toc-section { font-weight: 400; margin: 0.4rem 0; }
.toc-results { list-style: none; padding-left: 1.4rem; font-size: 0.92rem; margin: 0.2rem 0; font-weight: 400; }
.toc-results .result-label { font-weight: 600; }
.toc-results .result-title { font-weight: 400; }
.toc a { text-decoration: none; }
.toc a:hover { text-decoration: underline; }
.section-list { padding-left: 1.2rem; }

/* results */
.result { margin: 1.6rem 0; scroll-margin-top: 1rem; }
.result-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.4rem; margin-bottom: 0.2rem; }
.result-label { font-weight: 700; }
.result-link { color: inherit; text-decoration: none; }
.result-link:hover .result-label { text-decoration: underline; }
.result-title { font-weight: 600; }
.type-definition > .result-head .result-label { color: var(--def); }
.type-theorem > .result-head .result-label, .type-proposition > .result-head .result-label,
.type-lemma > .result-head .result-label, .type-corollary > .result-head .result-label { color: var(--thm); }
.type-remark > .result-head .result-label, .type-example > .result-head .result-label { color: var(--rem); }
/* italic statements (child combinator so knowls opened inside a theorem are not affected) */
.type-theorem > .statement, .type-lemma > .statement, .type-proposition > .statement,
.type-corollary > .statement, .type-conjecture > .statement { font-style: italic; }
.statement .katex { font-style: normal; }
.knowl-box { font-style: normal; }
.tag-link {
  margin-left: auto; font-family: ui-monospace, Consolas, monospace; font-size: 0.75rem; color: var(--muted);
  text-decoration: none; border: 1px solid var(--border); border-radius: 3px; padding: 0 0.3em;
}
h1 .tag-link { vertical-align: middle; margin-left: 0.5rem; }
.statement p:first-child, .proof-body p:first-child { margin-top: 0; }
.statement p:last-child { margin-bottom: 0; }

.proof { margin: 0.7rem 0 0; }
.proof-head { margin-bottom: 0.2rem; }
.proof-label { font-style: italic; font-weight: 600; }
details.proof > summary { cursor: pointer; }
.proof-body { position: relative; padding-right: 1.4em; }
.proof-body > p:last-of-type { margin-bottom: 0.4rem; }
.qed { position: absolute; right: 0; bottom: 0.4rem; color: var(--muted); }
.badge {
  display: inline-block; font-family: system-ui, sans-serif; font-size: 0.72rem; line-height: 1.5;
  padding: 0 0.5em; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; font-style: normal;
}
.badge-ai_generated { background: #fff4e5; border-color: #f0c37a; color: #7a4b00; }
.badge-polishing { background: #eef3ff; border-color: #a9bff0; color: #23408e; }
.badge-polished { background: #eaf7ee; border-color: #8fd0a2; color: #18623a; }
@media (prefers-color-scheme: dark) {
  .badge-ai_generated { background: #3a2a10; color: #f5c77a; border-color: #6b4f1d; }
  .badge-polishing { background: #1c2740; color: #a9bff0; border-color: #33497a; }
  .badge-polished { background: #12301d; color: #8fd0a2; border-color: #2a5b3a; }
}
.provenance { font-family: system-ui, sans-serif; font-size: 0.75rem; color: var(--muted); }

.math-display { overflow-x: auto; overflow-y: hidden; margin: 0.6rem 0; }
.part-picker { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0.2rem 0 0.6rem; font-family: system-ui, sans-serif; font-size: 0.8rem; }
.part-picker button { font: inherit; color: var(--fg); background: transparent; border: 1px solid var(--muted); border-radius: 999px; padding: 0.1rem 0.7rem; cursor: pointer; }
.part-picker button:hover { border-color: var(--accent); color: var(--accent); }
.part-picker button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.part-link { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.part-link:hover, .part-link:focus-visible { color: var(--accent); }
.tex-figure { margin: 0.8rem 0; text-align: center; }
.tex-figure img { max-width: 100%; height: auto; }
.katex-display { margin: 0.4rem 0; }
/* Inline math glued to touching punctuation (src/latex.ts): no break next to "(" or ".", breaks inside the formula. */
.math-nobr { white-space: nowrap; }
.math-nobr .katex-html { white-space: normal; }
.katex-tail { white-space: nowrap; }
.math-error, .ref-broken, .tex-unknown { color: var(--error); font-family: ui-monospace, Consolas, monospace; font-size: 0.85em; }
.math-error.display { display: block; white-space: pre-wrap; }
.item-label { font-weight: 600; margin-left: -0.2em; }
li.labeled { list-style: none; }
.footnote { font-size: 0.85em; color: var(--muted); }
.smallcaps { font-variant: small-caps; }
.center { text-align: center; }
blockquote { margin: 0.8rem 0; padding-left: 1rem; border-left: 3px solid var(--border); }

/* references and knowls */
a.ref { text-decoration: none; border-bottom: 1px dotted var(--accent); cursor: pointer; }
a.ref:hover, a.ref.knowl-open { background: var(--accent-soft); }
a.ref.knowl-open { border-bottom-style: solid; }
.knowl-box {
  margin: 0.5rem 0 0.8rem; padding: 0.2rem 0.8rem 0.5rem; background: var(--knowl-bg);
  border: 1px solid var(--knowl-border); border-left-width: 4px; border-radius: 4px; font-style: normal;
  animation: knowl-in 0.12s ease-out;
}
li > .knowl-box { margin-left: 0; }
.knowl-box .knowl-box { margin-left: 0.4rem; }
@media (max-width: 600px) {
  .knowl-box { padding: 0.2rem 0.5rem 0.4rem; border-left-width: 3px; }
  .knowl-box .knowl-box { margin-left: 0; }
}
.knowl-bar { display: flex; justify-content: flex-end; gap: 0.8rem; align-items: center; font-family: system-ui, sans-serif; font-size: 0.8rem; }
.knowl-close {
  border: none; background: none; color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 0 0.2rem;
}
.knowl-close:hover { color: var(--fg); }
.knowl-content .result { margin: 0; }
.knowl-loading, .knowl-error { font-family: system-ui, sans-serif; font-size: 0.85rem; color: var(--muted); }
.knowl-flash { animation: knowl-flash 0.8s ease-out; }
@keyframes knowl-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
@keyframes knowl-flash { 0% { box-shadow: 0 0 0 4px var(--knowl-border); } 100% { box-shadow: 0 0 0 0 transparent; } }

/* result page meta */
.result-meta { border-top: 1px solid var(--border); margin-top: 2rem; font-family: system-ui, sans-serif; font-size: 0.9rem; }
.deps { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 600px) { .deps { grid-template-columns: 1fr; } }
.dep-list { padding-left: 1.2rem; }
.prevnext { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem; font-family: system-ui, sans-serif; font-size: 0.9rem; }
.bibliography dt { font-weight: 600; }
.bibliography dd { margin: 0 0 0.8rem 1.5rem; }
