/* ---------- Headings: Computer Modern (the LaTeX typeface) ----------
   Served from jsDelivr, pinned to one commit so it can never change under us. */
@font-face {
  font-family: "CMU Serif";
  src: url("https://cdn.jsdelivr.net/gh/bitmaks/cm-web-fonts@333f55ec19733c28cdc43567ecf72eafd6b0af61/font/Serif/cmunrm.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "CMU Serif";
  src: url("https://cdn.jsdelivr.net/gh/bitmaks/cm-web-fonts@333f55ec19733c28cdc43567ecf72eafd6b0af61/font/Serif/cmunbx.woff") format("woff");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ---------- Tokens ----------
   Dark by default; the toggle in the top bar switches to the light palette
   below (saved per visitor). Two text colours: --fg for everything that
   matters, --muted for secondary text (both well above WCAG AA). One accent,
   --accent, used only for section markers and underlines. */
:root {
  --bg: #1b1b1a;
  --fg: #f2f0ed;
  --title: #ffffff;    /* your name stays bright white in dark mode */
  --muted: #d4d1cb;   /* ~11:1 on --bg */
  --rule: #353432;
  --accent: #cf9384;

  --display: "CMU Serif", "Latin Modern Roman", "Computer Modern Serif", Georgia, serif;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

  --wrap: 1160px;
  --gutter: clamp(1.25rem, 4vw, 3rem);
  --col-gap: clamp(1.5rem, 3vw, 2.5rem);

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f2f1ee;
  --fg: #1d1c1b;
  --title: #1d1c1b;
  --muted: #464440;   /* ~9:1 on --bg */
  --rule: #dcd9d4;
  --accent: #8e3a35;
  color-scheme: light;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 1.5rem;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 17px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--fg); color: var(--bg); }

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
  transition: text-decoration-color 0.2s ease;
}
a:hover { text-decoration-color: currentColor; }
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

ul { list-style: none; margin: 0; padding: 0; }

/* Links inside running text keep the text colour, with an accent underline */
.rich a {
  color: inherit;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.2em;
}
.rich a:hover { text-decoration-thickness: 2px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.wrap {
  max-width: var(--wrap);
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}

/* ---------- Top bar ---------- */
.topbar {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding-top: 1.5rem;
  padding-bottom: 1.5rem;
  font-size: 0.9375rem;
}
/* divider under the menu, spanning the content width like the footer's */
.topbar::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: var(--gutter);
  right: var(--gutter);
  border-bottom: 1px solid var(--rule);
}
.mark { font-weight: 600; text-decoration: none; }
.topbar-end {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 2.5vw, 2rem);
}

/* light/dark switch: a small pill; the dot sits left in dark, right in light */
.theme-toggle {
  position: relative;
  width: 2.1rem;
  height: 1.2rem;
  padding: 0;
  border: 1.5px solid var(--fg);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.2s ease;
}
.theme-toggle:hover { opacity: 1; }
.theme-toggle-knob {
  position: absolute;
  top: 50%;
  left: 0.16rem;
  width: 0.72rem;
  height: 0.72rem;
  border-radius: 50%;
  background: var(--fg);
  transform: translateY(-50%);
  transition: transform 0.2s ease;
}
:root[data-theme="light"] .theme-toggle-knob { transform: translate(0.88rem, -50%); }
.nav { display: flex; gap: clamp(1rem, 2.5vw, 2rem); }
.nav a {
  font-weight: 500;
  text-decoration-color: transparent;
}
.nav a:hover { text-decoration-color: currentColor; }
.nav a[aria-current="page"] {
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
}

/* ---------- Home: photo + name + about ---------- */
.hero {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-rows: auto auto 1fr;
  column-gap: var(--col-gap);
  padding-top: clamp(1.75rem, 5vh, 3.5rem);
  padding-bottom: clamp(2.25rem, 5vh, 3.25rem);
}

.portrait {
  grid-column: 1 / span 3;
  grid-row: 1 / span 3;
  display: block;
  width: 100%;
  max-width: 13rem;
  height: auto;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  border-radius: 8px;
  background: var(--rule);
}

.name {
  grid-column: 4 / -1;
  grid-row: 1;
  margin: -0.35rem 0 0.7rem;
  font: 400 clamp(2.5rem, 4.6vw, 3.75rem)/1.08 var(--display);
  letter-spacing: -0.005em;
  color: var(--title);
}

/* GitHub / LinkedIn / email icons under the name */
.profile-links {
  grid-column: 4 / -1;
  grid-row: 2;
  display: flex;
  align-items: center;
  gap: 1.1rem;
  margin-bottom: 1.4rem;
}
.profile-links a {
  display: block;
  color: var(--muted);
  transition: color 0.2s ease;
}
.profile-links a:hover { color: var(--fg); }
.profile-links svg {
  display: block;
  width: 1.4rem;
  height: 1.4rem;
  fill: currentColor;
}

.about { grid-column: 4 / -1; grid-row: 3; }
.about p {
  max-width: 41rem;
  margin: 0 0 1rem;
  font-size: 1.0625rem;
  line-height: 1.65;
}
.about p:last-child { margin-bottom: 0; }



/* ---------- Projects page heading ---------- */
.page-head {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--col-gap);
  padding-top: clamp(1.75rem, 5vh, 3.5rem);
  padding-bottom: clamp(1rem, 3vh, 1.75rem);
}
.page-head > * { grid-column: 1 / -1; }
.page-title {
  margin: -0.35rem 0 0.75rem;
  font: 400 clamp(2rem, 3.4vw, 2.75rem)/1.08 var(--display);
  letter-spacing: -0.005em;
}
.page-intro {
  max-width: 38rem;
  margin: 0;
  font-size: 1.0625rem;
  color: var(--muted);
}

/* ---------- Sections ---------- */
.section {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--col-gap);
  padding: clamp(3rem, 8vh, 5rem) 0;
  border-top: 1px solid var(--rule);
}

.label {
  grid-column: 1 / span 3;
  align-self: start;
  position: sticky;
  top: 1.5rem;
  margin: 0;
  padding-top: 0.45rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.label::before {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.6rem;
  border-radius: 2px;
  background: var(--accent);
  vertical-align: 0.04em;
}

.section-body {
  grid-column: 4 / -1;
  min-width: 0;
}

.prose p { margin: 0 0 1rem; }
.prose p:last-child { margin-bottom: 0; }

/* ---------- Home: compact list under the About ---------- */
.index { padding-bottom: clamp(2.5rem, 6vh, 4rem); }

.index-row {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--col-gap);
  align-items: center;
  padding: 1.05rem 0;
  border-top: 1px solid var(--rule);
}
.index-row .label {
  grid-column: 1 / span 3;
  position: static;
  align-self: center;
  padding-top: 0;
}

.index-link { grid-column: 4 / -1; }

.index-link {
  display: flex;
  align-items: baseline;
  gap: 0.4rem 1.25rem;
  text-decoration: none;
}
.index-title {
  font: 700 1.2rem/1.3 var(--display);
}
.index-desc {
  flex: 1;
  color: var(--fg);
  font-size: 1rem;
}
.index-arrow {
  font-size: 1.15rem;
  transition: transform 0.25s ease;
}
.index-link:hover .index-title {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}
.index-link:hover .index-arrow { transform: translateX(5px); }

/* ---------- Experience page ---------- */
.xp-role {
  margin: -0.3rem 0 0.4rem;
  font: 700 clamp(1.35rem, 2.1vw, 1.65rem)/1.25 var(--display);
  letter-spacing: 0;
}
.xp-org {
  margin: 0 0 1.25rem;
  font-weight: 500;
}
.xp-points {
  max-width: 44rem;
  padding-left: 1.15rem;
  list-style: disc;
}
.xp-points li + li { margin-top: 0.6rem; }
.xp-points li::marker { color: var(--muted); }
.xp-text { max-width: 44rem; margin: 0; }
/* shorter entries need less air between them */
.compact .section { padding: clamp(2rem, 5vh, 3rem) 0; }
.compact .index { padding-bottom: 0.75rem; }

/* Experience page: a tight list */
.dense .page-head { padding-bottom: 1.25rem; }
.dense .section { padding: 1.3rem 0; }
.dense .label { position: static; padding-top: 0.3rem; }
.dense .xp-role {
  margin: 0 0 0.15rem;
  font-size: 1.2rem;
  line-height: 1.3;
}
.dense .xp-org { margin: 0 0 0.35rem; font-size: 0.9375rem; }
.dense .xp-links { margin-top: 0.45rem; }
.dense .honors-list li { padding: 0.5rem 0; }
.dense .honors-list li:first-child { padding-top: 0; }
.xp-tools {
  margin: 1.25rem 0 0;
  font-size: 0.9375rem;
  color: var(--muted);
}
.xp-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin: 1rem 0 0;
  font-weight: 500;
}

.honors-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.25rem 1.5rem;
  padding: 0.85rem 0;
  border-top: 1px solid var(--rule);
}
.honors-list li:first-child { padding-top: 0; border-top: 0; }
.honor-name { font-weight: 600; }
.honor-note { color: var(--muted); text-align: right; }

/* ---------- Project write-up ---------- */
.feature-title {
  margin: 0 0 0.5rem;
  font: 700 clamp(1.75rem, 3vw, 2.4rem)/1.15 var(--display);
  letter-spacing: 0;
}
.feature-lede {
  max-width: 38rem;
  margin: 0 0 2rem;
  font-size: 1.1875rem;
  line-height: 1.5;
  color: var(--muted);
}

.feature-figure { margin: 0 0 2.75rem; }
.feature-figure > img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.feature-media {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: var(--rule);
  aspect-ratio: 16 / 9;
}
.feature-media video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
}

.media-toggle {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  padding: 0.45rem 0.8rem;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: #fff;
  font: 500 0.8125rem/1 var(--sans);
  cursor: pointer;
  transition: background 0.2s ease;
}
.media-toggle:hover { background: rgba(0, 0, 0, 0.75); }

.feature-figure figcaption,
.diagram figcaption {
  margin-top: 0.75rem;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--muted);
}

.diagram { margin: 2.75rem 0 0; }
.diagram a {
  display: block;
  padding: clamp(0.6rem, 1.6vw, 1.1rem);
  border-radius: 10px;
  background: #fff; /* the diagram itself is drawn on white */
  cursor: zoom-in;
}
.diagram img {
  display: block;
  width: 100%;
  height: auto;
}

/* ---------- Projects page: a list, one row per project ---------- */
.projects {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--col-gap);
}
.project-list {
  grid-column: 1 / -1;
  margin-bottom: clamp(2.5rem, 6vh, 4rem);
  border-top: 1px solid var(--rule);
}
.project-list li { border-bottom: 1px solid var(--rule); }

.project-row {
  display: grid;
  grid-template-columns: minmax(0, 34rem) 15rem;
  justify-content: start;
  gap: 3rem;
  align-items: center;
  padding: 1.5rem 0;
  text-decoration: none;
  color: inherit;
}
.project-row-title {
  display: block;
  margin-bottom: 0.4rem;
  font: 400 clamp(1.45rem, 2.3vw, 1.8rem)/1.2 var(--display);
}
.project-row-desc {
  display: block;
  max-width: 32rem;
  font-size: 1rem;
  line-height: 1.55;
  color: var(--muted);
}
.project-row-thumb {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border: 1px solid var(--rule);
  border-radius: 8px;
  transition: border-color 0.2s ease;
}
.project-row:hover .project-row-title {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}
.project-row:hover .project-row-thumb { border-color: var(--muted); }

/* ---------- Research page: publications ---------- */
.pub-list {
  grid-column: 1 / span 9;
  margin-bottom: clamp(2.5rem, 6vh, 4rem);
  border-top: 1px solid var(--rule);
}
.pub {
  padding: 1.6rem 0;
  border-bottom: 1px solid var(--rule);
}
.pub-title {
  margin: 0 0 0.5rem;
  font: 400 clamp(1.45rem, 2.3vw, 1.8rem)/1.2 var(--display);
}
.pub-title a { text-decoration: none; }
.pub-title a:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}
.pub-authors { margin: 0; }
.pub-authors strong { font-weight: 600; }
.pub-venue { margin: 0.15rem 0 0; color: var(--muted); }
.pub-summary {
  max-width: 42rem;
  margin: 0.9rem 0 0;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--muted);
}
.pub-links {
  display: flex;
  gap: 1.5rem;
  margin: 0.9rem 0 0;
  font-weight: 500;
}

/* ---------- A project's own page ---------- */
.project-page {
  grid-column: 1 / span 9;
  min-width: 0;
  padding: clamp(1.5rem, 4vh, 2.5rem) 0 clamp(2.5rem, 6vh, 4rem);
}
.back-link {
  display: inline-block;
  margin-bottom: 1.25rem;
  font-size: 0.9375rem;
  color: var(--muted);
  text-decoration: none;
}
.back-link:hover { color: var(--fg); }
.project-page .feature-figure { margin-bottom: 2rem; }
.project-meta {
  margin: -1rem 0 2rem;
  font-size: 0.9375rem;
  color: var(--muted);
}
.diagram.diagram-lead { max-width: 34rem; margin: 0 0 2rem; }
.project-links {
  margin: 2rem 0 0;
  font-weight: 500;
}
.project-page .prose { max-width: 40rem; }
.project-page .stats {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 2.25rem;
}

.feature-detail {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: clamp(2rem, 4vw, 3.5rem);
  align-items: start;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.75rem 1.5rem;
  margin: 0;
}
.stat {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-end;
  gap: 0.4rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--fg);
}
.stat dd {
  margin: 0;
  font: 400 clamp(2rem, 3.2vw, 2.6rem)/1 var(--display);
  letter-spacing: 0;
  white-space: nowrap;
}
.stat small {
  margin-left: 0.2rem;
  font: 500 0.875rem/1 var(--sans);
  letter-spacing: 0;
  color: var(--muted);
}
.stat dt {
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--muted);
}

/* ---------- Footer ---------- */
.footer {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem 1.5rem;
  padding-top: 2rem;
  padding-bottom: 2.5rem;
  font-size: 0.9375rem;
  color: var(--muted);
}
/* rule spans the content width, not the side padding */
.footer::before {
  content: "";
  position: absolute;
  top: 0;
  left: var(--gutter);
  right: var(--gutter);
  border-top: 1px solid var(--rule);
}
.footer a {
  color: var(--fg);
  font-weight: 500;
  text-decoration-color: transparent;
}
.footer a:hover { text-decoration-color: currentColor; }

/* ---------- 404 ---------- */
.lost {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.lost .name { margin-bottom: 1.5rem; }
.lost p { margin: 0; font-size: 1.25rem; }

/* ---------- Motion ---------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .reveal {
    animation: rise 0.8s cubic-bezier(0.2, 0.7, 0.2, 1) both;
    animation-delay: calc(var(--i, 0) * 80ms);
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* ---------- Tablet ---------- */
@media (max-width: 900px) {
  .label {
    grid-column: 1 / -1;
    position: static;
    margin-bottom: 1.5rem;
    padding-top: 0;
  }
  .section-body { grid-column: 1 / -1; }
  .page-head > * { grid-column: 1 / -1; }
  .project-list,
  .project-page,
  .pub-list { grid-column: 1 / -1; }
  .dense .label { margin-bottom: 0.5rem; }

  .feature-detail { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ---------- Phone ---------- */
@media (max-width: 640px) {
  body { font-size: 16px; }

  .topbar {
    justify-content: flex-start;
    padding-top: 1.1rem;
    padding-bottom: 1.1rem;
  }
  .mark { display: none; }
  .topbar-end { flex: 1; justify-content: space-between; }
  .nav { gap: 1.25rem; }

  .hero {
    grid-template-columns: 4.5rem minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    column-gap: 1rem;
    row-gap: 0.6rem;
    align-items: center;
    padding-top: 0.75rem;
  }
  .portrait { grid-column: 1; grid-row: 1 / span 2; }
  .name { grid-column: 2; grid-row: 1; align-self: end; margin: 0; font-size: 2.1rem; }
  .profile-links { grid-column: 2; grid-row: 2; align-self: start; margin: 0; gap: 0.95rem; }
  .profile-links svg { width: 1.25rem; height: 1.25rem; }
  .about { grid-column: 1 / -1; grid-row: 3; margin-top: 0.6rem; }
  .about p { font-size: 0.96rem; line-height: 1.55; margin-bottom: 0.75rem; }

  .index-row { row-gap: 0.45rem; padding: 0.95rem 0; }
  .index-row .label,
  .index-link { grid-column: 1 / -1; }
  .index-link { flex-wrap: wrap; }
  .index-desc { flex-basis: 100%; order: 3; }
  .index-arrow { margin-left: auto; }

  .footer { flex-direction: column; }

  .page-head { padding-top: 1rem; }
  .page-title { margin-top: 0; font-size: 1.9rem; }

  .stats,
  .project-page .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .project-row { grid-template-columns: minmax(0, 1fr); gap: 1rem; }

  .honors-list li { flex-direction: column; }
  .honor-note { text-align: left; }
}
