/* =============================================================================
   Peiyan Li — personal academic site
   Aesthetic: editorial / "research journal". Warm paper light theme + deep ink
   dark theme. Serif display (Fraunces) over sans body (Inter). Indigo accent.
   Two-column: fixed sidebar (identity) + scrolling content (the work).
   ============================================================================= */

/* ----------------------------------- Theme tokens ------------------------- */
:root {
  --paper:      #f6f3ec;   /* warm off-white background        */
  --paper-2:    #efeae0;   /* slightly deeper panels           */
  --card:       #fffdf8;   /* cards                            */
  --ink:        #20201d;   /* primary text                     */
  --ink-soft:   #56544d;   /* secondary text                   */
  --ink-faint:  #8d897e;   /* tertiary / meta                  */
  --line:       #ddd6c8;   /* hairlines / borders              */
  --accent:     #3a47d5;   /* indigo                           */
  --accent-2:   #c2410c;   /* warm rust (equal-contrib, awards)*/
  --accent-soft:#e7e9fb;
  --shadow:     0 1px 2px rgba(40,38,32,.04), 0 8px 30px rgba(40,38,32,.06);
  --shadow-lg:  0 12px 50px rgba(40,38,32,.14);

  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans:  "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono:  "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --sidebar-w: 332px;
  --maxw: 760px;
  --radius: 14px;
}

html[data-theme="dark"] {
  --paper:      #131312;
  --paper-2:    #1a1a18;
  --card:       #1c1c1a;
  --ink:        #eceae3;
  --ink-soft:   #b3b0a6;
  --ink-faint:  #7f7c72;
  --line:       #2e2e2a;
  --accent:     #8b95ff;
  --accent-2:   #f0915e;
  --accent-soft:#23253a;
  --shadow:     0 1px 2px rgba(0,0,0,.3), 0 10px 34px rgba(0,0,0,.35);
  --shadow-lg:  0 14px 56px rgba(0,0,0,.5);
}

/* ----------------------------------- Reset -------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html { scroll-behavior: smooth; scroll-padding-top: 32px; }

body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.65;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .4s ease, color .4s ease;
  overflow-x: hidden;
}

/* Subtle paper grain via layered gradients */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none; z-index: 0;
  background:
    radial-gradient(1200px 600px at 78% -8%, var(--accent-soft) 0%, transparent 55%),
    radial-gradient(900px 500px at -10% 110%, var(--accent-soft) 0%, transparent 50%);
  opacity: .5;
}

a { color: var(--accent); text-decoration: none; transition: color .2s; }
a:hover { color: var(--accent-2); }

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

/* ----------------------------------- Layout ------------------------------- */
.layout {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  max-width: 1180px;
  margin: 0 auto;
  min-height: 100vh;
}

/* ----------------------------------- Sidebar ------------------------------ */
.sidebar {
  position: sticky; top: 0;
  align-self: start;
  height: 100vh;
  padding: 46px 36px 30px 40px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
.sidebar-inner { display: flex; flex-direction: column; }

.avatar-wrap {
  width: 132px; height: 132px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  margin-bottom: 22px;
  position: relative;
  transition: transform .4s cubic-bezier(.2,.8,.2,1);
}
.avatar-wrap:hover { transform: translateY(-3px) rotate(-1.5deg); }
.avatar { width: 100%; height: 100%; object-fit: cover; }

.side-name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 2rem;
  line-height: 1.08;
  letter-spacing: -.01em;
}
.side-name-zh {
  font-family: var(--serif);
  color: var(--ink-soft);
  font-size: 1.05rem;
  margin-top: 2px;
}

.side-tagline {
  font-family: var(--mono);
  font-size: .82rem;
  margin: 14px 0 18px;
  color: var(--accent);
  display: flex; align-items: center;
  min-height: 1.2em;
}
.tag-prefix { color: var(--ink-faint); margin-right: 6px; }
.caret { animation: blink 1.1s step-end infinite; color: var(--accent); margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }

.side-meta {
  font-size: .86rem;
  color: var(--ink-soft);
  line-height: 1.45;
}
.side-affil { margin-top: 2px; }
.side-loc { color: var(--ink-faint); font-size: .8rem; margin-top: 2px; }

/* social / contact icon links */
.side-links {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin: 20px 0 24px;
}
.side-links a {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink-soft);
  font-size: .9rem;
  transition: all .2s ease;
}
.side-links a:hover {
  color: #fff; background: var(--accent);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.side-links a svg { width: 18px; height: 18px; fill: currentColor; }
.side-links .icon-email svg { fill: #ea4335; }
.side-links .icon-scholar svg { fill: #4285f4; }
.side-links .icon-github svg { fill: #333; }
.side-links .icon-twitter svg { fill: #1da1f2; }
.side-links .icon-linkedin svg { fill: #0a66c2; }
.side-links .icon-xhs svg { fill: #fe2c55; }
.side-links .icon-orcid svg { fill: #a6ce39; }
.side-links .icon-cv svg { fill: var(--ink-soft); }
html[data-theme="dark"] .side-links .icon-github svg { fill: #f0f6fc; }
html[data-theme="dark"] .side-links .icon-cv svg { fill: var(--ink-soft); }

/* in-page nav */
.side-nav { display: flex; flex-direction: column; gap: 1px; margin-top: 6px; }
.side-nav a {
  font-size: .82rem;
  color: var(--ink-faint);
  padding: 5px 0 5px 16px;
  border-left: 2px solid var(--line);
  transition: all .22s ease;
  letter-spacing: .02em;
}
.side-nav a:hover { color: var(--ink); border-left-color: var(--accent-2); }
.side-nav a.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

.side-footer {
  margin-top: 26px;
  font-size: .72rem;
  color: var(--ink-faint);
  font-family: var(--mono);
}

/* ----------------------------------- Content ------------------------------ */
.content {
  padding: 56px clamp(28px, 5vw, 76px) 80px;
  max-width: calc(var(--maxw) + 152px);
}

.section { margin-bottom: 64px; scroll-margin-top: 28px; }

.section-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.55rem;
  letter-spacing: -.01em;
  margin-bottom: 22px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: baseline; gap: 12px;
}
.sec-index {
  font-family: var(--mono);
  font-size: .7rem;
  color: var(--accent);
  font-weight: 500;
  letter-spacing: .05em;
}

/* Hero / about */
.section-hero { margin-bottom: 56px; }
.hero-greeting {
  font-family: var(--serif);
  font-size: clamp(1.9rem, 4vw, 2.9rem);
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: -.015em;
  margin-bottom: 22px;
}
.hero-greeting .accent { color: var(--accent); font-style: italic; }
.bio p {
  color: var(--ink-soft);
  font-size: 1.04rem;
  margin-bottom: 14px;
}
.bio strong { color: var(--ink); font-weight: 600; }

/* Contact call-out card */
.contact-card {
  display: flex; align-items: center; gap: 16px;
  margin-top: 24px;
  padding: 16px 20px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
  border-radius: var(--radius);
  background: linear-gradient(120deg,
    color-mix(in srgb, var(--accent) 9%, var(--card)),
    var(--card));
  box-shadow: var(--shadow);
  color: var(--ink);
  user-select: text;
}
.contact-icon-link {
  flex: none;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--accent);
  color: #fff; font-size: 1.3rem;
  transition: background .2s;
}
.contact-icon-link:hover { background: var(--accent-2); }
.contact-body { display: flex; flex-direction: column; line-height: 1.4; }
.contact-note { font-size: .95rem; color: var(--ink-soft); }
.contact-email {
  font-family: var(--mono);
  font-size: .92rem; font-weight: 500;
  color: var(--accent);
  margin-top: 2px;
}
.contact-card:hover .contact-email { color: var(--accent-2); }

.hero-org {
  margin-top: 24px;
  font-size: 1rem;
  color: var(--ink-soft);
}
.hero-org a {
  color: var(--accent);
  font-weight: 500;
}
.hero-org a:hover { color: var(--accent-2); }

.affil-strip {
  display: flex; flex-wrap: wrap; align-items: center; gap: 26px;
  margin-top: 26px; padding-top: 22px;
  border-top: 1px dashed var(--line);
}
.affil-strip img {
  height: 38px; width: auto;
  filter: grayscale(1); opacity: .55;
  transition: all .3s ease;
}
.affil-strip a:hover img { filter: grayscale(0); opacity: 1; }

/* News */
.news-list { list-style: none; }
.news-list li {
  display: grid;
  grid-template-columns: 64px 26px 1fr;
  gap: 8px;
  padding: 9px 0;
  font-size: .96rem;
  border-bottom: 1px dashed var(--line);
  align-items: baseline;
}
.news-list li:last-child { border-bottom: none; }
.news-date { font-family: var(--mono); font-size: .78rem; color: var(--ink-faint); }
.news-tag { font-size: 1rem; }
.news-body { color: var(--ink-soft); }
.news-body a { color: var(--accent); }
.news-body a:hover { color: var(--accent-2); }
.news-body a strong { color: inherit; }
.news-body strong { color: var(--ink); }

/* Publications */
.pub-filter { display: flex; gap: 8px; margin-bottom: 24px; }
.filter-btn {
  font-family: var(--mono);
  font-size: .76rem;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all .2s;
}
.filter-btn:hover { border-color: var(--accent); color: var(--accent); }
.filter-btn.is-active {
  background: var(--accent); color: #fff; border-color: var(--accent);
}

.pub-list { display: flex; flex-direction: column; gap: 26px; }

.pub {
  display: grid;
  grid-template-columns: 244px 1fr;
  gap: 26px;
  padding: 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .35s cubic-bezier(.2,.8,.2,1), box-shadow .35s, border-color .35s;
}
.pub:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
}

.pub-media {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: var(--paper-2);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}
.pub-media img, .pub-media video {
  width: 100%; height: auto; object-fit: contain;
  background: var(--paper-2);
  display: block;
}

.pub-body { display: flex; flex-direction: column; }
.pub-title {
  font-family: var(--serif);
  font-size: 1.18rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -.01em;
  margin-bottom: 7px;
}
.pub-title a { color: var(--ink); }
.pub-title a:hover { color: var(--accent); }

.pub-authors { font-size: .9rem; color: var(--ink-soft); margin-bottom: 4px; }
.pub-authors .me { color: var(--ink); font-weight: 700; }
.pub-authors .eq { color: var(--ink-soft); font-weight: 400; }
.pub-authors .co { color: var(--ink-soft); font-weight: 400; }

.pub-venue {
  font-size: .86rem; color: var(--ink-faint);
  font-style: italic;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-bottom: 10px;
}
.pub-venue .year { font-style: normal; font-family: var(--mono); font-size: .78rem; }

.pub-award {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: .72rem; font-weight: 600; font-style: normal;
  color: var(--accent-2);
  border: 1px solid color-mix(in srgb, var(--accent-2) 40%, transparent);
  padding: 1px 7px; border-radius: 20px;
  white-space: nowrap;
}

.pub-tldr {
  font-size: .9rem; color: var(--ink-soft);
  margin: 4px 0 12px; line-height: 1.55;
}

.pub-links { display: flex; flex-wrap: wrap; gap: 7px; margin-top: auto; }
.pub-links a {
  font-family: var(--mono);
  font-size: .74rem;
  padding: 4px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink-soft);
  display: inline-flex; align-items: center; gap: 5px;
  transition: all .18s ease;
}
.pub-links a:hover {
  background: var(--accent); color: #fff; border-color: var(--accent);
  transform: translateY(-1px);
}

/* Timeline (education / experience) */
.timeline { display: flex; flex-direction: column; }
.tl-item {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px dashed var(--line);
}
.tl-item:last-child { border-bottom: none; }
.tl-logo {
  width: 48px; height: 48px; border-radius: 10px;
  object-fit: contain; background: var(--card);
  border: 1px solid var(--line); padding: 6px;
}
.tl-period {
  font-family: var(--mono); font-size: .74rem;
  color: var(--ink-faint); margin-bottom: 2px;
}
.tl-degree { font-weight: 600; font-size: 1rem; color: var(--ink); }
.tl-org { font-size: .9rem; color: var(--ink-soft); }
.tl-note { font-size: .86rem; color: var(--ink-faint); margin-top: 2px; }

/* Simple lists (awards, talks, services) */
.simple-list { list-style: none; }
.simple-list li {
  display: flex; gap: 14px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--line);
  font-size: .96rem; color: var(--ink-soft);
}
.simple-list li:last-child { border-bottom: none; }
.simple-list .sl-year {
  font-family: var(--mono); font-size: .78rem;
  color: var(--accent); min-width: 52px; padding-top: 2px;
}
.simple-list .sl-text strong { color: var(--ink); }

.misc-text { color: var(--ink-soft); font-size: 1.02rem; }

/* Footer */
.footer {
  margin-top: 40px; padding-top: 24px;
  border-top: 1px solid var(--line);
  font-size: .82rem; color: var(--ink-faint);
}
.footer-credit { margin-top: 6px; font-family: var(--mono); font-size: .72rem; }

/* ----------------------------------- Controls ----------------------------- */
.theme-toggle {
  position: fixed; top: 20px; right: 22px; z-index: 50;
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 1.1rem; cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .3s, background .3s;
}
.theme-toggle:hover { transform: rotate(35deg) scale(1.08); }

.scroll-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  z-index: 60; transition: width .1s linear;
}

/* ----------------------------------- Reveal animation --------------------- */
.reveal {
  opacity: 0; transform: translateY(22px);
  transition: opacity .7s cubic-bezier(.2,.8,.2,1), transform .7s cubic-bezier(.2,.8,.2,1);
}
.reveal.is-visible { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; transition: none; }
  html { scroll-behavior: auto; }
  .caret { animation: none; }
}

/* ----------------------------------- Responsive --------------------------- */
@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto;
    border-right: none; border-bottom: 1px solid var(--line);
    padding: 40px 28px 30px;
    text-align: left;
  }
  .sidebar-inner { max-width: 640px; margin: 0 auto; }
  .side-nav { display: none; }
  .content { padding: 44px 28px 70px; max-width: 720px; margin: 0 auto; }
}

@media (max-width: 620px) {
  .pub { grid-template-columns: 1fr; gap: 16px; }
  .pub-media { aspect-ratio: 16 / 9; }
  .news-list li { grid-template-columns: 56px 22px 1fr; }
  .hero-greeting { font-size: 1.7rem; }
  .theme-toggle { top: 14px; right: 14px; }
}
