/* ═══════════════════════════════════════════════════════════════════════
   Kenfeng Huang — academic homepage
   Plain CSS, no build step, no web fonts. Restyle by editing the tokens.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Tokens ─────────────────────────────────────────────────────────── */
:root {
  --font-serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino,
                "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-sans:  -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
                "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei",
                "Noto Sans CJK SC", sans-serif;
  --font-mono:  ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
                "Liberation Mono", monospace;

  --measure: 1060px;
  --radius: 8px;
  --ease: cubic-bezier(.22, .61, .36, 1);
}

:root[data-theme="light"] {
  --bg:        #fdfcfa;
  --bg-tint:   #f3f1ec;
  --text:      #14161a;
  --text-soft: #3a3f49;
  --muted:     #757b88;
  --border:    #e6e3db;
  --accent:    #1f5f8b;
  --accent-hi: #16486a;
  --accent-soft: rgba(31, 95, 139, .10);
}

:root[data-theme="dark"] {
  --bg:        #101216;
  --bg-tint:   #191c22;
  --text:      #e8eaee;
  --text-soft: #c2c7d1;
  --muted:     #8d95a3;
  --border:    #272c35;
  --accent:    #79b7e5;
  --accent-hi: #a0cef1;
  --accent-soft: rgba(121, 183, 229, .14);
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-soft);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

h1, h2, h3 { font-family: var(--font-serif); font-weight: 600; line-height: 1.3; letter-spacing: -.01em; }
p { margin: 0 0 1em; }
strong, b { color: var(--text); font-weight: 640; }

a { color: var(--accent); text-decoration: none; transition: color .16s var(--ease); }
a:hover { color: var(--accent-hi); text-decoration: underline; text-underline-offset: .18em; }

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

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

.icon {
  width: 1em; height: 1em;
  fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
  flex: none;
}

.muted { color: var(--muted); }
.me { color: var(--text); border-bottom: 2px solid var(--accent-soft); }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #fff; padding: .7rem 1.1rem;
}
.skip-link:focus { left: 0; }

/* ── Top bar ──────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  border-bottom: 1px solid transparent;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  transition: border-color .25s var(--ease);
}
.topbar.is-stuck { border-bottom-color: var(--border); }

.topbar__inner {
  max-width: var(--measure);
  margin-inline: auto;
  padding: .6rem clamp(1.1rem, 4vw, 2.25rem);
  display: flex; align-items: center; gap: .9rem;
}

.topbar__brand {
  font-family: var(--font-serif);
  font-size: 1rem; font-weight: 600;
  color: var(--text);
  opacity: 0; transform: translateY(-4px);
  transition: opacity .3s var(--ease), transform .3s var(--ease);
  pointer-events: none; white-space: nowrap;
}
.topbar.is-stuck .topbar__brand { opacity: 1; transform: none; pointer-events: auto; }
.topbar__brand:hover { text-decoration: none; color: var(--accent); }

.topbar__nav {
  margin-left: auto;
  display: flex; gap: .05rem;
  overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none;
}
.topbar__nav::-webkit-scrollbar { display: none; }
.topbar__nav a {
  padding: .3rem .62rem;
  border-radius: 6px;
  font-size: .862rem; font-weight: 500;
  color: var(--muted); white-space: nowrap;
}
.topbar__nav a:hover { color: var(--text); background: var(--bg-tint); text-decoration: none; }
.topbar__nav a.is-active { color: var(--accent); background: var(--accent-soft); }

.topbar__actions { flex: none; display: flex; align-items: center; gap: .35rem; }

.pill-btn {
  flex: none;
  height: 30px; min-width: 30px;
  display: grid; place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  transition: color .18s var(--ease), border-color .18s var(--ease);
}
.pill-btn:hover { color: var(--accent); border-color: var(--accent); }
.lang-toggle { padding: 0 .5rem; font-size: .75rem; font-weight: 650; }
.theme-toggle .icon { width: 15px; height: 15px; }
:root[data-theme="light"] .icon--moon { display: none; }
:root[data-theme="dark"]  .icon--sun  { display: none; }

/* ── Bilingual switching ────────────────────────────────────────────────
   Every translatable string appears twice, tagged data-lang="en" / "zh";
   <html lang> decides which is shown. Pure CSS, so it also works without JS.
   ─────────────────────────────────────────────────────────────────────── */
:root[lang="en"] [data-lang="zh"],
:root[lang="zh"] [data-lang="en"] { display: none !important; }

/* CJK wants a bit more leading and no negative tracking.
   Deliberately no text-align:justify — it stretches CJK badly in narrow columns. */
:root[lang="zh"] body { line-height: 1.88; }
:root[lang="zh"] h1, :root[lang="zh"] h2, :root[lang="zh"] h3 { letter-spacing: 0; }

/* ── Page grid ──────────────────────────────────────────────────────── */
.page {
  max-width: var(--measure);
  margin-inline: auto;
  padding: clamp(2rem, 5vw, 3.75rem) clamp(1.1rem, 4vw, 2.25rem) 3rem;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: clamp(2rem, 4.5vw, 3.5rem);
  align-items: start;
}

/* ── Sidebar ────────────────────────────────────────────────────────── */
.sidebar__sticky { position: sticky; top: 86px; }

.avatar {
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 12px;
  object-fit: cover;
  object-position: 50% 22%;   /* keep the face in frame when the box gets shorter */
  border: 1px solid var(--border);
}

.profile__name { margin: 1.2rem 0 .45rem; font-size: 1.5rem; }
.profile__role { margin: 0 0 .35rem; font-size: .875rem; line-height: 1.55; color: var(--text-soft); }
.profile__where { margin: 0; font-size: .82rem; color: var(--muted); }

.social {
  margin-top: 1.25rem; padding-top: 1.1rem;
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .3rem .6rem;
}
.social a {
  display: flex; align-items: center; gap: .42rem;
  font-size: .83rem; color: var(--text-soft);
  padding: .12rem 0;
}
.social a:hover { color: var(--accent); text-decoration: none; }
.social .icon { width: 14px; height: 14px; color: var(--muted); }
.social a:hover .icon { color: var(--accent); }
.social span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Sections ───────────────────────────────────────────────────────── */
.section { margin-bottom: clamp(2.5rem, 4.5vw, 3.5rem); }

.section__title {
  display: flex; align-items: baseline; gap: .55rem;
  margin: 0 0 1.1rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
  font-size: 1.3rem;
  color: var(--text);
}
.section__emoji {
  font-size: .95em;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  line-height: 1;
}

/* The introduction runs long, so it is set a step smaller than the rest. */
.intro { font-size: .935rem; line-height: 1.78; }
.intro p { margin-bottom: .85em; }

/* Research-topic list inside the introduction */
.topics { margin: 0 0 1em; padding-left: 1.15rem; }
.topics li { margin-bottom: .3rem; font-size: .935rem; }
.topics li::marker { color: var(--muted); }

/* ── Education / experience rows ────────────────────────────────────── */
.cv { list-style: none; margin: 0; padding: 0; }
.cv li {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr) auto;
  gap: .3rem 1.1rem;
  align-items: center;
  padding: .7rem 0;
}
.cv li + li { border-top: 1px solid var(--border); }

.cv__date { font-family: var(--font-mono); font-size: .8rem; color: var(--muted); white-space: nowrap; }

.cv__main { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.cv__mark { width: 34px; height: 34px; flex: none; object-fit: contain; }
/* The emblem is blue on transparent, which sinks into a dark page — sit it on
   a white disc there, the way it appears on the university's own stationery. */
:root[data-theme="dark"] .cv__mark { background: #fff; border-radius: 50%; }
.cv__main b { display: block; font-size: .96rem; }
.cv__dept { display: block; font-size: .83rem; color: var(--muted); }

.cv__side { font-size: .83rem; color: var(--muted); text-align: right; white-space: nowrap; }

/* ── Publications ───────────────────────────────────────────────────── */
.pubs { margin: 0; padding-left: 1.35rem; }
.pubs > li { margin-bottom: 1.6rem; }
.pubs > li::marker { color: var(--muted); font-size: .85rem; }

.pub__cite { margin: 0 0 .85rem; font-size: .95rem; line-height: 1.7; }
.pub__cite a { color: var(--text); font-weight: 600; }
.pub__cite a:hover { color: var(--accent); }

.chip {
  display: inline-block;
  margin-left: .15rem;
  padding: 0 .42em;
  border: 1px solid var(--accent-soft);
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: .72rem; font-weight: 650;
  vertical-align: .08em;
}

.pub__src {
  margin-left: .2rem;
  font-size: .82rem; font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}
.pub__src:hover { color: var(--accent); }

/* The figure sits on a tinted plate with generous padding, so a dense,
   very wide diagram reads as a figure rather than a pasted screenshot. */
.paper__figure { margin: 0; }

.plate {
  position: relative;
  display: block;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-tint);
  transition: border-color .2s var(--ease);
}
.plate:hover { border-color: var(--accent); }
.plate img {
  width: 100%;
  border-radius: 4px;
  background: #fff;
}

.plate__zoom {
  position: absolute; right: 20px; bottom: 20px;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 6px;
  background: color-mix(in srgb, var(--text) 72%, transparent);
  color: var(--bg);
  opacity: 0;
  transition: opacity .2s var(--ease);
}
.plate:hover .plate__zoom, .plate:focus-visible .plate__zoom { opacity: 1; }
.plate__zoom .icon { width: 15px; height: 15px; }

.paper__figure figcaption {
  margin-top: .6rem;
  font-size: .82rem; line-height: 1.65;
  color: var(--muted);
}

/* ── News ───────────────────────────────────────────────────────────── */
.news { list-style: none; margin: 0; padding: 0; }
.news li {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: .9rem;
  padding: .38rem 0;
  font-size: .93rem;
}
.news__date { font-family: var(--font-mono); font-size: .8rem; color: var(--muted); white-space: nowrap; }

/* ── Contact ────────────────────────────────────────────────────────── */
.contact { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.contact li { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: .9rem; align-items: baseline; }
.contact__key { font-size: .78rem; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.contact a { font-family: var(--font-mono); font-size: .9rem; }

/* ── Footer ─────────────────────────────────────────────────────────── */
.footer { padding-top: 1.4rem; border-top: 1px solid var(--border); }
.footer p { margin: 0; font-size: .8rem; color: var(--muted); }

/* ── Back-to-top ─────────────────────────────────────────────────────── */
.to-top {
  position: fixed; right: 1.4rem; bottom: 1.4rem; z-index: 40;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: 50%;
  background: var(--bg); color: var(--muted);
  cursor: pointer;
  opacity: 0; transform: translateY(8px);
  transition: opacity .3s var(--ease), transform .3s var(--ease), color .18s var(--ease);
}
.to-top:not([hidden]) { opacity: 1; transform: none; }
.to-top:hover { color: var(--accent); border-color: var(--accent); }
.to-top .icon { width: 16px; height: 16px; }


/* ── Reveal on scroll ───────────────────────────────────────────────── */
.reveal { opacity: 0; transform: translateY(12px); }
.reveal.is-in { opacity: 1; transform: none; transition: opacity .55s var(--ease), transform .55s var(--ease); }
.reveal.is-static { opacity: 1; transform: none; }

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 880px) {
  .page { grid-template-columns: 1fr; gap: 2.25rem; }
  .sidebar__sticky { position: static; display: contents; }
  .sidebar {
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr);
    gap: .3rem 1.5rem;
    align-items: start;
  }
  .avatar { grid-row: span 4; align-self: start; }
  .profile__name { margin-top: 0; }
  .social { grid-column: 2; margin-top: .9rem; }
}

@media (max-width: 600px) {
  .sidebar { grid-template-columns: 1fr; justify-items: start; }
  .avatar { width: 160px; grid-row: auto; }
  .profile__name { margin-top: .9rem; }
  .social { grid-column: auto; width: 100%; }
  .cv li { grid-template-columns: 1fr; gap: .35rem; }
  .cv__side { text-align: left; }
  .news li, .contact li { grid-template-columns: 1fr; gap: .1rem; }
  .topbar__brand { display: none; }
  .topbar__nav { margin-left: 0; }
  .to-top { right: 1rem; bottom: 1rem; }
}

/* ── Motion & print ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .reveal { opacity: 1; transform: none; }
}

@media print {
  :root { --bg: #fff; --bg-tint: #fff; --text: #000; --text-soft: #222; --muted: #444; --border: #ccc; --accent: #000; }
  body { background: #fff; font-size: 10.5pt; }
  .topbar, .to-top, .social { display: none !important; }
  .page { display: block; max-width: none; padding: 0; }
  .sidebar { margin-bottom: 1.25rem; }
  .avatar { width: 96px; }
  .pubs > li, .cv li { break-inside: avoid; }
  a { color: #000; }
  .reveal { opacity: 1 !important; transform: none !important; }
}
