/* ---------- Bilingual visibility ---------- */
html[lang="en"] .i18n-zh,
html[lang="zh"] .i18n-en {
  display: none;
}

/* Language toggle in header */
.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0;
  margin: 1rem 0 0;
  font-family: var(--sans);
  font-size: 0.88rem;
}
.lang-btn {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  padding: 0.25rem 0.7rem;
  cursor: pointer;
  font: inherit;
  transition: color 120ms, background 120ms, border-color 120ms;
}
.lang-btn:first-child { border-radius: 999px 0 0 999px; }
.lang-btn:last-child  { border-radius: 0 999px 999px 0; border-left: none; }
.lang-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.lang-btn:hover { color: var(--accent); }

/* Better Chinese text rendering */
html[lang="zh"] body {
  font-family: "Source Serif 4", "Noto Serif SC", "Songti SC", "PingFang SC", "Charter", Georgia, serif;
}

/* ---------- Tokens ---------- */
:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --ink: #1d1d1b;
  --ink-soft: #4a4a47;
  --muted: #7a7a75;
  --rule: #e7e3da;
  --accent: #8b1d1d;       /* deep crimson — academic feel */
  --accent-soft: #f5e9e9;
  --link: #8b1d1d;
  --link-hover: #5d1414;
  --serif: "Source Serif 4", "Charter", "Iowan Old Style", "Palatino", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --maxw: 880px;
  --gutter: 1.5rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --surface: #1d1c19;
    --ink: #ece8e0;
    --ink-soft: #c2bdb2;
    --muted: #8e887e;
    --rule: #312f2a;
    --accent: #d68a8a;
    --accent-soft: #2a1e1e;
    --link: #d68a8a;
    --link-hover: #f0b3b3;
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 4.5rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 120ms ease, color 120ms ease;
}
a:hover {
  color: var(--link-hover);
  border-bottom-color: currentColor;
}

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.25;
  color: var(--ink);
}

h1 { font-size: 2.1rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.5rem; margin: 0 0 1rem; }
h3 { font-size: 1.1rem; margin: 0 0 0.4rem; }

p { margin: 0 0 1rem; }

ul, ol { margin: 0 0 1rem; padding-left: 1.25rem; }
li { margin-bottom: 0.4rem; }

.skip {
  position: absolute; left: -9999px; top: auto;
  background: var(--ink); color: var(--bg); padding: 0.5rem 1rem;
  z-index: 999;
}
.skip:focus { left: 1rem; top: 1rem; }

/* ---------- Header ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  padding: 2.5rem 0 0;
}

.header-grid {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 2rem;
  align-items: start;
  padding-bottom: 1.5rem;
}

.photo img {
  width: 160px;
  height: 160px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--rule);
  background: var(--accent-soft);
  display: block;
}

.intro h1 {
  font-size: 2.25rem;
}
.intro .title {
  font-family: var(--sans);
  font-size: 1.05rem;
  color: var(--ink-soft);
  margin: 0 0 0.5rem;
}
.intro .tagline {
  font-style: italic;
  color: var(--muted);
  margin: 0 0 1rem;
  font-size: 0.95rem;
}

.links {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.25rem;
  font-family: var(--sans);
  font-size: 0.92rem;
}
.links li { margin: 0; }
.links a {
  color: var(--ink-soft);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1px;
}
.links a:hover { color: var(--link); border-bottom-color: currentColor; }

/* ---------- Nav ---------- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(251, 250, 247, 0.92);
  backdrop-filter: saturate(140%) blur(10px);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.9rem;
}
@media (prefers-color-scheme: dark) {
  .site-nav { background: rgba(22, 21, 19, 0.92); }
}
.site-nav .container {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.4rem;
  padding-top: 0.7rem;
  padding-bottom: 0.7rem;
}
.site-nav a {
  color: var(--ink-soft);
  border: none;
  padding: 0.15rem 0;
}
.site-nav a:hover { color: var(--link); }

/* ---------- Sections ---------- */
main { padding: 2.5rem 0 1rem; }

section {
  padding: 1.75rem 0 2rem;
  border-bottom: 1px solid var(--rule);
}
section:last-of-type { border-bottom: none; }

section h2 {
  position: relative;
  padding-bottom: 0.4rem;
  margin-bottom: 1.25rem;
}
section h2::after {
  content: "";
  position: absolute;
  left: 0; bottom: 0;
  width: 32px; height: 2px;
  background: var(--accent);
}

/* ---------- News ---------- */
.news-list {
  list-style: none;
  padding-left: 0;
  display: grid;
  gap: 0.25rem;
}
.news-item {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 1rem;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--rule);
  align-items: start;
}
.news-item:last-child { border-bottom: none; }

.news-item > .when {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
  padding-top: 0.35rem;
}

.news-body {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.75rem;
  align-items: baseline;
}
.news-body > .tag {
  margin-top: 0;
  align-self: start;
  position: relative;
  top: 0.15rem;
}
.news-body > p {
  margin: 0;
  line-height: 1.55;
  color: var(--ink);
}

.tag-service   { color: #1f6feb; background: rgba(31,111,235,0.08); }
.tag-position  { color: var(--accent); background: var(--accent-soft); }
.tag-pub       { color: #047857; background: rgba(4,120,87,0.10); }
.tag-milestone { color: #92400e; background: rgba(146,64,14,0.10); }
@media (prefers-color-scheme: dark) {
  .tag-service   { color: #6aa6ff; background: rgba(106,166,255,0.12); }
  .tag-pub       { color: #5fd1a7; background: rgba(95,209,167,0.12); }
  .tag-milestone { color: #f5b970; background: rgba(245,185,112,0.12); }
}

/* ---------- Cards (research interests) ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.card {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1rem 1.1rem;
  background: var(--surface);
  transition: border-color 150ms ease, transform 150ms ease;
}
.card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.card h3 {
  font-size: 1rem;
  margin-bottom: 0.35rem;
  color: var(--accent);
}
.card p {
  font-size: 0.92rem;
  color: var(--ink-soft);
  margin: 0;
  line-height: 1.5;
}

/* ---------- Publications ---------- */
.pubs-meta {
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
}
.filter-btn {
  font: inherit;
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  margin-right: 0.25rem;
}
.filter-btn.active,
.filter-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.pub-list {
  list-style: none;
  padding-left: 0;
  counter-reset: pub;
}
.pub {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 1rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--rule);
}
.pub:last-child { border-bottom: none; }
.pub.hidden { display: none; }

.pub .year {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
  padding-top: 0.2rem;
}
.pub-title {
  font-weight: 600;
  margin: 0 0 0.2rem;
  color: var(--ink);
  line-height: 1.35;
}
.pub-authors {
  font-family: var(--sans);
  font-size: 0.92rem;
  color: var(--ink-soft);
  margin: 0 0 0.15rem;
}
.pub-venue {
  font-family: var(--sans);
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0;
}

/* ---------- Projects ---------- */
.project-list {
  list-style: none;
  padding-left: 0;
  display: grid;
  gap: 1.25rem;
}
.project-list > li {
  border-left: 3px solid var(--accent);
  padding: 0.25rem 0 0.25rem 1rem;
}
.project-list h3 { font-size: 1.1rem; margin-bottom: 0.15rem; }
.project-list .meta {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0 0 0.4rem;
}
.project-list p:last-child {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

/* ---------- Teaching ---------- */
.teaching-list {
  list-style: none;
  padding-left: 0;
  display: grid;
  gap: 0.25rem;
}
.teach {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
  align-items: start;
}
.teach:last-child { border-bottom: none; }

.teach > .year {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
  padding-top: 0.4rem;
}

.teach-body {
  display: grid;
  gap: 0.3rem;
}

.teach-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.teach-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.35;
  color: var(--ink);
  flex: 1;
}

.teach-where {
  font-family: var(--sans);
  font-size: 0.92rem;
  color: var(--ink-soft);
  margin: 0;
}

.tag-lecturer { color: var(--accent); background: var(--accent-soft); }
.tag-invited  { color: #1f6feb; background: rgba(31,111,235,0.08); }
.tag-ta       { color: #6b7280; background: rgba(107,114,128,0.10); }
@media (prefers-color-scheme: dark) {
  .tag-invited { color: #6aa6ff; background: rgba(106,166,255,0.12); }
  .tag-ta      { color: #9ca3af; background: rgba(156,163,175,0.12); }
}

/* ---------- Talks & Posters ---------- */
.talks-meta {
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
}
.talk-filter {
  font: inherit;
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  margin-right: 0.25rem;
}
.talk-filter.active,
.talk-filter:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.talk-list {
  list-style: none;
  padding-left: 0;
  display: grid;
  gap: 0.25rem;
}
.talk {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
  align-items: start;
}
.talk:last-child { border-bottom: none; }
.talk.hidden { display: none; }

.talk > .year {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
  padding-top: 0.4rem;
}

.talk-body {
  display: grid;
  gap: 0.3rem;
}

.talk-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.talk-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.35;
  color: var(--ink);
  flex: 1;
}

.tag {
  display: inline-block;
  flex-shrink: 0;
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  margin-top: 0.2rem;
}
.tag-talk    { color: #1f6feb; background: rgba(31,111,235,0.08); }
.tag-poster  { color: var(--accent); background: var(--accent-soft); }
@media (prefers-color-scheme: dark) {
  .tag-talk { color: #6aa6ff; background: rgba(106,166,255,0.12); }
}

.talk-venue {
  font-family: var(--sans);
  font-size: 0.92rem;
  color: var(--ink-soft);
  margin: 0;
}

.talk-link {
  margin: 0.15rem 0 0;
  font-family: var(--sans);
  font-size: 0.88rem;
}
.talk-link a {
  color: var(--accent);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1px;
}
.talk-link a:hover { border-bottom-color: currentColor; }

/* ---------- Two column ---------- */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}
.two-col h3 {
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}
.two-col ul { padding-left: 1rem; }
.two-col li { font-size: 0.95rem; color: var(--ink-soft); }

/* ---------- Back to top ---------- */
#back-to-top {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--sans);
  font-size: 1.2rem;
  line-height: 1;
  background: var(--surface);
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease, color 120ms ease, border-color 120ms ease, background 120ms ease;
  z-index: 50;
}
#back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
#back-to-top:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
#back-to-top:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
@media (max-width: 640px) {
  #back-to-top { right: 1rem; bottom: 1rem; width: 40px; height: 40px; }
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--rule);
  padding: 1.5rem 0 2.5rem;
  margin-top: 1rem;
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

/* ---------- Blog page ---------- */
.post-list { list-style: none; padding-left: 0; }
.post-list > li {
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
}
.post-list h3 { margin-bottom: 0.2rem; }
.post-list h3 a { color: var(--ink); border: none; }
.post-list h3 a:hover { color: var(--link); }
.post-list .meta {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0 0 0.4rem;
}
.post-list p:last-child {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

/* ---------- CV (inline + full page) ---------- */
.cv-subhead {
  font-size: 0.85rem;
  font-family: var(--sans);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 1.25rem 0 0.5rem;
}
.cv-subhead:first-of-type { margin-top: 0; }

.cv-fullcv {
  margin-top: 1.25rem;
  font-family: var(--sans);
  font-size: 0.95rem;
}
.cv-fullcv a {
  color: var(--accent);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1px;
}
.cv-fullcv a:hover { border-bottom-color: currentColor; }

.cv-section { margin-bottom: 2rem; }
.cv-entry {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px dashed var(--rule);
}
.cv-entry:last-child { border-bottom: none; }
.cv-entry .when {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
  padding-top: 0.15rem;
}
.cv-entry h3 { font-size: 1rem; margin-bottom: 0.15rem; }
.cv-entry .where {
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--ink-soft);
  margin: 0 0 0.4rem;
}
.cv-entry ul { margin: 0.2rem 0 0; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  body { font-size: 17px; }
  .header-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
    text-align: left;
  }
  .photo img { width: 120px; height: 120px; }
  h1 { font-size: 1.7rem; }
  .intro h1 { font-size: 1.7rem; }
  .pub, .news-item, .talk, .teach, .cv-entry {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }
  .pub .year, .news-item > .when, .talk > .year, .teach > .year, .cv-entry .when {
    padding-top: 0;
  }
  .talk-head, .teach-head { flex-direction: column; gap: 0.4rem; }
  .news-body { grid-template-columns: 1fr; gap: 0.4rem; }
  .tag { align-self: flex-start; }
  .two-col { grid-template-columns: 1fr; gap: 1rem; }
  .site-nav .container { gap: 0 1rem; overflow-x: auto; flex-wrap: nowrap; }
}
