/* ============================================================
   ResourceHub — Cinematic Theme Crossfade
   ------------------------------------------------------------
   Provides a buttery-smooth full-page dissolve / crossfade.

   Driven by static/js/theme.js.

   1. View Transitions API (Chrome, Edge, Safari 18+): a GPU-
      composited crossfade between snapshots of the two themes.
      html.theme-switching (set for the duration) turns element
      transitions off so nothing fades a second time underneath.
   2. Fallback for other browsers: html.theme-transition gives
      every element one uniform 0.35s colour transition.
   ============================================================ */

/* ------------------------------------------------------------
   1. Native GPU View Transitions (Pure Cinematic Crossfade)
   ------------------------------------------------------------ */
::view-transition-group(root) {
    animation-duration: 0.35s;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

::view-transition-old(root) {
    animation: 0.35s cubic-bezier(0.4, 0, 0.2, 1) both theme-fade-out;
}

::view-transition-new(root) {
    animation: 0.35s cubic-bezier(0.4, 0, 0.2, 1) both theme-fade-in;
}

@keyframes theme-fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes theme-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* While the crossfade runs, the live page must jump straight to the new
   theme: element-level colour transitions (cards 0.45s, inputs 0.4s...)
   would otherwise animate under the snapshot and keep going after it. */
html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after {
    transition: none !important;
}

/* ------------------------------------------------------------
   2. Enhanced CSS Crossfade Fallback (Scoped during swap)
   ------------------------------------------------------------ */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
    transition:
        background-color 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        color 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        border-color 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        fill 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        stroke 0.35s cubic-bezier(0.4, 0, 0.2, 1) !important;
    transition-delay: 0s !important;
}

/* Exempt heavy blurred elements to preserve 60fps frame budget */
html.theme-transition .hero-orb,
html.theme-transition .card-glow,
html.theme-transition .page-loader,
html.theme-transition .page-loader *,
html.theme-transition .page-loader *::before,
html.theme-transition .page-loader *::after {
    transition: none !important;
}

/* Smooth navbar background & border transition without dropping blur */
html.theme-transition .navbar {
    transition: background-color 0.35s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.35s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* ------------------------------------------------------------
   3. Reduced Motion
   ------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
        animation: none !important;
    }

    html.theme-transition,
    html.theme-transition *,
    html.theme-transition *::before,
    html.theme-transition *::after {
        transition: none !important;
    }
}

/* ------------------------------------------------------------
   Brand logo theme swap (see brand_logo in macros.html).
   Lives here because this is the one stylesheet every page,
   landing included, loads.
   ------------------------------------------------------------ */
.brand-logo {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}
.brand-logo img { display: block; }
.brand-logo-dark { display: none !important; }
html.dark-mode .brand-logo-light { display: none !important; }
html.dark-mode .brand-logo-dark { display: block !important; }

/* Theme toggle icon: both glyphs are in the markup and CSS shows the
   right one, so the icon flips with the theme itself - no JS re-render. */
.theme-icon-dark { display: none !important; }
html.dark-mode .theme-icon-light { display: none !important; }
html.dark-mode .theme-icon-dark { display: inline-block !important; }
