/* ── Design tokens ─────────────────────────────────────────────── */

:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --rule: #e4e4e4;
  --link: #1a4f8a;
  --nav-bg: rgba(255, 255, 255, 0.88);
  --measure: 46rem; /* content width */

  /* Body is sans (Inter if the visitor has it, otherwise the system UI face);
     headings are serif. No webfonts — nothing to download. */
  --font-body: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    sans-serif;
  --font-display: Georgia, "Times New Roman", "Songti SC", serif;
}

/* Dark palette: applied when the system asks for it, unless the visitor
   explicitly chose light; and always when they explicitly chose dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16171a;
    --fg: #e6e5e2;
    --muted: #9a9a96;
    --rule: #2e3034;
    --link: #8fb8e8;
    --nav-bg: rgba(22, 23, 26, 0.88);
  }
}

:root[data-theme="dark"] {
  --bg: #16171a;
  --fg: #e6e5e2;
  --muted: #9a9a96;
  --rule: #2e3034;
  --link: #8fb8e8;
  --nav-bg: rgba(22, 23, 26, 0.88);
}

/* ── Base ──────────────────────────────────────────────────────── */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--link) 35%, transparent);
}

a:hover {
  border-bottom-color: var(--link);
}

p {
  margin: 0 0 1rem;
}

/* ── Top navigation ────────────────────────────────────────────── */

.nav {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--rule);
}

.nav-inner {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0.7rem 1.5rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.nav-name {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--fg);
  border: none;
}

.nav-links {
  display: flex;
  flex-wrap: wrap; /* without this the links push the page wider than a phone */
  align-items: baseline;
  justify-content: center;
  gap: 0.4rem 1.25rem;
  font-size: 0.95rem;
}

.nav-links a {
  color: var(--muted);
  border: none;
}

.nav-links a:hover {
  color: var(--fg);
}

/* The page you are currently on. */
.nav-links a.active {
  color: var(--fg);
  font-weight: 600;
}

/* Theme toggle */
#theme-toggle {
  background: none;
  border: none;
  padding: 0;
  margin-left: 0.35rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 0;
}

#theme-toggle:hover {
  color: var(--fg);
}

#theme-toggle svg {
  width: 17px;
  height: 17px;
  display: block;
}

/* Show the sun in dark mode (click = go light) and the moon in light mode. */
#theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="dark"] #theme-toggle .icon-sun {
  display: block;
}

:root[data-theme="dark"] #theme-toggle .icon-moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme-toggle .icon-sun {
    display: block;
  }

  :root:not([data-theme="light"]) #theme-toggle .icon-moon {
    display: none;
  }
}

/* ── Header ────────────────────────────────────────────────────── */

.header {
  display: flex;
  align-items: flex-start;
  gap: 2rem;
  margin-bottom: 2.5rem;
}

.header-text {
  flex: 1;
  min-width: 0;
}

h1 {
  font-family: var(--font-display);
  font-size: 2.6rem;
  line-height: 1.15;
  margin: 0 0 0.7rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.affiliation {
  color: var(--muted);
  margin-bottom: 0.7rem;
}

.contact {
  font-size: 0.95rem;
  margin: 0;
}

.sep {
  color: var(--muted);
  margin: 0 0.4rem;
}

.photo {
  width: 160px;
  height: 200px;
  object-fit: cover;
  border-radius: 3px;
  flex-shrink: 0;
  background: var(--rule);
}

/* Heading of a subpage (Research, Education, …). */
.page-title {
  font-family: var(--font-display);
  font-size: 2.1rem;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin: 0 0 2rem;
}

/* ── Sections ──────────────────────────────────────────────────── */

section {
  margin-bottom: 2.75rem;
}

h2 {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--rule);
}

h3 {
  font-size: 0.98rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  margin: 1.75rem 0 0.6rem;
}

.muted {
  color: var(--muted);
}

/* ── Lists ─────────────────────────────────────────────────────── */

ul.plain {
  margin: 0;
  padding-left: 1.2rem;
}

ul.plain li {
  margin-bottom: 0.3rem;
}

/* Papers, notes, projects */
.papers {
  list-style: none;
  margin: 0;
  padding: 0;
}

.papers li {
  margin-bottom: 1rem;
}

.papers > li > span {
  display: block;
}

.paper-title {
  font-weight: 600;
}

.paper-meta,
.paper-links {
  font-size: 0.93rem;
  color: var(--muted);
}

/* Education / teaching timeline */
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}

.timeline li {
  display: flex;
  gap: 1.25rem;
  margin-bottom: 1.1rem;
}

/* Wider date column, for entries dated to the day. */
.timeline-wide .years {
  flex-basis: 10.5rem;
}

.years {
  flex: 0 0 7.5rem;
  color: var(--muted);
  font-size: 0.93rem;
  padding-top: 0.15rem;
  font-variant-numeric: tabular-nums;
}

.entry {
  flex: 1;
  min-width: 0;
}

/* One-line introduction under a page title. */
.lead {
  margin: -1.2rem 0 2rem;
  color: var(--muted);
}

/* ── Places ────────────────────────────────────────────────────── */

/* Photos need more room than a column of text does. Put class="wide" on <body>
   so the nav bar widens with the content and stays aligned with it.
   This one follows the window: most of the viewport, capped so the photos do
   not turn into a wall on an ultrawide monitor. */
body.wide main,
body.wide .nav-inner {
  max-width: min(94vw, 84rem);
}

/* Two photos per row on a desktop, one on a phone. Every photo is cropped to
   3:2, so the rows line up whatever the source was. */
.places-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.75rem 1.25rem;
}

.places-grid figure {
  margin: 0;
}

.places-grid img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border-radius: 4px;
  background: var(--rule);
}

.places-grid figcaption {
  margin-top: 0.5rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
}

.places-grid .caption {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

/* ── Footer ────────────────────────────────────────────────────── */

footer {
  margin-top: 3.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.88rem;
  color: var(--muted);
}

/* ── Small screens ─────────────────────────────────────────────── */

@media (max-width: 640px) {
  body {
    font-size: 16px;
  }

  .header {
    flex-direction: column-reverse;
    align-items: center;
    text-align: center;
    gap: 1.25rem;
  }

  .timeline li {
    flex-direction: column;
    gap: 0.15rem;
  }

  .years {
    flex: none;
  }

  .nav-inner {
    justify-content: center;
  }

  /* Pin the links to the container width so they wrap inside it instead of
     stretching the whole page wider than the screen. */
  .nav-links {
    width: 100%;
    gap: 0.35rem 0.9rem;
  }
}
