/* ============================================================
   Yao Zhang — academic site
   Palette carried over from the previous al-folio theme:
     light accent  #0000FF   dark accent  #2698BA
     dark surface  #1C1C1D   card (dark)  #212529
   ============================================================ */

:root {
  --bg:            #ffffff;
  --bg-subtle:     #fafafa;
  --card:          #ffffff;
  --text:          #14161a;
  --text-muted:    #5f6470;
  --accent:        #0000ff;
  --accent-ink:    #0000cc;
  --accent-soft:   rgba(0, 0, 255, 0.06);
  --accent-line:   rgba(0, 0, 255, 0.22);
  --border:        rgba(0, 0, 0, 0.10);
  --border-strong: rgba(0, 0, 0, 0.28);
  --footer-bg:     #1c1c1d;
  --footer-text:   #b8b8bd;
  --shadow:        0 1px 2px rgba(0,0,0,.04), 0 8px 24px -12px rgba(0,0,0,.12);
  --radius:        10px;
  --maxw:          1180px;

  /* ---- Typography ------------------------------------------------------
     Two knobs control every typeface on the site.
       --font-body     running text, headings, publication entries
       --font-ui       small caps labels, nav, buttons (kept sans for clarity)
     To change the whole site's look, edit --font-body only.
     ---------------------------------------------------------------------- */
  --font-body: -apple-system, BlinkMacSystemFont, "Helvetica Neue",
               Helvetica, Arial, sans-serif;
  --font-ui:   -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;

  /* legacy aliases so the rest of the sheet keeps working */
  --font-sans:  var(--font-body);
  --font-serif: var(--font-body);
}

html[data-theme="dark"] {
  --bg:            #1c1c1d;
  --bg-subtle:     #212225;
  --card:          #212529;
  --text:          #d7d8dc;
  --text-muted:    #9a9ca4;
  --accent:        #2698ba;
  --accent-ink:    #56b6d2;
  --accent-soft:   rgba(38, 152, 186, 0.13);
  --accent-line:   rgba(38, 152, 186, 0.35);
  --border:        #35363b;
  --border-strong: #4a4b52;
  --footer-bg:     #141415;
  --footer-text:   #8e9096;
  --shadow:        0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.6);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Always reserve the scrollbar's width. Without this, short pages (About)
     have no scrollbar and long ones (Research, Teaching) do, so the content
     column shifts sideways every time you switch page. */
  scrollbar-gutter: stable;
  overflow-y: scroll;            /* fallback for browsers without the above */
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: background-color .25s ease, color .25s ease;
}

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

a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: color .15s ease, background-color .15s ease;
}
a:hover { text-decoration: underline; color: var(--accent-ink); }

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

.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 28px; }

/* ---------- skip link ---------- */
.skip {
  position: absolute; left: -9999px; top: 0; z-index: 200;
  background: var(--accent); color: #fff; padding: 10px 16px;
  border-radius: 0 0 var(--radius) 0; font-size: .9rem;
}
.skip:focus { left: 0; }

/* ---------- nav ---------- */
.nav {
  position: sticky; top: 0; z-index: 100;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 20px; min-height: 62px;
}

.nav-right { display: flex; align-items: center; gap: 4px; }

.nav-links { display: flex; align-items: center; gap: 2px; }
.nav-links a {
  color: var(--text-muted);
  font-family: var(--font-ui); font-size: .93rem; font-weight: 500;
  padding: 7px 13px; border-radius: 7px;
  position: relative;
}
.nav-links a:hover { color: var(--accent); background: var(--accent-soft); text-decoration: none; }
.nav-links a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

.theme-toggle {
  margin-left: 8px;
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 8px;
  background: transparent; color: var(--text-muted);
  cursor: pointer; padding: 0;
  transition: color .15s ease, border-color .15s ease, background-color .15s ease;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.theme-toggle svg { width: 17px; height: 17px; }
html:not([data-theme="dark"]) .icon-sun { display: none; }
html[data-theme="dark"]      .icon-moon { display: none; }

/* ---------- page shell ---------- */
main { flex: 1 0 auto; padding: 44px 0 72px; }

.page-head { margin-bottom: 26px; }
.page-title {
  font-family: var(--font-serif);
  font-size: clamp(1.9rem, 1.4rem + 1.6vw, 2.5rem);
  font-weight: 600; letter-spacing: -0.02em; line-height: 1.15;
  margin: 0 0 10px;
}
.page-sub { color: var(--text-muted); font-size: 1rem; margin: 0; }

/* ---------- hero (about) ----------
   Photo floats at the top right and stays put (no sticky). The opening
   paragraph wraps beside it; everything from .below-figure onward clears
   the float and runs the full width of the column. */
.hero { display: block; }

.hero-figure {
  float: right;
  width: 320px;
  margin: 4px 0 22px 36px;
  position: static;          /* deliberately not sticky — the photo must not move */
}
.hero-figure img {
  width: 100%; height: auto;
  aspect-ratio: 4 / 5;
  object-fit: cover; object-position: 50% 20%;
  border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow);
}

.hero-name {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 1.4rem + 2vw, 2.75rem);
  font-weight: 600; letter-spacing: -0.025em; line-height: 1.1;
  margin: 0 0 8px;
}
.hero-role { color: var(--text-muted); font-size: 1.02rem; margin: 0 0 26px; }
.hero-role a { font-weight: 500; }

/* both intro paragraphs wrap beside the photo; the first heading clears it */
.prose h2:first-of-type { clear: right; }
.contact { clear: both; }

.prose p {
  margin: 0 0 20px;
  text-align: justify;
  -webkit-hyphens: auto; hyphens: auto;   /* avoids rivers of white space */
}
.prose > :last-child { margin-bottom: 0; }
.prose h2 {
  font-family: var(--font-serif);
  font-size: 1.28rem; font-weight: 600; letter-spacing: -0.01em;
  margin: 40px 0 14px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* highlighted call-out (PhD recruiting) */
.callout {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 18px 22px;
  margin: 0 0 26px;
  font-size: .97rem;
}
.callout p { margin: 0; }
.callout strong { font-weight: 600; }

/* link list used on the about page */
.linklist { list-style: none; margin: 0 0 4px; padding: 0; }
.linklist li {
  position: relative;
  padding: 9px 0 9px 22px;
  border-bottom: 1px solid var(--border);
  font-size: .96rem; line-height: 1.6;
}
.linklist li:last-child { border-bottom: none; }
.linklist li::before {
  content: ""; position: absolute; left: 3px; top: .92em;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent); opacity: .55;
}

/* ---------- contact strip ---------- */
.contact {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 34px; padding-top: 26px;
  border-top: 1px solid var(--border);
}
.contact a {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-ui); font-size: .88rem; font-weight: 500; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 14px;
}
.contact a:hover {
  text-decoration: none; color: var(--accent);
  border-color: var(--accent-line); background: var(--accent-soft);
}
.contact svg { width: 15px; height: 15px; flex: none; }

/* ---------- publications ---------- */
/* symbol key, inline at the end of the page intro (no box) */
.legend { display: inline-flex; flex-wrap: wrap; gap: 4px 14px; margin-left: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend svg { width: 1.02em; height: 1.02em; color: var(--accent); flex: none; }

.pub-section { margin-bottom: 30px; }
.pub-section:last-child { margin-bottom: 0; }
.section-title {
  display: flex; align-items: baseline; gap: 12px;
  margin-top: 0;
  font-family: var(--font-serif);
  font-size: 1.32rem; font-weight: 600; letter-spacing: -0.01em;
  margin: 0 0 6px;
}
.section-title .count {
  font-family: var(--font-ui);
  font-size: .72rem; font-weight: 600; letter-spacing: .06em;
  color: var(--text-muted); text-transform: uppercase;
}
.section-rule { height: 2px; background: var(--text); opacity: .85; margin-bottom: 4px; }

/* three rows per entry:
     1. Title
     2. Authors
     3. venue, year.  [icon links]  */
.pub {
  padding: 15px 0;
  border-bottom: 1px solid var(--border);
  font-size: .95rem;
}
.pub:last-child { border-bottom: none; }

.pub-title   { font-weight: 600; line-height: 1.5; margin: 0 0 1px; }
.pub-authors { color: var(--text-muted); line-height: 1.5; margin: 0 0 1px; }
.pub-meta    { color: var(--text-muted); line-height: 1.6; margin: 0;
               display: flex; align-items: center; flex-wrap: wrap; gap: 0 6px; }

.pub-venue   { font-style: italic; }
.pub-links   { display: inline-flex; align-items: center; gap: 1px; }

/* icon-only in the entries — the legend at the top of the page names them.
   flex centring keeps the glyphs on the same optical line as the venue text. */
.pub-links a {
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  width: 1.5em; height: 1.5em;
  border-radius: 4px;
}
.pub-links a:hover {
  text-decoration: none; color: var(--accent); background: var(--accent-soft);
}
.pub-links svg { width: 1.02em; height: 1.02em; flex: none; }

.equal-note { font-size: .85rem; color: var(--text-muted); margin-top: 4px; }

/* ---------- teaching ---------- */
/* Column flow rather than a strict grid: cards have very different
   lengths, and columns pack them without leaving a tall empty cell. */
.course-grid { columns: 2; column-gap: 26px; }
.course {
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  margin: 0 0 26px;
  background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px 24px; box-shadow: var(--shadow);
  transition: border-color .18s ease, transform .18s ease;
}
.course:hover { border-color: var(--accent-line); transform: translateY(-2px); }
.course-inst {
  font-family: var(--font-ui); font-size: .68rem; font-weight: 600; letter-spacing: .09em;
  text-transform: uppercase; color: var(--accent); margin: 0 0 8px;
}
.course h3 { font-size: 1.02rem; font-weight: 600; line-height: 1.35; margin: 0 0 16px; }
.course h3 a { color: var(--text); }
.course h3 a:hover { color: var(--accent); }
.course ol {
  margin: 0; padding-left: 20px;
  font-size: .875rem; line-height: 1.65; color: var(--text-muted);
}
.course ol li { margin-bottom: 3px; }
.course ol li::marker { color: var(--accent); font-variant-numeric: tabular-nums; }

/* ---------- footer ---------- */
.footer {
  flex: none;
  background: var(--footer-bg); color: var(--footer-text);
  font-family: var(--font-ui); padding: 30px 0; font-size: .85rem;
}
.footer-inner { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; }
.footer a { color: #fff; }
html[data-theme="dark"] .footer a { color: var(--accent-ink); }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .course-grid { columns: 1; }
  .hero-figure { float: none; width: 230px; margin: 0 0 24px; }
  .wrap { padding: 0 20px; }
  main { padding: 40px 0 64px; }
}

@media (max-width: 620px) {
  /* justified text in a narrow column opens ugly word gaps */
  .prose p { text-align: left; }
  .nav-links a { padding: 7px 9px; font-size: .88rem; }
  .footer-inner { flex-direction: column; align-items: flex-start; }
}

@media print {
  .nav, .theme-toggle, .footer { display: none; }
  body { color: #000; background: #fff; }
  a { color: #000; }
}

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

/* ---------- BibTeX dialog ---------- */
#bibdlg {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--text);
  padding: 0; width: min(620px, calc(100vw - 40px)); box-shadow: var(--shadow);
}
#bibdlg::backdrop { background: rgba(0,0,0,.45); }
#bibdlg .bd-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
#bibdlg .bd-title {
  font-family: var(--font-ui); font-size: .72rem; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase; color: var(--text-muted);
  margin: 0; margin-right: auto;
}
#bibdlg button {
  font-family: var(--font-ui); font-size: .78rem; font-weight: 600;
  border: 1px solid var(--border); border-radius: 6px;
  background: transparent; color: var(--text-muted);
  padding: 5px 12px; cursor: pointer;
}
#bibdlg button:hover {
  color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft);
}
#bibdlg pre {
  margin: 0; padding: 18px; overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .82rem; line-height: 1.6; white-space: pre; color: var(--text);
}
