/* =========================================================================
   Daniel J. Benjamin — site styles
   Direction: "Ledger" — cool grotesque type, ruled rows, year gutters.

   HOW TO ADJUST THINGS
   --------------------
   Colours, type and spacing are all set as custom properties in :root
   below. Change a value there and it updates everywhere on the site.
   Dark mode overrides live in the @media (prefers-color-scheme: dark)
   block immediately after :root — if you change a colour, change its
   dark counterpart too.
   ========================================================================= */

/* -------------------------------------------------------------------------
   0. Web fonts — self-hosted

   IBM Plex, served from assets/fonts/ rather than Google Fonts. Google's
   stylesheet was a render-blocking request to a third-party origin (~900ms
   before anything could paint), and it exposed every visitor's IP to Google.
   These are the identical woff2 files Google serves, so rendering is unchanged.

   Plex Sans is a VARIABLE font: one file covers 400-600, which is why the
   weight is declared as a range. Plex Mono is static 400.
   The unicode-range blocks are Google's own subsetting, kept intact so a
   browser only downloads latin-ext when a page actually uses those glyphs.
   Licensed under the SIL Open Font License 1.1 — see assets/fonts/LICENSE.txt.
   To refresh: node tools/fetch-fonts.js
   ---------------------------------------------------------------------- */

/* latin */
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url(../fonts/ibm-plex-sans-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* latin-ext */
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url(../fonts/ibm-plex-sans-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(../fonts/ibm-plex-mono-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* latin-ext */
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(../fonts/ibm-plex-mono-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* -------------------------------------------------------------------------
   1. Design tokens
   ---------------------------------------------------------------------- */
:root {
  /* Type families. Two webfonts only (IBM Plex Sans / Mono), each with a
     matching system fallback so there is no layout shift before they load. */
  --font-sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Colours — light mode. All body/UI text meets WCAG AA on --bg. */
  --ink:        #14181c;  /* primary text, strong rules            */
  --ink-2:      #3d444c;  /* secondary text (author lines)         */
  --ink-3:      #5d656e;  /* tertiary text (years, counts, notes)  */
  --rule:       #e3e6ea;  /* hairline rules between rows           */
  --bg:         #ffffff;  /* page background                       */
  --bg-alt:     #f7f9fb;  /* utility bar / quiet panels            */
  --accent:     #1f5480;  /* links, section labels, active states  */
  --accent-ink: #ffffff;  /* text on accent-filled surfaces        */
  --tag-bg:     #eef2f6;  /* research-area chips                   */
  --focus:      #b8560f;  /* focus ring — deliberately non-blue    */

  /* Spacing scale (used for page padding and vertical rhythm). */
  --gap-1: 0.375rem;
  --gap-2: 0.75rem;
  --gap-3: 1.25rem;
  --gap-4: 2rem;
  --gap-5: 3rem;
  --gap-6: 4.5rem;

  /* Layout */
  --measure: 70ch;        /* reading measure for prose             */
  --page-max: 1180px;     /* max content width                     */
  --page-pad: 1.25rem;    /* horizontal page padding (mobile)      */
}

@media (min-width: 640px)  { :root { --page-pad: 2rem; } }
@media (min-width: 1024px) { :root { --page-pad: 4rem; } }

/* Dark mode. Driven only by the OS setting; nothing is stored or scripted,
   so there is no flash on load. Delete this block to disable dark mode. */
@media (prefers-color-scheme: dark) {
  :root {
    --ink:        #e9edf1;
    --ink-2:      #bcc4cc;
    --ink-3:      #98a1aa;
    --rule:       #2b3238;
    --bg:         #14181c;
    --bg-alt:     #1a2027;
    --accent:     #8fbde4;
    --accent-ink: #10151a;
    --tag-bg:     #232b33;
    --focus:      #f0a15a;
  }
}

/* -------------------------------------------------------------------------
   2. Base
   ---------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: var(--page-max);
  margin-inline: auto;
  padding-inline: var(--page-pad);
}

/* Prose blocks get a comfortable 65–75 character measure. */
.prose { max-width: var(--measure); }
.prose p { margin: 0 0 var(--gap-3); text-wrap: pretty; }
.prose p:last-child { margin-bottom: 0; }

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

/* Visible focus everywhere, keyboard-only where the browser supports it. */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 1px;
}

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

/* Skip link — visible as soon as it receives focus. */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: var(--bg);
  padding: 0.75rem 1rem;
  z-index: 100;
}
.skip-link:focus { left: 0; color: var(--bg); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* -------------------------------------------------------------------------
   3. Header and navigation
   ---------------------------------------------------------------------- */
.site-header {
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-3);
  min-height: 60px;
}

.brand {
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
  padding-block: 0.75rem;
}

/* Menu button: hidden by default so that with JavaScript disabled the full
   nav list is simply shown. The `js` class is set in an inline script. */
.nav-toggle { display: none; }

.site-nav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.5rem;
  margin: 0;
  padding: 0;
}

.site-nav a {
  display: block;
  padding: 0.75rem 0;          /* keeps tap targets ≥44px tall */
  min-height: 44px;
  font-size: 0.875rem;
  color: var(--ink-2);
  text-decoration: none;
}
.site-nav a:hover { color: var(--ink); text-decoration: underline; }
.site-nav a[aria-current="page"] {
  color: var(--ink);
  font-weight: 500;
  box-shadow: inset 0 -2px 0 var(--accent);
}

/* Mobile nav (below 900px, and only when JS is available). */
@media (max-width: 899px) {
  .js .nav-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0 0.75rem;
    background: var(--bg);
    border: 1px solid var(--rule);
    border-radius: 3px;
    color: var(--ink);
    font: 500 0.875rem/1 var(--font-sans);
    cursor: pointer;
  }
  .js .site-nav {
    display: none;
    width: 100%;
    border-top: 1px solid var(--rule);
  }
  .js .site-nav.is-open { display: block; }
  .header-inner { flex-wrap: wrap; }
  .site-nav ul { flex-direction: column; gap: 0; padding-bottom: 0.5rem; }
  .site-nav li + li { border-top: 1px solid var(--rule); }
  .site-nav a { padding: 0.875rem 0; font-size: 1rem; }
  .site-nav a[aria-current="page"] { box-shadow: inset 3px 0 0 var(--accent); padding-left: 0.75rem; }
}

/* -------------------------------------------------------------------------
   4. Page furniture
   ---------------------------------------------------------------------- */
main { display: block; }

.page-head { padding-top: var(--gap-5); }

h1, h2, h3 { letter-spacing: -0.02em; line-height: 1.15; }

.page-title {
  margin: 0;
  font-size: clamp(1.75rem, 1.2rem + 2.4vw, 2.375rem);
  font-weight: 600;
}

.page-sub {
  margin: var(--gap-1) 0 0;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--ink-3);
}

/* Small uppercase section label (also used for publication sections). */
.eyebrow {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}

.site-footer {
  margin-top: var(--gap-6);
  border-top: 1px solid var(--rule);
  padding-block: var(--gap-4);
  font-size: 0.875rem;
  color: var(--ink-3);
}
.site-footer .footer-inner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-2) var(--gap-4);
  justify-content: space-between;
}
.site-footer a { color: var(--ink-2); }

/* -------------------------------------------------------------------------
   5. Home
   ---------------------------------------------------------------------- */
.home-grid {
  display: grid;
  gap: var(--gap-4);
  padding-top: var(--gap-4);
}
@media (min-width: 900px) {
  .home-grid {
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: var(--gap-6);
    padding-top: var(--gap-6);
    align-items: start;
  }
}
@media (min-width: 1200px) {
  .home-grid { grid-template-columns: minmax(0, 1fr) 340px; }
}

.home-title {
  margin: 0;
  font-size: clamp(2.125rem, 1.1rem + 4.4vw, 3.25rem);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.05;
  text-wrap: balance;
}

/* The three current appointments: a ruled ledger with a monospace year
   gutter. Rows stack on narrow screens. */
.appointments {
  list-style: none;
  margin: var(--gap-4) 0 0;
  padding: 0;
  border-top: 1px solid var(--ink);
}
.appointments li {
  display: grid;
  gap: 0.25rem 1.5rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
}
@media (min-width: 640px) {
  .appointments li { grid-template-columns: 8.5rem minmax(0, 1fr); padding: 1.25rem 0; }
}
.appointments .years {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--ink-3);
  padding-top: 0.15rem;
}
.appointments .role { max-width: 46ch; text-wrap: pretty; }

/* Portrait is shown uncropped at its native 1012×1568 proportions. */
/* The portrait ships as WebP with a JPEG fallback, so the <picture> wrapper is
   the grid item and has to lay out like the image used to. */
.home-grid picture { display: block; }

.portrait {
  display: block;
  width: 100%;
  max-width: 240px;
  height: auto;
  background: var(--bg-alt);
}
@media (min-width: 900px) { .portrait { max-width: 100%; } }

/* -------------------------------------------------------------------------
   6. Publications page
   ---------------------------------------------------------------------- */

/* Sticky utility bar: search + filters. Sticks to the top of the viewport. */
.pub-tools {
  position: sticky;
  top: 0;
  z-index: 20;
  margin-top: var(--gap-4);
  background: var(--bg-alt);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding-block: 0.75rem;
}
.pub-tools .tools-inner { display: grid; gap: 0.5rem; }
@media (min-width: 900px) {
  .pub-tools .tools-inner {
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 0.75rem;
  }
}

.field {
  min-height: 44px;
  padding: 0 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.4 var(--font-sans);
}
@media (min-width: 900px) { .field { font-size: 0.875rem; } }
input.field::placeholder { color: var(--ink-3); }

/* Research-area filter buttons. */
.facets { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.facets .facet {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 0 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--bg);
  color: var(--ink-2);
  font: 500 0.8125rem/1 var(--font-sans);
  cursor: pointer;
  white-space: nowrap;
}
.facets .facet[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}
.facets .facet:hover { color: var(--ink); }
.facets .facet[aria-pressed="true"]:hover { color: var(--bg); }

.tools-status {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-3);
  padding-top: 0.25rem;
}

/* Section jump-nav — real anchors, works without JS. */
.section-nav {
  border-bottom: 1px solid var(--rule);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.section-nav ul {
  display: flex;
  gap: 1.5rem;
  list-style: none;
  margin: 0;
  padding: 0;
  white-space: nowrap;
}
.section-nav a {
  display: inline-block;
  min-height: 44px;
  padding: 0.85rem 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-2);
  text-decoration: none;
}
.section-nav a:hover { color: var(--ink); }
.section-nav a.is-current { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
.section-nav .count { font-family: var(--font-mono); font-weight: 400; color: var(--ink-3); }

/* A publication section. */
.pub-section { padding-top: var(--gap-5); scroll-margin-top: 5.5rem; }
.pub-list {
  list-style: none;
  margin: 0.875rem 0 0;
  padding: 0;
  border-top: 1px solid var(--ink);
}

/* One entry: year gutter + citation body. */
.pub {
  display: grid;
  gap: 0.35rem 1.75rem;
  padding: 1.125rem 0;
  border-bottom: 1px solid var(--rule);
}
@media (min-width: 768px) {
  .pub { grid-template-columns: 5rem minmax(0, 1fr); padding: 1.375rem 0; }
}
.pub[hidden] { display: none; }

.pub .year {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--ink-3);
  padding-top: 0.1rem;
}
.pub .body { max-width: var(--measure); }

.pub .title {
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--ink);
  text-decoration: none;
}
.pub .title:hover { color: var(--accent); text-decoration: underline; }

.pub .authors {
  margin: 0.35rem 0 0;
  font-size: 0.9375rem;
  color: var(--ink-2);
  line-height: 1.55;
  text-wrap: pretty;
}
.pub .authors .me { font-weight: 600; color: var(--ink); }
.pub .venue { font-style: italic; }

/* Author truncation control (added by JS; hidden when JS is off). */
.authors-more {
  border: 0;
  background: none;
  padding: 0 0 0 0.25rem;
  font: 400 0.875rem/1.4 var(--font-mono);
  color: var(--ink-3);
  cursor: pointer;
  text-decoration: underline;
}
.authors-more:hover { color: var(--ink); }

/* Secondary links: appendices, FAQs, code, corrigenda. */
.pub .extras {
  margin: 0.4rem 0 0;
  font-size: 0.875rem;
  color: var(--ink-3);
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
}
.pub .note { margin: 0.4rem 0 0; font-size: 0.875rem; color: var(--ink-3); }

.pub .tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  list-style: none;
  margin: 0.55rem 0 0;
  padding: 0;
}
.pub .tags li {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.45rem;
  background: var(--tag-bg);
  color: var(--ink-2);
}

.empty-state {
  padding: var(--gap-5) 0;
  font-size: 1rem;
  color: var(--ink-3);
}

/* -------------------------------------------------------------------------
   7. Media page (grouped link lists)
   ---------------------------------------------------------------------- */
.media-list {
  list-style: none;
  margin: 0.875rem 0 0;
  padding: 0;
  border-top: 1px solid var(--ink);
  max-width: var(--measure);
}
.media-list li {
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--ink-2);
  text-wrap: pretty;
}
.media-list a { font-weight: 500; }

/* -------------------------------------------------------------------------
   8. Contact
   ---------------------------------------------------------------------- */
.contact-grid { display: grid; gap: var(--gap-4); padding-top: var(--gap-4); }
@media (min-width: 768px) { .contact-grid { grid-template-columns: repeat(2, minmax(0, 22rem)); gap: var(--gap-6); } }
.contact-grid h2 { margin: 0 0 0.5rem; font-size: 0.8125rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3); }
.contact-grid address { font-style: normal; line-height: 1.65; }
.email-link { min-height: 44px; display: inline-flex; align-items: center; font-weight: 500; }

/* -------------------------------------------------------------------------
   9. Motion
   ---------------------------------------------------------------------- */
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

