:root {
  --bg: #ffffff;
  --fg: #2e5894; /* text: B'dazzled Blue */
  --muted: #6b7891;
  --line: rgba(46, 88, 148, 0.06);
  --rule: rgba(46, 88, 148, 0.16);
  --accent: #2e5894;
  --header-ink: #d1a76b; /* difference-blends to #2e5894 over white */
  --cursor: #2e5894; /* same blue as the text, for the cursor and link previews */
  --ink-2: #3a5583;
  --gutter: 16px;
  color-scheme: light;
  --sans: "Inter Tight", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
}

:root[data-theme="dark"] {
  --bg: #0e0f12;
  --fg: #ecebe8;
  --muted: #8f8f8f;
  --line: rgba(255, 255, 255, 0.06);
  --rule: rgba(255, 255, 255, 0.16);
  --accent: #7487bd; /* the shirt navy, lifted so it reads on dark */
  --header-ink: #ffffff;
  --cursor: #5b8cff;
  --ink-2: #c4c4c2;
  color-scheme: dark;
}

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

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

::selection { background: var(--accent); color: #fff; }

a { color: inherit; text-decoration: none; }
a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

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

.wrap {
  position: relative;
  max-width: 1920px;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* ---------- Layout grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--gutter);
}
@media (min-width: 768px) {
  .grid { grid-template-columns: repeat(8, minmax(0, 1fr)); }
}
@media (min-width: 1200px) {
  .grid { grid-template-columns: repeat(12, minmax(0, 1fr)); }
}

main, header, footer { position: relative; z-index: 1; }

/* ---------- Type helpers ---------- */
.caps {
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.muted { color: var(--muted); }
.serif { font-family: var(--serif); }

/* ---------- Header: a row of ruled cells (carried over from version 2) ---------- */
/* Transparent, always on top; difference blend keeps it legible over any content or theme */
.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  color: var(--header-ink);
  mix-blend-mode: difference;
}
.bar {
  max-width: 1920px;
  margin: 0 auto;
  padding: 16px var(--gutter) 0;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0 var(--gutter);
  align-items: stretch;
}
/* One continuous rule under the whole menu, drawn inside the page margins */
.bar::after {
  content: "";
  grid-column: 1 / -1;
  border-bottom: 1px solid currentColor;
}
.nav, .nav ul { display: contents; }
.nav ul { list-style: none; margin: 0; padding: 0; }

.cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding-bottom: 12px;
  font-size: 13px;
  letter-spacing: 0.05em;
  line-height: 1.35;
  text-transform: uppercase;
  min-width: 0;
}
.brand strong { font-weight: 600; letter-spacing: 0.02em; }

.nav a { display: inline-flex; align-items: center; gap: 7px; }
.nav a::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  display: none;
}
.nav a.active::before, .nav a:hover::before { display: inline-block; }
.nav a.active { font-weight: 600; }

.cell--actions { align-items: flex-end; }
.theme-toggle, .menu-toggle {
  background: none; border: 0; padding: 0; margin: 0;
  font: inherit; color: inherit; text-transform: uppercase; letter-spacing: inherit;
  cursor: pointer;
}
.theme-toggle::before { content: "[ "; }
.theme-toggle::after { content: " ]"; }
.theme-toggle:focus-visible, .menu-toggle:focus-visible { outline: 1px solid currentColor; outline-offset: 4px; }
.menu-toggle { display: none; }

/* Eight cells need room: below 900px the row collapses to name + buttons */
@media (max-width: 899px) {
  .bar { grid-template-columns: 1fr auto; }
  .nav { display: none; }
  .cell--actions { flex-direction: row; gap: 18px; align-items: flex-start; }
  .menu-toggle { display: inline-block; }
  .menu-toggle::before { content: "[ "; }
  .menu-toggle::after { content: " ]"; }

  /* When the menu is open, drop the blend so the panel is solid and readable */
  .site-header.menu-open { mix-blend-mode: normal; color: var(--fg); background: var(--bg); }
  .site-header.menu-open .nav {
    display: block;
    position: absolute;
    top: 100%; left: 0; right: 0;
    background: var(--bg);
    padding: 8px var(--gutter) 24px;
    border-bottom: 1px solid var(--fg);
  }
  .site-header.menu-open .nav ul { display: block; }
  .site-header.menu-open .nav .cell { padding: 12px 0; border-bottom: 1px solid var(--rule); }
  .site-header.menu-open .nav .cell:last-child { border-bottom: 0; }
  .site-header.menu-open .nav a {
    font-size: 22px; font-weight: 400;
    text-transform: none; letter-spacing: -0.01em;
  }
}

/* ---------- Intro: name, lead and photo beside the bio ---------- */
.contact > .wrap { width: 100%; flex: 1; display: flex; flex-direction: column; justify-content: space-between; }
.intro { padding: 112px 0 96px; }
@media (min-width: 768px) { .intro { padding-top: 128px; padding-bottom: 112px; } }

.intro-side { grid-column: 1 / -1; }
.display {
  font-weight: 400;
  font-size: clamp(2.4rem, 5.6vw, 5.25rem);
  line-height: 0.98;
  letter-spacing: -0.03em;
  margin: 0 0 0 -0.04em;
}
.display .dot { color: var(--accent); }
.lead {
  margin: 24px 0 40px;
  font-size: clamp(1.05rem, 1.4vw, 1.3rem);
  line-height: 1.35;
  letter-spacing: -0.005em;
  color: var(--muted);
  max-width: 40ch;
}

.portrait { margin: 0; width: 75%; } /* 25% smaller than its column */
.portrait img {
  width: 100%;
  height: auto; /* override the HTML height attribute */
  aspect-ratio: 4 / 5;
  object-fit: cover;
  object-position: 50% 20%; /* keeps his head and the space above it in frame */
  background: #f2f2f2;
}

.bio {
  grid-column: 1 / -1;
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.6;
  margin-top: 48px;
  scroll-margin-top: 128px;
}
.bio p { margin: 0 0 1.1em; max-width: 62ch; }
.bio p:last-child { margin-bottom: 0; }
.bio p:first-child {
  font-family: var(--sans);
  font-size: clamp(1.2rem, 1.7vw, 1.5rem);
  line-height: 1.32;
  letter-spacing: -0.015em;
  margin-bottom: 1.4em;
}

@media (min-width: 768px) {
  .intro-side { grid-column: 1 / span 3; }
  .bio { grid-column: 4 / -1; margin-top: 0; padding-top: 0.35em; } /* first line level with the name */
  .bio { margin-bottom: -8.4px; } /* pull the row up to the last line's baseline, so the photo ends exactly on it */

  /* The photo fills the rest of the left column, so its bottom edge lands on the bio's last line */
  .intro-side { display: flex; flex-direction: column; }
  .portrait { flex: 1 1 auto; display: flex; flex-direction: column; position: relative; }
  .portrait img { flex: 1 1 0; min-height: 280px; aspect-ratio: auto; }
}
@media (min-width: 1200px) {
  .intro-side { grid-column: 1 / span 4; }
  .bio { grid-column: 6 / span 7; }
}

/* ---------- Sections ---------- */
.section {
  padding: 96px 0;
  border-top: 1px solid var(--rule);
}
@media (min-width: 768px) { .section { padding: 112px 0; } }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 48px;
}
.section-title {
  margin: 0;
  font-weight: 400;
  font-size: clamp(1.5rem, 3.2vw, 2.8rem);
  line-height: 1.05;
  letter-spacing: -0.025em;
}
.section-index { color: var(--muted); }

/* ---------- Research interests ---------- */
.interests {
  list-style: none;
  margin: 0; padding: 0;
  grid-column: 1 / -1;
  counter-reset: i;
}
.interests li {
  counter-increment: i;
  display: grid;
  grid-template-columns: 3.5rem 1fr;
  gap: var(--gutter);
  padding: 22px 0;
  border-bottom: 1px solid var(--rule);
  align-items: baseline;
}
.interests li::before {
  content: counter(i, decimal-leading-zero);
  font-size: 13px;
  color: var(--muted);
}
.interests h3 {
  margin: 0;
  font-weight: 400;
  font-size: clamp(1.5rem, 3.2vw, 2.8rem);
  letter-spacing: -0.025em;
  line-height: 1.05;
}
.interests p {
  grid-column: 2;
  margin: 8px 0 0;
  font-family: var(--serif);
  color: var(--ink-2);
  max-width: 60ch;
}
@media (min-width: 1200px) {
  .interests li { grid-template-columns: 1fr 6fr 5fr; }
  .interests p { grid-column: 3; margin: 0; }
}

/* ---------- Publications ---------- */
.pub-group {
  grid-column: 1 / -1;
  margin-bottom: 64px;
}
.pub-group:last-child { margin-bottom: 0; }
.pub-group > h3,
.pub-group > details > summary {
  margin: 0 0 8px;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  display: flex;
  justify-content: space-between;
  padding-bottom: 4px;
}
.pub-group > details > summary { cursor: pointer; list-style: none; }
.pub-group > details > summary::-webkit-details-marker { display: none; }
.pub-group > details > summary .toggle::after { content: "+ Show"; font-weight: 400; color: var(--muted); }
.pub-group > details[open] > summary .toggle::after { content: "− Hide"; }

.pubs { list-style: none; margin: 0; padding: 0; }
.pubs li {
  display: grid;
  grid-template-columns: 4.5rem 1fr;
  gap: var(--gutter);
  padding: 18px 0;
  border-bottom: 1px solid var(--rule);
}
.pubs .yr { font-size: 14px; color: var(--muted); padding-top: 3px; }
.pubs .cite {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.5;
  max-width: 78ch;
}
.pubs .cite .t { font-family: var(--sans); font-weight: 500; font-size: 18px; letter-spacing: -0.01em; display: block; margin-bottom: 4px; }
.pubs .cite .venue { font-style: italic; }
.pubs .cite .note { color: var(--muted); }
.pubs a.cite-link {
  display: inline-block;
  margin-top: 6px;
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--accent);
  color: var(--accent);
}
.pubs a.cite-link:hover { color: var(--fg); border-color: var(--fg); }

@media (min-width: 1200px) {
  .pub-group { grid-column: 3 / -1; }
}

/* ---------- Tables (teaching / cv) ---------- */
.rows { grid-column: 1 / -1; list-style: none; margin: 0; padding: 0; }
.rows li {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px var(--gutter);
  padding: 20px 0;
  border-bottom: 1px solid var(--rule);
}
.rows .when { font-size: 14px; color: var(--muted); }
.rows .what { font-size: clamp(1.15rem, 1.8vw, 1.5rem); letter-spacing: -0.015em; line-height: 1.2; }
.rows .where { font-family: var(--serif); color: var(--ink-2); }
@media (min-width: 768px) {
  .rows li { grid-template-columns: 2fr 3fr 3fr; align-items: baseline; }
}

.cv-block { grid-column: 1 / -1; margin-bottom: 72px; }
.cv-block:last-of-type { margin-bottom: 0; }
.cv-block > h3 {
  margin: 0 0 16px;
  font-weight: 600; font-size: 13px; letter-spacing: 0.05em; text-transform: uppercase;
}

.cv-download {
  grid-column: 1 / -1;
  margin-top: 64px;
}

.btn-line {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  font-size: clamp(1.15rem, 1.8vw, 1.5rem);
  letter-spacing: -0.015em;
  border-bottom: 1px solid var(--fg);
  padding-bottom: 6px;
  transition: color .25s, border-color .25s;
}
.btn-line:hover { color: var(--accent); border-color: var(--accent); }
.btn-line .arr { transition: transform .3s; }
.btn-line:hover .arr { transform: translateY(3px); }

/* ---------- Arrows: drawn with CSS masks rather than ↗/↓ characters,
   which iOS renders as emoji ---------- */
.arr {
  display: inline-block;
  width: 0.62em; height: 0.62em;
  vertical-align: 0.02em;
  background: currentColor;
  -webkit-mask: var(--arr) center / contain no-repeat;
          mask: var(--arr) center / contain no-repeat;
}
.arr--ne { --arr: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M2 8L8 2M3 2h5v5' fill='none' stroke='%23000' stroke-width='1.1'/%3E%3C/svg%3E"); }
.arr--down { --arr: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M5 1v8M1.5 5.5L5 9l3.5-3.5' fill='none' stroke='%23000' stroke-width='1.1'/%3E%3C/svg%3E"); }

/* ---------- Contact ---------- */
.contact {
  display: flex;
  flex-direction: column;
  padding: 112px 0 72px;
  border-top: 1px solid var(--rule);
}
.contact .display { font-size: clamp(1.5rem, 3.2vw, 2.8rem); line-height: 1.05; letter-spacing: -0.025em; }
.contact-grid { align-items: end; }
.contact-grid .intro {
  grid-column: 1 / -1;
  font-size: clamp(1.15rem, 1.8vw, 1.5rem);
  line-height: 1.3;
  letter-spacing: -0.01em;
  max-width: 30ch;
  margin: 0 0 40px;
}
.contact-links { grid-column: 1 / -1; }
.mail {
  display: block;
  width: fit-content;
  max-width: 100%;
  font-size: clamp(1.25rem, 2.2vw, 1.9rem);
  line-height: 1.2;
  letter-spacing: -0.015em;
  overflow-wrap: anywhere;
  padding: 4px 0;
  transition: color .25s;
}
.mail:hover { color: var(--accent); }
.socials { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 20px; }
.socials a { font-size: 17px; border-bottom: 1px solid var(--rule); }
.socials a:hover { border-color: var(--accent); color: var(--accent); }
.credit { border-bottom: 1px solid var(--rule); transition: color .25s, border-color .25s; }
.credit:hover { color: var(--accent); border-color: var(--accent); }

.site-footer .wrap {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 24px;
  padding-top: 20px;
  padding-bottom: 20px;
  border-top: 1px solid var(--rule);
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Cursor ---------- */
.cursor {
  position: fixed;
  top: 0; left: 0;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--cursor);
  pointer-events: none;
  z-index: 2000;
  opacity: 0;
  transition: opacity .3s;
  will-change: transform;
}
.cursor.visible { opacity: 1; }
.cursor.down { width: 10px; height: 10px; margin: -5px 0 0 -5px; }
@media (hover: none), (pointer: coarse) { .cursor { display: none; } }

@media (prefers-reduced-motion: reduce) { .cursor { display: none; } }

/* ---------- Link preview: a small square that appears above external links ---------- */
.link-preview {
  position: fixed;
  top: 0; left: 0;
  width: 200px; height: 200px;
  border: 1px solid var(--cursor);
  border-radius: 0;
  background: var(--bg);
  pointer-events: none;
  z-index: 1500;
  opacity: 0;
  visibility: hidden;
  transition: opacity .15s, visibility 0s .15s;
}
.link-preview.on { opacity: 1; visibility: visible; transition: opacity .15s; }
.link-preview img { width: 100%; height: 100%; object-fit: cover; object-position: top left; }
@media (hover: none), (pointer: coarse) { .link-preview { display: none; } }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip:focus {
  position: fixed; top: 12px; left: 12px; z-index: 2100;
  width: auto; height: auto; clip: auto; margin: 0;
  background: var(--accent); color: #fff; padding: 8px 14px;
}
