/* Site stylesheet. No external requests: system font stacks only. */

:root {
  color-scheme: light dark;
  --bg: #fcfbf8;
  --fg: #1f1e1c;
  --muted: #6a665f;
  --rule: #e2ded6;
  --tint: #f3f0ea;
  --accent: #8c3a1c;
  --serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, "Iowan Old Style", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --measure: 40rem;
}
:root:has(.site-header.consulting) { --accent: #1f4f7a; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171a;
    --fg: #e3e0da;
    --muted: #9b968d;
    --rule: #34333a;
    --tint: #212126;
    --accent: #e0916c;
  }
  :root:has(.site-header.consulting) { --accent: #86b4e0; }
}

/* Layout: every top-level block shares one centred column. Typst appends footnotes
   (section[role=doc-endnotes]) after the footer; flex order puts them back above it. */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: 1.1875rem;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
body > * {
  box-sizing: border-box;
  width: min(100% - 32px, var(--measure));
  margin-inline: auto;
  order: 1;
}
body > .site-header { order: 0; }
body > section[role="doc-endnotes"] { order: 2; }
body > .series-nav { order: 3; }
body > .site-footer { order: 4; margin-top: auto; }

/* Header and navigation */
.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1.5rem;
  padding: 2.25rem 0 1rem;
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 1.5rem;
}
.site-name { color: var(--fg); text-decoration: none; font-weight: 600; }
.site-name .wordmark {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.75rem;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-transform: lowercase;
  font-variant: small-caps;
}
.site-name .byline { color: var(--muted); font-weight: 400; margin-left: 0.6em; }
.site-header nav { display: flex; gap: 1.5rem; }
.site-header nav a { color: var(--muted); text-decoration: none; padding-bottom: 2px; }
.site-header nav a:hover { color: var(--fg); }
.site-header nav a.active { color: var(--fg); border-bottom: 2px solid var(--accent); }

.site-footer {
  padding: 1rem 0 2.5rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
}
.site-footer a { color: var(--muted); }
.sep { margin: 0 0.35em; opacity: 0.6; }

/* Text */
main { padding: 1.5rem 0 2.5rem; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }
p { margin: 0 0 1em; }
h1, h2, h3, h4 { line-height: 1.25; font-weight: 600; }
h1 { font-size: 2rem; margin: 0.5rem 0 0.5rem; letter-spacing: -0.01em; }
h2 { font-size: 1.4rem; margin: 2.2rem 0 0.7rem; }
h3 { font-size: 1.15rem; margin: 1.8rem 0 0.5rem; }
h4 { font-size: 1rem; margin: 1.5rem 0 0.4rem; }
ul, ol { padding-left: 1.4em; }
li { margin: 0.2em 0; }
blockquote { margin: 1.2em 0; padding: 0 0 0 1.1em; border-left: 3px solid var(--rule); color: var(--muted); }
blockquote p:last-child { margin-bottom: 0.3em; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 2em 0; }
strong { font-weight: 650; }
code, pre, kbd { font-family: var(--mono); font-size: 0.85em; }
code { font-size: 0.82em; }
pre { background: var(--tint); padding: 0.8em 1em; overflow-x: auto; border-radius: 4px; line-height: 1.45; }
pre code { background: none; padding: 0; font-size: 1em; }
dl dd { margin: 0 0 0.6em 1.4em; }
/* Typst term lists (`/ term: desc`): two columns on wide screens */
dl { margin: 0 0 1em; }
@media (min-width: 40rem) {
  dl { display: grid; grid-template-columns: minmax(4em, max-content) 1fr; gap: 0.35em 1.2em; align-items: baseline; }
  dl dt, dl dd { margin: 0; }
}
dl dt { font-weight: 400; }

/* Post header */
.post-header { margin-bottom: 2rem; }
.post-header h1 { margin-top: 0.2rem; }
.series { margin: 0; font-family: var(--sans); font-size: 0.85rem; color: var(--muted); }
.series-name { color: var(--accent); }
.post-meta { margin: 0.4rem 0 0; font-family: var(--sans); font-size: 0.85rem; color: var(--muted); }
.badge {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.7rem;
  line-height: 1.5;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0 0.45em;
  border: 1px solid currentColor;
  border-radius: 3px;
  color: var(--muted);
  vertical-align: 0.15em;
}
.badge-stub { border-style: dashed; }

/* Series navigation at the end of a post */
.series-nav {
  display: grid;
  margin-bottom: 3rem;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}
.series-nav a { text-decoration: none; color: var(--fg); display: block; }
.series-nav a .dir { display: block; font-family: var(--sans); font-size: 0.8rem; color: var(--muted); }
.series-nav a .t { color: var(--accent); }
.series-nav a:hover .t { text-decoration: underline; }
.series-nav .next { grid-column: 2; text-align: right; }

/* Home */
.intro { color: var(--muted); margin-bottom: 2rem; }
.post-list, .series-parts { list-style: none; padding: 0; margin: 0; }
.post-list > li { margin: 0 0 2rem; }
.entry p { margin: 0; }
.entry-title { font-size: 1.15rem; font-weight: 600; line-height: 1.35; }
.entry-title a { color: var(--fg); text-decoration: none; }
.entry-title a:hover { color: var(--accent); text-decoration: underline; }
.entry-date { font-family: var(--sans); font-size: 0.8rem; color: var(--muted); }
.entry-summary { color: var(--muted); font-size: 1rem; margin-top: 0.2rem !important; }
.series-label {
  margin: 0 0 0.6rem;
  font-family: var(--sans);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.series-parts { counter-reset: part; border-left: 2px solid var(--rule); padding-left: 1rem; }
.series-parts > li { counter-increment: part; margin: 0 0 1.1rem; }
.series-parts .entry-title::before { content: counter(part) ". "; color: var(--muted); font-weight: 400; }

/* About */
.page h1 { margin-bottom: 1.2rem; }
.page h2 { font-size: 1.15rem; }
.engagements { list-style: none; padding: 0; }
.engagements li { margin: 0 0 0.9rem; }
.engagements .who { font-weight: 600; }
.engagements .when { font-family: var(--sans); font-size: 0.8rem; color: var(--muted); margin-left: 0.4em; }

/* Math: Typst renders equations as inline SVG frames. The frame's bottom edge is the
   baseline, so the default vertical-align lines inline math up with the text. Black
   glyphs are repainted with currentColor so math follows the text colour (dark mode). */
.eq svg, .eq-block svg { overflow: visible; }
.eq { white-space: nowrap; }
.eq-block { margin: 1em 0; overflow-x: auto; overflow-y: hidden; padding: 0.4em 0; text-align: center; }
.eq-block svg { display: inline-block !important; margin: 0 auto; vertical-align: middle; }
.eq-block.numbered { display: grid; grid-template-columns: 2.5em 1fr 2.5em; align-items: center; }
.eq-block.numbered > svg { grid-column: 2; justify-self: center; }
.eq-num { grid-column: 3; justify-self: end; font-size: 0.95em; color: var(--muted); white-space: nowrap; }
main svg [fill="#000000"] { fill: currentColor; }
main svg [stroke="#000000"] { stroke: currentColor; }
main svg [fill="#ffffff"] { fill: var(--bg); }

/* Theorem-like blocks from fermat.typ: div.thm.defn | thm | obs */
.thm {
  margin: 1.4em 0;
  padding: 0.7em 1em;
  border-left: 3px solid var(--accent);
  background: var(--tint);
  border-radius: 0 4px 4px 0;
}
.thm > :last-child { margin-bottom: 0; }
.thm:not(.defn):not(.obs) { font-style: italic; }
.thm strong:first-child { font-style: normal; }
.thm.obs { border-left-color: var(--rule); background: transparent; }
.thm.defn { border-left-color: var(--accent); }

/* Editorial boxes of the Fermat series (fermat.typ: callout, plegable) */
.callout {
  margin: 1.4em 0;
  padding: 0.8em 1.1em;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--tint);
  font-size: 0.97em;
}
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout-title { font-family: var(--sans); font-size: 0.8em; letter-spacing: 0.04em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.4em; }
.callout.math { background: transparent; border-style: dashed; }
.callout.recap { border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0; }
details.fold { margin: 1.4em 0; padding: 0.5em 1em; border: 1px dashed var(--rule); border-radius: 6px; }
details.fold > summary { cursor: pointer; font-family: var(--sans); font-size: 0.9em; color: var(--accent); }
details.fold[open] > summary { margin-bottom: 0.8em; }
table.series-map { font-size: 0.85rem; }
table.series-map td:first-child { text-align: right; color: var(--muted); }

/* Figures, images, tables */
figure { margin: 1.8em 0; text-align: center; }
figure > * { margin-inline: auto; }
figcaption { font-size: 0.9rem; color: var(--muted); margin-top: 0.6em; text-align: left; line-height: 1.45; }
img { max-width: 100%; height: auto; }

/* Wide figures break out of the text column, centred on it, up to the viewport minus the page gutter. */
figure:has(> .wide-body) {
  width: min(100vw - 32px, 60rem);
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  margin-inline: 0;
}
figure img { margin-inline: auto; }
.fig-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
  gap: 0.75rem;
  align-items: center;
  justify-items: center;
}
.fig-grid > * { min-width: 0; max-width: 100%; text-align: center; }
.fig-grid table { font-size: 0.8rem; }
.align-center { text-align: center; }
.align-right, .align-end { text-align: right; }
.align-center > img, .align-center > figure { margin-inline: auto; }
tr.best { background: color-mix(in srgb, #2f9e5a 22%, transparent); font-weight: 600; }
tr.bad { opacity: 0.4; }
.fig-grid img { width: 100% !important; }
@media (max-width: 34rem) {
  .fig-grid { grid-template-columns: 1fr !important; }
}
table { border-collapse: collapse; margin: 1em auto; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
th, td { padding: 0.3em 0.7em; text-align: left; vertical-align: top; }
thead th, table tr:first-child th { border-bottom: 1px solid var(--fg); }
table { border-top: 1px solid var(--fg); border-bottom: 1px solid var(--fg); }
figure table { display: block; overflow-x: auto; max-width: 100%; width: max-content; }

/* Footnotes and bibliography (native Typst HTML output) */
sup[role="doc-noteref"] { line-height: 0; font-size: 0.72em; }
sup[role="doc-noteref"] a { text-decoration: none; padding: 0 0.1em; }
section[role="doc-endnotes"], section[role="doc-bibliography"], ol.notas {
  font-size: 0.92rem;
  line-height: 1.5;
}
section[role="doc-endnotes"] { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--rule); }
section[role="doc-endnotes"]::before { content: "Notes"; display: block; font-weight: 600; font-size: 1.1rem; margin-bottom: 0.6rem; }
html:lang(es) section[role="doc-endnotes"]::before { content: "Notas"; }
section[role="doc-endnotes"] ol { padding: 0; margin: 0; }
section[role="doc-endnotes"] li { position: relative; margin: 0 0 0.6em; padding-left: 2.2em; }
section[role="doc-endnotes"] li p { margin: 0 0 0.5em; }
section[role="doc-endnotes"] sup[role="doc-backlink"] { position: absolute; left: 0; width: 1.8em; text-align: right; top: 0.55em; line-height: 1; }
section[role="doc-endnotes"] sup[role="doc-backlink"] a { text-decoration: none; }
section[role="doc-bibliography"] { margin-top: 2.5rem; }
section[role="doc-bibliography"] h2 { font-size: 1.1rem; }
section[role="doc-bibliography"] ul { padding: 0; }
section[role="doc-bibliography"] li { margin: 0 0 0.6em; padding-left: 2.2em; text-indent: -2.2em; overflow-wrap: anywhere; }
section[role="doc-bibliography"] .prefix { display: inline-block; min-width: 2em; text-indent: 0; margin-right: 0.2em; }
section[role="doc-bibliography"] .prefix a { text-decoration: none; }

/* Dark mode: raster figures keep a light backing so black-on-transparent plots stay legible. */
@media (prefers-color-scheme: dark) {
  main img { background: #f4f2ee; border-radius: 2px; }
}

@media (max-width: 34rem) {
  body { font-size: 1.0625rem; }
  h1 { font-size: 1.6rem; }
  .site-header { padding-top: 1.2rem; font-size: 1.2rem; }
  .series-nav { grid-template-columns: 1fr; }
  .series-nav .next { grid-column: 1; }
}

/* About: portrait beside the intro (above it on narrow screens) */
.page img[src$="gonzalo.png"] {
  float: right;
  width: 8.5rem;
  height: 8.5rem;
  margin: 0.3rem 0 1rem 1.5rem;
  border-radius: 50%;
  object-fit: cover;
  background: none !important;
}
@media (max-width: 34rem) {
  .page img[src$="gonzalo.png"] { float: none; display: block; width: 6.5rem; height: 6.5rem; margin: 0 0 1.2rem; }
}
.page h2 { clear: both; }

/* Footnote tooltip (filled by the inline script from the end-of-post notes) */
.fn-tip {
  position: fixed;
  z-index: 10;
  box-sizing: border-box;
  max-width: min(26rem, calc(100vw - 24px));
  max-height: 50vh;
  overflow-y: auto;
  padding: 0.6em 0.8em;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.14);
  font-size: 0.88rem;
  line-height: 1.45;
  text-align: left;
}
.fn-tip[hidden] { display: none; }
.fn-tip p { margin: 0 0 0.4em; }
.fn-tip p:last-child { margin-bottom: 0; }
.fn-tip svg [fill="#000000"] { fill: currentColor; }
.fn-tip svg [stroke="#000000"] { stroke: currentColor; }
@media (prefers-color-scheme: dark) {
  .fn-tip { background: var(--tint); box-shadow: 0 4px 16px rgb(0 0 0 / 0.5); }
}
.tototren { margin-top: 3rem; font-family: var(--sans); font-size: 0.75rem; color: var(--muted); text-align: right; }

/* Scheduled posts: a link to a part not yet out reads as plain text; the series footer names the next part and its date. */
.unreleased { color: var(--muted); border-bottom: 1px dotted var(--rule); cursor: help; }
.series-nav .upcoming { color: var(--muted); }
.series-nav .upcoming time { font-variant-numeric: tabular-nums; }
