/* ==========================================================================
   Song Yuhao — academic homepage
   Warm paper + ink, one terracotta accent. Themes via CSS variables.
   Dark values are declared twice on purpose: explicit [data-theme="dark"]
   and a no-JS fallback for prefers-color-scheme.
   ========================================================================== */

/* Self-hosted variable fonts (SIL OFL, see assets/fonts/LICENSE.txt) */
@font-face {
  font-family: "Newsreader Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url("../fonts/newsreader-latin-opsz.woff2") format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../fonts/inter-latin-wght.woff2") format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* Chinese: subsets of Noto Serif SC / Noto Sans SC holding only the characters used on the page
   (rebuild with scripts/subset-cjk-fonts.py); other characters fall back to the system CJK font. */
@font-face {
  font-family: "Noto Serif SC Subset";
  font-style: normal;
  font-display: swap;
  font-weight: 400;
  src: url("../fonts/noto-serif-sc-400.woff2") format("woff2");
  unicode-range: U+3000-303F, U+4E00-9FFF, U+FF00-FFEF, U+2014, U+2018-201D, U+2026, U+00B7;
}
@font-face {
  font-family: "Noto Serif SC Subset";
  font-style: normal;
  font-display: swap;
  font-weight: 600;
  src: url("../fonts/noto-serif-sc-600.woff2") format("woff2");
  unicode-range: U+3000-303F, U+4E00-9FFF, U+FF00-FFEF, U+2014, U+2018-201D, U+2026, U+00B7;
}
@font-face {
  font-family: "Noto Sans SC Subset";
  font-style: normal;
  font-display: swap;
  font-weight: 400;
  src: url("../fonts/noto-sans-sc-400.woff2") format("woff2");
  unicode-range: U+3000-303F, U+4E00-9FFF, U+FF00-FFEF, U+2014, U+2018-201D, U+2026, U+00B7;
}
@font-face {
  font-family: "Noto Sans SC Subset";
  font-style: normal;
  font-display: swap;
  font-weight: 600;
  src: url("../fonts/noto-sans-sc-600.woff2") format("woff2");
  unicode-range: U+3000-303F, U+4E00-9FFF, U+FF00-FFEF, U+2014, U+2018-201D, U+2026, U+00B7;
}

:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --text: #1d1b18;
  --muted: #6a655c;
  --rule: #e6e1d7;
  --dot: rgba(60, 50, 30, 0.13);
  --accent: #b0432a;
  --accent-soft: rgba(176, 67, 42, 0.09);
  --shadow: 0 10px 30px -12px rgba(60, 40, 20, 0.22);

  --font-sans: "Inter Variable", "Noto Sans SC Subset", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  /* Latin from Newsreader; Chinese from the Noto Serif SC subset, then system fonts */
  --font-serif: "Newsreader Variable", "Noto Serif SC Subset", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", serif;

  --maxw: 1120px;
  --nav-h: 60px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #141311;
  --surface: #1c1a17;
  --text: #ece8e1;
  --muted: #a29c91;
  --rule: #2e2b26;
  --dot: rgba(255, 245, 225, 0.09);
  --accent: #e58f6f;
  --accent-soft: rgba(229, 143, 111, 0.12);
  --shadow: none;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #141311;
    --surface: #1c1a17;
    --text: #ece8e1;
    --muted: #a29c91;
    --rule: #2e2b26;
    --dot: rgba(255, 245, 225, 0.09);
    --accent: #e58f6f;
    --accent-soft: rgba(229, 143, 111, 0.12);
    --shadow: none;
    color-scheme: dark;
  }
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-h) + 24px);
  -webkit-text-size-adjust: 100%;
}

body {
  position: relative;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.7;
  font-optical-sizing: auto;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* faint dot grid that fades out downwards */
body::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 640px;
  z-index: -1;
  pointer-events: none;
  background-image: radial-gradient(circle at 1px 1px, var(--dot) 1px, transparent 1.5px);
  background-size: 22px 22px;
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0%, transparent 100%);
}

h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
h1, h2, h3, .profile__role { text-wrap: balance; }
p { text-wrap: pretty; }
ul, ol { padding: 0; list-style: none; }
img { max-width: 100%; height: auto; display: block; }

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color 0.15s ease;
}
a:hover { color: var(--text); }

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

::selection { background: var(--accent-soft); }

.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding-inline: 32px;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -60px;
  z-index: 100;
  padding: 8px 14px;
  background: var(--text);
  color: var(--bg);
  border-radius: 6px;
  text-decoration: none;
}
.skip-link:focus { top: 8px; color: var(--bg); }

[hidden] { display: none !important; }

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

.nav {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--nav-h);
}

.nav__brand {
  margin-right: auto;
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.nav__brand:hover { color: var(--accent); }

.nav__links { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.nav__links::-webkit-scrollbar { display: none; }

.nav__links a {
  position: relative;
  display: block;
  padding: 6px 12px;
  color: var(--muted);
  font-size: 0.925rem;
  text-decoration: none;
  white-space: nowrap;
}
.nav__links a::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 0;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.25s ease;
}
.nav__links a:hover { color: var(--text); }
.nav__links a[aria-current="true"] { color: var(--text); }
.nav__links a[aria-current="true"]::after { transform: scaleX(1); }

.lang-switch, .theme-toggle {
  flex: none;
  height: 36px;
  color: var(--muted);
  font-family: inherit;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 9px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}
.lang-switch { padding: 0 12px; margin-left: 8px; font-size: 0.875rem; }
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  padding: 0;
}
.lang-switch:hover, .theme-toggle:hover {
  color: var(--text);
  border-color: var(--muted);
  background: var(--surface);
}

/* show the icon for the theme you would switch TO */
.icon--sun { display: none; }
:root[data-theme="dark"] .icon--sun { display: block; }
:root[data-theme="dark"] .icon--moon { display: none; }

/* ---------- Page layout: sticky profile + scrolling content ---------- */
.page {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 80px;
  padding-top: 72px;
  padding-bottom: 40px;
}

.profile { align-self: start; }
.profile__inner {
  position: sticky;
  top: calc(var(--nav-h) + 40px);
}

.profile__photo { margin-bottom: 28px; }
.profile__photo img {
  width: 160px;
  height: 160px;
  object-fit: cover;
  border-radius: 50%;
  border: 1px solid var(--rule);
}

.profile h1 {
  font-family: var(--font-serif);
  font-size: clamp(2.7rem, 4.6vw, 3.5rem);
  line-height: 1.02;
  font-weight: 560;
  letter-spacing: -0.028em;
}
.profile__zh {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 400;
  letter-spacing: 0.1em;
}
.profile__role { margin-top: 22px; font-size: 1.05rem; font-weight: 600; line-height: 1.5; }
.profile__affil { margin-top: 4px; color: var(--muted); font-size: 0.95rem; }

.profile__links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }

.profile__block { margin-top: 32px; }
.eyebrow {
  margin-bottom: 8px;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.interests li { position: relative; padding-left: 16px; font-size: 0.975rem; }
.interests li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.78em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.facts {
  display: grid;
  gap: 6px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
}
.facts li { display: flex; align-items: baseline; gap: 12px; }
.facts strong {
  min-width: 1.1em;
  color: var(--accent);
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 500;
  line-height: 1.1;
}
.facts span { color: var(--muted); font-size: 0.925rem; }

/* entrance: stagger the profile in once, no JS */
@media (prefers-reduced-motion: no-preference) {
  .profile__inner > * { animation: rise 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
  .profile__inner > *:nth-child(2) { animation-delay: 0.05s; }
  .profile__inner > *:nth-child(3) { animation-delay: 0.1s; }
  .profile__inner > *:nth-child(4) { animation-delay: 0.15s; }
  .profile__inner > *:nth-child(5) { animation-delay: 0.2s; }
  .profile__inner > *:nth-child(6) { animation-delay: 0.25s; }
  .profile__inner > *:nth-child(7) { animation-delay: 0.3s; }
  @keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

  .js .reveal:not(.in) { opacity: 0; transform: translateY(14px); }
  .reveal { transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1); }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 8px 18px;
  color: var(--text);
  font-size: 0.925rem;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  text-decoration: none;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 9px;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}
.btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.btn--primary { color: var(--bg); background: var(--text); border-color: var(--text); }
.btn--primary:hover { color: var(--bg); background: var(--accent); border-color: var(--accent); }
.btn--sm { padding: 3px 11px; font-size: 0.83rem; border-radius: 7px; }

.links { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Sections ---------- */
.section + .section { margin-top: 72px; }

.section > h2 {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 28px;
  font-family: var(--font-serif);
  font-size: 2rem;
  line-height: 1.15;
  font-weight: 560;
  letter-spacing: -0.02em;
}
.section > h2::after { content: ""; flex: 1; height: 1px; background: var(--rule); }

.note { margin: -8px 0 24px; color: var(--muted); font-size: 0.925rem; }

.prose p { max-width: 38em; }
.prose p + p { margin-top: 1em; color: var(--muted); }
.lede {
  max-width: 30em !important;
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 1.6rem;
  font-weight: 400;
  line-height: 1.42;
  letter-spacing: -0.012em;
}

/* ---------- Panels (research, projects) ---------- */
.panel {
  padding: 24px 26px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}
.panel:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--rule)); box-shadow: var(--shadow); transform: translateY(-2px); }
.panel h3 { font-family: var(--font-serif); font-size: 1.4rem; line-height: 1.25; font-weight: 580; letter-spacing: -0.012em; }
.panel p { margin-top: 6px; color: var(--muted); font-size: 0.975rem; }

.areas { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.area--wide { grid-column: 1 / -1; }

.projects { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: stretch; }
.project { display: flex; flex-direction: column; }
.project .tags { margin-top: 16px; }
.project .links { margin-top: auto; padding-top: 18px; }
.project__media { margin: -24px -26px 20px; }
.project__media img { width: 100%; border-radius: 14px 14px 0 0; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.tags li {
  padding: 2px 11px;
  color: var(--muted);
  font-size: 0.8rem;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 999px;
}

/* ---------- Publications / patents ---------- */
.entries { counter-reset: entry; }
.entry {
  counter-increment: entry;
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr);
  padding: 22px 0;
  border-top: 1px solid var(--rule);
}
.entry:last-child { border-bottom: 1px solid var(--rule); }
.entry::before {
  content: counter(entry, decimal-leading-zero);
  padding-top: 0.45rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}
.entry__type {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.entry__title {
  margin-top: 6px;
  max-width: 36em;
  font-family: var(--font-serif);
  font-size: 1.5rem;
  line-height: 1.28;
  font-weight: 560;
  letter-spacing: -0.014em;
}
.entry__title--zh { max-width: 44em; font-size: 1.2rem; line-height: 1.55; font-weight: 600; letter-spacing: 0; }
.entry__meta { margin-top: 8px; color: var(--muted); font-size: 0.925rem; }
.entry__gloss { margin-top: 6px; max-width: 42em; color: var(--muted); font-size: 0.875rem; }
.entry .links { margin-top: 14px; }

/* ---------- Contact ---------- */
.contact { display: grid; grid-template-columns: max-content 1fr; gap: 10px 32px; }
.contact dt { color: var(--muted); }

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 40px;
  padding: 28px 0 44px;
  color: var(--muted);
  font-size: 0.875rem;
  border-top: 1px solid var(--rule);
}

/* ---------- Language-specific ---------- */
html:not(:lang(zh-CN)) .zh-only,
html:lang(zh-CN) .en-only { display: none; }

html:lang(zh-CN) .lede { max-width: 30em !important; font-size: 1.3rem; line-height: 1.85; letter-spacing: 0; }
html:lang(zh-CN) .prose p { max-width: 34em; line-height: 1.9; }
html:lang(zh-CN) .panel p,
html:lang(zh-CN) .entry__gloss { line-height: 1.8; }
html:lang(zh-CN) .entry__title { max-width: 32em; }
html:lang(zh-CN) .entry__title--zh { max-width: 44em; }
html:lang(zh-CN) .eyebrow,
html:lang(zh-CN) .entry__type { letter-spacing: 0.06em; text-transform: none; }

/* ---------- Responsive ---------- */
@media (max-height: 760px) {
  .profile__inner { position: static; }
}

@media (max-width: 1100px) {
  .projects { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
  .page { grid-template-columns: 1fr; gap: 56px; padding-top: 48px; }
  .profile__inner { position: static; }
  .profile__inner { display: grid; grid-template-columns: 1fr 1fr; column-gap: 40px; }
  .profile__inner > * { grid-column: 1 / -1; }
  .profile__inner > .profile__block { grid-column: 1; }
  .profile__inner > .facts { grid-column: 2; grid-row: auto; margin-top: 32px; padding-top: 0; border-top: 0; }
  .profile__inner > .profile__block { grid-row: span 1; }
}

@media (max-width: 720px) {
  .nav { flex-wrap: wrap; height: auto; padding-block: 8px; gap: 4px 8px; }
  .nav__brand { order: 1; }
  .lang-switch { order: 2; margin-left: 0; }
  .theme-toggle { order: 3; }
  .nav__links { order: 4; width: 100%; margin-left: -12px; }
  html { scroll-padding-top: 112px; }
  .areas, .projects { grid-template-columns: 1fr; }
  .section > h2 { font-size: 1.5rem; }
  .entry { grid-template-columns: 2.4rem minmax(0, 1fr); }
}

@media (max-width: 560px) {
  .container { padding-inline: 20px; }
  .nav__links { gap: 0; margin-left: -4px; }
  .nav__links a { padding: 6px 4px; font-size: 0.75rem; }
  .nav__links a::after { left: 4px; right: 4px; }
  .lede { font-size: 1.4rem; }
  html:lang(zh-CN) .lede { font-size: 1.2rem; }
  .profile__inner { display: block; }
  .profile__inner > .facts { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--rule); }
  .panel { padding: 20px; }
  .project__media { margin: -20px -20px 18px; }
  .contact { grid-template-columns: 1fr; gap: 0; }
  .contact dd { margin-bottom: 14px; }
}

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