/* ---------- Design tokens ---------- */
:root {
  --bg: #faf8f4;
  --bg-alt: #f1eee7;
  --surface: #ffffff;
  --ink: #1b2430;
  --muted: #566170;
  --line: #e0dbd0;
  --accent: #0d6b73;
  --accent-ink: #ffffff;
  --accent-soft: #dcefee;
  --warm: #b4501e;
  --bead: #0d6b73;
  --bond: #6f9599;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(20 30 40 / 6%), 0 8px 24px rgb(20 30 40 / 6%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151c;
    --bg-alt: #131b24;
    --surface: #18212c;
    --ink: #e8ecf1;
    --muted: #a3adba;
    --line: #2a3644;
    --accent: #5cc4cc;
    --accent-ink: #0b1218;
    --accent-soft: #17323a;
    --warm: #f0a070;
    --bead: #5cc4cc;
    --bond: #4d7479;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 30%);
  }
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1.0625rem/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
}

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

a { color: var(--accent); text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

[hidden] { display: none !important; }

h1, h2, h3, h4 { font-family: var(--serif); line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: clamp(1.7rem, 3.2vw, 2.3rem); margin-bottom: 1rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.25rem; }
p { margin: 0 0 1rem; }

.wrap { width: min(100% - 2rem, 70rem); margin-inline: auto; }

section { padding-block: clamp(3rem, 7vw, 5.5rem); }
section.alt { background: var(--bg-alt); }
.section-intro { color: var(--muted); max-width: 46rem; margin-bottom: 2rem; }

.skip-link {
  position: absolute; left: 1rem; top: -4rem; z-index: 100;
  background: var(--accent); color: var(--accent-ink);
  padding: 0.6rem 1rem; border-radius: 8px;
}
.skip-link:focus { top: 1rem; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.25rem 1.5rem; padding-block: 0.6rem; }
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none; }
.site-header nav > ul { display: flex; flex-wrap: wrap; gap: 0.1rem 1.1rem; list-style: none; margin: 0; padding: 0; }
.site-header nav > ul > li > a { display: inline-block; padding: 0.3rem 0; color: var(--muted); text-decoration: none; font-size: 0.97rem; font-weight: 500; }
.site-header nav > ul > li > a:hover, .site-header nav > ul > li > a[aria-current] { color: var(--accent); }

/* "Research" menu: opens on hover or keyboard focus (wide screens only; on phones the link goes to the Research section) */
.header-inner { position: relative; }
.fundamental { --group: var(--accent); }
.applied { --group: var(--warm); }
.submenu { display: none; position: absolute; right: 0; top: calc(100% - 0.6rem); width: min(46rem, 100%); padding-top: 0.6rem; z-index: 60; }
.has-menu:hover .submenu, .has-menu:focus-within .submenu { display: block; }
.submenu-box { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 2rem; padding: 1.1rem 1.3rem 0.9rem; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.submenu ul { list-style: none; margin: 0; padding: 0; }
.submenu-label { margin: 0 0 0.45rem; padding-bottom: 0.35rem; border-bottom: 3px solid var(--group); color: var(--group); font: 700 0.76rem/1.4 var(--sans); letter-spacing: 0.08em; text-transform: uppercase; }
.submenu a { display: block; padding: 0.3rem 0; color: var(--ink); text-decoration: none; font-size: 0.95rem; font-weight: 500; line-height: 1.35; }
.submenu a:hover, .submenu a[aria-current] { color: var(--group); text-decoration: underline; }
@media (max-width: 47.99rem) { .has-menu .submenu { display: none !important; } }

/* ---------- Hero ---------- */
.hero { position: relative; overflow: hidden; padding-block: clamp(2.5rem, 7vw, 6rem); border-bottom: 1px solid var(--line); }
#bead-bg {
  position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none;
  opacity: 0.5;
  /* index.js puts the centre and radius of the portrait in --pcx, --pcy and --pr, so no chain is ever
     drawn behind the portrait (its picture is opaque paper that is blended into the page) */
  --hole: radial-gradient(circle at var(--pcx, -99px) var(--pcy, -99px), rgb(0 0 0 / 0%) calc(var(--pr, 0px) * 1.05), #000 calc(var(--pr, 0px) * 1.9));
  /* quiet behind the text on the left, stronger on the open right-hand side */
  -webkit-mask-image: var(--hole), linear-gradient(to right, rgb(0 0 0 / 22%), #000 80%);
  mask-image: var(--hole), linear-gradient(to right, rgb(0 0 0 / 22%), #000 80%);
  -webkit-mask-composite: source-in;
  mask-composite: intersect;
}
@media (max-width: 47.99rem) {
  #bead-bg { opacity: 0.28; -webkit-mask-image: var(--hole); mask-image: var(--hole); }
}
.hero-inner { position: relative; }
/* Three arrangements from the same markup, portrait always on the right: phone = stacked; tablet = name
   on top, portrait beside the description; wide (from 50rem) = portrait spans the whole name + description block. */
.hero-intro {
  display: grid; align-items: center; column-gap: 1.25rem; row-gap: 0;
  grid-template-columns: 1fr;
  grid-template-areas: "portrait" "name" "lead" "tagline";
}
.hero-intro .portrait { grid-area: portrait; justify-self: end; margin-bottom: 1rem; }
.hero-intro h1 { grid-area: name; }
.hero-intro .lead { grid-area: lead; }
.hero-intro .tagline { grid-area: tagline; }
/* The sketch is blended into the page: the paper colour disappears, the strokes are softened,
   and the edge dissolves instead of ending in a frame. Tune --sketch-strength to taste. */
/* negative margin: the faded edge makes the visible sketch end a little inside the box */
.portrait { --sketch-strength: 0.72; margin: 0 -0.5rem 0 0; width: 8rem; aspect-ratio: 1; }
.portrait img {
  width: 100%; height: 100%; object-fit: cover;
  opacity: var(--sketch-strength);
  mix-blend-mode: multiply;
  -webkit-mask-image: radial-gradient(closest-side, #000 66%, rgb(0 0 0 / 60%) 86%, transparent 100%);
  mask-image: radial-gradient(closest-side, #000 66%, rgb(0 0 0 / 60%) 86%, transparent 100%);
}
@media (prefers-color-scheme: dark) {
  /* multiply would make dark pencil vanish on a dark page, and inverting flips the shading:
     show the sketch as a dimmed sheet of paper that dissolves into the page instead */
  .portrait { --sketch-strength: 0.9; }
  .portrait img { mix-blend-mode: normal; filter: brightness(0.78); }
}
.eyebrow { font-size: 0.82rem; font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.9rem; }
.hero h1 { font-size: clamp(2.4rem, 7vw, 4.2rem); margin-bottom: 0.4rem; }
.lead { font-family: var(--serif); font-size: clamp(1.15rem, 2.6vw, 1.5rem); color: var(--ink); margin-bottom: 0.7rem; }
.tagline { max-width: 42rem; margin: 0; color: var(--muted); font-size: 1.1rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.7rem; margin: 3rem 0 0; }

.btn {
  display: inline-block; padding: 0.65rem 1.2rem; border-radius: 999px;
  border: 1.5px solid var(--accent); color: var(--accent);
  font-weight: 600; font-size: 0.97rem; text-decoration: none; background: transparent;
  transition: background 0.15s, color 0.15s;
}
.btn:hover { background: var(--accent-soft); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.1); }
.btn-ghost { border-color: var(--line); color: var(--muted); }

@media (min-width: 40rem) {
  .hero-intro {
    grid-template-columns: 1fr auto;
    grid-template-areas: "name name" "lead portrait" "tagline portrait";
  }
  /* index.js makes the square a little larger than the text so the visible sketch spans the text, and gives
     the extra size back through these (negative) margins, so the text does not move */
  .hero-intro .portrait { margin-top: var(--portrait-up, 0px); margin-bottom: var(--portrait-down, 0px); margin-left: var(--portrait-drop, 0px); width: var(--portrait-size, 12rem); }
  /* the portrait is taller than lead + description here: keep the two text rows together
     instead of letting the spanned rows stretch apart */
  .hero-intro .lead { align-self: end; }
  .hero-intro .tagline { align-self: start; }
}
@media (min-width: 50rem) {
  .hero-intro { grid-template-areas: "name portrait" "lead portrait" "tagline portrait"; }
  .hero-intro .lead, .hero-intro .tagline { align-self: center; }
}
/* Line the portrait up with the letters themselves: trim the text boxes to the capitals of the name (top)
   and the baseline of the last line (bottom), and put back the space this removes. index.js then sets
   --portrait-size to the height of that block. */
@supports (text-box: trim-both cap alphabetic) {
  @media (min-width: 40rem) { .hero-intro .tagline { text-box: trim-end cap alphabetic; } .actions { margin-top: 3.5rem; } }
  @media (min-width: 50rem) { .hero-intro h1 { text-box: trim-start cap alphabetic; } .hero .eyebrow { margin-bottom: 2.2rem; } }
}

/* ---------- About ---------- */
.about-grid { display: grid; gap: 2rem; }
.prose { max-width: 40rem; }
.facts { margin: 0; display: grid; gap: 0.9rem; align-content: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.4rem; box-shadow: var(--shadow); }
.facts dt { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.facts dd { margin: 0.1rem 0 0; font-weight: 500; }
@media (min-width: 52rem) { .about-grid { grid-template-columns: 1.6fr 1fr; gap: 3rem; } }
.more { margin: 1.5rem 0 0; font-weight: 600; }

/* ---------- Research ---------- */
.theme-group + .theme-group { margin-top: 4rem; }
/* each group has its own colour: teal for fundamentals, warm orange for applications */
.theme-group { --group: var(--accent); }
.theme-group.applied { --group: var(--warm); }
.group-head { border-top: 4px solid var(--group); padding-top: 0.8rem; margin-bottom: 0; }
.theme-group h3 { font-size: clamp(1.4rem, 2.6vw, 1.8rem); color: var(--group); margin-bottom: 0.4rem; }
.theme-group .card { border-color: var(--group); border-color: color-mix(in srgb, var(--group) 55%, var(--line)); border-top: 4px solid var(--group); }
.theme-group .key-papers span { color: var(--group); }
.group-intro { color: var(--muted); max-width: 46rem; margin-bottom: 1.5rem; }
.cards { display: grid; gap: 1.5rem; }
@media (min-width: 52rem) { .cards { grid-template-columns: repeat(2, 1fr); } }
/* wide screens: the two groups run side by side, one card per row in each */
@media (min-width: 64rem) {
  .theme-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 1.75rem; }
  .theme-group + .theme-group { margin-top: 0; }
  .theme-group .cards { grid-template-columns: 1fr; }
  .group-intro { max-width: none; }
}
/* where supported, rows of the two groups line up card by card */
@supports (grid-template-rows: subgrid) {
  @media (min-width: 64rem) {
    .theme-groups { row-gap: 1.5rem; }
    .theme-group { display: grid; grid-template-rows: subgrid; grid-row: span 5; row-gap: inherit; }
    .theme-group .cards { grid-template-rows: subgrid; grid-row: span 4; row-gap: inherit; }
  }
}

.card { position: relative; transition: transform 0.15s, box-shadow 0.15s; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.card-link { color: inherit; text-decoration: none; }
.card-link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }  /* the whole card is the link */
.card-link span { color: var(--group, var(--accent)); display: inline-block; transition: transform 0.15s; }
.card:hover { transform: translateY(-2px); }
.card:hover .card-link { color: var(--group, var(--accent)); text-decoration: underline; text-underline-offset: 0.18em; }
.card:hover .card-link span { transform: translateX(3px); }
.card-link:focus-visible { outline: none; }
.card-link:focus-visible::after { outline: 3px solid var(--accent); outline-offset: -3px; }
.card .key-papers a { position: relative; z-index: 1; }  /* paper links stay clickable above the card link */
.card-art { margin: 0; background: var(--accent-soft); aspect-ratio: 16 / 10; border-bottom: 1px solid var(--line); }
.card-art img { width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: 1.3rem 1.4rem 1.5rem; display: flex; flex-direction: column; gap: 0.2rem; flex: 1; }
.card-body h4 { margin-bottom: 0.6rem; }
.card-body p { color: var(--muted); }
.key-papers { margin-top: auto; padding-top: 0.6rem; border-top: 1px dashed var(--line); font-size: 0.94rem; margin-bottom: 0; }
.key-papers span { display: block; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--warm); margin-bottom: 0.25rem; }

.software { margin-top: 2.5rem; background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: var(--radius); padding: 1.3rem 1.5rem; box-shadow: var(--shadow); }
.software h3 { font-size: 0.8rem; font-family: var(--sans); text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); margin-bottom: 0.7rem; }
.software-name { font-family: var(--serif); font-size: 1.35rem; font-weight: 700; margin-bottom: 0.4rem; }
.software p:last-child { margin-bottom: 0; color: var(--muted); }
.tag { display: inline-block; vertical-align: middle; margin-left: 0.3rem; padding: 0.1rem 0.55rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font: 600 0.72rem/1.6 var(--sans); letter-spacing: 0.02em; }

/* ---------- Publications ---------- */
.pubs { display: grid; gap: 2rem; }
.pub-year { display: grid; gap: 0.6rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.pub-year h2, .pub-year h3 { font-size: 1.6rem; color: var(--accent); margin: 0; }
.pub-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.1rem; }
.pub-list p { margin: 0; }
.pub-title { font-weight: 600; line-height: 1.4; }
.pub-authors { color: var(--muted); font-size: 0.93rem; }
.pub-authors strong { color: var(--ink); }
.pub-venue { color: var(--muted); font-size: 0.93rem; overflow-wrap: anywhere; }
@media (min-width: 44rem) {
  .pub-year { grid-template-columns: 6rem 1fr; gap: 1.5rem; }
  .pub-year h2, .pub-year h3 { position: sticky; top: 5rem; align-self: start; }
}

/* ---------- Recognition ---------- */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; max-width: 52rem; }
.timeline li { display: grid; gap: 0.1rem 1.5rem; padding-block: 0.95rem; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.when { font-family: var(--serif); font-size: 1.25rem; font-weight: 700; color: var(--accent); }
@media (min-width: 40rem) { .timeline li { grid-template-columns: 6rem 1fr; align-items: baseline; } }

.what .meta { display: block; color: var(--muted); font-size: 0.93rem; }
.subhead { margin: 2.75rem 0 0.7rem; }
.page-head .subhead { margin-top: 3.5rem; }

/* ---------- Career & education page ---------- */
.page-head h1 { font-size: clamp(2rem, 5vw, 3rem); margin-bottom: 0.8rem; }
.page-head .eyebrow { margin-bottom: 1.2rem; }
.page-head h1 + :not(.section-intro) { margin-top: 1.75rem; }  /* pages without an intro line */
.page-head .eyebrow a { color: inherit; text-decoration: none; }
.page-head .eyebrow a:hover { text-decoration: underline; }
.background { display: grid; gap: 2.5rem; margin-top: 2.75rem; }
.background h2 { margin-bottom: 0.4rem; }
.background .timeline li { padding-block: 0.75rem; }
@media (min-width: 52rem) { .background { grid-template-columns: 1.5fr 1fr; gap: 3rem; } }
.cv-links { display: flex; flex-wrap: wrap; gap: 0.7rem; margin: 0; }

/* ---------- Research direction pages ---------- */
.dir-kicker { margin: 0 0 0.5rem; color: var(--group); font: 700 0.8rem/1.4 var(--sans); letter-spacing: 0.09em; text-transform: uppercase; }
.dir-intro { display: grid; gap: 1.75rem; align-items: center; margin-top: 1.75rem; }
@media (min-width: 52rem) { .dir-intro { grid-template-columns: 1.15fr 1fr; gap: 3rem; } }
.dir-lead { max-width: 40rem; margin: 0 0 1.25rem; font-size: 1.15rem; }
.dir-related { margin: 0; color: var(--muted); }
.dir-related span { display: inline-block; margin-right: 0.4rem; color: var(--group); font: 700 0.76rem/1.4 var(--sans); letter-spacing: 0.08em; text-transform: uppercase; }
.dir-art { margin: 0; aspect-ratio: 16 / 10; overflow: hidden; background: var(--accent-soft); border: 1px solid var(--line); border-top: 4px solid var(--group); border-radius: var(--radius); box-shadow: var(--shadow); }
.dir-art img { width: 100%; height: 100%; object-fit: cover; }
.dir-all { display: grid; gap: 1.5rem 2.5rem; }
@media (min-width: 40rem) { .dir-all { grid-template-columns: 1fr 1fr; } }
.dir-all ul { list-style: none; margin: 0; padding: 0; }
.dir-all-label { margin: 0 0 0.5rem; padding-bottom: 0.4rem; border-bottom: 3px solid var(--group); color: var(--group); font: 700 0.78rem/1.4 var(--sans); letter-spacing: 0.08em; text-transform: uppercase; }
.dir-all li { margin: 0; }
.dir-all a { display: block; padding: 0.35rem 0; text-decoration: none; }
.dir-all a:hover { text-decoration: underline; }
.dir-all a[aria-current] { color: var(--muted); font-weight: 700; pointer-events: none; }
.page-head .software { margin-top: 2.5rem; }

/* ---------- Group page ---------- */
.group-art { margin: 1.75rem 0 0; max-width: 40rem; aspect-ratio: 640 / 420; overflow: hidden; background: var(--accent-soft); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.group-art img { width: 100%; height: 100%; }
.recipe { list-style: none; margin: 0 0 1.5rem; padding: 0; max-width: 40rem; }
.recipe li { padding: 0.7rem 0; border-bottom: 1px solid var(--line); }
.recipe li:last-child { border-bottom: 0; }
.recipe span { display: block; color: var(--warm); font: 700 0.76rem/1.4 var(--sans); letter-spacing: 0.08em; text-transform: uppercase; }
.group-note { max-width: 40rem; margin: 0; color: var(--muted); }

/* ---------- Teaching ---------- */
.teaching-grid { display: grid; gap: 1.25rem; }
@media (min-width: 40rem) { .teaching-grid { grid-template-columns: repeat(2, 1fr); } }
.teach-block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.4rem; box-shadow: var(--shadow); }
.teach-block h2 { font-size: 1.15rem; margin-bottom: 0.15rem; }
.teach-sub { color: var(--muted); font-size: 0.92rem; margin-bottom: 0.8rem; }
.teach-block.wide { grid-column: 1 / -1; }
.course-list { margin: 0; padding-left: 1.1rem; }
.course-list li { margin-bottom: 0.55rem; }
.course-list .meta { display: block; color: var(--muted); font-size: 0.9rem; line-height: 1.45; }
.level-grid { display: grid; gap: 1.25rem; margin-top: 1.1rem; }
.level + .level { border-top: 1px solid var(--line); padding-top: 1.25rem; }
.level h3 { font: 700 0.78rem/1.4 var(--sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--warm); margin-bottom: 0.6rem; }
@media (min-width: 52rem) {
  .level-grid { grid-template-columns: repeat(3, 1fr); gap: 2rem; }
  .level + .level { border-top: 0; padding-top: 0; border-left: 1px solid var(--line); padding-left: 2rem; }
}

/* ---------- Links ---------- */
.link-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); }
.link-grid a { display: block; height: 100%; padding: 1.1rem 1.25rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); box-shadow: var(--shadow); transition: border-color 0.15s, transform 0.15s; }
.link-grid a:hover { border-color: var(--accent); transform: translateY(-2px); }
.link-title { display: block; font-family: var(--serif); font-weight: 700; font-size: 1.15rem; color: var(--accent); }
.link-sub { display: block; font-size: 0.9rem; color: var(--muted); margin-top: 0.15rem; }

.contact { margin-top: 2.25rem; font-style: normal; color: var(--muted); line-height: 1.7; }
.contact strong { color: var(--ink); }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding-block: 2rem; color: var(--muted); font-size: 0.92rem; }
.site-footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem 1.5rem; }
.site-footer p { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .btn, .link-grid a { transition: none; }
  .link-grid a:hover { transform: none; }
}

@media print {
  .site-header, #bead-bg, .skip-link, .actions { display: none; }
  body { background: #fff; color: #000; }
  section { padding-block: 1.25rem; }
}
