/* Stylesheet for the HTML edition of LAMV. */

/* Libertinus fonts (SIL Open Font License), vendored in html/fonts/ as woff2. */
@font-face {
  font-family: "Libertinus Math";
  src: url("fonts/LibertinusMath-Regular.woff2") format("woff2");
  /* Wait (briefly) for the real font rather than laying out math with a fallback:
     Firefox doesn't always redo MathML layout when a swapped-in font arrives. */
  font-display: block;
}
@font-face {
  font-family: "Libertinus Serif";
  src: url("fonts/LibertinusSerif-Regular.woff2") format("woff2");
}
@font-face {
  font-family: "Libertinus Serif";
  font-style: italic;
  src: url("fonts/LibertinusSerif-Italic.woff2") format("woff2");
}
@font-face {
  font-family: "Libertinus Serif";
  font-weight: bold;
  src: url("fonts/LibertinusSerif-Bold.woff2") format("woff2");
}
@font-face {
  font-family: "Libertinus Serif";
  font-weight: bold;
  font-style: italic;
  src: url("fonts/LibertinusSerif-BoldItalic.woff2") format("woff2");
}

:root {
  --text: #1a1a1a;
  --muted: #666;
  --link: #0645ad;
  --internal: #c00;
  --headers: maroon;
  --partfill: #002299;
  --title: #0073a8;
  --sidebar-w: 19rem;
  --rule: #ddd;
}

html {
  font-size: 18px;
}
body {
  margin: 0;
  color: var(--text);
  font-family:
    "Libertinus Serif", "Linux Libertine", "STIX Two Text", Georgia, serif;
  line-height: 1.5;
}
math {
  font-family: "Libertinus Math", "STIX Two Math", "Cambria Math", math;
}
math[display="block"] {
  margin: 0.8em 0;
  overflow-x: auto;
  overflow-y: hidden;
}

/* ---------- layout ---------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  padding: 1rem 1.2rem 3rem;
  box-sizing: border-box;
  background: #f7f7f9;
  border-right: 1px solid var(--rule);
  font-family: "Noto Sans", "Libertinus Sans", system-ui, sans-serif;
  font-size: 0.75rem;
  line-height: 1.35;
}
.sidebar-title {
  text-align: left;
}
.sidebar-title a {
  font-weight: bold;
  font-size: 1rem;
  color: var(--title);
}
.sidebar ol {
  padding-left: 0;
}
.sidebar li {
  margin: 0.25em 0;
}
/* Part entries are the unnumbered ones. (Matching on href doesn't work: on the
   current page Typst links to "#loc-1" rather than "part-x.html#loc-1".) */
.sidebar li:not(:has(> a > .prefix)) {
  margin-top: 1em;
  font-weight: bold;
}
/* Typst places footnotes in a section after <main>, so lay it out the same way. */
main,
body > section[role="doc-endnotes"] {
  margin-left: var(--sidebar-w);
  padding: 1rem 2.5rem 4rem;
  max-width: 46rem;
}
main:has(+ section[role="doc-endnotes"]) {
  padding-bottom: 0;
}
section[role="doc-endnotes"] {
  border-top: 1px solid var(--rule);
  font-size: 0.9em;
}
section[role="doc-endnotes"] ol {
  padding-left: 0;
}
section[role="doc-endnotes"] li {
  margin: 0.4em 0;
}
.toc-toggle,
.toc-button {
  display: none;
}

@media (max-width: 900px) {
  .sidebar {
    display: none;
    z-index: 10;
    width: min(85vw, var(--sidebar-w));
    box-shadow: 0 0 2rem rgb(0 0 0 / 0.3);
  }
  .toc-toggle:checked ~ .sidebar {
    display: block;
  }
  .toc-button {
    display: block;
    position: sticky;
    top: 0;
    z-index: 11;
    padding: 0.4rem 1rem;
    background: #f7f7f9;
    border-bottom: 1px solid var(--rule);
    font-family: system-ui, sans-serif;
    font-size: 0.85rem;
    cursor: pointer;
  }
  main,
  body > section[role="doc-endnotes"] {
    margin-left: 0;
    padding: 0.5rem 1rem 3rem;
  }
}

/* ---------- prev/next ---------- */
.pagenav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin: 1rem 0;
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
}
.pagenav .next {
  margin-left: auto;
  text-align: right;
}

/* ---------- text ---------- */
a {
  color: var(--link);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
main a[href*="#"] {
  color: var(--internal);
}
strong {
  font-family: "Noto Sans", "Libertinus Sans", system-ui, sans-serif;
  font-size: 0.9em;
  color: #000055;
}
p {
  text-align: justify;
  hyphens: auto;
}
h2,
h3,
h4,
h5,
h6 {
  font-family: "Noto Sans", "Libertinus Sans", system-ui, sans-serif;
  line-height: 1.25;
  scroll-margin-top: 2.5rem;
}
h2 {
  font-size: 1.5rem;
  margin-top: 1.5em;
}
h3 {
  font-size: 1.2rem;
  margin-top: 1.6em;
}
h4 {
  font-size: 1.05rem;
}
h2.part {
  color: var(--partfill);
  font-size: 2rem;
  margin-top: 2rem;
}
img,
svg {
  max-width: 100%;
  height: auto;
}
/* Figures: Typst wraps the image in a <p>, and the caption is a plain <div>. */
figure {
  margin: 1.5em 0;
  text-align: center;
}
figure > p {
  text-align: center;
}
figure > div:last-child {
  font-size: 0.95em;
  margin: 0.5em auto 0;
  max-width: 36rem;
  text-align: left;
}
table {
  border-collapse: collapse;
  margin: 0 auto;
}
th,
td {
  padding: 0.25em 0.6em;
}
/* Tables in figures, as in the PDF: pink header row, striped body, horizontal rules. */
figure table {
  border-top: 1px solid #21222c;
}
figure :is(th, td) {
  border-bottom: 1px solid #21222c;
}
figure thead th {
  background: #ffeeff;
}
figure tbody tr:nth-child(even) > td {
  background: #eaf2f5;
}
/* Bare tables (outside figures) are plain grids. */
:not(figure) > table :is(th, td) {
  border: 0.5px solid #21222c;
}

blockquote {
  font-style: italic;
  margin: 1em 2em;
}

/* ---------- title / index ---------- */
.titleblock {
  text-align: center;
  margin: 2rem 0;
}
.titleblock h1 {
  color: var(--title);
  font-family: "Noto Sans", "Libertinus Sans", system-ui, sans-serif;
  font-size: 2.1rem;
  margin-bottom: 0.3em;
}
.titleblock .subtitle {
  font-family: "Noto Sans", "Libertinus Sans", system-ui, sans-serif;
  font-weight: bold;
  font-size: 1.2rem;
  text-align: center;
}
.titleblock p {
  text-align: center;
}
.titleblock .author {
  font-variant: small-caps;
  font-size: 1.4rem;
}
.cover {
  display: block;
  width: 100%;
  border: 2px solid black;
}
nav[role="doc-toc"] ol {
  list-style: none;
  padding-left: 1.5em;
}
main > nav[role="doc-toc"] > ol {
  padding-left: 0;
}
main > nav[role="doc-toc"] > ol > li > :is(div, a, p) {
  font-weight: bold;
  margin-top: 0.8em;
}

/* ---------- "this is experimental" warnings ---------- */
.warning-box {
  margin: 1.5rem 0;
  padding: 0.8em 1em;
  border: 1px solid #f1aeb5;
  border-left: 4px solid #dc3545;
  border-radius: 4px;
  background: #fbeaec;
  color: #58151c;
  text-align: left;
}
main .warning-box a,
.warning-box a {
  color: #a50e1e;
  text-decoration: underline;
}
.warning-box strong {
  color: inherit;
}
.sidebar-warning {
  margin: 0.5rem 0 1rem;
  padding: 0.5em 0.7em;
  font-size: 0.95em;
}

/* ---------- epigraph ---------- */
.epigraph {
  margin: 1.5rem 0 2rem 35%;
  font-size: 0.9em;
}
.epigraph footer {
  border-top: 1px solid #000;
  margin-top: 0.4em;
  padding-top: 0.2em;
  text-align: right;
  font-style: normal;
}

/* ---------- theorem-like environments (ctheorems) ---------- */
.thm {
  padding: 0.9em;
  margin: 0.8em 0;
  background: #eeeeee;
}
.thm > p:first-of-type {
  margin-top: 0;
}
.thm > :last-child {
  margin-bottom: 0;
}
.thm-theorem,
.thm-lemma,
.thm-proposition,
.thm-corollary,
.thm-conjecture {
  background: #eeeeff;
}
.thm-example {
  background: #ffeeee;
}
.thm-algorithm,
.thm-claim {
  background: #ddffdd;
}
.thm-definition {
  background: #eef5ee;
}
.thm-todo {
  background: #ddaa77;
}

/* ---------- gentle-clues style boxes ---------- */
.clue {
  --accent: #888;
  margin: 1em 0;
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 7%, white);
  overflow: hidden;
}
.clue-title {
  padding: 0.3em 0.8em;
  background: color-mix(in srgb, var(--accent) 22%, white);
  font-family: "Noto Sans", "Libertinus Sans", system-ui, sans-serif;
  font-weight: bold;
  font-size: 0.9em;
}
.clue-body {
  padding: 0.2em 0.9em 0.4em;
}
.clue-definition {
  --accent: #1e90ff;
}
.clue-problem,
.clue-exercise {
  --accent: #9400d3;
}
.clue-sample {
  --accent: #2e8b57;
}
.clue-solution {
  --accent: #6b8e23;
}
.clue-remark {
  --accent: #4682b4;
}
.clue-recipe {
  --accent: #ff8c00;
}
.clue-typesig {
  --accent: #708090;
}
.clue-digression {
  --accent: #bbbbbb;
}
.clue-info,
.clue-notify,
.clue-abstract {
  --accent: #1e90ff;
}
.clue-idea,
.clue-tip {
  --accent: #20b2aa;
}
.clue-memo {
  --accent: #d4a017;
}
.clue-warning,
.clue-danger,
.clue-error {
  --accent: #dc143c;
}
.clue-question {
  --accent: #8a2be2;
}
.clue-example,
.clue-experiment,
.clue-success,
.clue-conclusion {
  --accent: #2e8b57;
}
.clue-goal,
.clue-task {
  --accent: #e67e22;
}
.clue-code {
  --accent: #708090;
}

.stack {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

/* ---------- boxed answers (MathML) ---------- */
mrow.boxed {
  border: 1.5px solid #003300;
  background: #eeffee;
  padding: 0.15em 0.3em;
}

/* ---------- numbered equations ---------- */
.numbered-eqn {
  display: flex;
  align-items: center;
}
.numbered-eqn > math {
  flex: 1;
}
.eqn-num {
  margin-left: 1em;
}
