/* Layout concept: every page opens under a dark spectrogram band (the input a detector reads);
   content sits in one reading column with mono "margin labels" carrying units and dates. */
:root {
  --paper: #f4f5f8;
  --surface: #ffffff;
  --ink: #16171d;
  --muted: #5a5e6c;
  --line: #dcdee6;
  --accent: #b0245e;      /* magma crimson, taken from the spectrogram colormap */
  --accent-soft: #f7e6ed;
  --band: #0c0916;        /* spectrogram ground: dark in both themes on purpose */
  --band-text: #c9c3d8;
  --figure-bg: #ffffff;
  --display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", sans-serif;
  --body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f1016; --surface: #171923; --ink: #eceef3; --muted: #a2a6b6;
    --line: #2a2d3b; --accent: #f27ba4; --accent-soft: #2a1a24;
    --band: #07050e; --band-text: #b9b3c9; --figure-bg: #f4f5f8;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0f1016; --surface: #171923; --ink: #eceef3; --muted: #a2a6b6;
  --line: #2a2d3b; --accent: #f27ba4; --accent-soft: #2a1a24;
  --band: #07050e; --band-text: #b9b3c9; --figure-bg: #f4f5f8;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 17px/1.65 var(--body);
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

.wrap {
  max-width: 820px; margin: 0 auto;
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
}

/* ---------- top bar ---------- */
.topbar { background: var(--band); color: var(--band-text); }
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; padding-block: 14px; }
.brand { font: 600 1rem/1.2 var(--display); color: #fff; text-decoration: none; letter-spacing: .01em; }
.nav { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 0; padding: 0; list-style: none; }
.nav a {
  color: var(--band-text); text-decoration: none; font: 500 .8rem/1 var(--mono);
  letter-spacing: .08em; text-transform: uppercase; padding: 6px 0; border-bottom: 2px solid transparent;
}
.nav a:hover { color: #fff; }
.nav a[aria-current="page"] { color: #fff; border-bottom-color: #f27ba4; }

/* ---------- spectrogram band ---------- */
.band { background: var(--band); position: relative; }
.band canvas { display: block; width: 100%; height: 190px; }
.band.slim canvas { height: 56px; }
.band .axis {
  position: absolute; font: 400 .68rem/1 var(--mono); color: rgba(255,255,255,.62);
  letter-spacing: .06em; pointer-events: none;
}
.axis.tl { top: 10px; left: max(20px, env(safe-area-inset-left, 0px)); }
.axis.bl { bottom: 10px; left: max(20px, env(safe-area-inset-left, 0px)); }
.axis.br { bottom: 10px; right: max(20px, env(safe-area-inset-right, 0px)); }
.band-caption {
  background: var(--band); color: var(--band-text); font: 400 .78rem/1.5 var(--mono);
  border-top: 1px solid rgba(255,255,255,.08);
}
.band-caption .wrap { padding-block: 10px 14px; }

/* ---------- type ---------- */
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.12; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(2.3rem, 6vw, 3.6rem); letter-spacing: -.02em; font-weight: 700; }
h2 { font-size: 1.65rem; letter-spacing: -.01em; }
h3 { font-size: 1.3rem; }
p { margin: 0; }
.label {
  font: 500 .74rem/1.3 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
}
.lede { font-size: 1.12rem; color: var(--ink); }
.muted { color: var(--muted); }

main { padding-block: 48px 40px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
section + section { margin-top: 64px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: 22px; }

/* ---------- home intro ---------- */
.intro { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 32px; align-items: start; }
.portrait { width: 200px; aspect-ratio: 1; border-radius: 6px; overflow: hidden; background: var(--line); max-width: 100%; }
.portrait img { width: 100%; height: 100%; object-fit: cover; filter: saturate(.92); }
.role { font: 500 .95rem/1.5 var(--body); color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; padding: 0; list-style: none; }
.chips a, .chips span {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 500 .88rem/1 var(--body); text-decoration: none;
}
.chips a:hover { border-color: var(--accent); color: var(--accent); }
.chips .mono { font-family: var(--mono); font-size: .82rem; }

/* three questions */
.questions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; border-top: 2px solid var(--ink); }
.q { padding: 18px 20px 4px 0; }
.q + .q { padding-left: 20px; border-left: 1px solid var(--line); }
.q .label { color: var(--accent); }
.q p { font: 600 1.12rem/1.3 var(--display); margin-top: 8px; }

/* entries (research teasers, education) */
.entry { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 6px 24px; padding: 18px 0; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.entry .when { font: 400 .82rem/1.6 var(--mono); color: var(--muted); padding-top: 3px; }
.entry h3 { font-size: 1.15rem; margin-bottom: 6px; }
.entry h3 a { color: var(--ink); text-decoration: none; }
.entry h3 a:hover { color: var(--accent); }
.entry .num { font: 600 .9rem var(--mono); color: var(--accent); }

/* ---------- research articles ---------- */
.project { scroll-margin-top: 24px; }
.project + .project { margin-top: 80px; padding-top: 48px; border-top: 2px solid var(--ink); }
.project .meta { font: 400 .82rem/1.6 var(--mono); color: var(--muted); margin-top: 10px; }
.finding { font: 500 1.3rem/1.4 var(--display); margin-top: 18px; letter-spacing: -.005em; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; margin-top: 26px; border-block: 1px solid var(--line); }
.stat { padding: 16px 16px 16px 0; }
.stat + .stat { padding-left: 16px; border-left: 1px solid var(--line); }
.stat b { display: block; font: 600 2rem/1 var(--mono); color: var(--accent); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat span { display: block; margin-top: 8px; font-size: .9rem; color: var(--muted); line-height: 1.45; }
figure { margin: 30px 0 0; }
figure .frame { background: var(--figure-bg); border: 1px solid var(--line); border-radius: 6px; padding: 12px; overflow-x: auto; }
figcaption { font: 400 .82rem/1.55 var(--mono); color: var(--muted); margin-top: 10px; }
.points { margin: 26px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 14px; }
.points li { padding-left: 22px; position: relative; }
.points li::before { content: ""; position: absolute; left: 0; top: .62em; width: 10px; height: 2px; background: var(--accent); }
.points b { font-weight: 600; }
.repo-links { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-top: 26px; font: 500 .92rem/1.4 var(--body); }
.note { font-size: .9rem; color: var(--muted); margin-top: 20px; }

/* svg chart */
.chart svg { width: 100%; min-width: 520px; height: auto; display: block; }
.chart .frame { background: var(--surface); }
.chart text { font-family: var(--mono); fill: var(--ink); }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .bar { fill: var(--muted); opacity: .45; }
.chart .bar.real { fill: var(--ink); opacity: .85; }
.chart .bar.fake { fill: var(--accent); opacity: 1; }

/* ---------- music ---------- */
.tracks { border-top: 2px solid var(--ink); }
.track { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 4px 18px; align-items: baseline; padding: 18px 0; border-bottom: 1px solid var(--line); }
.track .no { font: 500 .85rem var(--mono); color: var(--muted); }
.track h3 { font-size: 1.15rem; }
.track .yr { font: 400 .85rem var(--mono); color: var(--muted); }
.track p { grid-column: 2 / -1; color: var(--muted); font-size: .95rem; }
.empty { border: 1px dashed var(--line); border-radius: 6px; padding: 28px; text-align: center; color: var(--muted); background: var(--surface); }

/* ---------- cv ---------- */
.cv-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.button {
  display: inline-flex; align-items: center; gap: 8px; padding: 11px 18px; border-radius: 6px;
  background: var(--ink); color: var(--paper); font: 600 .92rem/1 var(--body); text-decoration: none;
}
.button:hover { background: var(--accent); color: #fff; }
.button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.button.ghost:hover { border-color: var(--accent); color: var(--accent); background: transparent; }
.cv-entry { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 4px 24px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.cv-entry:last-child { border-bottom: 0; }
.cv-entry .when { font: 400 .82rem/1.6 var(--mono); color: var(--muted); padding-top: 3px; }
.cv-entry h3 { font-size: 1.08rem; font-family: var(--body); font-weight: 600; }
.cv-entry p { color: var(--muted); font-size: .95rem; }

/* ---------- footer ---------- */
footer { border-top: 1px solid var(--line); }
footer .wrap { padding-block: 22px 40px; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px 20px;
  font: 400 .8rem/1.5 var(--mono); color: var(--muted); }
footer a { color: var(--muted); }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  body { font-size: 16px; }
  main { padding-block: 32px 28px; }
  .intro { grid-template-columns: 1fr; gap: 22px; }
  .portrait { width: 132px; }
  .questions { grid-template-columns: 1fr; }
  .q, .q + .q { padding: 14px 0; border-left: 0; }
  .q + .q { border-top: 1px solid var(--line); }
  .entry, .cv-entry { grid-template-columns: 1fr; gap: 2px; }
  .stats { grid-template-columns: 1fr; }
  .stat, .stat + .stat { padding: 14px 0; border-left: 0; }
  .stat + .stat { border-top: 1px solid var(--line); }
  .band canvas { height: 140px; }
  .track { grid-template-columns: 40px minmax(0, 1fr); }
  .track .yr { grid-column: 2; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

/* ---------- music works ---------- */
.work { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.video { position: relative; aspect-ratio: 16 / 9; max-width: 100%; background: var(--band); border-radius: 6px; overflow: hidden; }
.video iframe, .video-play, .video-play img { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-play { padding: 0; cursor: pointer; background: var(--band); }
.video-play img { object-fit: cover; opacity: .9; transition: opacity .2s; }
.video-play:hover img { opacity: 1; }
.play-icon { position: absolute; left: 50%; top: 50%; width: 68px; height: 48px; transform: translate(-50%, -50%);
  background: var(--accent); border-radius: 12px; }
.play-icon::after { content: ""; position: absolute; left: 27px; top: 14px; border-style: solid; border-width: 10px 0 10px 17px;
  border-color: transparent transparent transparent #fff; }
.work-text { display: flex; flex-direction: column; gap: 8px; }
.role-tag { font: 500 .74rem/1.3 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
@media (max-width: 640px) { .work { grid-template-columns: 1fr; gap: 14px; } }

/* ---------- audio players ---------- */
.player { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 16px; align-items: center; padding: 18px 0; border-bottom: 1px solid var(--line); }
.pp { width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); cursor: pointer; display: grid; place-items: center; padding: 0; }
.pp:hover { border-color: var(--accent); }
.pp-icon { width: 0; height: 0; border-style: solid; border-width: 9px 0 9px 15px; border-color: transparent transparent transparent var(--ink); margin-left: 4px; }
.player.playing .pp { background: var(--accent); border-color: var(--accent); }
.player.playing .pp-icon { width: 14px; height: 18px; border: 0; margin: 0; border-left: 4px solid #fff; border-right: 4px solid #fff; }
.player-main { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.player-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.player-head h3 { font-size: 1.12rem; }
.player-head .en { font-family: var(--body); font-weight: 400; color: var(--muted); font-size: .95rem; margin-left: 6px; }
.player-head .yr { font: 400 .82rem var(--mono); color: var(--muted); white-space: nowrap; }
.wave { height: 40px; cursor: pointer; position: relative; border-radius: 3px; }
.wave canvas { width: 100%; height: 100%; display: block; }
.wave:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.times { display: flex; justify-content: space-between; font: 400 .74rem var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .player { grid-template-columns: 44px minmax(0, 1fr); gap: 12px; } .pp { width: 44px; height: 44px; } .player-head .en { display: block; margin-left: 0; } }

/* ---------- language switch + Chinese pages ---------- */
.lang-switch { order: 3; color: var(--band-text); text-decoration: none; font: 500 .8rem/1 var(--mono);
  border: 1px solid rgba(255,255,255,.28); border-radius: 999px; padding: 6px 12px; }
.lang-switch:hover { color: #fff; border-color: #f27ba4; }
.topbar nav { order: 2; margin-left: auto; }
@media (max-width: 640px) {
  .lang-switch { order: 2; margin-left: auto; }
  .topbar nav { order: 3; width: 100%; margin-left: 0; }
}
html[lang="zh-CN"] {
  --display: "Bricolage Grotesque", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --body: "IBM Plex Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --mono: "IBM Plex Mono", "PingFang SC", "Microsoft YaHei", ui-monospace, Menlo, Consolas, monospace;
}
html[lang="zh-CN"] body { line-height: 1.8; }
html[lang="zh-CN"] h1 { letter-spacing: 0; }
html[lang="zh-CN"] .label, html[lang="zh-CN"] .role-tag { letter-spacing: .06em; }
.name-en { display: block; font: 500 1.05rem/1.4 var(--body); color: var(--muted); margin-top: 6px; letter-spacing: 0; }

/* Without the script, each track falls back to the browser's own audio controls. */
.player .native { width: 100%; height: 40px; }
.player:not(.enhanced) .pp, .player:not(.enhanced) .wave, .player:not(.enhanced) .times { display: none; }
.player:not(.enhanced) { grid-template-columns: minmax(0, 1fr); }
.player.enhanced .native { display: none; }
