/* ==========================================================================
   Design tokens
   Change a value here and it updates everywhere. Colours are defined once for
   light mode, then overridden for dark mode further down.
   ========================================================================== */

:root {
  --font-serif: "Newsreader", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Paper-white, slightly warm. Easier on the eyes than pure #fff. */
  --bg: #fcfcfa;
  --bg-soft: #f4f4f0;
  --bg-code: #f6f6f2;
  --text: #1b1b19;
  --text-muted: #6c6c64;
  --text-faint: #91918a;
  --rule: #e3e3dc;
  --rule-strong: #cfcfc6;
  --accent: #14504c;
  --accent-soft: #e2efec;

  --measure: 52rem;      /* text column width */
  --measure-wide: 64rem; /* for wide figures, code blocks and tables */
  --gutter: 1.25rem;

  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151a;
    --bg-soft: #1c1e24;
    --bg-code: #1a1c22;
    --text: #e6e6e1;
    --text-muted: #a0a099;
    --text-faint: #7a7a74;
    --rule: #2b2d34;
    --rule-strong: #3c3f47;
    --accent: #7fe3d6;
    --accent-soft: #1e2f30;
  }
}

/* ==========================================================================
   Base
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  /* Longer lines need more leading, or the eye loses its place on the
     return sweep. Paired with --measure; raise both together. */
  line-height: 1.72;
  font-synthesis-weight: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;

  /* Sticky footer: page fills the viewport even when content is short. */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wrap {
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

main.wrap {
  flex: 1 0 auto;
  padding-block: 3rem 4rem;
}

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

a:hover { text-decoration-thickness: 2px; }

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

.skip-link {
  position: absolute;
  left: -9999px;
}

.skip-link:focus {
  left: var(--gutter);
  top: 0.5rem;
  z-index: 10;
  background: var(--bg);
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 0.875rem;
}

/* ==========================================================================
   Header and footer
   ========================================================================== */

.site-header {
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-sans);
}

.site-header .wrap {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 1.25rem;
}

.site-name {
  font-weight: 600;
  font-size: 0.9375rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}

.site-name:hover { color: var(--accent); }

.site-nav {
  display: flex;
  gap: 1.25rem;
  font-size: 0.9375rem;
}

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

.site-nav a:hover { color: var(--text); }

/* The current page gets a subtle underline rather than a different colour,
   which stays legible for colour-blind readers. */
.site-nav a[aria-current="page"] {
  color: var(--text);
  font-weight: 500;
  box-shadow: inset 0 -2px 0 var(--accent);
}

.site-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--rule);
  padding-block: 1.75rem 2.5rem;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0 0 0.5rem;
}

.footer-colophon { margin: 0; color: var(--text-faint); }

/* ==========================================================================
   Prose — the shared typography for About pages and post bodies
   ========================================================================== */

.prose > *:first-child { margin-top: 0; }
.prose > *:last-child { margin-bottom: 0; }

.prose p { margin: 0 0 1.25rem; }

.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.25;
  color: var(--text);
}

.prose h2 {
  font-size: 1.25rem;
  margin: 2.75rem 0 0.875rem;
}

.prose h3 {
  font-size: 1.0625rem;
  margin: 2rem 0 0.625rem;
}

.prose h4 {
  font-size: 0.9375rem;
  margin: 1.5rem 0 0.5rem;
  color: var(--text-muted);
}

.page-title {
  font-family: var(--font-sans);
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.15;
  margin: 0 0 1.75rem;
}

.prose ul, .prose ol {
  margin: 0 0 1.25rem;
  padding-left: 1.25rem;
}

.prose li { margin-bottom: 0.4rem; }
.prose li > ul, .prose li > ol { margin-top: 0.4rem; margin-bottom: 0; }

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

.prose blockquote {
  margin: 1.5rem 0;
  padding-left: 1.125rem;
  border-left: 2px solid var(--rule-strong);
  color: var(--text-muted);
  font-style: italic;
}

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

.prose strong { font-weight: 600; }

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

/* Small-caps-ish lead-in for the first line of a section. Use with
   <p class="lead"> if you want a slightly larger opening paragraph. */
.prose .lead {
  font-size: 1.1875rem;
  line-height: 1.55;
  color: var(--text-muted);
}

/* --- Code ---------------------------------------------------------------- */

.prose code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-code);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  word-break: break-word;
}

.prose pre {
  background: var(--bg-code);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  margin: 1.5rem 0;
  overflow-x: auto;
  font-size: 0.8125rem;
  line-height: 1.6;
}

/* Let code blocks breathe past the narrow text column, but only once the
   viewport is actually wide enough to give them the room. */
@media (min-width: 68rem) {
  .prose pre {
    width: var(--measure-wide);
    margin-inline: calc((var(--measure) - var(--measure-wide)) / 2);
  }
}

.prose pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
  word-break: normal;
}

/* --- Tables -------------------------------------------------------------- */

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  /* Numbers line up in columns. */
  font-variant-numeric: tabular-nums;
}

.prose th, .prose td {
  text-align: left;
  padding: 0.5rem 0.75rem 0.5rem 0;
  border-bottom: 1px solid var(--rule);
}

.prose th {
  font-weight: 600;
  color: var(--text-muted);
  border-bottom-color: var(--rule-strong);
}

/* --- Figures ------------------------------------------------------------- */

.figure {
  margin: 2rem 0;
  /* Shrink to the image's own width so the caption lines up with it rather
     than running the full column under a narrow screenshot. */
  width: fit-content;
  max-width: 100%;
  margin-inline: auto;
}

.figure img {
  display: block;
  /* `width: auto` matters: it stops a small screenshot being blown up past
     its natural size, which just makes it blurry. Images scale down to fit
     the column but never up. */
  width: auto;
  height: auto;
  max-width: 100%;
  /* No single figure should swallow the whole screen. With width and height
     both auto, this scales tall figures down proportionally. */
  max-height: 78vh;
  border-radius: var(--radius);
  /* A pale backing so screenshots with transparent margins, and figures that
     are mostly white, still read as a distinct object in dark mode. */
  background: #fff;
  border: 1px solid var(--rule);
}

/* Dense multi-panel figures are unreadable at column width, so the image
   links to itself. Hint that it is clickable without shouting about it. */
.figure-zoom {
  display: block;
  cursor: zoom-in;
}

.figure-zoom:hover img {
  border-color: var(--rule-strong);
}

.figure figcaption {
  margin-top: 0.625rem;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--text-muted);
}

/* Small figures: incidental UI screenshots that are illustrative rather than
   evidence. Kept deliberately modest so they don't compete with the results. */
.figure-small { width: 26rem; }

/* Wide figures escape the text column. The explicit max-width is needed to
   override the `max-width: 100%` on .figure above, which would otherwise
   clamp them straight back to column width. */
@media (min-width: 68rem) {
  .figure-wide {
    width: var(--measure-wide);
    max-width: var(--measure-wide);
    margin-inline: calc((var(--measure) - var(--measure-wide)) / 2);
  }
}

.figure-full {
  width: 100vw;
  margin-inline: calc(50% - 50vw);
  border-radius: 0;
}

.figure-full img { border-radius: 0; }
.figure-full figcaption {
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* --- Math ----------------------------------------------------------------
   KaTeX supplies its own stylesheet; these rules only fix the two things it
   leaves to the page. Class names come from KaTeX, not from us. */

.katex-display {
  /* A long equation scrolls sideways instead of blowing out the layout —
     the usual failure mode on a phone. */
  overflow-x: auto;
  overflow-y: hidden;
  /* Room for the scrollbar, and for descenders on tall fractions. */
  padding-block: 0.5rem;
  margin-block: 1.25rem;
}

/* KaTeX marks commands it doesn't recognise with this class. */
.katex-error {
  font-family: var(--font-mono);
  font-size: 0.85em;
}

/* ==========================================================================
   About page extras
   ========================================================================== */

.intro {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-bottom: 2rem;
}

.intro-photo {
  flex: 0 0 auto;
  width: 104px;
  height: 104px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-soft);
}

.intro-text h1 {
  font-family: var(--font-sans);
  font-size: 1.625rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  margin: 0 0 0.25rem;
  line-height: 1.15;
}

.intro-role {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}

.intro-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  margin: 0;
}

@media (max-width: 34rem) {
  .intro { flex-direction: column; gap: 1rem; }
}

/* A "Now" / current-focus callout. */
.callout {
  background: var(--accent-soft);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1rem 1.125rem;
  margin: 2rem 0;
  font-size: 0.9375rem;
}

.callout > *:first-child { margin-top: 0; }
.callout > *:last-child { margin-bottom: 0; }

.callout-label {
  display: block;
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
}

/* Project list on the About page.
   Qualified with `ul` so it outranks the `.prose ul` indent rule above —
   without that, the list sits indented and stops aligning with its heading. */
ul.projects { list-style: none; padding: 0; margin: 0; }

.projects li {
  padding-block: 0.875rem;
  border-bottom: 1px solid var(--rule);
  margin: 0;
}

.projects li:first-child { border-top: 1px solid var(--rule); }

.project-name {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 600;
  display: block;
}

.project-blurb {
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin: 0.2rem 0 0;
}

/* ==========================================================================
   Blog index
   ========================================================================== */

/* `ul` qualifier needed to outrank `.prose ul`; see the note on ul.projects. */
ul.post-list { list-style: none; padding: 0; margin: 0; }

/* Standfirst under a page title, e.g. the blurb at the top of the blog index. */
.page-intro {
  color: var(--text-muted);
  margin: -0.75rem 0 2.5rem;
}

.year-heading {
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 2.5rem 0 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--rule);
}

.year-heading:first-of-type { margin-top: 0; }

.post-list li {
  padding-block: 1.125rem;
  border-bottom: 1px solid var(--rule);
}

.post-link {
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
  color: var(--text);
  text-decoration: none;
  display: inline-block;
}

.post-link:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

.post-list .post-meta { margin: 0.3rem 0 0; }

.post-excerpt {
  margin: 0.4rem 0 0;
  color: var(--text-muted);
  font-size: 0.9375rem;
  line-height: 1.55;
}

.post-meta {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--text-faint);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.post-meta .dot { color: var(--rule-strong); }

.tags { display: flex; flex-wrap: wrap; gap: 0.375rem; }

.tag {
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 100px;
  padding: 0.05rem 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.empty-state {
  color: var(--text-muted);
  font-style: italic;
}

/* ==========================================================================
   Single post
   ========================================================================== */

.post-header { margin-bottom: 2.25rem; }

.post-title {
  font-family: var(--font-sans);
  font-size: 1.875rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin: 0 0 0.625rem;
}

.post-standfirst {
  font-size: 1.125rem;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0 0 0.875rem;
}

.post-footer {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  font-family: var(--font-sans);
}

.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.75rem;
}

.post-nav-link {
  flex: 1 1 0;
  min-width: 0;
  text-decoration: none;
  color: var(--text);
}

.post-nav-right { text-align: right; }

.post-nav-label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.2rem;
}

.post-nav-title {
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.35;
}

.post-nav-link:hover .post-nav-title { color: var(--accent); }

.post-back { font-size: 0.875rem; margin: 0; }

/* ==========================================================================
   Syntax highlighting (Rouge)
   Two small themes, one per colour scheme. Rouge emits these class names.
   ========================================================================== */

.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs { color: #8a8a80; font-style: italic; }
.highlight .k, .highlight .kd, .highlight .kn, .highlight .kp, .highlight .kr, .highlight .kt { color: #8a4b9e; }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sb, .highlight .sd, .highlight .se, .highlight .sh, .highlight .si, .highlight .sx { color: #3f7d4e; }
.highlight .m, .highlight .mf, .highlight .mh, .highlight .mi, .highlight .il { color: #b05c1e; }
.highlight .nf, .highlight .nd { color: #2a5d9e; }
.highlight .nc, .highlight .nn { color: #1f6f6b; }
.highlight .nb, .highlight .bp { color: #8a4b9e; }
.highlight .o, .highlight .ow { color: #6c6c64; }
.highlight .err { color: #c1442e; }

@media (prefers-color-scheme: dark) {
  .highlight .c, .highlight .c1, .highlight .cm, .highlight .cs { color: #707068; }
  .highlight .k, .highlight .kd, .highlight .kn, .highlight .kp, .highlight .kr, .highlight .kt { color: #d09bea; }
  .highlight .s, .highlight .s1, .highlight .s2, .highlight .sb, .highlight .sd, .highlight .se, .highlight .sh, .highlight .si, .highlight .sx { color: #9ed49f; }
  .highlight .m, .highlight .mf, .highlight .mh, .highlight .mi, .highlight .il { color: #e8b17a; }
  .highlight .nf, .highlight .nd { color: #8fbdf0; }
  .highlight .nc, .highlight .nn { color: #7fe3d6; }
  .highlight .nb, .highlight .bp { color: #d09bea; }
  .highlight .o, .highlight .ow { color: #a0a099; }
  .highlight .err { color: #f08a72; }
}

/* ==========================================================================
   Print — so a post prints cleanly if someone wants it on paper
   ========================================================================== */

@media print {
  .site-header, .site-footer, .post-nav, .post-back, .skip-link { display: none; }
  body { background: #fff; color: #000; }
  main.wrap { max-width: none; padding: 0; }
  .prose pre, .prose code { border-color: #ccc; background: #f7f7f7; }
  a { text-decoration: underline; }
}
