/* thomasdigiusto.com: shared style for every page.
   Pages link it relatively (assets/style.css at the root, ../assets/style.css one folder down).
   Theme: the colours below follow the system (prefers-color-scheme) unless the header button
   has set data-theme="light" or "dark" on <html> (assets/theme-init.js, assets/site.js).
   The "palette:" comments are read by the chart script, keep them next to the colour blocks. */

/* ---- fonts (assets/fonts/, written by tools/vendor-fonts.sh, SIL Open Font License) */
@font-face {
  font-family: "Inter";
  src: url("fonts/inter-4.1/inter-roman.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Site Serif";
  src: url("fonts/source-serif-4.005/source-serif-roman.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Site Serif";
  src: url("fonts/source-serif-4.005/source-serif-italic.woff2") format("woff2");
  font-weight: 400 700;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "STIX Two Math";
  src: url("fonts/stix-two-math-2.13/stix-two-math.woff2") format("woff2");
  font-display: swap;
}

/* ---- colours */
:root {
  /* palette: light */
  --bg: #fcfcfb;
  --fg: #1c1d21;
  --muted: #61646b;
  --line: #e5e6e9;
  --soft: #f3f4f6;
  --accent: #2f6fd6;
  --accent-soft: #e8f0fc;
  --code-bg: #f4f5f7;
  --warn-bg: #fff6db;
  --warn-fg: #5c4200;
  --warn-line: #d99a00;
  --pic-card: transparent;
  --pic-pad: 0;
  --pic-border: var(--line);
  color-scheme: light;
}
/* The dark palette is written twice: once for the button, once for the system setting. */
:root[data-theme="dark"] {
  /* palette: dark */
  --bg: #111317;
  --fg: #e4e5e8;
  --muted: #9a9ea8;
  --line: #2a2d34;
  --soft: #191c21;
  --accent: #7aa7f5;
  --accent-soft: #1b2638;
  --code-bg: #1a1d23;
  --warn-bg: #3a2f10;
  --warn-fg: #f3dc9a;
  --warn-line: #b8860b;
  /* photos and other raster images sit on a light card in the dark */
  --pic-card: #fff;
  --pic-pad: 0.6rem;
  --pic-border: transparent;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* palette: dark */
    --bg: #111317;
    --fg: #e4e5e8;
    --muted: #9a9ea8;
    --line: #2a2d34;
    --soft: #191c21;
    --accent: #7aa7f5;
    --accent-soft: #1b2638;
    --code-bg: #1a1d23;
    --warn-bg: #3a2f10;
    --warn-fg: #f3dc9a;
    --warn-line: #b8860b;
    --pic-card: #fff;
    --pic-pad: 0.6rem;
    --pic-border: transparent;
    color-scheme: dark;
  }
}

/* things that are swapped, not recoloured: charts with a dark version, the button icon */
.theme-pic .pic-dark, .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-pic .pic-light,
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-pic .pic-dark,
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-pic .pic-light,
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
  :root:not([data-theme="light"]) .theme-pic .pic-dark,
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
}

/* ---- type */
:root {
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Site Serif", Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --maths: "STIX Two Math", "Latin Modern Math", "Cambria Math", math;
  /* fluid scale: 16px text on a phone, 18px on a wide screen, headings grow a little faster */
  --step--1: clamp(0.84rem, 0.82rem + 0.1vw, 0.9rem);
  --step-0: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --step-1: clamp(1.13rem, 1.06rem + 0.35vw, 1.3rem);
  --step-2: clamp(1.3rem, 1.17rem + 0.6vw, 1.6rem);
  --step-3: clamp(1.9rem, 1.3rem + 2.6vw, 2.7rem);
  --radius: 10px;
  --measure: 68ch;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: var(--step-0);
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  font-kerning: normal;
}

body { margin: 0; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}

.wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding-inline: 1.25rem;
}

/* ---- header and footer */
.site-header, .site-footer, .page-meta, .post-meta, .tags, .series, .back,
.draft-banner, .toc, figcaption, table, h1, h2, h3, h4 {
  font-family: var(--sans);
}
.site-header { border-bottom: 1px solid var(--line); }
.site-header .wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  padding-top: 0.9rem;
  padding-bottom: 0.9rem;
}
.site-name {
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--fg);
  text-decoration: none;
}
.site-name:hover { color: var(--accent); }
.header-tools { display: flex; align-items: center; gap: 1.1rem; }
.site-nav { display: flex; gap: 1.1rem; }
.site-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
}
.site-nav a:hover { color: var(--accent); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle[hidden] { display: none; }
.theme-toggle svg { width: 1.1rem; height: 1.1rem; }

.site-footer {
  margin-top: 4rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.88rem;
}
.site-footer .wrap {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  padding-top: 1.5rem;
  padding-bottom: 2rem;
}
.site-footer a { color: var(--muted); }
.footer-links { display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem; }

main { padding-top: 2.5rem; }

/* ---- titles and text */
.page-title {
  font-size: var(--step-3);
  line-height: 1.12;
  letter-spacing: -0.025em;
  margin: 0 0 0.6rem;
}
.page-meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 2.5rem;
}

h1, h2, h3, h4 {
  line-height: 1.25;
  letter-spacing: -0.015em;
  margin: 2.2em 0 0.6em;
  scroll-margin-top: 1.5rem;
}
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }
h4 { font-size: var(--step-0); }

/* heading links: a # that shows on hover or keyboard focus */
.anchor {
  margin-left: 0.35em;
  color: var(--muted);
  font-weight: 400;
  text-decoration: none;
  opacity: 0;
}
h2:hover .anchor, h3:hover .anchor, .anchor:focus-visible { opacity: 1; }
.anchor:hover { color: var(--accent); }

p, ul, ol, blockquote, pre, figure, table { margin: 0 0 1.25em; }
ul, ol { padding-left: 1.4em; }
li { margin: 0.3em 0; }
li > ul, li > ol { margin: 0.3em 0 0; }
strong { font-weight: 650; }

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}
a:hover { text-decoration-thickness: 2px; }

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 2.5em 0;
}

blockquote {
  margin-left: 0;
  padding: 0.6em 1.1em;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--fg);
}
blockquote > :last-child { margin-bottom: 0; }

/* ---- figures */
figure { margin: 2em 0; text-align: center; }
picture { display: block; }
figure img, p > img, p > picture img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  border-radius: var(--radius);
  border: 1px solid var(--pic-border);
  background: var(--pic-card);
  padding: var(--pic-pad);
}
/* charts with a .dark.svg twin are drawn in the page colours: no card in either theme */
.theme-pic { display: block; }
.theme-pic img, figure .theme-pic img, p > .theme-pic img {
  background: none;
  padding: 0;
  border-color: var(--line);
}
figcaption {
  margin-top: 0.6em;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

/* ---- tables */
table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
  -webkit-overflow-scrolling: touch;
}
th, td {
  padding: 0.45em 0.9em;
  text-align: left;
  vertical-align: top;
}
th {
  font-weight: 600;
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
tbody tr:nth-child(odd) { background: var(--soft); }
td:first-child, th:first-child { padding-left: 0.6em; }
caption { color: var(--muted); font-size: 0.86rem; margin-bottom: 0.5em; }

/* ---- code */
code, pre, kbd { font-family: var(--mono); font-size: 0.86em; }
:not(pre) > code {
  background: var(--code-bg);
  padding: 0.12em 0.35em;
  border-radius: 5px;
}
pre {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9em 1.1em;
  overflow-x: auto;
  line-height: 1.55;
}
pre code { background: none; padding: 0; font-size: 0.82rem; }
div.sourceCode { margin: 0 0 1.25em; }
pre > code.sourceCode > span { display: inline; }
pre > code.sourceCode > span > a:first-child::before { text-decoration: none; }
/* token colours: assets/code.css, generated by tools/md2html.py, linked on pages with code */

/* ---- maths: MathML written by pandoc, drawn by the browser with a maths font */
math { font-family: var(--maths); font-size: 1.05em; }
/* md2html wraps each display equation in .math-block: the wrapper scrolls sideways when the
   equation is wider than the column (Firefox does not scroll a <math> element itself) */
.math-block {
  display: block;
  max-width: 100%;
  margin: 1em 0 1.25em;
  padding: 0.2em 0;
  overflow-x: auto;
  overflow-y: hidden;
}
math[display="block"] { display: block math; margin: 0; }
/* matrix cells aligned left or right (md2html turns pandoc's inline styles into these) */
math .ma-left { text-align: left; }
math .ma-right { text-align: right; }
math .ma-pl0 { padding-left: 0; }
math .ma-pr0 { padding-right: 0; }
/* thin scrollbars in the page colours (code, tables and wide maths on phones) */
pre, table, .math-block {
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

/* ---- home page: the article list */
.intro { color: var(--muted); font-size: 1.08rem; margin-bottom: 2.5rem; }
.post-list { list-style: none; padding: 0; margin: 0; }
.post-list > li {
  margin: 0;
  padding: 1.4rem 0;
  border-top: 1px solid var(--line);
}
.post-list > li:last-child { border-bottom: 1px solid var(--line); }
.post-list h2 { font-size: var(--step-1); margin: 0 0 0.25rem; }
.post-list h2 a { color: var(--fg); text-decoration: none; }
.post-list h2 a:hover { color: var(--accent); }
.post-list .post-meta { margin: 0; color: var(--muted); font-size: 0.86rem; }
.post-list p { margin: 0.4rem 0 0; color: var(--muted); }

/* ---- tags, as small chips */
.tags {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0;
  margin: 0.7rem 0 0;
}
.tags li { margin: 0; }
.tags a, .tags span {
  display: inline-block;
  padding: 0.05rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  line-height: 1.6;
  text-decoration: none;
}
.tags a:hover { text-decoration: underline; }

/* ---- article heading: title, date and reading time, tags, series */
.article-head { margin-bottom: 2.5rem; }
.article-head > * { margin-bottom: 0; }
.article-head > .page-title { margin-bottom: 0.6rem; }
.article-head .tags { margin-top: 0.6rem; }

/* ---- table of contents (articles with three or more sections, toc: false turns it off).
   Narrow screens: a <details> under the title. 1200px and wider: a column in the right margin. */
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc ol ol { padding-left: 0.9rem; }
.toc li { margin: 0.25rem 0; line-height: 1.35; }
.toc a { color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--accent); }
.toc-top {
  margin: -1rem 0 2.25rem;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.88rem;
}
.toc-top summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.toc-top[open] summary { margin-bottom: 0.4rem; }
.toc-side { display: none; }
@media (min-width: 1200px) {
  .toc-top { display: none; }
  .article-layout {
    display: grid;
    grid-template-columns: 100% 12.5rem;
    column-gap: 2.5rem;
  }
  .toc-side {
    display: block;
    align-self: start;
    position: sticky;
    top: 1.5rem;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
    padding: 0.2rem 0 0.2rem 1rem;
    border-left: 1px solid var(--line);
    font-size: 0.8rem;
    scrollbar-width: thin;
  }
  .toc-side .toc-title {
    margin: 0 0 0.5rem;
    color: var(--fg);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.72rem;
  }
  .toc-side a[aria-current] { color: var(--accent); font-weight: 600; }
}

/* ---- reading progress: a thin bar driven by the scroll position, no script.
   Browsers without scroll-driven animations show no bar. */
.progress { display: none; }
@supports (animation-timeline: scroll()) {
  .progress {
    display: block;
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 10;
    height: 3px;
    background: var(--accent);
    transform-origin: 0 50%;
    transform: scaleX(0);
    animation: progress linear both;
    animation-timeline: scroll(root block);
  }
}
@keyframes progress { to { transform: scaleX(1); } }

/* ---- series */
.series-note { color: var(--muted); font-size: 0.92rem; margin-top: 0.5rem; }
.series {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.6rem 1.5rem;
  margin-top: 3rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
}
.series p { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 0.88rem; }
.series a { text-decoration: none; }
.series a[rel="next"] { margin-left: auto; text-align: right; }

.back { margin-top: 3rem; }
.back a { text-decoration: none; }

/* ---- contact page */
.contact-list { list-style: none; padding: 0; }
.contact-list li { margin: 0.4rem 0; }
.contact-list .label {
  display: inline-block;
  min-width: 6rem;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.88rem;
}

/* ---- page transitions: a short cross-fade between pages of the site, none with reduced motion */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  ::view-transition-old(root), ::view-transition-new(root) {
    animation-duration: 160ms;
    animation-timing-function: ease-out;
  }
}

@media (max-width: 600px) {
  main { padding-top: 1.75rem; }
  .header-tools { gap: 0.9rem; }
}

@media print {
  .site-header, .site-footer, .back, .toc, .progress { display: none; }
  html { background: #fff; color: #000; }
  a { color: inherit; }
  .anchor { display: none; }
}

/* ---- status: hidden articles, local preview only (they are never deployed) */
.draft-banner {
  margin: 1.5rem 0 0;
  padding: 0.7rem 1rem;
  border: 1px solid var(--warn-line);
  border-left-width: 4px;
  border-radius: 6px;
  background: var(--warn-bg);
  color: var(--warn-fg);
  font-size: 0.88rem;
}
