/* ==========================================================================
   chenxuanqi.com — v2
   Editorial academic system. Tokens first, then layout, then components.
   ========================================================================== */

:root {
  /* Surfaces */
  --paper: #f4f2ed;
  --paper-2: #ebe8e0;
  --paper-3: #e2ded4;
  --card: #fbfaf7;
  /* Ink */
  --ink: #111318;
  --ink-2: #464a53;
  --ink-3: #82858c;
  --rule: rgba(17, 19, 24, .12);
  --rule-strong: rgba(17, 19, 24, .28);
  /* Material colors (used by figures too) */
  --si: #5d6f9a;          /* silicon tier */
  --si-deep: #3b4a6e;
  --cu: #b86d36;          /* copper interconnect */
  --cu-deep: #8a4d22;
  --ox: #13867c;          /* oxide semiconductor tier — primary accent */
  --ox-soft: rgba(19, 134, 124, .12);
  --h: #e0533f;           /* hydrogen */
  --el: #2f62d8;          /* electrons */
  --fl: #8b4fd8;          /* fluorine */
  --accent: var(--ox);
  --accent-ink: #0d6159;
  /* Type */
  --serif: "Newsreader", "Noto Serif SC", "Source Han Serif SC", "Songti SC", Georgia, serif;
  --serif-zh: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "Newsreader", serif;
  --sans: "Inter Tight", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  /* Rhythm */
  --gutter: clamp(16px, 4vw, 56px);
  --max: 1320px;
  --radius: 4px;
  --ease: cubic-bezier(.2, .7, .1, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0c0e11;
    --paper-2: #13161b;
    --paper-3: #1b1f26;
    --card: #111418;
    --ink: #ebe8e1;
    --ink-2: #a9abb0;
    --ink-3: #6e7178;
    --rule: rgba(235, 232, 225, .11);
    --rule-strong: rgba(235, 232, 225, .26);
    --si: #7f93c4;
    --si-deep: #4c5d88;
    --cu: #d48a52;
    --cu-deep: #a3643a;
    --ox: #3cc4b5;
    --ox-soft: rgba(60, 196, 181, .13);
    --h: #ff6b57;
    --el: #5b8cff;
    --fl: #b07cff;
    --accent-ink: #5fd6c8;
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 84px; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.6 var(--sans);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
/* subtle paper grain */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .5;
  background-image: radial-gradient(var(--rule) .6px, transparent .6px);
  background-size: 22px 22px;
  mask-image: linear-gradient(to bottom, #000 0, transparent 900px);
  -webkit-mask-image: linear-gradient(to bottom, #000 0, transparent 900px);
}
main, footer, header { position: relative; z-index: 1; }
a { color: inherit; text-decoration: none; }
img, svg, canvas { display: block; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 400; }
p { margin: 0; }
sub { font-size: .7em; line-height: 0; }
::selection { background: var(--ox); color: var(--paper); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

/* Bilingual switching */
html[data-lang="zh"] .en, html[data-lang="en"] .zh { display: none !important; }
html[data-lang="zh"] h1, html[data-lang="zh"] h2, html[data-lang="zh"] h3 { font-family: var(--serif-zh); }

.skip { position: absolute; left: -9999px; top: 8px; z-index: 100; background: var(--ink); color: var(--paper); padding: 8px 14px; }
.skip:focus { left: 8px; }

/* ---------- Masthead ---------- */
.masthead {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color .3s var(--ease);
}
.masthead.is-scrolled { border-bottom-color: var(--rule); }
.masthead-inner {
  max-width: calc(var(--max) + 2 * var(--gutter)); margin: 0 auto; padding: 0 var(--gutter);
  height: 64px; display: flex; align-items: center; gap: 32px;
}
/* Kiasu Pulse: a big, always-visible shortcut left of the name */
.kiasu-btn {
  display: inline-flex; align-items: center; gap: 10px; flex: none;
  min-height: 42px; padding: 6px 16px 6px 12px; border-radius: 999px;
  background: var(--ox-soft); border: 1px solid color-mix(in srgb, var(--ox) 45%, transparent); color: var(--ink);
  transition: background .2s, border-color .2s, transform .2s var(--ease);
}
.kiasu-btn:hover { background: color-mix(in srgb, var(--ox) 22%, transparent); border-color: var(--ox); }
.kiasu-btn:active { transform: scale(.97); }
.kiasu-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ox); position: relative; flex: none; }
.kiasu-dot::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 1.5px solid var(--ox); animation: ping 2.4s var(--ease) infinite; }
.kiasu-text { display: grid; line-height: 1.1; }
.kiasu-text b { font: 600 14px/1.15 var(--sans); letter-spacing: -.005em; }
.kiasu-text small { font-size: 11px; color: var(--ink-2); }
.mark { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.mark svg { width: 22px; height: 22px; }
.mark svg rect:nth-child(1) { fill: var(--si); }
.mark svg rect:nth-child(2) { fill: var(--cu); }
.mark svg rect:nth-child(3) { fill: var(--ox); }
.mark-name { font: 500 15px/1 var(--sans); letter-spacing: -.01em; }
.mark-zh { font: 400 13px/1 var(--serif-zh); color: var(--ink-3); letter-spacing: .12em; }
.primary { display: flex; gap: 28px; margin-left: auto; }
.primary a { font-size: 13.5px; color: var(--ink-2); position: relative; padding: 6px 0; transition: color .2s; }
.primary a::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: currentColor;
  transform: scaleX(0); transform-origin: left; transition: transform .35s var(--ease);
}
.primary a:hover, .primary a.is-active { color: var(--ink); }
.primary a:hover::after, .primary a.is-active::after { transform: scaleX(1); }
.masthead-tools { display: flex; align-items: center; gap: 14px; }
.more { position: relative; }
.more summary {
  list-style: none; cursor: pointer; font-size: 13px; color: var(--ink-2); white-space: nowrap;
  padding: 6px 10px; border: 1px solid var(--rule); border-radius: 999px;
}
.more summary::-webkit-details-marker { display: none; }
.more summary::after { content: " +"; color: var(--ink-3); }
.more[open] summary::after { content: " −"; }
.more-menu {
  position: absolute; right: 0; top: calc(100% + 10px); width: 260px;
  background: var(--card); border: 1px solid var(--rule); border-radius: 6px;
  box-shadow: 0 18px 40px -18px rgba(0,0,0,.25); padding: 6px;
}
.more-menu a { display: grid; gap: 2px; padding: 10px 12px; border-radius: 4px; font-size: 12.5px; color: var(--ink-3); }
.more-menu a b { font-weight: 500; font-size: 13.5px; color: var(--ink); }
.more-menu a:hover { background: var(--paper-2); }
.lang { display: flex; border: 1px solid var(--rule); border-radius: 999px; padding: 2px; }
.lang button { font: 500 12px/1 var(--sans); padding: 6px 10px; border-radius: 999px; color: var(--ink-3); transition: background .2s, color .2s; }
.lang button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; }
.progress i { display: block; height: 100%; width: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; }

/* ---------- Shared section scaffolding ---------- */
section { padding: 0 var(--gutter); }
.section-head {
  max-width: var(--max); margin: 0 auto 56px; display: grid;
  grid-template-columns: 120px 1fr auto; gap: 24px; align-items: end;
  padding-top: 28px; border-top: 1px solid var(--rule-strong);
}
.section-no { font: 500 12px/1 var(--mono); color: var(--ink-3); letter-spacing: .04em; align-self: start; padding-top: 10px; }
.section-head h2 { font: 300 clamp(34px, 4.6vw, 64px)/1.04 var(--serif); letter-spacing: -.025em; }
html[data-lang="zh"] .section-head h2 { font-weight: 400; letter-spacing: 0; line-height: 1.22; font-size: clamp(30px, 4vw, 54px); }
.section-sub { font-size: 14px; color: var(--ink-3); max-width: 300px; text-align: right; }
.section-sub a { color: var(--ink-2); border-bottom: 1px solid var(--rule-strong); transition: color .2s, border-color .2s; }
.section-sub a:hover { color: var(--accent-ink); border-color: var(--accent); }

.figure-frame { position: relative; border: 1px solid var(--rule); background: var(--card); border-radius: var(--radius); }
.corner { position: absolute; width: 9px; height: 9px; border-color: var(--ink-2); border-style: solid; border-width: 0; }
.corner.tl { top: -1px; left: -1px; border-top-width: 1px; border-left-width: 1px; }
.corner.tr { top: -1px; right: -1px; border-top-width: 1px; border-right-width: 1px; }
.corner.bl { bottom: -1px; left: -1px; border-bottom-width: 1px; border-left-width: 1px; }
.corner.br { bottom: -1px; right: -1px; border-bottom-width: 1px; border-right-width: 1px; }
.figure-head, .figure-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px; font: 400 11px/1 var(--mono); color: var(--ink-3); letter-spacing: .03em;
}
.figure-head { border-bottom: 1px solid var(--rule); }
.figure-foot { border-top: 1px solid var(--rule); }
.fig-no { color: var(--ink); font-weight: 500; }
.fig-tag { text-transform: uppercase; }
html[data-lang="zh"] .fig-tag { text-transform: none; }
figcaption { margin-top: 14px; font-size: 13px; line-height: 1.55; color: var(--ink-2); max-width: 62ch; }
figcaption b { font: 500 12px var(--mono); color: var(--ink); margin-right: 6px; }

/* ---------- Hero ---------- */
.hero { padding-top: clamp(40px, 7vw, 96px); padding-bottom: 64px; }
.hero-grid {
  max-width: var(--max); margin: 0 auto; display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr); gap: clamp(32px, 5vw, 80px); align-items: center;
}
.eyebrow { display: flex; align-items: center; gap: 10px; font: 400 12px/1.4 var(--mono); color: var(--ink-2); letter-spacing: .02em; }
.eyebrow .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--ox-soft); flex: none; }
.hero h1 { margin: 28px 0 32px; }
.h1-name {
  display: block; font: 300 clamp(56px, 8.6vw, 132px)/.92 var(--serif);
  letter-spacing: -.045em; font-variation-settings: "opsz" 72;
}
.h1-zh {
  display: block; margin-top: 18px; font: 400 clamp(20px, 2.1vw, 28px)/1 var(--serif-zh);
  letter-spacing: .5em; color: var(--ink-3);
}
.hero-lede { font: 300 clamp(19px, 1.65vw, 23px)/1.5 var(--serif); color: var(--ink-2); max-width: 30em; }
html[data-lang="zh"] .hero-lede { font-family: var(--serif-zh); font-weight: 400; font-size: clamp(17px, 1.45vw, 20px); line-height: 1.85; }
.hero-lede em { font-style: italic; color: var(--ink); }
html[data-lang="zh"] .hero-lede em { font-style: normal; color: var(--ink); background: linear-gradient(transparent 62%, var(--ox-soft) 62%); }
.hero-facts { margin: 36px 0 0; display: grid; gap: 0; border-top: 1px solid var(--rule); max-width: 520px; }
.hero-facts > div { display: grid; grid-template-columns: 88px 1fr; padding: 11px 0; border-bottom: 1px solid var(--rule); font-size: 14px; }
.hero-facts dt { font: 400 11px/1.9 var(--mono); color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.hero-facts dd { margin: 0; color: var(--ink); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 36px; }
.btn {
  display: inline-flex; align-items: center; gap: 12px; height: 46px; padding: 0 20px;
  font: 500 14px/1 var(--sans); border-radius: 999px; transition: background .25s, color .25s, border-color .25s, transform .25s var(--ease);
}
.btn .arrow { transition: transform .3s var(--ease); }
.btn:hover .arrow { transform: translateX(3px); }
.btn-solid { background: var(--ink); color: var(--paper); }
.btn-solid:hover { background: var(--accent-ink); }
.btn-line { border: 1px solid var(--rule-strong); }
.btn-line:hover { border-color: var(--ink); }

.hero-figure { margin: 0; }
.stack-stage { position: relative; aspect-ratio: 1 / .86; overflow: hidden; touch-action: pan-y; }
.stack-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.stack-labels { position: absolute; inset: 0; pointer-events: none; }
.stack-leaders { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.stack-leaders g { opacity: 0; transition: opacity .6s var(--ease); }
.stack-leaders g.is-on { opacity: 1; }
.stack-leaders line { stroke: currentColor; stroke-width: 1; stroke-opacity: .7; }
.stack-leaders circle { fill: currentColor; stroke: var(--card); stroke-width: 1.5; }
.stack-label {
  position: absolute; display: flex; align-items: center; gap: 10px; white-space: nowrap;
  opacity: 0; transition: opacity .6s var(--ease); will-change: transform;
}
.stack-label.is-on { opacity: 1; }
.stack-label i { width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid currentColor; background: var(--card); flex: none; }
.stack-label > span { display: grid; gap: 3px; padding: 7px 10px; background: color-mix(in srgb, var(--card) 88%, transparent); border: 1px solid var(--rule); border-radius: 3px; backdrop-filter: blur(4px); }
.stack-label b { font: 500 12.5px/1.1 var(--sans); color: var(--ink); }
.stack-label small { font: 400 10.5px/1.1 var(--mono); color: var(--ink-3); }
.stack-label[data-stack-label="3"] { color: var(--cu-deep); }
.stack-label[data-stack-label="2"] { color: var(--ox); }
.stack-label[data-stack-label="1"] { color: var(--cu); }
.stack-label[data-stack-label="0"] { color: var(--si); }
.stack-modes { display: inline-flex; padding: 2px; border: 1px solid var(--rule); border-radius: 999px; font-family: var(--sans); }
.stack-modes button { font: 500 12px/1 var(--sans); padding: 7px 12px; border-radius: 999px; color: var(--ink-3); letter-spacing: 0; transition: background .25s, color .25s; }
.stack-modes button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.stack-modes button:not([aria-pressed="true"]):hover { color: var(--ink); }
.stack-modes button[data-stack-mode="focus"][aria-pressed="true"] { background: var(--ox); color: #fff; }
.stack-label.focus { color: var(--ox); }
.stack-label.focus > span { padding: 5px 9px; }
.hint { display: inline-flex; align-items: center; gap: 8px; }
.hint::before { content: ""; width: 14px; height: 14px; border: 1px solid var(--ink-3); border-radius: 50%; box-shadow: inset 0 0 0 3px var(--card), inset 0 0 0 7px var(--ink-3); }

/* News strip */
.news {
  max-width: var(--max); margin: clamp(48px, 6vw, 80px) auto 0;
  display: grid; grid-template-columns: auto auto 1fr auto auto; align-items: center; gap: 22px;
  padding: 18px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.news-badge { display: inline-flex; align-items: center; gap: 8px; font: 500 11px/1 var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--accent-ink); }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); position: relative; }
.pulse::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 1px solid var(--accent); animation: ping 2.4s var(--ease) infinite; }
@keyframes ping { 0% { transform: scale(.6); opacity: 1; } 100% { transform: scale(2.2); opacity: 0; } }
.news-venue { font: 500 12px/1 var(--mono); padding: 6px 8px; border: 1px solid var(--rule-strong); border-radius: 3px; }
.news-title { font: 400 19px/1.3 var(--serif); }
html[data-lang="zh"] .news-title { font-family: var(--serif-zh); font-size: 17px; }
.news-title:hover { color: var(--accent-ink); }
.news-meta { font-size: 13px; color: var(--ink-3); }
.news-link { font-size: 13px; color: var(--ink-2); border-bottom: 1px solid var(--rule-strong); }
.news-link:hover { color: var(--accent-ink); border-color: var(--accent); }

/* ---------- Ledger ---------- */
.ledger { padding-top: 0; padding-bottom: clamp(80px, 10vw, 140px); }
.ledger-grid { max-width: var(--max); margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); }
.ledger-item { padding: 28px 24px 8px 0; display: grid; gap: 14px; align-content: start; }
.ledger-item + .ledger-item { padding-left: 24px; border-left: 1px solid var(--rule); }
.ledger-num { font: 300 clamp(36px, 3.6vw, 52px)/1 var(--serif); letter-spacing: -.03em; }
.ledger-text { font-size: 13px; line-height: 1.5; color: var(--ink-3); }

/* ---------- Story (scrollytelling) ---------- */
.story { padding-bottom: clamp(80px, 10vw, 140px); }
.story-body {
  max-width: var(--max); margin: 0 auto; display: grid;
  grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); gap: clamp(32px, 5vw, 80px);
}
.story-steps { display: grid; gap: 0; padding-bottom: 20vh; }
.step {
  min-height: 72vh; display: flex; flex-direction: column; justify-content: center; gap: 18px;
  opacity: .28; transition: opacity .5s var(--ease);
}
.step.is-active { opacity: 1; }
.step-no { font: 500 12px/1 var(--mono); color: var(--accent-ink); letter-spacing: .05em; }
.step h3 { font: 400 clamp(26px, 2.6vw, 36px)/1.15 var(--serif); letter-spacing: -.015em; }
html[data-lang="zh"] .step h3 { font-size: clamp(23px, 2.2vw, 30px); line-height: 1.35; letter-spacing: 0; }
.step p { font-size: 16px; line-height: 1.75; color: var(--ink-2); max-width: 34em; }
.step .step-key { font-size: 13.5px; color: var(--ink-3); padding-left: 14px; border-left: 2px solid var(--accent); }
.step-link { align-self: flex-start; font: 500 12.5px/1 var(--mono); color: var(--ink); padding: 9px 12px; border: 1px solid var(--rule-strong); border-radius: 999px; transition: border-color .2s, color .2s; }
.step-link:hover { border-color: var(--accent); color: var(--accent-ink); }
.story-visual { position: relative; }
.story-figure { position: sticky; top: calc(64px + 4vh); margin: 0; }
.story-canvas-wrap { position: relative; aspect-ratio: 2.3 / 1; border-top: 1px solid var(--rule); }
.story-canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

/* 3D device view */
.dev3d { position: relative; aspect-ratio: 1.75 / 1; max-height: calc(100vh - 64px - 4vh - 320px); min-height: 260px; width: 100%; overflow: hidden; }
.dev3d > canvas, .dev3d-leaders { position: absolute; inset: 0; width: 100%; height: 100%; }
.dev3d-leaders { pointer-events: none; overflow: visible; transition: opacity .35s var(--ease); }
.dev3d-leaders.is-dim { opacity: 0; }
.dev3d-leaders line { stroke: var(--ink); stroke-opacity: .45; stroke-width: 1; }
.dev3d-leaders circle { fill: var(--ink); stroke: var(--card); stroke-width: 1.2; }
.dev3d-leaders text { fill: var(--ink); font-family: var(--sans); font-weight: 500; dominant-baseline: middle; }
html[data-lang="zh"] .dev3d-leaders text { font-family: "PingFang SC", "Microsoft YaHei", var(--sans); }
.dev-hud { position: absolute; left: 14px; top: 12px; display: grid; gap: 8px; justify-items: start; pointer-events: none; }
.dev-cond { font: 400 11.5px/1 var(--mono); padding: 6px 10px; border-radius: 999px; border: 1px solid; transition: opacity .4s; }
.dev-cond[data-kind="h"] { color: var(--h); border-color: color-mix(in srgb, var(--h) 55%, transparent); background: color-mix(in srgb, var(--h) 8%, transparent); }
.dev-cond[data-kind="f"] { color: var(--fl); border-color: color-mix(in srgb, var(--fl) 55%, transparent); background: color-mix(in srgb, var(--fl) 8%, transparent); }
.dev-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); }
.dev-legend span { display: inline-flex; align-items: center; gap: 6px; transition: opacity .4s; }
.dev-legend i { width: 10px; height: 10px; border-radius: 50%; box-shadow: inset -2px -2px 3px rgba(0,0,0,.25), inset 1px 1px 2px rgba(255,255,255,.6); }
.dev-legend [data-k="h"] i { background: #e5493a; }
.dev-legend [data-k="e"] i { background: #2f68d8; }
.dev-legend [data-k="f"] i { background: #8b4fd8; }

/* A–A′ section: a quiet button; hover peeks, click pins, click the inset to put it away */
.xs-toggle {
  position: absolute; right: 12px; bottom: 12px; z-index: 3; display: inline-flex; align-items: center; gap: 7px;
  font: 500 12px/1 var(--sans); padding: 8px 12px 8px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--card) 88%, transparent); border: 1px solid var(--rule-strong); color: var(--ink-2);
  backdrop-filter: blur(6px); transition: opacity .25s, transform .25s var(--ease), border-color .2s, color .2s;
}
.xs-toggle:hover, .xs-toggle:focus-visible { color: var(--ink); border-color: var(--ink); }
.xs-ico { width: 14px; height: 10px; border: 1.3px solid currentColor; border-radius: 2px; position: relative; }
.xs-ico::before { content: ""; position: absolute; left: -3px; right: -3px; top: 50%; border-top: 1.3px dashed currentColor; }
.xs-inset {
  position: absolute; right: 12px; bottom: 12px; z-index: 2; width: min(46%, 380px); aspect-ratio: 1.85 / 1;
  background: #fff; border: 1px solid rgba(17,19,24,.14); border-radius: 6px; box-shadow: 0 18px 40px -18px rgba(0,0,0,.45);
  opacity: 0; transform: translateY(8px) scale(.97); transform-origin: 100% 100%; pointer-events: none;
  transition: opacity .25s var(--ease), transform .3s var(--ease); cursor: zoom-out; outline: none;
}
.xs-inset canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.xs-tag { position: absolute; left: 9px; top: 7px; z-index: 1; font: 600 11px/1 var(--sans); color: #464a53; letter-spacing: .02em; }
.xs-close { position: absolute; right: 8px; top: 5px; z-index: 1; font: 400 15px/1 var(--sans); color: #82858c; opacity: 0; transition: opacity .2s; }
.dev3d.xs-peek .xs-inset { opacity: 1; transform: none; bottom: 52px; }
.dev3d.xs-pinned .xs-inset { opacity: 1; transform: none; pointer-events: auto; }
.dev3d.xs-pinned .xs-close { opacity: 1; }
.dev3d.xs-pinned .xs-toggle { opacity: 0; transform: translateY(6px); pointer-events: none; }
.xs-inset:focus-visible { box-shadow: 0 0 0 2px var(--accent), 0 18px 40px -18px rgba(0,0,0,.45); }
.dev3d.no-webgl > canvas { display: none; }
.story-dots { display: flex; gap: 8px; justify-content: center; padding: 12px; border-top: 1px solid var(--rule); }
.story-dots button { width: 26px; height: 3px; border-radius: 2px; background: var(--rule-strong); transition: background .3s, width .3s var(--ease); }
.story-dots button[aria-current="step"] { background: var(--accent); width: 44px; }
.story-dots button::before { content: ""; display: block; height: 20px; margin-top: -9px; } /* larger hit area */

/* ---------- Research themes ---------- */
.research { padding-bottom: clamp(80px, 10vw, 140px); }
.themes { max-width: var(--max); margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--rule); }
.theme {
  display: flex; flex-direction: column; gap: 18px; padding: 32px 28px 36px 0;
  position: relative;
}
.theme + .theme { padding-left: 28px; border-left: 1px solid var(--rule); }
.theme::before { content: ""; position: absolute; top: -1px; left: 0; height: 2px; width: 0; background: var(--accent); transition: width .6s var(--ease); }
.theme + .theme::before { left: -1px; }
.theme:hover::before { width: 100%; }
.theme-top { display: flex; justify-content: space-between; align-items: center; }
.theme-no { font: 300 44px/1 var(--serif); font-style: italic; color: var(--ink-3); }
.theme-tag { font: 500 11px/1 var(--mono); letter-spacing: .06em; color: var(--ink-2); padding: 6px 8px; background: var(--paper-2); border-radius: 3px; }
.theme h3 { font: 400 26px/1.2 var(--serif); letter-spacing: -.01em; margin-top: 18px; }
html[data-lang="zh"] .theme h3 { font-size: 23px; line-height: 1.4; }
.theme p { font-size: 15px; line-height: 1.7; color: var(--ink-2); }
.methods { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.methods li { font-size: 12px; color: var(--ink-2); padding: 5px 9px; border: 1px solid var(--rule); border-radius: 999px; }
.theme-link { margin-top: auto; padding-top: 14px; display: inline-flex; gap: 8px; font-size: 14px; font-weight: 500; }
.theme-link span[aria-hidden] { transition: transform .3s var(--ease); }
.theme-link:hover { color: var(--accent-ink); }
.theme-link:hover span[aria-hidden] { transform: translate(2px, -2px); }
.collab { max-width: var(--max); margin: 28px auto 0; padding-top: 20px; border-top: 1px solid var(--rule); font-size: 14px; color: var(--ink-3); }
.collab a { color: var(--ink); border-bottom: 1px solid var(--rule-strong); }
.collab a:hover { color: var(--accent-ink); border-color: var(--accent); }

/* ---------- Publications ---------- */
.pubs { padding-bottom: clamp(80px, 10vw, 140px); }
.pub-filters { max-width: var(--max); margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.pub-filters button {
  display: inline-flex; align-items: center; gap: 8px; font-size: 13px; padding: 7px 12px;
  border: 1px solid var(--rule); border-radius: 999px; color: var(--ink-2); transition: all .2s;
}
.pub-filters button i { font: 500 10.5px/1 var(--mono); font-style: normal; color: var(--ink-3); }
.pub-filters button:hover { border-color: var(--rule-strong); color: var(--ink); }
.pub-filters button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.pub-filters button[aria-pressed="true"] i { color: var(--paper); opacity: .6; }
.pub-list { list-style: none; padding: 0; max-width: var(--max); margin: 0 auto; }
.pub {
  display: grid; grid-template-columns: 150px minmax(0, 1fr) 110px; gap: 28px; align-items: start;
  padding: 28px 0; border-bottom: 1px solid var(--rule); position: relative;
  transition: opacity .35s var(--ease);
}
.pub::after { content: ""; position: absolute; inset: 0 calc(var(--gutter) * -0.5); background: var(--paper-2); opacity: 0; z-index: -1; border-radius: 4px; transition: opacity .3s; }
.pub:hover::after { opacity: .55; }
.pub.is-hidden { display: none; }
.pub-when { display: grid; gap: 8px; }
.pub-year { font: 300 30px/1 var(--serif); letter-spacing: -.02em; }
.pub-venue { font: 500 11.5px/1 var(--mono); color: var(--accent-ink); letter-spacing: .03em; }
.pub-main h3 { font: 400 20px/1.38 var(--serif); letter-spacing: -.005em; }
html[data-lang="zh"] .pub-main h3 span.zh { font-family: var(--serif-zh); font-size: 18.5px; }
.pub-main h3 a { background: linear-gradient(currentColor, currentColor) 0 100% / 0 1px no-repeat; transition: background-size .45s var(--ease); }
.pub-main h3 a:hover { background-size: 100% 1px; }
.pub-note { margin-top: 8px; font-size: 14px; color: var(--ink-2); }
.pub-authors { margin-top: 10px; font-size: 13px; color: var(--ink-3); display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.pub-authors b { color: var(--ink); font-weight: 600; }
.role { font: 500 10.5px/1 var(--mono); text-transform: uppercase; letter-spacing: .05em; color: var(--accent-ink); padding: 4px 7px; border-radius: 3px; background: var(--ox-soft); }
html[data-lang="zh"] .role { text-transform: none; letter-spacing: .02em; }
.pub-link { justify-self: end; font: 500 12px/1 var(--mono); padding: 9px 12px; border: 1px solid var(--rule-strong); border-radius: 999px; white-space: nowrap; transition: all .2s; }
.pub-link:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.footnote { max-width: var(--max); margin: 16px auto 0; font-size: 12.5px; color: var(--ink-3); }

/* ---------- About ---------- */
.about { padding-bottom: clamp(80px, 10vw, 140px); }
.about-grid { max-width: var(--max); margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: clamp(40px, 7vw, 120px); }
.about-copy { display: grid; gap: 22px; align-content: start; }
.about-lead { font: 300 clamp(22px, 2.1vw, 30px)/1.42 var(--serif); letter-spacing: -.01em; }
html[data-lang="zh"] .about-lead { font-family: var(--serif-zh); font-weight: 400; font-size: clamp(19px, 1.8vw, 24px); line-height: 1.75; letter-spacing: 0; }
.about-copy > p:not(.about-lead) { font-size: 15.5px; line-height: 1.8; color: var(--ink-2); max-width: 40em; }
.mini-h { font: 500 11px/1 var(--mono) !important; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin-bottom: 16px !important; }
.toolset { margin-top: 18px; }
.tool-groups { display: grid; border-top: 1px solid var(--rule); }
.tool-groups > div { display: grid; grid-template-columns: 90px 1fr; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.tg-label { font-size: 13px; color: var(--ink-3); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips i { font: 500 12px/1 var(--mono); font-style: normal; padding: 6px 9px; background: var(--paper-2); border-radius: 3px; }
.honors { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
.honor { display: flex; gap: 16px; align-items: flex-start; padding: 18px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--card); }
.honor-year { font: 300 26px/1 var(--serif); color: var(--cu); }
.honor b { display: block; font-weight: 500; font-size: 15px; }
.honor small { display: block; margin-top: 4px; font-size: 12.5px; color: var(--ink-3); }
.timeline ol { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline ol::before { content: ""; position: absolute; left: 5px; top: 8px; bottom: 8px; width: 1px; background: var(--rule-strong); }
.timeline li { position: relative; padding: 0 0 36px 32px; display: grid; gap: 5px; }
.timeline li::before { content: ""; position: absolute; left: 0; top: 5px; width: 11px; height: 11px; border-radius: 50%; background: var(--paper); border: 1px solid var(--ink-2); }
.timeline li.now::before { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 5px var(--ox-soft); }
.timeline time { font: 400 12px/1.4 var(--mono); color: var(--ink-3); }
.timeline b { font: 400 21px/1.3 var(--serif); }
html[data-lang="zh"] .timeline b .zh { font-family: var(--serif-zh); font-size: 19px; }
.timeline li > span { font-size: 14.5px; color: var(--ink-2); }
.timeline small { font-size: 13px; color: var(--accent-ink); }

/* ---------- Contact ---------- */
.contact { background: var(--ink); color: var(--paper); padding-top: clamp(80px, 10vw, 140px); padding-bottom: clamp(80px, 10vw, 140px); position: relative; overflow: hidden; }
.contact::before {
  content: ""; position: absolute; inset: 0; opacity: .5; pointer-events: none;
  background-image: linear-gradient(color-mix(in srgb, var(--paper) 8%, transparent) 1px, transparent 1px), linear-gradient(90deg, color-mix(in srgb, var(--paper) 8%, transparent) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse at 80% 20%, #000, transparent 65%);
  -webkit-mask-image: radial-gradient(ellipse at 80% 20%, #000, transparent 65%);
}
.contact-inner { max-width: var(--max); margin: 0 auto; position: relative; display: grid; gap: 22px; }
.contact .section-no { color: color-mix(in srgb, var(--paper) 50%, transparent); padding: 0; }
.contact h2 { font: 300 clamp(48px, 7vw, 104px)/1 var(--serif); letter-spacing: -.035em; }
html[data-lang="zh"] .contact h2 { font-family: var(--serif-zh); font-weight: 400; letter-spacing: .02em; font-size: clamp(40px, 5.6vw, 80px); }
.contact p { font-size: 16px; color: color-mix(in srgb, var(--paper) 65%, transparent); max-width: 36em; }
.contact-row { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin-top: 18px; }
.contact-mail {
  font: 300 clamp(22px, 3.4vw, 46px)/1.1 var(--serif); letter-spacing: -.01em;
  background: linear-gradient(var(--ox), var(--ox)) 0 100% / 100% 1px no-repeat; padding-bottom: 6px;
  transition: background-size .5s var(--ease), color .3s; word-break: break-all;
}
.contact-mail:hover { color: var(--ox); }
.copy { font: 500 12px/1 var(--mono); padding: 9px 13px; border: 1px solid color-mix(in srgb, var(--paper) 30%, transparent); border-radius: 999px; transition: all .2s; }
.copy:hover { border-color: var(--paper); }
.copy.is-done { background: var(--ox); border-color: var(--ox); color: var(--ink); }
.contact-links { display: flex; flex-wrap: wrap; gap: 28px; margin-top: 30px; padding-top: 24px; border-top: 1px solid color-mix(in srgb, var(--paper) 16%, transparent); font-size: 14px; }
.contact-links a { color: color-mix(in srgb, var(--paper) 75%, transparent); transition: color .2s; }
.contact-links a:hover { color: var(--paper); }
@media (prefers-color-scheme: dark) {
  .contact { background: var(--paper-2); color: var(--ink); border-top: 1px solid var(--rule); }
  .contact .section-no, .contact p, .contact-links a { color: var(--ink-2); }
  .contact-links { border-color: var(--rule); }
  .copy { border-color: var(--rule-strong); }
  .contact::before { background-image: linear-gradient(var(--rule) 1px, transparent 1px), linear-gradient(90deg, var(--rule) 1px, transparent 1px); }
}

/* ---------- Footer ---------- */
.footer {
  max-width: calc(var(--max) + 2 * var(--gutter)); margin: 0 auto; padding: 26px var(--gutter);
  display: flex; justify-content: space-between; gap: 16px; font-size: 12.5px; color: var(--ink-3);
}
.footer a:hover { color: var(--ink); }

/* ---------- Reveal motion ---------- */
.js .reveal { opacity: 0; transform: translateY(18px); transition: opacity 1s var(--ease), transform 1s var(--ease); }
.js .reveal.is-in { opacity: 1; transform: none; }
.js .hero .reveal:nth-child(2) { transition-delay: .08s; }
.js .hero .reveal:nth-child(3) { transition-delay: .16s; }
.js .hero .reveal:nth-child(4) { transition-delay: .24s; }
.js .hero .reveal:nth-child(5) { transition-delay: .32s; }
.js .hero-figure.reveal { transition-delay: .2s; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .js .reveal { opacity: 1; transform: none; transition: none; }
  .pulse::after { animation: none; }
  * { transition-duration: .01ms !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .primary { gap: 18px; }
  .themes { grid-template-columns: 1fr 1fr; }
  .theme:nth-child(3) { grid-column: 1 / -1; border-left: 0; padding-left: 0; border-top: 1px solid var(--rule); }
  .news { grid-template-columns: auto auto 1fr; }
  .news-meta, .news-link { grid-column: 3; }
  .news-meta { margin-top: -14px; }
}
@media (max-width: 1180px) {
  .masthead-inner { gap: 20px; }
  .mark-zh { display: none; }
}
@media (max-width: 900px) {
  .primary { display: none; }
  .masthead-tools { margin-left: auto; }
  .hero-grid { grid-template-columns: 1fr; }
  .section-head { grid-template-columns: 1fr; gap: 14px; }
  .section-no { padding-top: 0; }
  .section-sub { text-align: left; max-width: none; }
  .ledger-grid { grid-template-columns: 1fr 1fr; }
  .ledger-item:nth-child(3) { padding-left: 0; border-left: 0; }
  .ledger-item:nth-child(n+3) { border-top: 1px solid var(--rule); margin-top: 8px; }
  /* story: visual sticks on top, steps scroll beneath */
  .story-body { grid-template-columns: 1fr; gap: 0; }
  .story-visual { order: -1; position: sticky; top: 64px; z-index: 2; background: var(--paper); padding: 10px 0; margin: 0 calc(var(--gutter) * -1); padding-left: var(--gutter); padding-right: var(--gutter); }
  .story-figure { position: static; }
  .story-figure figcaption { display: none; }
  .story-steps { padding-bottom: 10vh; }
  .step { min-height: 62vh; justify-content: flex-start; padding-top: 6vh; }
  .about-grid { grid-template-columns: 1fr; }
  .pub { grid-template-columns: 1fr; gap: 12px; }
  .pub-when { grid-auto-flow: column; justify-content: start; align-items: baseline; gap: 12px; }
  .pub-year { font-size: 22px; }
  .pub-link { justify-self: start; }
}
@media (max-width: 480px) {
  .more { display: none; }             /* Lab Breakout stays reachable from the contact section */
}
@media (max-width: 640px) {
  .mark-zh { display: none; }
  .masthead-inner { gap: 10px; }
  .kiasu-btn { min-height: 44px; padding: 6px 12px 6px 11px; gap: 8px; }
  .kiasu-text b { font-size: 13px; }
  .kiasu-text small { font-size: 10.5px; }
  .mark { gap: 7px; }
  .mark-name { font-size: 14px; }
  .more summary { padding: 6px 9px; }
  .themes { grid-template-columns: 1fr; }
  .theme, .theme + .theme { padding: 28px 0; border-left: 0; }
  .theme + .theme { border-top: 1px solid var(--rule); }
  .theme + .theme::before { left: 0; }
  .news { grid-template-columns: 1fr 1fr; gap: 12px; }
  .news-title { grid-column: 1 / -1; }
  .news-meta, .news-link { grid-column: auto; margin: 0; }
  .news-link { justify-self: end; }
  .honors { grid-template-columns: 1fr; }
  .h1-zh { letter-spacing: .35em; }
  .hero-facts > div { grid-template-columns: 64px 1fr; }
  .stack-label small { display: none; }
  .stack-label > span { padding: 5px 7px; }
  .stack-label b { font-size: 11px; }
  .footer { flex-direction: column; }
  .story-canvas-wrap { aspect-ratio: 2.1 / 1; width: 100%; }
  .dev3d { aspect-ratio: 1.5 / 1; min-height: 0; max-height: 36vh; }
  .dev-legend { font-size: 11px; }
  .xs-inset { width: 62%; }
  .story-figure .figure-head { padding: 9px 12px; font-size: 10px; }
  .story-dots { padding: 8px; }
  .step { min-height: 80vh; padding-top: 0; justify-content: flex-end; padding-bottom: 6vh; }
}
