:root {
  color-scheme: light dark;
  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-alt: #f4f5f4;
  --ink: #151922;
  --muted: #525b6a;
  --subtle: #6e7787;
  --line: #e4e7ec;
  --line-strong: #cdd3dc;
  --accent: #0d5c63;
  --accent-hover: #084449;
  --accent-soft: #eaf4f4;
  --badge-bg: #eef4f4;
  --badge-ink: #0d5c63;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 6px 20px rgba(15, 23, 42, 0.04);
  --radius: 12px;
  --font-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #0e1217;
  --surface: #151b23;
  --surface-alt: #1b222c;
  --ink: #e8edf4;
  --muted: #a6b0c0;
  --subtle: #828d9e;
  --line: #252f3d;
  --line-strong: #364355;
  --accent: #5ec6c6;
  --accent-hover: #83d8d8;
  --accent-soft: #152b2e;
  --badge-bg: #172e31;
  --badge-ink: #7ed6d6;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1217;
    --surface: #151b23;
    --surface-alt: #1b222c;
    --ink: #e8edf4;
    --muted: #a6b0c0;
    --subtle: #828d9e;
    --line: #252f3d;
    --line-strong: #364355;
    --accent: #5ec6c6;
    --accent-hover: #83d8d8;
    --accent-soft: #152b2e;
    --badge-bg: #172e31;
    --badge-ink: #7ed6d6;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2.5px;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  transition: color 0.14s ease, text-decoration-color 0.14s ease;
}
a:hover {
  color: var(--accent-hover);
  text-decoration-color: currentColor;
}

code {
  font-family: var(--font-mono);
  font-size: 0.87em;
  background: var(--surface-alt);
  padding: 0.1em 0.36em;
  border-radius: 4px;
}

.wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 58px;
}
.brand {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.08rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand:hover { color: var(--accent); text-decoration: none; }

.nav-links {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.nav-links a {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
}
.nav-links a:hover { color: var(--ink); }

.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.95rem;
  transition: border-color 0.14s ease, color 0.14s ease;
}
.theme-btn:hover { border-color: var(--line-strong); color: var(--ink); }

/* Hero */
.hero {
  padding: 52px 0 40px;
  border-bottom: 1px solid var(--line);
}
.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 236px;
  gap: 44px;
  align-items: start;
}
.hero h1 {
  font-family: var(--font-serif);
  font-size: clamp(2.15rem, 3.8vw, 2.75rem);
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
}
.role-line {
  font-size: 1.04rem;
  color: var(--muted);
  margin: 0 0 20px;
  font-weight: 500;
}
.role-line strong {
  color: var(--ink);
  font-weight: 600;
}
.bio {
  margin: 0 0 14px;
  color: var(--ink);
  max-width: 66ch;
}
.bio:last-of-type { margin-bottom: 22px; }

.profile-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pill-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 500;
  text-decoration: none;
  transition: border-color 0.14s ease, background 0.14s ease, color 0.14s ease;
}
.pill-link:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
}
.pill-link.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
:root[data-theme="dark"] .pill-link.primary { color: #091316; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pill-link.primary { color: #091316; }
}
.pill-link.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.portrait-col {
  text-align: center;
}
.portrait-frame {
  width: 236px;
  height: 236px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background: var(--surface-alt);
}
.portrait-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.portrait-meta {
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--subtle);
  line-height: 1.45;
}

/* Sections */
section[id] { scroll-margin-top: 74px; }
section.block {
  padding: 48px 0;
  border-bottom: 1px solid var(--line);
}
section.block:last-of-type { border-bottom: none; }

.sec-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.sec-head h2 {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 0;
}
.sec-sub {
  font-size: 0.92rem;
  color: var(--muted);
  margin: 0;
}

/* Research cards */
.research-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  transition: border-color 0.16s ease, transform 0.16s ease;
}
.card:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}
.card-media {
  display: block;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  aspect-ratio: 16 / 10;
  overflow: hidden;
}
.card-media.dark-bg { background: #121824; }
.card-media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  padding: 8px;
}
.card-media.flush img { padding: 0; }
.card-body {
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  flex: 1;
}
.card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.card h3 {
  font-size: 1.12rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
.venue {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--badge-ink);
  background: var(--badge-bg);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.card p {
  margin: 0 0 12px;
  font-size: 0.93rem;
  color: var(--muted);
  line-height: 1.58;
}
.card-meta {
  font-size: 0.82rem;
  color: var(--subtle);
  margin: 0 0 14px;
}
.card-links {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.88rem;
  font-weight: 600;
}

/* Open-source grid */
.oss-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}
.oss-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.oss-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.oss-card h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
}
.stat-tag {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--muted);
  background: var(--surface-alt);
  padding: 2px 8px;
  border-radius: 6px;
}
.oss-card p {
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
  line-height: 1.56;
}
.oss-thumb {
  margin-top: 4px;
  border-radius: 8px;
  border: 1px solid var(--line);
  overflow: hidden;
  background: #ffffff;
  aspect-ratio: 16 / 9;
}
.oss-thumb.dark-bg { background: #000000; }
.oss-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.oss-links {
  margin-top: auto;
  padding-top: 4px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 0.87rem;
  font-weight: 600;
}

/* Publications list */
.pub-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.pub-item {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.pub-item:last-child { border-bottom: none; }
.pub-year {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  color: var(--subtle);
  padding-top: 2px;
}
.pub-title {
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}
.pub-title:hover { color: var(--accent); text-decoration: underline; }
.pub-authors {
  font-size: 0.88rem;
  color: var(--muted);
  margin-top: 2px;
}
.pub-authors strong { color: var(--ink); font-weight: 600; }
.pub-venue {
  font-size: 0.84rem;
  color: var(--subtle);
  margin-top: 2px;
}

details.more-pubs {
  margin-top: 16px;
}
details.more-pubs summary {
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  padding: 6px 0;
  user-select: none;
}
details.more-pubs summary:hover { color: var(--accent-hover); }

/* Background & honors */
.bg-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 32px;
}
.bg-col h3 {
  font-size: 0.82rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--subtle);
  margin: 0 0 14px;
}
.exp-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.exp-list li {
  font-size: 0.93rem;
  line-height: 1.5;
}
.exp-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.exp-org { font-weight: 600; color: var(--ink); }
.exp-date { font-family: var(--font-mono); font-size: 0.8rem; color: var(--subtle); }
.exp-desc { color: var(--muted); font-size: 0.88rem; margin-top: 2px; }

/* Beyond research strip */
.beyond-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}
.beyond-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.beyond-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  border-bottom: 1px solid var(--line);
}
.beyond-card .pad {
  padding: 14px 16px 16px;
}
.beyond-card h3 {
  font-size: 0.98rem;
  font-weight: 600;
  margin: 0 0 6px;
}
.beyond-card p {
  font-size: 0.87rem;
  color: var(--muted);
  margin: 0;
  line-height: 1.52;
}

/* Footer */
footer.site-footer {
  padding: 36px 0 48px;
  border-top: 1px solid var(--line);
  font-size: 0.88rem;
  color: var(--muted);
}
.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.footer-links {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.footer-links a { color: var(--muted); text-decoration: none; }
.footer-links a:hover { color: var(--accent); text-decoration: underline; }

/* 404 */
.notfound {
  min-height: calc(100vh - 160px);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px;
}
.notfound-box { max-width: 480px; }
.notfound-code {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--accent);
  margin-bottom: 8px;
}
.notfound h1 {
  font-family: var(--font-serif);
  font-size: 2rem;
  margin: 0 0 12px;
}
.notfound p { color: var(--muted); margin: 0 0 24px; }

/* Responsive */
@media (max-width: 820px) {
  .hero-grid {
    grid-template-columns: 1fr;
    gap: 24px;
  }
  .portrait-col {
    order: -1;
    display: flex;
    align-items: center;
    gap: 18px;
    text-align: left;
  }
  .portrait-frame { width: 108px; height: 108px; flex: none; border-radius: 14px; }
  .portrait-meta { margin-top: 0; }
  .research-grid, .oss-grid, .bg-grid, .beyond-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .wrap { padding: 0 16px; }
  .topbar-inner { height: auto; min-height: 52px; padding: 10px 0; flex-wrap: wrap; row-gap: 6px; }
  .nav-links { gap: 12px; width: 100%; justify-content: space-between; }
  .nav-links a { font-size: 0.84rem; }
  .theme-btn { width: 30px; height: 30px; }
  .hero { padding: 28px 0 26px; }
  section.block { padding: 36px 0; }
  .pub-item { grid-template-columns: 1fr; gap: 2px; }
}
