/*
  Layout: two page types, following the reference site.
  The landing page pairs a long copy column with a large photo.
  Inner pages use a sticky profile sidebar beside a reading column.

  To change the main colour, edit --ledger in all three colour blocks below.
*/
:root {
  --paper: #FBFAF6;
  --paper-soft: #F3F0E6;
  --ink: #1F1A12;
  --ink-mid: #3D372A;
  --ink-soft: #57534E;
  --ledger: #1D4A3C;
  --red-ink: #8C3818;
  --brass: #B5853A;
  --rule: rgba(31, 26, 18, .12);
  --rule-strong: rgba(31, 26, 18, .28);
  --mast: rgba(251, 250, 246, .88);
  --photo-shadow: rgba(31, 26, 18, .28);

  --serif: "Newsreader", "Noto Serif SC", Georgia, "Songti SC", "STSong", "SimSun", serif;
  --serif-cjk: "Noto Serif SC", "Songti SC", "STSong", "SimSun", "Newsreader", Georgia, serif;
  --sans: "Inter", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;

  --page: 1180px;
  --gutter: clamp(16px, 3.5vw, 32px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #171A18;
    --paper-soft: #212522;
    --ink: #F6F4EC;
    --ink-mid: #D3CFC2;
    --ink-soft: #B4B0A4;
    --ledger: #8CC7AD;
    --red-ink: #DD8A68;
    --brass: #D4A258;
    --rule: rgba(251, 250, 246, .14);
    --rule-strong: rgba(251, 250, 246, .3);
    --mast: rgba(23, 26, 24, .88);
    --photo-shadow: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #171A18;
  --paper-soft: #212522;
  --ink: #F6F4EC;
  --ink-mid: #D3CFC2;
  --ink-soft: #B4B0A4;
  --ledger: #8CC7AD;
  --red-ink: #DD8A68;
  --brass: #D4A258;
  --rule: rgba(251, 250, 246, .14);
  --rule-strong: rgba(251, 250, 246, .3);
  --mast: rgba(23, 26, 24, .88);
  --photo-shadow: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* Language switch: every string exists twice, one .en and one .zh */
html[data-lang="zh"] .en { display: none !important; }
html:not([data-lang="zh"]) .zh { display: none !important; }

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

html {
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 5.5rem;
}
@media (min-width: 1100px) { html { font-size: 18px; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.7;
  overflow-wrap: break-word;
}
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 30;
  background: var(--paper);
}

img { display: block; max-width: 100%; height: auto; }

a {
  color: var(--ledger);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: var(--rule-strong);
  transition: color .15s ease, text-decoration-color .15s ease;
}
a:hover { color: var(--red-ink); text-decoration-color: currentColor; }

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

h1, h2, h3 { text-wrap: balance; }

.wrap {
  max-width: var(--page);
  margin-inline: auto;
  padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
  padding-right: max(var(--gutter), env(safe-area-inset-right, 0px));
}

/* Masthead */
.masthead {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  background: var(--mast);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.masthead__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .3rem 1.5rem;
  padding-block: .62rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  margin-right: auto;
  color: var(--ink);
  font-weight: 600;
  font-size: .95rem;
  text-decoration: none;
}
.brand:hover { color: var(--ink); }
.brand__mark { flex: none; display: block; }
.brand__mark rect { fill: var(--ledger); }
.brand__mark text {
  fill: var(--paper);
  font-family: var(--serif);
  font-style: italic;
  font-size: 46px;
}
.nav {
  display: flex;
  align-items: center;
  gap: clamp(.9rem, 2.4vw, 1.7rem);
}
.nav a {
  padding-block: .28rem;
  color: var(--ink);
  font-size: .93rem;
  text-decoration: none;
  border-bottom: 2px solid transparent;
}
.nav a:hover { color: var(--red-ink); }
.nav a[aria-current="page"] {
  font-weight: 600;
  border-bottom-color: var(--ink);
}
.tools { display: flex; align-items: center; gap: .3rem; }
.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  min-height: 2rem;
  padding: 0 .4rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
}
.tool:hover { background: var(--paper-soft); color: var(--red-ink); }
.tool svg { width: 1.05rem; height: 1.05rem; display: block; }

/* Landing hero */
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(240px, 30vw, 380px);
  gap: clamp(2.5rem, 5vw, 4rem);
  align-items: start;
  padding-block: clamp(2rem, 5vw, 3.2rem) 1.2rem;
}
.hero__copy { min-width: 0; }
.eyebrow {
  margin: 0 0 .85rem;
  color: var(--red-ink);
  font-size: .72rem;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
}
/* The dot belongs to the second name and sits left of it. If the second name wraps
   to a new line (narrow window, or wider fallback fonts), overflow clips the dot. */
.hero__name {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: .62em;
  margin: 0;
  padding-bottom: .12em;
  overflow: hidden;
  font-family: var(--serif);
  font-size: clamp(2.45rem, 4.9vw, 3.3rem);
  font-weight: 500;
  line-height: 1.08;
  letter-spacing: -.005em;
}
.hero__name .second { position: relative; }
.hero__name .second::before {
  content: "·";
  position: absolute;
  left: -.42em;
  color: var(--brass);
  font-weight: 400;
}
.hero__name .cjk {
  font-family: var(--serif-cjk);
  letter-spacing: .02em;
}
.hero__role {
  margin: 1.2rem 0 .7rem;
  color: var(--ledger);
  font-size: .98rem;
  font-weight: 600;
}
.pills {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.pills li {
  padding: .22rem .78rem;
  border: 1px solid var(--ledger);
  border-radius: 999px;
  color: var(--ledger);
  font-size: .78rem;
  font-weight: 500;
  line-height: 1.4;
}
.hero__bio { max-width: 38rem; margin-top: 2.1rem; }
.hero__bio p {
  margin: 0 0 .9rem;
  color: var(--ink-soft);
  font-size: 1.02rem;
  line-height: 1.78;
}
.hero__bio p:last-child { margin-bottom: 0; }
.hero__bio .job-market { color: var(--ink); }
.hero__bio strong { color: var(--ink); font-weight: 600; }
.hero__bio a strong { color: inherit; }
.hero__links {
  margin: 1rem 0 0;
  color: var(--ink-soft);
  font-size: .88rem;
  line-height: 1.5;
  text-align: right;
}
.hero__links a { font-weight: 500; }
.hero__photo { position: sticky; top: 5.5rem; }
/* The English bio runs longer than the Chinese one, so the photo sits lower to balance it. */
@media (min-width: 861px) {
  html:not([data-lang="zh"]) .hero__photo { margin-top: 4.5rem; }
}
.hero__photo img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 22px;
  box-shadow: 0 26px 50px -26px var(--photo-shadow);
}

/* Section headings */
.section-head {
  margin: 0 0 1rem;
  color: var(--ledger);
  font-size: .8rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.section-head::after {
  content: "";
  display: block;
  width: 34px;
  height: 2px;
  margin-top: .55rem;
  background: var(--red-ink);
}

/* Landing-page lists */
.home-section { padding-block: 1.9rem .4rem; }
.home-section:last-child { padding-bottom: 3.6rem; }
.entry {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  padding-block: .95rem;
  border-bottom: 1px solid var(--rule);
}
.entry__main { min-width: 0; }
.entry__title {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.16rem;
  font-weight: 600;
  line-height: 1.32;
}
.entry__title a {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.entry__title a:hover { color: var(--ledger); border-bottom-color: var(--ledger); }
.entry__meta {
  margin: .22rem 0 0;
  color: var(--ink-mid);
  font-size: .82rem;
  line-height: 1.5;
}
.entry__meta strong { color: var(--ink); font-weight: 600; }
.entry__date {
  flex: none;
  margin: 0;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: .98rem;
  font-style: italic;
  font-variant-numeric: tabular-nums;
}
.more { margin: 1.2rem 0 0; font-size: .85rem; font-weight: 500; }

/* Inner pages */
.layout {
  display: grid;
  grid-template-columns: 12.5rem minmax(0, 1fr);
  gap: clamp(2rem, 4.5vw, 3.6rem);
  padding-block: 2.4rem 4rem;
}
.sidebar {
  position: sticky;
  top: 5.4rem;
  align-self: start;
  display: grid;
  gap: .85rem;
}
.sidebar__photo {
  width: min(100%, 9rem);
  aspect-ratio: 1;
  padding: 4px;
  border: 1px solid var(--rule-strong);
  border-radius: 50%;
  object-fit: cover;
}
.sidebar__name { margin: 0; font-size: 1.02rem; font-weight: 600; line-height: 1.35; }
.sidebar__role {
  margin: .2rem 0 0;
  color: var(--ledger);
  font-size: .82rem;
  font-weight: 600;
  line-height: 1.4;
}
.sidebar .pills { gap: .35rem; }
.sidebar .pills li { padding: .16rem .6rem; font-size: .73rem; }
.contact {
  display: grid;
  gap: .4rem;
  margin: .2rem 0 0;
  padding: 0;
  color: var(--ink-mid);
  font-size: .78rem;
  line-height: 1.45;
  list-style: none;
}
.contact li { display: flex; gap: .5rem; min-width: 0; }
.contact svg { flex: none; width: .95em; height: .95em; margin-top: .25em; fill: currentColor; }
.contact a { min-width: 0; color: inherit; overflow-wrap: anywhere; }
.contact a:hover { color: var(--red-ink); }

.content { min-width: 0; max-width: 47rem; }
.page-title {
  margin: 0 0 1.6rem;
  font-size: 1.7rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -.01em;
}
.block { margin-top: 2.5rem; }
.page-title + .block { margin-top: 0; }

/* Research entries */
.paper {
  display: grid;
  gap: .42rem;
  padding-block: 1.35rem;
  border-bottom: 1px solid var(--rule);
}
.paper:first-of-type { padding-top: .35rem; }
.paper:last-child { border-bottom: 0; padding-bottom: 0; }
.paper > * { margin: 0; min-width: 0; }
.paper__title {
  font-family: var(--serif);
  font-size: 1.26rem;
  font-weight: 600;
  line-height: 1.3;
}
.paper__title a { color: var(--ink); text-decoration: none; border-bottom: 1px solid transparent; }
.paper__title a:hover { color: var(--ledger); border-bottom-color: var(--ledger); }
.paper__original {
  color: var(--ink-soft);
  font-family: var(--serif-cjk);
  font-size: .9rem;
  line-height: 1.5;
}
.paper__authors { color: var(--ink-mid); font-size: .88rem; line-height: 1.5; }
.paper__authors strong { color: var(--ink); font-weight: 600; }
.paper__status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem .7rem;
  margin-block: .12rem .2rem;
}
.badge {
  padding: .1rem .62rem;
  border: 1px solid var(--ledger);
  border-radius: 999px;
  color: var(--ledger);
  font-size: .74rem;
  font-weight: 500;
  line-height: 1.45;
}
.badge--plain { border-color: var(--rule-strong); color: var(--ink-mid); }
.badge--wip { border-color: var(--red-ink); color: var(--red-ink); }
.paper__year {
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: .95rem;
  font-style: italic;
}
.paper__summary { color: var(--ink-mid); font-size: .93rem; line-height: 1.68; }
.paper__cite { color: var(--ink-soft); font-size: .78rem; line-height: 1.6; }
.paper__links { font-size: .82rem; font-weight: 500; }

/* CV */
.cv-list {
  display: grid;
  gap: .78rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: .93rem;
  line-height: 1.58;
}
.cv-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: .05rem 1.5rem;
}
.cv-item__main { flex: 1 1 18rem; min-width: 0; }
.cv-item__main small { display: block; color: var(--ink-soft); font-size: .86rem; }
.cv-item__date {
  flex: none;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-style: italic;
  font-variant-numeric: tabular-nums;
}
.cv-text { margin: 0; font-size: .93rem; line-height: 1.6; }
.cv-num { margin: 0; padding-left: 1.3rem; display: grid; gap: .7rem; font-size: .9rem; line-height: 1.58; }
.cv-num strong { font-weight: 600; }

/* Database */
.lede { margin: 0 0 2rem; color: var(--ink-soft); font-size: 1rem; line-height: 1.75; }
.data-card {
  display: grid;
  gap: 1rem;
  padding: clamp(1.1rem, 3vw, 1.7rem);
  border: 1px solid var(--rule-strong);
  border-radius: 14px;
  background: var(--paper-soft);
}
.data-card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem 1rem;
}
.data-card__title {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.36rem;
  font-weight: 600;
  line-height: 1.3;
}
.data-card__desc { margin: 0; color: var(--ink-mid); font-size: .95rem; line-height: 1.68; }
.data-table {
  display: grid;
  grid-template-columns: minmax(7rem, 9.5rem) minmax(0, 1fr);
  gap: .6rem 1.2rem;
  margin: 0;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: .9rem;
  line-height: 1.55;
}
.data-table dt { color: var(--ink-soft); }
.data-table dd { margin: 0; min-width: 0; }

/* Five tiles in one row; on phones two per row, with the last one spanning the row. */
.data-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: .55rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
@media (max-width: 640px) {
  .data-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .data-stats li:last-child { grid-column: 1 / -1; }
}
.data-stats li {
  min-width: 0;
  padding: .65rem .7rem;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
}
.data-stats strong {
  display: block;
  color: var(--ledger);
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 600;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.data-stats span { display: block; margin-top: .2rem; color: var(--ink-soft); font-size: .78rem; line-height: 1.35; }

.section-text { margin: 0 0 1.2rem; color: var(--ink-mid); font-size: .95rem; line-height: 1.72; }

.data-figure { margin: 0; }
.data-figure img {
  width: 100%;
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
  background: #FFFFFF;
}
.data-figure figcaption { margin-top: .55rem; color: var(--ink-soft); font-size: .8rem; line-height: 1.5; }

/* Footer */
.footer {
  border-top: 1px solid var(--rule);
  background: var(--paper-soft);
  color: var(--ink-soft);
  font-size: .78rem;
}
.footer__inner { padding-block: 1.3rem; }
.footer p { margin: 0; }

/* Narrow screens */
@media (max-width: 860px) {
  .hero { grid-template-columns: minmax(0, 1fr); gap: 1.5rem; }
  .hero__photo { order: -1; position: static; max-width: 280px; }
  .hero__bio { margin-top: 1.6rem; }

  .layout { grid-template-columns: minmax(0, 1fr); gap: 1.7rem; padding-block: 1.4rem 3rem; }
  .sidebar {
    position: static;
    grid-template-columns: 5rem minmax(0, 1fr);
    align-items: center;
    column-gap: 1rem;
    padding-bottom: 1.2rem;
    border-bottom: 1px solid var(--rule);
  }
  .sidebar__photo { width: 5rem; }
  .sidebar .pills { display: none; }
  .contact {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: .3rem 1.1rem;
    margin: 0;
  }
  .content { max-width: none; }
}

@media (max-width: 640px) {
  .nav { order: 3; width: 100%; justify-content: space-between; }
  .entry { flex-wrap: wrap; gap: .1rem 1rem; }
  .entry__main { flex: 1 1 100%; }
}

@media (max-width: 560px) {
  .hero__name .second { flex-basis: 100%; margin-top: .08em; font-size: .78em; }
  .data-table { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .data-table dt { margin-top: .7rem; font-size: .82rem; }
  .data-table dt:first-child { margin-top: 0; }
}

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