/* =========================================================================
   Shengcao Cao — personal site
   Editorial / typographic theme. Plain static CSS, no build step.
   ========================================================================= */

/* ---- Design tokens ---------------------------------------------------- */
:root {
  --bg:        #f9fafc;   /* cool near-white */
  --bg-soft:   #eef1f7;
  --ink:       #12151c;   /* cool near-black text */
  --muted:     #5a6474;   /* secondary text */
  --faint:     #98a1b0;   /* tertiary / captions */
  --rule:      #e2e7f0;   /* hairlines */
  --accent:    #0053d6;   /* primary blue */
  --accent-soft:#e6eefb;
  --sel:       #cfe0fb;

  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans:  "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --maxw: 1120px;
  --gutter: clamp(1.25rem, 5vw, 4.5rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0c0f16;
    --bg-soft:   #141926;
    --ink:       #eef1f7;
    --muted:     #98a2b4;
    --faint:     #5f6a7d;
    --rule:      #232a39;
    --accent:    #5b9bff;
    --accent-soft:#132844;
    --sel:       #1d3a63;
  }
}
/* explicit theme overrides (in case a toggle stamps data-theme) */
:root[data-theme="light"] {
  --bg:#f9fafc; --bg-soft:#eef1f7; --ink:#12151c; --muted:#5a6474;
  --faint:#98a1b0; --rule:#e2e7f0; --accent:#0053d6; --accent-soft:#e6eefb; --sel:#cfe0fb;
}
:root[data-theme="dark"] {
  --bg:#0c0f16; --bg-soft:#141926; --ink:#eef1f7; --muted:#98a2b4;
  --faint:#5f6a7d; --rule:#232a39; --accent:#5b9bff; --accent-soft:#132844; --sel:#1d3a63;
}

/* ---- Reset-ish -------------------------------------------------------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  font-feature-settings: "kern", "liga";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--sel); }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding-inline: var(--gutter); }

/* ---- Top bar ---------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: saturate(140%) blur(8px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--rule);
}
.topbar .wrap {
  display: flex; align-items: center; justify-content: space-between;
  height: 60px;
}
.brand { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; letter-spacing: .01em; }
.brand .dot { color: var(--accent); }
.nav { display: flex; align-items: center; gap: clamp(.9rem, 2.5vw, 2rem); }
.nav a {
  font-size: .82rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); font-weight: 500; padding: 4px 0; position: relative;
  transition: color .18s ease;
}
.nav a::after {
  content: ""; position: absolute; left: 0; bottom: -2px;
  width: 0; height: 1.5px; background: var(--accent); transition: width .22s ease;
}
.nav a:hover { color: var(--ink); }
.nav a:hover::after { width: 100%; }
@media (max-width: 640px) { .nav a:not(.nav-cta) { display: none; } }

/* theme toggle */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; border-radius: 8px;
  border: 1px solid var(--rule); background: transparent; color: var(--muted);
  cursor: pointer; -webkit-appearance: none; appearance: none;
  transition: color .18s, border-color .18s, background .18s;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--accent); background: var(--accent-soft); }
.theme-toggle svg { width: 17px; height: 17px; }
/* default (light): show moon; dark: show sun */
.theme-toggle .sun { display: none; }
.theme-toggle .moon { display: block; }
@media (prefers-color-scheme: dark) {
  .theme-toggle .sun { display: block; }
  .theme-toggle .moon { display: none; }
}
:root[data-theme="light"] .theme-toggle .sun { display: none; }
:root[data-theme="light"] .theme-toggle .moon { display: block; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }

/* ---- Section scaffolding --------------------------------------------- */
section { padding-block: clamp(3.5rem, 8vw, 7rem); }
.eyebrow {
  font-size: .72rem; letter-spacing: .22em; text-transform: uppercase;
  color: var(--accent); font-weight: 600;
  display: flex; align-items: center; gap: .7rem; margin: 0 0 1.6rem;
}
.eyebrow::before { content: ""; width: 26px; height: 1.5px; background: var(--accent); display: inline-block; }
.section-divider { border: 0; border-top: 1px solid var(--rule); margin: 0; }

h2.head {
  font-family: var(--serif); font-weight: 500;
  font-size: clamp(1.9rem, 4.5vw, 2.9rem);
  line-height: 1.05; letter-spacing: -.01em; margin: 0 0 1.4rem;
  text-wrap: balance;
}

/* ---- Hero ------------------------------------------------------------- */
.hero { padding-top: clamp(2.5rem, 6vw, 5rem); }
.hero-grid {
  display: grid; grid-template-columns: 1.55fr .95fr;
  gap: clamp(1.5rem, 5vw, 4rem); align-items: center;
}
.kicker {
  font-size: .78rem; letter-spacing: .2em; text-transform: uppercase;
  color: var(--muted); font-weight: 600; margin: 0 0 1.1rem;
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
}
.kicker .cjk { font-family: var(--serif); letter-spacing: .05em; color: var(--faint); text-transform: none; font-size: .95rem; }

.name {
  font-family: var(--serif); font-weight: 600;
  font-size: clamp(3.3rem, 12vw, 7.4rem);
  line-height: .92; letter-spacing: -.03em; margin: 0;
}
.name .l2 { color: var(--muted); }
.rule-accent { width: min(240px, 60%); height: 3px; background: var(--accent); margin: 1.6rem 0 1.5rem; border: 0; }
.lede { font-size: clamp(1.05rem, 2.2vw, 1.28rem); line-height: 1.5; color: var(--ink); max-width: 30ch; margin: 0 0 .4rem; }
.affil { color: var(--muted); font-size: 1rem; margin: .9rem 0 1.7rem; }
.affil a { color: var(--ink); border-bottom: 1px solid var(--rule); transition: border-color .18s; }
.affil a:hover { border-color: var(--accent); }

/* social row */
.social { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.social a {
  display: inline-flex; align-items: center; gap: .5rem;
  border: 1px solid var(--rule); border-radius: 999px;
  padding: .5rem .95rem; font-size: .86rem; font-weight: 500; color: var(--muted);
  transition: color .18s, border-color .18s, background .18s, transform .18s;
}
.social a:hover { color: var(--ink); border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.social svg { width: 16px; height: 16px; }

/* portrait (square, in colour) — click to flip */
.portrait-wrap { position: relative; justify-self: end; width: 100%; max-width: 340px; perspective: 1000px; }
.portrait-wrap::before {
  content: ""; position: absolute; inset: 16px -16px -16px 16px;
  border: 1.5px solid var(--accent); border-radius: 6px; z-index: 0;
}
.portrait { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }

.portrait-card {
  position: relative; z-index: 1; display: block; width: 100%;
  margin: 0; padding: 0; border: 0; background: transparent;
  font: inherit; color: inherit; cursor: pointer; text-align: left;
}
.portrait-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 5px; border-radius: 8px; }
.portrait-inner {
  position: relative; display: block; width: 100%; aspect-ratio: 1 / 1;
  transition: transform .8s cubic-bezier(.34, 1.32, .5, 1);
  transform-style: preserve-3d; will-change: transform;
}
.portrait-card.flipped .portrait-inner { transform: rotateY(180deg); }
/* a lively pop on each flip: card scale composes with the inner rotation */
.portrait-card.animating { animation: portrait-pop .8s ease; }
@keyframes portrait-pop {
  0%, 100% { transform: scale(1); }
  42%      { transform: scale(1.06); }
}
.portrait-face {
  position: absolute; inset: 0; display: block; border-radius: 6px;
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
  box-shadow: 0 18px 50px -22px rgba(0,0,0,.5);
}
.portrait-back {
  transform: rotateY(180deg);
  background: var(--bg-soft); border: 1px solid var(--rule);
  display: flex; align-items: center; justify-content: center;
  padding: clamp(1.1rem, 5%, 1.9rem);
}
.cat-caption {
  font-family: var(--serif); font-size: clamp(.92rem, 2.3vw, 1.12rem);
  line-height: 1.55; color: var(--muted); text-align: left;
}
.cat-caption b { color: var(--accent); font-weight: 600; }
.flip-hint {
  position: absolute; right: 10px; bottom: 10px; z-index: 2;
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink); background: color-mix(in srgb, var(--bg) 70%, transparent);
  border: 1px solid var(--rule); backdrop-filter: blur(4px);
  opacity: 0; transition: opacity .22s;
}
.flip-hint svg { width: 15px; height: 15px; }
.portrait-card:hover .flip-hint,
.portrait-card:focus-visible .flip-hint { opacity: 1; }
/* Flip intentionally animates even under prefers-reduced-motion (per request). */
@media (max-width: 820px) {
  .hero-grid { grid-template-columns: 1fr; }
  .portrait-wrap { order: -1; max-width: 230px; justify-self: start; }
  .portrait-wrap::before { inset: 12px -12px -12px 12px; }
}

/* ---- Prose ------------------------------------------------------------ */
.prose p { margin: 0 0 1.15rem; max-width: 68ch; color: var(--ink); font-size: 1.08rem; text-wrap: pretty; }
.prose p.muted { color: var(--muted); }
.prose a { color: var(--accent); border-bottom: 1px solid var(--accent-soft); transition: border-color .18s; }
.prose a:hover { border-color: var(--accent); }

/* ---- Experience + Education (side by side) ---------------------------- */
.cv-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: clamp(2rem, 6vw, 5rem); align-items: start;
}
@media (max-width: 820px) { .cv-grid { grid-template-columns: 1fr; gap: 3rem; } }

.tl { list-style: none; margin: 0; padding: 0; }
.tl li { padding: 1.15rem 0; border-top: 1px solid var(--rule); }
.tl li:last-child { border-bottom: 1px solid var(--rule); }
.tl .when {
  color: var(--accent); font-size: .8rem; font-weight: 600; letter-spacing: .03em;
  font-variant-numeric: tabular-nums; margin: 0 0 .35rem; text-transform: uppercase;
}
.tl .role { font-family: var(--serif); font-size: 1.15rem; font-weight: 500; line-height: 1.25; margin: 0 0 .15rem; }
.tl .org { color: var(--ink); font-size: .96rem; }
.tl .meta { color: var(--faint); font-size: .86rem; margin: .2rem 0 0; }

/* ---- Publications ----------------------------------------------------- */
.pubs { list-style: none; margin: 0; padding: 0; }
.pub { padding: 1.6rem 0; border-top: 1px solid var(--rule); }
.pub:last-child { border-bottom: 1px solid var(--rule); }
.pub .title {
  font-family: var(--serif); font-weight: 500; font-size: clamp(1.12rem, 2.2vw, 1.4rem);
  line-height: 1.25; letter-spacing: -.005em; margin: 0 0 .4rem;
}
.pub .title a { color: inherit; transition: color .18s; }
.pub .title a:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
.pub .authors { color: var(--muted); font-size: .95rem; line-height: 1.5; margin: 0 0 .5rem; }
.pub .authors .me { color: var(--ink); font-weight: 600; }

/* venue label — OPTION A (accent uppercase label); swap per choice below */
.pub .venue { color: var(--accent); font-size: .74rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; margin: 0; }
/* OPTION B (italic serif citation):
.pub .venue { color: var(--muted); font-family: var(--serif); font-style: italic; font-size: 1rem; letter-spacing: 0; text-transform: none; font-weight: 400; margin: 0; }
*/

.footnote { color: var(--faint); font-size: .82rem; margin-top: 1.3rem; }
.footnote a { color: var(--muted); border-bottom: 1px solid var(--rule); }

/* ---- Footer ----------------------------------------------------------- */
footer.site { background: var(--bg-soft); border-top: 1px solid var(--rule); padding-block: clamp(2rem, 5vw, 3.5rem); }
.foot { display: flex; flex-wrap: wrap; gap: 1rem 2rem; justify-content: space-between; align-items: center; }
.foot-copy { color: var(--faint); font-size: .85rem; margin: 0; }
/* a little secret ♥ hidden in the cat caption */
.secret { text-decoration: none; cursor: pointer; }
.secret:focus-visible { outline: none; }
.secret .heart {
  font-size: .72em; color: var(--faint); display: inline-block;
  transition: color .25s ease, transform .25s ease;
}
.secret:hover .heart, .secret:focus-visible .heart { color: #e0567f; transform: scale(1.3); }
.foot-links { display: flex; flex-wrap: wrap; gap: 1.3rem; }
.foot-links a { color: var(--muted); font-size: .9rem; transition: color .18s; }
.foot-links a:hover { color: var(--accent); }

/* ---- Reveal on scroll ------------------------------------------------- */
.reveal { opacity: 0; transform: translateY(18px); transition: opacity .7s ease, transform .7s ease; }
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .reveal { opacity: 1; transform: none; transition: none; } }
