:root {
  /* ── Bootstrap 5 Colors & Fonts (Light Mode) ── */
  --font-family-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  --font-family-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  --bs-blue: #0d6efd;
  --bs-indigo: #6610f2;
  --bs-purple: #6f42c1;
  --bs-pink: #d63384;
  --bs-red: #dc3545;
  --bs-orange: #fd7e14;
  --bs-yellow: #ffc107;
  --bs-green: #198754;
  --bs-teal: #20c997;
  --bs-cyan: #0dcaf0;
  --bs-gray: #6c757d;
  --bs-gray-dark: #343a40;

  --body-bg: #ffffff;
  --body-color: #212529;
  --link-color: #0d6efd;
  --link-hover-color: #0a58ca;
  --border-color: #dee2e6;
  
  --header-bg: #212529;
  --header-color: #f8f9fa;
  --header-link-color: rgba(255, 255, 255, 0.75);
  --header-link-hover-color: #ffffff;

  --nav-bg: #f8f9fa;
  --nav-border-color: #e9ecef;
  --nav-link-color: rgba(0, 0, 0, 0.65);
  --nav-link-hover-color: rgba(0, 0, 0, 0.7);
  --nav-active-color: #000000;
  --nav-toggle-color: rgba(0, 0, 0, 0.65);

  --heading-color: #212529;
  --bullet-color: #6c757d;
  
  --footer-color: #6c757d;
  --footer-border-color: #dee2e6;

  --skeleton-bg: #e9ecef;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* ── Dark Mode Overrides ── */
    --body-bg: #212529;
    --body-color: #dee2e6;
    --link-color: #6ea8fe;
    --link-hover-color: #8bb9fe;
    --border-color: #495057;

    --header-bg: #000000;
    --header-color: #f8f9fa;
    --header-link-color: rgba(255, 255, 255, 0.75);
    --header-link-hover-color: #ffffff;

    --nav-bg: #343a40;
    --nav-border-color: #495057;
    --nav-link-color: rgba(255, 255, 255, 0.70);
    --nav-link-hover-color: rgba(255, 255, 255, 0.75);
    --nav-active-color: #ffffff;
    --nav-toggle-color: rgba(255, 255, 255, 0.70);

    --heading-color: #f8f9fa;
    --bullet-color: #adb5bd;

    --footer-color: #adb5bd;
    --footer-border-color: #343a40;
    
    --skeleton-bg: #343a40;
  }
}

/* ── Reset & Base ────────────────────────────────────────── */

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family-sans-serif);
  background: var(--body-bg);
  color: var(--body-color);
  line-height: 1.6;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--link-color);
  text-decoration: none;
  transition: color 0.15s ease-in-out;
}

a:hover {
  color: var(--link-hover-color);
  text-decoration: underline;
}

/* ── Skip Link ─────────────────────────────────────────── */

.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--header-bg);
  color: var(--header-color);
  font-weight: 600;
  z-index: 2000;
  border-radius: 0 0 4px 4px;
  text-decoration: none;
}

.skip-link:focus {
  top: 0;
  outline: 2px solid var(--link-color);
  outline-offset: 2px;
}

/* ── Focus Styles ──────────────────────────────────────── */

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--link-color);
  outline-offset: 2px;
}

.site-nav li a:focus-visible {
  outline-offset: -2px;
}

/* ── Hero ───────────────────────────────────────────────── */

.hero {
  min-height: 100svh;
  background: var(--header-bg);
  color: var(--header-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 2rem;
  position: relative;
}

.hero h1 {
  font-size: 2.5rem;
  font-weight: 300;
  line-height: 1.2;
  margin-bottom: 0.75rem;
}

.hero-portrait {
  width: 280px;
  height: 280px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 1.5rem;
  border: 4px solid rgba(255, 255, 255, 0.15);
}

.hero-intro {
  max-width: 600px;
  font-size: 1.1rem;
  line-height: 1.6;
  margin-top: 1rem;
  opacity: 0.9;
}

.hero-intro p {
  margin-bottom: 0.5rem;
}

.contact-info {
  list-style: none;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem 1.6rem;
  font-size: 0.95rem;
}

.hero .contact-info a {
  color: var(--header-link-color);
  text-decoration: none;
}

.hero .contact-info a:hover {
  color: var(--header-link-hover-color);
  text-decoration: underline;
}

footer .contact-info {
  margin-bottom: 0.5rem;
}

footer .contact-info a {
  color: var(--footer-color);
  text-decoration: none;
}

footer .contact-info a:hover {
  color: var(--link-hover-color);
  text-decoration: underline;
}

/* ── Scroll Indicator ──────────────────────────────────── */

.scroll-indicator {
  position: absolute;
  bottom: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  text-decoration: none;
}

.scroll-arrow {
  display: block;
  width: 20px;
  height: 20px;
  border-right: 2px solid var(--header-link-color);
  border-bottom: 2px solid var(--header-link-color);
  transform: rotate(45deg);
  animation: bounce 2s ease-in-out infinite;
}

.scroll-indicator:hover .scroll-arrow {
  border-color: var(--header-link-hover-color);
}

@keyframes bounce {
  0%, 100% { transform: translateY(0) rotate(45deg); }
  50% { transform: translateY(8px) rotate(45deg); }
}

/* ── Navigation ─────────────────────────────────────────── */

.site-nav {
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border-color);
  position: sticky;
  top: 0;
  z-index: 1030;
}

.nav-toggle {
  display: none;
  width: 100%;
  padding: 0.75rem 1.5rem;
  background: var(--nav-bg);
  border: none;
  border-bottom: 1px solid var(--nav-border-color);
  font-family: inherit;
  font-size: 1rem;
  color: var(--nav-toggle-color);
  cursor: pointer;
  text-align: left;
}

.site-nav ul {
  list-style: none;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0;
  max-width: 800px;
  margin: 0 auto;
}

.site-nav li a {
  display: block;
  padding: 0.8rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--nav-link-color);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
}

.site-nav li a:hover {
  color: var(--nav-active-color);
}

.site-nav li a.active {
  color: var(--nav-active-color);
  border-bottom-color: var(--nav-active-color);
}

/* ── Main Content ───────────────────────────────────────── */

main {
  max-width: 992px;
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
}

section {
  margin-bottom: 3.5rem;
}

section h2 {
  font-family: var(--font-family-sans-serif);
  font-size: 1.75rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--heading-color);
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
  margin-bottom: 1.5rem;
}

/* ── Rendered Markdown ──────────────────────────────────── */

.section-content h3 {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--heading-color);
  margin: 1.5rem 0 0.5rem;
}

.section-content h3:first-child {
  margin-top: 0;
}

.section-content ul {
  list-style: none;
  padding: 0;
  margin-bottom: 1rem;
}

.section-content ul ul {
  margin-bottom: 0;
}

.section-content ul li {
  position: relative;
  padding: 0.25rem 0 0.25rem 1.2rem;
}

.section-content ul li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--bullet-color);
}

.section-content p {
  margin-bottom: 0.5rem;
}

/* Bibliography / Hanging Indent Styles */
#publications .section-content p,
.subsection-research-in-progress p,
.subsection-other-service-activities p,
.hanging-indent {
  padding-left: 2rem;
  text-indent: -2rem;
}

.subsection h3 {
  font-style: italic;
}

.section-content a {
  color: var(--link-color);
}

.section-content a:hover {
  text-decoration: underline;
  color: var(--link-hover-color);
}

/* ── Footer ─────────────────────────────────────────────── */

footer {
  text-align: center;
  padding: 2rem;
  font-size: 0.875rem;
  color: var(--footer-color);
  border-top: 1px solid var(--footer-border-color);
  background: var(--body-bg);
}

/* ── Back To Top ───────────────────────────────────────── */

.back-to-top {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  z-index: 2140;
  min-width: 52px;
  min-height: 52px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--nav-border-color);
  border-radius: 999px;
  background: var(--nav-bg);
  color: var(--nav-link-color);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.16);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease, color 0.15s ease-in-out;
}

.back-to-top.visible {
  opacity: 0.95;
  transform: translateY(0);
  pointer-events: auto;
}

.back-to-top:hover {
  color: var(--nav-active-color);
}

/* ── Loading State ──────────────────────────────────────── */

.section-content:empty::after {
  content: "";
  display: block;
  width: 60%;
  height: 1rem;
  background: var(--skeleton-bg);
  border-radius: 4px;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0% { opacity: 0.6; }
  50% { opacity: 0.3; }
  100% { opacity: 0.6; }
}

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

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

/* ── Responsive ─────────────────────────────────────────── */

@media (max-width: 768px) {
  html {
    scroll-padding-top: 0; /* sticky h2 at top:0 handles the visual offset */
  }

  .hero {
    padding: 2rem 1rem;
    min-height: 100svh;
  }

  .hero h1 {
    font-size: 2rem;
  }

  .hero-portrait {
    width: 200px;
    height: 200px;
  }

  .hero-intro {
    font-size: 1rem;
  }

  /* Sticky section headers on mobile for orientation */
  section h2 {
    position: sticky;
    top: 0;
    z-index: 1020;
    background: var(--body-bg);
    padding-top: 3.75rem; /* pushes text below the nav toggle overlay */
    margin-left: -1.5rem;
    margin-right: -1.5rem;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }

  section {
    scroll-margin-top: 0;
  }

  .nav-toggle {
    display: block;
  }

  .site-nav ul {
    display: none;
    flex-direction: column;
    max-width: none;
  }

  .site-nav.open ul {
    display: flex;
  }

  .site-nav li a {
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--nav-border-color);
  }

  .site-nav li a.active {
    border-bottom-color: var(--nav-border-color);
    font-weight: 700;
  }

  .back-to-top {
    right: 0.75rem;
    bottom: calc(4.25rem + env(safe-area-inset-bottom));
  }
}

/* ── Print ──────────────────────────────────────────────── */

@media print {
  .back-to-top,
  .site-nav,
  .nav-toggle {
    display: none;
  }

  .hero {
    min-height: auto;
    background: none;
    color: #000;
    padding: 1rem 0;
    border-bottom: 2px solid #000;
  }

  .hero-portrait,
  .scroll-indicator {
    display: none;
  }

  .hero-intro {
    max-width: 100%;
    opacity: 1;
    color: #000;
  }

  .contact-info a {
    color: #000;
    text-decoration: none;
  }

  body {
    font-size: 12pt;
    font-family: serif;
    background: #fff;
    color: #000;
  }

  main {
    padding: 2rem 0;
    max-width: 100%;
  }

  section {
    page-break-inside: avoid;
    border: none;
  }

  section h2 {
    border-bottom: 1px solid #000;
    color: #000;
  }

  a {
    color: #000 !important;
    text-decoration: none;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
  }
  
  a[href^="#"]::after {
    content: "";
  }
}
