/* ========== Tokens ========== */
:root {
  --bg: #f6f4ef;
  --bg-soft: #efece4;
  --surface: #fffdf9;
  --ink: #17171c;
  --ink-2: #3b3b45;
  --muted: #74737d;
  --line: #e2ded4;
  --accent: #3a46d6;
  --accent-ink: #2b35a8;
  --accent-soft: rgba(58, 70, 214, .09);
  --warm: #d4572b;
  --shadow: 0 1px 2px rgba(20, 20, 30, .04), 0 8px 28px -12px rgba(20, 20, 30, .14);
  --radius: 14px;
  --serif: "Fraunces", "Noto Serif SC", Georgia, serif;
  --sans: "Inter", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --maxw: 1080px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0e0f13;
  --bg-soft: #15171d;
  --surface: #17191f;
  --ink: #ecebe6;
  --ink-2: #c4c3cc;
  --muted: #8b8a95;
  --line: #262832;
  --accent: #8f9bff;
  --accent-ink: #b3bbff;
  --accent-soft: rgba(143, 155, 255, .12);
  --warm: #ff8a5c;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -12px rgba(0,0,0,.6);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0f13; --bg-soft: #15171d; --surface: #17191f;
    --ink: #ecebe6; --ink-2: #c4c3cc; --muted: #8b8a95; --line: #262832;
    --accent: #8f9bff; --accent-ink: #b3bbff; --accent-soft: rgba(143,155,255,.12);
    --warm: #ff8a5c; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -12px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}

/* ========== Base ========== */
*, *::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: 16px/1.7 var(--sans); -webkit-font-smoothing: antialiased;
  transition: background .3s, color .3s;
}
body::before { /* subtle grain glow */
  content: ""; position: fixed; inset: -20% -10% auto; height: 70vh; z-index: -1; pointer-events: none;
  background:
    radial-gradient(40% 50% at 15% 20%, var(--accent-soft), transparent 70%),
    radial-gradient(30% 40% at 85% 10%, rgba(212, 87, 43, .07), transparent 70%);
}
a { color: var(--accent); text-decoration: none; transition: color .2s; }
a:hover { color: var(--accent-ink); }
img { max-width: 100%; display: block; }
::selection { background: var(--accent); color: #fff; }
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }
@media (max-width: 600px) { .wrap { padding: 0 16px; } }

h1, h2, h3 { font-family: var(--serif); font-weight: 500; letter-spacing: -.01em; line-height: 1.2; margin: 0; }
.muted { color: var(--muted); }

/* ========== Nav ========== */
.nav {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid transparent; transition: border-color .3s;
}
.nav.scrolled { border-bottom-color: var(--line); }
.nav-inner { display: flex; align-items: center; gap: 24px; height: 64px; }
.brand { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; color: var(--ink); display: flex; align-items: center; gap: 10px; }
.brand:hover { color: var(--ink); }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: var(--ink); color: var(--bg); font-size: .85rem; font-family: var(--serif); font-style: italic;
}
.nav-links { display: flex; gap: 4px; margin-left: auto; }
.nav-links a {
  color: var(--ink-2); font-size: .92rem; font-weight: 500; padding: 6px 12px; border-radius: 999px;
}
.nav-links a:hover { color: var(--ink); background: var(--bg-soft); }
.nav-links a.active { color: var(--ink); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-2); display: grid; place-items: center; cursor: pointer; font-size: .9rem;
}
.icon-btn:hover { color: var(--ink); }
.menu-btn { display: none; }
@media (max-width: 760px) {
  .menu-btn { display: grid; margin-left: auto; }
  .nav-links {
    position: absolute; top: 64px; left: 0; right: 0; flex-direction: column; gap: 2px;
    background: var(--bg); border-bottom: 1px solid var(--line); padding: 8px 16px 16px;
    display: none;
  }
  .nav-links.open { display: flex; }
  .nav-links a { padding: 10px 12px; }
}

/* ========== Hero ========== */
.hero { padding: 72px 0 40px; }
.hero-grid { display: grid; grid-template-columns: 1fr 280px; gap: 56px; align-items: center; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 8px; font-size: .8rem; font-weight: 500; color: var(--ink-2);
  padding: 5px 12px 5px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
}
.eyebrow .dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.hero h1 { font-size: clamp(2.6rem, 6vw, 4.4rem); margin: 20px 0 6px; font-weight: 400; }
.hero h1 em { font-style: italic; color: var(--accent); }
.hero .zh { font-family: var(--serif); color: var(--muted); font-size: 1.1rem; letter-spacing: .2em; }
.hero .lede { font-size: 1.2rem; color: var(--ink-2); margin: 22px 0 0; max-width: 34em; line-height: 1.6; }
.hero .lede b { color: var(--ink); font-weight: 600; }
.cta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 999px;
  font-size: .9rem; font-weight: 500; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); transition: transform .15s, border-color .2s, background .2s;
}
.btn:hover { color: var(--ink); border-color: var(--ink-2); transform: translateY(-1px); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.primary:hover { color: var(--bg); }

.portrait { position: relative; }
.portrait img {
  width: 100%; aspect-ratio: 4/5; object-fit: cover; border-radius: 22px; box-shadow: var(--shadow);
  position: relative; z-index: 1;
}
.portrait::before {
  content: ""; position: absolute; inset: 14px -14px -14px 14px; border-radius: 22px;
  border: 1.5px solid var(--accent); opacity: .5;
}
.facts { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 8px; font-size: .88rem; color: var(--ink-2); }
.facts i { width: 20px; color: var(--muted); }
@media (max-width: 820px) {
  .hero { padding: 40px 0 24px; }
  .hero-grid { grid-template-columns: 1fr; gap: 32px; }
  .portrait { max-width: 220px; order: -1; }
}

/* ========== Sections ========== */
.section { padding: 48px 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.section-head h2 { font-size: 1.9rem; }
.section-head h2 .idx { font-family: var(--mono); font-size: .8rem; color: var(--warm); vertical-align: super; margin-right: 8px; letter-spacing: 0; }
.section-head a.more { font-size: .9rem; font-weight: 500; white-space: nowrap; }
.section-head a.more i { font-size: .75rem; transition: transform .2s; }
.section-head a.more:hover i { transform: translateX(3px); }
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }

.page-head { padding: 64px 0 24px; }
.page-head h1 { font-size: clamp(2.2rem, 5vw, 3.4rem); font-weight: 400; }
.page-head p { color: var(--ink-2); font-size: 1.1rem; max-width: 40em; margin: 12px 0 0; }

/* Interests */
.interests { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.interest {
  padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  transition: transform .2s, box-shadow .2s;
}
.interest:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.interest i { font-size: 1.1rem; color: var(--accent); }
.interest h3 { font-size: 1.12rem; margin: 14px 0 6px; }
.interest p { margin: 0; font-size: .88rem; color: var(--muted); line-height: 1.55; }
@media (max-width: 900px) { .interests { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .interests { grid-template-columns: 1fr; } }

/* News */
.news { list-style: none; margin: 0; padding: 0; }
.news li { display: grid; grid-template-columns: 90px 1fr; gap: 16px; padding: 12px 0; border-bottom: 1px dashed var(--line); }
.news li:last-child { border-bottom: 0; }
.news .date { font-family: var(--mono); font-size: .82rem; color: var(--muted); padding-top: 2px; }

/* Two column */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 48px; }
@media (max-width: 820px) { .split { grid-template-columns: 1fr; gap: 24px; } }

/* ========== Publications ========== */
.pub {
  display: grid; grid-template-columns: 96px 1fr; gap: 20px; padding: 20px 0;
  border-bottom: 1px solid var(--line);
}
.pub:last-child { border-bottom: 0; }
.venue-tag {
  align-self: start; text-align: center; padding: 8px 6px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent-ink);
  font-size: .75rem; font-weight: 600; line-height: 1.3; letter-spacing: .02em;
}
.venue-tag span { display: block; font-family: var(--mono); font-weight: 400; opacity: .8; margin-top: 2px; }
.pub h3 { font-family: var(--sans); font-size: 1.02rem; font-weight: 600; line-height: 1.45; letter-spacing: 0; }
.pub h3 a { color: var(--ink); }
.pub h3 a:hover { color: var(--accent); }
.pub .authors { margin: 6px 0 0; font-size: .9rem; color: var(--muted); }
.pub .authors b { color: var(--ink); font-weight: 600; text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; }
.pub-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: .76rem; font-weight: 500;
  padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2); background: var(--surface);
}
a.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.tag { background: transparent; color: var(--muted); }
@media (max-width: 560px) {
  .pub { grid-template-columns: 1fr; gap: 8px; }
  .venue-tag { justify-self: start; display: inline-flex; gap: 6px; padding: 4px 10px; }
  .venue-tag span { margin: 0; }
}

/* Toolbar / filters */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 16px 0 8px; position: sticky; top: 64px; z-index: 10; background: var(--bg); }
.search {
  flex: 1 1 260px; display: flex; align-items: center; gap: 10px; padding: 0 14px; height: 42px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
}
.search:focus-within { border-color: var(--accent); }
.search i { color: var(--muted); font-size: .85rem; }
.search input { border: 0; outline: 0; background: transparent; color: var(--ink); font: inherit; font-size: .92rem; width: 100%; }
.seg { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.seg button, .filters button {
  border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: .84rem; font-weight: 500;
  padding: 6px 14px; border-radius: 999px; cursor: pointer;
}
.seg button.on { background: var(--ink); color: var(--bg); }
.filters { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 8px; }
.filters button { border: 1px solid var(--line); background: var(--surface); padding: 4px 12px; }
.filters button.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.year-label { font-family: var(--serif); font-size: 1.5rem; color: var(--muted); padding: 28px 0 4px; display: flex; align-items: center; gap: 14px; }
.year-label::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.count { font-size: .85rem; color: var(--muted); }
.empty { padding: 48px 0; text-align: center; color: var(--muted); }

/* ========== Blog ========== */
.posts { display: grid; gap: 4px; }
.post-item {
  display: grid; grid-template-columns: 120px 1fr; gap: 20px; padding: 22px 16px; margin: 0 -16px;
  border-radius: var(--radius); color: var(--ink); transition: background .2s;
}
.post-item:hover { background: var(--surface); color: var(--ink); }
.post-item time { font-family: var(--mono); font-size: .82rem; color: var(--muted); padding-top: 4px; }
.post-item h3 { font-size: 1.35rem; transition: color .2s; }
.post-item:hover h3 { color: var(--accent); }
.post-item p { margin: 6px 0 10px; color: var(--ink-2); font-size: .95rem; }
@media (max-width: 560px) { .post-item { grid-template-columns: 1fr; gap: 4px; } }

.article { max-width: 720px; margin: 0 auto; padding: 56px 0 40px; }
.article-head { margin-bottom: 36px; }
.article-head h1 { font-size: clamp(2rem, 5vw, 2.9rem); font-weight: 400; margin: 14px 0 12px; }
.article-head .meta { color: var(--muted); font-size: .9rem; display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.back { font-size: .9rem; font-weight: 500; }
.prose { font-size: 1.06rem; line-height: 1.85; color: var(--ink-2); }
.prose > * + * { margin-top: 1.1em; }
.prose h2 { font-size: 1.6rem; color: var(--ink); margin-top: 2em; }
.prose h3 { font-size: 1.25rem; color: var(--ink); margin-top: 1.6em; }
.prose strong { color: var(--ink); }
.prose p, .prose ul, .prose ol { margin-bottom: 0; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li + li { margin-top: .3em; }
.prose blockquote {
  margin: 1.4em 0; padding: 4px 20px; border-left: 3px solid var(--accent); color: var(--ink-2);
  background: var(--accent-soft); border-radius: 0 10px 10px 0;
}
.prose code { font-family: var(--mono); font-size: .86em; background: var(--bg-soft); padding: 2px 6px; border-radius: 6px; }
.prose pre { background: #15161c; color: #e6e6e6; padding: 18px 20px; border-radius: 12px; overflow-x: auto; font-size: .88rem; line-height: 1.6; }
.prose pre code { background: none; padding: 0; color: inherit; font-size: inherit; }
.prose img { border-radius: 12px; margin: 1.6em auto; }
.prose table { width: 100%; border-collapse: collapse; font-size: .92rem; display: block; overflow-x: auto; }
.prose th, .prose td { padding: 8px 14px; border-bottom: 1px solid var(--line); text-align: left; }
.prose th { color: var(--ink); font-weight: 600; }
.prose hr { border: 0; height: 1px; background: var(--line); margin: 2.4em 0; }
.prose .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

/* ========== Projects ========== */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card {
  display: flex; flex-direction: column; padding: 22px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--ink); transition: transform .2s, box-shadow .2s, border-color .2s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); color: var(--ink); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-top i.fa-folder-open { color: var(--accent); font-size: 1.1rem; }
.card h3 { font-family: var(--sans); font-size: 1.05rem; font-weight: 600; margin: 14px 0 8px; letter-spacing: 0; }
.card p { color: var(--muted); font-size: .9rem; margin: 0 0 16px; line-height: 1.6; flex: 1; }
.card-foot { display: flex; align-items: center; gap: 14px; font-size: .8rem; color: var(--muted); flex-wrap: wrap; }
.lang-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.stars { display: inline-flex; align-items: center; gap: 4px; }

/* ========== Timeline ========== */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 26px 26px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 10px; bottom: -10px; width: 1px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.timeline li::after { content: ""; position: absolute; left: 0; top: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--bg); border: 2px solid var(--accent); }
.timeline .when { font-family: var(--mono); font-size: .78rem; color: var(--muted); }
.timeline h3 { font-family: var(--sans); font-size: 1rem; font-weight: 600; letter-spacing: 0; margin: 2px 0; }
.timeline .org { color: var(--accent); font-size: .9rem; font-weight: 500; }
.timeline p { margin: 4px 0 0; font-size: .88rem; color: var(--muted); }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: .94rem; }
.plain li:last-child { border-bottom: 0; }
h3.sub { font-size: 1.25rem; margin-bottom: 14px; }

/* ========== Footer ========== */
.footer { margin-top: 56px; border-top: 1px solid var(--line); padding: 40px 0 48px; }
.footer-inner { display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap; }
.footer .social { display: flex; gap: 8px; }
.footer small { color: var(--muted); font-size: .84rem; }

/* Reveal animation */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity .6s ease, transform .6s ease; }
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .reveal { opacity: 1; transform: none; transition: none; } html { scroll-behavior: auto; } }
