/* zefancai.com — one stylesheet for the whole site.
   One sans family, left-aligned blocks, sections set apart by space, one teal accent, light theme only.
   Blog posts add their own sheet on top (ar-drift.css, lastkv-rl.css); see "Blog posts" at the end. */

/* Hanken Grotesk, self-hosted variable woff2 (SIL OFL, licence text beside the files). Chinese falls through to the system face. */
@font-face { font-family: "Hanken Grotesk"; font-style: normal; font-weight: 400 700; font-display: swap; src: url("../fonts/hanken-grotesk/HankenGrotesk-normal-latin-ext.woff2") format("woff2"); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Hanken Grotesk"; font-style: normal; font-weight: 400 700; font-display: swap; src: url("../fonts/hanken-grotesk/HankenGrotesk-normal-latin.woff2") format("woff2"); 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: "Hanken Grotesk"; font-style: italic; font-weight: 400 700; font-display: swap; src: url("../fonts/hanken-grotesk/HankenGrotesk-italic-latin-ext.woff2") format("woff2"); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Hanken Grotesk"; font-style: italic; font-weight: 400 700; font-display: swap; src: url("../fonts/hanken-grotesk/HankenGrotesk-italic-latin.woff2") format("woff2"); 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; }

:root {
  --paper: #FFFFFF;
  --paper-2: #F7F9F8;        /* quiet fills */
  --paper-3: #EFF2F1;        /* hover fills */
  --ink: #1F2423;
  --ink-2: #3B4241;
  --ink-3: #5D6766;          /* at least 4.5:1 on paper */
  --rule: #D9DEDD;
  --rule-2: #E7EBEA;
  --accent: #176B65;         /* change these three to recolour the site */
  --accent-hover: #104C48;
  --link-line: rgba(23, 107, 101, 0.4);
  --mint: #D7EBE7; --mint-2: #C3E0DA; --mint-ink: #0A3A36;   /* pills */
  --deep: #1F2423; --deep-ink: #E7EBEA; --deep-muted: #9BA5A3; --deep-rule: #3B4241;   /* the footer band */

  /* research lines: the dot beside a line's name, wherever it appears */
  --line-memory: #1B7F79;
  --line-architecture: #B7791F;
  --line-cache: #6B5BB5;
  --line-multimodal: #285A8A;
  --line-reasoning: #406B33;
  --line-alignment: #99455F;
  --line-data: #7A631B;
  --line-language: #4D6774;
  --line-survey: #5B636E;

  --font-sans: "Hanken Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --max: 1180px;
  --gutter: clamp(20px, 4vw, 56px);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 24px;
}
/* clip (not hidden) keeps position: sticky intact */
html, body { margin: 0; padding: 0; overflow-x: clip; }
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
body > main { flex: 1 0 auto; width: 100%; }

a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; }
::selection { background: var(--mint-2); color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 1px;
}
#main:focus { outline: none; }

/* Skip link: hidden until focused, then a pill at the top left */
.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 2000;
  padding: 8px 16px;
  border-radius: 50px;
  background: var(--mint);
  color: var(--mint-ink);
  font-size: 15px;
  font-weight: 600;
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

/* ---------- Layout shell ---------- */
.page {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* ---------- Top bar ---------- */
.topbar {
  position: relative;
  z-index: 50;
  background: var(--paper);
  border-bottom: 1px solid var(--rule-2);
}
.topbar-inner {
  height: 72px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand {
  margin-right: auto;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap;
}
.nav {
  display: flex;
  align-items: center;
  gap: 28px;
}
.nav a {
  padding: 6px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-2);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.15s;
}
.nav a:hover { color: var(--accent-hover); }
.nav a.active { color: var(--ink); border-bottom-color: var(--accent); }

/* Language switch: a pill pair, the current language filled */
.language-switch {
  display: inline-flex;
  flex: none;
  padding: 2px;
  border-radius: 50px;
  background: var(--paper-3);
}
.language-switch a {
  padding: 5px 12px;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--ink-2);
  white-space: nowrap;
  transition: color 0.15s;
}
.language-switch a:hover { color: var(--accent-hover); }
.language-switch a[aria-current] { background: var(--mint); color: var(--mint-ink); }

/* Hamburger: shown at 860px and below */
.nav-toggle {
  display: none;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-right: -8px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s;
}
.nav-toggle:hover { background: var(--paper-3); }
.burger { position: relative; display: block; width: 18px; height: 14px; }
.burger span {
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform 0.2s ease, opacity 0.15s ease;
}
.burger span:nth-child(1) { top: 0; }
.burger span:nth-child(2) { top: 6px; }
.burger span:nth-child(3) { top: 12px; }
.nav-toggle[aria-expanded="true"] .burger span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] .burger span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] .burger span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

@media (max-width: 1000px) {
  .nav { gap: 20px; }
  .nav a { font-size: 15px; }
}
/* Narrow screens: the links drop down as a full-width panel under the bar (site.js toggles .open).
   Without scripts they stay in a second row instead. */
@media (max-width: 860px) {
  .topbar-inner { height: 60px; gap: 12px; }
  .brand { font-size: 18px; }
  .js .nav-toggle { display: inline-flex; order: 2; }
  .js .nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 60;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 4px var(--gutter) 16px;
    background: var(--paper);
    border-bottom: 1px solid var(--rule);
    box-shadow: 0 12px 24px rgba(31, 36, 35, 0.08);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
  }
  .js .nav.open { opacity: 1; visibility: visible; transform: none; }
  .js .nav a { padding: 13px 0; font-size: 16px; border-bottom: 0; }
  .js .nav a + a { border-top: 1px solid var(--rule-2); }
  .js .nav a.active { color: var(--accent-hover); }
  html:not(.js) .topbar-inner { height: auto; flex-wrap: wrap; padding-top: 10px; padding-bottom: 6px; }
  html:not(.js) .nav { order: 3; width: 100%; gap: 18px; overflow-x: auto; }
}

/* ---------- Sections: set apart by space ---------- */
section.journal { padding: clamp(56px, 8vw, 96px) 0 0; }
main > section.journal:last-child { padding-bottom: clamp(72px, 9vw, 112px); }
section.journal#hero { padding-top: clamp(40px, 6vw, 72px); }

/* Section heading: the title, and links to the full lists at the right */
.sec-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 24px;
}
.sec-title {
  margin: 0;
  font-size: clamp(25px, 2.4vw, 30px);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.sec-links { display: flex; flex-wrap: wrap; gap: 4px 22px; }
.sec-more {
  flex: none;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  transition: color 0.15s;
}
.sec-more:hover,
.work-links a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* The text link: ink on a light teal underline, teal on hover */
.hero-bio a,
.log a,
.note a,
.lede a,
.archive p a,
.ar-main a {
  color: var(--ink);
  border-bottom: 1px solid var(--link-line);
  padding: 0 1px;
  transition: color 0.15s, border-color 0.15s;
}
.hero-bio a:hover,
.log a:hover,
.note a:hover,
.lede a:hover,
.archive p a:hover,
.ar-main a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------- Research lines: one dot colour per line ---------- */
.selected-work-category--memory, .line-memory { --line: var(--line-memory); }
.selected-work-category--architecture, .line-architecture { --line: var(--line-architecture); }
.selected-work-category--cache, .line-cache { --line: var(--line-cache); }
.research-category--multimodal { --line: var(--line-multimodal); }
.research-category--reasoning { --line: var(--line-reasoning); }
.research-category--alignment { --line: var(--line-alignment); }
.research-category--data, .research-category--instruction { --line: var(--line-data); }
.research-category--language { --line: var(--line-language); }
.research-category--survey { --line: var(--line-survey); }

.research-category::before,
.work-line::before,
.hero-bio li::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line, var(--ink-3));
}

/* ---------- Hero: portrait column on the left, name and bio on the right ---------- */
.hero-grid {
  display: grid;
  grid-template-columns: clamp(190px, 21vw, 240px) minmax(0, 1fr);
  gap: clamp(32px, 6vw, 88px);
  align-items: stretch;
}
.hero-text { grid-column: 2; grid-row: 1; min-width: 0; }
.hero-aside { grid-column: 1; grid-row: 1; display: flex; flex-direction: column; }

.hero-name {
  margin: 0 0 24px;
  font-size: clamp(34px, 4.6vw, 46px);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.015em;
  color: var(--ink);
}
.hero-bio {
  max-width: 660px;
  font-size: 18px;
  line-height: 1.6;
  color: var(--ink-2);
}
.hero-bio p { margin: 0 0 16px; }
.hero-bio > :last-child { margin-bottom: 0; }
.hero-bio strong { font-weight: 600; color: var(--ink); }
/* the three research lines */
.hero-bio ul {
  list-style: none;
  margin: -6px 0 16px;
  padding: 0;
  display: grid;
  gap: 4px;
}
.hero-bio li { display: flex; align-items: baseline; gap: 12px; }
.hero-bio li::before { position: relative; top: -2px; }
.hero-bio li strong { font-weight: 600; }

.avatar-frame {
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 8px;
  background: var(--paper-2);
}
.avatar-frame img { display: block; width: 100%; height: 100%; object-fit: cover; }

/* Contact row: five equal cells, each a round-cornered hover area */
.dock {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
  margin-top: 14px;
}
.dock a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 40px;
  border-radius: 8px;
  color: var(--ink-3);
  transition: color 0.15s, background 0.15s;
}
.dock a:hover { color: var(--ink); background: var(--paper-3); }
.dock svg { display: block; width: 17px; height: 17px; }
.dock .dock-text { font-size: 13px; font-weight: 700; line-height: 1; }

/* Affiliations: a logo and two lines each */
.hero-aff {
  list-style: none;
  margin: 0;
  padding: 26px 0 0;
  display: grid;
  gap: 14px;
}
.hero-aff li { display: flex; align-items: center; gap: 14px; }
.hero-aff img { flex: none; width: 32px; height: 32px; object-fit: contain; }
.hero-aff span { display: flex; flex-direction: column; gap: 2px; font-size: 13px; line-height: 1.35; color: var(--ink-3); }
.hero-aff b { font-size: 15px; font-weight: 600; color: var(--ink); }

/* Narrow screens: the portrait sits beside the name, the contact row spans under both, then the bio.
   The two grid children dissolve (display: contents) so the four parts form one grid. */
@media (max-width: 860px) {
  .hero-grid {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "avatar name"
      "dock dock"
      "bio bio";
    column-gap: clamp(18px, 5vw, 28px);
    row-gap: 0;
    align-items: center;
  }
  .hero-text, .hero-aside { display: contents; }
  .hero-aff { display: none; }
  .avatar-frame { grid-area: avatar; width: clamp(88px, 24vw, 128px); }
  .hero-name { grid-area: name; margin: 0; }
  .dock { grid-area: dock; max-width: 400px; margin-top: 20px; }
  .hero-bio { grid-area: bio; margin-top: 20px; }
}
@media (max-width: 600px) {
  .hero-bio { font-size: 17px; }
}

/* ---------- Selected work: a figure tile and the paper beside it, grouped by research line ---------- */
.work-group + .work-group { margin-top: 28px; }
.work-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink);
}
.work-line::after { content: ""; flex: 1; min-width: 24px; height: 1px; background: var(--rule-2); }

.work {
  display: grid;
  grid-template-columns: clamp(240px, 31%, 340px) minmax(0, 1fr);
  gap: clamp(20px, 3vw, 36px);
  align-items: start;
  padding: 24px 0;
}
.work + .work { border-top: 1px solid var(--rule-2); }
.work-fig {
  position: relative;
  display: block;
  aspect-ratio: 2 / 1;
  overflow: hidden;
  border: 1px solid var(--rule-2);
  border-radius: 8px;
  background: #fff;
  transition: border-color 0.15s;
}
.work-fig:hover { border-color: var(--rule); }
.work-fig img {
  position: absolute;
  inset: 12px;
  width: calc(100% - 24px);
  height: calc(100% - 24px);
  object-fit: contain;
}
.work-body { min-width: 0; }
.work-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.work-title a { transition: color 0.15s; }
.work-title a:hover, .work:has(.work-fig:hover) .work-title a { color: var(--accent); }
.work-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
}
.work-award {
  padding: 1px 10px;
  border-radius: 50px;
  background: var(--mint);
  color: var(--mint-ink);
  font-size: 13px;
}
.work-authors {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-3);
}
.work-authors b { font-weight: 600; color: var(--ink); }
.work-desc {
  margin: 0 0 12px;
  max-width: 68ch;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink-2);
}
.work-desc strong { font-weight: 600; color: var(--ink); }
.work-links { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 0; }
.work-links a {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  transition: color 0.15s;
}
@media (max-width: 720px) {
  .work { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .work-fig { max-width: 420px; }
}

/* ---------- News log: a date column and one sentence per entry ---------- */
.log { list-style: none; margin: 0; padding: 0; }
.log li {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 20px;
  align-items: baseline;
  padding: 10px 0;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink-2);
}
.log .date {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-3);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.log strong { font-weight: 600; color: var(--ink); }
/* Hairline where the year changes */
.log li.year-start {
  border-top: 1px solid var(--rule-2);
  margin-top: 8px;
  padding-top: 18px;
}
:lang(zh) .log li { grid-template-columns: 104px minmax(0, 1fr); }
@media (max-width: 600px) {
  .log li { grid-template-columns: 76px minmax(0, 1fr); gap: 12px; padding: 9px 0; font-size: 15px; }
  :lang(zh) .log li { grid-template-columns: 92px minmax(0, 1fr); }
}

/* Collapsed log (site.js): older entries fade out behind a pill that opens them */
.log.is-collapsed {
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 72px), transparent);
          mask-image: linear-gradient(to bottom, #000 calc(100% - 72px), transparent);
}
.log-toggle {
  display: inline-flex;
  align-items: center;
  margin-top: 16px;
  padding: 8px 16px;
  border: 0;
  border-radius: 50px;
  background: var(--mint);
  color: var(--mint-ink);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.log-toggle:hover { background: var(--mint-2); }

/* ---------- Posts: the homepage grid and the blog index rows ---------- */
.post-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: clamp(28px, 4vw, 56px);
  row-gap: 40px;
}
.post-card { display: flex; flex-direction: column; min-width: 0; }
.post-meta,
.page__date {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.post-title {
  margin: 6px 0 6px;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.post-title a,
.archive__item-title a { transition: color 0.15s; }
.post-title a:hover,
.archive__item-title a:hover { color: var(--accent); }
.post-desc {
  margin: 0;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink-2);
}
@media (max-width: 640px) {
  .post-grid { grid-template-columns: minmax(0, 1fr); row-gap: 32px; }
}

/* ---------- Experience, education, awards: two columns of entries ---------- */
.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 48px clamp(32px, 6vw, 88px);
}
.two .sec-title { margin-bottom: 12px; }
.two .sec-title:not(:first-child) { margin-top: 48px; }
.entries { list-style: none; margin: 0; padding: 0; }
.entries li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 0;
  border-bottom: 1px solid var(--rule-2);
}
.entries li:last-child { border-bottom: 0; }
.what { font-size: 17px; font-weight: 600; line-height: 1.35; color: var(--ink); }
.when { font-size: 14px; font-weight: 500; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.note { font-size: 15px; line-height: 1.5; color: var(--ink-2); }
.when + .note { margin-top: 4px; }
@media (max-width: 760px) {
  .two { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Footer: a dark band ---------- */
footer.foot {
  padding: 48px 0 40px;
  background: var(--deep);
  color: var(--deep-ink);
  font-size: 15px;
}
.foot-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px 24px;
}
.foot-brand {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: #FFFFFF;
}
.foot-mail { margin-top: 10px; }
.foot-mail a,
.foot-links a {
  color: var(--deep-ink);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--deep-rule);
  transition: color 0.15s, text-decoration-color 0.15s;
}
.foot-mail a:hover,
.foot-links a:hover { color: #FFFFFF; text-decoration-color: currentColor; }
.foot-side { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.foot-links { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 22px; }
.foot-meta { font-size: 14px; color: var(--deep-muted); }
@media (max-width: 640px) {
  .foot-side { align-items: flex-start; }
}

/* ========================================================
   Subpages
   ======================================================== */

/* Page hero: the page's title and its lede */
.page-hero { padding: clamp(40px, 6vw, 72px) 0 0; }
.page-hero h1 {
  max-width: 20em;
  margin: 0 0 16px;
  font-size: clamp(34px, 4.6vw, 46px);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.015em;
}
.lede {
  max-width: 38em;
  font-size: clamp(18px, 1.6vw, 20px);
  line-height: 1.45;
  color: var(--ink-2);
}
.lede p { margin: 0; }
.page-hero + section.journal { padding-top: clamp(32px, 5vw, 56px); }

/* Two columns with a contents list on the left (years on Publications, lines on Research) */
.with-toc {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: clamp(32px, 5vw, 72px);
  align-items: start;
}
.toc { position: sticky; top: 32px; font-size: 15px; }
.toc-label { margin-bottom: 10px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--rule-2); }
.toc a {
  display: block;
  margin-left: -2px;
  padding: 5px 0 5px 14px;
  border-left: 2px solid transparent;
  line-height: 1.4;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  transition: color 0.15s, border-color 0.15s;
}
.toc a:hover { color: var(--ink); }
.toc a.active { color: var(--ink); border-left-color: var(--accent); }
@media (max-width: 860px) {
  .with-toc { grid-template-columns: minmax(0, 1fr); gap: 28px; }
  .toc { display: none; }
}

/* Page body: plain copy, headings, and lists of entries */
.archive { min-width: 0; }
.archive p {
  max-width: 66ch;
  margin: 0 0 16px;
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink-2);
}
.archive strong { font-weight: 600; color: var(--ink); }
.archive code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--paper-3);
  font-family: var(--font-mono);
  font-size: 0.86em;
}
.archive h2 {
  margin: 48px 0 12px;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  scroll-margin-top: 24px;
}
.archive > :first-child { margin-top: 0; }
.archive > :last-child { margin-bottom: 0; }
.archive h2 > a { transition: color 0.15s; }
.archive h2 > a:hover { color: var(--accent); }

/* Entry rows: blog index, archives, sitemap */
.list__item { padding: 24px 0; border-bottom: 1px solid var(--rule-2); }
.archive > .list__item:first-child { padding-top: 4px; }
.archive > .list__item:last-child { border-bottom: 0; }
.archive .archive__item-title {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.archive .page__date { margin: 0 0 6px; font-size: 14px; }
.archive .archive__item-excerpt {
  max-width: 66ch;
  margin: 8px 0 0;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink-2);
}
.archive h2 + .list__item { padding-top: 8px; }

/* Sitemap: the same rows, set small */
.page-sitemap .list__item, .page-sitemap .archive h2 + .list__item { padding: 12px 0; }
.page-sitemap .archive .archive__item-title { font-size: 17px; line-height: 1.4; }
.page-sitemap .archive .archive__item-excerpt { margin-top: 2px; font-size: 15px; }

/* ---------- Research index: lines as groups, one row per project ---------- */
.archive h2.research-category {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 56px 0 6px;
}
.archive h2.research-category:first-child { margin-top: 0; }
.research-index-item.list__item, .archive h2 + .research-index-item.list__item { padding: 0; }
.research-index-item.list__item:has(+ h2) { border-bottom: 0; }
.research-index-item .archive__item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, auto);
  gap: 4px 28px;
  align-items: baseline;
  padding: 14px 0;
}
.archive .research-index-item .archive__item-title { font-size: 18px; line-height: 1.35; }
.archive .research-index-item .page__meta {
  max-width: none;
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--ink-3);
  text-align: right;
}
@media (max-width: 720px) {
  .research-index-item .archive__item { grid-template-columns: minmax(0, 1fr); }
  .archive .research-index-item .page__meta { text-align: left; }
}

/* ---------- Publications: year groups; each paper is a title, its lines, and one paragraph ---------- */
.archive h1[id^="year-"] {
  margin: 56px 0 10px;
  font-size: clamp(25px, 2.4vw, 30px);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  scroll-margin-top: 24px;
}
.archive h1[id^="year-"]:first-of-type { margin-top: 0; }
/* notes above the first year */
.page-publications .archive > p { max-width: 76ch; margin: 0 0 28px; font-size: 15px; line-height: 1.6; color: var(--ink-3); }
.page-publications .archive > p:has(> span[id]:first-child) { margin: 0; }
/* a paper's paragraph: authors, venue, links */
.page-publications .archive > h1 ~ p { margin: 0; padding: 0 0 22px; }
.page-publications .archive h3 {
  margin: 0 0 6px;
  padding-top: 20px;
  border-top: 1px solid var(--rule-2);
  font-size: 19px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  scroll-margin-top: 24px;
}
.page-publications .archive h1 + h3 { padding-top: 8px; border-top: 0; }
.publication-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 16px;
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-3);
}
.publication-tags span { display: inline-flex; align-items: center; gap: 6px; }
.publication-tags span::before { width: 7px; height: 7px; }
.page-publications .archive > h1 ~ p em { font-style: normal; font-weight: 600; color: var(--ink-2); }
.page-publications .archive > h1 ~ p a {
  padding: 0;
  border-bottom: 0;
  font-weight: 600;
  color: var(--accent);
}
.page-publications .archive > h1 ~ p a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 3px; }
.page-publications .archive small { font-size: 14px; color: var(--ink-3); }

/* ========================================================
   Research pages: one reading column
   ======================================================== */
.ar-page {
  max-width: calc(760px + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter) 96px;
}
.ar-head, .ar-main { min-width: 0; }
.ar-crumb {
  margin: 40px 0 36px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-3);
}
.ar-crumb p, .ar-eyebrow p, .ar-meta p { margin: 0; }
.ar-crumb a { transition: color 0.15s; }
.ar-crumb a:hover { color: var(--accent); }
.ar-eyebrow {
  margin-bottom: 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
}
.ar-eyebrow a { display: inline-flex; align-items: center; gap: 8px; transition: color 0.15s; }
.ar-eyebrow a:hover { color: var(--accent); }
.ar-head h1 {
  margin: 0;
  font-size: clamp(32px, 4.4vw, 44px);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
/* pages without a back link open on the title */
.ar-head > h1:first-child { margin-top: clamp(40px, 6vw, 72px); }
/* venue and links under the title */
.ar-meta {
  margin-top: 22px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-3);
}
.ar-meta em { font-style: normal; font-weight: 600; color: var(--ink-2); }
.ar-meta strong { font-weight: 600; color: var(--ink); }
.ar-meta a { font-weight: 600; color: var(--accent); transition: color 0.15s; }
.ar-meta a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 3px; }

.ar-main { margin-top: 36px; }
.ar-main p {
  margin: 0 0 20px;
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink-2);
}
.ar-main ul, .ar-main ol { margin: 0 0 20px; padding-left: 1.3em; font-size: 17px; line-height: 1.65; color: var(--ink-2); }
.ar-main li { margin-bottom: 6px; }
.ar-main h2 {
  margin: clamp(48px, 7vw, 72px) 0 16px;
  font-size: clamp(25px, 2.4vw, 30px);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  scroll-margin-top: 24px;
}
.ar-main h3 { margin: 32px 0 12px; font-size: 21px; font-weight: 600; line-height: 1.3; letter-spacing: -0.01em; }
.ar-main > :first-child { margin-top: 0; }
.ar-main > :last-child { margin-bottom: 0; }
.ar-main strong { font-weight: 600; color: var(--ink); }
.ar-main code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--paper-3);
  font-family: var(--font-mono);
  font-size: 0.86em;
}
.ar-main pre {
  margin: 0 0 20px;
  padding: 14px 16px;
  border-radius: 8px;
  background: var(--paper-3);
  font-size: 14px;
  line-height: 1.6;
  overflow-x: auto;
}
.ar-main pre code { padding: 0; border-radius: 0; background: none; font-size: inherit; }

/* Figures: a white tile with a hairline; the image opens in the lightbox */
.research-figure { margin: 36px 0; }
.research-figure > a {
  display: block;
  padding: 14px;
  border: 1px solid var(--rule-2);
  border-radius: 8px;
  background: #fff;
  transition: border-color 0.15s;
}
.research-figure > a:hover { border-color: var(--rule); }
.js .research-figure > a[data-zoom] { cursor: zoom-in; }
.research-figure img { display: block; width: 100%; height: auto; }
.research-figure figcaption {
  margin-top: 10px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-3);
}
@media (max-width: 600px) {
  .ar-crumb { margin: 24px 0 28px; }
  .ar-main p, .ar-main ul, .ar-main ol { font-size: 16px; line-height: 1.6; }
  .ar-main h3 { font-size: 19px; }
  .research-figure > a { padding: 8px; }
}

/* Lightbox (site.js) */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  background: rgba(31, 36, 35, 0.95);
}
.lightbox.open { display: flex; }
.lightbox-img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 140px);
  object-fit: contain;
  border-radius: 4px;
  background: #fff;
}
.lightbox-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18px;
  padding: 0 24px;
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
  color: var(--deep-ink);
}
.lightbox-close {
  position: absolute;
  top: 14px;
  right: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--deep-ink);
  font-family: inherit;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.12); }
.lightbox-close:focus-visible { outline-color: #fff; }

/* ========================================================
   Polish: wrapping, Chinese copy, motion, print
   ======================================================== */
.hero-name, .sec-title, .page-hero h1, .post-title, .work-title, .archive__item-title, .ar-main h2 { text-wrap: balance; }
.hero-bio p, .lede, .archive p, .post-desc, .work-desc, .log li > span, .ar-main p { text-wrap: pretty; }

/* Chinese sets a little looser and without negative tracking */
:lang(zh) :is(.hero-name, .sec-title, .page-hero h1, .ar-head h1, .work-title, .post-title, .archive__item-title, .archive h2, .archive h3, .ar-main h2, .ar-main h3) { letter-spacing: 0; }
:lang(zh) :is(.hero-bio, .ar-main p, .archive p) { line-height: 1.8; }
:lang(zh) :is(.work-desc, .post-desc, .log li, .archive__item-excerpt, .note) { line-height: 1.7; }
:lang(zh) :is(.hero-name, .page-hero h1, .ar-head h1) { line-height: 1.25; }

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

@media print {
  body { display: block; min-height: 0; }
  .log.is-collapsed {
    max-height: none !important;
    -webkit-mask-image: none !important;
            mask-image: none !important;
  }
  header.topbar, footer.foot, .skip-link, .toc, .log-toggle, .sec-more, .dock, .lightbox { display: none !important; }
  .with-toc { display: block; }
  .work, .research-figure, .entries li { break-inside: avoid; }
  .sec-title, .ar-main h2, .archive h2, .archive h3 { break-after: avoid; }
}

/* ========================================================
   Blog posts
   Posts carry their own sheet (ar-drift.css, lastkv-rl.css), written on top of the previous theme's base rules.
   These zero-specificity rules restate the ones the posts lean on; the posts' own rules still win.
   ======================================================== */
:where(.drift-prose) a { text-decoration: underline; }
:where(.drift-prose) :is(h1, h2, h3, h4, h5, h6) { margin: 2em 0 0.5em; line-height: 1.2; font-weight: bold; }
:where(.drift-prose) p { margin: 0 0 1.3em; }
:where(.drift-prose) :is(ul, ol) li { margin-bottom: 0.5em; }
:where(.drift-prose) li :is(ul, ol) { margin-top: 0.5em; }
:where(.drift-prose) img { vertical-align: middle; border: 0; }
:where(.drift-prose) :is(sub, sup) { position: relative; font-size: 75%; line-height: 0; vertical-align: baseline; }
:where(.drift-prose) sup { top: -0.5em; }
:where(.drift-prose) sub { bottom: -0.25em; }
:where(.drift-prose) blockquote { margin: 2em 1em 2em 0; padding: 0 1em; border-left: 0.25em solid var(--rule); font-style: italic; }
:where(.drift-prose) hr { display: block; margin: 1em 0; border: 0; border-top: 1px solid var(--rule); }
:where(.drift-prose) pre { overflow-x: auto; }
:where(.drift-prose) figure { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; margin: 2em 0; }
:where(.drift-prose) figure img { width: 100%; margin-bottom: 1em; }
:where(.drift-prose) figcaption { margin-bottom: 0.5em; font-size: smaller; }
:where(.drift-prose) nav li { list-style: none; }
:where(.drift-prose) nav a { text-decoration: none; }
:where(.drift-prose) table {
  width: 100%;
  margin-bottom: 1em;
  font-family: -apple-system, ".SFNSText-Regular", "San Francisco", "Roboto", "Segoe UI", "Helvetica Neue", "Lucida Grande", Arial, sans-serif;
  border-collapse: collapse;
  border: 1px solid #bdc1c4;
}
:where(.drift-prose) thead { background-color: #f2f3f3; border-bottom: 1px solid #bdc1c4; }
:where(.drift-prose) :is(th, td) { border-right: 1px solid #bdc1c4; }
:where(.drift-prose) label { margin-bottom: 0.25em; cursor: pointer; }
:where(.drift-prose) input {
  font-family: -apple-system, ".SFNSText-Regular", "San Francisco", "Roboto", "Segoe UI", "Helvetica Neue", "Lucida Grande", Arial, sans-serif;
  font-size: 100%;
  color: #494e52;
  border-radius: 4px;
}
:where(.drift-prose) :is(p, pre, blockquote, ul, ol, dl, figure, table) { orphans: 3; widows: 3; }
:where(.drift-prose) :is(b, i, strong, em, blockquote, p, q, span, figure, img, h1, h2, header, input, a, tr, td) { transition: all 0.2s ease-in-out; }
:where(.drift-article) { text-rendering: auto; }
