:root {
  --bg: #fbfbfd;
  --surface: #ffffff;
  --text: #1d1f2b;
  --muted: #5d6275;
  --border: #e3e5ee;
  --accent: #3d48b8;
  --accent-soft: #eceefe;
  --highlight: #c0392b;
  --texture-opacity: 0.035;
  --shadow: 0 1px 2px rgba(20, 24, 60, 0.06), 0 4px 16px rgba(20, 24, 60, 0.06);
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --header-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11131b;
    --surface: #191c27;
    --text: #e6e7ee;
    --muted: #9fa4b8;
    --border: #2a2e3d;
    --accent: #9aa3ff;
    --accent-soft: #232845;
    --highlight: #ff7a6b;
    --texture-opacity: 0.02;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11131b;
  --surface: #191c27;
  --text: #e6e7ee;
  --muted: #9fa4b8;
  --border: #2a2e3d;
  --accent: #9aa3ff;
  --accent-soft: #232845;
  --highlight: #ff7a6b;
  --texture-opacity: 0.02;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 12px); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: url("../img/randomcomplex.png") repeat;
  background-size: 480px auto;
  opacity: var(--texture-opacity);
  pointer-events: none;
  z-index: -1;
}
:root[data-theme="dark"] body::before { filter: invert(1); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) body::before { filter: invert(1); } }

img { max-width: 100%; height: auto; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.wrap.narrow { max-width: 780px; }
.muted { color: var(--muted); }

.skip-link { position: absolute; left: -9999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip-link:focus { left: 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.nav {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 16px;
}
.nav-name { font-family: var(--serif); font-weight: 600; font-size: 1.1rem; color: var(--text); white-space: nowrap; }
.nav-name:hover { text-decoration: none; }
.nav-links {
  display: flex;
  gap: 4px;
  list-style: none;
  margin: 0 0 0 auto;
  padding: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-links::-webkit-scrollbar { display: none; }
.nav-links a {
  display: block;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
}
.nav-links a:hover { color: var(--text); text-decoration: none; background: var(--accent-soft); }
.nav-links a.active { color: var(--accent); background: var(--accent-soft); }
.theme-toggle {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--text); }

/* Hero */
.hero { padding: 56px 0 24px; }
.hero-grid {
  display: grid;
  grid-template-columns: 180px 1fr 300px;
  gap: 40px;
  align-items: center;
}
.profile-pic { width: 180px; border-radius: 12px; box-shadow: var(--shadow); }
.hero-text h1 { font-size: clamp(2rem, 4vw, 2.75rem); margin: 0 0 6px; }
.affiliations { list-style: none; margin: 0 0 16px; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 24px; }
.affiliations li { display: flex; flex-direction: column; gap: 4px; padding-left: 12px; border-left: 2px solid var(--border); }
.aff-name { color: var(--muted); font-size: 0.98rem; line-height: 1.45; }
.email { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; color: var(--muted); }
.social { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.social a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
}
.social a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.hero-figure { margin: 0; }
.hero-figure img { border-radius: 8px; box-shadow: var(--shadow); background: #fff; }

.latest { margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--border); }
.eyebrow {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 12px;
}
.latest-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 900px) { .latest-list { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .latest-list { grid-template-columns: 1fr; } }
.latest-list li { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.latest-list a { font-weight: 600; color: var(--text); display: block; line-height: 1.35; margin-bottom: 4px; }
.latest-list a:hover { color: var(--accent); }
.latest-list .meta { font-size: 0.85rem; color: var(--muted); }

/* Sections */
.section { padding: 64px 0; }
.section-title { font-size: 2rem; margin: 0 0 20px; }
.section-title::after { content: ""; display: block; width: 40px; height: 3px; background: var(--highlight); margin-top: 10px; border-radius: 2px; }

/* Research */
.lede { font-size: 1.08rem; max-width: 720px; margin: 0 0 28px; }
.research-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.theme {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 12px;
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
}
.theme h3 { font-size: 1.3rem; margin: 0 0 10px; }
.theme p { margin: 0 0 16px; font-size: 0.96rem; }
.theme h4 {
  margin: auto 0 8px;
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.key-papers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.key-papers li { font-size: 0.92rem; line-height: 1.4; padding-left: 14px; position: relative; }
.key-papers li::before { content: ""; position: absolute; left: 0; top: 0.55em; width: 6px; height: 6px; border-radius: 50%; background: var(--highlight); }
.key-papers a { color: var(--text); font-weight: 500; }
.key-papers a:hover { color: var(--accent); }
.key-papers span { color: var(--muted); font-size: 0.85em; white-space: nowrap; }
.key-papers span::before { content: "· "; }
@media (max-width: 760px) { .research-grid { grid-template-columns: 1fr; } }

/* Publications */
.pub-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin: 20px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit;
  font-size: 0.88rem;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.chip:hover { color: var(--text); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.chip .count { opacity: 0.7; font-size: 0.8em; margin-left: 2px; }
.search { position: relative; flex: 1 1 260px; max-width: 360px; }
.search i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 0.85rem; }
.search input {
  width: 100%;
  font: inherit;
  font-size: 0.92rem;
  padding: 8px 12px 8px 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.year-group { display: grid; grid-template-columns: 72px 1fr; gap: 16px; border-top: 1px solid var(--border); padding: 18px 0; }
.year-label { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; color: var(--muted); position: sticky; top: calc(var(--header-h) + 12px); align-self: start; }
.pub-items { list-style: none; margin: 0; padding: 0; }
.pub { padding: 0 0 18px; }
.pub:last-child { padding-bottom: 0; }
.pub-title { font-weight: 600; line-height: 1.4; }
.pub-title a { color: var(--text); }
.pub-title a:hover { color: var(--accent); }
.pub-authors { color: var(--text); font-size: 0.93rem; }
.pub-authors .me { font-weight: 600; }
.pub-venue { color: var(--muted); font-size: 0.9rem; font-style: italic; }
.pub-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; align-items: center; }
.tag, .pub-links a {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 2px 8px;
  border-radius: 5px;
  font-style: normal;
}
.pub-links a { border: 1px solid var(--border); color: var(--accent); background: var(--surface); }
.pub-links a:hover { border-color: var(--accent); text-decoration: none; }
.pub-links a.corrected i { margin-right: 3px; }
.pub-note { font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
.bib-btn {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 2px 8px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
}
.bib-btn:hover { border-color: var(--accent); }
.bib-dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.25);
}
.bib-dialog::backdrop { background: rgba(10, 12, 24, 0.45); }
.bib-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.bib-head h2 { font-size: 1.1rem; margin: 0; }
.bib-actions { display: flex; gap: 8px; }
.bib-actions form { margin: 0; }
.bib-dialog pre {
  margin: 0;
  padding: 16px;
  overflow: auto;
  max-height: calc(100vh - 160px);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre;
  background: var(--bg);
}
.tag { text-transform: uppercase; background: var(--accent-soft); color: var(--muted); }
.tag.preprint { color: var(--highlight); background: color-mix(in srgb, var(--highlight) 12%, transparent); }

/* Teaching */
.card-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.card-list li { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; display: flex; flex-direction: column; }
.card-list span { color: var(--muted); font-size: 0.88rem; }

/* Talks */
.talks-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.talk { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; color: var(--text); }
.talk:hover { border-color: var(--accent); text-decoration: none; }
.talk img { aspect-ratio: 16 / 9; object-fit: cover; width: 100%; display: block; }
.talk span { padding: 10px 14px 14px; font-weight: 500; font-size: 0.95rem; line-height: 1.4; }

/* Viewer + CV */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
}
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--accent); }
.viewer-frame {
  min-height: 220px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--surface);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
}
.viewer-frame.loaded { padding: 0; border-style: solid; overflow: hidden; }
.viewer-frame iframe { width: 100%; height: 720px; border: 0; display: block; }
.demo + .demo { margin-top: 40px; padding-top: 32px; border-top: 1px solid var(--border); }
.demo h3 { font-family: var(--serif); font-size: 1.3rem; font-weight: 600; margin: 0 0 8px; }
.demo-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 28px; align-items: center; }
.demo-shot { display: block; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); background: #fbfaf7; }
.demo-shot:hover { border-color: var(--accent); }
.demo-shot img { display: block; width: 100%; height: auto; }
.small-note { font-size: 0.9rem; }
.small-note code { font-size: 0.85em; }
.demo-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0 0; }
.pdf-frame { margin-top: 16px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); background: var(--surface); }
.pdf-frame iframe { width: 100%; height: 760px; border: 0; display: block; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); padding: 24px 0 40px; color: var(--muted); font-size: 0.9rem; }
.site-footer .wrap { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Responsive */
@media (max-width: 900px) {
  .hero-grid { grid-template-columns: 150px 1fr; }
  .profile-pic { width: 150px; }
  .hero-figure { display: none; }
}
@media (max-width: 640px) {
  .hero { padding-top: 32px; }
  .hero-grid { grid-template-columns: 1fr; gap: 20px; }
  .profile-pic { width: 120px; }
  .nav-name { display: none; }
  .nav-links { margin-left: 0; }
  .section { padding: 48px 0; }
  .year-group { grid-template-columns: 1fr; gap: 8px; }
  .year-label { position: static; }
  .pdf-frame { display: none; }
  .viewer-frame iframe { height: 560px; }
  .demo-split { grid-template-columns: 1fr; gap: 18px; }
}
