:root {
  --paper: #fbf8f2;
  --paper-raised: #ffffff;
  --ink: #1d1c1a;
  --ink-soft: #565248;
  --rule: #e2dbcd;
  --accent: #8a5a2b;
  --accent-soft: #f2e9db;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --measure: 44rem;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 1rem; top: 1rem; background: var(--paper-raised); padding: .5rem .75rem; z-index: 50; }

a { color: var(--accent); text-decoration-color: var(--rule); text-underline-offset: 2px; }
a:hover { text-decoration-color: currentColor; }

/* ---------------------------------------------------------------- structure */

.shell { display: flex; align-items: flex-start; }

.topbar {
  display: none;
  position: sticky; top: 0; z-index: 20;
  align-items: center; gap: .75rem;
  padding: .6rem 1rem;
  background: rgba(251, 248, 242, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.brand { font-family: var(--sans); font-size: .9rem; font-weight: 600; color: var(--ink); text-decoration: none; }
.menu-toggle {
  font-family: var(--sans); font-size: .8rem; letter-spacing: .04em; text-transform: uppercase;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid var(--rule); border-radius: 999px; padding: .35rem .8rem; cursor: pointer;
}

.sidebar {
  position: sticky; top: 0;
  flex: 0 0 20rem; max-width: 20rem;
  height: 100vh; overflow-y: auto;
  padding: 2.75rem 1.5rem 3rem 2rem;
  border-right: 1px solid var(--rule);
}
.side-brand {
  display: block; font-size: 1.15rem; line-height: 1.35; font-weight: 600;
  color: var(--ink); text-decoration: none; margin-bottom: 2rem;
}
.side-label {
  font-family: var(--sans); font-size: .68rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-soft); margin: 0 0 .75rem;
}
.nav { list-style: none; margin: 0; padding: 0; }
.nav li + li { margin-top: .15rem; }
.nav-link {
  display: flex; gap: .6rem; align-items: baseline;
  padding: .4rem .55rem; border-radius: .4rem;
  font-size: .95rem; line-height: 1.4; color: var(--ink-soft); text-decoration: none;
}
.nav-link:hover { background: var(--accent-soft); color: var(--ink); }
.nav-link.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }


.content { flex: 1 1 auto; min-width: 0; padding: 3.5rem 3rem 6rem; }
.prose { max-width: var(--measure); margin: 0 auto; }

/* -------------------------------------------------------------------- prose */

.prose h1 {
  font-size: clamp(2rem, 4vw, 2.8rem);
  line-height: 1.15; letter-spacing: -.01em;
  margin: 0 0 2rem;
}
.prose h1::after {
  content: ""; display: block; width: 3.5rem; height: 2px;
  background: var(--accent); margin-top: 1.25rem; opacity: .6;
}
.prose h2 { font-size: 1.6rem; line-height: 1.25; margin: 3rem 0 1rem; padding-top: .5rem; border-top: 1px solid var(--rule); }
.prose h3 { font-size: 1.25rem; margin: 2.25rem 0 .75rem; }
.prose h4, .prose h5, .prose h6 { font-size: 1.05rem; margin: 1.75rem 0 .5rem; }
.prose p { margin: 0 0 1.15rem; }
.prose strong { font-weight: 700; }
.prose em { font-style: italic; }
.prose ul, .prose ol { margin: 0 0 1.15rem; padding-left: 1.4rem; }
.prose li { margin: .3rem 0; }
.prose li > ul, .prose li > ol { margin-top: .35rem; }
.prose hr { border: none; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

.prose blockquote {
  margin: 1.5rem 0; padding: .25rem 0 .25rem 1.25rem;
  border-left: 3px solid var(--accent); color: var(--ink-soft); font-style: italic;
}

.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .9em; background: var(--accent-soft); padding: .1em .35em; border-radius: .25rem;
}
.prose pre {
  background: #201e1b; color: #f3ece1; padding: 1rem 1.15rem; border-radius: .5rem;
  overflow-x: auto; font-size: .9rem; line-height: 1.55;
}
.prose pre code { background: none; padding: 0; color: inherit; }

.prose img {
  display: block; max-width: 100%; height: auto;
  margin: 1.75rem auto; border: 1px solid var(--rule); border-radius: .5rem; background: var(--paper-raised);
}

.prose table { width: 100%; border-collapse: collapse; margin: 1.5rem 0; font-size: .95rem; }
.prose th, .prose td { border: 1px solid var(--rule); padding: .5rem .7rem; text-align: left; }
.prose th { background: var(--accent-soft); font-family: var(--sans); font-size: .82rem; letter-spacing: .03em; }

.prose table.proof-table tbody tr.proof-assumption { background-color: #fce4e4; }
.prose table.proof-table tbody tr.proof-conclusion { background-color: #e4f4e4; }

.proof-block {
  margin: 1.5rem 0;
}

.proof-block > table.proof-table {
  margin: 0;
}

.proof-subproof {
  margin: 0 1rem 0;
  padding: 0 .7rem .7rem;
  border: 1px solid var(--rule);
  border-top: none;
  border-radius: 0 0 .35rem .35rem;
  background: var(--paper-raised);
}

.proof-subproof-label {
  padding: .45rem .2rem .35rem;
  font-family: var(--sans);
  font-size: .68rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.proof-subproof > table.proof-table {
  margin: 0;
}

/* ---------------------------------------------------------------- math, toc */

.katex { font-size: 1.04em; }
.katex-display {
  margin: 1.5rem 0; padding: .25rem 0;
  overflow-x: auto; overflow-y: hidden;
}

.toc {
  background: var(--paper-raised);
  border: 1px solid var(--rule); border-radius: .6rem;
  padding: 1.1rem 1.35rem; margin: 0 0 2.5rem;
}
.toc-title {
  font-family: var(--sans); font-size: .68rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-soft); margin: 0 0 .6rem;
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: .2rem 0; font-size: .95rem; }
.toc li.toc-h3 { padding-left: 1rem; }
.toc a { color: var(--ink-soft); text-decoration: none; }
.toc a:hover { color: var(--accent); }

/* ------------------------------------------------------------------- pager */

.pager {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
  margin-top: 4rem; padding-top: 1.5rem; border-top: 1px solid var(--rule);
}
.pager-link {
  display: block; padding: .9rem 1.1rem; border: 1px solid var(--rule); border-radius: .6rem;
  background: var(--paper-raised); color: var(--ink); text-decoration: none; font-size: .98rem; line-height: 1.35;
}
.pager-link:hover { border-color: var(--accent); }
.pager-link span {
  display: block; font-family: var(--sans); font-size: .68rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-soft); margin-bottom: .3rem;
}
.pager-next { text-align: right; }

/* ------------------------------------------------------------------ mobile */

@media (max-width: 60rem) {
  .topbar { display: flex; }
  .shell { display: block; }
  .sidebar {
    display: none; position: static; height: auto; max-width: none; width: 100%;
    border-right: none; border-bottom: 1px solid var(--rule); padding: 1.5rem 1.25rem;
  }
  .side-brand { display: none; }
  body.nav-open .sidebar { display: block; }
  .content { padding: 2rem 1.25rem 4rem; }
}

/* ---------------------------------------------------------------- callouts */

.callout {
  margin: 1.75rem 0;
  padding: 1rem 1.25rem .3rem;
  border: 1px solid var(--callout-line, var(--rule));
  border-left: 4px solid var(--callout-line, var(--accent));
  border-radius: .5rem;
  background: var(--callout-bg, var(--paper-raised));
}
.callout-label {
  font-family: var(--sans);
  font-size: .68rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--callout-line, var(--accent));
  margin: 0 0 .6rem;
}
.callout-body > *:last-child { margin-bottom: .9rem; }
.callout .katex-display { margin: 1rem 0; }

.callout-definition { --callout-bg: #eef3fa; --callout-line: #35618e; }
.callout-theorem    { --callout-bg: #f4eefa; --callout-line: #6b4a9c; }
.callout-proof      { --callout-bg: #edf5ef; --callout-line: #3d6b4a; }
.callout-exercise   { --callout-bg: #fdf3e6; --callout-line: #a8621b; }
.callout-note       { --callout-bg: #f5f2ea; --callout-line: #6b6455; }
.callout-solution   { --callout-bg: #edf5ef; --callout-line: #3d6b4a; }

/* collapsible callouts (Obsidian `[!note]-` blocks) */
.callout-fold { padding: .55rem 1.25rem .1rem; }
.callout-fold > .callout-label {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  cursor: pointer; list-style: none;
  font-family: var(--serif, inherit);
  font-size: 1rem; letter-spacing: 0; text-transform: none;
  font-weight: 600;
  color: var(--callout-line, var(--accent));
  margin: .35rem 0;
}
.callout-fold > .callout-label::-webkit-details-marker { display: none; }
.callout-chevron {
  flex: 0 0 auto; width: .5rem; height: .5rem;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg); transition: transform .18s ease;
}
.callout-fold[open] > .callout-label .callout-chevron { transform: rotate(-135deg); }
.callout-fold > .callout-body { padding-left: 1rem; }
.callout-fold > .callout-body > *:first-child { margin-top: .4rem; }

/* ------------------------------------------------------------ margin notes */
/* note callouts sit in the right-hand margin on wide screens */

@media (min-width: 76rem) {
  .prose {
    max-width: calc(var(--measure) + var(--note-w) + var(--note-gap));
    padding-right: calc(var(--note-w) + var(--note-gap));
    --note-w: 15rem;
    --note-gap: 2.25rem;
  }
  .callout-note {
    float: right;
    clear: right;
    width: var(--note-w);
    margin-right: calc(-1 * (var(--note-w) + var(--note-gap)));
    margin-top: .35rem;
    margin-bottom: 1.4rem;
    font-size: .92rem;
    line-height: 1.55;
  }
  .callout-note .katex { font-size: .98em; }
  .callout-note .katex-display { margin: .7rem 0; }
  .prose > .section:last-of-type,
  .section-body { overflow: visible; }
}



/* ---------------------------------------------------- collapsible sections */

.section {
  border-top: 1px solid var(--rule);
  margin: 0;
}
.section + .section { margin-top: 0; }
.section-summary {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  cursor: pointer; list-style: none;
  padding: .35rem 0;
}
.section-summary::-webkit-details-marker { display: none; }
.section-summary:hover h2 { color: var(--accent); }
.section-summary h2 {
  border-top: none; padding-top: 0; margin: 1.4rem 0 1.1rem;
  flex: 1 1 auto;
}
.section-chevron {
  flex: 0 0 auto; width: .6rem; height: .6rem;
  border-right: 2px solid var(--accent); border-bottom: 2px solid var(--accent);
  transform: rotate(45deg); transition: transform .18s ease;
  margin-right: .25rem;
}
.section[open] > .section-summary .section-chevron { transform: rotate(-135deg); }
.section-body {
  padding-bottom: 1.5rem;
  padding-left: 1.5rem;
}
.section-body > *:first-child { margin-top: 0; }
