/* ---------- Design tokens ---------- */
:root {
  --serif: "Source Serif 4", Charter, "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  --ink: #1a1a1a;
  --ink-muted: #555;
  --ink-faint: #888;
  --rule: #e3e3e0;
  --bg: #f3f6ee;
  --accent: #7a2e2e;
  --accent-hover: #5a1f1f;
  --accent-blue: #1f4d8f;

  /* Caps the shell, but also keeps a visible margin on screens narrower than
     the cap — otherwise the page runs edge-to-edge on a 1440px laptop. */
  --page-max: min(1166px, 73vw);
  --sidebar-w: 260px;
  --gap: 64px;
  --gutter: 48px;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "kern", "liga", "onum";
}

/* ---------- Links ---------- */
a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

a:hover {
  color: var(--accent-hover);
  border-bottom-color: var(--accent-hover);
}

a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ---------- Top site header ---------- */
.site-header {
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(180%) blur(10px);
}

.site-header-inner {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 18px var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.site-name {
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  border-bottom: none;
}

.site-name:hover {
  color: var(--accent);
  border-bottom: none;
}

/* ---------- English / Chinese name formatting ---------- */
.name-en {
  font-family: inherit;
}

.name-zh {
  font-family: "Kaiti SC", "STKaiti", KaiTi, "楷体", serif;
  font-size: 0.84em;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-left: 0.16em;
  color: var(--ink);
  vertical-align: baseline;
  position: relative;
  top: 0.01em;
}

.site-name .name-zh {
  font-size: 0.78em;
  font-weight: 600;
}

.sidebar-name .name-zh {
  font-size: 0.84em;
  font-weight: 600;
}

/* ---------- Top nav ---------- */
.page-nav {
  font-family: var(--sans);
  font-size: 0.92rem;
  display: flex;
  gap: 28px;
}

.page-nav a {
  color: var(--ink-muted);
  border-bottom: none;
  padding: 6px 0;
  position: relative;
}

.page-nav a:hover {
  color: var(--accent);
  border-bottom: none;
}

.page-nav a[aria-current="page"] {
  color: var(--ink);
  font-weight: 600;
}

.page-nav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -19px;
  height: 2px;
  background: var(--accent);
}

/* ---------- Page grid ---------- */
.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 56px var(--gutter) 96px;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: var(--gap);
  align-items: start;
}

.page--no-sidebar {
  grid-template-columns: 1fr;
  max-width: var(--page-max);
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 96px;
  align-self: start;
}

.headshot {
  width: 100%;
  max-width: 220px;
  height: auto;
  border-radius: 2px;
  background: #eee;
  display: block;
  margin: 0 0 22px;
}

.sidebar-name {
  font-family: var(--serif);
  font-size: 1.55rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin: 0 0 8px;
}

.sidebar-institution {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink);
  font-weight: 500;
  margin: 0 0 14px;
  line-height: 1.5;
}

.sidebar-meta {
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: var(--sans);
  font-size: 0.95rem;
}

.sidebar-meta li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  color: var(--ink-muted);
  line-height: 1.4;
}

.sidebar-meta a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-muted);
  border-bottom: none;
}

.sidebar-meta a:hover {
  color: var(--accent);
  border-bottom: none;
}

.sidebar-meta .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--ink-faint);
}

.sidebar-meta a:hover .icon {
  color: var(--accent);
}

/* ---------- Content sections ---------- */
.content section {
  margin-bottom: 32px;
  scroll-margin-top: 96px;
}

.content section:last-child {
  margin-bottom: 0;
}

/* ---------- Page intro: role + department ---------- */
/* .intro-role is set with the h2 rule below so the role line reads as the
   same kind of heading as "Research Interests" / "Research Topics". */
.intro-dept {
  font-family: var(--sans);
  font-size: 0.98rem;
  color: var(--ink-muted);
  margin: 0;
  line-height: 1.5;
}

.intro-dept a {
  color: inherit;
  border-bottom: 1px solid transparent;
}

.intro-dept a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.about-text {
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
}

/* ---------- Research topics list ---------- */
/* Inherits the body serif, size, colour and leading, so each topic is set
   exactly like the research-interests line above it — only bulleted. */
.research-list {
  padding-left: 1.2em;
  margin: 0;
}

/* ---------- Headings ---------- */
/* Three tiers, each a different family/size so the level is unambiguous:
   page title (serif) > group label (sans) > paper title (serif). */
h2,
.intro-role {
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin: 0 0 16px;
  text-wrap: balance;
}

/* The role sits directly on its department line, not on a block of content. */
.intro-role {
  margin-bottom: 4px;
}

h3.subsection {
  font-family: var(--sans);
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--ink);
  margin: 48px 0 22px;
}

/* Two classes, so the colour wins over h3.subsection whatever the source order. */
.subsection.subsection--blue {
  color: var(--accent-blue);
}

/* A qualifier inside a group label — e.g. the institution — steps back from
   the label itself. em keeps it proportional to the heading. */
.subsection-note {
  font-size: 0.74em;
  font-weight: 400;
}

/* The first group label needs no leading gap — it opens the section. */
h3.subsection:first-child,
h2 + h3.subsection {
  margin-top: 0;
}

/* A group label following a paper closes the group with the same hairline,
   and the same 32px on either side, that separates two papers. */
.paper + h3.subsection {
  border-top: 1px solid var(--rule);
  margin-top: 32px;
  padding-top: 32px;
}

p {
  margin: 0 0 14px;
}

section p:last-child {
  margin-bottom: 0;
}

em {
  color: var(--ink);
}

/* ---------- Papers ---------- */
.paper {
  margin: 0 0 32px;
}

.paper:last-child {
  margin-bottom: 0;
}

/* Hairline only between consecutive entries — the same separator the news,
   talks and CV lists use — so no stray rule is left above the next heading. */
.paper + .paper {
  border-top: 1px solid var(--rule);
  padding-top: 32px;
}

.paper-title {
  font-family: var(--serif);
  font-size: 1.32rem;
  font-weight: 600;
  margin: 0 0 6px;
  line-height: 1.4;
  text-wrap: balance;
}

.paper-meta,
.paper-links {
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--ink-muted);
  margin: 0 0 10px;
}

/* Poster / Website carry the same weight as the paper title. */
.paper-links a {
  font-weight: 600;
}

.paper-status {
  font-style: italic;
}

.paper-sep {
  color: var(--ink-faint);
}

.paper-meta .sep {
  color: var(--ink-faint);
  margin: 0 6px;
}

.paper-meta .status {
  font-style: italic;
}

.paper-abstract {
  font-size: 1.08rem;
  color: var(--ink-muted);
  line-height: 1.68;
  margin: 0;
}

.paper-abstract p {
  margin: 0;
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
}

.paper-abstract em {
  font-style: normal;
  font-weight: 600;
  color: var(--ink);
}

.paper-abstract strong {
  font-weight: 600;
  color: var(--ink);
}

.paper-presentations {
  font-family: var(--sans);
  font-size: 0.98rem;
  color: var(--ink-muted);
  line-height: 1.6;
  margin: 12px 0 0;
}

.paper-presentations em {
  font-style: normal;
  font-weight: 600;
  color: var(--ink);
}

.paper-presentations .presentation-note {
  color: var(--ink-faint);
  font-style: italic;
}

/* ---------- Lists ---------- */
/* Entries are set like .paper-title so a work-in-progress reads as the same
   kind of object as a working paper, but with no rule between them. */
.wip-list {
  list-style: none;
  font-family: var(--serif);
  font-size: 1.32rem;
  font-weight: 600;
  color: var(--ink);
  padding-left: 0;
  margin: 0;
}

.wip-list li {
  margin-bottom: 32px;
  line-height: 1.4;
}

.wip-list li:last-child {
  margin-bottom: 0;
}

/* ---------- Section intro ---------- */
.section-intro {
  font-size: 1.2rem;
  color: var(--ink);
  margin: 0 0 24px;
}

.section-intro:has(+ h3) {
  margin-bottom: 16px;
}

/* ---------- News list ---------- */
.news-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.97rem;
}

.news-list li {
  display: flex;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
  line-height: 1.5;
}

.news-list li:last-child {
  border-bottom: none;
}

.news-date {
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex: 0 0 88px;
  padding-top: 3px;
}

/* ---------- Talks / teaching ---------- */
/* The grid lives on the list, not on each row, so every entry shares the same
   column tracks and the terms line up in a column. Rows are `display: contents`
   so their three spans land directly in that shared grid. */
.talk-list,
.teaching-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 150px auto 1fr;
  align-items: baseline;
  column-gap: 20px;
  row-gap: 22px;
}

.talk,
.course {
  display: contents;
}

.talk-type,
.course-type {
  font-family: var(--sans);
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--ink);
  grid-column: 1;
}

.talk-title,
.course-title {
  font-family: var(--serif);
  font-size: 1.32rem;
  font-weight: 600;
  color: var(--ink);
  grid-column: 2;
  line-height: 1.4;
}

.talk-meta,
.course-meta {
  font-family: var(--sans);
  font-size: 0.98rem;
  color: var(--ink-muted);
  grid-column: 3;
  padding-left: 32px;
}

.course-sep {
  color: var(--ink-faint);
}

/* ---------- CV ---------- */
.cv-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.cv-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
}

.cv-item:last-child {
  border-bottom: none;
}

.cv-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
}

.cv-title {
  font-family: var(--serif);
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.4;
}

.cv-date {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cv-detail {
  font-family: var(--sans);
  font-size: 0.92rem;
  color: var(--ink-muted);
  margin-top: 2px;
  line-height: 1.55;
}

/* ---------- Footer ---------- */
footer {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 24px var(--gutter) 40px;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--ink-faint);
  text-align: center;
}

footer p {
  margin: 0;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  :root {
    /* The desktop shell is capped at a share of the viewport, which would
       leave a phone with a fraction of its own width. Below the breakpoint the
       gutter alone sets the margin. */
    --page-max: 100%;
    --gutter: 22px;
  }

  /* Name and nav stay on one line and wrap only if they must, rather than
     always stacking into a two-row sticky header. */
  .site-header-inner {
    flex-wrap: wrap;
    gap: 8px 20px;
    padding: 14px var(--gutter);
  }

  .page-nav {
    gap: 20px;
  }

  .content {
    overflow-wrap: break-word;
  }

  .page-nav a[aria-current="page"]::after {
    display: none;
  }

  .page-nav a[aria-current="page"] {
    color: var(--accent);
  }

  .page {
    grid-template-columns: 1fr;
    gap: 36px;
    padding: 36px var(--gutter) 64px;
  }

  .sidebar {
    position: static;
    text-align: center;
  }

  .headshot {
    max-width: 160px;
    margin: 0 auto 16px;
  }

  .sidebar-name {
    font-size: 1.4rem;
  }
}

@media (max-width: 600px) {
  body {
    font-size: 17px;
  }

  /* The desktop scale is tuned for a ~1000px column; on a phone the same sizes
     leave headings with too few words per line. */
  h3.subsection {
    font-size: 1.3rem;
    margin-top: 40px;
  }

  .paper-title,
  .wip-list {
    font-size: 1.22rem;
  }

  .section-intro {
    font-size: 1.1rem;
  }

  /* Justified text needs room to distribute; on a narrow column it opens
     rivers of white space instead. */
  .paper-abstract p,
  .about-text {
    text-align: left;
    hyphens: none;
  }

  /* A fixed label column would leave the course title only ~180px; drop the
     shared grid and stack the three parts per entry instead. */
  .talk-list,
  .teaching-list {
    display: block;
  }

  .talk,
  .course {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2px;
    padding: 14px 0;
  }

  .talk-type,
  .course-type {
    grid-row: 1;
    grid-column: 1;
    padding-top: 0;
  }

  .talk-title,
  .course-title {
    grid-row: 2;
    grid-column: 1;
  }

  .talk-meta,
  .course-meta {
    grid-row: 3;
    grid-column: 1;
  }

  footer {
    padding: 20px var(--gutter) 32px;
  }
}
