/* ------------------------------------------------------------------ tokens */
:root {
  --bg: #020618;            /* page background (AGrade) */
  --panel: #0f172b;         /* cards */
  --panel-2: #152040;       /* hover / raised */
  --border: #1c2742;
  --border-strong: #2a3a5e;
  --text: #f1f5f9;
  --muted: #9aa8bf;
  --blue: #2774ae;          /* UCLA blue: fills, slider progress */
  --blue-deep: #246ba1;
  --blue-light: #6db6e6;    /* headings, links, readouts */
  --gold: #ffd100;          /* UCLA gold: interactable elements only */
  --gold-ink: #1a1500;
  --radius: 14px;
  --radius-sm: 10px;
  --header-h: 60px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 12px); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue-light); text-decoration: none; }
a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
button { font: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }
::selection { background: rgba(39, 116, 174, 0.55); }

.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 900px; }

/* ------------------------------------------------------------------ header */
.top {
  position: sticky; top: 0; z-index: 20;
  background: rgba(2, 6, 24, 0.86); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.top .wrap { display: flex; align-items: center; gap: 18px; min-height: var(--header-h); }
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); flex: 0 0 auto; }
.brand:hover { text-decoration: none; }
.avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border-strong); background: var(--panel); }
.brand b { display: block; font-size: 16px; font-weight: 650; letter-spacing: 0.01em; line-height: 1.15; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.nav { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding: 4px 0; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 8px 13px; border-radius: 999px; border: 1px solid transparent;
  color: var(--muted); font-size: 14px; font-weight: 500;
}
.nav a:hover { color: var(--text); text-decoration: none; background: var(--panel); }
.nav a.active { color: var(--gold); border-color: rgba(255, 209, 0, 0.35); background: rgba(255, 209, 0, 0.08); }
.nav a .ext { font-size: 11px; opacity: 0.7; }

@media (max-width: 760px) {
  :root { --header-h: 104px; }
  .top .wrap { flex-wrap: wrap; gap: 6px 12px; padding-top: 8px; padding-bottom: 4px; }
  .nav { margin-left: -16px; margin-right: -16px; padding: 4px 16px 8px; width: calc(100% + 32px);
         -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); }
}

/* ------------------------------------------------------------------ cards & text */
main { padding: 18px 0 32px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.sec-title {
  display: flex; align-items: center; gap: 10px; margin: 0;
  font-size: 13px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--blue-light);
}
.sec-title::before { content: ""; width: 3px; height: 15px; border-radius: 2px; background: var(--blue-light); }
.page-title { font-size: 26px; font-weight: 700; margin: 6px 0 16px; letter-spacing: -0.01em; }
.page-title small { display: block; font-size: 14px; font-weight: 400; color: var(--muted); margin-top: 4px; }
.prose p { margin: 8px 0; color: var(--muted); line-height: 1.6; }
.prose p:first-child { margin-top: 6px; }
.prose h4 { margin: 18px 0 4px; font-size: 15px; color: var(--text); }
.prose ul { margin: 6px 0; padding-left: 20px; color: var(--muted); }
.prose li { margin: 5px 0; }
.prose mjx-container[display="true"] { margin: 10px 0 !important; overflow-x: auto; overflow-y: hidden; max-width: 100%; padding: 2px 0; }
mjx-container { color: var(--text); }

/* ------------------------------------------------------------------ home grid */
.home {
  display: grid; gap: 16px; align-items: start;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-areas: "about about" "head side" "stage side" "model side";
}
.about { grid-area: about; display: grid; grid-template-columns: 116px minmax(0, 1fr); gap: 18px; align-items: center; }
.about .portrait { width: 116px; height: 116px; border-radius: 14px; object-fit: cover; border: 1px solid var(--border-strong); transition: opacity 0.26s ease; }
.about .portrait.fade { opacity: 0; }
.about p { margin: 0; font-size: 15.5px; line-height: 1.6; color: var(--text); }
.about p a { font-weight: 600; }
.stage-head { grid-area: head; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stage-wrap { grid-area: stage; min-width: 0; }
.panel { grid-area: side; position: sticky; top: calc(var(--header-h) + 12px); max-height: calc(100vh - var(--header-h) - 24px); overflow: auto; }
.model { grid-area: model; }
.model h3 { margin: 10px 0 2px; font-size: 18px; }

@media (max-width: 960px) {
  .home { grid-template-columns: minmax(0, 1fr); grid-template-areas: "about" "head" "stage" "side" "model"; }
  .panel { position: static; max-height: none; }
}
@media (max-width: 560px) {
  .about { grid-template-columns: 84px minmax(0, 1fr); gap: 14px; align-items: start; }
  .about .portrait { width: 84px; height: 84px; }
  .about p { font-size: 15px; }
}

/* ------------------------------------------------------------------ segmented switcher & icon buttons */
.segment { display: inline-flex; flex-wrap: wrap; max-width: 100%; gap: 4px; padding: 4px; background: var(--panel); border: 1px solid var(--border); border-radius: 24px; }
.segment button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 8px 16px; min-height: 38px; border-radius: 999px; font-size: 14px; font-weight: 500; white-space: nowrap;
}
.segment button:hover { color: var(--text); }
.segment button.active { background: var(--gold); color: var(--gold-ink); font-weight: 650; }
.stage-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--panel); color: var(--gold);
  display: grid; place-items: center;
}
.icon-btn:hover { border-color: var(--gold); background: var(--panel-2); }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.icon-btn.restart svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------------ stage */
.stage {
  position: relative; overflow: hidden; border-radius: var(--radius);
  border: 1px solid var(--border); background: #181818;
  height: min(68vh, 720px); min-height: 320px;
}
@media (max-width: 960px) { .stage { height: auto; min-height: 0; aspect-ratio: 1 / 1; } }
.stage canvas#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.stage canvas#stage.brush { touch-action: pan-y; cursor: crosshair; }
.stage.paused canvas#stage { opacity: 0.72; }
.stage.paused::after {
  content: "Paused"; position: absolute; top: 12px; left: 12px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--gold); background: rgba(2, 6, 24, 0.8); border: 1px solid rgba(255, 209, 0, 0.4);
}
.stage noscript { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); padding: 20px; text-align: center; }

/* ------------------------------------------------------------------ parameter panel */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.presets { margin: 6px 0 4px; }
.chip {
  border: 1px solid var(--border-strong); background: transparent; color: var(--text); cursor: pointer;
  border-radius: 999px; padding: 6px 12px; min-height: 34px; font-size: 13px; line-height: 1.2;
}
.chip:hover { border-color: var(--gold); color: var(--gold); }
.chip.active { border-color: var(--gold); color: var(--gold); background: rgba(255, 209, 0, 0.1); font-weight: 600; }
.chip.small { padding: 4px 10px; min-height: 28px; font-size: 12px; color: var(--muted); }
.group-title { margin: 16px 0 2px; font-size: 11.5px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

.ctl {
  display: grid; grid-template-columns: minmax(0, 1fr) 82px; grid-template-areas: "name val" "range range";
  column-gap: 12px; row-gap: 2px; padding: 9px 0 6px; border-top: 1px solid var(--border);
}
.ctl.wide { grid-template-columns: 1fr; grid-template-areas: "name" "range"; row-gap: 8px; padding-bottom: 10px; }
.ctl.derived { grid-template-areas: "name val"; padding: 8px 0; align-items: center; }
.ctl-val.readonly { color: var(--blue-light); border-style: dashed; background: transparent; width: auto; min-width: 60px; }
.ctl-name { grid-area: name; display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; font-size: 14.5px; min-height: 22px; }
.ctl-name .tex mjx-container { font-size: 108%; }
.ctl-name .lbl { font-weight: 500; }
.ctl-name .sub { color: var(--muted); font-size: 12.5px; }
.ctl-name .unit { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.ctl-val {
  grid-area: val; width: 82px; justify-self: end;
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: 8px;
  color: var(--gold); font-family: var(--mono); font-size: 13px; text-align: right; padding: 5px 8px;
  -moz-appearance: textfield; appearance: textfield;
}
.ctl-val::-webkit-outer-spin-button, .ctl-val::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ctl-val:focus { border-color: var(--gold); outline: none; }
.ctl-select {
  grid-area: range; width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 9px 10px; font-size: 14px;
}
.ctl .chips { grid-area: range; }

/* range slider */
.ctl input[type="range"] {
  grid-area: range; -webkit-appearance: none; appearance: none; width: 100%; height: 30px; margin: 0;
  background: transparent; cursor: pointer; --p: 50%;
}
.ctl input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px;
  background: linear-gradient(to right, var(--blue) 0, var(--blue) var(--p), var(--border-strong) var(--p), var(--border-strong) 100%);
}
.ctl input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%;
  background: var(--gold); border: 2px solid var(--gold-ink); box-shadow: 0 0 0 3px rgba(255, 209, 0, 0.18);
}
.ctl input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: var(--border-strong); }
.ctl input[type="range"]::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--blue); }
.ctl input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--gold); border: 2px solid var(--gold-ink); box-shadow: 0 0 0 3px rgba(255, 209, 0, 0.18); }

/* ------------------------------------------------------------------ publications */
.pubs { display: grid; gap: 12px; }
.pub { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.pub-title { font-weight: 600; font-size: 15.5px; line-height: 1.35; margin-bottom: 4px; }
.pub-authors { font-size: 13.5px; color: var(--muted); margin-bottom: 8px; }
.pub-authors .you { color: var(--text); font-weight: 600; }
.pub-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag { display: inline-block; padding: 2px 9px; border: 1px solid var(--border-strong); border-radius: 999px; font-size: 12px; color: var(--muted); }
.tag-kind { color: var(--blue-light); border-color: rgba(109, 182, 230, 0.35); }
.pub-links { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; min-height: 32px;
  border: 1px solid var(--border-strong); border-radius: 999px; color: var(--text); font-size: 13px; text-decoration: none;
}
.btn:hover { border-color: var(--gold); color: var(--gold); text-decoration: none; }
.btn.ghost { border-style: dashed; color: var(--muted); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); font-weight: 650; }
.btn.gold:hover { background: #ffdc3c; color: var(--gold-ink); }
.btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sub-heading { margin: 22px 0 10px; font-size: 13px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.sub-heading:first-child { margin-top: 4px; }

/* ------------------------------------------------------------------ teaching */
.courses { display: grid; gap: 12px; }
.course { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.course-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.course-title { font-weight: 600; font-size: 15px; }
.quarter { font-size: 12.5px; color: var(--blue-light); white-space: nowrap; }
.files { margin: 8px 0 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.files li { font-size: 14px; }
.files a { display: inline-flex; align-items: center; gap: 8px; padding: 3px 0; }
.files a::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--blue); flex: 0 0 auto; }
.files .embargo { display: inline-flex; align-items: center; gap: 8px; padding: 3px 0; color: var(--muted); }
.files .embargo::before { content: ""; width: 6px; height: 6px; border-radius: 50%; border: 1px solid var(--border-strong); flex: 0 0 auto; }
.files .embargo small { font-size: 12px; color: var(--muted); opacity: 0.8; }
.hours { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px 20px; margin: 0 0 16px; }
.hours div { font-size: 14px; color: var(--muted); }
.hours b { display: block; color: var(--text); font-weight: 600; }

/* ------------------------------------------------------------------ CV */
.cv-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.cv-frame { width: 100%; height: calc(100vh - var(--header-h) - 160px); min-height: 480px; border: 1px solid var(--border); border-radius: var(--radius); background: #1e2433; overflow: hidden; }
.cv-frame object { display: block; width: 100%; height: 100%; }
.cv-fallback { padding: 24px; text-align: center; color: var(--muted); }

/* ------------------------------------------------------------------ footer */
.foot { border-top: 1px solid var(--border); margin-top: 16px; }
.foot .wrap { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 18px; padding: 24px 16px 36px; font-size: 14px; color: var(--muted); }
.foot h3 { margin: 0 0 6px; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--blue-light); }
.foot b { color: var(--text); font-weight: 600; }
.foot p { margin: 3px 0; }
.foot .fine { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 12px; }

.copy-email {
  position: relative; display: inline; padding: 0; border: 0; background: none; font: inherit; cursor: pointer;
  color: var(--blue-light); text-decoration: underline dotted; text-underline-offset: 3px; word-break: break-all;
}
.copy-email:hover { text-decoration-style: solid; }
.copy-email .copied {
  position: absolute; left: 50%; top: -1.7em; transform: translateX(-50%);
  background: var(--gold); color: var(--gold-ink); font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px;
  opacity: 0; pointer-events: none; transition: opacity 0.15s; white-space: nowrap;
}
.copy-email.done .copied { opacity: 1; }

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