/* Homepage — self-contained stylesheet (no framework, no web fonts).
   Dark is the default for everyone, regardless of OS setting. The top-bar button
   switches to light by setting data-theme="light" on <html> (see head script in index.html). */

/* Default palette: dark. Also used when JavaScript is off. */
:root {
  color-scheme: dark;
  --bg: #111214;
  --surface: #18191c;
  --ink: #f4f4f5;
  --text: #c4c4cc;
  --muted: #8f8f99;
  --line: #2a2b30;
  --accent: #f0a37c;
  --accent-soft: #3a2418;
  --thumb-bg: #f4f4f5;
  --header-bg: rgb(17 18 20 / 0.75);

  --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Helvetica Neue", Arial, sans-serif;
  --measure: 72rem;
  --gutter: clamp(1rem, 4vw, 2rem);
  --radius: 12px;
  --topbar-h: 3.5rem;
}

/* Light palette: only when the visitor picks it with the toggle. */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fafaf9;
  --surface: #ffffff;
  --ink: #18181b;
  --text: #3f3f46;
  --muted: #71717a;
  --line: #e7e5e4;
  --accent: #b4542a;
  --accent-soft: #f6e7df;
  --thumb-bg: #ffffff;
  --header-bg: rgb(250 250 249 / 0.78);
}

/* ---------- Base ---------- */

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: clamp(1rem, 0.96rem + 0.2vw, 1.0625rem);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  margin: 0;
  color: var(--ink);
  line-height: 1.2;
  text-wrap: balance;
}

p {
  margin: 0;
  text-wrap: pretty;
}

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

a {
  color: inherit;
}

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

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 1em;
  height: 1em;
  flex: none;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 20;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  text-decoration: none;
}

.skip-link:focus {
  top: 0.75rem;
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--header-bg);
  border-bottom: 1px solid transparent;
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
}

@supports (animation-timeline: scroll()) {
  .topbar {
    animation: topbar-border linear both;
    animation-timeline: scroll();
    animation-range: 0 4rem;
  }

  @keyframes topbar-border {
    to { border-bottom-color: var(--line); }
  }
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: var(--measure);
  height: var(--topbar-h);
  margin: 0 auto;
  padding-inline: var(--gutter);
}

.topbar-name {
  color: var(--ink);
  font-weight: 650;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.theme-toggle .icon {
  width: 1rem;
  height: 1rem;
}

/* Show the moon in light mode (click for dark) and the sun in dark mode.
   Without JavaScript there is no data-theme, so the button is hidden. */
:root:not([data-theme]) .theme-toggle,
:root[data-theme="dark"] .icon-moon,
:root[data-theme="light"] .icon-sun {
  display: none;
}

.topbar nav {
  display: flex;
  gap: 1.5rem;
  font-size: 0.9375rem;
}

.topbar nav a {
  color: var(--muted);
  text-decoration: none;
  transition: color 150ms ease;
}

.topbar nav a:hover {
  color: var(--ink);
}

/* ---------- Layout ---------- */

.page {
  max-width: var(--measure);
  margin: 0 auto;
  padding-inline: var(--gutter);
}

.section {
  padding-block: 3rem;
  border-top: 1px solid var(--line);
}

.section h2 {
  margin-bottom: 1.25rem;
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 1.25rem;
}

.section-head h2 {
  margin-bottom: 0;
}

.pubs-stats {
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.pubs-stats a {
  color: var(--text);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}

.pubs-stats strong {
  color: var(--ink);
  font-weight: 600;
}

.pubs-stats a:hover,
.pubs-stats a:hover strong {
  color: var(--accent);
}

.section-aside {
  color: var(--muted);
  font-size: 0.9375rem;
  text-decoration: none;
}

.section-aside:hover {
  color: var(--accent);
}

/* ---------- Hero ---------- */

.hero {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  align-items: center;
  gap: 1.5rem 2rem;
  max-width: var(--measure);
  margin-inline: auto;
  padding-block: 3rem 2.5rem;
}

.avatar {
  width: 168px;
  height: 168px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 0 1px var(--line), 0 8px 24px -12px rgb(0 0 0 / 0.35);
}

.hero h1 {
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.035em;
}

.name-chinese {
  padding-bottom: 0.38rem;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.2rem);
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.hero-name-row {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
}

.role {
  margin-top: 0.5rem;
  color: var(--ink);
  font-size: 1.1875rem;
  font-weight: 500;
}

.affiliation {
  color: var(--muted);
  font-size: 1.0625rem;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1.25rem;
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 0.9375rem;
}

.hero-meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.hero-meta .icon {
  color: var(--accent);
}

.profile-links {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.profile-link {
  display: grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease,
    transform 150ms ease;
}

.profile-link .icon {
  width: 1.05rem;
  height: 1.05rem;
}

.profile-link:hover {
  transform: translateY(-2px);
  border-color: var(--line);
  background: var(--surface);
  color: var(--accent);
}

.profile-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- About ---------- */

.prose p + p {
  margin-top: 1rem;
}

.prose > p {
  max-width: 72ch;
}

.prose a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  transition: color 150ms ease, text-decoration-color 150ms ease;
}

.prose a:hover {
  color: var(--accent);
  text-decoration-color: currentColor;
}

/* ---------- Work ---------- */

.section-intro {
  margin-bottom: 1.5rem;
}

.work-card {
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1.35rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.work-card h3 {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.work-card-heading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.work-card-heading h3 {
  min-width: 0;
}

.work-card p {
  font-size: 0.9375rem;
  line-height: 1.6;
}

.work-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
}

.work-icon svg {
  width: 1.15rem;
  height: 1.15rem;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.85rem 0 0;
  padding: 0;
  list-style: none;
}

.pills li {
  padding: 0.15rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink);
  font-size: 0.8125rem;
  font-weight: 500;
}

.work-card .pills {
  margin-top: auto;
  padding-top: 0.85rem;
}


.pills-compact li {
  padding: 0.1rem 0.5rem;
  color: var(--muted);
  font-size: 0.6875rem;
  line-height: 1.45;
}

.work-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

/* ---------- Highlights ---------- */

.highlights {
  margin: 0;
  padding: 0;
  list-style: none;
}

.highlights li {
  display: grid;
  grid-template-columns: 4rem minmax(0, 1fr);
  gap: 1rem;
  padding-block: 0.55rem;
}

.highlights li + li {
  border-top: 1px solid var(--line);
}

.hl-year {
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.highlights p {
  font-size: 0.9875rem;
  line-height: 1.55;
}

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

.highlights a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
  text-underline-offset: 3px;
}

.highlights a:hover {
  color: var(--accent);
}

/* ---------- Publications ---------- */

/* Selected / All switch (pure CSS via :has; older browsers simply show everything) */
.pub-filter {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.pub-filter input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.pub-filter label {
  padding: 0.2rem 0.85rem;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.pub-filter label:hover {
  color: var(--ink);
}

.pub-filter input:checked + label {
  background: var(--ink);
  color: var(--bg);
}

.pub-filter input:focus-visible + label {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#publications:has(#pf-selected:checked) .pub:not(.is-selected):not(:target),
#publications:has(#pf-selected:checked) .year-group:not(:has(.is-selected, :target)),
#publications:has(#pf-selected:checked) .pub-flag,
#publications:has(#pf-all:checked) .pubs-show-all {
  display: none;
}

.pubs-more {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-top: 1.75rem;
}

.pubs-show-all {
  color: var(--accent);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
}

.pubs-show-all:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.pubs-more .section-aside {
  margin-left: auto;
}

.year-group {
  display: grid;
  grid-template-columns: 4rem minmax(0, 1fr);
  gap: 1rem;
}

.year-group + .year-group {
  margin-top: 1.5rem;
}

.year {
  position: sticky;
  top: calc(var(--topbar-h) + 1rem);
  align-self: start;
  padding-top: 1rem;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.pubs {
  margin: 0;
  padding: 0;
  list-style: none;
}

.pub {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  gap: 1.25rem;
  margin-inline: -0.75rem;
  padding: 1rem 0.75rem;
  border-radius: var(--radius);
  transition: background-color 150ms ease;
}

.pub:hover {
  background: var(--surface);
}

.pub:target {
  background: var(--accent-soft);
}

.pub-thumb {
  width: 100%;
  aspect-ratio: 16 / 10;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--thumb-bg);
  object-fit: contain;
}

.pub-flag {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 0.25rem;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.pub-flag .icon {
  width: 0.85rem;
  height: 0.85rem;
}

.pub-award {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.5rem;
  padding: 0.1rem 0.65rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 0.8125rem;
  font-weight: 550;
}

.pub-award .icon {
  color: var(--accent);
}

.pub-title {
  color: var(--ink);
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.005em;
}

.pub-authors {
  margin-top: 0.3rem;
  font-size: 0.9375rem;
  line-height: 1.55;
}

.me {
  color: var(--ink);
  font-weight: 600;
}

.pub-venue {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

.tag {
  display: inline-block;
  margin-right: 0.4rem;
  padding: 0.05rem 0.45rem;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.pub-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.6rem 0 0;
  padding: 0;
  list-style: none;
}

.pub-links a {
  display: inline-block;
  padding: 0.1rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
  transition: border-color 150ms ease, color 150ms ease;
}

.pub-links a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Footer ---------- */

.footer {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 2rem var(--gutter) 3rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8125rem;
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  body {
    font-size: 1rem;
  }

  .topbar nav {
    gap: clamp(0.45rem, 2.2vw, 0.85rem);
    font-size: clamp(0.78rem, 3.3vw, 0.9rem);
  }

  .topbar-actions {
    gap: 0.75rem;
  }

  .hero {
    grid-template-columns: 1fr;
    gap: 1rem;
    padding-block: 2.5rem 2rem;
  }

  .avatar {
    width: 96px;
    height: 96px;
  }

  .section {
    padding-block: 2.25rem;
  }

  .work-grid {
    grid-template-columns: 1fr;
  }

  .highlights li {
    grid-template-columns: 3rem minmax(0, 1fr);
    gap: 0.75rem;
  }

  .year-group {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .year {
    position: static;
    padding-top: 0;
  }

  .pub {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .pub-thumb {
    aspect-ratio: auto;
  }
}

@media (max-width: 400px) {
  .topbar-inner {
    gap: 0.5rem;
  }

  .topbar nav {
    gap: clamp(0.35rem, 1.8vw, 0.65rem);
    font-size: clamp(0.75rem, 3.1vw, 0.82rem);
  }

  .topbar-actions {
    gap: 0.5rem;
  }

  .theme-toggle {
    width: 1.85rem;
    height: 1.85rem;
  }
}

@media (min-width: 641px) and (max-width: 900px) {
  .hero {
    grid-template-columns: clamp(120px, 22vw, 168px) minmax(0, 1fr);
    max-width: none;
  }

  .avatar {
    width: clamp(120px, 22vw, 168px);
    height: clamp(120px, 22vw, 168px);
  }

  .work-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

@media print {
  .topbar,
  .skip-link,
  .profile-links {
    display: none;
  }

  .pub {
    break-inside: avoid;
  }

  #publications .year-group,
  #publications .pub {
    display: grid !important;
  }

  .pub-filter,
  .pubs-more {
    display: none !important;
  }
}
