/* Responsive webbook styles. */
:root {
  color-scheme: light dark;
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-alt: #f2f0e9;
  --text: #22211f;
  --muted: #67635c;
  --border: #d8d3c8;
  --accent: #315d86;
  --accent-strong: #18496f;
  --definition: #315d86;
  --exercise: #79611d;
  --result: #664582;
  --focus: #b14c00;
  --serif: Charter, "Bitstream Charter", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171817;
    --surface: #202220;
    --surface-alt: #292b28;
    --text: #eceae4;
    --muted: #b7b3aa;
    --border: #444741;
    --accent: #8db9dc;
    --accent-strong: #b4d4ec;
    --definition: #8db9dc;
    --exercise: #d6bd6f;
    --result: #c7a3e5;
    --focus: #ffad66;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.08rem;
  line-height: 1.68;
}
a { color: var(--accent-strong); text-underline-offset: .16em; }
a:hover { text-decoration-thickness: .12em; }
a:focus-visible,
summary:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex="0"]:focus-visible {
  outline: .18rem solid var(--focus);
  outline-offset: .18rem;
}
img, svg { max-width: 100%; }
code { font-family: var(--mono); }

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: .5rem;
  left: .5rem;
  padding: .55rem .8rem;
  transform: translateY(-180%);
  background: var(--surface);
  border: 2px solid var(--focus);
  font-family: var(--sans);
}
.skip-link:focus { transform: translateY(0); }

.book-layout {
  display: grid;
  grid-template-columns: 17rem minmax(0, 48rem) minmax(0, 1fr);
  gap: 2rem;
  max-width: 90rem;
  min-height: calc(100vh - 5rem);
  margin: 0 auto;
  padding: 0 1.5rem;
}
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  padding: 1.5rem 0 3rem;
  border-right: 1px solid var(--border);
}
.main-content { min-width: 0; padding: 3rem 0 5rem; }
.mobile-header { display: none; }

.book-nav { padding-right: 1.25rem; font-family: var(--sans); font-size: .84rem; line-height: 1.35; }
.book-nav__title { display: block; margin-bottom: 1.2rem; color: var(--text); font-family: var(--serif); font-size: 1.12rem; font-weight: 700; text-decoration: none; }
.book-nav ul { margin: .45rem 0 .9rem; padding: 0; list-style: none; }
.book-nav li { margin: .38rem 0; }
.book-nav a { display: block; color: var(--text); text-decoration: none; }
.book-nav a:hover, .book-nav a[aria-current="page"] { color: var(--accent-strong); }
.book-nav a[aria-current="page"] { font-weight: 700; }
.book-nav details { margin: .7rem 0; }
.book-nav summary { cursor: pointer; font-weight: 700; }
.book-nav details > ul { padding-left: 1rem; }
.book-nav__overview { font-style: italic; }
.chapter-number, .section-number { color: var(--muted); font-variant-numeric: tabular-nums; }
.pending { color: var(--muted); }

.prose { max-width: 48rem; }
.prose p { margin: 1em 0; }
.prose h1, .prose h2, .prose h3 { line-height: 1.2; }
.prose h2 { margin-top: 2.5rem; }
.page-header { margin-bottom: 2.5rem; padding-bottom: .9rem; border-bottom: 1px solid var(--border); }
.page-header h1 { max-width: 24ch; margin: .25rem 0 0; font-size: clamp(2rem, 4vw, 2.7rem); font-weight: 600; line-height: 1.12; letter-spacing: -.012em; text-wrap: balance; }
.eyebrow { margin: 0; color: var(--muted); font-family: var(--serif); font-size: .88rem; font-variant-caps: small-caps; font-weight: 600; letter-spacing: .035em; }
dfn { font-style: normal; font-weight: 700; }
.custom-list ol, .custom-list--labeled { padding: 0; list-style: none; counter-reset: none; }
.custom-list li { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: .6rem; margin: .45rem 0; }
.list-content > :first-child { margin-top: 0; }
.list-content > :last-child { margin-bottom: 0; }
.list-marker { font-family: var(--sans); font-size: .88em; font-weight: 650; font-variant-numeric: tabular-nums; }

.statement {
  position: relative;
  margin: 1.9rem 0;
  padding: .85rem 1rem .25rem;
  border: 1px solid var(--border);
  border-left: .16rem solid color-mix(in srgb, var(--definition) 55%, var(--border));
  border-radius: .16rem;
  background: color-mix(in srgb, var(--surface) 97%, var(--bg));
  scroll-margin-top: 1rem;
}
.statement--theorem,
.statement--lemma,
.statement--proposition,
.statement--corollary { border-left-color: color-mix(in srgb, var(--result) 55%, var(--border)); }
.statement--exercise { border-left-color: color-mix(in srgb, var(--exercise) 55%, var(--border)); background: color-mix(in srgb, var(--surface) 96%, var(--exercise)); }
.statement__header { display: flex; flex-wrap: wrap; gap: .15rem .35rem; align-items: baseline; font-family: var(--serif); font-size: 1rem; font-weight: 700; line-height: 1.4; }
.statement__number { font-variant-numeric: tabular-nums; }
.statement__title { font-style: italic; font-weight: 400; }
.statement__body > :first-child { margin-top: .45rem; }
.statement__body > :last-child { margin-bottom: .55rem; }
.statement__slogan, .standalone-slogan {
  margin: .65rem 0;
  color: var(--muted);
  font-family: var(--sans);
  font-size: .8rem;
  font-style: normal;
  line-height: 1.4;
}
.permalink { margin-left: auto; color: var(--muted); font-weight: 500; text-decoration: none; opacity: 0; }
.statement:hover .permalink, .permalink:focus-visible { color: var(--accent-strong); opacity: 1; }
.legacy-anchor, .index-anchor { position: relative; top: -1rem; }

.proof { margin: 1.5rem 0 2rem; padding-left: 1.1rem; border-left: 1px solid var(--border); }
.proof__title { float: left; margin-right: .35rem; font-style: italic; font-weight: 700; }
.proof__body > :first-child { margin-top: 0; }
.proof__body > :last-child::after { content: " □"; float: right; }
.goal { margin: 1.5rem 0; padding: 1rem; border: 1px solid var(--border); background: var(--surface-alt); }
.goal__title { font-family: var(--sans); font-weight: 700; }
.footnote-reference { font-family: var(--sans); font-size: .72em; line-height: 0; vertical-align: super; }
.footnotes { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--border); font-size: .88rem; }
.footnotes ol { padding-left: 1.4rem; }
.footnotes li { margin: .65rem 0; }
.footnote-backref { font-family: var(--sans); text-decoration: none; }
.signature { margin: 2rem 0; text-align: right; }

.thematic-break { width: 55%; margin: 3.2rem auto; border: 0; border-top: 1px solid var(--border); overflow: visible; text-align: center; }
.thematic-break::after { content: "◇"; position: relative; top: -.88rem; padding: 0 .65rem; background: var(--bg); color: var(--muted); }

.math-overflow { max-width: 100%; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
mjx-container[display="true"] { max-width: 100%; margin: 1.25rem 0 !important; padding: .2rem; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.diagram { margin: 1.4rem auto; text-align: center; }
.diagram img { display: block; width: min(100%, var(--diagram-width)); height: auto; margin: .5rem auto; }
.diagram figcaption { margin-top: .65rem; color: var(--muted); font-size: .9rem; }
.diagram figcaption span { font-family: var(--sans); font-size: .82rem; font-weight: 700; }
@media (prefers-color-scheme: dark) { .diagram img { filter: invert(.88) hue-rotate(180deg); } }

.page-navigation { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 4rem; padding-top: 1.2rem; border-top: 1px solid var(--border); font-family: var(--sans); font-size: .76rem; text-transform: uppercase; }
.page-navigation a { text-decoration: none; }
.page-navigation a span { display: block; font-family: var(--serif); font-size: 1rem; text-transform: none; }
.page-navigation__next { text-align: right; }
.chapter-sections ol { padding-left: 0; list-style: none; }
.chapter-sections li { margin: .7rem 0; }
.chapter-sections li span:first-child { display: inline-block; width: 3rem; color: var(--muted); font-family: var(--sans); font-size: .85rem; }

.home { max-width: 46rem; }
.home__masthead { margin-top: .4rem; padding: 2.6rem 0 2.15rem; border: 0; }
.home__masthead h1 { max-width: 19ch; margin: 0; font-size: clamp(2.5rem, 6vw, 4rem); font-weight: 600; line-height: 1.08; letter-spacing: -.018em; text-wrap: balance; }
.home__author { margin: .9rem 0 0; font-size: 1.12rem; }
.home__metadata { display: flex; flex-wrap: wrap; gap: .2rem .7rem; margin-top: 1.6rem; color: var(--muted); font-family: var(--sans); font-size: .74rem; letter-spacing: .035em; text-transform: uppercase; }
.home__metadata span + span::before { content: "·"; margin-right: .7rem; }
.home__actions { display: flex; flex-wrap: wrap; gap: 1.5rem; margin-top: 1rem; font-family: var(--sans); font-size: .84rem; }
.home__actions a { font-weight: 600; text-decoration-thickness: 1px; text-underline-offset: .25em; }
.home__section { margin-top: 3.6rem; }
.home__section > h2 { margin: 0 0 1.2rem; padding-bottom: .5rem; border-bottom: 1px solid var(--border); font-size: 1.3rem; font-weight: 600; line-height: 1.3; }
.home__about .prose > :first-child { margin-top: 0; }
.home__about .prose > :last-child { margin-bottom: 0; }
.contents__chapters { margin: 0; padding: 0; border-bottom: 1px solid var(--border); list-style: none; }
.contents__chapters > li { margin: 0; padding: .95rem 0 1rem; border-top: 1px solid var(--border); }
.contents__chapters ol { margin: .45rem 0 0; padding: 0; list-style: none; }
.contents__chapters ol > li,
.contents__chapter { display: grid; grid-template-columns: 3.4rem minmax(0, 1fr); column-gap: .35rem; align-items: baseline; }
.contents__chapters ol > li { margin: .24rem 0; font-size: .93rem; line-height: 1.45; }
.contents__chapter { font-size: 1.04rem; font-weight: 600; line-height: 1.4; }
.contents__number { color: var(--muted); font-family: var(--sans); font-size: .76rem; font-variant-numeric: tabular-nums; font-weight: 500; }
.contents a { color: var(--text); text-decoration: none; }
.contents a:hover { color: var(--accent-strong); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .2em; }
.contents__matter { padding-top: .8rem !important; padding-bottom: .8rem !important; }

.index-jump { display: flex; flex-wrap: wrap; gap: .5rem; margin: 2rem 0; font-family: var(--sans); }
.index-letter { scroll-margin-top: 4rem; }
.index-letter > h2 { margin-bottom: 0; padding-bottom: .35rem; border-bottom: 1px solid var(--border); font-family: var(--sans); font-size: 1rem; }
.index-list { columns: 2 20rem; column-gap: 2.5rem; column-rule: 1px solid var(--border); margin-top: 0; }
.index-entry { display: inline-block; width: 100%; break-inside: avoid; }
.index-entry > dt { margin-top: 1.5rem; font-size: 1.25rem; font-weight: 700; }
.index-list dd { margin-left: 1.5rem; }
.index-list dl dt { font-style: italic; }
.index-list ul { margin: .2rem 0 .8rem; padding-left: 1.2rem; }
.search-form label { display: block; margin-bottom: .5rem; font-weight: 700; }
.search-form div { display: flex; gap: .5rem; }
.search-form input { flex: 1; min-width: 0; padding: .7rem; border: 1px solid var(--border); border-radius: .2rem; background: var(--surface); color: var(--text); font: inherit; }
.search-form button { padding: .7rem 1rem; border: 0; border-radius: .2rem; background: var(--accent-strong); color: var(--bg); font-family: var(--sans); font-weight: 700; }
.search-results li { margin: .7rem 0; }

.site-footer { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem 1.5rem; padding: 1.5rem; border-top: 1px solid var(--border); color: var(--muted); font-family: var(--sans); font-size: .76rem; }
.site-footer a { color: inherit; }

@media (min-width: 82rem) {
  .statement__slogan { position: absolute; left: calc(100% + 1.4rem); top: .3rem; width: 10rem; margin: 0; }
  .standalone-slogan { float: right; width: 10rem; margin: .2rem -12rem .5rem 1rem; }
}

@media (max-width: 71.99rem) {
  .mobile-header { display: flex; position: sticky; z-index: 20; top: 0; align-items: center; justify-content: space-between; gap: 1rem; padding: .65rem 1rem; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(.5rem); font-family: var(--sans); font-size: .88rem; }
  .mobile-header > a { color: var(--text); font-family: var(--serif); font-weight: 700; text-decoration: none; }
  .mobile-nav { position: relative; }
  .mobile-nav > summary { cursor: pointer; font-weight: 700; }
  .mobile-nav__panel { position: absolute; right: 0; width: min(23rem, calc(100vw - 2rem)); max-height: calc(100vh - 4rem); padding: 1rem; overflow-y: auto; border: 1px solid var(--border); border-radius: .25rem; background: var(--surface); box-shadow: 0 .6rem 2rem rgb(0 0 0 / .18); }
  .book-layout { display: block; max-width: 51rem; padding: 0 1.25rem; }
  .sidebar { display: none; }
  .main-content { padding-top: 2.2rem; overflow-x: clip; }
}

@media (max-width: 35rem) {
  body { font-size: 1rem; }
  .book-layout { padding: 0 .9rem; }
  .page-navigation { grid-template-columns: 1fr; }
  .page-navigation__next { text-align: left; }
  .home__masthead { padding-top: 1.8rem; }
}

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

@media print {
  :root { color-scheme: light; --bg: #fff; --surface: #fff; --surface-alt: #fff; --text: #000; --muted: #333; --border: #999; --accent-strong: #000; }
  body { font-size: 11pt; }
  .mobile-header, .sidebar, .page-navigation, .site-footer, .permalink, .home__actions { display: none !important; }
  .book-layout { display: block; max-width: none; padding: 0; }
  .main-content, .prose { max-width: none; padding: 0; }
  .statement, .proof, .diagram { break-inside: avoid; }
  .statement__slogan, .standalone-slogan { position: static; float: none; width: auto; margin: .4rem 0; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-family: var(--sans); font-size: 8pt; font-weight: normal; overflow-wrap: anywhere; }
  mjx-container, .math-overflow { overflow: visible !important; }
  .diagram img { filter: none; }
}
