:root {
  --ink: #171b20;
  --muted: #5f6872;
  --faint: #8a929a;
  --line: #e4e8ec;
  --line-strong: #d1d7dd;
  --paper: #ffffff;
  --wash: #f5f7f8;
  --accent: #286fd1;
  --accent-dark: #1856a4;
  --selected: #ed1b2f;
  --max-width: 880px;
  --reading-width: 700px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 0.9rem;
  line-height: 1.67;
  text-rendering: optimizeLegibility;
}

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

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-dark);
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

h1,
h2,
h3 {
  margin-top: 0;
  font-weight: 560;
  letter-spacing: -0.025em;
  line-height: 1.18;
}

h1 {
  max-width: 850px;
  margin-bottom: 1rem;
  font-size: clamp(1.65rem, 3.7vw, 2.65rem);
}

h2 {
  margin-bottom: 1.15rem;
  font-size: clamp(1.2rem, 2.4vw, 1.6rem);
}

h3 {
  margin-bottom: 0.45rem;
  font-size: 0.98rem;
}

p {
  margin: 0 0 1.25rem;
}

/* ==========================================================================
   Header and navigation
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1.5px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.nav-shell {
  width: min(calc(100% - 5rem), var(--max-width));
  min-height: 5.15rem;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
}

.brand-heading {
  margin: 0;
  padding: 0;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
}

.brand,
.brand:visited,
.brand:hover,
.brand:focus,
.brand:active {
  display: inline-flex;
  width: 12.5rem;
  height: 5.15rem;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  background:
    linear-gradient(rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0.4)),
    url("/assets/images/header-background-long.jpg") center / 100% 100% no-repeat;
  font-size: 1.55rem;
  font-weight: 630;
  letter-spacing: 0.005em;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}

.brand span {
  display: inline;
  color: inherit;
}

.brand span + span {
  margin-left: 0.35em;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.55rem;
}

.site-nav a {
  position: relative;
  padding: 1.75rem 0 1.55rem;
  color: var(--muted);
  font-size: 1.15rem;
  text-decoration: none;
}

.site-nav a::after {
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: transparent;
  content: "";
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--ink);
}

.site-nav a[aria-current="page"]::after {
  background: var(--selected);
}

.menu-toggle {
  display: none;
  padding: 0.5rem;
  border: 0;
  color: var(--ink);
  background: transparent;
  font: inherit;
}

.menu-toggle span {
  display: block;
  width: 1.35rem;
  height: 1px;
  margin: 0.3rem 0;
  background: currentColor;
}

/* ==========================================================================
   Layout
   ========================================================================== */
main {
  width: min(calc(100% - 8rem), var(--max-width));
  min-height: calc(100vh - 12rem);
  margin: 0 auto;
  padding: clamp(3.4rem, 8vw, 6.5rem) 0 5rem;
}

/* Slightly more space above the About section. */
main:has(> .home-intro) {
  padding-top: clamp(2.5rem, 4vw, 3.4rem);
}

/* Slightly more breathing room above page titles. */
main:has(> .page-intro) {
  padding-top: clamp(2.6rem, 5vw, 3.8rem);
}

.research-detail main {
  max-width: var(--reading-width);
}

.reading-column {
  max-width: var(--reading-width);
}

.item-meta {
  color: var(--muted);
  font-size: 0.86rem;
  letter-spacing: 0.025em;
}

.page-intro {
  padding-bottom: clamp(2.5rem, 6vw, 4.5rem);
  border-bottom: 1.5px solid var(--line-strong);
}

.page-intro--no-rule {
  /* padding-bottom: 1.5rem; */
  border-bottom: 0;
}

.text-link {
  font-size: 0.94rem;
  font-weight: 560;
}

/* ==========================================================================
   Home
   ========================================================================== */
.home-intro {
  display: grid;
  grid-template-columns: minmax(140px, 180px) minmax(0, 1fr);
  gap: clamp(2rem, 4vw, 3rem);
  align-items: start;
  max-width: 820px;
  margin-right: auto;
  margin-left: auto;
}

.home-heading {
  margin-bottom: 1.65rem;
  font-size: clamp(1.45rem, 2.8vw, 1.9rem);
}

.contact-line {
  margin-top: 1.8rem;
}

.profile-photo {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  object-position: center;
  filter: saturate(0.86) contrast(1.02);
}

.home-portrait {
  width: 100%;
  max-width: 180px;
  justify-self: start;
}

.social-links {
  display: flex;
  gap: 0.8rem;
  margin-top: 1.75rem;
}

.social-links a {
  display: inline-flex;
  width: 1.75rem;
  height: 1.75rem;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.social-links a:hover {
  opacity: 0.72;
}

.social-links img {
  width: 1.55rem;
  height: 1.55rem;
  border: 0;
  object-fit: contain;
}

/* ==========================================================================
   Research list
   ========================================================================== */
.section-block {
  margin-top: clamp(4rem, 9vw, 7rem);
}

.page-intro--no-rule + .section-block {
  margin-top: 0;
}

/* Keep the horizontal rule close to the page title. */
.page-intro:has(+ .section-block),
.page-intro:has(+ .project-entry) {
  padding-bottom: clamp(0.4rem, 1.2vw, 0.7rem);
}

/* Bring the Projects page title closer to its horizontal rule. */
main:has(.project-entry) > .page-intro:not(.page-intro--no-rule),
main:has(.project-list) > .page-intro:not(.page-intro--no-rule) {
  padding-bottom: 0.2rem;
}

/* Projects page: match the research detail page title-to-divider spacing.
   The :has() selectors also work if the HTML has no projects-page body class. */
.projects-page .page-intro,
body:has(main .project-entry) main > .page-intro,
body:has(main .project-list) main > .page-intro {
  padding-bottom: clamp(0.4rem, 1.2vw, 0.7rem);
}

.projects-page .page-intro h1,
body:has(main .project-entry) main > .page-intro h1,
body:has(main .project-list) main > .page-intro h1 {
  margin-bottom: 0;
}

.projects-page .page-intro + .section-block,
body:has(main .project-entry) main > .page-intro + .section-block,
body:has(main .project-list) main > .page-intro + .section-block {
  margin-top: 0;
}

/* Prevent default last-child margins from creating extra space above the rule. */
.page-intro > h1:last-child,
.page-intro > p:last-child {
  margin-bottom: 0;
}

.page-intro + .project-entry {
  margin-top: 0;
}

.work-list,
.project-list {
  border-top: 1.5px solid var(--line-strong);
}

.work-item {
  display: grid;
  grid-template-columns: 8rem minmax(0, 1fr) auto;
  gap: 1.5rem;
  align-items: start;
  padding: 1.8rem 0;
  border-bottom: 1.5px solid var(--line);
}

.work-item h2 {
  margin-bottom: 0.45rem;
}

.work-item p {
  max-width: 610px;
  margin-bottom: 0;
  color: var(--muted);
}

.work-title-link,
.work-title-link:visited,
.work-title-link:hover,
.work-title-link:focus,
.work-title-link:active {
  color: var(--ink);
  text-decoration: none;
}

.work-title-link:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.14em;
}

/* ==========================================================================
   Research detail pages
   ========================================================================== */
.article-section {
  max-width: var(--reading-width);
  margin-top: clamp(3.25rem, 7vw, 5.4rem);
}

.article-section h2 {
  padding-bottom: 0;
  border-bottom: none;
}

.research-detail h1 {
  font-size: clamp(1.45rem, 3vw, 2.05rem);
}

.research-detail h2 {
  font-size: clamp(1.1rem, 2vw, 1.35rem);
}

.research-detail h3 {
  font-size: 0.96rem;
}

.research-detail .page-intro {
  padding-bottom: clamp(0.4rem, 1.2vw, 0.7rem);
}

.research-detail .page-intro + .article-section {
  margin-top: clamp(1.25rem, 3vw, 2rem);
}

.equation {
  margin: 1.8rem 0;
  background: var(--paper);
  text-align: center;
}

.equation math[display="block"] {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  font-size: clamp(0.9rem, 2.2vw, 1.12rem);
}

.thesis-link {
  display: grid;
  grid-template-columns: minmax(150px, 230px) minmax(0, 1fr);
  gap: clamp(1.6rem, 5vw, 3.5rem);
  align-items: center;
  max-width: 800px;
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1.5px solid var(--line);
}

.thesis-link img {
  border: 1px solid var(--line-strong);
}

.thesis-link h3 {
  font-size: 1.12rem;
}

/* ==========================================================================
   Media and image fallbacks
   ========================================================================== */
.media {
  max-width: 900px;
  margin: 2.4rem 0 3.2rem;
}

.media img {
  width: 100%;
  height: auto;
  border: 0;
  background: var(--wash);
}

.media--rounded img {
  border-radius: 4px;
}

.media.home-portrait {
  margin-top: 4.5rem;
}

.research-detail main > figure.media {
  width: min(92%, 640px);
  max-width: 640px;
  margin-right: auto;
  margin-left: auto;
}

.research-detail main > figure.media--narrow {
  max-width: 80%;
  margin: 2rem auto;
}

.research-detail main > figure.media--reduced-plot {
  max-width: 70%;
}

.research-detail figure.media > img {
  margin-right: auto;
  margin-left: auto;
}

.asset-fallback {
  display: none;
  min-height: 320px;
  padding: 2rem;
  border: 1.5px solid var(--line);
  align-items: center;
  justify-content: center;
  background: var(--wash);
  color: var(--muted);
  text-align: center;
}

.media.is-missing img {
  display: none;
}

.media.is-missing .asset-fallback {
  display: flex;
}

.media--portrait .asset-fallback {
  min-height: 420px;
}

/* ==========================================================================
   Projects
   ========================================================================== */
.project-entry {
  display: grid;
  grid-template-columns: minmax(260px, 42%) minmax(0, 1fr);
  gap: clamp(2rem, 7vw, 5rem);
  align-items: center;
  padding: clamp(1.75rem, 4vw, 3rem) 0;
  border-bottom: 1.5px solid var(--line);
}

/* Entry with a stacked column of images beside the text. */
.project-entry--split {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

.project-entry:nth-child(even) .project-media {
  order: 2;
}

.work-item:last-child,
.project-entry:last-child {
  border-bottom: 0;
}

.project-entry .media {
  margin: 0;
}

.project-media--stack {
  display: flex;
  flex: 0 0 380px;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  max-width: 100%;
}

.project-media--stack .media {
  width: 100%;
  margin: 0 auto;
}

.project-media--stack .media--inset {
  width: 85%;
}

.project-content {
  flex: 1;
  min-width: 280px;
}

.project-media--diagram img {
  padding: clamp(1rem, 3vw, 1.75rem);
  background: var(--paper);
}

.project-entry .asset-fallback {
  min-height: 245px;
}

.project-entry h2 {
  margin-bottom: 0.35rem;
}

.project-entry .item-meta {
  margin-bottom: 1rem;
}

.project-content .item-meta {
  opacity: 0.7;
  font-size: 0.9em;
}

.project-entry p:last-child {
  margin-bottom: 0;
}

/* ==========================================================================
   CV
   ========================================================================== */
.cv-section {
  max-width: 900px;
  margin-top: clamp(2.2rem, 4vw, 3.3rem);
}

.cv-section h2 {
  margin-bottom: 0.75rem;
  padding-bottom: 0.55rem;
  border-bottom: 1.5px solid var(--line);
}

.page-intro + .cv-section {
  margin-top: 2.5rem;
}

.page-intro--no-rule:has(+ .cv-section) {
  padding-bottom: 0.4rem;
}

.cv-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.cv-list li {
  display: grid;
  grid-template-columns: 11rem minmax(0, 1fr);
  gap: 1.5rem;
  padding: 1.05rem 0;
  border-bottom: 1.5px solid var(--line);
}

.cv-date {
  color: var(--muted);
  font-size: 0.88rem;
}

.cv-list h3 {
  margin-bottom: 0.35rem;
  font-size: 0.98rem;
}

.cv-list p {
  margin-bottom: 0.35rem;
  color: #343c45;
}

.cv-list p:last-child {
  margin-bottom: 0;
}

.cv-list .item-meta {
  color: var(--muted);
}

.cv-list--compact li {
  padding: 0.9rem 0;
}

.cv-list--no-bottom-rule li:last-child {
  border-bottom: 0;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.site-footer {
  width: min(calc(100% - 5rem), var(--max-width));
  margin: 0 auto;
  padding: 2rem 0 3.2rem;
  border-top: 1.5px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
}

.site-footer p {
  margin: 0;
}

/* ==========================================================================
   Small screens
   ========================================================================== */
@media (max-width: 760px) {
  .nav-shell,
  main,
  .site-footer {
    width: min(calc(100% - 2.5rem), var(--max-width));
  }

  .nav-shell {
    min-height: 4.7rem;
  }

  .brand,
  .brand:visited,
  .brand:hover,
  .brand:focus,
  .brand:active {
    width: 8.8rem;
    height: 3.06rem;
    font-size: 1.55rem;
  }

  .menu-toggle {
    display: block;
  }

  .site-nav {
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    display: none;
    padding: 0.4rem 1.25rem 1.1rem;
    border-bottom: 1.5px solid var(--line);
    background: var(--paper);
  }

  .site-nav.is-open {
    display: grid;
  }

  .site-nav a {
    padding: 0.65rem 0;
  }

  .site-nav a::after {
    display: none;
  }

  main {
    padding-top: 3.2rem;
  }

  main:has(> .page-intro) {
    padding-top: 2.5rem;
  }

  main:has(> .home-intro) {
    padding-top: 2.3rem;
  }

  .home-intro,
  .project-entry,
  .thesis-link {
    grid-template-columns: 1fr;
  }

  .home-portrait {
    max-width: 180px;
    justify-self: start;
  }

  .media.home-portrait {
    margin-top: 0;
  }

  .work-item {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }

  .project-entry:nth-child(even) .project-media {
    order: 0;
  }

  .project-entry .asset-fallback,
  .asset-fallback {
    min-height: 220px;
  }

  .cv-list li {
    grid-template-columns: 1fr;
    gap: 0.3rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
