/* Terminal-style homepage.
   Shell: status bar / explorer + view / command bar. The view pane is a terminal
   screen: every view starts with a prompt line and its output is revealed line by
   line. Selecting another component refreshes the screen instead of stacking. */

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url(../fonts/jetbrains-mono-normal-400-500.woff2) format("woff2");
}

:root {
  --bg: #0f1116;
  --win: #14171e;
  --bar: #191d26;
  --pane: #12151c;
  --raise: #171b24;
  --line: #262b36;
  --line-hi: #3a4252;
  --text: #d5dbe6;
  --bright: #ffffff;
  --dim: #99a2b1;
  --faint: #838b9b;
  --green: #7ee787;
  --blue: #79c0ff;
  --amber: #e3b341;
  --red: #ff7b72;
  --purple: #d2a8ff;
  --flash: rgba(121, 192, 255, .09);
  --sel: rgba(121, 192, 255, .28);
  --lb-bg: rgba(8, 10, 14, .92);
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", monospace;
  --sidebar: 300px;
  --pad: 22px;
}

:root[data-theme="light"] {
  --bg: #f4f6f9;
  --win: #ffffff;
  --bar: #eceff3;
  --pane: #ffffff;
  --raise: #f1f4f8;
  --line: #d5dbe3;
  --line-hi: #b4bdc9;
  --text: #2a313a;
  --bright: #0d1117;
  --dim: #5b6672;
  --faint: #636d7a;
  --green: #1a7f37;
  --blue: #0969da;
  --amber: #9a6700;
  --red: #cf222e;
  --purple: #8250df;
  --flash: rgba(9, 105, 218, .08);
  --sel: rgba(9, 105, 218, .18);
  --lb-bg: rgba(24, 30, 38, .82);
}

* { box-sizing: border-box; }

html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.65 var(--mono);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body.is-locked { overflow: hidden; }

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--sel); color: var(--bright); }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 3px; }

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }

.skip {
  position: absolute; left: 8px; top: -40px; z-index: 200;
  padding: 6px 10px; border-radius: 3px; background: var(--blue); color: var(--bg);
  font-size: 13px; text-decoration: none;
}
.skip:focus { top: 8px; }

.vh {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ── app shell ─────────────────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  min-height: 540px;
}

.workbench {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 0;
}

/* ── status bar ────────────────────────────────────────────────────────── */

.statusbar {
  display: flex; align-items: center; gap: 12px;
  height: 34px; padding: 0 10px;
  background: var(--bar); border-bottom: 1px solid var(--line);
  font-size: 12.5px; white-space: nowrap;
}

.sb-menu {
  display: none; padding: 2px 9px; border: 1px solid var(--line); border-radius: 3px;
  color: var(--dim); font-size: 12px;
}
.sb-menu:hover { border-color: var(--blue); color: var(--text); }

.sb-session {
  padding: 3px 8px; border-radius: 3px;
  background: var(--green); color: var(--bg); font-weight: 500;
}

.sb-cwd { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--dim); }

.sb-right { display: flex; align-items: center; gap: 12px; margin-left: auto; color: var(--dim); }
.sb-spark { display: block; width: 72px; height: 18px; }
.sb-metric { color: var(--blue); font-variant-numeric: tabular-nums; }
.sb-theme {
  padding: 2px 8px; border: 1px solid var(--line); border-radius: 3px;
  color: var(--dim); font-size: 12px;
}
.sb-theme:hover { border-color: var(--blue); color: var(--text); }
.sb-clock { color: var(--text); font-variant-numeric: tabular-nums; }

/* ── panes ─────────────────────────────────────────────────────────────── */

.pane { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--pane); }
.pane--tree { border-right: 1px solid var(--line); }

.pane-title {
  display: flex; align-items: center; gap: 4px 8px; flex: none; flex-wrap: wrap;
  min-height: 26px; padding: 3px 12px;
  border-bottom: 1px solid var(--line); background: var(--win);
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--dim);
}
.pane-title .sub { letter-spacing: 0; text-transform: none; color: var(--faint); }

.pane-foot {
  flex: none; padding: 7px 12px; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--faint);
}
.pane-foot b { font-weight: 400; color: var(--dim); }

/* ── explorer tree ─────────────────────────────────────────────────────── */

.tree { flex: 1; min-height: 0; overflow: auto; padding: 6px 0 12px; scrollbar-width: thin; scrollbar-color: var(--line-hi) transparent; }

.tree a {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 12px; border-left: 2px solid transparent;
  color: var(--text); font-size: 13px; text-decoration: none;
}
.tree a:hover { background: var(--flash); text-decoration: none; }
.tree a[aria-current="true"] { background: var(--flash); border-left-color: var(--blue); color: var(--bright); }
.tree a .dot { flex: none; width: 6px; height: 6px; border-radius: 1px; background: var(--dim); }
.tree a .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree a .tag { margin-left: auto; padding-left: 8px; color: var(--faint); font-size: 11.5px; white-space: nowrap; }
.tree a[aria-current="true"] .tag { color: var(--dim); }

.tree a[data-open^="about"] .dot { background: var(--blue); }
.tree a[data-open^="paper"] .dot { background: var(--amber); }
.tree a[data-open^="projects"] .dot { background: var(--green); }
.tree a[data-open^="contact"] .dot { background: var(--purple); }
.tree a[data-open="pubs"] .dot { background: var(--amber); opacity: .55; }
.tree a[data-open="model"] .dot { background: var(--red); }

.tree .grp > a { padding-left: 12px; color: var(--dim); }
.tree .grp > a .dot { background: none; width: auto; height: auto; border-radius: 0; color: var(--faint); }
.tree .grp .kids a { padding-left: 26px; }

/* ── view pane: a terminal screen ──────────────────────────────────────── */

.view-scroll {
  flex: 1; min-height: 0; overflow: auto;
  padding: var(--pad) 26px 30px;
  scrollbar-width: thin; scrollbar-color: var(--line-hi) transparent;
}

.view { max-width: 1080px; counter-reset: ln; }
.js .view { display: none; }
.js .view.is-active { display: block; }

.view-foot {
  flex: none; display: flex; flex-wrap: wrap; gap: 4px 16px;
  padding: 8px 14px; border-top: 1px solid var(--line); background: var(--win);
  font-size: 11.5px; color: var(--faint);
}
.view-foot a { color: var(--dim); }
.view-foot a:hover { color: var(--blue); }
.view-foot .sp { margin-left: auto; }

/* output lines ------------------------------------------------------------ */

.ln { position: relative; padding-left: 4ch; }

.ln--txt { counter-increment: ln; }
.ln--txt::before {
  content: counter(ln);
  position: absolute; left: 0; top: 0; width: 3ch;
  text-align: right; color: var(--faint); font-size: 11.5px; line-height: 1.65;
  font-variant-numeric: tabular-nums; user-select: none;
}

.ln--cmd { padding-left: 0; margin-bottom: 4px; }
.ln--gap { height: 1.65em; padding-left: 0; }
.ln--block { margin: 4px 0; }
.ln--flush { padding-left: 0; }

.ps1 { color: var(--green); }
.ps1 .d { color: var(--blue); }
.cmd { color: var(--bright); }

.caret {
  display: inline-block; width: .6em; height: 1.1em; vertical-align: -.18em; margin-left: 1px;
  background: var(--green); animation: caret-blink 1.05s steps(1) infinite;
}
.caret--line { background: var(--text); }
@keyframes caret-blink { 50% { opacity: 0; } }

/* the reveal: hidden until the stream reaches the line */
.js .ln { opacity: 0; }
.js .ln.is-on { opacity: 1; }
.js .ln.is-new { animation: ln-in .3s ease-out; }
@keyframes ln-in { from { background: var(--flash); } to { background: transparent; } }

.k { display: inline-block; width: 10ch; color: var(--faint); }
.k--ind { margin-left: 2ch; }
.k--inline { width: auto; margin-right: 2px; }
.kc { display: inline-block; width: 30ch; color: var(--green); }

.v { color: var(--amber); }
.oral { padding: 0 6px; border: 1px solid var(--amber); color: var(--amber); font-size: 12px; }
.ln--title { color: var(--bright); font-weight: 500; }
.ln--au { color: var(--dim); }
.ln--au b, .au b { font-weight: 400; color: var(--green); }
.ln--dim { color: var(--faint); }

.lnk a { margin-right: 12px; }

.cp {
  margin-left: 10px; padding: 0 7px; border: 1px solid var(--line); border-radius: 3px;
  color: var(--dim); font-size: 11.5px;
}
.cp:hover { border-color: var(--blue); color: var(--blue); }

.filters { display: inline-flex; gap: 6px; }
.filters button {
  padding: 0 8px; border: 1px solid var(--line); border-radius: 3px;
  color: var(--dim); font-size: 12px;
}
.filters button:hover { border-color: var(--line-hi); color: var(--text); }
.filters button[aria-pressed="true"] { border-color: var(--green); color: var(--green); }

/* about ------------------------------------------------------------------- */

/* name and affiliation, then the bio */
.hero-bio { margin-top: 12px; }

.h1 { font: 500 26px/1.25 var(--mono); color: var(--bright); letter-spacing: -.01em; }
.h1 .cn { margin-left: 10px; font-size: 20px; color: var(--dim); font-weight: 400; white-space: nowrap; }
.affil { margin-top: 8px; color: var(--dim); font-size: 13.5px; text-wrap: balance; }

.viz-panel { border: 1px solid var(--line); background: var(--win); }
.viz-panel .pane-title { border-bottom: 1px solid var(--line); }
.viz-body { padding: 10px; }
.viz-panel--full { max-width: 1000px; }
/* two figures side by side; they stack once a column would get too narrow */
.viz-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-items: start; }
@media (max-width: 1000px) {
  .viz-row { grid-template-columns: minmax(0, 1fr); }
}
/* a short window squeezes the diagram instead of pushing its last row below the fold */
@media (min-width: 861px) {
  .viz-panel--full .viz-body { max-height: calc(100dvh - 280px); }
}

/* publications list ------------------------------------------------------- */

#pubs .ln--paper + .ln--paper { border-top: 1px dashed var(--line); }
#pubs .ln--paper.is-first { border-top: 0; }

.ln--paper {
  display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 2px 16px;
  padding: 10px 10px 12px 4ch; margin-right: -10px; cursor: pointer;
}
.ln--paper:hover { background: var(--flash); }
.ln--paper.is-focus { background: var(--flash); box-shadow: inset 2px 0 0 var(--blue); }
.ln--paper[hidden] { display: none; }

.thumb {
  width: 150px; height: 104px; padding: 4px;
  background: #fff; border: 1px solid var(--line); object-fit: contain;
}

.pt-h { color: var(--bright); font-size: 14.5px; line-height: 1.45; }
.pt-h a { color: inherit; }
.pt-h a:hover { color: var(--blue); }
.idx { display: inline-block; min-width: 3ch; color: var(--faint); }
.pt .au { margin-top: 2px; color: var(--dim); font-size: 12.5px; line-height: 1.55; }
.pt .lnk { margin-top: 2px; font-size: 12.5px; }

/* paper detail ------------------------------------------------------------ */

.ln--fig { max-width: 880px; }
.fig {
  display: block; width: 100%; padding: 8px;
  background: #fff; border: 1px solid var(--line);
}
.fig img { display: block; width: 100%; height: auto; max-height: 46vh; object-fit: contain; }
.fig:hover { border-color: var(--blue); }
.cap { margin-top: 6px; font-size: 12px; color: var(--faint); }
.cap b { font-weight: 400; color: var(--dim); }

.pager { display: flex; gap: 8px; max-width: 880px; }
.pager button {
  flex: 1; min-width: 0; padding: 6px 10px; border: 1px solid var(--line);
  background: var(--raise); color: var(--dim); font-size: 12.5px; text-align: left;
}
.pager button:hover { border-color: var(--blue); color: var(--text); }
.pager button span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager button.next { text-align: right; }
.pager button i { font-style: normal; color: var(--faint); }

.bib {
  margin: 0; padding: 10px 12px; border: 1px solid var(--line); background: var(--win);
  color: var(--text); font: 400 12.5px/1.6 var(--mono); white-space: pre-wrap; overflow-x: auto;
}
.out-body .ln--txt { white-space: pre-wrap; }

/* projects ---------------------------------------------------------------- */

.ln--proj { padding: 2px 10px 2px 4ch; margin-right: -10px; cursor: pointer; }
.ln--proj:hover { background: var(--flash); }
.ln--proj .ph { display: flex; gap: 12px; }
.ln--proj .y { color: var(--faint); }
.ln--proj .t { color: var(--bright); }
.ln--proj .t a { color: inherit; }
.ln--proj .t a:hover { color: var(--blue); }
.ln--proj .d { padding-left: 10ch; color: var(--dim); }
.ln--proj .lnk { padding-left: 10ch; }

/* command bar ──────────────────────────────────────────────────────────── */

.cmdbar { flex: none; border-top: 1px solid var(--line); background: var(--bar); }
.cmd-msg { padding: 0 14px; color: var(--red); font-size: 12.5px; line-height: 1.6; }
.cmd-msg.on { padding: 6px 14px 0; }
.cmd-msg.is-note { color: var(--dim); }
.cmd-row { display: flex; align-items: center; gap: 10px; padding: 8px 14px; }
.cmdbar .prompt { color: var(--green); white-space: nowrap; font-size: 13px; }
.cmdbar .prompt .d { color: var(--blue); }
.cmdbar input {
  flex: 1; min-width: 0; padding: 2px 0;
  border: 0; outline: 0; background: none; color: var(--text); font: inherit; font-size: 13px;
  caret-color: var(--green);
}
.cmdbar input::placeholder { color: var(--faint); }
.cmdbar .chips { display: flex; gap: 6px; }
.cmdbar .chips button {
  padding: 2px 9px; border: 1px solid var(--line); border-radius: 3px;
  background: var(--raise); color: var(--dim); font-size: 12px; white-space: nowrap;
}
.cmdbar .chips button:hover { border-color: var(--blue); color: var(--text); }

/* drawer (narrow screens) ------------------------------------------------- */

.drawer-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(8, 10, 14, .55); }
.drawer-backdrop[hidden] { display: none; }
:root[data-theme="light"] .drawer-backdrop { background: rgba(24, 30, 38, .34); }

/* matrix easter egg ------------------------------------------------------- */

.matrix { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
.matrix canvas { display: block; width: 100%; height: 100%; }

/* lightbox ─────────────────────────────────────────────────────────────── */

.lb {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 24px;
  background: var(--lb-bg);
}
.lb[hidden] { display: none; }
.lb-box {
  width: min(1120px, 100%); max-height: 100%; overflow: auto;
  border: 1px solid var(--line); background: var(--win);
}
.lb-box figure { padding: 12px; background: #fff; }
.lb-box img { display: block; width: 100%; max-height: 62vh; object-fit: contain; }
.lb-box figcaption { padding: 8px 4px 0; font-size: 12.5px; color: #5a6372; }
.lb-body { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.lb-body h3 { font: 500 14px/1.45 var(--mono); color: var(--bright); }
.lb-body .nav { display: flex; gap: 6px; margin-left: auto; }
.lb-body .nav button, .lb-close {
  padding: 3px 10px; border: 1px solid var(--line); border-radius: 3px;
  background: var(--raise); color: var(--dim); font-size: 12px; white-space: nowrap;
}
.lb-body .nav button:hover, .lb-close:hover { border-color: var(--blue); color: var(--text); }
.lb-close { position: absolute; top: 14px; right: 16px; background: var(--win); }

/* boot log ─────────────────────────────────────────────────────────────── */

.boot {
  position: absolute; inset: 0; z-index: 5; padding: var(--pad) 26px;
  background: var(--pane); color: var(--dim); font-size: 13px; line-height: 1.8;
}
.boot[hidden] { display: none; }
.boot p { opacity: 0; animation: boot-in .12s ease-out forwards; }
.boot p b { font-weight: 400; color: var(--green); }
.boot p i { font-style: normal; color: var(--faint); }
@keyframes boot-in { to { opacity: 1; } }

/* 404 ───────────────────────────────────────────────────────────────────── */

.nf {
  max-width: 74ch; min-height: 100dvh; margin: 0 auto;
  padding: 10vh var(--pad) 8vh; display: flex; flex-direction: column; justify-content: center;
}
.nf p { margin: 0; }
.nf-line { overflow-wrap: anywhere; }
.nf-gap { height: 1.65em; }
.nf-err { color: var(--red); }
.nf-h { margin: 0; font-size: 22px; font-weight: 500; line-height: 1.4; color: var(--bright); }
.nf-h span { font-weight: 400; color: var(--dim); }
.nf-k { display: inline-block; width: 5ch; color: var(--faint); }

/* ── responsive ────────────────────────────────────────────────────────── */

@media (max-width: 860px) {
  :root { --sidebar: 0px; --pad: 16px; }
  .app { height: auto; min-height: 100dvh; }
  .workbench { grid-template-columns: minmax(0, 1fr); }
  .sb-menu { display: inline-block; }
  .sb-spark, .sb-metric, .sb-host { display: none; }

  /* the explorer turns into a drawer instead of a second top row */
  .pane--tree {
    position: fixed; z-index: 50; top: 0; bottom: 0; left: 0;
    width: min(320px, 84vw);
    border-right: 1px solid var(--line); background: var(--pane);
    transform: translateX(-101%); transition: transform .18s ease-out;
  }
  .pane--tree.is-open { transform: none; }
  .pane--tree .pane-foot { display: none; }
  .tree { padding: 8px 0 16px; }

  .view-scroll { overflow: visible; padding: var(--pad) 16px 24px; }
  .ln--paper { grid-template-columns: 108px minmax(0, 1fr); }
  .thumb { width: 108px; height: 76px; }
  .k { width: 9ch; }
  .kc { display: block; width: auto; }
  .ln--proj .d, .ln--proj .lnk { padding-left: 0; }
  .cmdbar { position: sticky; bottom: 0; }
  .cmdbar .chips { display: none; }

  /* a long subtitle flows inline with its label instead of taking its own row */
  .pane-title { display: block; }
}

@media (max-height: 560px) and (min-width: 861px) {
  .app { height: auto; min-height: 0; }
  .view-scroll { overflow: visible; }
}

@media (prefers-reduced-motion: reduce) {
  .js .ln { opacity: 1; }
  .js .ln.is-new { animation: none; }
  .caret { animation: none; }
  .pane--tree { transition: none; }
  .boot p { animation: none; opacity: 1; }
  * { scroll-behavior: auto !important; }
}

/* print: paper-white page, the current view's text, no shell -------------------- */

@media print {
  :root, :root[data-theme="light"] {
    --bg: #fff; --win: #fff; --bar: #fff; --pane: #fff; --raise: #fff;
    --line: #bbb; --line-hi: #999;
    --text: #000; --bright: #000; --dim: #333; --faint: #555;
    --green: #000; --blue: #000; --amber: #000; --red: #000; --purple: #000;
    --flash: transparent; --sel: transparent;
  }
  html { color-scheme: light; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .statusbar, .pane--tree, .cmdbar, .viz-panel, .pager, .filters, .cp,
  .boot, .drawer-backdrop, .skip, .view-foot .sp { display: none !important; }
  .app, .workbench, .pane, .view-scroll {
    display: block; height: auto; min-height: 0; overflow: visible;
  }
  .view-scroll { padding: 0; }
  .view { max-width: none; }
  .view-foot { border: 0; padding: 12px 0 0; }
  a { color: #000; text-decoration: underline; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 9pt; color: #333; }
  .thumb, .fig { background: #fff; border-color: #999; }
  .ln { break-inside: avoid; }
}
