@font-face {
  font-family: "Source Serif 4";
  src: url("/assets/fonts/source-serif-4-regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Source Serif 4";
  src: url("/assets/fonts/source-serif-4-italic.woff2") format("woff2");
  font-style: italic;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Source Serif 4";
  src: url("/assets/fonts/source-serif-4-semibold.woff2") format("woff2");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

@font-face {
  font-family: "Source Sans 3";
  src: url("/assets/fonts/source-sans-3-regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Source Sans 3";
  src: url("/assets/fonts/source-sans-3-semibold.woff2") format("woff2");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

:root {
  color-scheme: light;
  --paper: #fff;
  --paper-raised: #fff;
  --ink: #111;
  --ink-soft: #555;
  --rule: #ccc;
  --accent: #0000ee;
  --code-paper: #f3f3f3;
  --selection: #cfe3ff;
  --focus: #005fcc;
  --font-serif: "Source Serif 4", Georgia, serif;
  --font-sans: "Source Sans 3", Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --site-width: 52rem;
  --reading-width: 40rem;
  --note-width: 14rem;
  --note-gap: 2rem;
  --gutter: clamp(1rem, 4vw, 2rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #111;
    --paper-raised: #181818;
    --ink: #eee;
    --ink-soft: #aaa;
    --rule: #444;
    --accent: #8ab4f8;
    --code-paper: #1d1d1d;
    --selection: #264f78;
    --focus: #8ab4f8;
  }
}

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

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

body {
  isolation: isolate;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 1.125rem;
  line-height: 1.65;
}

/* A finite, genuine hat patch: never repeat it or size it to the article.
   The large viewport height keeps the crop stable as mobile toolbars retract.
   Appearance is generated from background.config.json, including both themes. */
body::before,
body::after {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  height: 100lvh;
  pointer-events: none;
  content: "";
}

body::before {
  z-index: -2;
  width: 100%;
  background: url("/assets/images/hat-chevron-light.svg") center / cover no-repeat;
}

/* Select the image in the parent document: SVG image media queries can stay
   light in WebKit, including no-JS and reduced-motion backgrounds. */
@media (prefers-color-scheme: dark) {
  body::before { background-image: url("/assets/images/hat-chevron-dark.svg"); }
}

/* Every static page and fallback uses the initial Chevron. Preparing an
   identical frame at scroll zero does not replace it: reveal the SVG only
   after the first nonzero frame, then retain it for the rest of the journey.
   Reading-column and foreground styles do not participate in the handoff. */
.hat-motion {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  height: 100lvh;
  z-index: -2;
  pointer-events: none;
  visibility: hidden;
  overflow: hidden;
  /* A separate compositor layer prevents Chromium pinholes when an opaque
     SVG patch is culled. This identity transform leaves its colors unchanged. */
  transform: translateZ(0);
}
.hat-motion[hidden] { display: none; }
@media (prefers-reduced-motion: no-preference) {
  body[data-hat-animation="ready"][data-hat-started]::before { background-image: none; }
  body[data-hat-animation="ready"][data-hat-started] .hat-motion { visibility: visible; }
}

/* An uninterrupted paper column, without changing the centered reading measure. */
body::after {
  z-index: -1;
  right: 0;
  width: min(calc(100% - var(--gutter)), calc(var(--reading-width) + 2 * var(--gutter)));
  margin-inline: auto;
  background: var(--paper);
}

@media print, (forced-colors: active) {
  body::before,
  body::after,
  .hat-motion {
    display: none;
  }
}

::selection {
  background: var(--selection);
  color: var(--ink);
}

img,
svg {
  display: block;
  max-width: 100%;
}

a {
  color: var(--accent);
  text-decoration-thickness: 0.07em;
  text-underline-offset: 0.16em;
}

a:hover {
  color: var(--ink);
}

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

.site-shell {
  width: min(calc(100% - (2 * var(--gutter))), var(--site-width));
  margin-inline: auto;
}

.skip-link {
  position: fixed;
  z-index: 10;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.45rem 0.7rem;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  transform: translateY(-180%);
}

.skip-link:focus {
  color: var(--paper);
  transform: translateY(0);
}

/* Header */

.masthead {
  max-width: var(--reading-width);
  min-height: 5rem;
  display: flex;
  align-items: center;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem;
}

.site-nav a {
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 1.5rem;
  line-height: 1.2;
  text-decoration: none;
}

.site-nav a:hover,
.site-nav [aria-current] {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 0.07em;
  text-underline-offset: 0.2em;
}

.nav-divider {
  color: var(--ink-soft);
  font-family: var(--font-serif);
  font-size: 1.25rem;
  line-height: 1;
}

/* Home: a compact contact directory and a plain, chronological reading list.
   Borrow the reference's typography and spacing, not its colors. */

.home-main {
  max-width: var(--reading-width);
  padding-block: clamp(1.5rem, 4vw, 2.5rem) 3rem;
}

.home-contact {
  margin-bottom: 3rem;
}

.home-contact h1,
.home-main .article-index > h2 {
  margin: 0 0 1.25rem;
  font-family: var(--font-serif);
  font-size: clamp(2rem, 4vw, 2.5rem);
  font-weight: 400;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.contact-list {
  display: grid;
  grid-template-columns: fit-content(35%) minmax(0, 1fr);
  gap: 0.15rem 0.85rem;
  margin: 0;
  font-size: 1.125rem;
  line-height: 1.5;
}

.contact-list dt {
  text-align: right;
  overflow-wrap: anywhere;
}

.contact-list dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.contact-list a,
.article-title {
  text-decoration: none;
}

.contact-list a:hover,
.article-title:hover {
  text-decoration: underline;
}

.article-index {
  max-width: var(--reading-width);
}

.article-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.article-row + .article-row {
  margin-top: 1.4rem;
}

.article-title {
  font-size: 1.3rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.article-row time {
  display: block;
  margin-top: 0.15rem;
  color: var(--ink-soft);
  font-family: var(--font-serif);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
}

.empty-articles {
  margin: 0;
  color: var(--ink-soft);
}

.archive-main {
  padding-block: clamp(4rem, 8vw, 6rem) clamp(6rem, 11vw, 9rem);
}

.archive-header {
  width: min(100%, var(--reading-width));
  margin: 0 auto 3rem;
}

.archive-header h1 {
  margin: 0.6rem 0 0.75rem;
  font-size: clamp(2.6rem, 6vw, 4rem);
  font-weight: 400;
  letter-spacing: -0.035em;
  line-height: 1.04;
}

.archive-header > p:last-child {
  margin: 0;
  color: var(--ink-soft);
  font-size: 1.1rem;
}

.archive-main .article-index {
  width: min(100%, var(--reading-width));
  margin-inline: auto;
  padding-bottom: 0;
}

/* Shared pages */

.page-main,
.article-main {
  padding-block: clamp(4rem, 8vw, 6.5rem) clamp(6rem, 11vw, 9rem);
}

.page-header,
.page-body,
.article-header,
.article-body,
.article-footer {
  width: min(100%, var(--reading-width));
  margin-inline: auto;
}

.page-header,
.article-header {
  margin-bottom: clamp(3.5rem, 7vw, 5rem);
}

.eyebrow,
.article-kicker,
.article-meta {
  margin: 0;
  color: var(--ink-soft);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  line-height: 1.4;
  text-transform: uppercase;
}

.eyebrow,
.article-kicker,
.article-kicker a {
  color: var(--accent);
}

.article-kicker a {
  text-decoration: none;
}

.page-header h1,
.article-header h1,
.not-found h1 {
  margin: 0.75rem 0 1rem;
  font-size: clamp(2.6rem, 6vw, 4rem);
  font-weight: 400;
  letter-spacing: -0.035em;
  line-height: 1.04;
}

.page-header > p:last-child,
.article-dek {
  margin: 0;
  color: var(--ink-soft);
  font-size: 1.2rem;
  line-height: 1.5;
}

.article-meta {
  margin-top: 1.5rem;
}

/* Prose */

.prose {
  font-size: 1.125rem;
  line-height: 1.65;
}

.prose::after {
  display: table;
  clear: both;
  content: "";
}

.prose p {
  margin: 0 0 1.45em;
}

.prose :is(h1, h2, h3, h4, h5, h6) {
  clear: left;
  text-wrap: balance;
}

.prose .prose-h2 {
  position: relative;
  margin: 2.4em 0 0.6em;
  font-size: 1.9rem;
  font-style: italic;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.heading-anchor {
  position: absolute;
  top: 0.32em;
  right: calc(100% + 0.55rem);
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 0.58em;
  font-style: normal;
  font-weight: 600;
  text-decoration: none;
}

.prose .prose-h3 {
  margin: 2.1em 0 0.55em;
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1.25;
}

.prose .prose-h4 {
  margin: 2em 0 0.5em;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.prose a {
  overflow-wrap: anywhere;
}

.prose strong {
  font-weight: 600;
}

.prose ul,
.prose ol {
  margin: 0.25rem 0 1.5rem;
  padding-left: 1.4rem;
}

.prose li {
  margin: 0.25rem 0;
  padding-left: 0.15rem;
}

.prose li::marker {
  color: var(--accent);
}

.prose blockquote {
  margin: 2rem 0;
  padding: 0.25rem 0 0.25rem 1.25rem;
  border-left: 2px solid var(--accent);
  color: var(--ink-soft);
  font-size: 1.08em;
  font-style: italic;
}

.prose blockquote p:last-child {
  margin-bottom: 0;
}

.prose .article-figure {
  margin: 2.5rem 0;
}

.article-figure img {
  width: auto;
  height: auto;
  margin-inline: auto;
}

/* These generated diagrams share a square canvas. Reserve their space before
   lazy loading so they do not change the scroll journey's denominator. */
.article-figure img[src^="/assets/images/making-the-background/"] {
  width: 100%;
  aspect-ratio: 1;
}

/* The About cloud is a static 1000 × 720 SVG. Reserve its space before loading. */
.prose img[src="/assets/images/interests.svg"] {
  width: 100%;
  height: auto;
  aspect-ratio: 25 / 18;
  border: 0;
}

/* The SVG has transparent paper and #111 ink. Inverting only this monochrome
   image gives #eee ink without relying on WebKit's embedded-SVG media queries. */
@media (prefers-color-scheme: dark) {
  .prose img[src="/assets/images/interests.svg"] { filter: invert(1); }
}

@media print, (forced-colors: active) {
  .prose img[src="/assets/images/interests.svg"] { filter: none; }
}

.article-figure figcaption {
  margin-top: 0.65rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.5;
}

.prose .katex-block {
  margin-block: 2rem;
}

.katex-display {
  max-width: 100%;
  padding-block: 0.35rem 0.55rem;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.prose code {
  padding: 0.08em 0.28em;
  border: 1px solid var(--rule);
  background: var(--code-paper);
  font-family: var(--font-mono);
  font-size: 0.8em;
  font-variant-ligatures: none;
}

.prose pre {
  position: relative;
  margin: 2rem 0;
  padding: 2rem 1rem 1rem;
  overflow-x: auto;
  border: 1px solid var(--rule);
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 0.875rem;
  line-height: 1.55;
  tab-size: 2;
}

.prose pre::before {
  position: absolute;
  top: 0.5rem;
  left: 1rem;
  color: var(--ink-soft);
  content: attr(data-language);
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.prose pre code {
  min-width: 100%;
  display: block;
  width: max-content;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
}

.prose pre.shiki {
  background-color: var(--paper-raised) !important;
}

@media (prefers-color-scheme: dark) {
  .shiki,
  .shiki span {
    color: var(--shiki-dark) !important;
  }
}

.prose hr {
  width: 4rem;
  height: 1px;
  margin: 3.5rem auto;
  border: 0;
  background: var(--rule);
}

.prose img {
  width: 100%;
  height: auto;
  margin: 2rem 0;
  border: 1px solid var(--rule);
}

/* Margin notes */

.sidenote-number {
  margin-left: 0.12rem;
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-style: normal;
  font-weight: 600;
  line-height: 1;
  vertical-align: super;
}

.sidenote {
  float: right;
  clear: right;
  width: var(--note-width);
  margin: 0.2rem calc(-1 * (var(--note-width) + var(--note-gap))) 1rem 0;
  padding: 0.35rem 0.5rem;
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 0.82rem;
  line-height: 1.45;
}

.sidenote-index {
  margin-right: 0.35rem;
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
}

/* Article ending */

.article-footer {
  margin-top: clamp(4.5rem, 9vw, 7rem);
}

.article-footer::before {
  display: block;
  margin-bottom: 2rem;
  color: var(--ink-soft);
  content: "⁂";
  font-size: 1.15rem;
  text-align: center;
}

.article-pagination {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
}

.article-pagination a {
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1.4;
  text-decoration: none;
}

.article-pagination a:hover {
  color: var(--accent);
}

.article-pagination a span {
  color: var(--ink);
}

.previous-article {
  grid-column: 1;
}

.next-article {
  grid-column: 2;
  text-align: right;
}

/* 404 */

.not-found {
  min-height: calc(100vh - 11rem);
  display: flex;
  max-width: var(--reading-width);
  flex-direction: column;
  justify-content: center;
  padding-block: 5rem;
}

.not-found > p:not(.eyebrow) {
  max-width: 34rem;
  margin: 0 0 1.5rem;
  color: var(--ink-soft);
}

.not-found > a {
  width: fit-content;
}

/* Responsive */

@media (max-width: 75rem) {
  .sidenote {
    float: none;
    width: auto;
    display: block;
    margin: 1rem 0 1.25rem;
    padding: 0.8rem 1rem;
    border-left: 2px solid var(--accent);
    background: var(--code-paper);
    font-size: 0.9rem;
  }
}

@media (max-width: 42rem) {
  .masthead {
    min-height: 4.25rem;
    padding-block: 0.5rem;
  }

  .site-nav {
    gap: 0.55rem;
  }

  .site-nav a {
    font-size: 1.2rem;
  }

  .nav-divider {
    font-size: 1rem;
  }

  .page-header > p:last-child,
  .article-dek {
    font-size: 1.1rem;
  }

  .page-main,
  .article-main,
  .archive-main {
    padding-block: 3.5rem 5rem;
  }

  .page-header,
  .article-header {
    margin-bottom: 3.25rem;
  }

  .heading-anchor {
    position: static;
    display: inline-block;
    margin-right: 0.4rem;
  }

  .article-pagination {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .previous-article,
  .next-article {
    grid-column: 1;
    text-align: left;
  }

}

@media print {
  :root {
    color-scheme: light;
    --paper: #fff;
    --paper-raised: #fff;
    --ink: #000;
    --ink-soft: #333;
    --rule: #bbb;
  }

  body {
    font-size: 11pt;
  }

  .site-header,
  .article-footer,
  .sidenote-number {
    display: none;
  }

  .site-shell,
  .article-header,
  .article-body {
    width: 100%;
    max-width: none;
  }

  .article-main {
    padding: 0;
  }

  .prose pre.shiki,
  .prose pre.shiki span {
    color: #000 !important;
  }

  .sidenote {
    float: none;
    width: auto;
    display: block;
    margin: 0.5rem 0 1rem;
    padding-left: 1rem;
    border-left: 1px solid #777;
    font-size: 9pt;
  }

  .article-figure {
    break-inside: avoid;
  }

  .prose img[src="/assets/images/interests.svg"] {
    break-inside: avoid;
  }

  .katex-display {
    overflow: visible;
  }

  a {
    color: inherit;
  }
}
