/* =========================================================
   Yuhang Zhang — personal site
   Plain CSS, no build step. Tokens live on :root; dark mode
   Light is the default on every device; dark is opt-in through the toggle ([data-theme]).
   ========================================================= */

:root {
  --bg: #f3efe6;
  --bg-2: #e9e4d8;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #fffdf9;
  --border: rgba(30, 30, 30, 0.09);
  --border-strong: rgba(30, 30, 30, 0.18);
  --text: #1d2127;
  --muted: #5b6370;
  --accent: #0e7490;
  --accent-2: #b4531b;
  --accent-soft: rgba(14, 116, 144, 0.12);
  --accent-2-soft: rgba(180, 83, 27, 0.12);
  --dot: rgba(30, 30, 30, 0.10);
  --surface-flat: #fcfbf8;
  --bg-translucent: rgba(243, 239, 230, 0.8);
  --bg-translucent-soft: rgba(243, 239, 230, 0.6);
  --blob-1: rgba(14, 116, 144, 0.2);
  --blob-2: rgba(180, 83, 27, 0.16);
  --border-accent: rgba(14, 116, 144, 0.45);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 28px -14px rgba(20, 30, 40, 0.22);
  --radius: 14px;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
               "Noto Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-serif: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", "Noto Serif CJK SC",
                "Songti SC", "SimSun", Georgia, serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1317;
  --bg-2: #161c22;
  --surface: rgba(24, 30, 37, 0.72);
  --surface-solid: #181e25;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.2);
  --text: #e7e9ec;
  --muted: #9aa4b1;
  --accent: #5fd3c7;
  --accent-2: #f0a36b;
  --accent-soft: rgba(95, 211, 199, 0.14);
  --accent-2-soft: rgba(240, 163, 107, 0.14);
  --dot: rgba(255, 255, 255, 0.07);
  --surface-flat: #161b21;
  --bg-translucent: rgba(15, 19, 23, 0.8);
  --bg-translucent-soft: rgba(15, 19, 23, 0.6);
  --blob-1: rgba(95, 211, 199, 0.2);
  --blob-2: rgba(240, 163, 107, 0.16);
  --border-accent: rgba(95, 211, 199, 0.45);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px -14px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
img { max-width: 100%; }
h1, h2, h3 { font-family: var(--font-serif); font-weight: 600; letter-spacing: -0.01em; }
.muted { color: var(--muted); }

/* ---------- background layer ---------- */
.bg {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: -1;
  background:
    radial-gradient(55% 45% at 8% -5%, var(--blob-1), transparent 70%),
    radial-gradient(45% 40% at 95% 8%, var(--blob-2), transparent 70%),
    var(--bg);
}
.bg canvas {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0.92;
  display: none;
}
/* only the side margins: the 57.5rem content column (plus a soft feather) is masked out */
@media (min-width: 62.5em) {
  .bg canvas {
    display: block;
    -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(50% - 33.125rem), transparent calc(50% - 29.375rem), transparent calc(50% + 29.375rem), #000 calc(50% + 33.125rem), #000 100%);
            mask-image: linear-gradient(90deg, #000 0, #000 calc(50% - 33.125rem), transparent calc(50% - 29.375rem), transparent calc(50% + 29.375rem), #000 calc(50% + 33.125rem), #000 100%);
  }
}

/* ---------- motion ---------- */
html.js .reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.6s ease, transform 0.6s ease;
  transition-delay: calc(var(--i, 0) * 70ms);
}
html.js .reveal.is-in { opacity: 1; transform: none; }
html.theme-anim,
html.theme-anim *,
html.theme-anim *::before,
html.theme-anim *::after {
  transition: background-color 0.35s ease, color 0.35s ease, border-color 0.35s ease, fill 0.35s ease !important;
}

/* ---------- nav ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-translucent);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
          backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.nav__inner {
  max-width: 57.5rem;
  margin: 0 auto;
  padding: 0.625rem 1rem;
  display: flex;
  align-items: center;
  gap: 12px;
}
.nav__brand {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text);
  white-space: nowrap;
}
.nav__brand:hover { text-decoration: none; color: var(--accent); }
.nav__links {
  margin-left: auto;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav__links::-webkit-scrollbar { display: none; }
.nav__links a {
  padding: 6px 11px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.nav__links a:hover,
.nav__links a.is-active { color: var(--text); background: var(--accent-soft); text-decoration: none; }

.theme-toggle {
  flex: none;
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle:active { transform: scale(0.94); }
.theme-toggle .icon { width: 18px; height: 18px; }
.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }
:root[data-theme="light"] .icon-sun { display: block; }
:root[data-theme="light"] .icon-moon { display: none; }

/* ---------- icons ---------- */
.icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ---------- layout ---------- */
.container { max-width: 57.5rem; margin: 0 auto; padding: 0 1rem 3.5rem; }
.section { padding: 1.75rem 0 0.5rem; scroll-margin-top: 4.5rem; }
.section > h2 {
  font-size: 1.6rem;
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.section > h2::after { content: ""; flex: 1; height: 1px; background: var(--border-strong); opacity: 0.6; }
.h2__emoji { font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; font-size: 0.9em; margin-right: 2px; }
.section__note { margin: -6px 0 18px; color: var(--muted); font-size: 0.95rem; }

/* ---------- hero ---------- */
.hero {
  display: grid;
  grid-template-columns: 12.5rem 1fr;
  gap: 2.25rem;
  align-items: center;
  padding: 3.5rem 0 1.25rem;
  scroll-margin-top: 4.5rem;
}
.hero__photo img {
  display: block;
  width: 12.5rem;
  height: 15.625rem;
  object-fit: cover;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--surface-solid);
  box-shadow: var(--shadow);
}
.hero__name {
  margin: 0;
  font-size: clamp(2rem, 4.2vw, 2.65rem);
  line-height: 1.15;
  font-weight: 700;
}
.hero__cn {
  font-weight: 500;
  font-size: 0.78em;
  color: var(--muted);
  margin-left: 0.3em;
  letter-spacing: 0.04em;
}
.hero__role { margin: 10px 0 18px; color: var(--muted); font-size: 1rem; line-height: 1.55; }

.links { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.links a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  transition: border-color 0.15s, color 0.15s, transform 0.15s;
}
.links a:hover { border-color: var(--brand, var(--accent)); color: var(--brand, var(--accent)); text-decoration: none; transform: translateY(-1px); }
.icon--brand { fill: currentColor; stroke: none; width: 17px; height: 17px; }
.links a .icon--brand { color: var(--brand, currentColor); }
.brand--mail { --brand: #EA4335; }
.brand--scholar { --brand: #4285F4; }
.brand--github { --brand: #181717; }
.brand--linkedin { --brand: #0A66C2; }
:root[data-theme="dark"] .brand--github { --brand: #ffffff; }

/* ---------- about ---------- */
.about { padding-top: 12px; }
.interests {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 24px;
}
.interests li { position: relative; padding-left: 18px; font-size: 1rem; }
.interests li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.62em;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.85;
}
.about p { margin: 0 0 0.9em; font-size: 1.02rem; }
.tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.tag {
  padding: 4px 11px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 500;
}

/* ---------- news (timeline) ---------- */
.news { list-style: none; margin: 0; padding: 0; }
.news li {
  position: relative;
  display: grid;
  grid-template-columns: 6rem 1fr;
  gap: 0.25rem 2.125rem;
  padding: 8px 0 16px;
}
.news li::before {
  content: "";
  position: absolute;
  left: 6.75rem;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border-strong);
  opacity: 0.6;
}
.news li:first-child::before { top: 16px; }
.news li:last-child::before { bottom: calc(100% - 16px); }
.news li::after {
  content: "";
  position: absolute;
  left: 6.5rem;
  top: 0.75rem;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--bg);
}
.news time { color: var(--muted); font-size: 0.92rem; font-variant-numeric: tabular-nums; padding-top: 1px; white-space: nowrap; }

.news__toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0.625rem 0 0 8.125rem;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.news__toggle:hover { border-color: var(--accent); color: var(--accent); }
.news__chev { width: 15px; height: 15px; transition: transform 0.2s ease; }
.news__toggle[aria-expanded="true"] .news__chev { transform: rotate(180deg); }
html.js .news.is-collapsed > li:nth-child(n + 4) { display: none; }
html.js .news.is-collapsed > li:nth-child(3)::before { bottom: calc(100% - 16px); }

/* ---------- publications ---------- */
.pubs { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; }
.pub {
  display: grid;
  grid-template-columns: 16.25rem 1fr;
  gap: 1.25rem;
  padding: 16px;
  background: var(--surface-flat);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  align-items: start;
  transition: transform 0.25s ease, border-color 0.2s ease, box-shadow 0.25s ease;
}
.pub:hover { transform: translateY(-3px); border-color: var(--border-accent); box-shadow: var(--shadow), 0 18px 40px -22px rgba(20, 30, 40, 0.35); }
.pub__thumb {
  position: relative;
  display: block;
  aspect-ratio: 16 / 10;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
/* older engines without aspect-ratio keep the same box via padding */
@supports not (aspect-ratio: 16 / 10) {
  .pub__thumb { height: 0; padding-bottom: 62.5%; }
}
/* absolute + object-fit resolves everywhere; percentage max-height on a grid item does not */
.pub__thumb picture { display: contents; }
.pub__thumb img {
  position: absolute;
  top: 7px;
  right: 7px;
  bottom: 7px;
  left: 7px;
  width: calc(100% - 14px);
  height: calc(100% - 14px);
  object-fit: contain;
  object-position: center;
  transition: transform 0.25s ease;
}
.pub:hover .pub__thumb img { transform: scale(1.02); }
.pub__meta { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--muted); }
.badge {
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.74rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.badge--journal { background: var(--accent-soft); color: var(--accent); }
.badge--preprint { background: var(--accent-2-soft); color: var(--accent-2); }
.pub__title { margin: 6px 0 4px; font-family: var(--font-sans); font-size: 1.05rem; font-weight: 600; line-height: 1.4; letter-spacing: 0; }
.pub__title a { color: var(--text); }
.pub__title a:hover { color: var(--accent); text-decoration: none; }
.pub__authors { margin: 0 0 10px; font-size: 0.92rem; color: var(--muted); }
.pub__authors strong { color: var(--text); font-weight: 600; }
.pub__venue { margin: -6px 0 10px; font-size: 0.9rem; color: var(--muted); font-style: italic; }
.pub__links { margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.pub__links a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  background: var(--surface-solid);
  transition: border-color 0.15s, color 0.15s;
}
.pub__links a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.pub__links .stars { color: var(--muted); font-weight: 400; }

/* ---------- education ---------- */
.edus { list-style: none; margin: 0; padding: 0; position: relative; }
.edus::before {
  content: "";
  position: absolute;
  left: 1.6875rem;
  top: 2.125rem;
  bottom: 2.125rem;
  width: 2px;
  background: var(--border-strong);
  opacity: 0.6;
}
.edu {
  position: relative;
  display: grid;
  grid-template-columns: 3.5rem 1fr;
  gap: 1rem;
  padding: 0.75rem 0;
}
.edu__logo { width: 3.5rem; height: 3.5rem; object-fit: contain; }
.edu__logo--ntu { transform: scale(1.14); }
.edu__head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; align-items: baseline; }
.edu__head h3 { margin: 0; font-family: var(--font-sans); font-size: 1.02rem; font-weight: 600; letter-spacing: 0; }
.edu__time { color: var(--muted); font-size: 0.9rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.edu p { margin: 2px 0 0; }
.edu .muted { font-size: 0.92rem; }

/* ---------- services ---------- */
.services { display: grid; gap: 14px; }
.services__group h3 { margin: 0 0 6px; font-family: var(--font-sans); font-size: 1rem; font-weight: 600; letter-spacing: 0; }
.services__group ul { margin: 0; padding-left: 20px; }
.services__group li { margin: 3px 0; }

/* ---------- back to top ---------- */
.to-top {
  position: fixed;
  right: 1.25rem;
  bottom: 1.5rem;
  z-index: 9;
  width: 2.75rem;
  height: 2.75rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease, border-color 0.15s, color 0.15s;
}
.to-top.is-visible { opacity: 1; transform: none; pointer-events: auto; }
.to-top:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.to-top .icon { width: 20px; height: 20px; }

/* ---------- visitor map ---------- */
.visitors { max-width: 22.5rem; margin: 0 auto 1rem; }
.visitors:empty { display: none; }
.visitors img, .visitors canvas { max-width: 100%; height: auto; border-radius: 8px; }

/* ---------- footer ---------- */
.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
  padding: 28px 16px 40px;
  border-top: 1px solid var(--border);
  background: var(--bg-translucent-soft);
}
.footer p { margin: 4px 0; }
.footer__small { font-size: 0.8rem; opacity: 0.8; }

/* ---------- responsive ---------- */
@media (max-width: 45em) {
  .hero { grid-template-columns: 1fr; gap: 22px; padding: 32px 0 12px; }
  .hero__photo img { width: 9rem; height: 11.25rem; border-radius: 1.25rem; }
  .hero__name { font-size: 2rem; }
  .pub { grid-template-columns: 1fr; gap: 14px; padding: 14px; }
  .news li { grid-template-columns: 1fr; gap: 0.125rem; padding-left: 1.5rem; }
  .news li::before { left: 0.25rem; }
  .news li::after { left: 0; }
  .news__toggle { margin-left: 1.5rem; }
  .edus::before { left: 1.3125rem; }
  .interests { grid-template-columns: 1fr; }
  .edu { grid-template-columns: 2.75rem 1fr; gap: 0.75rem; }
  .edu__logo { width: 2.75rem; height: 2.75rem; }
  .edu__time { white-space: normal; }
  .nav__brand { font-size: 1rem; }
  .to-top { right: 0.875rem; bottom: 1rem; width: 2.5rem; height: 2.5rem; }
  .nav__links a { padding: 6px 9px; font-size: 0.88rem; }
  .nav__links {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 1.75rem), transparent);
            mask-image: linear-gradient(to right, #000 calc(100% - 1.75rem), transparent);
    padding-right: 1.5rem;
  }
}
@media (max-width: 30em) {
  .nav__brand { display: none; }
  .nav__links { margin-left: 0; }
}

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

@media print {
  .bg, .nav, .theme-toggle { display: none; }
  .pub { box-shadow: none; break-inside: avoid; }
  a { color: inherit; }
}
