/* ============ Tokens ============ */
:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f3f1ec;
  --text: #1c1f24;
  --muted: #5d636b;
  --faint: #8a9098;
  --line: #e4e1da;
  --accent: #1d4e6e;
  --accent-ink: #163d57;
  --accent-soft: #e6eef4;
  --highlight: #9a3412;
  --badge-bg: #f4ead9;
  --badge-ink: #7a4a10;
  --shadow: 0 1px 2px rgba(20, 24, 30, .04), 0 4px 16px rgba(20, 24, 30, .05);

  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius: 10px;
  --maxw: 1180px;
  --topbar-h: 58px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418;
    --surface: #171b20;
    --surface-2: #1d2228;
    --text: #e7e9ec;
    --muted: #a3aab3;
    --faint: #7a828c;
    --line: #2a3038;
    --accent: #7fb6d9;
    --accent-ink: #a5cde6;
    --accent-soft: #1b2b38;
    --highlight: #f0a070;
    --badge-bg: #2e2617;
    --badge-ink: #e8c48a;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111418;
  --surface: #171b20;
  --surface-2: #1d2228;
  --text: #e7e9ec;
  --muted: #a3aab3;
  --faint: #7a828c;
  --line: #2a3038;
  --accent: #7fb6d9;
  --accent-ink: #a5cde6;
  --accent-soft: #1b2b38;
  --highlight: #f0a070;
  --badge-bg: #2e2617;
  --badge-ink: #e8c48a;
  --shadow: none;
  color-scheme: dark;
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
/* App shell: header and footer stay put, only the middle scrolls. */
body {
  margin: 0;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; text-underline-offset: 3px; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.25; margin: 0; color: var(--text); }
p { margin: 0 0 1em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }

/* ============ Top bar ============ */
.topbar {
  position: relative; z-index: 50; flex: none;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.scroller {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  scroll-behavior: smooth; scroll-padding-top: 16px;
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto; height: var(--topbar-h);
  display: flex; align-items: center; gap: 24px; padding: 0 24px;
}
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.15rem; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
/* Center the links between brand and buttons; auto margins (unlike justify-content)
   keep the first link reachable if the row ever overflows. */
.nav a:first-child { margin-left: auto; }
.nav a:last-child { margin-right: auto; }
.nav a {
  color: var(--muted); font-size: .88rem; padding: 6px 10px; border-radius: 6px; white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--accent); background: var(--accent-soft); }
.topbar-actions { display: flex; gap: 6px; margin-left: auto; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: none; }
  :root:not([data-theme="light"]) .i-moon { display: block; }
}
.menu-btn { display: none; }

/* ============ Layout ============ */
.layout {
  max-width: var(--maxw); margin: 0 auto; padding: 28px 24px 24px;
  display: grid; grid-template-columns: 272px minmax(0, 1fr); gap: 56px;
}
/* Sticky sidebar never taller than the visible area; scrolls on its own if needed. */
.sidebar {
  position: sticky; top: 28px; align-self: start;
  max-height: calc(100vh - var(--topbar-h) - 40px - 56px);
  max-height: calc(100dvh - var(--topbar-h) - 40px - 56px);
  overflow-y: auto; scrollbar-width: thin; padding-bottom: 4px;
}
.content { min-width: 0; }

/* ============ Sidebar ============ */
.avatar {
  width: 136px; height: 136px; border-radius: 50%; object-fit: cover;
  border: 1px solid var(--line); background: var(--surface-2);
}
.avatar-fallback {
  display: grid; place-items: center; font-family: var(--serif); font-size: 3.2rem; font-weight: 600;
  color: var(--accent); background: var(--accent-soft);
}
.side-name { font-size: 1.75rem; margin-top: 16px; letter-spacing: -.01em; }
.side-native { font-family: var(--sans); font-weight: 400; color: var(--muted); font-size: 1.05rem; margin-left: 6px; }
.side-title { color: var(--text); margin: 6px 0 0; font-size: .95rem; }
.side-aff { color: var(--muted); font-size: .95rem; margin: 0; }
.side-tag { font-family: var(--serif); font-style: italic; color: var(--muted); margin: 10px 0 0; font-size: 1rem; line-height: 1.45; }
.side-links { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 4px; }
.side-links a, .side-links span {
  display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: .9rem;
}
.side-links a:hover { color: var(--accent); text-decoration: none; }
.side-links svg { width: 16px; height: 16px; flex: none; fill: currentColor; }
.side-cv {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 20px;
  padding: 8px 16px; border-radius: 8px; background: var(--accent); color: var(--bg);
  font-weight: 500; font-size: .9rem;
}
.side-cv:hover { text-decoration: none; filter: brightness(1.08); }
.side-cv svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; }
.metrics { display: flex; gap: 20px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.metric b { display: block; font-family: var(--serif); font-size: 1.5rem; font-weight: 600; line-height: 1.1; }
.metric span { font-size: .75rem; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; }
.metrics-note { font-size: .72rem; color: var(--faint); margin-top: 6px; }
.metrics-note a { color: inherit; }

/* ============ Sections ============ */
.section { padding: 8px 0 44px; }
.section + .section { border-top: 1px solid var(--line); padding-top: 40px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.section h2 { font-size: 1.6rem; font-weight: 600; letter-spacing: -.01em; }
.section h3 { font-size: 1.1rem; font-weight: 600; }
.lead p { font-size: 1.04rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.chip {
  font-size: .82rem; padding: 3px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted);
}

/* Job market banner (top of About) */
.callout {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin: 0 0 28px; padding: 14px 18px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}
.callout-dot {
  width: 10px; height: 10px; border-radius: 50%; flex: none; background: #2f9e6b;
  box-shadow: 0 0 0 4px color-mix(in srgb, #2f9e6b 22%, transparent);
}
.callout-body { flex: 1; min-width: 220px; }
.callout strong { color: var(--accent-ink); font-family: var(--serif); font-size: 1.05rem; }
.callout p { margin: 2px 0 0; color: var(--muted); font-size: .9rem; line-height: 1.5; }
.callout-links { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; font-size: .84rem; font-weight: 500;
  padding: 5px 12px; border-radius: 7px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  cursor: pointer; font-family: var(--sans);
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn[disabled], .btn.is-soon { color: var(--faint); cursor: default; border-style: dashed; }
.btn.is-soon:hover { border-color: var(--line); color: var(--faint); }

/* News */
.news { list-style: none; margin: 0; padding: 0; }
.news li { display: grid; grid-template-columns: 76px 1fr; gap: 16px; padding: 7px 0; }
.news .when { font-family: var(--mono); font-size: .8rem; color: var(--faint); padding-top: 3px; }
.news li.is-hidden { display: none; }
.more-btn { margin-top: 10px; }

/* Research themes */
.themes { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.theme {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 18px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.theme .num { font-family: var(--mono); font-size: .75rem; color: var(--accent); letter-spacing: .08em; }
.theme h3 { margin: 6px 0 8px; font-size: 1.08rem; }
.theme p { color: var(--muted); font-size: .92rem; margin-bottom: 12px; }
.theme-papers { margin-top: auto; display: flex; flex-wrap: wrap; gap: 6px; }
.theme-papers a {
  font-size: .78rem; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text);
}
.theme-papers a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }

/* Publications */
.pub-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 8px; }
.pub-search {
  flex: 1; min-width: 180px; font: inherit; font-size: .88rem; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text);
}
.pub-note { font-size: .8rem; color: var(--faint); margin: 0 0 14px; }
.pubs { list-style: none; margin: 0; padding: 0; }
.pub { padding: 16px 0; border-bottom: 1px solid var(--line); }
.pub:last-child { border-bottom: 0; }
.pub.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { background: var(--accent-soft); } 100% { background: transparent; } }
.venue-tag {
  display: inline-block; max-width: 100%; margin-bottom: 7px;
  font-size: .76rem; font-weight: 500; line-height: 1.45;
  color: var(--accent-ink); background: var(--accent-soft); border-radius: 6px; padding: 3px 9px;
}
.pub-title { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; line-height: 1.38; color: var(--text); }
.pub-authors { font-size: .9rem; color: var(--muted); margin-top: 3px; }
.pub-authors .me { color: var(--text); font-weight: 600; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.pub-venue { font-size: .88rem; font-style: italic; color: var(--muted); }
.pub-detail { font-size: .82rem; color: var(--muted); margin: 4px 0 0; }
.pub-tldr { font-size: .9rem; color: var(--text); margin: 6px 0 0; opacity: .88; }
.empty { color: var(--faint); font-style: italic; padding: 16px 0; }

/* Projects */
.projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.project {
  display: flex; flex-direction: column; gap: 6px; padding: 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.project:hover { border-color: var(--accent); text-decoration: none; }
.project-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.project-top b { font-family: var(--serif); font-size: 1.05rem; }
.stars { font-family: var(--mono); font-size: .78rem; color: var(--badge-ink); white-space: nowrap; }
.project p { margin: 0; color: var(--muted); font-size: .9rem; }
.project .chips { margin-top: auto; padding-top: 6px; }
.project .chip { font-size: .72rem; padding: 1px 8px; }

/* Timeline (experience) */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { display: grid; grid-template-columns: 150px 1fr; gap: 20px; padding: 10px 0 14px; }
.timeline .when { font-family: var(--mono); font-size: .8rem; color: var(--faint); padding-top: 3px; }
.timeline .org { font-weight: 600; }
.timeline .role { color: var(--accent); font-size: .9rem; }
.timeline p { color: var(--muted); font-size: .92rem; margin: 4px 0 0; }

/* Shared date column keeps education dates on one line and schools aligned. */
.education { display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: 20px; }
.education li { grid-column: 1 / -1; grid-template-columns: subgrid; }
.education .when { white-space: nowrap; }

/* Generic dated list */
.dated { list-style: none; margin: 0; padding: 0; }
.dated li { display: grid; grid-template-columns: 76px 1fr; gap: 16px; padding: 7px 0; }
.dated .when { font-family: var(--mono); font-size: .8rem; color: var(--faint); padding-top: 3px; }
.dated .sub { display: block; color: var(--muted); font-size: .9rem; }

/* Mentoring and alumni */
.people { list-style: none; margin: 0; padding: 0; }
.people li { padding: 7px 0; }
.people-note { color: var(--muted); }
.people-period { display: block; font-family: var(--mono); font-size: .8rem; color: var(--faint); }

.kv { display: grid; gap: 10px; }
.kv-row { display: grid; grid-template-columns: 200px 1fr; gap: 16px; font-size: .95rem; }
.kv-row .k { font-weight: 600; }
.kv-row .v { color: var(--muted); }

.subhead { font-family: var(--serif); font-size: 1.1rem; margin: 28px 0 12px; }
.subhead.first { margin-top: 0; }

/* Footer */
.footer {
  flex: none; color: var(--faint); font-size: .78rem; background: var(--bg);
  padding: 10px max(24px, calc((100% - var(--maxw)) / 2 + 24px));
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 16px; border-top: 1px solid var(--line);
}
.footer a { color: inherit; text-decoration: underline; }

/* ============ Responsive ============ */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; gap: 28px; padding-top: 28px; }
  .sidebar { position: static; max-height: none; overflow: visible; display: flex; gap: 28px; align-items: flex-start; }
  .sidebar .avatar { width: 128px; height: 128px; flex: none; }
  .side-info { flex: 1; min-width: 0; }
  .side-name { margin-top: 0; }
  .side-links { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 14px; }
  .metrics { border-top: 0; padding-top: 0; margin-top: 16px; }
}
@media (max-width: 820px) {
  .menu-btn { display: grid; }
  .nav {
    position: absolute; top: var(--topbar-h); left: 0; right: 0; flex-direction: column;
    background: var(--bg); border-bottom: 1px solid var(--line); padding: 8px 16px 14px; display: none;
  }
  .nav.open { display: flex; }
  .nav a { padding: 10px 8px; font-size: .95rem; }
  .nav a:first-child, .nav a:last-child { margin: 0; }
}
@media (max-width: 640px) {
  body { font-size: 15.5px; }
  .topbar-inner, .layout { padding-left: 16px; padding-right: 16px; }
  .footer { padding: 8px 16px; }
  .sidebar { flex-direction: column; gap: 14px; }
  .sidebar .avatar { width: 112px; height: 112px; }
  .side-links { gap: 6px 16px; }
  .section h2 { font-size: 1.4rem; }
  .timeline li, .kv-row { grid-template-columns: 1fr; gap: 2px; }
  .education { grid-template-columns: minmax(0, 1fr); }
  .news li, .dated li { grid-template-columns: 64px 1fr; gap: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .scroller { scroll-behavior: auto; }
  .pub.flash { animation: none; }
}
@media print {
  body { height: auto; overflow: visible; display: block; }
  .scroller { overflow: visible; }
  .topbar, .pub-tools, .more-btn, .footer { display: none !important; }
  .layout { display: block; }
  .sidebar { position: static; }
  .news li.is-hidden { display: grid; }
}

/* About heading is for screen readers / outline only */
.visually-about { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#about .section-head { margin: 0; }

[hidden] { display: none !important; }

/* Short laptop screens: tighten the sidebar so it fits without inner scrolling. */
@media (min-width: 981px) and (max-height: 800px) {
  .sidebar .avatar { width: 96px; height: 96px; }
  .avatar-fallback { font-size: 2.2rem; }
  .side-name { font-size: 1.5rem; margin-top: 10px; }
  .side-tag { margin-top: 6px; font-size: .92rem; }
  .side-links { grid-template-columns: 1fr 1fr; gap: 2px 12px; margin-top: 10px; }
  .side-links a, .side-links span { font-size: .84rem; }
  .side-links li:first-child { grid-column: 1 / -1; }
  .metrics { margin-top: 10px; padding-top: 10px; }
  .metric b { font-size: 1.25rem; }
}

/* Email drawn as an image (see drawEmails in main.js) */
.email-link { display: inline-flex; align-items: center; gap: 10px; }
.email-img { display: inline-block; vertical-align: middle; }
