/* ==========================================================================
   Theme tokens
   ========================================================================== */
:root,
:root[data-theme="dark"] {
  --bg: #0e1116;
  --surface: #151a21;
  --surface-2: #1c232c;
  --border: #29313c;
  --text: #e6e9ef;
  --text-strong: #ffffff;
  --muted: #9aa4b2;
  --accent: #2dd4bf;
  --accent-strong: #5eead4;
  --accent-soft: rgba(45, 212, 191, 0.12);
  --topbar-bg: rgba(14, 17, 22, 0.82);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --border: #dde2e8;
  --text: #1f2630;
  --text-strong: #0b0f14;
  --muted: #5a6573;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: rgba(15, 118, 110, 0.1);
  --topbar-bg: rgba(247, 248, 250, 0.85);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  color-scheme: light;
}

:root {
  --topbar-h: 60px;
  --toc-w: 200px;
  --content-w: 760px;
  --gap: 56px;
  --gutter: 24px;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16.5px;
  line-height: 1.65;
  padding-top: var(--topbar-h);
  overflow-x: hidden;
}

h1, h2, h3 {
  color: var(--text-strong);
  line-height: 1.25;
  font-weight: 650;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 3px; }

a:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

ul { margin: 0; padding: 0; list-style: none; }
p { margin: 0 0 0.75em; }

.icon { width: 18px; height: 18px; display: block; flex-shrink: 0; }
.icon-sm { width: 14px; height: 14px; }

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 100;
  padding: 8px 12px;
  background: var(--accent);
  color: var(--bg);
  border-radius: 6px;
}
.skip-link:focus { top: 12px; }

/* ==========================================================================
   Top bar
   ========================================================================== */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--topbar-h);
  z-index: 50;
  background: var(--topbar-bg);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: calc(var(--toc-w) + var(--gap) + var(--content-w) + 2 * var(--gutter));
  height: 100%;
  margin: 0 auto;
  padding: 0 var(--gutter);
  display: flex;
  align-items: center;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-strong);
  font-weight: 650;
  white-space: nowrap;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.brand:hover { color: var(--text-strong); text-decoration: none; }

.brand-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
}

/* On Home the avatar only appears once the hero has scrolled away. */
.topbar.has-hero .brand {
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
}
.topbar.has-hero.show-avatar .brand {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
}
.nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 500;
}
.nav a:hover { color: var(--text-strong); background: var(--surface-2); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { color: var(--text-strong); background: var(--surface-2); }

.theme-toggle { margin-left: 6px; }
[data-theme="dark"] .when-light,
[data-theme="light"] .when-dark { display: none; }

.menu-toggle { display: none; }

/* ==========================================================================
   Page grid (TOC + content)
   ========================================================================== */
.page,
.hero {
  max-width: calc(var(--toc-w) + var(--gap) + var(--content-w) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.page { padding-top: 40px; padding-bottom: 40px; }

.content { min-width: 0; }

@media (min-width: 1000px) {
  .page,
  .hero {
    display: grid;
    grid-template-columns: var(--toc-w) minmax(0, var(--content-w));
    column-gap: var(--gap);
  }
  .page:not(.has-toc) .content { grid-column: 2; }
}

/* ==========================================================================
   Hero
   ========================================================================== */
.hero {
  padding-top: 56px;
  padding-bottom: 16px;
  align-items: center;
}

.hero-photo {
  width: 168px;
  height: 168px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--surface-2);
  box-shadow: 0 0 0 1px var(--border), 0 0 0 6px var(--accent-soft);
  justify-self: end;
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 2.75rem);
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.hero-tagline {
  font-size: 1.15rem;
  color: var(--accent);
  font-weight: 500;
  margin-bottom: 6px;
}
.hero-affiliation { color: var(--muted); margin: 0; }

@media (max-width: 999px) {
  .hero { display: flex; gap: 32px; }
  .hero-photo { width: 136px; height: 136px; }
}

@media (max-width: 600px) {
  .hero {
    flex-direction: column;
    text-align: center;
    gap: 20px;
    padding-top: 36px;
  }
}

/* ==========================================================================
   Table of contents
   ========================================================================== */
.toc-title {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.toc a {
  display: block;
  color: var(--muted);
  font-size: 0.93rem;
  white-space: nowrap;
}
.toc a:hover { color: var(--text-strong); text-decoration: none; }
.toc a.active { color: var(--accent); }

@media (min-width: 1000px) {
  .toc {
    position: sticky;
    top: calc(var(--topbar-h) + 32px);
    align-self: start;
  }
  .toc a {
    padding: 5px 0 5px 14px;
    border-left: 2px solid var(--border);
  }
  .toc a.active { border-left-color: var(--accent); }
}

/* Below 1000px the TOC becomes a sticky row of chips under the top bar. */
@media (max-width: 999px) {
  .toc {
    position: sticky;
    top: var(--topbar-h);
    z-index: 40;
    margin: -40px calc(-1 * var(--gutter)) 24px;
    padding: 10px var(--gutter);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }
  .toc-title { display: none; }
  .toc ul {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .toc ul::-webkit-scrollbar { display: none; }
  .toc a {
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.85rem;
  }
  .toc a.active { border-color: var(--accent); background: var(--accent-soft); }
}

/* ==========================================================================
   Sections
   ========================================================================== */
.section {
  margin-bottom: 56px;
  scroll-margin-top: calc(var(--topbar-h) + 24px);
}
@media (max-width: 999px) {
  .section { scroll-margin-top: calc(var(--topbar-h) + 72px); }
}

.section h2 {
  font-size: 1.35rem;
  margin: 0 0 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.section h3 {
  font-size: 1rem;
  color: var(--muted);
  font-weight: 600;
  margin: 24px 0 12px;
}

.page-title {
  font-size: 2rem;
  margin: 0 0 8px;
}
.page-intro { color: var(--muted); margin-bottom: 36px; }

.prose p:last-child { margin-bottom: 0; }
.prose strong { color: var(--text-strong); }

.section-link {
  display: inline-block;
  margin-top: 16px;
  font-weight: 500;
}

.intro-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.intro-row p { margin: 0; }

.btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }

.chips {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.chips li {
  display: flex;
  align-items: center;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.92rem;
  line-height: 1.4;
}

@media (max-width: 600px) {
  .chips { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chips li { font-size: 0.85rem; padding: 7px 10px; }
}

/* ==========================================================================
   News
   ========================================================================== */
.news-list { display: grid; gap: 18px; }

.news-item {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  gap: 16px;
}
.news-date {
  color: var(--muted);
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  padding-top: 2px;
}
.news-item.has-image { grid-template-columns: 80px minmax(0, 1fr) 96px; }

.news-thumb {
  align-self: start;
  display: block;
  width: 96px;
  height: 72px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}
.news-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s ease;
}
.news-thumb:hover { border-color: var(--accent); }
.news-thumb:hover img { transform: scale(1.04); }

.news-body p { display: inline; margin: 0; }
.news-body strong { color: var(--text-strong); }

.tag {
  display: inline-block;
  margin-right: 8px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.7;
  vertical-align: 2px;
  background: var(--surface-2);
  color: var(--muted);
}
.tag-publication,
.tag-grant,
.tag-award { background: var(--accent-soft); color: var(--accent); }

.more-link {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 6px;
  font-size: 0.9rem;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .news-item { grid-template-columns: 1fr; gap: 2px; }
  .news-item.has-image { grid-template-columns: minmax(0, 1fr) 72px; column-gap: 12px; }
  .news-item.has-image .news-date { grid-column: 1 / -1; }
  .news-thumb { width: 72px; height: 54px; }
}

/* ==========================================================================
   Publications
   ========================================================================== */
.pub-list { display: grid; gap: 22px; }

.pub {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 16px;
}

.venue-badge {
  align-self: start;
  justify-self: start;
  padding: 2px 8px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.pub-title {
  color: var(--text-strong);
  font-weight: 600;
  line-height: 1.4;
}
.pub-title:hover { color: var(--accent); }

.pub-authors,
.pub-venue {
  margin: 4px 0 0;
  font-size: 0.92rem;
  color: var(--muted);
}
.pub-authors strong { color: var(--text); }

@media (max-width: 600px) {
  .pub { grid-template-columns: 1fr; gap: 6px; }
}

/* ==========================================================================
   CV entries
   ========================================================================== */
.entry {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.entry[open] { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

.entry summary {
  position: relative;
  display: block;
  padding: 14px 44px 14px 18px;
  cursor: pointer;
  list-style: none;
}
.entry summary::-webkit-details-marker { display: none; }
.entry summary:hover .entry-title { color: var(--accent); }

.entry-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 16px;
}
.entry-title { color: var(--text-strong); font-weight: 600; }
.entry-org { font-weight: 500; color: var(--text); }
.entry-dates {
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.entry-summary {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.93rem;
}

.entry-chevron {
  position: absolute;
  right: 16px;
  top: 18px;
  color: var(--muted);
  transition: transform 0.2s ease;
}
.entry[open] .entry-chevron { transform: rotate(90deg); }

.entry-body {
  padding: 4px 18px 18px;
  border-top: 1px solid var(--border);
  margin-top: 0;
  font-size: 0.95rem;
}
.entry-body > :first-child { margin-top: 14px; }
.entry-body ul:not(.skills) { list-style: disc; padding-left: 20px; margin-bottom: 12px; }
.entry-body li { margin-bottom: 4px; }
.entry-location { color: var(--muted); font-size: 0.88rem; }
.entry-subhead { font-weight: 600; color: var(--text-strong); margin: 12px 0 6px; }

.skills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.skills li {
  margin: 0;
  padding: 1px 9px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8rem;
}

.facts {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 4px 16px;
  margin: 0 0 8px;
}
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

@media (max-width: 600px) {
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dd { margin-bottom: 8px; }
}

/* Teaching, grants, languages */
.term-list li {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.term-list li:last-child { border-bottom: 0; }
.term {
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  padding-top: 1px;
}

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

.grant-list { display: grid; gap: 14px; }
.grant-list li {
  padding-left: 14px;
  border-left: 2px solid var(--accent);
}
.grant-title { display: block; color: var(--text-strong); font-weight: 500; }
.grant-meta { display: block; color: var(--muted); font-size: 0.92rem; }
.grant-meta strong { color: var(--accent); font-weight: 600; }

.lang-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}
.lang-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.lang-name { color: var(--text-strong); font-weight: 500; }
.lang-level { color: var(--muted); font-size: 0.9rem; }

/* ==========================================================================
   Footer
   ========================================================================== */
.footer {
  border-top: 1px solid var(--border);
  padding: 24px var(--gutter);
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}
.footer p { margin: 0; }

/* ==========================================================================
   Small screens
   ========================================================================== */
@media (max-width: 760px) {
  :root { --gutter: 16px; }

  .topbar-inner { gap: 8px; }
  .menu-toggle { display: inline-flex; }
  .theme-toggle { margin-left: 0; }

  .nav {
    display: none;
    position: absolute;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    flex-direction: column;
    padding: 8px var(--gutter) 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }
  .nav.open { display: flex; }
  .nav a { padding: 10px 12px; }

  .topbar-actions { margin-left: auto; }
}

@media (max-width: 480px) {
  .brand-name { display: none; }
  .icon-btn { width: 34px; }
}
