/* Self-hosted subsets built by scripts/build_web_fonts.py; licenses sit beside the files. */
@font-face {
  font-family: 'Newsreader';
  src: url('/assets/fonts/newsreader/Newsreader.woff2') format('woff2');
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
}

@font-face {
  font-family: 'Newsreader';
  src: url('/assets/fonts/newsreader/Newsreader-Italic.woff2') format('woff2');
  font-style: italic;
  font-weight: 400 700;
  font-display: swap;
}

@font-face {
  font-family: 'Cormorant Garamond';
  src: url('/assets/fonts/cormorant-garamond/CormorantGaramond.woff2') format('woff2');
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
}

@font-face {
  font-family: 'Cormorant Garamond';
  src: url('/assets/fonts/cormorant-garamond/CormorantGaramond-Italic.woff2') format('woff2');
  font-style: italic;
  font-weight: 400;
  font-display: swap;
}

/* Colors: light by default, dark when the system prefers it, and either one
   when the reader picks it with the theme toggle (data-theme on <html>).
   Print always uses the light palette. */
:root {
  color-scheme: light;
  --font-body: 'Newsreader', serif;
  --font-heading: 'Cormorant Garamond', serif;
  --side-column-width: 220px;
  --column-gap: 40px;
  --bg: #fffff8;
  --fg: #000;
  --muted: #666;
  --code-bg: #f4f1e8;
  --rule: #d8d2c0;
  --link: #0000ee;
  --link-visited: #551a8b;
  --link-active: #ff0000;
  --link-underline: #5b7fc4;
}

/* The two dark blocks below must stay identical: one follows the system,
   the other the toggle. */
@media screen and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1E1E1E;
    --fg: #CCCCCC;
    --muted: #a19e95;
    --code-bg: #2a2a2a;
    --rule: #403d35;
    --link: #8ab4f8;
    --link-visited: #c4a3f5;
    --link-active: #ff7b72;
    --link-underline: #6f93d6;
  }
}

@media screen {
  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #1E1E1E;
    --fg: #CCCCCC;
    --muted: #a19e95;
    --code-bg: #2a2a2a;
    --rule: #403d35;
    --link: #8ab4f8;
    --link-visited: #c4a3f5;
    --link-active: #ff7b72;
    --link-underline: #6f93d6;
  }
}

html {
  background: var(--bg);
}

body {
  box-sizing: border-box;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 1.1rem;
  line-height: 1.4;
  padding: 0 10px;
  max-width: 720px;
  margin: 50px 0 50px 10%;
  counter-reset: sidenote-counter;
}

body.post {
  max-width: 900px;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-heading);
}

a {
  text-decoration: none;
}

a:link {
  color: var(--link);
}

a:visited {
  color: var(--link-visited);
}

a:active {
  color: var(--link-active);
}

article a:not(.toc a),
.sidenote-number::after {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

article a:not(.toc a):hover,
article a:not(.toc a):focus-visible,
.sidenote-number:hover::after,
.sidenote-number:focus-visible::after {
  text-decoration-thickness: 2px;
}

.theme-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.25em 0.5em;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.9em;
  cursor: pointer;
}

.theme-toggle svg {
  display: block;
  width: 1.125em;
  height: 1.125em;
  flex: none;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  color: var(--fg);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.profile-links {
  display: flex;
  align-items: center;
  gap: 0.75em;
}

.profile-links a {
  display: inline-flex;
  color: inherit;
  padding: 0.25em;
}

.profile-links svg {
  width: 1.125em;
  height: 1.125em;
  fill: currentColor;
}

img {
  max-width: 100%;
  height: auto;
}

img.centered,
article img {
  display: block;
  margin-inline: auto;
}

article img {
  max-width: 70%;
}

figure {
  margin: 1.5em 0;
}

.figure-half img {
  display: block;
  max-width: 50%;
  margin-inline: auto;
}

figcaption {
  margin-top: 0.5em;
  color: var(--muted);
  font-size: 0.9em;
}

/* An image figure shrinks to its image, capped at the 70% image column,
   so the caption wraps at the image's width and starts at its left edge.
   inline-size containment keeps a long caption from widening the figure. */
article figure:has(> img):not(.figure-half) {
  width: fit-content;
  max-width: 70%;
  margin-inline: auto;
}

article figure:has(> img):not(.figure-half) > img {
  max-width: 100%;
}

article figure:has(> img):not(.figure-half) > figcaption {
  contain: inline-size;
}

caption {
  caption-side: bottom;
  margin-top: 0.5em;
  text-align: left;
}

pre {
  overflow-x: auto;
  padding: 0.75em;
  background: var(--code-bg);
  font-size: 0.75em;
  line-height: 1.45;
}

pre code {
  font-size: 1em;
}

mjx-container[display="true"] {
  overflow-x: auto;
  overflow-y: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin: 1em 0;
}

table.comparison {
  table-layout: auto;
  font-size: 0.9em;
}

.table-scroll {
  width: 100%;
  margin: 1em 0;
}

.table-scroll table {
  margin: 0;
}

th,
td {
  text-align: left;
  vertical-align: top;
}

.comparison th,
.comparison td {
  border-bottom: 1px solid var(--rule);
  padding: 0.35em 0.5em;
  overflow-wrap: anywhere;
}

th:first-child,
td:first-child {
  width: 145px;
}

.comparison th:first-child,
.comparison td:first-child {
  width: auto;
}

.toc h2 {
  font-size: 1.17em;
  margin-bottom: 0.5em;
}

.toc ul {
  padding-left: 1.25em;
}

.toc a {
  color: inherit;
}

.sidenote {
  width: var(--side-column-width);
  margin-right: calc(-1 * (var(--side-column-width) + var(--column-gap)));
  margin-bottom: 1.25em;
  float: right;
  clear: right;
  font-size: 0.85em;
  line-height: 1.5;
  position: relative;
}

.sidenote-number {
  counter-increment: sidenote-counter;
  cursor: pointer;
}

.sidenote-number::after,
.sidenote::before {
  font-size: 0.8em;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}

.sidenote-number::after {
  content: counter(sidenote-counter);
  top: -0.5em;
  left: 0.1em;
}

.sidenote-number-consecutive::after {
  content: ", " counter(sidenote-counter);
}

.sidenote::before {
  content: counter(sidenote-counter) " ";
  top: -0.5em;
}

input.margin-toggle {
  display: none;
}

.print-citations {
  display: none;
}

@media (max-width: 1359px) {
  .sidenote {
    display: none;
  }

  .margin-toggle:checked + .sidenote {
    display: block;
    float: none;
    clear: both;
    width: auto;
    margin: 1em 0 1.25em;
    padding-left: 1em;
    border-left: 1px solid;
  }
}

@media screen and (min-width: 1200px) {
  body.post {
    margin-left: calc(var(--side-column-width) + var(--column-gap) + 20px);
    max-width: min(900px, calc(100vw - var(--side-column-width) - var(--column-gap) - 40px));
  }

  .toc {
    position: fixed;
    top: 50px;
    left: 30px;
    width: var(--side-column-width);
    max-height: calc(100vh - 100px);
    overflow: auto;
  }

  .toc h2 {
    margin-top: 0;
  }

  .toc ul {
    list-style: none;
    margin: 0;
    padding-left: 0;
  }

  .toc li {
    margin: 0;
  }

  .toc a {
    color: var(--muted);
    text-decoration: none;
  }

  .toc a:hover,
  .toc a:focus {
    color: inherit;
    text-decoration: none;
  }

  h2,
  h3 {
    scroll-margin-top: 2rem;
  }
}

@media screen and (min-width: 1360px) {
  body.post {
    --article-width: min(900px, calc(100vw - 2 * (var(--side-column-width) + var(--column-gap)) - 40px));
    max-width: var(--article-width);
    margin-inline: auto;
  }

  .toc {
    /* Match the right sidenote's gap, accounting for the article's 10px padding. */
    left: calc(50% - var(--article-width) / 2 - var(--side-column-width) - var(--column-gap) + 10px);
  }
}

@media (max-width: 650px) {
  body {
    margin: 25px 0 40px;
  }

  article img,
  .figure-half img,
  article figure:has(> img):not(.figure-half) {
    max-width: 100%;
  }

  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  .comparison th,
  .comparison td {
    white-space: nowrap;
  }
}

@media print {
  .theme-toggle {
    display: none;
  }

  body {
    margin-left: 0;
    padding: 0;
  }

  /* Start the post title at the page margin: drop the screen top margin,
     the top Index link, and the title's own top margin. */
  body.post {
    margin-top: 0;
  }

  body.post > nav {
    display: none;
  }

  body.post article > header > h1 {
    margin-top: 0;
  }

  .toc {
    position: static;
    width: auto;
    max-height: none;
    overflow: visible;
  }

  .toc h2 {
    margin-top: 1em;
  }

  .toc ul {
    list-style: disc;
    margin: 1em 0;
    padding-left: 40px;
  }

  .toc li {
    margin: 0;
  }

  .toc a {
    color: inherit;
    text-decoration: none;
  }

  .sidenote {
    display: none !important;
  }

  .print-citations {
    display: block;
    margin-top: 3em;
  }

  .print-citations h2 {
    font-size: 1.17em;
  }

  .print-citations li {
    margin-bottom: 0.5em;
    break-inside: avoid;
  }

  article a[data-print-source]::after {
    content: "[" attr(data-print-source) "]";
    font-size: 0.75em;
    vertical-align: super;
    line-height: 0;
  }

  .print-source-url {
    overflow-wrap: anywhere;
    color: var(--muted);
  }
}
