/* ==========================================================================
   Personal homepage styles
   Sections: tokens, base, layout, sidebar, content, news, publications,
   footer, figure viewer, responsive, dark mode, print
   ========================================================================== */

/* ---------- Tokens ---------- */

:root {
  --bg: #faf9f6;
  --surface: #ffffff;
  --ink: #15181c;
  --text: #30353c;
  --muted: #667085;
  --faint: #a0a8b4;
  --line: #e7e3da;
  --accent: #002d72;
  --link: #0a4595;
  --link-underline: rgba(10, 69, 149, 0.32);
  --pill-bg: #e8eef8;
  --pill-ink: #0a3a86;
  --selection: #cfe0f7;
  --shadow: 0 1px 2px rgba(21, 24, 28, 0.05), 0 6px 20px rgba(21, 24, 28, 0.06);
  --shadow-hover: 0 2px 4px rgba(21, 24, 28, 0.06), 0 14px 34px rgba(21, 24, 28, 0.13);
  --radius: 12px;

  --font-serif: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-body: var(--font-serif);
}

/* ---------- Base ---------- */

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.09rem;
  line-height: 1.68;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body.font-sans {
  --font-body: var(--font-ui);
  font-size: 1rem;
}

::selection {
  background: var(--selection);
}

img {
  max-width: 100%;
}

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

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 10;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: 500 0.85rem/1.4 var(--font-ui);
  text-decoration: none;
}

.skip-link:focus {
  top: 1rem;
}

/* ---------- Layout ---------- */

.page {
  display: grid;
  grid-template-columns: 15.5rem minmax(0, 1fr);
  column-gap: 4.5rem;
  align-items: start;
  max-width: 68rem;
  margin: 0 auto;
  padding: 4rem 2rem 3rem;
}

.content {
  max-width: 44rem;
  min-width: 0;
}

/* ---------- Sidebar ---------- */

.sidebar {
  position: sticky;
  top: 4rem;
}

.avatar {
  display: block;
  width: 10.5rem;
  height: 10.5rem;
  object-fit: cover;
  border-radius: 18px;
  background: var(--line);
  box-shadow: var(--shadow);
}

.name {
  margin: 1.5rem 0 0.45rem;
  color: var(--ink);
  font: 600 2rem/1.15 var(--font-serif);
  letter-spacing: -0.015em;
}

.role {
  margin: 0;
  color: var(--text);
  font: 400 0.93rem/1.55 var(--font-ui);
}

.role a {
  color: inherit;
  text-decoration: none;
}

.role a:hover {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.tagline {
  margin: 1rem 0 0;
  color: var(--muted);
  font: 600 0.68rem/1.5 var(--font-ui);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.links {
  display: grid;
  gap: 0.1rem;
  margin: 1.5rem 0 0;
  padding: 0;
  list-style: none;
}

.links a {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.28rem 0;
  color: var(--text);
  font: 500 0.88rem/1.4 var(--font-ui);
  text-decoration: none;
  transition: color 0.15s ease;
}

.links i {
  width: 1.1rem;
  color: var(--muted);
  font-size: 1rem;
  text-align: center;
  transition: color 0.15s ease;
}

.links a:hover,
.links a:hover i {
  color: var(--accent);
}

.toc {
  display: grid;
  margin-top: 1.75rem;
  border-left: 1px solid var(--line);
}

.toc[hidden] {
  display: none;
}

.toc a {
  margin-left: -1px;
  padding: 0.28rem 0 0.28rem 1rem;
  border-left: 1px solid transparent;
  color: var(--muted);
  font: 500 0.84rem/1.4 var(--font-ui);
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.toc a:hover {
  color: var(--ink);
}

.toc a.is-active {
  border-left-color: var(--accent);
  color: var(--ink);
}

/* ---------- Content ---------- */

.content h2 {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 3.25rem 0 1.3rem;
  color: var(--accent);
  font: 600 0.74rem/1.2 var(--font-ui);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.content h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.content > h2:first-child {
  margin-top: 0.4rem;
}

.content h3,
.content h4 {
  margin: 1.4rem 0 0.4rem;
  color: var(--ink);
  font: 600 1em/1.4 var(--font-body);
}

.content h2 + h3,
.content h2 + h4 {
  margin-top: 0;
}

.content p {
  margin: 0 0 1.05em;
}

/* Opening paragraph of the page reads as a lede. */
.content > h2:first-child + p {
  color: var(--ink);
  font-size: 1.18em;
  line-height: 1.55;
  letter-spacing: -0.004em;
}

.content a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  transition: text-decoration-color 0.15s ease, color 0.15s ease;
}

.content a:hover {
  text-decoration-color: currentColor;
}

.content ul {
  margin: 0 0 1.05em;
  padding-left: 1.15rem;
}

.content li {
  margin: 0.3em 0;
}

.content li::marker {
  color: var(--faint);
}

.content p + ul {
  margin-top: -0.6em;
}

.content h3 + ul,
.content h4 + ul {
  margin-top: -0.2em;
}

.content .quiet-links a {
  color: inherit;
  text-decoration-color: transparent;
}

.content .quiet-links a:hover {
  color: var(--link);
  text-decoration-color: currentColor;
}

/* ---------- News (a list tagged with the "timeline" class) ---------- */

.content .timeline {
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline li {
  position: relative;
  margin: 0 0 0.85rem;
  padding-left: 6.25rem;
}

.timeline li:last-child {
  margin-bottom: 0;
}

.timeline li > strong:first-child {
  position: absolute;
  top: 0.42em;
  left: 0;
  color: var(--muted);
  font: 600 0.72rem/1.5 var(--font-ui);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* ---------- Publications ---------- */

.pubs {
  margin: 0;
  padding: 0;
  list-style: none;
}

.pub {
  display: grid;
  grid-template-columns: 13.5rem minmax(0, 1fr);
  gap: 1.6rem;
  align-items: start;
  margin: 0;
  padding: 1.5rem 0;
  border-top: 1px solid var(--line);
}

.pub:first-child {
  padding-top: 0.25rem;
  border-top: 0;
}

.pub:last-child {
  padding-bottom: 0;
}

.pub.no-figure {
  grid-template-columns: minmax(0, 1fr);
}

.pub-figure {
  display: block;
  aspect-ratio: 16 / 10;
  padding: 0.6rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  cursor: zoom-in;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.pub-figure:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.pub-figure img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.pub-figure.is-cover {
  padding: 0;
}

.pub-figure.is-cover img {
  object-fit: cover;
}

.content .pub-title {
  margin: 0 0 0.35rem;
  color: var(--ink);
  font: 600 1.14rem/1.35 var(--font-serif);
  letter-spacing: -0.005em;
}

.pub-title a {
  color: inherit;
  text-decoration: none;
}

.pub-title a:hover {
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.content .pub-authors {
  margin: 0 0 0.6rem;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.5;
}

.pub-authors strong {
  color: var(--ink);
  font-weight: 600;
}

.content .pub-venue {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font: 400 0.82rem/1.7 var(--font-ui);
}

.pill {
  display: inline-block;
  margin-right: 0.45rem;
  padding: 0.12rem 0.6rem;
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--pill-ink);
  font: 600 0.72rem/1.6 var(--font-ui);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.content .pub-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
}

.pub-links a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.22rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: 500 0.78rem/1.5 var(--font-ui);
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.pub-links a i {
  color: var(--faint);
  font-size: 0.72rem;
  transition: color 0.15s ease;
}

.pub-links a:hover,
.pub-links a:hover i {
  border-color: var(--accent);
  color: var(--accent);
}

.pub-note {
  color: #b42318;
  font: 600 0.78rem/1.5 var(--font-ui);
}

/* ---------- Footer ---------- */

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.25rem 1.5rem;
  margin-top: 4rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font: 400 0.78rem/1.6 var(--font-ui);
}

.site-footer a {
  color: inherit;
}

/* ---------- Figure viewer ---------- */

.lightbox {
  max-width: 94vw;
  max-height: 94vh;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
}

.lightbox::backdrop {
  background: rgba(10, 13, 18, 0.74);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.lightbox figure {
  position: relative;
  margin: 0;
  padding: 1.1rem;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.lightbox img {
  display: block;
  width: auto;
  height: auto;
  /* 94vw - 2.2rem is the room inside the dialog, so the figure never overflows it. */
  max-width: min(88vw, 94vw - 2.2rem, 87.5rem);
  max-height: 78vh;
}

.lightbox-scroll {
  overflow-x: auto;
}

.lightbox-hint {
  margin: 0.6rem 0 0;
  color: #667085;
  font: 500 0.75rem/1.4 var(--font-ui);
}

.lightbox figcaption {
  max-width: 70ch;
  margin-top: 0.8rem;
  color: #475467;
  font: 500 0.82rem/1.5 var(--font-ui);
}

.lightbox-close {
  position: absolute;
  top: -0.9rem;
  right: -0.9rem;
  display: grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #15181c;
  color: #fff;
  font: 400 1.25rem/1 var(--font-ui);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

/* ---------- Responsive ---------- */

/* Keep the sidebar in the flow when the window is too short to show all of it. */
@media (max-height: 760px) {
  .sidebar {
    position: static;
  }
}

@media (max-width: 1040px) {
  .page {
    grid-template-columns: 13.5rem minmax(0, 1fr);
    column-gap: 3rem;
  }

  .pub {
    grid-template-columns: 11rem minmax(0, 1fr);
    gap: 1.25rem;
  }
}

@media (max-width: 860px) {
  body {
    font-size: 1.06rem;
  }

  .page {
    display: block;
    padding: 2.25rem 1.25rem 2.5rem;
  }

  .sidebar {
    position: static;
    display: grid;
    grid-template-columns: 5.5rem minmax(0, 1fr);
    column-gap: 1.1rem;
    align-items: center;
    margin-bottom: 2.25rem;
    padding-bottom: 1.75rem;
    border-bottom: 1px solid var(--line);
  }

  .avatar {
    width: 5.5rem;
    height: 5.5rem;
    border-radius: 14px;
  }

  .name {
    margin: 0 0 0.25rem;
    font-size: 1.65rem;
  }

  .tagline,
  .links {
    grid-column: 1 / -1;
  }

  .links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 1rem;
  }

  .links a {
    gap: 0.45rem;
    padding: 0.3rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    font-size: 0.8rem;
  }

  .links i {
    width: auto;
    font-size: 0.85rem;
  }

  .toc {
    display: none;
  }

  .content {
    max-width: none;
  }

  .content > h2:first-child {
    margin-top: 0;
  }

  .content > h2:first-child + p {
    font-size: 1.12em;
  }

  /* A very wide figure would be a sliver here: keep it readable, scrolling sideways. */
  .lightbox.is-wide img {
    max-width: none;
    height: min(42vh, 15rem);
  }
}

@media (max-width: 620px) {
  .lightbox-close {
    right: -0.4rem;
  }

  .pub {
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
  }

  .pub-figure {
    aspect-ratio: 16 / 9;
  }

  .timeline li {
    padding-left: 0;
  }

  .timeline li > strong:first-child {
    position: static;
    display: block;
    margin-bottom: 0.1rem;
  }
}

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

  *,
  *::before,
  *::after {
    transition: none !important;
  }
}

/* ---------- Dark mode (follows the visitor's system setting) ---------- */

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #0f1319;
    --surface: #171c24;
    --ink: #f2f4f7;
    --text: #c8cfd8;
    --muted: #8d97a5;
    --faint: #5d6673;
    --line: #262d38;
    --accent: #8ec1f2;
    --link: #8ec1f2;
    --link-underline: rgba(142, 193, 242, 0.38);
    --pill-bg: #17293f;
    --pill-ink: #a9d0f7;
    --selection: #234a7a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.28);
    --shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.3), 0 14px 34px rgba(0, 0, 0, 0.45);
  }

  html[data-theme="auto"] .pub-figure {
    border-color: transparent;
    background: #dde1e8;
  }

  html[data-theme="auto"] .pub-figure img {
    mix-blend-mode: multiply;
  }

  html[data-theme="auto"] .pub-note {
    color: #ff8a7a;
  }
}

/* ---------- Print ---------- */

@media print {
  body {
    background: #fff;
    font-size: 11pt;
  }

  .page {
    display: block;
    padding: 0;
  }

  .sidebar {
    position: static;
    margin-bottom: 1.5rem;
  }

  .toc,
  .skip-link,
  .lightbox {
    display: none;
  }

  .pub {
    break-inside: avoid;
  }
}
