:root {
  /* Color variables that adapt to light/dark mode */
  --color-bg-primary: #ffffff;
  --color-bg-secondary: #f6f6f4;
  --color-text-primary: #1a1a1a;
  --color-text-secondary: #4d4d4d;
  --color-text-tertiary: #767676;
  --color-link-primary: #1a4f96;
  --color-link-secondary: #1a4f96;
  --color-link-hover: #143c73;
  --color-active-bg: rgba(26, 79, 150, 0.08);
  --color-active-bg-strong: rgba(26, 79, 150, 0.14);
  --color-border: #ebebeb;
  --color-btn-primary-bg: #1a4f96;
  --color-btn-primary-text: #fff;
  --color-btn-primary-hover: #143c73;
  --color-popover-bg: #fff;
  --color-popover-shadow: 0 6px 20px rgba(0,0,0,0.12), 0 2px 6px rgba(0,0,0,0.06);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  --transition-fast: 0.15s ease;
  /* Single radius everywhere; matches Bootstrap .rounded (0.375rem) used on images */
  --radius: 6px;
}

/* Dark mode: redefine the same variables */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg-primary: #161616;
    --color-bg-secondary: #1e1e1e;
    --color-text-primary: #e8e8e8;
    --color-text-secondary: #a3a3a3;
    --color-text-tertiary: #8a8a8a;
    --color-link-primary: #7db3e8;
    --color-link-secondary: #a3a3a3;
    --color-link-hover: #a3c9ef;
    --color-active-bg: rgba(125, 179, 232, 0.1);
    --color-active-bg-strong: rgba(125, 179, 232, 0.18);
    --color-border: #2c2c2c;
    --color-btn-primary-bg: #7db3e8;
    --color-btn-primary-text: #161616;
    --color-btn-primary-hover: #a3c9ef;
    --color-popover-bg: #242424;
    --color-popover-shadow: 0 6px 20px rgba(0,0,0,0.35), 0 2px 6px rgba(0,0,0,0.2);
    --shadow-hover: 0 4px 12px rgba(0,0,0,0.5), 0 2px 4px rgba(0,0,0,0.35);
  }
}

body {
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  background-color: var(--color-bg-primary);
  color: var(--color-text-secondary);
  line-height: 1.6;
}
/* Optional serif accent for headings (zero cost, system fonts) — uncomment to enable:
h1, h2 { font-family: var(--font-serif); font-weight: 500; letter-spacing: -0.01em; }
*/
h1 {
  font-weight: 600;
  letter-spacing: -0.02em;
  font-size: 2rem;
  line-height: 1.2;
  color: var(--color-text-primary);
}
h2 {
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--color-text-primary);
  margin-top: 0;
  margin-bottom: 1.25rem;
  font-size: 1.4375rem;
  line-height: 1.25;
}
* + h2 {
  margin-top: 2.5rem;
}
h3 {
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--color-text-primary);
  font-size: 1.125rem;
  line-height: 1.3;
  margin-top: 0;
  margin-bottom: 0.75rem;
}
h4 {
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--color-text-primary);
  margin-bottom: 1rem;
  font-size: 1.0625rem;
  line-height: 1.3;
}
h5 {
  font-weight: 600;
  color: var(--color-text-primary);
  font-size: 1rem;
  line-height: 1.3;
}
small,
.small {
  font-size: 0.875em;
}

/* Section rhythm: single source of vertical spacing between page sections */
main > section {
  padding-block: 2.5rem 3rem;
}
header.topbar {
  padding-block: 1.5rem;
}
section[id],
header[id] {
  scroll-margin-top: 1rem;
}
@media (min-width: 1400px) {
  .topbar .container {
    max-width: 1140px;
  }
}
.publogo {
  margin-right: 20px;
  border-radius: var(--radius);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  z-index: 2;
}
.media-container.loaded .publogo:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-hover);
}
.publication {
  padding-block: 0.875rem;
  margin-bottom: 0;
}
.publication p {
  margin-bottom: 0;
}
.publication strong a {
  color: var(--color-text-primary);
  text-decoration: none;
}
.publication strong a:hover {
  color: var(--color-link-primary);
  text-decoration: underline;
}
ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
ul li {
  padding-bottom: 6px;
}
.nameplate {
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.nameplate h1 {
  margin-bottom: 0.375rem;
}
#me {
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--color-border);
}
.site-nav {
  background-color: var(--color-bg-primary);
}
a {
  color: var(--color-link-primary);
  text-decoration: none;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}
a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

.navbar-link {
  color: var(--color-link-secondary);
  text-decoration: none;
  padding: 0.5rem 1rem;
  display: block;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  transition: background-color var(--transition-fast);
}
.navbar-link:hover {
  color: var(--color-link-secondary);
  background-color: var(--color-active-bg);
  text-decoration: none;
}
.navbar-toggler {
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  border: none;
  background-color: var(--color-bg-secondary);
  border-radius: var(--radius);
  transition: background-color var(--transition-fast);
}
.navbar-toggler:hover {
  background-color: var(--color-active-bg);
}
.navbar-toggler:focus:not(:focus-visible) {
  box-shadow: none;
  outline: none;
}
.active {
  color: var(--color-link-primary) !important;
  background-color: var(--color-active-bg) !important;
  border-radius: var(--radius);
}
.active:hover {
  color: var(--color-link-primary) !important;
  text-decoration: none;
}
.student {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 10px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--color-text-secondary);
  transition: background-color var(--transition-fast);
}
.student:hover {
  background-color: var(--color-active-bg);
  color: var(--color-text-secondary);
  text-decoration: none;
}
.student-photo {
  width: 104px;
  height: 104px;
  object-fit: cover;
  flex-shrink: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.student:hover .student-photo {
  transform: scale(1.03);
  box-shadow: var(--shadow-hover);
}
.student-name {
  font-size: 1rem;
  line-height: 1.3;
}

.navbar-light {
  background-color: var(--color-bg-primary) !important;
}
.topbar,
.darker {
  background-color: var(--color-bg-secondary);
}
.topbar a {
  color: var(--color-text-secondary);
}

.publication .links {
  line-height: 1.8;
}
.publication strong {
  font-weight: 600;
}
.publication .links a {
  margin-right: 15px;
  display: inline-block;
}

/* Nav pills styling */
.nav-pills .nav-link {
  color: var(--color-link-secondary);
  border-radius: var(--radius);
  transition: background-color var(--transition-fast);
}

.nav-pills .nav-link:hover {
  color: var(--color-link-secondary);
  background-color: var(--color-active-bg);
  text-decoration: none;
}

.nav-pills .nav-link.active {
  background-color: var(--color-active-bg-strong);
  color: var(--color-link-primary);
}

/* Modal styling */
.modal-dialog {
  /* Bootstrap only auto-centers dialogs at >=576px; keep this one centered
     at all widths since it is capped narrower than the viewport */
  max-width: min(400px, calc(100% - 1rem));
  margin-inline: auto;
}

.modal-content {
  background-color: var(--color-bg-secondary);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.modal-body {
  overflow-y: auto;
  max-height: calc(90vh - 120px);
  padding: 1.5rem;
}

/* Custom scrollbar for modal */
.modal-body::-webkit-scrollbar {
  width: 8px;
}

.modal-body::-webkit-scrollbar-track {
  background: var(--color-bg-primary);
  border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-secondary);
}

/* Responsive modal height */
@media (max-height: 600px) {
  .modal-content {
    max-height: 80vh;
  }
  
  .modal-body {
    max-height: calc(80vh - 100px);
  }
}

/* Hamburger icon styling */
.navbar-toggler-icon {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%2845, 45, 45, 0.9%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

/* Dark mode specific overrides (only non-color changes) */
@media (prefers-color-scheme: dark) {
  .navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28230, 235, 240, 0.9%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
  }

  .btn-close {
    filter: invert(1);
  }
}

/* Student grid layout */
.student-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.75rem 1rem;
}

@media (max-width: 991.98px) {
  .student {
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }
  .student-photo {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
  }
  .student-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
}

/* Mobile inline button wrapper */
.mobile-inline-button {
  display: inline-block;
}

/* Button styles */
.btn-primary {
  background-color: var(--color-btn-primary-bg);
  border-color: var(--color-btn-primary-bg);
  color: var(--color-btn-primary-text);
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
  background-color: var(--color-btn-primary-hover);
  border-color: var(--color-btn-primary-hover);
  color: var(--color-btn-primary-text);
}

/* Image placeholder and loading states */
.media-container {
  position: relative;
  width: 100px;
  margin-right: 20px;
  float: left;
}

.media-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100px;
  height: 100px;
  background-color: var(--color-bg-secondary);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  overflow: hidden;
}


/* Spinner in placeholder */
.media-placeholder .spinner-border {
  width: 1.5rem;
  height: 1.5rem;
  opacity: 0.5;
  z-index: 2;
  position: relative;
}

/* Hide placeholder when media is loaded */
.media-container.loaded .media-placeholder {
  visibility: hidden;
}

/* Ensure hover transition works properly */
.media-container.loaded .publogo {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Alumni student styling: content-width items flowing left to right */
.alumni-flow {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  /* cancel the item padding so the first item's text aligns with the heading above */
  margin-inline: -0.6rem;
}

.alumni-student {
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius);
  transition: background-color var(--transition-fast);
}

.alumni-student:hover {
  background-color: var(--color-active-bg);
}

/* Publication placeholder for papers without images */
.publication-placeholder {
  width: 100px;
  height: 100px;
  background-color: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.publication-placeholder i {
  font-size: 2.5rem;
  color: var(--color-text-secondary);
  opacity: 0.4;
}

.publication-placeholder:hover {
  transform: scale(1.02);
  background-color: var(--color-active-bg);
  box-shadow: var(--shadow-hover);
}

/* Year heading horizontal rules */
.year {
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  background-color: var(--color-bg-primary);
  z-index: 10;
  margin-left: -1rem;
  margin-right: -1rem;
  padding: 0.5rem 1rem 0.25rem;
  margin-bottom: 0;
}
.year::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, var(--color-border), transparent);
}

/* Popover base styling using CSS variables for automatic dark mode */
.popover {
  background-color: var(--color-popover-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text-secondary);
  font-size: 0.85rem;
  box-shadow: var(--color-popover-shadow);
}

.popover-header {
  background-color: var(--color-popover-bg);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-primary);
  font-weight: 600;
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
}

.popover-body {
  color: var(--color-text-secondary);
  padding: 0.6rem 0.75rem;
}

/* Popover arrow overrides */
.bs-popover-top > .popover-arrow::before, .bs-popover-auto[data-popper-placement^=top] > .popover-arrow::before { border-top-color: var(--color-border); }
.bs-popover-top > .popover-arrow::after, .bs-popover-auto[data-popper-placement^=top] > .popover-arrow::after { border-top-color: var(--color-popover-bg); }
.bs-popover-bottom > .popover-arrow::before, .bs-popover-auto[data-popper-placement^=bottom] > .popover-arrow::before { border-bottom-color: var(--color-border); }
.bs-popover-bottom > .popover-arrow::after, .bs-popover-auto[data-popper-placement^=bottom] > .popover-arrow::after { border-bottom-color: var(--color-popover-bg); }
.bs-popover-start > .popover-arrow::before, .bs-popover-auto[data-popper-placement^=left] > .popover-arrow::before { border-left-color: var(--color-border); }
.bs-popover-start > .popover-arrow::after, .bs-popover-auto[data-popper-placement^=left] > .popover-arrow::after { border-left-color: var(--color-popover-bg); }
.bs-popover-end > .popover-arrow::before, .bs-popover-auto[data-popper-placement^=right] > .popover-arrow::before { border-right-color: var(--color-border); }
.bs-popover-end > .popover-arrow::after, .bs-popover-auto[data-popper-placement^=right] > .popover-arrow::after { border-right-color: var(--color-popover-bg); }

/* BibTeX popover */
.bibtex-popover {
  max-width: 450px;
}

.bibtex-popover .bibtex-preview pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--color-text-secondary);
  background: none;
  border: none;
  padding: 0;
}

.bibtex-popover .bibtex-preview code {
  color: var(--color-text-secondary);
  background: none;
}

.bibtex-popover .popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.bibtex-popover .bibtex-copy-btn {
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  line-height: 1.3;
}

/* Student popover */
.student-popover .popover-body {
  text-align: left;
  padding: 0.4rem 0.6rem;
}

.student-popover .alumni-popover-layout {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}

.student-popover .alumni-photo {
  flex-shrink: 0;
}

.student-popover .alumni-photo img {
  width: 50px;
  border-radius: var(--radius);
}

.student-popover .alumni-info {
  flex: 1;
  min-width: 0;
}

.student-popover .alumni-section + .alumni-section {
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--color-border);
}

.student-popover {
  max-width: 340px;
}

.student-popover .alumni-section-title {
  font-weight: 600;
  color: var(--color-text-primary);
  font-size: 0.8rem;
  margin-bottom: 0.1rem;
}

/* Abstract popover */
.abstract-popover {
  max-width: 400px;
}

.abstract-popover .popover-body {
  max-height: 250px;
  overflow-y: auto;
}

/* Cursor hints for alumni */
.alumni-student[data-alumni-popover] {
  cursor: help;
}

.alumni-student[data-alumni-url] {
  cursor: pointer;
}

/* Accessibility: visible keyboard focus */
:focus-visible {
  outline: 2px solid var(--color-link-primary);
  outline-offset: 2px;
  border-radius: 2px;
}
.navbar-link:focus-visible,
.nav-pills .nav-link:focus-visible,
.student:focus-visible {
  outline-offset: 0;
  border-radius: var(--radius);
}

/* Accessibility: respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
