:root {
  --bg: #ffffff;
  --panel: #f6f8fa;
  --fg: #16202a;
  --muted: #5b6875;
  --line: #d8dee6;
  --accent: #0b6e7a;
  --accent-soft: #e6f1f3;
  --wrap: 1060px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161b;
    --panel: #171e25;
    --fg: #e6edf3;
    --muted: #9bacbd;
    --line: #2a343f;
    --accent: #5ac8d8;
    --accent-soft: #17323a;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 20px; }

.skip {
  position: absolute; left: -9999px;
}
.skip:focus {
  left: 12px; top: 12px; z-index: 10; background: var(--accent); color: #fff;
  padding: 8px 14px; border-radius: 6px;
}

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

/* ---------- header ---------- */

header.site {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--line);
}

.bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; min-height: 60px; flex-wrap: wrap;
}

.brand {
  font-weight: 650; letter-spacing: -0.01em; color: var(--fg); text-decoration: none;
}
.brand .deg { color: var(--muted); font-weight: 400; }

header nav { display: flex; gap: 18px; flex-wrap: wrap; }
header nav a {
  color: var(--muted); text-decoration: none; font-size: 0.92rem;
}
header nav a:hover { color: var(--accent); }

/* ---------- sections ---------- */

section { padding: 56px 0; }
/* .wrap's `padding: 0 20px` is a class selector, so it beats `section` above and zeroes the
   vertical padding of every <section class="wrap">. Restate all four sides here (section.wrap
   outranks .wrap) so plain sections get the same 56px as the shaded .band ones. */
section.wrap { padding: 56px 20px; }

.band { background: var(--panel); border-block: 1px solid var(--line); }

h1 {
  font-size: clamp(1.9rem, 4.2vw, 2.9rem);
  line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 18px; max-width: 22ch;
}

h2 {
  font-size: clamp(1.3rem, 2.4vw, 1.7rem);
  letter-spacing: -0.01em; margin: 0 0 14px;
}

h3 { font-size: 1.08rem; margin: 30px 0 10px; }
h4 { font-size: 0.98rem; margin: 0 0 6px; }

p { /* no measure cap: paragraphs run the full column width */ }

.eyebrow {
  text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.76rem;
  color: var(--accent); margin: 0 0 14px; font-weight: 600;
}

.lede { font-size: 1.06rem; color: var(--muted); }

.note { font-size: 0.9rem; color: var(--muted); }

/* ---------- hero ---------- */

.hero { padding: 72px 0 60px; }
/* books/papers: the hero is text only, so it sits closer to the first section
   than the home page's hero, which carries the portrait. */
.hero.compact { padding-bottom: 26px; }
.hero.compact + section.wrap { padding-top: 26px; }

/* Portrait sits to the right of the opening text on a wide screen, below it on a
   phone, where it closes the hero just above "What I work on". */
.hero-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 52px;
  align-items: center;
}

.hero-text { min-width: 0; }

.portrait {
  order: 2;
  width: clamp(264px, 25vw, 360px);
  /* The width/height attributes on the <img> reserve the box before the file
     loads. They also become presentation hints, which beat aspect-ratio, so
     without height:auto the portrait stretches into a strip wherever the CSS
     width is narrower than the attribute says. */
  height: auto;
  aspect-ratio: 1;
  border-radius: 5%;
  object-fit: cover;
  border: 1px solid var(--line);
  background: var(--panel);
}

.thread {
  margin: 24px 0 0;
  padding-left: 14px;
  border-left: 3px solid var(--accent);
  font-size: 1rem;
  color: var(--fg);
}

.chips {
  list-style: none; display: flex; flex-wrap: wrap; gap: 8px;
  padding: 0; margin: 26px 0 0;
}
.chips li {
  font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--fg); background: var(--accent-soft);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px;
}

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 26px; max-width: none; }

.btn {
  display: inline-block; padding: 9px 16px; border-radius: 7px;
  border: 1px solid var(--line); color: var(--fg); text-decoration: none;
  font-size: 0.93rem; background: var(--bg);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { color: #fff; filter: brightness(1.08); }
.btn[data-todo] { opacity: 0.55; }

/* ---------- cards ---------- */

.cards { display: grid; gap: 16px; margin-top: 22px; }
.cards.four { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.cards.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.cards.three { grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }

.card {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 18px 18px 16px;
}
.card p { max-width: none; margin: 0 0 8px; }
.card ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 0.94rem; }
.card li { margin: 4px 0; }

.topics { font-size: 0.85rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }

/* ---------- TERRA ---------- */

.contrast { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin: 26px 0; }
.contrast blockquote {
  margin: 0; padding: 16px 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg);
}
.contrast .new { border-color: var(--accent); background: var(--accent-soft); }
.contrast .label {
  text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.72rem;
  color: var(--muted); margin: 0 0 8px;
}
.contrast p { max-width: none; margin: 0; }

.grid.six { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-top: 16px; }
.q {
  border-left: 3px solid var(--accent); padding: 4px 0 4px 14px;
}
.q p { margin: 0; color: var(--muted); font-size: 0.94rem; max-width: none; }

/* ---------- studies ---------- */

.study {
  border-top: 1px solid var(--line); padding: 22px 0 6px;
}
.study h3 { margin: 0 0 10px; font-size: 1.15rem; }
.study .sub { color: var(--muted); margin: 0 0 10px; font-size: 0.95rem; }

.study .tag {
  text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.72rem;
  color: var(--accent); font-weight: 600; margin: 0 0 6px;
}

/* the measurement-choice pipeline: 12 hypotheses -> 5 readings -> 1 recommended */
.pipeline {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
  margin: 0 0 14px;
}
.pipeline span {
  display: inline-flex; align-items: baseline; gap: 7px;
  font-size: 0.9rem; color: var(--muted);
}
.pipeline span strong { font-size: 1.5rem; color: var(--fg); font-weight: 700; line-height: 1; }
.pipeline span + span::before { content: "→"; color: var(--accent); margin-right: 6px; }

.headline-stat {
  margin: 0 0 14px; font-size: 0.95rem; color: var(--muted);
}
.headline-stat strong {
  display: block; font-size: 1.9rem; line-height: 1.1; color: var(--accent);
  letter-spacing: -0.02em; margin-bottom: 2px;
}

.bench { width: auto; min-width: min(360px, 100%); margin: 4px 0 16px; }
.bench th, .bench td { padding: 8px 18px 8px 0; }
.bench thead th {
  font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 600; border-top: none;
}
.bench td:last-child { text-align: left; font-variant-numeric: tabular-nums; }
.bench .win td { font-weight: 700; color: var(--accent); }
.demo {
  font-size: 0.85rem; color: var(--muted);
}
.more { margin-top: 26px; }

/* ---------- tables ---------- */

table { border-collapse: collapse; width: 100%; margin-top: 18px; font-size: 0.95rem; }
th, td { text-align: left; vertical-align: top; padding: 11px 12px; border-top: 1px solid var(--line); }
th[scope="row"] { font-weight: 550; padding-left: 0; }
table td:last-child { text-align: right; white-space: nowrap; }

.books th .sub { display: block; font-weight: 400; color: var(--muted); font-size: 0.88rem; }
.skills th[scope="row"] { width: 34%; }
.skills td { color: var(--muted); text-align: left; white-space: normal; }

/* ---------- experience ---------- */

.role { border-top: 1px solid var(--line); padding: 22px 0 4px; }
.role h3 { margin: 0; font-size: 1.08rem; }
.role .meta { color: var(--muted); font-size: 0.92rem; margin: 2px 0 10px; }
.role ul { padding-left: 18px; color: var(--muted); font-size: 0.95rem; }
.role li { margin: 3px 0; }

.education { padding-left: 18px; }
.education li { margin: 6px 0; }
.certs { font-size: 0.88rem; color: var(--muted); }

/* ---------- contact + footer ---------- */

.contact .address { font-size: 1.1rem; margin-top: 14px; }

footer.site {
  border-top: 1px solid var(--line); padding: 24px 0; margin-top: 20px;
  color: var(--muted); font-size: 0.9rem;
}
footer .wrap { display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; }

@media (max-width: 760px) {
  .hero-inner { grid-template-columns: 1fr; gap: 28px; }
  /* order:2 is inherited, so the portrait follows the hero text and closes the
     section just above "What I work on". */
  .portrait { width: min(288px, 74%); justify-self: center; }
}

@media (max-width: 640px) {
  body { font-size: 16px; }
  section { padding: 40px 0; }
  section.wrap { padding: 40px 20px; }
  .book-grid { gap: 18px; grid-template-columns: 1fr; }
  .hero { padding: 48px 0 40px; }
  header nav { gap: 12px; }
  header nav a { font-size: 0.86rem; }
  table td:last-child { white-space: normal; }
}

/* ---------- papers + books pages ---------- */

h2 .count {
  font-size: 0.8rem; font-weight: 600; color: var(--muted);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 9px; margin-left: 8px; vertical-align: middle;
  /* inside h2.domain the badge is a flex item: keep the pill at its own content
     width instead of letting it take the leftover space on a wrapped line. */
  max-width: fit-content;
}

ul.papers { list-style: none; padding: 0; margin: 18px 0 0; }
ul.papers li {
  border-top: 1px solid var(--line); padding: 13px 0;
  display: flex; gap: 14px; justify-content: space-between; align-items: baseline; flex-wrap: wrap;
}
ul.papers li a { font-size: 1.02rem; text-decoration: none; }
ul.papers li a:hover { text-decoration: underline; }
ul.papers .meta { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }

.book-grid {
  display: grid; gap: 26px; margin-top: 26px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.book {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden;
  /* share the grid's rows so heading, cover, blurb and button line up across a row,
     however long a title or blurb runs. Four children, four tracks. */
  display: grid; grid-row: span 4; grid-template-rows: subgrid;
}
@supports not (grid-template-rows: subgrid) {
  .book { display: flex; flex-direction: column; }
  .book .more { margin-top: auto; }
}
.book-cover { display: block; line-height: 0; }
/* width/height on the <img> are presentation hints that beat aspect-ratio, so the
   cover needs height:auto to scale instead of stretching. */
.book-cover img {
  width: 100%; height: auto; display: block;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.book-head { padding: 16px 18px 13px; }
.book-blurb { padding: 15px 18px 0; margin: 0; }
.book-head h2.domain {
  font-size: 1.06rem; margin: 0 0 8px; line-height: 1.3;
  /* a card is ~320px wide: without this the row wraps and drops the icon onto its own line */
  flex-wrap: nowrap; align-items: flex-start; gap: 9px;
}
.book-head h2.domain > span { padding-top: 1px; }
.book-head .domain-icon { width: 20px; height: 20px; padding: 3px; margin-top: 1px; }
.book-head h2.domain .sub {
  display: block; font-size: 0.84rem; font-weight: 400; color: var(--muted); margin-top: 3px;
}
.book-blurb { font-size: 0.94rem; }
.book .more { margin: 0; padding: 14px 18px 18px; align-self: end; }
.book h2 { font-size: 1.16rem; margin: 0 0 8px; }
.book h2 .sub { display: block; font-size: 0.92rem; font-weight: 400; color: var(--muted); margin-top: 3px; }
.book .more { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.book .meta { color: var(--muted); font-size: 0.88rem; }

/* domain icons on the papers and books pages */
h2.domain {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
h2.domain > span { flex: 1 1 auto; min-width: 0; }
.domain-icon {
  width: 26px; height: 26px; flex: none;
  color: var(--accent);
  padding: 4px; box-sizing: content-box;
  background: var(--accent-soft); border: 1px solid var(--line); border-radius: 8px;
}
.book h2.domain > span { font-weight: 650; }
