/* ==========================================================================
   Qinxin Yan — personal academic site
   Plain HTML + CSS. No build step.
   ========================================================================== */

:root {
  --bg: #fbfbf9;
  --surface: #ffffff;
  --text: #1a1e26;
  --muted: #555e6c;
  --faint: #8a929e;
  --line: #e5e3dd;
  --line-strong: #d3d0c8;
  --accent: #1f4e8c;
  --accent-hover: #163b6c;
  --accent-soft: #eef3fa;
  --ok: #2f6b3f;
  --ok-soft: #eaf4ec;
  --warn: #7a5412;
  --warn-soft: #faf2e3;

  --serif: "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;

  --wrap: 1040px;
  --prose: 700px;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #171a21;
    --text: #e5e7eb;
    --muted: #a3abb8;
    --faint: #7c8594;
    --line: #262b35;
    --line-strong: #353b47;
    --accent: #8fb5ea;
    --accent-hover: #b3cdf2;
    --accent-soft: rgba(143, 181, 234, 0.1);
    --ok: #8fcf9e;
    --ok-soft: rgba(143, 207, 158, 0.1);
    --warn: #e3bd78;
    --warn-soft: rgba(227, 189, 120, 0.1);
  }
}

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

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 5rem;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.65;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  transition: color 0.15s, text-decoration-color 0.15s;
}
a:hover { color: var(--accent-hover); text-decoration-color: currentColor; }

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

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin: 0;
}

p { margin: 0 0 1em; }

strong { font-weight: 600; }

.skip-link {
  position: absolute; left: -999px; top: 0.5rem;
  background: var(--surface); padding: 0.5rem 1rem; z-index: 100;
  font-family: var(--sans); font-size: 0.9rem;
}
.skip-link:focus { left: 1rem; }

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

/* ---------- Header / nav ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}

.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  min-height: 4rem;
}

.brand {
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: -0.01em;
}
.brand:hover { color: var(--text); }

.site-nav ul {
  display: flex;
  gap: 0.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-nav a {
  display: block;
  padding: 0.4rem 0.7rem;
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border-radius: 6px;
  white-space: nowrap;
}
.site-nav a:hover { color: var(--text); background: var(--accent-soft); }
.site-nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

/* ---------- Page scaffolding ---------- */

main { padding: 3.5rem 0 4.5rem; }

.page-head {
  max-width: var(--prose);
  margin-bottom: 2.75rem;
}
.page-head h1 {
  font-size: clamp(2rem, 4vw, 2.6rem);
  margin-bottom: 0.6rem;
}
.page-head .lede {
  color: var(--muted);
  font-size: 1.15rem;
  margin: 0;
}

.eyebrow {
  display: block;
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 0.9rem;
}

.section { margin-top: 3.5rem; }
.section:first-child { margin-top: 0; }

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.65rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--line);
}
.section-title h2 { font-size: 1.45rem; }
.section-title .more {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.prose { max-width: var(--prose); }
.prose ul { padding-left: 1.2rem; }
.prose li { margin-bottom: 0.4rem; }

.sans { font-family: var(--sans); }
.muted { color: var(--muted); }

/* ---------- Home hero ---------- */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 4rem;
  align-items: start;
}

.hero h1 {
  font-size: clamp(2.5rem, 5.5vw, 3.4rem);
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}

.hero .role {
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--muted);
  margin-bottom: 1.8rem;
  line-height: 1.5;
}
.hero .role strong { color: var(--text); font-weight: 600; }

.hero .bio p { margin-bottom: 1.05em; }

.profile-card {
  position: sticky;
  top: 5.5rem;
}

.profile-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  object-position: 50% 40%;
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(15, 25, 40, 0.08);
}

.contact {
  list-style: none;
  margin: 1.4rem 0 0;
  padding: 0;
  font-family: var(--sans);
  font-size: 0.875rem;
}
.contact li {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}
.contact li:last-child { border-bottom: 0; }
.contact svg { flex: none; width: 16px; height: 16px; color: var(--faint); }
.contact a { color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.contact a:hover { color: var(--accent); }

.btn-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1.9rem; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.6rem 1.05rem;
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--bg); }
.btn svg { width: 15px; height: 15px; }

/* ---------- Interest list ---------- */

.interests {
  list-style: none;
  padding: 0;
  margin: 0;
  max-width: 820px;
  counter-reset: interest;
}
.interests li {
  counter-increment: interest;
  display: grid;
  grid-template-columns: 2.2rem minmax(0, 1fr);
  padding: 0.55rem 0;
  line-height: 1.55;
}
.interests li::before {
  content: counter(interest, decimal-leading-zero);
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--accent);
  padding-top: 0.3rem;
}

/* ---------- Timeline (appointments, talks, teaching) ---------- */

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

.timeline > li {
  display: grid;
  grid-template-columns: 9.5rem minmax(0, 1fr);
  gap: 1.5rem;
  padding: 1.05rem 0;
  border-bottom: 1px solid var(--line);
}
.timeline > li:first-child { padding-top: 0.2rem; }
.timeline > li:last-child { border-bottom: 0; }

.timeline .when {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--faint);
  padding-top: 0.2rem;
  font-variant-numeric: tabular-nums;
}
.timeline .what { font-weight: 600; line-height: 1.4; }
.timeline .where { color: var(--muted); font-size: 1rem; line-height: 1.5; margin-top: 0.15rem; }
.timeline .note { color: var(--faint); font-family: var(--sans); font-size: 0.82rem; margin-top: 0.3rem; }
.timeline em { font-style: italic; }

.year-label {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--faint);
  margin: 2.2rem 0 0.4rem;
}
.year-label:first-child { margin-top: 0; }

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

.pubs {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: pub var(--start, 0);
}

.pub {
  counter-increment: pub;
  position: relative;
  padding: 1.25rem 0 1.25rem 3rem;
  border-bottom: 1px solid var(--line);
}
.pub:first-child { padding-top: 0.25rem; }
.pub:last-child { border-bottom: 0; }

.pub::before {
  content: "[" counter(pub) "]";
  position: absolute;
  left: 0;
  top: 1.45rem;
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.pub:first-child::before { top: 0.45rem; }

.pub-title {
  font-size: 1.12rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 0.3rem;
}
.pub-title a { color: var(--text); text-decoration: none; }
.pub-title a:hover { color: var(--accent); }

.pub-authors { color: var(--muted); font-size: 1rem; margin: 0 0 0.1rem; }
.pub-authors .me { color: var(--text); font-weight: 600; }

.pub-venue { font-size: 1rem; margin: 0; color: var(--muted); }
.pub-venue em { color: var(--text); }

.pub-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.7rem;
}

.chip, .badge, .pub-meta summary {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1;
  padding: 0.38rem 0.6rem;
  border-radius: 5px;
  white-space: nowrap;
}

.chip {
  color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
}
.chip:hover { color: var(--accent-hover); background: color-mix(in srgb, var(--accent) 16%, transparent); }
.chip svg { width: 12px; height: 12px; }

.badge { border: 1px solid var(--line-strong); color: var(--muted); }
.badge.published { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.badge.accepted { color: var(--warn); background: var(--warn-soft); border-color: transparent; }

.theme-tag {
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--faint);
  margin-left: 0.2rem;
}

.pub details { display: contents; }
.pub-meta summary {
  list-style: none;
  cursor: pointer;
  color: var(--muted);
  border: 1px solid var(--line-strong);
  user-select: none;
}
.pub-meta summary::-webkit-details-marker { display: none; }
.pub-meta summary::after { content: "+"; font-weight: 600; margin-left: 0.15rem; }
.pub-meta details[open] summary::after { content: "−"; }
.pub-meta summary:hover { color: var(--text); border-color: var(--muted); }
.pub-abstract {
  flex-basis: 100%;
  margin: 0.4rem 0 0;
  padding: 0.85rem 1rem;
  font-size: 0.98rem;
  line-height: 1.6;
  color: var(--muted);
  background: var(--surface);
  border-left: 3px solid var(--line-strong);
  border-radius: 0 6px 6px 0;
}

/* ---------- Research themes ---------- */

.themes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.themes li {
  padding: 1.2rem 1.25rem 1.3rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.themes .num {
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.themes h3 { font-size: 1.05rem; margin: 0.45rem 0 0.5rem; line-height: 1.35; }
.themes p { font-size: 0.95rem; line-height: 1.55; color: var(--muted); margin: 0; }

/* ---------- Cards (code, notes) ---------- */

.cards { display: grid; gap: 1.1rem; }

.card {
  display: block;
  padding: 1.5rem 1.6rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
a.card:hover {
  color: inherit;
  border-color: var(--line-strong);
  box-shadow: 0 6px 22px rgba(15, 25, 40, 0.07);
  transform: translateY(-1px);
}
.card h3 { font-size: 1.2rem; margin-bottom: 0.45rem; }
.card p { color: var(--muted); font-size: 1rem; margin-bottom: 0.8rem; }
.card p:last-child { margin-bottom: 0; }

.repo {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  color: var(--accent);
}
.repo svg { width: 15px; height: 15px; }

.note-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 2rem;
  align-items: center;
}
.note-card .thumb {
  aspect-ratio: 16 / 10;
  border-radius: 7px;
  background: #fff;
  border: 1px solid var(--line);
  overflow: hidden;
}
.note-card .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: left center; }
.note-card .meta { font-family: var(--sans); font-size: 0.8rem; color: var(--faint); margin-bottom: 0.5rem; }
.note-card .read { font-family: var(--sans); font-size: 0.85rem; font-weight: 500; color: var(--accent); }

/* ---------- CV ---------- */

.cv-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 1.5rem;
  max-width: none;
}
.cv-contact { font-family: var(--sans); font-size: 0.9rem; color: var(--muted); margin: 0; line-height: 1.7; }
.cv-contact a { color: var(--muted); }

.cv-section { margin-top: 2.75rem; }
.cv-section > h2 {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  padding-bottom: 0.6rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}
.cv-section h3 {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin: 1.4rem 0 0.6rem;
}
.cv-section .timeline > li { padding: 0.7rem 0; border-bottom: 0; }
.cv-section .pub { padding-top: 0.7rem; padding-bottom: 0.7rem; border-bottom: 0; }
.cv-section .pub::before { top: 0.95rem; }
.cv-section .pub:first-child::before { top: 0.45rem; }
.cv-section .pub-title { font-size: 1.02rem; margin-bottom: 0.1rem; }
.cv-list { margin: 0; padding-left: 1.2rem; }
.cv-list li { margin-bottom: 0.35rem; }

/* ---------- Article (essay) ---------- */

.article { max-width: var(--prose); margin: 0 auto; }

.article-head { margin-bottom: 2.5rem; }
.article-head h1 { font-size: clamp(2.1rem, 5vw, 2.9rem); letter-spacing: -0.02em; margin-bottom: 0.9rem; }
.article-head .meta { font-family: var(--sans); font-size: 0.875rem; color: var(--faint); }
.article-head .back {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  margin-bottom: 1.8rem;
}

.article .lead {
  font-size: 1.25rem;
  line-height: 1.6;
  color: var(--muted);
  padding-bottom: 2rem;
  margin-bottom: 2.5rem;
  border-bottom: 1px solid var(--line);
}

.article h2 { font-size: 1.6rem; margin: 3.2rem 0 1rem; }
.article h3 { font-size: 1.2rem; margin: 2.2rem 0 0.7rem; }
.article ol, .article ul { padding-left: 1.4rem; margin: 0 0 1.2em; }
.article li { margin-bottom: 0.45rem; }

.callout {
  margin: 2rem 0;
  padding: 1.2rem 1.4rem;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.callout strong {
  display: block;
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.4rem;
}
.callout p { margin: 0; }

.math-display {
  margin: 1.4rem 0;
  overflow-x: auto;
  overflow-y: hidden;
}
mjx-container[display="true"] { margin: 0 !important; padding: 0.2rem 0; }

.table-scroll { overflow-x: auto; margin: 1.8rem 0 0; -webkit-overflow-scrolling: touch; }
.article table {
  width: 100%;
  min-width: 34rem;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.article th, .article td { padding: 0.55rem 0.75rem; text-align: right; border-bottom: 1px solid var(--line); }
.article th { font-weight: 600; color: var(--muted); border-bottom: 1.5px solid var(--line-strong); vertical-align: bottom; }
.article tbody tr:hover { background: var(--accent-soft); }
.article tr.coexist td { color: var(--accent); font-weight: 600; }

.article figure { margin: 2.4rem 0; }
.article figure img {
  display: block;
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem;
}
.article figcaption, .table-note {
  margin-top: 0.75rem;
  font-family: var(--sans);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--faint);
}

.article-foot {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}
.article-foot h3 { font-family: var(--sans); font-size: 0.8rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); margin: 1.6rem 0 0.7rem; }
.article-foot h3:first-child { margin-top: 0; }
.article-foot ul { font-size: 1rem; }

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

.site-footer {
  border-top: 1px solid var(--line);
  padding: 1.8rem 0 2.4rem;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--faint);
}
.site-footer .wrap { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0.8rem; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }

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

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; gap: 2.2rem; }
  .profile-card { position: static; display: grid; grid-template-columns: 160px 1fr; gap: 1.5rem; align-items: center; order: -1; }
  .contact { margin-top: 0; }
  .note-card { grid-template-columns: 1fr; gap: 1.2rem; }
  .note-card .thumb { order: -1; }
}

@media (max-width: 720px) {
  body { font-size: 1.0625rem; }
  .site-header .wrap { flex-direction: column; align-items: stretch; gap: 0; padding-top: 0.75rem; }
  .brand { padding-bottom: 0.3rem; }
  .site-nav { padding-bottom: 0.55rem; }
  .site-nav ul { flex-wrap: wrap; gap: 0.1rem; margin-left: -0.55rem; }
  .site-nav a { padding: 0.35rem 0.55rem; }
  main { padding-top: 2.25rem; }
  .timeline > li { grid-template-columns: 1fr; gap: 0.2rem; }
  .pub { padding-left: 0; }
  .pub::before { position: static; display: block; margin-bottom: 0.25rem; }
}

@media (max-width: 480px) {
  .wrap { padding: 0 1.15rem; }
  .profile-card { grid-template-columns: 104px minmax(0, 1fr); gap: 1.1rem; }
  .contact { font-size: 0.8rem; }
  .contact li { padding: 0.32rem 0; gap: 0.5rem; }
  .contact svg { width: 14px; height: 14px; }
}

/* ---------- Print (CV → PDF) ---------- */

@media print {
  :root {
    --bg: #fff; --surface: #fff; --text: #000; --muted: #333; --faint: #555;
    --line: #ccc; --line-strong: #999; --accent: #1f4e8c; --accent-soft: transparent;
  }
  @page { margin: 1.6cm 1.8cm; }
  body { font-size: 10.5pt; line-height: 1.45; }
  .site-header, .site-footer, .no-print, .skip-link { display: none !important; }
  main { padding: 0; }
  a { color: inherit; text-decoration: none; }
  .cv-section { margin-top: 1.4rem; break-inside: auto; }
  .cv-section > h2 { break-after: avoid; }
  .timeline > li, .pub { break-inside: avoid; }
  .timeline > li { grid-template-columns: 7.5rem 1fr; gap: 1rem; }
  .page-head h1 { font-size: 22pt; }
  .pub-meta { display: none; }
}
