/* ==========================================================================
   Site styles
   Colours are tokens on :root; dark mode redefines them below.
   ========================================================================== */

:root {
  --bg: #ffffff;
  --bg-soft: #f5f7fa;
  --surface: #ffffff;
  --text: #18202e;
  --text-2: #475165;
  --text-3: #667085;
  --border: #e4e7ec;
  --accent: #1a5fb4;
  --accent-hover: #144c91;
  --accent-ink: #ffffff;
  --accent-soft: #eaf1fb;
  --journal: #1a5fb4;
  --journal-bg: #eaf1fb;
  --conf: #0b7a6e;
  --conf-bg: #e2f5f2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 16px rgba(16, 24, 40, .07);
  --radius: 12px;
  --topbar-h: 60px;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-serif: "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1117;
    --bg-soft: #161b24;
    --surface: #131821;
    --text: #e7eaf0;
    --text-2: #b4bccb;
    --text-3: #8b94a7;
    --border: #262d3a;
    --accent: #82b1ff;
    --accent-hover: #a8c8ff;
    --accent-ink: #0e1117;
    --accent-soft: rgba(130, 177, 255, .12);
    --journal: #82b1ff;
    --journal-bg: rgba(130, 177, 255, .13);
    --conf: #5ad1bf;
    --conf-bg: rgba(90, 209, 191, .13);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 16px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1117;
  --bg-soft: #161b24;
  --surface: #131821;
  --text: #e7eaf0;
  --text-2: #b4bccb;
  --text-3: #8b94a7;
  --border: #262d3a;
  --accent: #82b1ff;
  --accent-hover: #a8c8ff;
  --accent-ink: #0e1117;
  --accent-soft: rgba(130, 177, 255, .12);
  --journal: #82b1ff;
  --journal-bg: rgba(130, 177, 255, .13);
  --conf: #5ad1bf;
  --conf-bg: rgba(90, 209, 191, .13);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 16px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + 16px);
  -webkit-text-size-adjust: 100%;
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); 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;
}

img { max-width: 100%; height: auto; }
b, strong { font-weight: 600; }
p { margin: 0 0 1em; }

.container {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 0 24px;
}

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

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  gap: 16px;
}

.brand {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { color: var(--text); text-decoration: none; }

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

.nav { display: flex; align-items: center; gap: 2px; }
.nav a {
  padding: 6px 11px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: .92rem;
  font-weight: 500;
}
.nav a:hover { color: var(--text); background: var(--bg-soft); text-decoration: none; }
.nav a.active { color: var(--accent); }
.nav .nav-cv {
  margin-left: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 14px;
}
.nav .nav-cv:hover { border-color: var(--accent); color: var(--accent); background: transparent; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-size: 17px;
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }

.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: inline; }
:root[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: inline; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}

.menu-btn { display: none; }

/* ---------- Hero / About ---------- */
.hero {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  grid-template-areas:
    "photo main"
    "photo bio";
  column-gap: 44px;
  padding: 56px 0 48px;
}

.hero-photo { grid-area: photo; }
.hero-main { grid-area: main; }
.bio { grid-area: bio; margin-top: 22px; }

.avatar {
  display: block;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-soft);
  box-shadow: 0 0 0 4px var(--bg), 0 0 0 5px var(--border), var(--shadow);
}

.hero h1 {
  margin: 4px 0 8px;
  font-family: var(--font-serif);
  font-size: clamp(2.1rem, 5vw, 2.75rem);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -.015em;
}

.role {
  margin: 0;
  color: var(--text-2);
  font-size: 1.08rem;
}
.role a { color: inherit; border-bottom: 1px solid var(--border); }
.role a:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  margin: 10px 0 18px;
  color: var(--text-3);
  font-size: .93rem;
}
.hero-meta .fa { margin-right: 4px; }

.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: .92rem;
  font-weight: 600;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }

.social { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.social a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-2);
  font-size: 17px;
  transition: color .15s, border-color .15s, transform .15s;
}
.social a:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.social .ai { font-size: 18px; }

.bio p { color: var(--text-2); }
.bio p b { color: var(--text); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 0; padding: 0; list-style: none; }
.chips li {
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .82rem;
  font-weight: 500;
}

/* ---------- Sections ---------- */
.section { padding: 48px 0; border-top: 1px solid var(--border); }

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 8px;
}
.section-head .section-title { margin-bottom: 0; }

.section-title {
  margin: 0 0 24px;
  font-family: var(--font-serif);
  font-size: 1.7rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -.01em;
}

.section-aside { color: var(--text-3); font-size: .9rem; font-weight: 500; }
.section-aside .fa { font-size: .8em; margin-left: 2px; }

/* ---------- News ---------- */
.news { margin: 0; padding: 0; list-style: none; }
.news li {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 18px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
}
.news li:last-child { border-bottom: 0; }
.news-date {
  padding-top: 1px;
  color: var(--text-3);
  font-size: .88rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.news-text { color: var(--text-2); }
.news li.is-highlight .news-date { color: var(--accent); }
.news li.is-highlight .news-text { color: var(--text); }
.news-text strong { color: var(--text); }

details.more { margin-top: 6px; }
details.more summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
details.more summary::-webkit-details-marker { display: none; }
details.more summary::before { content: "+"; font-weight: 700; }
details.more[open] summary::before { content: "\2212"; }
details.more .news { margin-top: 8px; }

/* ---------- Publications ---------- */
.year-label {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 28px 0 4px;
  color: var(--text-3);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .1em;
}
.year-label::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.pubs { margin: 0; padding: 0; list-style: none; }
.pub {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 18px;
  padding: 14px 0;
}

.pub-meta { display: flex; flex-direction: column; gap: 6px; margin-top: 3px; }
.pub-first {
  color: var(--accent);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-align: center;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  width: 100%;
  padding: 4px 6px;
  border-radius: 6px;
  background: var(--journal-bg);
  color: var(--journal);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .02em;
  line-height: 1.3;
  text-align: center;
  white-space: nowrap;
}
.badge-conference { background: var(--conf-bg); color: var(--conf); }

.pub-body p { margin: 0; }
.pub-title { color: var(--text); font-weight: 600; line-height: 1.45; }
.pub-authors { margin-top: 3px !important; color: var(--text-2); font-size: .94rem; }
.pub-authors .me {
  color: var(--text);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}
.pub-venue { color: var(--text-3); font-size: .92rem; }
.pub-note {
  display: inline-block;
  margin-left: 4px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--conf-bg);
  color: var(--conf);
  font-size: .75rem;
  font-style: normal;
  font-weight: 700;
}

.pub-body .pub-remark {
  display: inline-flex;
  gap: 8px;
  margin-top: 8px;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--text-2);
  font-size: .88rem;
  line-height: 1.5;
}
.pub-remark .fa { margin-top: 3px; color: var(--accent); }

.pub-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pub-links:empty { display: none; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-2);
  font-size: .78rem;
  font-weight: 600;
  line-height: 1.6;
}
.pill:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

/* ---------- Project cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color .2s, box-shadow .2s, transform .2s;
}
.card:hover {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.card-image { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-bottom: 1px solid var(--border); }
.card-body { display: flex; flex-direction: column; flex: 1; padding: 18px 20px 20px; }
.card-meta { margin: 0 0 6px; color: var(--text-3); font-size: .8rem; font-weight: 500; }
.card-title { margin: 0 0 8px; font-size: 1.04rem; font-weight: 600; line-height: 1.4; }
.card-text { margin: 0 0 14px; color: var(--text-2); font-size: .93rem; line-height: 1.6; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.tags li {
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text-2);
  font-size: .75rem;
  font-weight: 500;
}

.card-links { display: flex; flex-wrap: wrap; gap: 14px; margin-top: auto; padding-top: 14px; font-size: .88rem; font-weight: 600; }

/* ---------- Timeline (education / experience) ---------- */
.timeline { position: relative; margin: 0; padding: 0; list-style: none; }
.timeline::before {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 6px;
  width: 2px;
  background: var(--border);
}

.tl-item { position: relative; padding: 0 0 28px 36px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
  content: "";
  position: absolute;
  top: 7px;
  left: 0;
  width: 14px;
  height: 14px;
  border: 3px solid var(--accent);
  border-radius: 50%;
  background: var(--bg);
}

.tl-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px 16px;
}
.tl-title { margin: 0; font-size: 1.04rem; font-weight: 600; line-height: 1.45; }
.tl-when { color: var(--text-3); font-size: .87rem; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tl-org { margin: 2px 0 0; color: var(--text-2); font-size: .95rem; }
.tl-org a { color: var(--text); font-weight: 500; }
.tl-org a:hover { color: var(--accent); }
.tl-loc { color: var(--text-3); white-space: nowrap; }

.tl-notes { margin: 8px 0 0; padding-left: 18px; color: var(--text-2); font-size: .93rem; list-style: disc; }
.tl-notes li { margin: 3px 0; }
.tl-notes li::marker { color: var(--text-3); }

/* ---------- Service & honors ---------- */
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 40px; }
.sub-title {
  margin: 0 0 10px;
  color: var(--text-3);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.plain-list { margin: 0; padding: 0; list-style: none; color: var(--text-2); font-size: .95rem; }
.plain-list li { padding: 6px 0; border-bottom: 1px dashed var(--border); }
.plain-list li:last-child { border-bottom: 0; }
.honor-year { margin-right: 6px; color: var(--text-3); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Footer ---------- */
.footer {
  padding: 36px 0 48px;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-3);
  font-size: .87rem;
  text-align: center;
}
.footer .social { justify-content: center; margin-bottom: 16px; }
.footer .social a { width: 34px; height: 34px; font-size: 15px; }
.footer p { margin: 4px 0; }
.footer .credit { font-size: .8rem; }
.footer .credit a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.visitor-map { display: flex; justify-content: center; max-width: 260px; margin: 18px auto 0; opacity: .85; }

/* ---------- WeChat dialog ---------- */
.qr-dialog {
  max-width: min(92vw, 340px);
  padding: 28px 24px 18px;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
  text-align: center;
}
.qr-dialog::backdrop { background: rgba(10, 14, 20, .55); }
.qr-dialog img { display: block; width: 100%; height: auto; border-radius: 8px; }
.qr-dialog p { margin: 12px 0 0; color: var(--text-2); font-size: .9rem; }
.qr-close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-3);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.qr-close:hover { background: var(--bg-soft); color: var(--text); }

/* ---------- Simple pages (404, project pages) ---------- */
.page { padding: 64px 0; }
.page h1 { margin: 0 0 8px; font-family: var(--font-serif); font-size: 2.2rem; font-weight: 600; line-height: 1.15; }
.page .subtitle { margin: 0 0 28px; color: var(--text-3); font-size: 1.1rem; }
.page .back { display: inline-block; margin-bottom: 20px; font-size: .9rem; font-weight: 600; }
.prose { color: var(--text-2); }
.prose h2, .prose h3 { color: var(--text); }
.prose img { border-radius: 8px; }
.figure { margin: 24px 0; text-align: center; }
.figure figcaption { margin-top: 8px; color: var(--text-3); font-size: .88rem; }

.notfound { padding: 96px 0; text-align: center; }
.notfound .code { margin: 0; color: var(--accent); font-family: var(--font-serif); font-size: 5rem; font-weight: 700; line-height: 1; }
.notfound h1 { margin: 12px 0 8px; font-family: var(--font-serif); font-size: 1.8rem; font-weight: 600; }
.notfound p { color: var(--text-2); }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .menu-btn { display: inline-flex; }
  .nav {
    position: absolute;
    top: var(--topbar-h);
    right: 0;
    left: 0;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 8px 16px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    box-shadow: var(--shadow);
  }
  .nav.open { display: flex; }
  .nav a { padding: 10px 12px; font-size: 1rem; }
  .nav .nav-cv { margin: 6px 0 0; text-align: center; }
}

@media (max-width: 720px) {
  .hero {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "photo" "main" "bio";
    padding: 40px 0 36px;
    text-align: center;
  }
  .hero-photo { display: flex; justify-content: center; margin-bottom: 20px; }
  .avatar { width: 148px; height: 148px; }
  .hero-meta, .hero-actions, .hero-actions .social { justify-content: center; }
  .bio { text-align: left; }
  .chips { justify-content: flex-start; }

  .cards, .two-col { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 560px) {
  .container { padding: 0 16px; }
  .section { padding: 40px 0; }
  .section-title { font-size: 1.5rem; }

  .news li { grid-template-columns: minmax(0, 1fr); gap: 2px; }

  .pub { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .pub-meta { flex-direction: row; align-items: center; gap: 10px; margin-top: 0; }
  .badge { width: auto; padding: 3px 9px; }

  .tl-item { padding-left: 30px; }
}

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

@media print {
  .topbar, .footer, .hero-actions, .skip-link, .pub-links, .card-links { display: none !important; }
  .section { padding: 20px 0; }
  .card { break-inside: avoid; }
  a { color: inherit; }
}
