/* ============ Base ============ */
:root {
  --text: #1f2937;
  --heading: #111827;
  --muted: #6b7280;
  --faint: #9ca3af;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff4ff;
  --border: #e8eaed;
  --bg: #ffffff;
  --surface: #ffffff;
  --card-hover: #f7f9fc;
  --maxw: 800px;
}

/* Dark theme (explicit choice) */
:root[data-theme="dark"] {
  --text: #c4cbd4;
  --heading: #e7eaef;
  --muted: #8a94a0;
  --faint: #656e79;
  --accent: #7cb0f7;
  --accent-hover: #9cc6ff;
  --accent-soft: #1b2636;
  --border: #2f343c;
  --bg: #1a1e24;
  --surface: #23272f;
  --card-hover: #23272f;
}

/* Dark theme fallback when JS is disabled and system prefers dark */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --text: #c4cbd4;
    --heading: #e7eaef;
    --muted: #8a94a0;
    --faint: #656e79;
    --accent: #7cb0f7;
    --accent-hover: #9cc6ff;
    --accent-soft: #1b2636;
    --border: #2f343c;
    --bg: #1a1e24;
    --surface: #23272f;
    --card-hover: #23272f;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  font-size: 16.5px;
  line-height: 1.72;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 0.2s ease, color 0.2s ease;
}

/* ============ Top navigation ============ */
.topnav {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topnav-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.nav-brand {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
  color: var(--heading);
}
.nav-brand:hover { color: var(--accent); text-decoration: none; }
.nav-links {
  display: flex;
  gap: 22px;
  margin-left: auto;
}
.nav-links a {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
}
.nav-links a:hover { color: var(--accent); text-decoration: none; }

/* ============ Theme toggle ============ */
#theme-toggle {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s, transform 0.15s;
}
#theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
}
#theme-toggle svg { width: 18px; height: 18px; fill: currentColor; }

/* Offset anchored sections so they clear the sticky nav */
header.hero { scroll-margin-top: 64px; }
h2.section { scroll-margin-top: 74px; }

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 24px 90px;
}

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

/* ============ Section headings ============ */
h2.section {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.22rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--heading);
  margin: 58px 0 20px;
  padding-bottom: 11px;
  border-bottom: 1px solid var(--border);
}
h2.section::before {
  content: "";
  flex: 0 0 auto;
  width: 5px;
  height: 20px;
  border-radius: 3px;
  background: var(--accent);
}

/* ============ Header ============ */
header.hero {
  display: flex;
  align-items: center;
  gap: 50px;
  padding: 66px 0 30px;
}

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

.hero-text h1 {
  font-size: 2.3rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--heading);
  margin: 0 0 6px;
}
.hero-text .cn {
  color: var(--faint);
  font-weight: 500;
  font-size: 1.2rem;
  letter-spacing: 0;
  margin-left: 6px;
}

.hero-text .role {
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--text);
  margin: 12px 0 2px;
}
.hero-text .affil { color: var(--muted); font-size: 0.98rem; margin: 0; }

.hero-photo {
  flex: 0 0 auto;
  width: 188px;
  height: 188px;
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 18%;
  border: 5px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border), 0 14px 34px rgba(17, 24, 39, 0.16);
}

/* ============ Contact links ============ */
.links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}
.links a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 15px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: color 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.links a:hover {
  color: var(--accent);
  border-color: var(--accent);
  text-decoration: none;
  box-shadow: 0 3px 10px rgba(37, 99, 235, 0.12);
  transform: translateY(-1px);
}
.links svg { width: 16px; height: 16px; fill: currentColor; }

/* ============ Text blocks ============ */
p { margin: 0 0 15px; }
.about p:last-child { margin-bottom: 0; }
.about strong { color: var(--heading); font-weight: 650; }

/* ============ News ============ */
.news {
  max-height: 250px;
  overflow-y: auto;
  padding-right: 6px;
}
.news ul { list-style: none; margin: 0; padding: 0; }
.news li {
  display: flex;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 0.96rem;
}
.news li:last-child { border-bottom: none; }
.news .date {
  flex: 0 0 66px;
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 0.88rem;
  padding-top: 2px;
}

/* ============ Publications ============ */
.pub {
  display: flex;
  align-items: center;
  gap: 26px;
  padding: 20px;
  margin: 4px -20px;
  border-radius: 14px;
  transition: background 0.18s, box-shadow 0.18s;
}
.pub:hover {
  background: var(--card-hover);
  box-shadow: 0 6px 22px rgba(17, 24, 39, 0.06);
}

.pub-thumb {
  flex: 0 0 280px;
  width: 280px;
  height: auto;
  border-radius: 10px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(17, 24, 39, 0.06);
}

.pub-body { flex: 1 1 auto; min-width: 0; }
.pub-title {
  display: inline-block;
  font-weight: 700;
  font-size: 1.08rem;
  line-height: 1.36;
  color: var(--accent);
  margin: 0 0 5px;
}
.pub-title:hover { color: var(--accent-hover); text-decoration: underline; }
.pub-authors { font-size: 0.95rem; color: var(--text); margin: 0 0 3px; }
.pub-authors .me { font-weight: 700; color: var(--heading); }
.pub-venue { font-size: 0.93rem; font-style: italic; color: var(--muted); margin: 0 0 7px; }
.pub-venue b { color: var(--text); font-style: normal; }
.pub-desc { font-size: 0.93rem; color: var(--text); margin: 0 0 8px; }
.pub-links { display: flex; flex-wrap: wrap; gap: 8px; }
.pub-links a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 13px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  transition: background 0.15s, color 0.15s;
}
.pub-links a:hover {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}
.pub-links svg { width: 13px; height: 13px; fill: currentColor; }

/* ============ Experience ============ */
.exp {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.exp:last-of-type { border-bottom: none; }
.exp-logo {
  flex: 0 0 62px;
  width: 62px;
  height: 62px;
  object-fit: contain;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--border);
  padding: 6px;
}
.exp-body { flex: 1 1 auto; }
.exp-role { font-weight: 650; font-size: 1.02rem; color: var(--heading); margin: 0 0 3px; }
.exp-meta { font-style: italic; color: var(--muted); font-size: 0.93rem; margin: 0 0 3px; }
.exp-desc { color: var(--text); font-size: 0.94rem; margin: 0; }

/* ============ Education ============ */
.entry { display: flex; align-items: center; gap: 20px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.entry:last-of-type { border-bottom: none; }
.edu-logo {
  flex: 0 0 auto;
  width: 54px;
  height: 54px;
  object-fit: contain;
  border-radius: 10px;
}
:root[data-theme="dark"] .edu-logo,
:root[data-theme="dark"] .exp-logo { background: #e9eaed; }
:root[data-theme="dark"] .pub-thumb { filter: brightness(0.9); }
.entry .what { flex: 1 1 auto; }
.entry .what .place { font-weight: 650; color: var(--heading); }
.entry .what .detail { color: var(--muted); font-size: 0.94rem; }

/* ============ Footer ============ */
footer {
  margin-top: 60px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  color: var(--faint);
  font-size: 0.85rem;
  text-align: center;
}

/* ============ Responsive ============ */
@media (max-width: 640px) {
  body { font-size: 16px; }
  .topnav-inner { height: 52px; gap: 12px; padding: 0 14px; }
  .nav-brand { display: none; }
  .nav-links {
    margin-left: 0;
    gap: 15px;
    font-size: 0.85rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .nav-links::-webkit-scrollbar { display: none; }
  #theme-toggle { margin-left: auto; }
  header.hero {
    flex-direction: column-reverse;
    text-align: center;
    gap: 22px;
    padding-top: 44px;
  }
  .links { justify-content: center; }
  .hero-text h1 { font-size: 2rem; }
  .hero-photo { width: 158px; height: 158px; }
  .pub { flex-direction: column; align-items: flex-start; gap: 14px; }
  .pub-thumb { width: 100%; height: auto; flex-basis: auto; }
  .exp, .entry { align-items: flex-start; }
}
