/* ---------------------------------------------------------------------
   Tokens — dark theme is the default; [data-theme="light"] overrides
   below. Everything else in this file reads these variables rather than
   hardcoding colors, so the whole page (including the center column)
   follows whichever theme is active.
--------------------------------------------------------------------- */
:root {
  --paper: #1c1d21;
  --paper-alt: #26272c;
  --ink: #e8e8ea;
  --muted: #9a9ca6;
  --line: #35363d;
  --accent: #8da2ff;
  --accent-dim: #8da2ff26;

  /* Tint laid over the backdrop image so it stays legible/muted behind
     the center column, regardless of the image's own colors. */
  --backdrop-tint: rgba(10, 10, 12, 0.0);
  --content-shadow: 0 25px 70px rgba(0, 0, 0, 0.55);
  /* Swap these two filenames for your own dark/light backdrop images —
     nothing else needs to change, the toggle already switches this. */
  --bg-image: url("images/bg-dark.jpg");

  --font-display: "Space Grotesk", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Ideal max width of the whole centered column on a wide screen — nav,
     hero, about, and every entry row (image + text) all size off this one
     value. Tweak this single number to make the page narrower or wider;
     the entry thumbnail stays exactly 1/3 of it automatically. */
  --content-w: 900px;
  --gutter: clamp(24px, 5vw, 64px);
}

:root[data-theme="light"] {
  --paper: #fafaf8;
  --paper-alt: #f1f1ec;
  --ink: #17181c;
  --muted: #6b6d76;
  --line: #dcdcd6;
  --accent: #2648d6;
  --accent-dim: #2648d61a;

  --backdrop-tint: rgba(255, 255, 255, 0.0);
  --content-shadow: 0 25px 70px rgba(0, 0, 0, 0.15);
  --bg-image: url("images/bg-light.jpg");
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

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

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1.55;

  /* Placeholder backdrop — one image per theme, via --bg-image (declared
     per theme up in :root / [data-theme="light"] above). Swap those two
     url()s for your own images whenever you have them; nothing else
     needs to change. The tint keeps it muted behind the (opaque) center
     column and adapts with the theme. */
  background-color: var(--paper);
  background-image: linear-gradient(var(--backdrop-tint), var(--backdrop-tint)), var(--bg-image);
  /* "cover" is the only setting that guarantees the image always fills
     the full viewport with zero letterbox bands, on any window shape —
     it scales up whichever dimension is short, then crops the other.
     Trade-off: which side gets cropped (and how much) shifts with the
     window's aspect ratio, so a wide window may crop the sides while a
     narrow one crops top/bottom instead. There's no setting that avoids
     all cropping AND guarantees full coverage on every window shape. */
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
}

/* The inline script in index.html's <head> picks the random starting
   backdrop mode before first paint and stores it as html[data-bg-mode].
   "voronoi"/"circles" fully replace body's background with the canvas the
   moment background-live.js runs (see #bg-canvas below) — but that's a
   beat after the page's first paint, so without this rule body's own
   static photo would still get one visible frame first. Hiding it here,
   keyed off the same attribute, means that frame never happens. Left
   alone for "animation": there, body's photo is the deliberate fallback
   while frames are loading, so it should keep showing at first paint. */
html[data-bg-mode="voronoi"] body,
html[data-bg-mode="circles"] body {
  background-image: none;
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  text-decoration-thickness: 2px;
}

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

h1, h2, h3 {
  font-family: var(--font-display);
  line-height: 1.15;
  margin: 0;
  font-weight: 600;
}

p {
  margin: 0 0 1em;
  max-width: 62ch;
}

.mono {
  font-family: var(--font-mono);
}

/* ---------------------------------------------------------------------
   Layout shell: centered single content column
--------------------------------------------------------------------- */
main {
  width: 100%;
  padding: 40px var(--gutter) 80px;
}

.content {
  max-width: var(--content-w);
  margin: 0 auto;
  background: var(--paper);
  box-shadow: var(--content-shadow);
  padding: 56px var(--gutter) 80px;
  /* Explicitly stacked above #bg-canvas (z-index: 0) — see the comment
     there for why this pair of non-negative z-indices, rather than a
     negative one on the canvas, is what actually makes the backdrop
     clickable in its margins while staying behind the visible card. */
  position: relative;
  z-index: 1;
}

@media (max-width: 860px) {
  main {
    padding: 20px var(--gutter) 40px;
  }
  .content {
    padding-top: 32px;
  }
}

/* ---------------------------------------------------------------------
   Theme toggle — corner button, dark is the default theme.

   position: absolute rather than fixed (also true of .bg-controls-panel,
   .bg-hint and .bg-click-hint below) — scrolls away with the rest of the
   page instead of staying pinned to the viewport. On a phone-sized
   screen a pinned button/hint sits on top of the content underneath it
   for the entire scroll, which is much more of a nuisance than on
   desktop; scrolling it away with the page (it's only ever needed near
   the top anyway, right when the backdrop is first seen) avoids that.
   The backdrop itself (#bg-canvas, .bg-anim-layer) stays position: fixed
   — only this UI chrome moves.
--------------------------------------------------------------------- */
.theme-toggle {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 10;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--content-shadow);
}

.theme-toggle:hover {
  border-color: var(--accent);
}

/* The backdrop-mode button sits just to the left of the theme toggle. */
.bg-mode-toggle {
  right: 68px;
}

/* Per-mode controls panel — one instance for "voronoi" (#voronoi-controls:
   "smooth" + "drag") and one for "circles" (#circles-controls: "repulse"),
   each shown only in its own mode (toggled via the [hidden] attribute in
   applyMode(), background-live.js) — never both at once, since only one
   mode is ever active. Sits right below the two round buttons, same spot
   the "try these out!" hint uses (also never at the same time as that:
   switching mode requires clicking a button, which already dismisses the
   hint for good). */
.bg-controls-panel {
  position: absolute;
  top: 62px;
  right: 12px;
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--content-shadow);
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

/* Belt and suspenders: a plain class selector's specificity ties with the
   UA stylesheet's [hidden] rule, and ours is declared later in the
   cascade, so without this explicit override the panel could stay
   visible even while [hidden] is set on it. */
.bg-controls-panel[hidden] {
  display: none;
}

.bg-controls-row {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.bg-controls-row input[type="checkbox"] {
  cursor: pointer;
}

.bg-controls-row input[type="number"] {
  width: 52px;
  background: var(--paper-alt);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 2px 6px;
  cursor: text;
}

/* "try these out!" nudge, sitting right below the two corner buttons.
   Pure decoration (pointer-events is off so it never blocks a click) —
   blinks slowly to draw the eye until either button is used, then just
   disappears — see advanceHintTo() in background-live.js. */
.bg-hint {
  position: absolute;
  top: 62px;
  right: 12px;
  z-index: 9;
  pointer-events: none;
}

.bg-hint.is-hidden {
  display: none;
}

.bg-hint-box {
  padding: 5px 12px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-style: italic;
  /* Always literal black/white (not the theme's --paper, which is an
     off-black/off-white) so it pops against the colorful backdrop
     underneath, in either theme. */
  background: #000;
  color: #fff;
  box-shadow: var(--content-shadow);
  animation: bg-hint-blink 1.8s ease-in-out infinite;
}

:root[data-theme="light"] .bg-hint-box {
  background: #fff;
  color: #000;
}

@keyframes bg-hint-blink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

/* Persistent "click anywhere..." reminder — see updateClickHint() in
   background-live.js. Unlike .bg-hint above (which nudges once, below the
   buttons, then vanishes for good), this one sticks around for as long as
   a click-driven mode ("voronoi"/"circles") stays active, sitting to the
   LEFT of the two corner buttons instead. Only "right" is set (no width),
   so it hugs the buttons and grows further left as needed for the text —
   same reasoning as .theme-toggle/.bg-mode-toggle being corner-anchored. */
.bg-click-hint {
  position: absolute;
  top: 20px;
  right: 116px;
  z-index: 9;
  height: 40px;
  display: flex;
  align-items: center;
  pointer-events: none;
}

.bg-click-hint[hidden] {
  display: none;
}

.bg-click-hint-box {
  padding: 5px 12px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-style: italic;
  white-space: nowrap;
  /* Same literal black/white treatment as .bg-hint-box, for the same
     reason: needs to pop against whichever colorful backdrop is behind it
     in either theme. */
  background: #000;
  color: #fff;
  box-shadow: var(--content-shadow);
}

:root[data-theme="light"] .bg-click-hint-box {
  background: #fff;
  color: #000;
}

/* ---------------------------------------------------------------------
   Interactive backdrop canvas (Voronoi / Delaunay-circles modes) — see
   background-live.js. Hidden by default; shown only while one of those
   modes is active, at which point it fully replaces the plain
   background-image on body (drawing its own solid --paper fill each
   frame).

   Deliberately z-index: 0 rather than a negative value: a NEGATIVE
   z-index on a fixed/absolute element paints it behind <body>'s own box
   in the stacking order, even though body has no visible background —
   body (and main, and anything else non-positioned) still sits in a
   higher paint layer and silently swallows every click across its full
   invisible box. Using 0 here (a normal, non-negative stacking level)
   and promoting .content to z-index: 1 gets the same visual result —
   canvas behind the content card — while keeping the canvas reachable
   by clicks everywhere main's transparent padding would otherwise have
   intercepted them.
--------------------------------------------------------------------- */
#bg-canvas {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  touch-action: none;
}

/* "animation" mode's two cross-faded frame layers — see the comment on
   these elements in index.html and updateAnimationFrame() in
   background-live.js. Same z-index reasoning as #bg-canvas above (0, not
   negative, so main's padding stays clickable); position: fixed keeps
   each layer pinned to the viewport as its own element, so — unlike
   body's background-attachment: fixed — no attachment property is needed
   to stop it scrolling with the page. Layer B sits on top and fades in
   over layer A as its own opacity, driven directly by scroll position. */
.bg-anim-layer {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  pointer-events: none;
}

#bg-anim-layer-b {
  opacity: 0;
}

/* ---------------------------------------------------------------------
   Top contact bar — email, links, CV, in a horizontal line above the hero
--------------------------------------------------------------------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  padding-bottom: 24px;
  margin-bottom: 40px;
  border-bottom: 1px solid var(--line);
}

.topbar a {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
  padding-left: 18px;
  border-left: 1px solid var(--line);
}

.topbar a:first-child {
  padding-left: 0;
  border-left: none;
}

.topbar a:hover {
  color: var(--accent);
}

.topbar a.cv-button {
  color: var(--ink);
  border: 1px solid var(--ink);
  padding: 6px 12px;
  margin-left: auto;
}

.topbar a.cv-button:hover {
  background: var(--ink);
  color: var(--paper);
}

/* ---------------------------------------------------------------------
   Hero
--------------------------------------------------------------------- */
.hero {
  display: flex;
  gap: 32px;
  align-items: start;
  margin-bottom: 40px;
}

.hero-visuals {
  display: flex;
  flex: 0 0 33%; /* profile picture column = 1/3 of the content width */
  min-width: 0; /* same fix as .entry-thumb: don't let a real photo's
    intrinsic size override the 33% flex-basis */
  gap: 16px;
}

.profile-pic-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  overflow: hidden;
  flex-shrink: 0;
}

.profile-pic-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero h1 {
  font-size: clamp(1.8rem, 3vw, 2.4rem);
  margin-bottom: 6px;
}

.hero-role {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.hero .tagline {
  color: var(--muted);
  font-size: 1.05rem;
  max-width: 52ch;
}

@media (max-width: 640px) {
  .hero {
    flex-direction: column;
  }
  .hero-visuals {
    order: -1;
    flex-basis: auto;
    width: 33%;
  }
}

@media (max-width: 860px) {
  section {
    scroll-margin-top: 72px;
  }
}

/* ---------------------------------------------------------------------
   Sections
--------------------------------------------------------------------- */
section {
  margin-bottom: 64px;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
  margin-bottom: 22px;
}

.section-heading h2 {
  font-size: 1.15rem;
}

.section-count {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
}

/* About */
.about-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.about-list li {
  padding-left: 18px;
  border-left: 2px solid var(--line);
}

/* Bibliographic list rows: papers, projects, awards */
.entry-list {
  display: flex;
  flex-direction: column;
}

.entry {
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  gap: 24px;
}

.entry-main {
  flex: 1;
  min-width: 0; /* let text wrap/shrink instead of overflowing the row */
}

.entry-thumb {
  flex: 0 0 33%; /* fixed one-third of the row width, always — a wide
    image no longer pushes the text below it, since the two sit in
    separate flex columns rather than the text flowing/wrapping around
    a float. */
  /* Flex items default to min-width:auto, which for a replaced element
     like <img> resolves to its own intrinsic (natural pixel) size — that
     silently overrides flex-basis as a floor, so a large real photo would
     balloon past 33% and squeeze the text to nothing. min-width:0 removes
     that floor so flex-basis:33% is actually what wins. */
  min-width: 0;
  /* height is intentionally NOT set: with only width fixed, the browser
     computes height purely from the image's own intrinsic aspect ratio,
     so nothing is ever cropped or stretched — a wide image just ends up
     shorter, a tall one ends up taller, exactly as it should. */
  border: 1px solid var(--line);
  background: var(--paper-alt);
}

@media (max-width: 560px) {
  .entry {
    flex-direction: column;
  }
  .entry-thumb {
    flex-basis: auto;
    width: 100%;
  }
}

.entry:first-child {
  padding-top: 0;
}

.entry-year {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--muted);
  padding-top: 2px;
}

.entry-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.entry-meta {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.entry-desc {
  font-size: 0.94rem;
  color: var(--ink);
  margin-bottom: 8px;
}

.entry-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 8px;
}

.entry-links a {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  margin-right: 14px;
}

.entry-toggle {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  background: none;
  border: none;
  padding: 0;
  margin-right: 14px;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.entry-toggle:hover {
  color: var(--accent);
}

.entry-panel {
  margin-top: 12px;
  padding: 14px 16px;
  background: var(--paper-alt);
  border: 1px solid var(--line);
}

.entry-panel p {
  margin: 0;
  font-size: 0.9rem;
  max-width: none;
}

.entry-bibtex {
  margin: 0 0 10px;
  padding: 0;
  font-size: 0.76rem;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
  color: var(--ink);
}

.entry-copy {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--ink);
  padding: 4px 10px;
  cursor: pointer;
}

.entry-copy:hover {
  background: var(--ink);
  color: var(--paper);
}

.entry.is-archived {
  opacity: 0.55;
}

/* Timeline (Experience — genuinely sequential) */
.timeline {
  position: relative;
  padding-left: 26px;
  border-left: 1px solid var(--line);
}

.timeline-item {
  position: relative;
  padding-bottom: 32px;
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: -30px;
  top: 4px;
  width: 9px;
  height: 9px;
  background: var(--accent);
  border-radius: 50%;
}

.timeline-dates {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.timeline-role {
  font-weight: 600;
  margin-bottom: 2px;
}

.timeline-org {
  color: var(--muted);
  font-size: 0.92rem;
  margin-bottom: 6px;
}

footer {
  border-top: 1px solid var(--line);
  padding-top: 20px;
  margin-top: 40px;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
