/* ==========================================================================
   Xingjian (Scott) Zhang — personal site
   ========================================================================== */

:root {
  --bg: #faf9f6;
  --surface: #ffffff;
  --ink: #16181d;
  --ink-2: #3b4049;
  --muted: #6b717c;
  --line: #e7e4dd;
  --line-strong: #d4d0c6;
  --accent: #1f4fd1;
  --accent-ink: #1a43b3;
  --accent-soft: #eaf0fd;
  --ok: #1f9d55;

  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1014;
    --surface: #151820;
    --ink: #eceae5;
    --ink-2: #c7cad1;
    --muted: #8f96a2;
    --line: #232833;
    --line-strong: #323846;
    --accent: #8ea8ff;
    --accent-ink: #a9bdff;
    --accent-soft: #1a2342;
    --ok: #4ade80;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1014;
  --surface: #151820;
  --ink: #eceae5;
  --ink-2: #c7cad1;
  --muted: #8f96a2;
  --line: #232833;
  --line-strong: #323846;
  --accent: #8ea8ff;
  --accent-ink: #a9bdff;
  --accent-soft: #1a2342;
  --ok: #4ade80;
  color-scheme: dark;
}

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

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 32px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent-ink); text-decoration: none; text-underline-offset: 3px; }
a:hover { text-decoration: underline; text-decoration-thickness: 1px; }

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

p { margin: 0 0 1em; }

h1, h2, h3, h4 { color: var(--ink); margin: 0; font-weight: 500; }

i, em { font-style: italic; }

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 16px; top: -48px; z-index: 10;
  background: var(--ink); color: var(--bg); padding: 8px 12px; border-radius: 8px;
}
.skip-link:focus { top: 16px; }

.dim { color: var(--muted); }

svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

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

.layout {
  max-width: 1120px;
  margin: 0 auto;
  padding: 80px 32px 56px;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  gap: 80px;
}

/* ---------- Sidebar ---------- */

.profile { position: sticky; top: 64px; align-self: start; }

.avatar {
  position: relative;
  width: 112px; height: 112px;
  border-radius: 50%;
  background: var(--accent-soft);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  overflow: hidden;
  margin-bottom: 24px;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.monogram { font-family: var(--serif); font-size: 40px; color: var(--accent-ink); letter-spacing: 0.02em; }

.name {
  font-family: var(--serif);
  font-size: 2.1rem;
  line-height: 1.1;
  letter-spacing: -0.015em;
}
.aka { margin: 6px 0 14px; font-family: var(--serif); font-style: italic; color: var(--muted); font-size: 1.05rem; }
.role { font-size: 0.93rem; line-height: 1.5; color: var(--ink-2); margin-bottom: 20px; }

.contact { list-style: none; padding: 0; margin: 0 0 32px; display: grid; gap: 8px; font-size: 0.9rem; }
.contact li { display: flex; align-items: center; gap: 10px; min-width: 0; }
.contact li svg { color: var(--muted); }
.contact a { color: var(--ink-2); overflow-wrap: anywhere; }
.contact a:hover { color: var(--accent-ink); }

.toc { display: grid; gap: 2px; margin-bottom: 28px; border-left: 1px solid var(--line); }
.toc a {
  font-family: var(--mono); font-size: 0.74rem; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); padding: 5px 0 5px 14px; margin-left: -1px; border-left: 1px solid transparent;
  transition: color .15s, border-color .15s;
}
.toc a:hover { color: var(--ink); text-decoration: none; }
.toc a.active { color: var(--accent-ink); border-left-color: var(--accent); }

.theme-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  font: 500 0.78rem var(--sans); color: var(--muted);
  background: transparent; border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; cursor: pointer; transition: color .15s, border-color .15s;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--line-strong); }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* ---------- Sections ---------- */

main { min-width: 0; }

section + section { margin-top: 80px; }

section > h2 {
  font-family: var(--serif);
  font-size: 1.6rem;
  letter-spacing: -0.01em;
  padding-bottom: 12px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--line);
}

.section-note { color: var(--muted); font-size: 0.95rem; margin-top: -12px; margin-bottom: 24px; max-width: 62ch; }

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

#about p { max-width: 66ch; }

.lede {
  font-family: var(--serif);
  font-size: 1.62rem;
  line-height: 1.32;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: 28px;
}

.status {
  display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
  margin: 8px 0 40px;
  padding: 10px 16px;
  font-size: 0.92rem; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.status a { font-weight: 500; }
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent);
  animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 50%, transparent); }
  70%, 100% { box-shadow: 0 0 0 8px transparent; }
}

.interests { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.interest {
  padding: 18px 18px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.interest h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 6px; line-height: 1.35; }
.interest p { font-size: 0.88rem; line-height: 1.55; color: var(--muted); margin: 0; }

/* ---------- News ---------- */

.news { list-style: none; margin: 0; padding: 0; }
.news li {
  display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 16px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}
.news li:last-child { border-bottom: 0; }
.news time { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); padding-top: 3px; white-space: nowrap; }
.news p { margin: 0; font-size: 0.96rem; }

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

.group-label {
  font-family: var(--mono); font-size: 0.74rem; font-weight: 500; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
  margin: 40px 0 8px;
}
.group-label:first-of-type { margin-top: 0; }

.pub {
  display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 24px;
  padding: 22px 0;
  border-bottom: 1px solid var(--line);
}
.pub:last-of-type { border-bottom: 0; }

.pub-side { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding-top: 4px; }
.venue {
  font-family: var(--mono); font-size: 0.7rem; font-weight: 500; letter-spacing: 0.02em;
  color: var(--accent-ink); background: var(--accent-soft);
  padding: 3px 8px; border-radius: 6px; white-space: nowrap;
}
.year { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); padding-left: 2px; }

.pub-title { font-family: var(--serif); font-size: 1.2rem; line-height: 1.35; letter-spacing: -0.005em; margin-bottom: 8px; }
.pub-title a { color: var(--ink); }
.pub-title a:hover { color: var(--accent-ink); }

.authors { font-size: 0.88rem; color: var(--muted); margin-bottom: 2px; }
.me { color: var(--ink); font-weight: 600; }
.more {
  font: 500 0.78rem var(--sans); color: var(--accent-ink);
  background: none; border: 0; padding: 0 0 0 6px; cursor: pointer;
}
.more:hover { text-decoration: underline; text-underline-offset: 3px; }

.where { font-size: 0.88rem; color: var(--ink-2); margin-bottom: 10px; }
.summary { font-size: 0.93rem; color: var(--ink-2); margin-bottom: 14px; max-width: 70ch; }

.pub-links { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.badge {
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.01em;
  color: var(--ink); padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line-strong);
}
.btn {
  font: 500 0.78rem var(--sans); color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line); border-radius: 7px;
  padding: 4px 11px; cursor: pointer; line-height: 1.4;
  transition: border-color .15s, color .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent-ink); text-decoration: none; }
.btn[aria-expanded="true"] { border-color: var(--accent); color: var(--accent-ink); }

.bib { position: relative; margin-top: 12px; }
.bib pre {
  margin: 0; padding: 14px 16px; overflow-x: auto;
  font-family: var(--mono); font-size: 0.74rem; line-height: 1.6; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
.copy {
  position: absolute; top: 8px; right: 8px;
  font: 500 0.7rem var(--sans); color: var(--muted);
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 8px; cursor: pointer;
}
.copy:hover { color: var(--ink); border-color: var(--line-strong); }

/* ---------- Code ---------- */

.repos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.repo {
  display: flex; flex-direction: column; gap: 8px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink-2);
  transition: border-color .15s, transform .15s;
}
.repo:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-1px); }
.repo-name {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 0.82rem; font-weight: 500; color: var(--accent-ink);
  overflow-wrap: anywhere;
}
.repo-name svg { color: var(--muted); }
.repo-desc { font-size: 0.88rem; line-height: 1.55; flex: 1; }
.repo-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.76rem; color: var(--muted); }
.lang { display: inline-flex; align-items: center; gap: 6px; }
.lang::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #3572a5; }

/* ---------- Education ---------- */

.edu { list-style: none; margin: 0; padding: 0; }
.edu li {
  display: flex; justify-content: space-between; align-items: baseline; gap: 24px;
  padding: 16px 0; border-bottom: 1px solid var(--line);
}
.edu li:last-child { border-bottom: 0; }
.edu h3 { font-family: var(--serif); font-size: 1.2rem; margin-bottom: 4px; }
.edu p { margin: 0; font-size: 0.93rem; }
.edu-place { color: var(--muted); font-size: 0.85rem !important; }
.edu-date { font-family: var(--mono); font-size: 0.78rem; color: var(--ink-2); white-space: nowrap; }

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

.site-footer {
  margin-top: 96px; padding-top: 20px;
  border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px;
  font-size: 0.82rem; color: var(--muted);
}
.site-footer p { margin: 0; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--accent-ink); }

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

@media (max-width: 960px) {
  .layout { grid-template-columns: 232px minmax(0, 1fr); gap: 48px; padding-top: 56px; }
  .interests { grid-template-columns: 1fr; }
  .repos { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 48px; padding: 40px 16px 40px; }
  .profile { position: static; }
  .toc { display: none; }
  .avatar { width: 88px; height: 88px; margin-bottom: 18px; }
  .monogram { font-size: 32px; }
  .name { font-size: 1.9rem; }
  .lede { font-size: 1.38rem; }
  section + section { margin-top: 64px; }
  .pub { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .pub-side { flex-direction: row; align-items: center; padding-top: 0; }
  .news li { grid-template-columns: 80px minmax(0, 1fr); gap: 12px; }
  .edu li { flex-direction: column; gap: 6px; }
  .status { border-radius: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .status-dot { animation: none; }
  .repo, .repo:hover { transition: none; transform: none; }
}

@media print {
  .toc, .theme-toggle, .skip-link, .pub-links button, .status-dot { display: none !important; }
  .layout { display: block; padding: 0; }
  .profile { position: static; margin-bottom: 24px; }
  body { background: #fff; color: #000; }
}

/* ---------- Copy-email button (sidebar) ---------- */

.copy-email {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px; margin-left: -4px;
  color: var(--muted); background: transparent; border: 0; border-radius: 6px; cursor: pointer;
}
.copy-email svg { width: 14px; height: 14px; }
.copy-email:hover { color: var(--accent-ink); background: var(--accent-soft); }

/* ---------- Experience ---------- */

.exp { list-style: none; margin: 0; padding: 0; }
.exp > li { padding: 18px 0; border-bottom: 1px solid var(--line); }
.exp > li:first-child { padding-top: 0; }
.exp > li:last-child { border-bottom: 0; }
.exp-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.exp-head h3 { font-family: var(--serif); font-size: 1.15rem; line-height: 1.35; }
.exp-date { font-family: var(--mono); font-size: 0.76rem; color: var(--muted); white-space: nowrap; }
.exp-org { font-size: 0.9rem; color: var(--muted); margin: 2px 0 8px; }
.exp ul { margin: 0; padding-left: 1.1em; }
.exp ul li { font-size: 0.93rem; margin-bottom: 4px; max-width: 72ch; }
.exp ul li::marker { color: var(--line-strong); }

/* ---------- Contact ---------- */

.email-card {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px;
  padding: 20px 22px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.email-label { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.email-address { font-family: var(--serif); font-size: 1.35rem; color: var(--ink); overflow-wrap: anywhere; flex: 1 1 auto; }
.email-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: #fff; }
:root[data-theme="dark"] .btn-primary, :root[data-theme="dark"] .btn-primary:hover { color: #0e1014; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-primary, :root:not([data-theme="light"]) .btn-primary:hover { color: #0e1014; }
}
.contact-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.contact-links .btn { padding: 6px 14px; font-size: 0.84rem; }

/* Let the last section scroll to the top when picked from the sidebar. */
@media (min-width: 761px) {
  #contact { min-height: calc(100vh - 225px); }
}

/* ---------- Toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  z-index: 20; padding: 9px 16px; border-radius: 999px;
  font-size: 0.86rem; font-weight: 500;
  background: var(--ink); color: var(--bg);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}

@media (max-width: 760px) {
  .exp-head { flex-direction: column; gap: 2px; }
  .email-address { font-size: 1.15rem; flex-basis: 100%; }
}
