/* Layout, typography and components of the site.
   Colours and fonts come from tokens.css; never hard-code them here.
   The look is the CS 2490 textbook's (reading column, sticky monospace sidebar, mono labels,
   cards) with the cs-5500 workbench's controls (buttons, segmented controls, interactive figures). */

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17.5px;
  line-height: 1.62;
  padding-inline: 20px;
  padding-block: 40px 32px;
  -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; }
a { color: var(--structure); text-underline-offset: .14em; text-decoration-thickness: from-font; }
strong { font-weight: 600; }
sup, sub { line-height: 0; font-size: .72em; }
:focus-visible { outline: 2px solid var(--hi); outline-offset: 2px; }

.skip {
  position: absolute;
  left: -9999px;
  top: 12px;
  z-index: 10;
  font: 500 13px/1 var(--sans);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 10px 14px;
}
.skip:focus { left: 12px; }

/* ---------- shell: sidebar + reading column ---------- */
.site {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 56px;
  --measure: 40rem;   /* width of the reading column, about 70 characters of body text */
}
.site > main { max-width: var(--measure); min-width: 0; }

.side {
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 28px);
  align-self: start;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  display: grid;
  gap: 26px;
}
.brand { display: grid; gap: 2px; text-decoration: none; color: var(--ink); padding-left: 10px; }
.brand .name { font: 700 19px/1.2 var(--serif); letter-spacing: -.005em; }
.brand .role { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.brand:hover .name { color: var(--structure); }

.side .label {
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  font-size: 11px;
  margin: 0 0 8px;
  padding-left: 10px;
}
.side ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
.side li { margin: 0; }
.side nav a {
  color: var(--ink);
  text-decoration: none;
  display: block;
  padding: 3px 8px;
  border-left: 2px solid transparent;
  border-radius: 0 3px 3px 0;
}
.side nav a:hover { border-left-color: var(--structure); background: var(--structure-soft); }
.side nav a[aria-current] { border-left-color: var(--structure); }
.sitenav a[aria-current="page"] { font-weight: 500; }
.sitenav .ext, .pill .ext { color: var(--muted); font-size: .85em; margin-left: 4px; }
nav.toc a { color: var(--muted); }
nav.toc a:hover, nav.toc a[aria-current] { color: var(--ink); }

/* ---------- page header ---------- */
.eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--structure);
  margin: 0 0 10px;
}
h1 {
  font-size: clamp(2rem, 1.4rem + 2.4vw, 2.9rem);
  line-height: 1.1;
  margin: 0 0 12px;
  font-weight: 700;
  letter-spacing: -.01em;
  text-wrap: balance;
}
.lede { color: var(--muted); margin: 0 0 28px; font-size: 1.05rem; }

/* home: name and portrait side by side */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) 168px; gap: 32px; align-items: center; margin-bottom: 8px; }
.hero .lede { margin-bottom: 0; }
.portrait { margin: 0; }
.portrait img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--rule);
  background: var(--sunk);
}

/* ---------- running text ---------- */
main > section { margin-top: 52px; scroll-margin-top: 24px; }
h2 {
  font-size: 1.5rem;
  line-height: 1.25;
  margin: 0 0 14px;
  font-weight: 700;
  text-wrap: balance;
}
h3 { font-size: 1.15rem; line-height: 1.3; margin: 28px 0 10px; font-weight: 600; text-wrap: balance; }
h3.sub {
  font: 500 12px/1.3 var(--mono);
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 30px 0 10px;
}
p { margin: 0 0 14px; }
ul, ol { margin: 0 0 14px; padding-left: 1.25em; }
li { margin-bottom: 6px; }
li::marker { color: var(--muted); }
code, kbd {
  font-family: var(--mono);
  font-size: .82em;
  background: var(--code-bg);
  padding: .08em .35em;
  border-radius: 3px;
}
pre {
  font-family: var(--mono);
  font-size: .8rem;
  line-height: 1.55;
  background: var(--code-bg);
  border-radius: 6px;
  padding: 12px 14px;
  margin: 0 0 14px;
  overflow-x: auto;
}
pre code { background: none; padding: 0; font-size: inherit; }
dfn { font-style: normal; font-weight: 600; color: var(--structure); }
.muted { color: var(--muted); }
.fr { font-style: italic; }   /* titles in French */
/* math inside uppercase labels must keep its case */
mjx-container { text-transform: none; letter-spacing: normal; }
mjx-assistive-mml { max-height: 100%; }

/* tables */
.table-scroll { overflow-x: auto; margin: 0 0 18px; }
table { border-collapse: collapse; font-size: .95rem; font-variant-numeric: tabular-nums; width: 100%; }
th, td { text-align: left; vertical-align: top; padding: 7px 12px 7px 0; border-bottom: 1px solid var(--rule); }
th {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  font-weight: 500;
}
td.code { font-family: var(--mono); font-size: .85rem; white-space: nowrap; padding-top: 9px; }
td.when { font-family: var(--mono); font-size: .82rem; color: var(--muted); white-space: nowrap; padding-top: 9px; }

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin: 0 0 22px; }
.cards.lead > :first-child { grid-column: 1 / -1; }   /* a wide first card above the others */
.cards.stack { grid-template-columns: minmax(0, 1fr); gap: 10px; }
.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 14px 16px 6px;
  min-width: 0;
}
.card .kicker, .entry .kicker {
  font: 500 11.5px/1.3 var(--mono);
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--structure);
  margin: 0 0 6px;
}
.card h3 { font-size: 1.05rem; margin: 0 0 6px; }
.card h3 a { color: var(--ink); text-decoration: none; }
.card h3 a:hover { color: var(--structure); }
.card p { font-size: .95rem; margin: 0 0 10px; }
.card .links { margin-bottom: 10px; }

/* a highlighted box, e.g. "this semester" */
.callout {
  background: var(--structure-soft);
  border-radius: 10px;
  padding: 14px 18px 4px;
  margin: 0 0 22px;
}
.callout .kicker { font: 500 11.5px/1.3 var(--mono); letter-spacing: .09em; text-transform: uppercase; color: var(--structure); margin: 0 0 8px; }
.callout ul { padding-left: 1.1em; }

/* ---------- lists of works: publications, talks, notes ----------
   Markup: <ol class="entries"><li class="entry" id="…"><span class="when">2024</span><div>…</div></li></ol> */
ol.entries { list-style: none; padding: 0; margin: 0 0 18px; border-top: 1px solid var(--rule); }
ol.entries > li {
  display: grid;
  grid-template-columns: 3.4em minmax(0, 1fr);
  gap: 14px;
  padding: 16px 0 12px;
  border-bottom: 1px solid var(--rule);
  margin: 0;
  scroll-margin-top: 24px;
}
ol.entries > li:target { background: linear-gradient(90deg, var(--structure-soft), transparent 70%); }
.entry .when { font: 13px/1.5 var(--mono); color: var(--structure); padding-top: .28em; }
.entry h3 { font-size: 1.08rem; line-height: 1.35; margin: 0 0 4px; font-weight: 600; }
.entry p { font-size: .95rem; margin: 0 0 6px; }
.entry .who { color: var(--muted); margin: 0 0 2px; }
.entry .who .me { color: var(--ink); }
.entry .links { margin-top: 8px; }
.entry .where cite, .entry .where em { font-style: italic; }
.entry > div > p:last-child { margin-bottom: 4px; }
.entries.compact h3 { font-size: 1rem; font-weight: 600; }
.entries.compact > li { padding: 12px 0 8px; }

/* link pills: PDF, DOI, arXiv, slides, code */
.links { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 6px; padding: 0; list-style: none; }
.links li { margin: 0; }
a.pill {
  display: inline-block;
  font: 500 11.5px/1 var(--mono);
  letter-spacing: .06em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--structure);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--surface);
  white-space: nowrap;
}
a.pill:hover { border-color: var(--structure); background: var(--structure-soft); }

/* small status tags next to a title or venue */
.tag {
  display: inline-block;
  font: 500 10.5px/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--chip);
  border-radius: 999px;
  padding: 4px 8px;
  vertical-align: .16em;
  margin-left: 6px;
  white-space: nowrap;
}
.tag.yes { color: var(--yes); background: var(--yes-soft); }
.tag.warn { color: var(--warn); background: var(--warn-soft); }
.tag.structure { color: var(--structure); background: var(--structure-soft); }

/* folded extras: abstract, BibTeX. Closed ones sit side by side; an open one drops below. */
.folds { display: flex; flex-wrap: wrap; gap: 0 18px; }
details.more { min-width: 0; }
details.more[open] { flex-basis: 100%; order: 1; }
details.more > summary {
  font: 500 11.5px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  cursor: pointer;
  padding: 8px 0;
  width: max-content;
}
details.more > summary:hover, details.more[open] > summary { color: var(--ink); }
details.more > :not(summary) { margin-top: 4px; }
details.more p { font-size: .95rem; }
.bibtex-wrap { position: relative; }
.bibtex-wrap pre { padding-right: 70px; margin-bottom: 10px; }
.bibtex-wrap .btn { position: absolute; top: 8px; right: 8px; padding: 5px 9px; font-size: 12px; }

/* course material: a fold with a table inside */
details.material {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  margin: 0 0 14px;
}
details.material > summary {
  cursor: pointer;
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  list-style: none;
}
details.material > summary::-webkit-details-marker { display: none; }
details.material > summary::before {
  content: "▸";
  font-family: var(--mono);
  color: var(--muted);
  transition: transform .15s;
  display: inline-block;
}
details.material[open] > summary::before { transform: rotate(90deg); }
details.material > summary .title { font-weight: 600; }
details.material > summary .count { font: 12px var(--mono); color: var(--muted); margin-left: auto; }
details.material > .body { padding: 0 16px 6px; }
details.material table { font-size: .92rem; }
details.material tr:last-child > td { border-bottom: 0; }
details.material td .links { margin: 0; }
details.material p { font-size: .95rem; }

/* contact details */
dl.contact { display: grid; grid-template-columns: 7.5em minmax(0, 1fr); gap: 8px 16px; margin: 0 0 18px; }
dl.contact dt {
  font: 500 11px/1.3 var(--mono);
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  padding-top: .45em;
}
dl.contact dd { margin: 0; }

/* chips: research interests */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; padding: 0; list-style: none; }
.chips li { margin: 0; }
.chip { font: 15px/1.3 var(--serif); padding: 3px 11px; border-radius: 999px; background: var(--chip); display: inline-block; }

/* ---------- footer ---------- */
.site > .side { grid-row: 1 / span 2; }
.site > footer.foot { grid-column: 2; max-width: var(--measure); }
footer.foot {
  margin-top: 72px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  justify-content: space-between;
  font: 12.5px/1.5 var(--mono);
  color: var(--muted);
}
footer.foot p { margin: 0; }
footer.foot a { color: inherit; }
.theme-switch { display: flex; align-items: center; gap: 8px; }
.theme-switch .seg button { font-size: 12.5px; padding: 6px 10px; }

/* ---------- controls (from the workbench) ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; }
.controls label, .controls .label { font: 500 12.5px/1.3 var(--sans); color: var(--muted); }
.btn {
  font: 500 13.5px/1.1 var(--sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}
.btn:hover { border-color: var(--faint); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }

/* segmented control: <div class="seg"><button aria-pressed="true">…</button>…</div> */
.seg { display: inline-flex; flex-wrap: wrap; padding: 3px; gap: 2px; background: var(--chip); border-radius: 9px; }
.seg button { font: 500 13.5px/1.1 var(--sans); color: var(--muted); background: transparent; border: 0; border-radius: 7px; padding: 8px 12px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .08), 0 0 0 1px var(--rule); }

input[type="range"] { accent-color: var(--hi); flex: 1 1 160px; min-width: 120px; }
.status { font: 14px/1.45 var(--sans); color: var(--muted); margin: 0; min-height: 2.9em; }
.status i { font-family: var(--serif); font-size: 15.5px; }

/* ---------- interactive figures ----------
   Markup: <figure class="interactive" data-widget="name">…<figcaption>…</figcaption></figure>
   The widget module renders its UI before the figcaption. */
figure { margin: 0 0 22px; }
figcaption { font-size: .92rem; color: var(--muted); margin-top: 8px; }
.interactive {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 14px;
  display: grid;
  gap: 12px;
}
.interactive figcaption { margin: 0; }
.panes { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 10px; }
.canvas {
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--sunk);
  overflow: hidden;
  display: grid;
  align-content: start;
}
.canvas .cap-h {
  font: 500 11px/1.3 var(--mono);
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 10px 12px 0;
}
.canvas svg { display: block; width: 100%; height: auto; }
.canvas svg.drag { touch-action: none; user-select: none; -webkit-user-select: none; }
.noscript-note { font: 14px/1.45 var(--sans); color: var(--muted); margin: 0; }

/* ---------- SVG drawing (classes used by js/lib/svg.js and the widgets) ---------- */
svg text { font-family: var(--serif); fill: var(--ink); }
svg .lb { font-style: italic; font-size: 16px; }
svg .lb.up { font-style: normal; }
svg .cap { font-family: var(--sans); font-size: 12px; fill: var(--muted); letter-spacing: .03em; }
svg .mono { font-family: var(--mono); font-size: 11px; fill: var(--muted); letter-spacing: .04em; }
svg .faint { fill: var(--faint); }
.c-ink { --c: var(--ink); } .c-muted { --c: var(--muted); } .c-faint { --c: var(--faint); }
.c-structure { --c: var(--structure); } .c-hi { --c: var(--hi); }
.c-yes { --c: var(--yes); } .c-no { --c: var(--no); } .c-warn { --c: var(--warn); }
.arw .ar { fill: none; stroke: var(--c); stroke-width: 1.6; stroke-linecap: round; }
.arw .hd { fill: var(--c); }
.arw.em .ar { stroke-width: 2.6; }
.ring { fill: none; stroke: var(--ink); stroke-width: 1.6; }
.ring.off { stroke: var(--faint); }
.hit { fill: transparent; stroke: transparent; stroke-width: 26; cursor: pointer; }
.axis { stroke: var(--structure); stroke-width: 1.3; stroke-dasharray: 5 5; fill: none; }
.floor { fill: var(--chip); stroke: var(--rule); stroke-width: 1; }
.guide { stroke: var(--faint); stroke-width: 1.2; stroke-dasharray: 2 4; stroke-linecap: round; }
.strand { stroke: var(--muted); stroke-width: 1; stroke-opacity: .7; }
.strand.back { stroke-opacity: .3; }
.strand.base { stroke: var(--structure); stroke-width: 1.8; stroke-opacity: 1; }
.tick { stroke: var(--muted); stroke-width: 1.4; }
.pt { fill: var(--c, var(--ink)); }
.pt.ghost { fill: none; stroke: var(--faint); stroke-width: 1.4; }
.mark .dot { fill: var(--hi); }
.mark .halo { fill: none; stroke: var(--hi); stroke-width: 3; }
.mark:hover .halo { stroke-width: 4; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* ---------- narrow screens ---------- */
@media (max-width: 900px) {
  .site { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .site > .side { grid-row: auto; }
  .site > footer.foot { grid-column: 1; max-width: none; }
  .side { position: static; gap: 14px; margin-bottom: 34px; padding-bottom: 18px; border-bottom: 1px solid var(--rule); }
  .brand { padding-left: 0; }
  .side .label { display: none; }
  .sitenav ol { display: flex; flex-wrap: wrap; gap: 6px; }
  .sitenav a { border: 1px solid var(--rule); border-radius: 999px; padding: 4px 12px; background: var(--surface); }
  .sitenav a:hover, .sitenav a[aria-current] { border-color: var(--structure); }
  nav.toc { display: none; }
  .site > main { max-width: none; }
}
@media (max-width: 640px) {
  .panes { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  body { font-size: 16.5px; padding-inline: 16px; padding-block: 24px 24px; }
  .hero { grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .hero .portrait { order: -1; width: 132px; }
  ol.entries > li { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .entry .when { padding-top: 0; }
  dl.contact { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  dl.contact dd { margin-bottom: 10px; }
  .interactive { padding: 10px; }
  details.material > .body { padding-inline: 12px; }
}

/* ---------- print ---------- */
@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #000; font-size: 11pt; padding: 0; }
  .site { display: block; }
  .side, footer.foot .theme-switch, .controls, .status, .skip, .bibtex-wrap .btn { display: none; }
  .card, figure, ol.entries > li { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}
