/* ==========================================================================
   Hui Lu — personal academic site
   Single stylesheet shared by index.html and pub.html.
   Light/dark themes via CSS custom properties. Theme is chosen by the
   visitor's OS setting, and can be overridden with the toggle in the nav
   (stored in localStorage as "theme").
   ========================================================================== */

:root {
  /* Type */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Light palette */
  --bg: #fbfbfa;
  --bg-elev: #ffffff;
  --bg-sunken: #f2f2ef;
  --border: #e3e2dd;
  --border-strong: #cfcdc6;
  --text: #1d1d1b;
  --text-2: #4d4c48;
  --text-3: #7a7873;
  --accent: #0b5fb0;          /* deep blue */
  --accent-strong: #094c8c;
  --accent-soft: #e6f0fa;
  --accent-2: #d9641c;        /* warm orange, used sparingly */
  --accent-2-soft: #fbeee4;
  --shadow: 0 1px 2px rgba(20, 20, 20, .04), 0 6px 20px -8px rgba(20, 20, 20, .12);
  --radius: 14px;
  --radius-sm: 8px;

  /* Layout */
  --wrap: 1120px;
  --sidebar: 280px;
  --gutter: 20px;
  --nav-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111214;
    --bg-elev: #191a1d;
    --bg-sunken: #0c0d0f;
    --border: #2a2c31;
    --border-strong: #3a3d44;
    --text: #ecebe7;
    --text-2: #b8b6b0;
    --text-3: #85837d;
    --accent: #6fb0f0;
    --accent-strong: #93c4f5;
    --accent-soft: #16273a;
    --accent-2: #f19a5f;
    --accent-2-soft: #33211a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -10px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  --bg: #111214;
  --bg-elev: #191a1d;
  --bg-sunken: #0c0d0f;
  --border: #2a2c31;
  --border-strong: #3a3d44;
  --text: #ecebe7;
  --text-2: #b8b6b0;
  --text-3: #85837d;
  --accent: #6fb0f0;
  --accent-strong: #93c4f5;
  --accent-soft: #16273a;
  --accent-2: #f19a5f;
  --accent-2-soft: #33211a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -10px rgba(0, 0, 0, .6);
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--nav-h) + 16px); }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; text-underline-offset: 3px; }
a:hover { color: var(--accent-strong); text-decoration: underline; }
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px;
}
h1, h2, h3 { font-family: var(--font-serif); font-weight: 600; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
p { margin: 0 0 1em; }
ul { margin: 0; padding: 0; list-style: none; }
img { max-width: 100%; display: block; }
strong { font-weight: 600; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

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

/* --------------------------------------------------------------------------
   Top navigation
   -------------------------------------------------------------------------- */
.site-nav {
  position: sticky; top: 0; z-index: 50;
  height: var(--nav-h);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.site-nav .wrap { height: 100%; display: flex; align-items: center; gap: 16px; }
.brand { font-family: var(--font-serif); font-weight: 700; font-size: 1.15rem; color: var(--text); }
.brand:hover { text-decoration: none; color: var(--accent); }
.nav-links { display: flex; gap: 4px; margin-left: auto; }
.nav-links a {
  font-size: .9rem; font-weight: 500; color: var(--text-2);
  padding: 6px 10px; border-radius: 999px;
}
.nav-links a:hover, .nav-links a[aria-current="page"] { color: var(--text); background: var(--bg-sunken); text-decoration: none; }

.theme-toggle, .nav-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text-2);
  cursor: pointer; padding: 0;
}
.theme-toggle:hover, .nav-toggle:hover { color: var(--text); border-color: var(--border-strong); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: none; }
}
.nav-toggle { display: none; margin-left: auto; }
.nav-toggle svg { width: 20px; height: 20px; }

/* --------------------------------------------------------------------------
   Two-column layout: sticky profile sidebar + content
   -------------------------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  gap: 56px;
  padding: 44px 0 64px;
}
.sidebar { position: sticky; top: calc(var(--nav-h) + 28px); align-self: start; }

.profile-photo {
  width: 100%; height: auto; aspect-ratio: 1 / 1; object-fit: cover; object-position: center top;
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.profile-name { font-size: 1.85rem; margin-top: 20px; }
.profile-role { color: var(--text-2); margin: 6px 0 0; font-size: .95rem; line-height: 1.45; }
.profile-role a { color: inherit; }
.profile-role a:hover { color: var(--accent); }
.profile-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 0; }
.profile-tags li {
  font-size: .72rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft); padding: 4px 9px; border-radius: 999px;
}

.profile-links { display: grid; gap: 6px; margin-top: 20px; }
.profile-links a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text); font-size: .92rem; font-weight: 500;
  border: 1px solid transparent;
}
.profile-links a:hover { background: var(--bg-elev); border-color: var(--border); text-decoration: none; }
.profile-links svg { width: 18px; height: 18px; color: var(--text-3); flex: none; }
.profile-links a:hover svg { color: var(--accent); }
.profile-email { font-family: var(--font-mono); font-size: .84rem; }

.recruit-note {
  margin-top: 22px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--accent-2-soft); border-left: 3px solid var(--accent-2);
  font-size: .88rem; color: var(--text-2); line-height: 1.5;
}
.recruit-note strong { color: var(--text); }

/* --------------------------------------------------------------------------
   Content sections
   -------------------------------------------------------------------------- */
.content > section + section { margin-top: 64px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.section-head h2 { font-size: 1.65rem; }
.section-head .more { font-size: .9rem; font-weight: 500; white-space: nowrap; }
.section-head .more::after { content: " →"; }
.content h3 { font-family: var(--font-sans); font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); margin: 28px 0 12px; }
.content h3:first-of-type { margin-top: 0; }

.lede { font-size: 1.18rem; line-height: 1.5; font-family: var(--font-serif); font-weight: 500; color: var(--text); margin-bottom: 18px; }
.prose p { color: var(--text-2); max-width: 68ch; }
.prose a { font-weight: 500; }

/* Research theme cards */
.theme-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.theme-card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 20px 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
  transition: transform .15s ease, border-color .15s ease;
}
.theme-card:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.theme-card h3 { font-family: var(--font-serif); font-size: 1.12rem; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--text); margin: 0; }
.theme-card p { color: var(--text-2); font-size: .92rem; margin: 0; }
.theme-card ul { margin-top: auto; padding-top: 10px; border-top: 1px dashed var(--border); display: grid; gap: 5px; }
.theme-card li { font-size: .85rem; color: var(--text-2); display: flex; gap: 8px; align-items: baseline; }
.theme-card li a { color: var(--text); font-weight: 500; }
.theme-card li a:hover { color: var(--accent); }
.venue {
  flex: none; font-family: var(--font-mono); font-size: .68rem; font-weight: 600;
  color: var(--accent); background: var(--accent-soft); border: 1px solid transparent;
  padding: 1px 6px; border-radius: 5px; white-space: nowrap; letter-spacing: .02em;
}

/* Publication list (compact, used on index) */
.pub-list { display: grid; gap: 2px; }
.pub-list li {
  display: grid; grid-template-columns: 118px minmax(0, 1fr); gap: 14px; align-items: baseline;
  padding: 9px 10px; margin: 0 -10px; border-radius: var(--radius-sm);
}
.pub-list li:hover { background: var(--bg-elev); }
.pub-list .venue { font-size: .72rem; justify-self: start; }
.pub-list .title { color: var(--text); font-weight: 500; line-height: 1.4; }
.pub-list .title:hover { color: var(--accent); }
.pub-list .soon { font-size: .74rem; color: var(--text-3); font-weight: 500; margin-left: 6px; white-space: nowrap; }

/* Funding cards */
.grant-list { display: grid; gap: 10px; }
.grant {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 18px; align-items: start;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px;
}
.grant .title { font-weight: 500; color: var(--text); line-height: 1.4; }
.grant .title:hover { color: var(--accent); }
.grant .sponsor { grid-column: 1; font-size: .8rem; color: var(--text-3); }
.grant .years { grid-column: 2; grid-row: 1 / span 2; font-family: var(--font-mono); font-size: .8rem; color: var(--text-2); white-space: nowrap; padding-top: 2px; }
.grant.career { border-left: 3px solid var(--accent-2); }

/* Teaching */
.course-list { display: grid; gap: 10px; }
.course { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 14px; padding: 12px 0; border-top: 1px solid var(--border); }
.course:last-child { border-bottom: 1px solid var(--border); }
.course .code { font-family: var(--font-mono); font-size: .84rem; font-weight: 600; color: var(--accent); }
.course .name { font-weight: 500; }
.course .terms { font-size: .86rem; color: var(--text-3); margin-top: 2px; }

/* Students */
.people-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.person {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; display: flex; gap: 12px; align-items: center;
}
.person .avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--font-serif); font-weight: 600; font-size: .95rem;
  background: var(--accent-soft); color: var(--accent);
}
.person.alum .avatar { background: var(--bg-sunken); color: var(--text-2); }
.person .name { font-weight: 500; color: var(--text); line-height: 1.3; }
.person .meta { font-size: .8rem; color: var(--text-3); line-height: 1.35; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); padding: 24px 0 40px; font-size: .85rem; color: var(--text-3); }
.site-footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 20px; }
.site-footer a { color: var(--text-2); }

/* --------------------------------------------------------------------------
   Publications page
   -------------------------------------------------------------------------- */
.page-head { padding: 44px 0 20px; }
.page-head h1 { font-size: 2.2rem; }
.page-head p { color: var(--text-2); margin: 10px 0 0; max-width: 64ch; }
.pub-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 22px 0 8px; position: sticky; top: var(--nav-h); z-index: 5; background: var(--bg); padding: 10px 0; }
.pub-tools input {
  flex: 1 1 240px; max-width: 360px; font: inherit; font-size: .92rem; color: var(--text);
  padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg-elev);
}
.pub-tools input::placeholder { color: var(--text-3); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit; font-size: .82rem; font-weight: 500; cursor: pointer;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg-elev); color: var(--text-2);
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .chip[aria-pressed="true"] { color: #0c1219; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip[aria-pressed="true"] { color: #0c1219; } }
.pub-count { font-size: .84rem; color: var(--text-3); margin-left: auto; }

.year-group { margin-top: 30px; }
.year-group h2 { font-family: var(--font-sans); font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); padding-bottom: 8px; border-bottom: 1px solid var(--border); margin-bottom: 8px; position: sticky; top: calc(var(--nav-h) + 62px); background: var(--bg); }
.year-group[hidden] { display: none; }

.pub-full { display: grid; gap: 2px; }
.pub-full li {
  display: grid; grid-template-columns: 128px minmax(0, 1fr); gap: 4px 16px; align-items: baseline;
  padding: 12px 10px; margin: 0 -10px; border-radius: var(--radius-sm);
}
.pub-full li:hover { background: var(--bg-elev); }
.pub-full li[hidden] { display: none; }
.pub-full .venue { grid-row: 1; justify-self: start; font-size: .72rem; }
.pub-full .title { grid-column: 2; color: var(--text); font-weight: 500; line-height: 1.4; }
.pub-full .title:hover { color: var(--accent); }
.pub-full .authors { grid-column: 2; font-size: .9rem; color: var(--text-2); line-height: 1.45; }
.pub-full .authors b { font-weight: 600; color: var(--text); }
.pub-full .where { grid-column: 2; font-size: .84rem; color: var(--text-3); font-style: italic; }
.pub-full .note { grid-column: 2; font-size: .78rem; color: var(--text-3); margin-top: 2px; }
.pub-full .note .tag { font-style: normal; font-family: var(--font-mono); background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 5px; padding: 0 6px; margin-right: 6px; }
.pub-full .pdf { grid-column: 2; margin-top: 4px; }
.pub-full .pdf a { font-size: .8rem; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.pub-full .pdf svg { width: 13px; height: 13px; }
.empty { color: var(--text-3); padding: 30px 0; text-align: center; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 36px; padding-top: 28px; }
  .sidebar { position: static; display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 10px 24px; align-items: start; }
  .profile-photo { grid-row: 1 / span 4; width: 150px; }
  .profile-name { margin-top: 0; font-size: 1.7rem; }
  .profile-links { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .recruit-note { grid-column: 1 / -1; }
  .theme-grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .nav-links {
    display: none; position: absolute; top: var(--nav-h); left: 0; right: 0;
    flex-direction: column; gap: 2px; padding: 10px var(--gutter) 14px;
    background: var(--bg); border-bottom: 1px solid var(--border); box-shadow: var(--shadow);
  }
  .nav-links[data-open="true"] { display: flex; }
  .nav-links a { padding: 10px 12px; font-size: 1rem; }
  .nav-toggle { display: inline-flex; }
  .site-nav .theme-toggle { margin-left: 0; }
  .sidebar { grid-template-columns: 112px minmax(0, 1fr); gap: 8px 16px; }
  .profile-photo { grid-row: 1 / span 2; width: 112px; }
  .profile-name { font-size: 1.5rem; }
  .profile-role { font-size: .88rem; }
  .profile-tags, .profile-links, .recruit-note { grid-column: 1 / -1; }
  .profile-tags { margin-top: 6px; }
  .profile-links { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 10px; }
  .recruit-note { margin-top: 12px; }
  .pub-list li { grid-template-columns: 1fr; gap: 4px; }
  .pub-full li { grid-template-columns: 1fr; }
  .pub-full .title, .pub-full .authors, .pub-full .where, .pub-full .note, .pub-full .pdf { grid-column: 1; }
  .grant { grid-template-columns: 1fr; }
  .grant .years { grid-column: 1; grid-row: auto; }
  .course { grid-template-columns: 1fr; gap: 2px; }
  .section-head { flex-direction: column; align-items: flex-start; gap: 4px; }
  .content > section + section { margin-top: 48px; }
  .year-group h2 { position: static; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .theme-card { transition: none; }
}
