/* Set theory primer — web edition.
   Palette and type follow tomifrancis.com: Lato, teal #006580 links, near-black text. */

:root {
  --ink: #1a1a1a;
  --ink-soft: #555;
  --ink-faint: #767676;
  --teal: #006580;
  --teal-dark: #00485c;
  --rule: #e2e2e2;
  --rule-soft: #efefef;
  --bg: #fff;
  --bg-soft: #f7f9fa;
  --bg-peek: #fbfcfd;
  --accent-soft: #e8f2f5;
  --fig-bg: #fff;
  /* Widened from 40rem when the sidebar was trimmed by 25%: the space freed there
     belongs to the text, not to the margins. */
  --maxw: 46rem;
  /* The sidebar gutter is reserved permanently, whether the sidebar is showing or
     not, so that opening it never moves the text. 20.25rem = 27rem less 25%. */
  --peek-w: 20.25rem;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  /* Reserve the sidebar's column for good. Everything else lays out inside what is
     left, so the sidebar appearing changes nothing about the text's position. */
  padding-right: var(--peek-w);
  font-family: Lato, "Segoe UI", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.62;
  color: var(--ink);
  background: var(--bg);
}

.skip {
  position: absolute; left: -9999px;
}
.skip:focus {
  left: .5rem; top: .5rem; z-index: 50; background: #fff;
  padding: .5rem .75rem; border: 2px solid var(--teal);
}

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem;
  padding: .7rem 1.25rem;
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--rule);
  /* Bleed back across the reserved gutter so the header rule still spans the whole
     window, while the bar's contents stay inside the text column. */
  margin-right: calc(-1 * var(--peek-w));
  padding-right: calc(1.25rem + var(--peek-w));
}
.topbar .home {
  font-weight: 700; letter-spacing: .01em; color: var(--ink);
  text-decoration: none; font-size: .95rem;
}
.topbar .home:hover { color: var(--teal); }
.tocbtn {
  display: none;
  font: inherit; font-size: .85rem; cursor: pointer;
  background: none; border: 1px solid var(--rule); border-radius: 4px;
  padding: .25rem .6rem; color: var(--ink-soft);
}

/* ---------------------------------------------------------------- layout */
.shell {
  display: grid;
  grid-template-columns: 16.5rem minmax(0, 1fr);
  gap: 2.5rem;
  max-width: 70rem;
  margin: 0 auto;
  /* The bottom padding lives on `main`, NOT here. On .shell it sat outside the grid
     row, so the sticky contents ran out of containing block ~5rem before the end of
     the page and drifted upward at the very bottom of a scroll. */
  padding: 2rem 1.25rem 0;
}
main { padding-bottom: 5rem; }

.toc {
  /* Full-height grid item (no align-items:start) so `sticky` has somewhere to stick
     for the whole scroll, making the contents' position independent of the text's. */
  position: sticky; top: 4.2rem;
  max-height: calc(100vh - 5.4rem);
  overflow-y: auto; overscroll-behavior: contain;
  font-size: .82rem;
  line-height: 1.45;
  border-right: 1px solid var(--rule-soft);
  padding-right: 1rem;
}
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0 0 .28rem; }
.toc a {
  color: var(--ink-soft); text-decoration: none;
  display: block; padding: .12rem .35rem; border-radius: 3px;
  border-left: 2px solid transparent;
}
.toc a:hover { color: var(--teal); background: var(--bg-soft); }
.toc li.here > a {
  color: var(--teal); font-weight: 700;
  border-left-color: var(--teal); background: var(--accent-soft);
}

main { max-width: var(--maxw); min-width: 0; }

h1 {
  font-size: 1.75rem; line-height: 1.22; font-weight: 700;
  margin: 0 0 1.6rem; letter-spacing: -.01em;
}
h1 .secno {
  display: block; font-size: .78rem; letter-spacing: .13em;
  text-transform: uppercase; color: var(--ink-faint); font-weight: 700;
  margin-bottom: .3rem;
}
h2.subhead { font-size: 1.05rem; margin: 2rem 0 .6rem; }

p { margin: 0 0 1rem; }
main > ul { margin: 0 0 1rem; padding-left: 1.4rem; }
main > ul.marked { list-style: none; padding-left: .4rem; }
ul.marked .imark { display: inline-block; min-width: 1.7rem; color: var(--ink-soft); }
li { margin-bottom: .3rem; }

a { color: var(--teal); }
a:hover { color: var(--teal-dark); }

/* ---------------------------------------------------------------- maths */
.m { white-space: nowrap; }
.m i { font-family: Georgia, "Times New Roman", serif; font-style: italic; }
.m sub, .m sup { font-size: .72em; }
.upright { font-style: normal; font-family: inherit; white-space: normal; }
.displaymath {
  text-align: center; margin: 1.4rem 0; font-size: 1.05rem;
}
.frac { display: inline-block; vertical-align: middle; text-align: center; font-size: .9em; }
.frac .num { display: block; border-bottom: 1px solid currentColor; padding: 0 .2em; }
.frac .den { display: block; padding: 0 .2em; }

/* ---------------------------------------------------------------- blocks */
.block { margin: 1.5rem 0; }

.blockhead { margin: 0; }
/* Plain by default: only a figure's label is a control, because only proofs and
   figures collapse. Propositions, definitions and exercises never hide. */
.lbl { font-weight: 700; }
.fig .lbl {
  cursor: pointer; border-radius: 3px;
  padding: 0 .12rem; margin: 0 -.12rem;
  text-decoration: underline dotted rgba(0,101,128,.4);
  text-underline-offset: 3px;
}
.fig .lbl:hover { background: var(--accent-soft); color: var(--teal); }

.prop, .exercise {
  border-left: 3px solid var(--rule);
  padding: .1rem 0 .1rem 1rem;
}
.prop .stmt { font-style: italic; }
.exercise { border-left-color: #d8c9a8; }
.prop:target, .exercise:target, .def:target, .fig:target {
  background: #fffbe9; border-left-color: #d8b74a;
  box-shadow: 0 0 0 .55rem #fffbe9;
}

/* Definitions and axioms: same shape as a proposition, but upright rather than
   italic, and tinted so the formal statement reads as distinct from the chatty
   prose that introduces it. */
.defn {
  border-left: 3px solid #9ec6d2;
  background: var(--bg-soft);
  padding: .55rem .8rem .55rem 1rem;
  border-radius: 0 3px 3px 0;
}
.defn .stmt { font-style: normal; }
.defn:target { background: #fffbe9; border-left-color: #d8b74a; }

/* proofs ------------------------------------------------------- */
.proof { margin: .55rem 0 0; }
.prooftog {
  font: inherit; font-size: .78rem; letter-spacing: .06em; text-transform: uppercase;
  font-weight: 700; color: var(--teal);
  background: none; border: 0; cursor: pointer;
  padding: .2rem .45rem .2rem 0; display: inline-flex; align-items: center; gap: .4rem;
}
.prooftog:hover { color: var(--teal-dark); }
.caret {
  display: inline-block; width: 0; height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent; border-bottom: 4px solid transparent;
  transition: transform .15s ease;
}
.proof[data-open="1"] .caret { transform: rotate(90deg); }
.proofbody {
  margin: .35rem 0 0; padding: .1rem 0 .1rem .9rem;
  border-left: 2px solid var(--rule-soft);
  font-size: .95rem; color: #262626;
}
.proofbody p:last-child { margin-bottom: 0; }
.proof[data-open="0"] .proofbody { display: none; }

/* A figure folded into the proposition or definition it illustrates. */
.prop .fig, .defn .fig, .exercise .fig {
  margin: .7rem 0 .2rem;
  border-top: 1px dashed var(--rule);
  padding-top: .6rem;
}
.prop .fig figcaption, .defn .fig figcaption { font-size: .8rem; }
.defn .fig { border-top-color: #c6dde5; }

/* figures ------------------------------------------------------ */
.fig { margin: 1.8rem 0; text-align: center; }
.figbody {
  display: flex; gap: 1.5rem; justify-content: center; align-items: flex-start;
  cursor: pointer; padding: .4rem; border-radius: 4px;
}
.figbody:hover { background: var(--bg-soft); }
.fig[data-open="0"] .figbody { display: none; }
.pic { flex: 0 1 auto; max-width: 100%; }
.figsvg { width: 100%; max-width: 21rem; height: auto; color: var(--ink); }
.fig figcaption {
  font-size: .86rem; color: var(--ink-soft); margin-top: .5rem;
  max-width: 32rem; margin-left: auto; margin-right: auto;
}

/* ---------------------------------------------------------------- links */
.xref {
  text-decoration: none;
  border-bottom: 1px solid rgba(0,101,128,.35);
  cursor: pointer;
}
.xref:hover { background: var(--accent-soft); border-bottom-color: var(--teal); }
.xref.term {
  color: inherit;
  border-bottom: 1px dotted rgba(0,101,128,.55);
}
.xref.term:hover { color: var(--teal); background: var(--accent-soft); }
.badref { color: #b00; font-weight: 700; }

/* ---------------------------------------------------------------- footnotes */
.footnotes {
  margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--rule);
  font-size: .85rem; color: var(--ink-soft);
}
.footnotes ol { padding-left: 1.2rem; margin: 0; }
.fnref a { text-decoration: none; }
.fnback { text-decoration: none; margin-left: .25rem; }

/* ---------------------------------------------------------------- pager */
.pager {
  display: flex; justify-content: space-between; gap: 1rem;
  margin-top: 3.5rem; padding-top: 1.2rem; border-top: 1px solid var(--rule);
  font-size: .9rem;
}
.pager a { text-decoration: none; }
.pager a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- sidebar */
.peek {
  position: fixed; top: 0; right: 0; z-index: 40;
  width: var(--peek-w); height: 100vh;
  background: var(--bg-peek);
  border-left: 1px solid var(--rule);
  box-shadow: -8px 0 28px rgba(0,0,0,.07);
  display: flex; flex-direction: column;
  animation: slidein .16s ease;
}
@keyframes slidein { from { transform: translateX(12px); opacity: 0; } }
.peek[hidden] { display: none; }
/* Grid, not a flex row: proposition names are long ("a set and its complement
   exhaust the domain") and in a narrower sidebar a single row wrapped untidily.
   The title wraps freely with the close button pinned top-right, and the jump
   link sits underneath. */
.peekbar {
  display: grid; grid-template-columns: 1fr auto;
  gap: .2rem .6rem; align-items: start;
  padding: .7rem .9rem; border-bottom: 1px solid var(--rule);
  background: #fff;
}
.peektitle {
  grid-column: 1; grid-row: 1;
  font-weight: 700; font-size: .78rem; letter-spacing: .07em;
  text-transform: uppercase; color: var(--teal); line-height: 1.35;
}
.peekbar .peekclose { grid-column: 2; grid-row: 1; }
.peekbar .peekgo { grid-column: 1 / -1; grid-row: 2; justify-self: start; }
.peekgo { font-size: .8rem; text-decoration: none; white-space: nowrap; }
.peekgo:hover { text-decoration: underline; }
.peekclose {
  font: inherit; font-size: 1.4rem; line-height: 1; cursor: pointer;
  background: none; border: 0; color: var(--ink-faint); padding: 0 .2rem;
}
.peekclose:hover { color: var(--ink); }
.peekbody { padding: 1.1rem 1.2rem 2rem; overflow-y: auto; flex: 1; }
.peekbody .stmt { font-style: italic; }
.peekbody .figsvg { max-width: 100%; }
.peekbody .pic { margin: 0 auto; }
/* A side-by-side pair (the two distributivity figures) is unreadable at half the
   sidebar's width, so pairs stack here even though they sit side by side in the text. */
.peekbody .figbody { flex-wrap: wrap; gap: .5rem; }
.peekbody .fig { margin: 1rem 0 0; }
.peekbody figcaption { font-size: .8rem; color: var(--ink-soft); text-align: center; }
.peekhint {
  font-size: .78rem; color: var(--ink-faint); margin-top: 1.2rem;
  padding-top: .7rem; border-top: 1px dashed var(--rule);
}
/* Nothing reflows when the sidebar opens: its column is reserved by the padding on
   body, so `.peekopen` deliberately has no layout effect. (It used to shrink
   .shell's max-width, which moved the text every time you clicked a reference.) */

/* List of Exercises: the proposition to be proved is set apart from the
   instruction, so an entry can be read at a glance. Italic matches how
   propositions are set in the body. */
.exstmt, .exhint {
  display: block;
  margin: .3rem 0 .1rem;
  padding-left: 1.6rem;
  border-left: 2px solid var(--rule-soft);
}
.exstmt { font-style: italic; }
.exhint { font-size: .92rem; color: var(--ink-soft); }

/* A quiet note about the web version's clicking, on the landing page only. */
.usenote {
  margin: 1.8rem 0 0;
  padding: .75rem 1rem;
  background: var(--bg-soft);
  border-left: 3px solid #9ec6d2;
  border-radius: 0 3px 3px 0;
  font-size: .93rem;
}
.usenote p { margin: 0; }

/* ---------------------------------------------------------------- contents page */
.contents-list { list-style: none; padding: 0; margin: 1.5rem 0 0; }
.contents-list li { margin: 0 0 .1rem; }
.contents-list a {
  display: flex; gap: .8rem; align-items: baseline;
  padding: .5rem .6rem; border-radius: 4px; text-decoration: none;
  border-bottom: 1px solid var(--rule-soft);
}
.contents-list a:hover { background: var(--bg-soft); }
.contents-list .n {
  font-variant-numeric: tabular-nums; color: var(--ink-faint);
  font-size: .8rem; min-width: 1.4rem;
}

/* ---------------------------------------------------------------- responsive */
@media (max-width: 62rem) {
  /* Too narrow to hold a reserved gutter: give the space back and let the sidebar
     overlay the page instead. */
  body { padding-right: 0; }
  .topbar { margin-right: 0; padding-right: 1.25rem; }
  .peek { width: 100%; }
  .shell { grid-template-columns: 1fr; gap: 0; padding-top: 1.2rem; }
  .tocbtn { display: inline-flex; }

  /* Contents becomes a drawer that slides OVER the text from the left, opened by
     the tab in the top-left. Tomi, 18 Aug: the central text should be the only
     thing normally shown, and opening the contents must not navigate away or take
     focus off the page. */
  .toc {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 45;
    width: min(19rem, 84vw);
    max-height: none; margin: 0;
    padding: 4.2rem 1rem 2rem;
    background: var(--bg);
    border-right: 1px solid var(--rule);
    box-shadow: 6px 0 24px rgba(0,0,0,.10);
    overflow-y: auto; overscroll-behavior: contain;
    font-size: .9rem;
    /* Driven by a class, NOT the `hidden` attribute. Overriding `[hidden]`'s
       display and then removing the attribute left the drawer stuck at its
       translated-away position; a plain class has no UA behaviour to fight. */
    transform: translateX(-102%);
    visibility: hidden;
    transition: transform .18s ease, visibility .18s ease;
  }
  .toc.open { transform: translateX(0); visibility: visible; }
  .toc a { padding: .45rem .4rem; }
  .tocveil {
    position: fixed; inset: 0; z-index: 44;
    background: rgba(0,0,0,.35);
    border: 0; padding: 0; margin: 0;
  }
  .tocveil[hidden] { display: none; }
}

/* ---------------------------------------------------------------- phones
   Tomi, 17 August 2026: "I want my students to be able to browse it by phone."
   The sidebar becomes a full-screen sheet; there is no reserved gutter to keep,
   so nothing is lost by the reflow that desktop deliberately avoids. */
@media (max-width: 34rem) {
  body { font-size: 16px; }
  .shell { padding: 1rem .9rem 3.5rem; }
  .topbar { padding: .6rem .9rem; }
  h1 { font-size: 1.4rem; }
  .prop, .exercise, .defn { padding-left: .7rem; }
  .defn { padding-right: .6rem; }
  /* Side-by-side figure pairs must stack rather than shrink to illegibility. */
  .figbody { flex-wrap: wrap; gap: .6rem; }
  .figsvg { max-width: 100%; }
  .proofbody { padding-left: .6rem; }
  .peek { box-shadow: none; border-left: 0; }
  .peekbody { padding: 1rem .9rem 3rem; }
  /* Stop the page scrolling underneath the sheet or the drawer. */
  body.peekopen, body.tocopen { overflow: hidden; }
  /* Stacked, so `justify-content: space-between` now works on the VERTICAL axis
     and does nothing horizontally — both links stretched full width and read as
     left-aligned. The next link is pushed right explicitly. */
  .pager { flex-direction: column; gap: .5rem; align-items: stretch; }
  .pager .next { align-self: flex-end; text-align: right; }
  main { padding-bottom: 3rem; }

  /* On a phone the sidebar is a sheet, so its two actions need to look and behave
     like buttons rather than a quiet link. */
  .peekbar { padding: .8rem .9rem; gap: .5rem .6rem; }
  .peekbar .peekgo {
    display: inline-block; margin-top: .25rem;
    padding: .45rem .8rem; border-radius: 5px;
    background: var(--teal); color: #fff; font-weight: 700;
    text-decoration: none; font-size: .82rem;
  }
  .peekbar .peekgo:hover, .peekbar .peekgo:active { background: var(--teal-dark); color: #fff; }
  .peekclose {
    font-size: 1.7rem; line-height: 1; padding: .1rem .5rem;
    border: 1px solid var(--rule); border-radius: 5px; color: var(--ink);
  }
}

/* Taps must not be treated as double-tap-to-zoom, or every reference would zoom
   the page instead of opening the sidebar. */
a, button, .lbl, .figbody, [data-toggle] { touch-action: manipulation; }

/* Give touch targets a usable height without changing how they look. */
@media (pointer: coarse) {
  .lbl, .prooftog, .xref { padding-top: .15rem; padding-bottom: .15rem; }
  .peekclose { font-size: 1.8rem; padding: 0 .45rem; }
}
@media print {
  .toc, .peek, .pager, .topbar, .tocbtn { display: none !important; }
  .proof[data-open="0"] .proofbody, .fig[data-open="0"] .figbody { display: block !important; }
}
