/* ── Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 64px;
}

body {
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  font-size: 1.06rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Variables ── */
:root {
  color-scheme: light;
  --accent:            #1a535c;
  --accent-dark:       #0f3d44;
  --text:              #1a1a2e;
  --text-muted:        #4a4a6a;
  --bg:                #ffffff;
  --bg-alt:            #f4f6f7;
  --border:            #dfe3e8;
  --nav-bg:            rgba(255, 255, 255, 0.92);
  --nav-bg-mobile:     rgba(255, 255, 255, 0.97);
  --surface:           #ffffff;
  --code-bg:           #f3f5f7;
  --footer-bg:         #1a1a2e;
  --footer-text:       rgba(255, 255, 255, 0.72);
  --btn-text:          #ffffff;
  --accent-subtle:     rgba(26, 83, 92, 0.10);
  --accent-hover:      rgba(26, 83, 92, 0.08);
  --badge-bg:          rgba(0, 0, 0, 0.05);
  --badge-border:      rgba(0, 0, 0, 0.12);
  --badge-hover-bg:    rgba(0, 0, 0, 0.10);
  --badge-hover-border: rgba(0, 0, 0, 0.20);
  --photo-shadow:      rgba(0, 0, 0, 0.10);
  --dropdown-shadow:   rgba(0, 0, 0, 0.08);
  --nav-h:             60px;
  --max-w:             1100px;
  --radius:            8px;
}

/* ── Typography ── */
h1 { font-size: 2.5rem;  font-weight: 700; line-height: 1.2; font-family: 'Source Serif 4', Georgia, serif; }
h2 { font-size: 1.75rem; font-weight: 700; line-height: 1.3; margin-bottom: 1.25rem; font-family: 'Source Serif 4', Georgia, serif; }
h3 { font-size: 1.1rem; font-weight: 600; }

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s;
}
a:hover { color: var(--accent-dark); }

/* ── Layout ── */
.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 1.5rem;
}

section {
  padding: 5rem 0;
}

section.alt-bg {
  background: var(--bg-alt);
}

/* ── Navigation ── */
#navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: var(--nav-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
  display: flex;
  align-items: center;
  padding: 0 2rem;
  gap: 1rem;
}

.nav-brand {
  font-family: 'Source Serif 4', Georgia, serif;
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
}
.nav-brand:hover { color: var(--accent); }

.nav-links {
  list-style: none;
  display: flex;
  gap: 0.25rem;
  align-items: center;
  margin-left: auto;
}

.nav-links a {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.nav-links a:hover,
.nav-links a.active {
  color: var(--accent);
  background: var(--accent-hover);
}

.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.25s, opacity 0.25s;
}
.nav-toggle[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.nav-toggle[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
}
.nav-toggle[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ── About Section ── */
#about {
  padding-top: calc(var(--nav-h) + 4rem);
}

.about-layout {
  display: flex;
  align-items: flex-start;
  gap: 2.5rem;
}

.about-photo-wrap {
  flex-shrink: 0;
}

.about-photo,
.about-photo-fallback {
  width: 190px;
  height: 190px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent);
  box-shadow: 0 4px 20px var(--photo-shadow), 0 0 0 1px var(--accent-subtle);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.about-photo:hover {
  transform: scale(1.03);
  box-shadow: 0 6px 24px var(--photo-shadow), 0 0 0 3px var(--accent-subtle);
}

.about-photo-fallback {
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--bg-alt);
  color: var(--accent);
  font-size: 2rem;
  font-weight: 700;
}

.about-text h1 {
  margin-bottom: 0.35rem;
}

.about-position {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.about-affil {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.about-bio {
  margin-bottom: 1.5rem;
  color: var(--text);
}

.social-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.social-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.3rem 0.75rem;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.social-link:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-hover);
}
.social-link i {
  font-size: 0.95em;
}

/* ── Research Section ── */
.research-blurb {
  margin-bottom: 1.5rem;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag {
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--accent-subtle);
  color: var(--accent-dark);
  border-radius: 20px;
  padding: 0.25rem 0.75rem;
}

/* ── Education Timeline ── */
.timeline {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 9px;
  top: 14px;
  bottom: 14px;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  display: flex;
  gap: 1.25rem;
  padding-bottom: 2rem;
  position: relative;
}
.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 2px var(--accent);
  flex-shrink: 0;
  margin-top: 2px;
  position: relative;
  z-index: 1;
}

.alt-bg .timeline-dot {
  border-color: var(--bg-alt);
}

.timeline-body {
  flex: 1;
}

.timeline-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.2rem;
}

.timeline-degree {
  font-weight: 600;
  font-size: 1rem;
}

.timeline-date {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.timeline-inst {
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.15rem;
  font-size: 0.95rem;
}

.timeline-detail {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ── Publications ── */
.section-note {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
}

.pub-list {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  margin-bottom: 2rem;
}

.pub-card {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}
.pub-list .pub-card:first-child {
  border-top: 1px solid var(--border);
}

.pub-authors {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.pub-authors strong {
  color: var(--text);
}

.pub-title {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.4;
  margin-bottom: 0.3rem;
}
.pub-title-link {
  color: inherit;
  transition: color 0.15s;
}
.pub-title-link:hover {
  color: var(--accent);
}

.pub-venue {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.pub-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pub-badge {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 2px 10px;
  border-radius: 20px;
  background: var(--badge-bg);
  color: var(--text-muted);
  border: 1px solid var(--badge-border);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.pub-badge:hover {
  background: var(--badge-hover-bg);
  color: var(--text);
  border-color: var(--badge-hover-border);
}

.subsection-title {
  font-weight: 600;
  margin-bottom: 0.875rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.8rem;
}

.subsection-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4em;
  padding: 0 0.45em;
  margin-left: 0.35em;
  border-radius: 20px;
  background: var(--accent-subtle);
  color: var(--accent-dark);
  font-size: 0.9em;
  font-weight: 700;
  letter-spacing: 0;
  vertical-align: middle;
  position: relative;
  top: -0.08em;
}
.subsection-count:empty {
  display: none;
}

/* Spaced variant — used when a subsection heading follows another block */
.subsection-title--spaced {
  margin-top: 2.5rem;
}

/* ── Collapsible publication subsections (native <details>) ── */
.pub-section > summary.subsection-title {
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.pub-section > summary.subsection-title::-webkit-details-marker {
  display: none;
}
.pub-section > summary.subsection-title::after {
  content: "";
  display: inline-block;
  width: 0.42em;
  height: 0.42em;
  margin-left: 0.55em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  opacity: 0.5;
  vertical-align: middle;
  position: relative;
  top: -0.15em;
  transition: transform 0.2s ease;
}
.pub-section:not([open]) > summary.subsection-title::after {
  transform: rotate(-45deg);
}
.pub-section > summary.subsection-title:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ── Collapsible talks subsections (native <details>) ── */
.talks-section > summary.talks-subheading {
  cursor: pointer;
  list-style: none;
  user-select: none;
  margin-top: 0;
}
.talks-section > summary.talks-subheading::-webkit-details-marker {
  display: none;
}
.talks-section > summary.talks-subheading::after {
  content: "";
  display: inline-block;
  width: 0.42em;
  height: 0.42em;
  margin-left: 0.55em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  opacity: 0.5;
  vertical-align: middle;
  position: relative;
  top: -0.15em;
  transition: transform 0.2s ease;
}
.talks-section:not([open]) > summary.talks-subheading::after {
  transform: rotate(-45deg);
}
.talks-section > summary.talks-subheading:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}
.talks-section + .talks-section {
  margin-top: 1.75rem;
}

/* ── Teaching (card grid, distinct from the timeline) ── */
.teaching-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.875rem;
}

.teaching-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.teaching-card:hover {
  box-shadow: 0 3px 12px var(--dropdown-shadow);
  border-color: var(--accent);
}

.teaching-year {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--accent-dark);
  background: var(--accent-subtle);
  border-radius: 20px;
  padding: 1px 0.65em;
}

.teaching-course {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.3;
}

.teaching-inst {
  font-size: 0.83rem;
  color: var(--text-muted);
}

/* ── Talks ── */
.talks-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.talk-item {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}
.talk-item:first-child {
  border-top: 1px solid var(--border);
}

.talk-date {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  min-width: 70px;
  font-variant-numeric: tabular-nums;
}

.talk-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.talk-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.talk-role-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 20px;
  background: var(--badge-bg);
  color: var(--text-muted);
  border: 1px solid var(--badge-border);
  white-space: nowrap;
}

.talk-slides-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  transition: color 0.15s, border-color 0.15s;
}
.talk-slides-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.talk-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.talk-name-link {
  color: inherit;
  transition: color 0.15s;
}
.talk-name-link:hover {
  color: var(--accent);
}

.talk-loc {
  font-size: 0.83rem;
  color: var(--text-muted);
}

/* ── Talks subheadings ── */
.talks-subheading {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-top: 1.75rem;
  margin-bottom: 0.25rem;
}
.talks-subheading:first-of-type {
  margin-top: 0;
}

/* ── Author links — inherit muted color, only accent on hover ── */
.pub-authors a {
  color: inherit;
}
.pub-authors a:hover {
  color: var(--accent);
}

/* ── Cite button (inherits .pub-badge, just needs button resets) ── */
button.pub-badge {
  cursor: pointer;
  font-family: inherit;
  line-height: 1;
}

/* ── Citation Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 20, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.modal-overlay[hidden] {
  display: none;
}

.modal-box {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.18);
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-weight: 600;
  font-size: 0.9rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 0.25rem;
  transition: color 0.15s;
}
.modal-close:hover {
  color: var(--text);
}

.modal-pre {
  margin: 0;
  padding: 1.25rem;
  background: var(--code-bg);
  font-family: 'Fira Mono', 'Consolas', 'Menlo', monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  white-space: pre;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.modal-footer {
  padding: 0.75rem 1.25rem;
  display: flex;
  justify-content: flex-end;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--accent);
  color: var(--btn-text);
  border: none;
  border-radius: 6px;
  padding: 0.45rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
}
.copy-btn:hover {
  background: var(--accent-dark);
}
.copy-btn.copied {
  background: #2d6a4f;
  color: #ffffff;
}

/* ── About text fill ── */
.about-text {
  flex: 1;
  min-width: 0;
}

/* ── Secondary page first sections (cv.html, events.html) ── */
#education,
#upcoming,
#download {
  padding-top: calc(var(--nav-h) + 4rem);
}

.cv-section {
  text-align: center;
}
.cv-section h2 { margin-bottom: 0.5rem; }
.cv-section p { color: var(--text-muted); margin-bottom: 1.5rem; }

.cv-button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--accent);
  color: var(--btn-text);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.65rem 1.75rem;
  border-radius: 8px;
  transition: background 0.15s, transform 0.1s;
}
.cv-button:hover { background: var(--accent-dark); color: var(--btn-text); transform: translateY(-1px); }

/* ── "See all" link below truncated lists ── */
.see-all-link {
  display: inline-block;
  margin-top: 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--accent);
}
.see-all-link:hover {
  color: var(--accent-dark);
}

/* ── Loading placeholder ── */
.loading-msg {
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 0.5rem 0;
}

/* ── Footer ── */
footer {
  background: var(--footer-bg);
  color: var(--footer-text);
  font-size: 0.82rem;
  padding: 2.5rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.footer-inner {
  text-align: center;
}
.footer-links {
  display: flex;
  justify-content: center;
  gap: 1.25rem;
  margin-bottom: 0.75rem;
}
.footer-links a {
  color: var(--footer-text);
  font-size: 1.1rem;
  transition: color 0.15s;
}
.footer-links a:hover {
  color: #ffffff;
}

/* ── Scroll animations ── */
.fade-in-section {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.7s ease-out, transform 0.7s ease-out;
}
.fade-in-section.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Theme toggle ── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.85rem;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  flex-shrink: 0;
  padding: 0;
}
.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-hover);
}

/* ── Dark mode ── */
[data-theme="dark"] {
  color-scheme: dark;
  --accent:            #4ecdc4;
  --accent-dark:       #3db8b0;
  --text:              #e0e4e8;
  --text-muted:        #8b92a0;
  --bg:                #0f1419;
  --bg-alt:            #161b22;
  --border:            #2a2f38;
  --nav-bg:            rgba(15, 20, 25, 0.92);
  --nav-bg-mobile:     rgba(22, 27, 34, 0.97);
  --surface:           #1a1f27;
  --code-bg:           #1a1f27;
  --footer-bg:         #0a0e12;
  --footer-text:       rgba(224, 228, 232, 0.6);
  --btn-text:          #0f1419;
  --accent-subtle:     rgba(78, 205, 196, 0.10);
  --accent-hover:      rgba(78, 205, 196, 0.08);
  --badge-bg:          rgba(255, 255, 255, 0.06);
  --badge-border:      rgba(255, 255, 255, 0.12);
  --badge-hover-bg:    rgba(255, 255, 255, 0.12);
  --badge-hover-border: rgba(255, 255, 255, 0.20);
  --photo-shadow:      rgba(0, 0, 0, 0.30);
  --dropdown-shadow:   rgba(0, 0, 0, 0.30);
}

[data-theme="dark"] .about-photo {
  filter: brightness(0.9) contrast(1.05);
}

/* ── Mobile ── */
@media (max-width: 640px) {
  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.3rem; }

  section { padding: 3.5rem 0; }
  #about  { padding-top: calc(var(--nav-h) + 2.5rem); }

  #navbar {
    padding: 0 1.25rem;
  }

  .nav-toggle {
    display: flex;
    order: 2;
  }

  .theme-toggle {
    margin-left: auto;
    order: 1;
  }

  .nav-links {
    display: none;
    position: fixed;
    top: var(--nav-h);
    left: 0;
    right: 0;
    background: var(--nav-bg-mobile);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    flex-direction: column;
    align-items: stretch;
    padding: 1rem 1.5rem 1.5rem;
    border-bottom: 1px solid var(--border);
    gap: 0.25rem;
    box-shadow: 0 8px 24px var(--dropdown-shadow);
  }

  .nav-links.open {
    display: flex;
  }

  .nav-links a {
    font-size: 1rem;
    padding: 0.6rem 0.75rem;
  }

  .about-layout {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 1.5rem;
  }

  .social-links {
    justify-content: center;
  }

  .about-bio {
    max-width: 100%;
  }

  .timeline-row {
    flex-direction: column;
    gap: 0.1rem;
  }

  .talk-item {
    flex-direction: column;
    gap: 0.3rem;
  }
}

/* ════════════════════════════════════════════════════
   Research page (research.html)
   ════════════════════════════════════════════════════ */

:root {
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --fig-surface: #ffffff;
}
[data-theme="dark"] {
  --series-1: #3987e5;
  --series-2: #d95926;
  --fig-surface: #1a1f27;
}

#overview { padding-top: calc(var(--nav-h) + 4rem); }
#overview h1 { margin-bottom: 1.25rem; }

.research-lead { max-width: 52rem; margin-bottom: 1rem; }
.research-intro { max-width: 52rem; margin-bottom: 0.5rem; }

.research-more-link { margin-top: 1.25rem; }

/* Inline math set in the serif face */
.m {
  font-family: 'Source Serif 4', Georgia, serif;
  font-style: italic;
  white-space: nowrap;
}
.m b { font-style: normal; font-weight: 700; }
.m sub { font-size: 0.7em; }

.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-top: 2.25rem;
}
.theme-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1.15rem 1.25rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.theme-card:hover {
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 3px 12px var(--dropdown-shadow);
  transform: translateY(-2px);
}
.theme-kicker,
.section-kicker {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.section-kicker { margin-bottom: 0.25rem; }
.theme-title {
  font-family: 'Source Serif 4', Georgia, serif;
  font-weight: 600;
  font-size: 1.1rem;
  line-height: 1.3;
}
.theme-desc { font-size: 0.875rem; color: var(--text-muted); line-height: 1.55; }

/* One piece of work: text beside its figure */
.research-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 2.75rem;
  align-items: start;
  padding-top: 3rem;
  margin-top: 3rem;
  border-top: 1px solid var(--border);
}
.research-item--flip .research-text { order: 2; }
.research-text h3 {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 1.3rem;
  line-height: 1.3;
  margin-bottom: 0.75rem;
}
.research-text p { margin-bottom: 0.9rem; }

.research-ref { margin: 1.1rem 0 1.25rem; }
.research-ref .pub-card {
  border: 0;
  border-left: 3px solid var(--accent);
  padding: 0.15rem 0 0.15rem 0.9rem;
}

/* Figures and their controls */
.research-fig {
  min-width: 0;
}

/* Figures sit directly on the section background: the surface used for
   mark gaps and tooltips follows the section the figure is in */
section { --fig-surface: var(--bg); }
section.alt-bg { --fig-surface: var(--bg-alt); }
.research-fig figcaption,
.research-embed .embed-head p {
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--text-muted);
}
.research-fig figcaption { margin-top: 0.75rem; }

.fig-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}
.fig-controls[hidden] { display: none; }
.fig-controls-label { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); }
.chart-wrap + .fig-controls { margin: 0.75rem 0 0.5rem; }

.seg {
  display: inline-flex;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px;
  gap: 2px;
  background: var(--bg-alt);
}
.seg-btn {
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-muted);
  background: none;
  border: 0;
  border-radius: 18px;
  padding: 0.3rem 0.8rem;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.seg--small .seg-btn { font-size: 0.75rem; padding: 0.25rem 0.65rem; }
.seg-btn:hover { color: var(--accent); }
.seg-btn.is-active { background: var(--accent); color: var(--btn-text); }
.seg-btn:focus-visible,
.embed-load:focus-visible,
#cut-svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Renderings come on a white background; keep it in dark mode too */
.fig-frame {
  border-radius: 6px;
  overflow: hidden;
}
/* Renderings have a white background: in light mode, multiply it away so the
   picture sits on the section colour; in dark mode keep a white panel */
.fig-frame img { mix-blend-mode: multiply; }
[data-theme="dark"] .fig-frame { background: #ffffff; }
[data-theme="dark"] .fig-frame img { mix-blend-mode: normal; }
.fig-frame img {
  display: block;
  width: 100%;
  height: auto;
  transition: opacity 0.2s;
}
.fig-frame img.is-swapping { opacity: 0.35; }
/* Switchers whose pictures differ in shape: the frame keeps the shape of the
   tallest one and each picture is fitted inside, so switching never moves the page */
.fig-frame--fixed { aspect-ratio: var(--ar); }
.fig-frame--fixed img { height: 100%; object-fit: contain; }

/* Switched captions and button rows: all variants share one grid cell, the
   inactive ones are invisible but still take up room (see stackCaption) */
.caption-stack, .fig-controls-stack { display: grid; }
.caption-stack > span, .fig-controls-stack > .fig-controls { grid-area: 1 / 1; }
.caption-stack > .is-off, .fig-controls-stack > .is-off { visibility: hidden; }

.fig-readout {
  min-height: 3em;
  font-size: 0.9rem;
  font-weight: 500;
  margin-top: 0.6rem;
  font-variant-numeric: tabular-nums;
}
.fig-readout strong { color: var(--accent); }

.fig-legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.fig-legend li { display: inline-flex; align-items: center; gap: 0.4rem; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.swatch--inner { background: var(--cut-inner); }
.swatch--cut   { background: var(--cut-cut); }
.swatch--small { background: var(--series-2); }

/* Cost chart */
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
#cost-chart text { font-family: 'DM Sans', system-ui, sans-serif; font-size: 11px; fill: var(--text-muted); }
#cost-chart .axis-title { font-size: 11.5px; font-weight: 600; }
#cost-chart .direct-label { font-size: 12px; font-weight: 600; fill: var(--text); }
#cost-chart .grid { stroke: var(--border); stroke-width: 1; }
#cost-chart .axis { stroke: var(--text-muted); stroke-width: 1; opacity: 0.6; }
#cost-chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
#cost-chart .line--2d { stroke: var(--series-1); }
#cost-chart .line--3d { stroke: var(--series-2); }
#cost-chart .line--extra { stroke-dasharray: 2 5; }
#cost-chart .dot { stroke: var(--fig-surface); stroke-width: 2; }
#cost-chart .dot--2d { fill: var(--series-1); }
#cost-chart .dot--3d { fill: var(--series-2); }
#cost-chart .target { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 4 4; opacity: 0.8; }
#cost-chart .cross { fill: var(--fig-surface); stroke: var(--series-1); stroke-width: 2; }
#cost-chart .hit { fill: transparent; cursor: default; }

.chart-tip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 14px var(--dropdown-shadow);
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 12px));
  z-index: 5;
}
.chart-tip[hidden] { display: none; }
.chart-tip b { font-weight: 600; }

/* Cut-mesh demo */
:root { --cut-inner: rgba(26, 83, 92, 0.16); --cut-cut: rgba(26, 83, 92, 0.55); }
[data-theme="dark"] { --cut-inner: rgba(78, 205, 196, 0.16); --cut-cut: rgba(78, 205, 196, 0.5); }
#cut-svg { touch-action: none; cursor: grab; border-radius: 6px; }
#cut-svg.is-dragging { cursor: grabbing; }
#cut-svg .tri { stroke: var(--border); stroke-width: 1; fill: none; }
#cut-svg .tri--inner { fill: var(--cut-inner); }
#cut-svg .tri--cut   { fill: var(--cut-cut); }
#cut-svg .tri--small { fill: var(--series-2); }
#cut-svg .bnd { fill: none; stroke: var(--text); stroke-width: 2; }
#cut-radius { flex: 1; min-width: 120px; accent-color: var(--accent); }

/* Click-to-load embeds */
.research-embed {
  margin-top: 3rem;
  padding-top: 3rem;
  border-top: 1px solid var(--border);
}
.embed-head h3 { font-family: 'Source Serif 4', Georgia, serif; font-size: 1.3rem; margin-bottom: 0.25rem; }
.embed-head { margin-bottom: 1rem; }
.embed-slot {
  position: relative;
  height: 560px;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  background:
    repeating-linear-gradient(135deg, transparent 0 14px, var(--accent-subtle) 14px 15px),
    var(--bg-alt);
}
.embed-slot--square { height: auto; aspect-ratio: 1 / 1; }
.embed-slot--wide { height: auto; aspect-ratio: 4 / 3; }
#drum-embed .embed-slot:not(.is-loaded) { height: 180px; }
.embed-slot.is-loaded { background: #ffffff; }
.embed-slot iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.embed-load {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--accent);
  color: var(--btn-text);
  border: 0;
  border-radius: 8px;
  padding: 0.65rem 1.5rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.embed-load:hover { background: var(--accent-dark); transform: translateY(-1px); }
.embed-alt { font-size: 0.8rem; color: var(--text-muted); }
a.embed-alt:hover { color: var(--accent); }

/* Work-in-progress notice at the top of research.html */
.wip-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid #e0b25c;
  border-left-width: 4px;
  border-radius: var(--radius);
  background: rgba(240, 180, 60, 0.14);
  font-size: 0.92rem;
}
.wip-banner i { color: #b7791f; font-size: 1.05rem; }
[data-theme="dark"] .wip-banner { border-color: #a27a2e; background: rgba(240, 180, 60, 0.10); }
[data-theme="dark"] .wip-banner i { color: #e0b25c; }

/* Collapsible explainer (nematic sketches) */
.explainer {
  margin-top: 2rem;
  border-radius: var(--radius);
  background: var(--accent-subtle);
}
.explainer summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  cursor: pointer;
  list-style: none;
}
.explainer summary::-webkit-details-marker { display: none; }
.explainer-title { font-family: 'Source Serif 4', Georgia, serif; font-size: 1.15rem; font-weight: 600; }
.explainer-hint {
  flex-shrink: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}
.explainer-hint::after { content: ' ▾'; }
.explainer[open] .explainer-hint { font-size: 0; }
.explainer[open] .explainer-hint::after { content: 'Hide ▴'; font-size: 0.85rem; }
.explainer summary:hover .explainer-title { color: var(--accent); }
.explainer-body { padding: 0 1.25rem 1.25rem; }
.explainer-body > p { max-width: 52rem; margin-bottom: 0.75rem; }
.sketch-groups {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-top: 1.25rem;
}
.sketch-group h4 { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.5rem; }
.sketch-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.sketch-pair figure { margin: 0; }
.sketch-pair canvas { display: block; width: 100%; }
.sketch-pair figcaption { margin-top: 0.35rem; text-align: center; font-size: 0.8rem; color: var(--text-muted); }
@media (max-width: 760px) {
  .sketch-groups { grid-template-columns: 1fr; gap: 1.25rem; }
}

/* Explainer with text and a figure side by side */
.explainer-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  align-items: start;
}
.explainer-split > div > p { margin-bottom: 0.75rem; }
#surface-widget .fig-frame { max-width: 21rem; margin: 0 auto; }
@media (max-width: 860px) {
  .explainer-split { grid-template-columns: 1fr; gap: 1.25rem; }
}

/* Helmholtz–Hodge decomposition, full width: field = rot + harm + grad */
.decomp { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.decomp > p { max-width: 52rem; margin-bottom: 1rem; }
.decomp-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
}
.decomp-row figure { margin: 0; }
.decomp-row img { display: block; width: 100%; height: auto; }
.decomp-row figcaption {
  margin-top: 0.4rem;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.35;
}
.decomp-row figcaption span { font-weight: 400; font-size: 0.78rem; color: var(--text-muted); }
.decomp-op { font-size: 1.6rem; color: var(--text-muted); padding-bottom: 2.2rem; }
@media (max-width: 760px) {
  .decomp-row { grid-template-columns: 1fr 1fr; row-gap: 1.25rem; }
  .decomp-op { display: none; }
}

/* Axisymmetric reduction animation */
#axisym-canvas { display: block; width: 100%; aspect-ratio: 5 / 3; }
#unfitted-canvas { display: block; width: 100%; aspect-ratio: 2 / 1.08; }

/* Video figure: the video itself has an alpha channel (VP9 WebM), so it sits
   directly on the section background in light and dark mode. In Safari a
   colour+mask mp4 is recombined on a canvas (.is-stacked); the video stays in
   the layout, invisible under the canvas, so WebKit keeps playing it. */
.alpha-video { position: relative; max-width: 22rem; margin: 0 auto; }
.alpha-video video,
.alpha-video canvas { display: block; width: 100%; height: auto; cursor: pointer; background: transparent; transition: opacity 0.4s ease; }
.alpha-video.is-stacked video { position: absolute; inset: 0; height: 100%; opacity: 0; pointer-events: none; }
.alpha-video.is-fading video,
.alpha-video.is-fading canvas { opacity: 0; }
.video-toggle {
  position: absolute;
  left: 0.5rem;
  bottom: 0.5rem;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.15s;
}
.video-toggle:hover, .video-toggle:focus-visible { opacity: 1; }

.research-outro {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1.5rem;
}
.research-outro .see-all-link { margin-top: 0; }

@media (max-width: 860px) {
  .theme-grid { grid-template-columns: 1fr; }
  .research-item { grid-template-columns: 1fr; gap: 1.5rem; }
  .research-item--flip .research-text { order: 0; }
}
@media (max-width: 640px) {
  #overview { padding-top: calc(var(--nav-h) + 2.5rem); }
  /* the drum needs its two columns; on phones, link to the hosted app instead */
  #drum-embed .embed-load { display: none; }
  #drum-embed .embed-slot:not(.is-loaded) { height: 140px; }
}
