/* ==========================================================================
   Dark mode
   Turned on by <html data-theme="dark"> (set before the page paints by the
   small script in each page's <head>; toggled by the ☾/☀ button in the header).
   Palette: a soft violet-tinted charcoal rather than pure black, so the purple
   accents and the rainbow header feel at home. All text/background pairs meet
   WCAG AA contrast (most reach AAA).
   ========================================================================== */

/* Light mode is the default. Say so explicitly: the pages declare support for both
   schemes, so without this a browser in dark mode would paint its own dark default
   page background behind the (light-mode) dark text. */
html, html[data-theme="light"] {
  color-scheme: only light;   /* "only": stops browsers' auto-dark features (Brave Night mode,
                                 Chrome "Auto Dark Mode") from repainting light mode; the
                                 site has its own dark mode instead */
  background: #fff;
}
html[data-theme="light"] body { background: #fff; }

html[data-theme="dark"] {
  color-scheme: dark;

  --dm-bg:        #121119;   /* page */
  --dm-surface:   #1a1923;   /* header, cards */
  --dm-surface-2: #201e2b;   /* open boxes, hover rows */
  --dm-border:    #302d40;
  --dm-text:      #e6e3ef;   /* body text        14.8:1 on bg */
  --dm-strong:    #f5f3fb;   /* headings         17.1:1 */
  --dm-muted:     #a9a5ba;   /* secondary text    7.8:1 */
  --dm-faint:     #908ca3;   /* captions          5.6:1 */
  --dm-link:      #82bdf2;   /* links             9.4:1 */
  --dm-accent:    #b9a8ff;   /* purple accents    9.0:1 */
  --dm-accent-bg: #2a2445;   /* purple pill fill */
  --dm-accent-on: #6d56e3;   /* active pill fill (white text 5.1:1) */
  --dm-green:     #86d6a2;   /* code / "cited by" 10.9:1 */
  --dm-rose:      #f2b3aa;   /* header nav links  10.5:1 */

  background: var(--dm-bg);
}

html[data-theme="dark"] body { background: var(--dm-bg); color: var(--dm-text); }

/* ---- general text & links ---- */
html[data-theme="dark"] p,
html[data-theme="dark"] .text-content p { color: var(--dm-text); }
html[data-theme="dark"] a,
html[data-theme="dark"] A.class1, html[data-theme="dark"] A.class2 { color: var(--dm-link); }
html[data-theme="dark"] strong, html[data-theme="dark"] b { color: var(--dm-strong); }
html[data-theme="dark"] h1, html[data-theme="dark"] h2,
html[data-theme="dark"] h3, html[data-theme="dark"] h4 { color: var(--dm-strong); }
html[data-theme="dark"] .gt-fellowship { color: var(--dm-green); }
html[data-theme="dark"] .collaborator { color: #e8b27a; }

/* ---- header ---- */
html[data-theme="dark"] .site-header {
  background: var(--dm-surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6), 0 6px 14px rgba(0, 0, 0, 0.45);
}
html[data-theme="dark"] body.scrolled .site-header::after {
  background: linear-gradient(to bottom, rgba(18, 17, 25, 0.6), transparent);
}
html[data-theme="dark"] .nav-name a { color: var(--dm-strong); }
html[data-theme="dark"] .nav-name a:hover { color: var(--dm-accent); }
html[data-theme="dark"] .navbar-element,
html[data-theme="dark"] .nav-links ul li { color: var(--dm-rose); }
html[data-theme="dark"] .nav-links ul li::after { background: var(--dm-accent); }
html[data-theme="dark"] #mobileMenuToggle { color: var(--dm-text); }
/* phone dropdown menu */
@media (max-width: 1000px) {
  html[data-theme="dark"] #navLinks {
    --menu-bg: var(--dm-surface);
    background: var(--dm-surface);
    border-color: var(--dm-border);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  }
  html[data-theme="dark"] #navLinks a:hover,
  html[data-theme="dark"] #navLinks a:focus { background: rgba(255, 255, 255, 0.06); }
}

/* ---- homepage left column ---- */
html[data-theme="dark"] .profile_image { filter: brightness(0.94); }
html[data-theme="dark"] .photo-sheen {
  background-image: linear-gradient(110deg, rgba(255, 255, 255, 0) 34%, rgba(255, 255, 255, 0.17) 47%, rgba(255, 255, 255, 0.06) 54%, rgba(255, 255, 255, 0) 64%);
}
html[data-theme="dark"] .photo:hover .profile_image {
  box-shadow: 0 0 0 2px var(--dm-bg), 0 0 4px 4px #8f7be0, 0 10px 25px rgba(0, 0, 0, 0.5);
}
html[data-theme="dark"] {
  --ring-color: #4f8fc4;
  --ring-color-hover: #e6e3ef;
}
html[data-theme="dark"] .social-icons a {
  background-color: var(--dm-surface);
  color: var(--dm-text);
  box-shadow: inset 0 0 0 var(--ring) var(--ring-color), 0 0 20px 10px rgba(0, 0, 0, 0.25);
}
html[data-theme="dark"] .social-icons a .fab,
html[data-theme="dark"] .social-icons a .ai,
html[data-theme="dark"] .social-icons a .fas { color: var(--dm-text); }
html[data-theme="dark"] .email-reveal img { filter: brightness(0.88); }
html[data-theme="dark"] .cv-btn a {
  background: var(--dm-surface);
  color: var(--dm-text);
  box-shadow: inset 0 0 0 var(--cv-ring) #4a4170, 0 10px 24px rgba(0, 0, 0, 0.45);
}
html[data-theme="dark"] .cv-btn a::before { background: linear-gradient(120deg, #cbbcff 0%, #a993ff 100%); }
html[data-theme="dark"] .cv-btn a:hover,
html[data-theme="dark"] .cv-btn a:focus-visible,
html[data-theme="dark"] .cv-btn a.is-hover {
  color: #15121f;
  box-shadow: inset 0 0 0 var(--cv-ring) #cbbcff, 0 14px 30px rgba(0, 0, 0, 0.5);
}

/* ---- Education list ---- */
html[data-theme="dark"] .cv-heading { color: var(--dm-accent); }
html[data-theme="dark"] .cv-heading::after { background: linear-gradient(to right, var(--dm-border), transparent); }
html[data-theme="dark"] .cv-item:hover { background-color: var(--dm-surface-2); }
html[data-theme="dark"] .cv-title { color: var(--dm-strong); }
html[data-theme="dark"] .cv-org { color: var(--dm-muted); }
html[data-theme="dark"] .cv-note { color: var(--dm-faint); }
html[data-theme="dark"] .cv-label { color: var(--dm-muted); }
html[data-theme="dark"] .cv-date { background: var(--dm-accent-bg); color: var(--dm-accent); }
/* logos keep their own colours on a light square */
html[data-theme="dark"] .cv-logo { background: #f3f1f8; }
/* round seals (white inside, transparent outside) need no tile */
html[data-theme="dark"] .cv-logo--round:has(img) { background: transparent; }

/* ---- globe ---- */
html[data-theme="dark"] .visitor-globe canvas { filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.55)); }
html[data-theme="dark"] .visitor-globe figcaption { color: var(--dm-muted); }
html[data-theme="dark"] .globe-credit { color: var(--dm-faint); }
html[data-theme="dark"] .globe-tip { background: rgba(245, 243, 251, 0.95); color: #15121f; }

/* ---- shared pill buttons & boxes (abstract, cite, name) ---- */
html[data-theme="dark"] .abs-btn,
html[data-theme="dark"] .name-btn {
  background: var(--dm-accent-bg);
  border-color: #4a4170;
  color: var(--dm-accent);
}
html[data-theme="dark"] .abs-btn:hover, html[data-theme="dark"] .abs-btn:focus-visible,
html[data-theme="dark"] .name-btn:hover, html[data-theme="dark"] .name-btn:focus-visible {
  background: #352d58;
  border-color: #6a5bb0;
}
html[data-theme="dark"] .abs-btn[aria-expanded="true"],
html[data-theme="dark"] .name-btn:not(.visitor-btn)[aria-expanded="true"] {
  background: var(--dm-accent-on);
  border-color: var(--dm-accent-on);
  color: #fff;
}
html[data-theme="dark"] .abstract-box.is-open .abs-inner,
html[data-theme="dark"] .name-box.is-open .name-inner {
  background: var(--dm-surface-2);
  border-color: var(--dm-border);
  border-left-color: #8f7be0;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
}
html[data-theme="dark"] .abs-label,
html[data-theme="dark"] .name-list dt { color: var(--dm-accent); }
html[data-theme="dark"] .abstract-box p,
html[data-theme="dark"] .name-list dd { color: var(--dm-text); }
html[data-theme="dark"] .abs-tldr p { color: var(--dm-strong); }
html[data-theme="dark"] .abs-full { border-top-color: var(--dm-border); }
html[data-theme="dark"] .abs-more { color: var(--dm-accent); }
html[data-theme="dark"] .cite-code { color: var(--dm-green); }
html[data-theme="dark"] .cite-copy {
  background: var(--dm-surface);
  border-color: #4a4170;
  color: var(--dm-accent);
}
html[data-theme="dark"] .cite-copy:hover { background: var(--dm-accent-bg); }
html[data-theme="dark"] .cite-copy.is-done { background: #1f8a4c; border-color: #1f8a4c; color: #fff; }

/* ---- News ---- */
html[data-theme="dark"] .news-date { color: var(--dm-accent); }
html[data-theme="dark"] .news-text { color: var(--dm-text); }
html[data-theme="dark"] .news-list li + li { border-top-color: var(--dm-border); }
html[data-theme="dark"] .news-box {
  --news-bg: var(--dm-surface);
  border-color: var(--dm-border);
}
html[data-theme="dark"] .news-list::-webkit-scrollbar-thumb { background-color: #4a4170; }
html[data-theme="dark"] .news-list::-webkit-scrollbar-thumb:hover { background-color: #6a5bb0; }
@supports not selector(::-webkit-scrollbar) {
  html[data-theme="dark"] .news-list { scrollbar-color: #4a4170 transparent; }
}
html[data-theme="dark"] .news-list::after { background: linear-gradient(to bottom, rgba(26, 25, 35, 0), var(--news-bg)); }

/* ---- research page ---- */
html[data-theme="dark"] .publication-card {
  background-color: var(--dm-surface);
  border-color: var(--dm-border);
}
html[data-theme="dark"] .publication-card h3 { color: var(--dm-strong); }
html[data-theme="dark"] .publication-authors { color: var(--dm-muted); }
html[data-theme="dark"] .author-list a { color: #a9b4ff; }
html[data-theme="dark"] .author-list [style*="4500b6"] { color: #cdbfff !important; }
html[data-theme="dark"] .publication-venue { color: var(--dm-muted); }
html[data-theme="dark"] .publication-access,
html[data-theme="dark"] .publication-access strong { color: var(--dm-text); }
html[data-theme="dark"] .publication-access a { color: var(--dm-green); }
html[data-theme="dark"] .equal-contribution-note { color: #d8d27a; }
html[data-theme="dark"] ol > li::marker { color: var(--dm-muted); }
html[data-theme="dark"] #searchInput { background: var(--dm-surface); border-color: var(--dm-border); color: var(--dm-text); }

/* ---- footer ---- */
html[data-theme="dark"] footer { border-top-color: var(--dm-border); color: var(--dm-faint); }
html[data-theme="dark"] .footer { color: #8fb6d6; }

/* ---- theme toggle button (both themes) ---- */
.theme-toggle {
  all: unset;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  color: #4a2fb0;                 /* moon: the site's violet */
}
.theme-toggle:hover { background: rgba(90, 60, 200, 0.1); color: #3a1f9e; }
.theme-toggle:focus-visible { outline: 2px solid #6a4fd6; outline-offset: 2px; }
.theme-toggle--bar { position: relative; top: -3px; }   /* line up with the nav links */
.theme-toggle .ti { display: block; width: 28px; height: 28px; overflow: visible; transition: transform 0.45s ease; }
.theme-toggle:hover .ti { transform: rotate(-18deg); }
html[data-theme="dark"] .theme-toggle { color: #f5c451; }  /* sun: warm amber */
html[data-theme="dark"] .theme-toggle:hover { background: rgba(245, 196, 81, 0.12); color: #ffd36b; }
html[data-theme="dark"] .theme-toggle:hover .ti { transform: rotate(45deg); }

/* One icon that morphs: in light mode a crescent moon (a disc with a
   circular bite taken out); switching to dark, the bite slides away,
   the disc shrinks to the sun, and the rays turn in. Reverses on the way back. */
.ti-orb .ti-disc, .ti-orb .ti-cut, .ti-orb .ti-rays { transform-origin: 12px 12px; }
.ti-orb .ti-disc { transition: transform 0.5s cubic-bezier(0.45, 0, 0.2, 1) 0.1s; }
.ti-orb .ti-cut  { transition: transform 0.5s cubic-bezier(0.45, 0, 0.2, 1) 0.1s; }
.ti-orb .ti-rays {
  opacity: 0; transform: scale(0.5) rotate(-60deg);
  transition: opacity 0.25s ease, transform 0.35s ease;   /* leave quickly */
}
html[data-theme="dark"] .ti-orb .ti-disc { transform: scale(0.5); transition-delay: 0s; }
html[data-theme="dark"] .ti-orb .ti-cut  { transform: translate(9px, -9px); transition-delay: 0s; }
html[data-theme="dark"] .ti-orb .ti-rays {
  opacity: 1; transform: none;
  transition: opacity 0.35s ease 0.25s, transform 0.55s cubic-bezier(0.2, 0.7, 0.3, 1) 0.2s;   /* arrive after the disc */
}
.theme-toggle { transition: background-color 0.2s ease, color 0.5s ease; }
@media (prefers-reduced-motion: reduce) {
  .ti-orb .ti-disc, .ti-orb .ti-cut, .ti-orb .ti-rays, .theme-toggle .ti { transition: none !important; }
}

/* Switching theme, the smooth way: the whole page crossfades from the old
   look to the new one as one image (javascript/theme.js starts a view
   transition), while the toggle is lifted out so its morph plays on top. */
::view-transition-old(theme-toggle) { display: none; }
::view-transition-new(theme-toggle) { animation: none; }
html.theme-vt::view-transition-group(root),
html.theme-vt::view-transition-group(site-header) { animation-duration: 0.6s; }
html.theme-vt::view-transition-old(root),
html.theme-vt::view-transition-old(site-header) { animation: 0.6s cubic-bezier(0.4, 0, 0.2, 1) both vt-theme-out; }
html.theme-vt::view-transition-new(root),
html.theme-vt::view-transition-new(site-header) { animation: 0.6s cubic-bezier(0.4, 0, 0.2, 1) both vt-theme-in; }
@keyframes vt-theme-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes vt-theme-in  { from { opacity: 0; } to { opacity: 1; } }

/* Fallback (no view transitions, or reduced motion): fade every colour at once.
   The toggle keeps its own transitions for the morph. */
html.theme-anim, html.theme-anim *:not(.theme-toggle):not(.theme-toggle *),
html.theme-anim *::before, html.theme-anim *::after {
  transition: background-color 0.5s ease, color 0.5s ease, border-color 0.5s ease,
              fill 0.5s ease, stroke 0.5s ease, box-shadow 0.5s ease !important;
}

/* In the bar on larger screens; inside the dropdown menu on phones */
.theme-menu-item { display: none !important; }
.theme-toggle--menu {
  width: 34px;
  height: 34px;
  border-radius: 50%;
}
.theme-toggle--menu .ti { width: 24px; height: 24px; }
.theme-toggle-label {               /* kept for screen readers only */
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 1000px) {
  .theme-toggle--bar { display: none; }
  .theme-menu-item { display: block !important; }
  .theme-menu-item::after { display: none !important; }
  /* make room for the extra icon in the one-row menu */
  #navLinks ul { margin-left: 6px; margin-right: 6px; padding-left: 10px; padding-right: 10px; }
  #navLinks ul li:nth-last-child(2)::after { margin-right: 6px; }
  .theme-toggle--menu { width: 30px; height: 30px; }
}
@media (max-width: 380px) {
  #navLinks ul li:not(:last-child)::after { margin-left: 10px; margin-right: 10px; }
  #navLinks ul li:nth-last-child(2)::after { margin-right: 4px; }
}

/* ---- News photos (dark) ---- */
html[data-theme="dark"] .news-photos-btn,
html[data-theme="dark"] .text-content .news-text a.news-photos-link {
  color: var(--dm-accent);
  text-decoration-color: rgba(185, 168, 255, 0.55);
}
html[data-theme="dark"] .news-photos-btn:hover,
html[data-theme="dark"] .text-content .news-text a.news-photos-link:hover { color: #d6cbff; }
html[data-theme="dark"] .news-thumb { background: var(--dm-surface-2); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); }
html[data-theme="dark"] .news-strong { color: var(--dm-strong); }
html[data-theme="dark"] .news-credit,
html[data-theme="dark"] .text-content p.news-credit { color: var(--dm-faint); }
html[data-theme="dark"] .text-content .news-credit a:hover { color: var(--dm-accent); }

/* ---- Night sky (dark mode only; drawn by javascript/night-sky.js) ---- */
#night-sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.8s ease;
}
#night-sky.is-on { opacity: 1; transition-duration: 0.15s; }   /* the stars themselves fade in (night-sky.js) */
/* the page colour stays on <html>; the body is transparent so the stars show
   through, while cards, header and boxes keep their own surfaces */
html[data-theme="dark"] body { background: transparent; }
/* shooting stars: a clipped layer inside the header, behind its contents */
.header-sky { position: absolute; inset: 0; border-radius: inherit; overflow: hidden; pointer-events: none; z-index: -1; }
.header-sky canvas { display: block; width: 100%; height: 100%; }
html:not([data-theme="dark"]) .header-sky { display: none; }
@media print { #night-sky, .header-sky { display: none; } }

/* light that follows the pointer: a little brighter on the dark surfaces */
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  html[data-theme="dark"] .publication-card::before, html[data-theme="dark"] .news-box::before {
    background: radial-gradient(340px circle at var(--sx, 50%) var(--sy, 50%), rgba(169, 150, 255, 0.11), transparent 70%);
  }
  html[data-theme="dark"] .publication-card::after, html[data-theme="dark"] .news-box::after {
    background: radial-gradient(250px circle at var(--sx, 50%) var(--sy, 50%), rgba(196, 182, 255, 0.95), transparent 70%);
  }
}
