/* =========================================================
   Site-wide enhancements: dark mode, back-to-top FAB,
   theme toggle, CV expand/collapse-all, print stylesheet.
   Loaded on every page via <link rel="stylesheet">.
   ========================================================= */

/* ---------- Dark mode palette ---------- */
html[data-theme="dark"] {
  --body-color: rgba(255,255,255,0.86) !important;
  --header-color: #BFBBFF !important;
  --title-color: #BFBBFF !important;
  --heading-color: #BFBBFF !important;
  --text-color: rgba(255,255,255,0.82) !important;
  --aside-color: rgba(255,255,255,0.6) !important;
  --fig-cap-color: rgba(255,255,255,0.6) !important;
  --link-color: #9D98FF !important;
  --link-hover-color: #C9C5FF !important;
  color-scheme: dark;
}

html[data-theme="dark"] body,
html[data-theme="dark"] .d-article,
html[data-theme="dark"] d-article,
html[data-theme="dark"] main {
  background-color: #0E1020 !important;
  color: rgba(255,255,255,0.86) !important;
}

html[data-theme="dark"] .distill-site-header {
  --text-color: #E7E5FF !important;
  --hover-color: #BFBBFF !important;
  --bkgd-color: #0E1020 !important;
  background-color: #0E1020 !important;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
html[data-theme="dark"] .distill-site-header a { color: #E7E5FF !important; }

html[data-theme="dark"] .distill-site-footer {
  --bkgd-color: #15172A !important;
  --text-color: #BFBBFF !important;
  background-color: #15172A !important;
  color: #BFBBFF !important;
}

/* Cards + panels in dark */
html[data-theme="dark"] .card,
html[data-theme="dark"] .edu-block,
html[data-theme="dark"] .exp-block,
html[data-theme="dark"] .teach-block,
html[data-theme="dark"] .project-card {
  background-color: #181A2E !important;
  border-color: rgba(159,155,255,0.18) !important;
  color: rgba(255,255,255,0.86) !important;
  box-shadow: 0 4px 18px rgba(0,0,0,0.4), 0 1px 3px rgba(0,0,0,0.2) !important;
}

html[data-theme="dark"] .card::before {
  background-image:
    radial-gradient(circle at 1px 1px, rgba(255,255,255,0.18) 1px, transparent 1.6px),
    linear-gradient(160deg, #2A2547 0%, #2E2352 45%, #1E2748 100%) !important;
}
html[data-theme="dark"] .card::after {
  background: radial-gradient(circle at center, rgba(159,155,255,0.22) 0%, rgba(159,155,255,0) 70%) !important;
}

/* CV headings keep their per-section colors but on dark bg we lift lightness */
html[data-theme="dark"] .cv-section h3 { color: #BFBBFF !important; border-bottom-color: rgba(191,187,255,0.35) !important; }
html[data-theme="dark"] .cv-section h3 i { background: rgba(191,187,255,0.15) !important; color: #BFBBFF !important; }
html[data-theme="dark"] section.edu.cv-section h3 { color: #B4AFFF !important; }
html[data-theme="dark"] section.experience.cv-section h3,
html[data-theme="dark"] section.exp.cv-section h3 { color: #D2B4FF !important; }
html[data-theme="dark"] section.skills-prog.cv-section h3 { color: #9EC7FF !important; }
html[data-theme="dark"] section.interests.cv-section h3 { color: #B9C0FF !important; }

/* Entry titles (role / degree) — were hardcoded #1f1f1f in light mode */
html[data-theme="dark"] .edu-degree,
html[data-theme="dark"] .exp-role,
html[data-theme="dark"] .edu-degree strong,
html[data-theme="dark"] .exp-role strong { color: #F1EEFF !important; }

html[data-theme="dark"] .edu-inst,
html[data-theme="dark"] .exp-inst { color: rgba(255,255,255,0.72) !important; }

html[data-theme="dark"] .edu-head .edu-date,
html[data-theme="dark"] .exp-head .exp-date {
  background: rgba(159,155,255,0.18) !important;
  color: #D7D4FF !important;
}

html[data-theme="dark"] .edu ul.edu-bullets li,
html[data-theme="dark"] .exp ul.exp-bullets li,
html[data-theme="dark"] .edu-bullets li,
html[data-theme="dark"] .exp-bullets li { color: rgba(255,255,255,0.8) !important; }

/* Skills section */
html[data-theme="dark"] .skill-row { background: rgba(255,255,255,0.04) !important; border-color: rgba(255,255,255,0.1) !important; color: rgba(255,255,255,0.86) !important; }
html[data-theme="dark"] .skill-row:hover { background: rgba(159,155,255,0.08) !important; border-color: rgba(159,155,255,0.22) !important; }
html[data-theme="dark"] .skill-label { background: rgba(159,155,255,0.18) !important; color: #BFBBFF !important; }
html[data-theme="dark"] .skill-items { color: rgba(255,255,255,0.82) !important; }

html[data-theme="dark"] .interests-items li { background: rgba(159,155,255,0.15) !important; color: #D7D4FF !important; border-color: rgba(159,155,255,0.22) !important; }
html[data-theme="dark"] .interests-items li i { color: #BFBBFF !important; }

/* Projects cards / summary banners in dark */
html[data-theme="dark"] .project-title-text a,
html[data-theme="dark"] .project-title-text { color: #E7E5FF !important; }
html[data-theme="dark"] .project-desc { color: rgba(255,255,255,0.75) !important; }
html[data-theme="dark"] .project-cta { background: rgba(159,155,255,0.18) !important; color: #D7D4FF !important; }
html[data-theme="dark"] .project-cta:hover { background: #6A66D5 !important; color: #fff !important; }

/* Teaching cards in dark */
html[data-theme="dark"] h4.teach-course,
html[data-theme="dark"] .teach-course,
html[data-theme="dark"] .teach-course a { color: #F1EEFF !important; }
html[data-theme="dark"] .teach-course a { border-bottom-color: rgba(159,155,255,0.35) !important; }
html[data-theme="dark"] .teach-course a:hover { color: #BFBBFF !important; border-bottom-color: #BFBBFF !important; }
html[data-theme="dark"] .teach-code { color: rgba(255,255,255,0.5) !important; }
html[data-theme="dark"] .teach-inst,
html[data-theme="dark"] .teach-meta { color: rgba(255,255,255,0.72) !important; }
html[data-theme="dark"] .teach-meta .teach-role { color: #BFBBFF !important; }
html[data-theme="dark"] .teach-date { background: rgba(159,155,255,0.15) !important; color: #D7D4FF !important; }
html[data-theme="dark"] .teach-bullets li { color: rgba(255,255,255,0.8) !important; }
html[data-theme="dark"] .teach-tagline { color: rgba(255,255,255,0.82) !important; }
html[data-theme="dark"] .teach-quote { background: rgba(159,155,255,0.08) !important; border-left-color: #BFBBFF !important; color: rgba(255,255,255,0.82) !important; }

/* Horizontal rules */
html[data-theme="dark"] hr { border-color: rgba(255,255,255,0.1) !important; }

/* Generic prose */
html[data-theme="dark"] p,
html[data-theme="dark"] li,
html[data-theme="dark"] .d-article p,
html[data-theme="dark"] .d-article li,
html[data-theme="dark"] d-article p,
html[data-theme="dark"] d-article li { color: rgba(255,255,255,0.85) !important; }

/* Page title heading (the "About Me" / "CV" / "Teaching" h1) */
html[data-theme="dark"] .d-title h1,
html[data-theme="dark"] d-title h1 { color: #BFBBFF !important; }
html[data-theme="dark"] .d-title, html[data-theme="dark"] d-title { color: rgba(255,255,255,0.85) !important; }

/* Footer on each page */
html[data-theme="dark"] footer { color: rgba(255,255,255,0.6) !important; }
html[data-theme="dark"] footer hr { border-color: rgba(255,255,255,0.1) !important; }
html[data-theme="dark"] footer a { color: #BFBBFF !important; }

/* Article background */
html[data-theme="dark"] .d-article,
html[data-theme="dark"] d-article { background-color: transparent !important; }

/* Links */
html[data-theme="dark"] a { color: #9D98FF !important; }
html[data-theme="dark"] a:hover { color: #C9C5FF !important; }

/* ---------- Theme toggle (two placements) ---------- */
/* Inline variant: sits inside the distill-site nav alongside other icons. */
.site-theme-toggle--in-nav {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: 2rem; height: 2rem;
  margin-right: 0.35rem;
  padding: 0;
  background: transparent;
  color: inherit;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  opacity: 0.75;
  transition: opacity 0.15s ease, background-color 0.15s ease, color 0.15s ease;
  vertical-align: middle;
}
.site-theme-toggle--in-nav:hover { opacity: 1; background: rgba(106,102,213,0.10); color: #6A66D5; }
.site-theme-toggle--in-nav:focus-visible { outline: 2px solid #6A66D5; outline-offset: 2px; opacity: 1; }
html[data-theme="dark"] .site-theme-toggle--in-nav:hover { background: rgba(159,155,255,0.16); color: #BFBBFF; }

/* Floating variant (fallback when nav is not found). */
.site-theme-toggle--floating {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(106,102,213,0.25);
  background: #fff;
  color: #6A66D5;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  display: inline-flex;
  align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.2s ease, color 0.2s ease;
  padding: 0;
}
.site-theme-toggle--floating:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.16); }
.site-theme-toggle--floating:focus-visible { outline: 2px solid #6A66D5; outline-offset: 2px; }
html[data-theme="dark"] .site-theme-toggle--floating {
  background: #181A2E;
  color: #E7E5FF;
  border-color: rgba(159,155,255,0.35);
  box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

/* ---------- Back-to-top FAB ---------- */
.site-back-to-top {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 1000;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: none;
  background: #6A66D5;
  color: #fff;
  box-shadow: 0 4px 14px rgba(106,102,213,0.4);
  display: inline-flex;
  align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease, background-color 0.2s ease;
  padding: 0;
}
.site-back-to-top.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.site-back-to-top:hover { background: #5753C0; }
.site-back-to-top:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
html[data-theme="dark"] .site-back-to-top { background: #9D98FF; color: #0E1020; box-shadow: 0 4px 14px rgba(159,155,255,0.45); }
html[data-theme="dark"] .site-back-to-top:hover { background: #BFBBFF; }

/* ---------- Table of contents (sticky left rail, grouped) ---------- */
/* Two placements, driven by JS (matchMedia):
     .site-toc--rail   -> fixed left sidebar (wide screens, attached to body)
     .site-toc--inline -> compact panel at top of article (narrow screens) */
.site-toc {
  padding: 1rem 1.1rem;
  background: rgba(255,255,255,0.82);
  border: 1px solid rgba(106,102,213,0.18);
  border-radius: 12px;
  box-shadow: 0 4px 18px rgba(106,102,213,0.08), 0 1px 3px rgba(0,0,0,0.04);
  font-family: var(--body-font, -apple-system, sans-serif);
  font-size: 0.82rem;
  line-height: 1.4;
  color: rgba(0,0,0,0.72);
  z-index: 60;
}
.site-toc--rail {
  position: fixed;
  top: 50%;
  left: 1.25rem;
  transform: translateY(-50%);
  width: 220px;
  max-height: calc(100vh - 8rem);
  overflow-y: auto;
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
}
.site-toc--inline {
  position: static;
  margin: 0 auto 1.5rem;
  max-width: 100%;
  overflow: hidden;
}
.site-toc--inline ul { columns: 2; column-gap: 1.25rem; }
.site-toc--inline .site-toc__item { break-inside: avoid; }
@media (max-width: 640px) {
  .site-toc--inline ul { columns: 1; }
  .site-toc { font-size: 0.84rem; }
}
.site-toc__title {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.68rem;
  font-weight: 700;
  color: #6A66D5;
  margin: 0 0 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(106,102,213,0.15);
}
.site-toc__group {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.65rem;
  font-weight: 700;
  color: rgba(106,102,213,0.85);
  margin: 0.75rem 0 0.2rem;
  padding-left: 0.35rem;
}
.site-toc__group:first-of-type { margin-top: 0; }
.site-toc ul {
  list-style: none;
  margin: 0 0 0.25rem;
  padding: 0;
  display: block;
}
.site-toc__item { margin: 0; min-width: 0; }
.site-toc a {
  color: rgba(0,0,0,0.62);
  text-decoration: none;
  display: block;
  padding: 0.28rem 0.45rem 0.28rem 0.65rem;
  border-left: 2px solid transparent;
  border-radius: 4px;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.site-toc a:hover { color: #6A66D5; background: rgba(106,102,213,0.08); }
.site-toc a.is-active {
  color: #6A66D5;
  border-left-color: #6A66D5;
  font-weight: 600;
  background: rgba(106,102,213,0.10);
}

/* Dark mode */
html[data-theme="dark"] .site-toc {
  background: rgba(30,28,58,0.75);
  border-color: rgba(159,155,255,0.22);
  color: rgba(255,255,255,0.78);
  box-shadow: 0 4px 18px rgba(0,0,0,0.35);
}
html[data-theme="dark"] .site-toc__title {
  color: #BFBBFF;
  border-bottom-color: rgba(159,155,255,0.25);
}
html[data-theme="dark"] .site-toc__group { color: rgba(191,187,255,0.85); }
html[data-theme="dark"] .site-toc a { color: rgba(255,255,255,0.72); }
html[data-theme="dark"] .site-toc a:hover { color: #BFBBFF; background: rgba(159,155,255,0.12); }
html[data-theme="dark"] .site-toc a.is-active { color: #BFBBFF; border-left-color: #BFBBFF; background: rgba(159,155,255,0.18); }

/* ---------- Page background image (light theme only) ---------- */
:root {
  --page-background: none;
  --page-overlay: rgba(255,255,255,0.86);
}
html:not([data-theme="dark"]) body {
  background-image:
    linear-gradient(var(--page-overlay), var(--page-overlay)),
    var(--page-background);
  background-size: cover, cover;
  background-position: center, center;
  background-attachment: fixed, fixed;
  background-repeat: no-repeat, no-repeat;
}
/* Distill wraps the article in its own white container; make it slightly
   translucent so the tinted background shows through at the edges without
   hurting readability. */
html:not([data-theme="dark"]) .distill-site-header,
html:not([data-theme="dark"]) .distill-site-nav,
html:not([data-theme="dark"]) footer { background-color: rgba(255,255,255,0.72); }
html:not([data-theme="dark"]) d-article,
html:not([data-theme="dark"]) .d-article { background: transparent; }

/* Research page: sit the prose on a translucent white card so the tiled
   background reads clearly around it. The card is placed on the <p>
   itself (not on d-article) so the page <footer> with the copyright and
   Back to Top button stays *outside* the card. Distill normally uses a
   CSS grid on <d-article> to put prose in a centered "middle" column;
   on this page we flatten that so the card can span the article width. */
html:not([data-theme="dark"])[data-page="research"] d-article,
html:not([data-theme="dark"])[data-page="research"] .d-article {
  display: block !important;
  grid-template-columns: none !important;
  grid-column-gap: 0 !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  padding: 0 !important;
}
html:not([data-theme="dark"])[data-page="research"] d-article > *,
html:not([data-theme="dark"])[data-page="research"] .d-article > * {
  grid-column: 1 / -1 !important;
  max-width: 100% !important;
  width: auto !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}
html:not([data-theme="dark"])[data-page="research"] d-article > p,
html:not([data-theme="dark"])[data-page="research"] .d-article > p {
  background: rgba(255,255,255,0.88);
  border: 1px solid rgba(106,102,213,0.14);
  border-radius: 14px;
  box-shadow: 0 6px 22px rgba(30,58,138,0.08), 0 1px 3px rgba(0,0,0,0.04);
  padding: 2rem 2.25rem;
  margin: 1.5rem auto 2rem !important;
  max-width: min(860px, calc(100% - 2rem)) !important;
}
/* Keep the page <footer> visually separate from the card. */
html:not([data-theme="dark"])[data-page="research"] d-article > footer,
html:not([data-theme="dark"])[data-page="research"] .d-article > footer {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
}
/* Hide the stray <hr> Distill/knitr inserts above the first paragraph so
   it doesn't float orphaned above the card. */
html:not([data-theme="dark"])[data-page="research"] d-article > hr:first-of-type,
html:not([data-theme="dark"])[data-page="research"] .d-article > hr:first-of-type {
  display: none !important;
}
@media (max-width: 640px) {
  html:not([data-theme="dark"])[data-page="research"] d-article > p,
  html:not([data-theme="dark"])[data-page="research"] .d-article > p {
    padding: 1.25rem 1.1rem;
    border-radius: 10px;
  }
}

/* ---------- Site header banner: dark-blue title + icons (light mode) ---------- */
html:not([data-theme="dark"]) .distill-site-header,
html:not([data-theme="dark"]) .distill-site-header a,
html:not([data-theme="dark"]) .distill-site-header .title,
html:not([data-theme="dark"]) .distill-site-header a.nav-toggle,
html:not([data-theme="dark"]) .distill-site-header .nav-dropbtn {
  color: #1E3A8A !important;
}
html:not([data-theme="dark"]) .distill-site-header a:hover,
html:not([data-theme="dark"]) .distill-site-header a:focus {
  color: #0F2463 !important;
}
html:not([data-theme="dark"]) .site-theme-toggle--in-nav {
  color: #1E3A8A !important;
}
html:not([data-theme="dark"]) .site-theme-toggle--in-nav:hover {
  color: #0F2463 !important;
  background: rgba(30,58,138,0.08);
}

/* ---------- CV: Expand/Collapse all controls ---------- */
.cv-controls {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin: 0 0 1.25rem;
}
.cv-controls .cv-toggle-all {
  font-family: var(--body-font, inherit);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
  color: #6A66D5;
  background: rgba(106,102,213,0.08);
  border: 1px solid rgba(106,102,213,0.2);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.cv-controls .cv-toggle-all:hover { background: #6A66D5; color: #fff; }
.cv-controls .cv-toggle-all:focus-visible { outline: 2px solid #6A66D5; outline-offset: 2px; }
html[data-theme="dark"] .cv-controls .cv-toggle-all { color: #BFBBFF; background: rgba(159,155,255,0.12); border-color: rgba(159,155,255,0.3); }
html[data-theme="dark"] .cv-controls .cv-toggle-all:hover { background: #9D98FF; color: #0E1020; }

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .site-back-to-top,
  .site-theme-toggle,
  .cv-controls .cv-toggle-all { transition: none !important; }
}

/* ---------- Icon Legend (About page) ----------
   A compact key explaining the nav + social icons. JS decides whether to
   mount it as a sticky left rail (wide screens) or inline at the end of
   the bio card (narrow). */
.icon-legend {
  font-family: var(--body-font, inherit);
  font-size: 0.82rem;
  line-height: 1.3;
  color: #3F3C7A;
}
.icon-legend__group {
  margin-bottom: 0.85rem;
}
.icon-legend__group:last-child { margin-bottom: 0; }
.icon-legend__heading {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  color: #6A66D5;
  margin: 0 0 0.45rem 0;
}
.icon-legend__list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.35rem;
}
.icon-legend__item {
  display: grid;
  grid-template-columns: 1.5em 1fr;
  align-items: center;
  gap: 0.55rem;
  padding: 0.3rem 0.5rem;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.icon-legend__item:hover,
.icon-legend__item:focus-visible {
  background: rgba(106,102,213,0.09);
  color: #4F4BB8;
  text-decoration: none;
  outline: none;
}
.icon-legend__icon {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 1.5em;
  color: #6A66D5;
  font-size: 0.95rem;
}
.icon-legend__label {
  font-weight: 500;
}
/* Theme-toggle button variant: same look as a link item but behaves as a
   button with no underline / native button styling. */
button.icon-legend__item {
  font: inherit;
  background: none;
  border: 0;
  width: 100%;
  cursor: pointer;
  text-align: left;
}

/* Sticky left-rail placement (wide screens). The JS appends the legend
   to <body> in this mode so it can fix-position relative to the viewport
   without being trapped by a containing block. Vertically centered so
   it sits in line with the prose below the page title. */
.icon-legend--rail {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  left: 1.25rem;
  width: 200px;
  max-height: calc(100vh - 8rem);
  overflow-y: auto;
  padding: 1rem 1rem 1.1rem;
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(106,102,213,0.18);
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(30,58,138,0.08), 0 1px 3px rgba(0,0,0,0.04);
  z-index: 20;
}

/* Inline placement (narrow screens). JS appends it after the bio card.
   Distill puts prose in a centered grid column inside <d-article>, so we
   force the legend onto Distill's named "page" track (full readable
   width) and set its own width. */
.icon-legend--inline {
  display: block;
  grid-column: page !important;
  margin: 1.5rem auto 0 !important;
  width: 100% !important;
  max-width: 640px !important;
  padding: 1rem 1.15rem 1.15rem;
  background: rgba(255,255,255,0.9);
  border: 1px solid rgba(106,102,213,0.14);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(30,58,138,0.06);
}
.icon-legend--inline .icon-legend__list {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

/* Dark mode */
html[data-theme="dark"] .icon-legend {
  color: rgba(255,255,255,0.86);
}
html[data-theme="dark"] .icon-legend__heading {
  color: #BFBBFF;
}
html[data-theme="dark"] .icon-legend__icon {
  color: #9D98FF;
}
html[data-theme="dark"] .icon-legend--rail,
html[data-theme="dark"] .icon-legend--inline {
  background: rgba(20,22,44,0.92);
  border-color: rgba(159,155,255,0.22);
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}
html[data-theme="dark"] .icon-legend__item:hover,
html[data-theme="dark"] .icon-legend__item:focus-visible {
  background: rgba(159,155,255,0.12);
  color: #BFBBFF;
}

/* Hide legend in print */
@media print {
  .icon-legend { display: none !important; }
}

/* ---------- Page-to-page nav arrows ----------
   Floating pill-shaped buttons anchored to the left/right viewport
   edges. Hidden at the first/last page on that side. Keyboard users get
   the same behaviour via the global Left/Right arrow key handlers. */
.site-page-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.85rem;
  font-family: var(--body-font, inherit);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  color: #fff;
  background: rgba(106,102,213,0.9);
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(30,58,138,0.22), 0 1px 3px rgba(0,0,0,0.08);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease,
    background-color 0.15s ease,
    box-shadow 0.15s ease;
  opacity: 0.85;
}
.site-page-nav:hover,
.site-page-nav:focus-visible {
  opacity: 1;
  background: #5F5BCF;
  color: #fff;
  text-decoration: none;
  outline: none;
  box-shadow: 0 8px 22px rgba(30,58,138,0.3), 0 1px 3px rgba(0,0,0,0.1);
}
.site-page-nav:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.site-page-nav__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.92rem;
}
.site-page-nav__label {
  white-space: nowrap;
}
.site-page-nav--prev {
  left: 14px;
}
.site-page-nav--next {
  right: 14px;
}
/* When a left-side rail (TOC or icon legend) is mounted at wide widths,
   push the Previous arrow past it so the two don't overlap. The rails
   occupy up to ~240px from the left edge, so 260px clears them. */
@media (min-width: 1181px) {
  html.has-side-rail .site-page-nav--prev { left: 260px; }
}
.site-page-nav--prev:hover,
.site-page-nav--prev:focus-visible {
  transform: translateY(-50%) translateX(-2px);
}
.site-page-nav--next:hover,
.site-page-nav--next:focus-visible {
  transform: translateY(-50%) translateX(2px);
}

/* Dark mode: use a solid deep-indigo chip with white icon + label so the
   arrows are clearly legible against the dark page background. */
html[data-theme="dark"] .site-page-nav,
html[data-theme="dark"] .site-page-nav:link,
html[data-theme="dark"] .site-page-nav:visited {
  background: rgba(60,58,135,0.92);
  color: #ffffff !important;
  border-color: rgba(191,187,255,0.4);
  box-shadow: 0 6px 18px rgba(0,0,0,0.4), 0 1px 3px rgba(0,0,0,0.2);
}
html[data-theme="dark"] .site-page-nav .site-page-nav__icon,
html[data-theme="dark"] .site-page-nav .site-page-nav__icon i,
html[data-theme="dark"] .site-page-nav .site-page-nav__label {
  color: #ffffff !important;
}
html[data-theme="dark"] .site-page-nav:hover,
html[data-theme="dark"] .site-page-nav:focus-visible {
  background: #6A66D5;
  color: #ffffff !important;
}
html[data-theme="dark"] .site-page-nav:hover .site-page-nav__icon,
html[data-theme="dark"] .site-page-nav:hover .site-page-nav__icon i,
html[data-theme="dark"] .site-page-nav:hover .site-page-nav__label,
html[data-theme="dark"] .site-page-nav:focus-visible .site-page-nav__icon,
html[data-theme="dark"] .site-page-nav:focus-visible .site-page-nav__icon i,
html[data-theme="dark"] .site-page-nav:focus-visible .site-page-nav__label {
  color: #ffffff !important;
}

/* Hide the labels on narrow screens so only compact arrow chips show,
   and pull them tighter against the edges. */
@media (max-width: 900px) {
  .site-page-nav { padding: 0.45rem 0.55rem; }
  .site-page-nav__label { display: none; }
  .site-page-nav--prev { left: 8px; }
  .site-page-nav--next { right: 8px; }
}
/* Avoid colliding with the Back-to-Top FAB in the bottom-right corner. */
@media (max-width: 640px) {
  .site-page-nav { font-size: 0.78rem; }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .site-page-nav { transition: none !important; }
  .site-page-nav:hover,
  .site-page-nav:focus-visible { transform: translateY(-50%) !important; }
}

/* Hide nav arrows in print */
@media print {
  .site-page-nav { display: none !important; }
}

/* ---------- Print stylesheet ---------- */
@media print {
  html, body { background: #fff !important; color: #000 !important; }
  .distill-site-header,
  .distill-site-footer,
  nav,
  .site-theme-toggle,
  .site-theme-toggle--floating,
  .site-theme-toggle--in-nav,
  .site-back-to-top,
  .site-toc,
  .cv-controls,
  footer a[href="#"],
  footer { display: none !important; }

  /* Force all collapsible sections open */
  details { display: block !important; }
  details > summary { display: block !important; pointer-events: none !important; }
  details:not([open]) > :not(summary) { display: revert !important; }
  details > summary::after,
  details > summary h3::after { display: none !important; content: none !important; }

  /* Article width + typography for print */
  .d-article, d-article, main, .resume { max-width: 100% !important; margin: 0 !important; padding: 0 !important; }
  a { color: #000 !important; text-decoration: underline; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #555; }

  /* Card: remove side gradient for print */
  .card { box-shadow: none !important; border: 1px solid #ccc !important; }
  .card::before, .card::after { display: none !important; }

  /* CV cards: keep ribbon accent as black bar so structure reads on paper */
  .edu-block, .exp-block, .project-card, .teach-block {
    break-inside: avoid;
    box-shadow: none !important;
    border: 1px solid #ddd !important;
    background: #fff !important;
  }
  .edu-block::before, .exp-block::before, .project-card::before, .teach-block::before {
    background: #333 !important;
  }

  h1, h2, h3, h4 { break-after: avoid; }
}
