/* ==========================================================================
   Liuyang Bai — personal site
   Colors and fonts live in :root below. Change them there and the whole
   site follows.
   ========================================================================== */

/* ---------- Fonts (self-hosted so they load everywhere, incl. mainland China) */
@font-face { font-family: "Space Grotesk"; font-weight: 400; font-style: normal; font-display: swap; src: url("../fonts/space-grotesk-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Space Grotesk"; font-weight: 500; font-style: normal; font-display: swap; src: url("../fonts/space-grotesk-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Space Grotesk"; font-weight: 600; font-style: normal; font-display: swap; src: url("../fonts/space-grotesk-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 400; font-style: normal; font-display: swap; src: url("../fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 500; font-style: normal; font-display: swap; src: url("../fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Playfair Display"; font-weight: 500; font-style: normal; font-display: swap; src: url("../fonts/playfair-display-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Playfair Display"; font-weight: 500; font-style: italic; font-display: swap; src: url("../fonts/playfair-display-latin-500-italic.woff2") format("woff2"); }

/* ---------- Design tokens */
:root {
  --bg: #F6F2EA;          /* paper */
  --ink: #1C1B18;         /* main text, strong rules */
  --body: #3A3731;        /* secondary paragraphs */
  --muted: #5E5A52;       /* labels, dates */
  --rule: #DDD6CA;        /* light dividers */
  --placeholder: #E9E3D8; /* image backgrounds while loading */
  --accent: #540D15;      /* surname, venues, switch */
  --accent-hover: #8A2330;
  --on-accent: #F6F2EA;

  --sans: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --display: "Playfair Display", Georgia, "Times New Roman", serif;
  --cjk: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;

  --max: 1240px;
  --gutter: clamp(20px, 5vw, 64px);
  --ease: cubic-bezier(.2, .7, .2, 1);
}

/* ---------- Base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { display: block; max-width: 100%; }
a { color: var(--ink); text-decoration-thickness: 1px; text-underline-offset: 3px; transition: color .15s ease; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
::selection { background: var(--accent); color: var(--on-accent); }

.wrap { max-width: var(--max); margin: 0 auto; padding: 0 var(--gutter); }
.mono { font-family: var(--mono); }
.label {
  font-family: var(--mono); font-size: 13px; font-weight: 400;
  text-transform: uppercase; letter-spacing: .06em; margin: 0;
}
.muted { color: var(--muted); }
.accent { color: var(--accent); }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Header */
.site-header {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
  gap: 12px 28px; padding: 28px 0;
}
.site-header a { text-decoration: none; }
.site-header nav { display: flex; flex-wrap: wrap; gap: 8px 28px; }
.site-header nav a[aria-current="page"] { color: var(--accent); }

/* ---------- Masthead */
.masthead {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 40px;
  padding: 48px 0 40px; border-bottom: 1px solid var(--ink);
}
.masthead h1 {
  flex: 999 1 560px; margin: 0;
  font-family: var(--display); font-weight: 500;
  font-size: clamp(68px, 12vw, 184px); line-height: .9; letter-spacing: -.035em;
}
.surname { color: var(--accent); }
.portrait {
  flex: 1 1 220px; max-width: 260px; aspect-ratio: 4 / 5;
  background: var(--placeholder); overflow: hidden;
}
.portrait img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Intro + side card */
.intro {
  display: flex; flex-wrap: wrap; gap: 48px 72px;
  padding: 64px 0 80px; border-bottom: 1px solid var(--ink);
}
.intro-text { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 24px; }
.lede { margin: 0; font-size: clamp(22px, 2.3vw, 29px); line-height: 1.36; letter-spacing: -.015em; }
.intro-text p.secondary { margin: 0; color: var(--body); }
.status {
  display: flex; gap: 14px; align-items: flex-start;
}
.status::before {
  content: ""; flex: 0 0 10px; height: 10px; margin-top: 8px; background: var(--accent);
}
.status p { margin: 0; }
.status strong { font-weight: 600; }

.card { flex: 1 1 260px; max-width: 320px; display: flex; flex-direction: column; gap: 24px; }
.cn-name { font-family: var(--cjk); font-size: 40px; font-weight: 500; line-height: 1.1; letter-spacing: .04em; margin: 0; }
.card-block {
  border-top: 1px solid var(--ink); padding-top: 16px;
  display: flex; flex-direction: column; gap: 8px; font-size: 15px; line-height: 1.5;
}
.card-block .label { font-size: 12px; color: var(--muted); }
.card-block.links { font-family: var(--mono); font-size: 13px; gap: 10px; }

/* ---------- Generic section */
.section { padding: 40px 0 72px; border-bottom: 1px solid var(--ink); }
.section:last-of-type { border-bottom: 0; }
.section-head {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 12px 24px; margin-bottom: 12px;
}

/* ---------- News */
.news { list-style: none; margin: 0; padding: 0; }
.news li {
  display: flex; flex-wrap: wrap; gap: 4px 40px; padding: 18px 0;
  border-bottom: 1px solid var(--rule);
}
.news li:last-child { border-bottom: 0; }
.news time { flex: 0 0 160px; font-family: var(--mono); font-size: 13px; color: var(--muted); padding-top: 4px; }
.news p { flex: 999 1 480px; margin: 0; font-size: 18px; line-height: 1.5; }
.news strong { font-weight: 600; }
.hello { font-family: var(--mono); font-size: 16px; color: var(--accent); }

/* ---------- Publications + switch */
.pub-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; }
.count { color: var(--muted); text-transform: none; letter-spacing: 0; margin-left: 12px; }

.switch {
  display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 0;
  background: none; border: 0; cursor: pointer; color: var(--ink);
  font: inherit; font-family: var(--mono); font-size: 13px;
  text-transform: uppercase; letter-spacing: .06em;
}
.switch-label { color: var(--muted); transition: color .25s ease; }
.switch[aria-checked="false"] .switch-label[data-for="selected"],
.switch[aria-checked="true"]  .switch-label[data-for="all"] { color: var(--ink); }
.switch-track {
  position: relative; display: inline-block; width: 46px; height: 26px;
  border: 1px solid var(--ink); border-radius: 99px;
  transition: background-color .3s var(--ease), border-color .3s var(--ease);
}
.switch-knob {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 99px;
  background: var(--ink);
  transition: transform .35s var(--ease), background-color .3s var(--ease), width .2s var(--ease);
}
.switch:active .switch-knob { width: 22px; }                      /* tiny squish on press */
.switch[aria-checked="true"] .switch-track { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"] .switch-knob { transform: translateX(20px); background: var(--on-accent); }
.switch[aria-checked="true"]:active .switch-knob { transform: translateX(16px); }

/* Each paper is a 1-row grid so its height can animate open/closed. */
.pubs { list-style: none; margin: 0; padding: 0; }
.pub {
  display: grid; grid-template-rows: 1fr; opacity: 1;
  transition: grid-template-rows .45s var(--ease), opacity .3s ease .1s;
}
.pub-inner {
  overflow: hidden; min-height: 0;
}
.pub-body {
  display: flex; flex-wrap: wrap; gap: 20px 28px; padding: 24px 0;
  border-bottom: 1px solid var(--rule);
}
.pubs[data-view="selected"] .pub[data-selected="false"] {
  grid-template-rows: 0fr; opacity: 0;
  transition: grid-template-rows .45s var(--ease), opacity .2s ease;
}
.pub-thumb {
  flex: 0 0 220px; aspect-ratio: 16 / 10; background: var(--placeholder); overflow: hidden;
}
.pub-thumb img { width: 100%; height: 100%; object-fit: cover; }
.pub-text { flex: 999 1 300px; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.venue { font-family: var(--mono); font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; margin: 0; }
.pub-title { margin: 0; font-size: 21px; font-weight: 500; line-height: 1.3; letter-spacing: -.01em; }
.authors { margin: 0; font-size: 14px; color: var(--muted); line-height: 1.5; }
.authors strong { color: var(--ink); font-weight: 600; }
.pub-links { display: flex; flex-wrap: wrap; gap: 4px 16px; font-family: var(--mono); font-size: 13px; }

/* ---------- Photo strip (home) */
.photo-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }
.photo-strip figure { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.photo-strip a { display: block; aspect-ratio: 4 / 5; background: var(--placeholder); overflow: hidden; }
.photo-strip img { width: 100%; height: 100%; object-fit: cover; transition: transform .6s var(--ease); }
.photo-strip a:hover img { transform: scale(1.03); }
figcaption.meta { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
figcaption.meta .year { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ---------- Footer */
.site-footer {
  border-top: 1px solid var(--ink); padding: 24px 0 40px;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px;
  font-family: var(--mono); font-size: 12px; color: var(--muted);
}

/* ---------- Photography page */
.gallery-head {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end;
  gap: 32px; padding: 56px 0 40px; border-bottom: 1px solid var(--ink);
}
.gallery-head h1 {
  margin: 8px 0 0; font-family: var(--display); font-weight: 500;
  font-size: clamp(60px, 9vw, 128px); line-height: .9; letter-spacing: -.03em;
}
.gallery-head p { margin: 0; max-width: 400px; color: var(--body); font-size: 16px; }
.gallery { columns: 3 300px; column-gap: 16px; padding: 40px 0 56px; }
.gallery figure {
  break-inside: avoid; margin: 0 0 28px; display: flex; flex-direction: column; gap: 10px;
  animation: rise .5s var(--ease) both;
}
.gallery button.frame {
  display: block; width: 100%; padding: 0; border: 0; cursor: zoom-in;
  background: var(--placeholder); overflow: hidden;
}
.gallery img { width: 100%; height: auto; transition: transform .6s var(--ease); }
.gallery button.frame:hover img { transform: scale(1.02); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* Lightbox */
.lightbox {
  width: 100vw; height: 100vh; max-width: 100vw; max-height: 100vh; margin: 0; padding: 0;
  border: 0; background: rgba(20, 18, 16, .97); color: #F6F2EA;
}
.lightbox[open] { display: grid; grid-template-rows: auto 1fr auto; }
.lightbox::backdrop { background: transparent; }
.lb-bar { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; font-family: var(--mono); font-size: 13px; }
.lb-stage { display: flex; align-items: center; justify-content: center; min-height: 0; padding: 0 64px; }
.lb-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lb-caption { display: flex; justify-content: center; gap: 16px; padding: 14px 20px 22px; font-size: 15px; }
.lb-caption .year { font-family: var(--mono); font-size: 13px; color: #B9B1A3; }
.lb-btn {
  min-width: 44px; min-height: 44px; border: 0; background: none; color: inherit; cursor: pointer;
  font-family: var(--mono); font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
}
.lb-btn:hover { color: #D9A3A9; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 28px; }
.lb-prev { left: 8px; } .lb-next { right: 8px; }

/* ---------- Small screens */
@media (max-width: 640px) {
  body { font-size: 16px; }
  .masthead { padding-top: 24px; }
  .portrait { max-width: 180px; }
  .intro { padding: 40px 0 56px; }
  .card { max-width: none; }
  .news time { flex-basis: 100%; padding-top: 0; }
  .pub-thumb { flex-basis: 100%; }
  .lb-stage { padding: 0 8px; }
  .lb-nav { top: auto; bottom: 8px; transform: none; }
}

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