:root {
  --bg: #fdfdfc;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --rule: #e4e4e0;
  --link: #1a4fa0;
  --code-bg: #f4f4f1;
  --measure: 42rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131313;
    --fg: #e8e8e6;
    --muted: #9a9a96;
    --rule: #2c2c2c;
    --link: #8ab4f8;
    --code-bg: #1e1e1e;
  }
}

* { box-sizing: border-box; }

/* Safety net: a stale or missing rule below must never let an image blow the
   page out sideways. */
img { max-width: 100%; height: auto; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.65 ui-serif, Georgia, "Times New Roman", serif;
  -webkit-text-size-adjust: 100%;
}

header.site, main, footer.site {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 1.25rem;
}

header.site {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding-top: 2.5rem;
  padding-bottom: 2.5rem;
}

.wordmark {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1rem;
  letter-spacing: .02em;
  text-decoration: none;
  color: var(--fg);
}

header.site nav a {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .8rem;
  color: var(--muted);
  margin-left: 1rem;
  text-decoration: none;
}
header.site nav a:hover { color: var(--link); }
header.site nav a[aria-current="page"] { color: var(--fg); }

/* The wordmark is a link home; make that visible rather than implied. */
.wordmark:hover { color: var(--link); }

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

h1 { font-size: 1.9rem; line-height: 1.25; margin: 0 0 .5rem; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; margin: 2.5rem 0 .75rem; }
h3 { font-size: 1.05rem; margin: 2rem 0 .5rem; }

.intro p { color: var(--muted); font-size: 1.05rem; }

.posts ul, .projects ul { list-style: none; padding: 0; margin: 0; }
.posts li, .projects li { padding: 1rem 0; border-bottom: 1px solid var(--rule); }
.posts .title { font-size: 1.1rem; text-decoration: none; }
.posts .title:hover { text-decoration: underline; }
.posts time { display: block; font-size: .8rem; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }
.dek { color: var(--muted); font-size: .95rem; margin: .35rem 0 0; }
.empty { color: var(--muted); }

.post .meta {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .8rem;
  color: var(--muted);
  margin: 0 0 2rem;
}

.repo-banner {
  border-left: 3px solid var(--link);
  padding: .6rem .9rem;
  background: var(--code-bg);
  font-size: .95rem;
  margin: 0 0 2rem;
}

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

blockquote {
  margin: 1.5rem 0;
  padding-left: 1rem;
  border-left: 3px solid var(--rule);
  color: var(--muted);
}

pre, code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .875rem; }
pre {
  background: var(--code-bg);
  padding: 1rem;
  overflow-x: auto;
  border-radius: 4px;
  line-height: 1.5;
}
code { background: var(--code-bg); padding: .1em .3em; border-radius: 3px; }
pre code { background: none; padding: 0; }

table { border-collapse: collapse; width: 100%; font-size: .92rem; display: block; overflow-x: auto; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--rule); }
th { font-weight: 600; }

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

.syndication, .next { color: var(--muted); font-size: .9rem; }

footer.site {
  margin-top: 4rem;
  padding-top: 1.5rem;
  padding-bottom: 3rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: .85rem;
}

figure {
  margin: 2.5rem 0;
}
figure img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--rule);
  border-radius: 4px;
}
figcaption {
  margin-top: .6rem;
  font-size: .85rem;
  line-height: 1.5;
  color: var(--muted);
}
figcaption b { color: var(--fg); font-weight: 600; }

/* A 4670px-wide flow diagram squeezed into the text measure is a 100px strip
   nobody can read. Wide figures keep a legible height and scroll inside their
   own box; the full-size viewer is still one click away. */
figure.wide .zoom {
  overflow-x: auto;
  overscroll-behavior-x: contain;
}
figure.wide img {
  width: auto;
  max-width: none;
  height: clamp(8rem, 20vh, 13rem);
}
figure.wide figcaption::after {
  content: " Scroll to read, or click to view full size.";
}

/* -- full-size figure viewer ------------------------------------------------ */

.post figure a.zoom { display: block; cursor: zoom-in; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  padding: 1.5rem;
  background: rgba(10, 10, 10, .93);
}
.lightbox[hidden] { display: none; }

.lightbox-scroll {
  max-width: 100%;
  max-height: 85vh;
  overflow: auto;
  display: flex;
  align-items: center;
}
.lightbox img {
  max-width: min(96vw, 1600px);
  max-height: 85vh;
  width: auto;
  height: auto;
  cursor: zoom-in;
  background: #fff;
  border-radius: 4px;
}
.lightbox.is-actual img {
  max-width: none;
  max-height: none;
  cursor: zoom-out;
}

.lightbox-caption {
  margin: 0;
  max-width: 44rem;
  color: #c9c9c5;
  font-size: .82rem;
  line-height: 1.5;
  text-align: center;
}

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: 1px solid rgba(255, 255, 255, .35);
  border-radius: 4px;
  color: #e8e8e6;
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .75rem;
  padding: .25rem .5rem;
  cursor: pointer;
}
.lightbox-close:hover { border-color: rgba(255, 255, 255, .7); }

/* KaTeX display blocks scroll instead of overflowing the measure. */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: .25rem 0; }

/* -- series label ----------------------------------------------------------- */

.eyebrow {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .7rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 .5rem;
}

/* -- home ------------------------------------------------------------------- */

.intro .thesis {
  font-size: 1.1rem;
  color: var(--fg);
  margin: 0 0 .75rem;
}
.intro .dek { font-size: .95rem; }

.posts .cards li {
  padding: 1.5rem 0 1.75rem;
}
.posts .cards li:first-child { padding-top: .5rem; }

.posts .thumb {
  display: block;
  max-width: 26rem;
  margin-bottom: 1rem;
}
.posts .thumb img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--rule);
  border-radius: 4px;
}
.posts .cards time { margin-top: .3rem; }

/* -- home: topic cards + one sortable list -------------------------------- */

/* Topic cards: one per series. They filter the list below (assets/js/home.js);
   without JS they are plain anchors and the full list still shows. */
.topics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr));
  gap: .75rem;
  margin: 1rem 0 2rem;
  padding: 0;
  list-style: none;
}
.topics li { padding: 0; border: 0; margin: 0; }
.topic {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  height: 100%;
  padding: .9rem 1rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--fg);
  text-decoration: none;
  transition: border-color .15s, background .15s;
}
.topic:hover { border-color: var(--muted); }
.topic.is-active {
  border-color: var(--fg);
  box-shadow: inset 0 0 0 1px var(--fg);
}
.topic-name { font-size: 1.02rem; font-weight: 600; line-height: 1.3; }
.topic-count {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .7rem;
  letter-spacing: .03em;
  color: var(--muted);
}
.nowrap { white-space: nowrap; }
.topic-short { font-size: .88rem; line-height: 1.45; color: var(--muted); }
/* Phones: a compact two-column grid, names and counts only, so the posts
   start within the first screen. */
@media (max-width: 30rem) {
  .topics { grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: 1.5rem; }
  .topic { padding: .65rem .7rem .7rem; gap: .2rem; }
  .topic-name { font-size: .92rem; }
  .topic-short { display: none; }
}

.list-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: .5rem 1rem;
  padding: .75rem 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  scroll-margin-top: 1rem;
}
.list-status { margin: 0; font-size: .9rem; color: var(--muted); flex: 1 1 18rem; }
#list-count { color: var(--fg); font-weight: 600; }
.sort {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .75rem;
  color: var(--muted);
}
.sort button {
  font: inherit;
  color: var(--muted);
  background: none;
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: .25rem .55rem;
  cursor: pointer;
}
.sort button[aria-pressed="true"] { color: var(--fg); border-color: var(--fg); }

/* The list: small thumbnail beside the text on wide screens, above it on phones. */
.post-list li {
  display: grid;
  grid-template-columns: 1fr;
  gap: .75rem;
  padding: 1.4rem 0;
  border-bottom: 1px solid var(--rule);
}
.post-list li:first-child { padding-top: 1.4rem; }
.post-list li[hidden] { display: none; }
.post-list .thumb { max-width: 100%; margin: 0; }
@media (min-width: 40rem) {
  .post-list li { grid-template-columns: 9.5rem 1fr; gap: 1.25rem; }
  .post-list li:not(:has(.thumb)) .post-text { grid-column: 2; }
}
.post-list .eyebrow { margin-bottom: .3rem; }
.post-list .title { font-size: 1.08rem; line-height: 1.35; }
.post-list .dek { margin: .35rem 0 0; font-size: .92rem; }

/* -- about ------------------------------------------------------------------ */

.about h1 { margin-bottom: 1.25rem; }
.about h2 { font-size: 1.05rem; }
.about ul { padding-left: 1.1rem; }
.about li { margin-bottom: .6rem; }
