/* Transition between pages, the same in every browser (no View Transitions API).
   A fixed sheet in the page background colour (html.main-site in style.css) covers
   the screen. Leaving: it fades in over the page while the click handler in page.tpl
   waits; the next page then loads under it already covered, and it fades out: one
   after the other, no cross-fade. The page itself is never faded (fading a whole
   page means re-rendering it on every frame, which was jerky); only this flat sheet
   changes opacity. It sits under the top menu (z-index 100), so the menu is never
   covered, and under the particle canvas on the homepage (z-index 90). */

/* Switch off style.css's older fade of the page content (.wrapper): the sheet below
   replaces it. */
.wrapper,
body.fadeout .wrapper {
    animation: none;
}

body::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 85;
    background: #0a0a0a;
    pointer-events: none;
    opacity: 0;
    animation: veil-out 750ms ease-out both;
}

body.fadeout::after {
    animation: veil-in 750ms ease-in forwards;
}

/* On arrival the sheet stays opaque until the page has settled: html.veil-wait is set
   at the top of the page and removed by the script in page.tpl (after load and an
   idle moment, at the latest after 1.2 s), which then lets the fade-out run. */
html.veil-wait body:not(.fadeout)::after {
    animation-play-state: paused;
}

/* The particle canvas (js/background_particles.js, class "particle-bg") is not hidden by
   the sheet: while the sheet is on screen it is lifted above it (z-index 90; the
   homepage canvas is always there), then drops back to its own z-index, behind the
   page content, once the sheet has gone. The animation below holds 90 for the length of
   the arrival fade and shares its wait (html.veil-wait); on leaving, the class
   "fadeout" lifts it at once. During those moments the particles are drawn over
   the page rather than behind it. */
.particle-bg {
    animation: particles-over 750ms linear both;
}

@keyframes particles-over {
    0%, 99% { z-index: 90; }
}

html.veil-wait body:not(.fadeout) > .particle-bg {
    animation-play-state: paused;
}

body.fadeout > .particle-bg {
    animation: none;
    z-index: 90 !important;
}

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

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

/* Top menu, on click (desktop). "pressed" (the clicked page link) and "leave-left" /
   "leave-right" (the other page links, before / after it) are added by the click
   handler in page.tpl. The clicked link keeps its size and turns white (it is drawn
   white as the current link on the next page, so there is no jump); the others fade
   out towards their own side. Only transform and opacity change. */
html body .topbar a.pressed {
    color: #fff;
}

@keyframes nav-out-left {
    to { opacity: 0; transform: translateX(-24px); }
}

@keyframes nav-out-right {
    to { opacity: 0; transform: translateX(24px); }
}

@media (min-width: 1025px) {
    body.fadeout .menu_page a.leave-left {
        animation: nav-out-left 300ms ease-in forwards;
    }

    body.fadeout .menu_page a.leave-right {
        animation: nav-out-right 300ms ease-in forwards;
    }
}

/* Language links: a short pulse on click */
@keyframes nav-press {
    0%   { transform: scale(1);    color: rgba(255,255,255,0.65); }
    45%  { transform: scale(1.08); color: #fff; }
    100% { transform: scale(1);    color: #fff; }
}

@media (min-width: 1025px) {
    html body .topbar .menu_language a.pressed {
        animation: nav-press 220ms ease-out forwards;
    }
}

/* Accessibility: no fading (the click handler still waits before loading the page) */
@media (prefers-reduced-motion: reduce) {
    body::after,
    body.fadeout::after,
    .particle-bg,
    body.fadeout .menu_page a,
    html body .topbar a.pressed,
    .menu_page a {
        animation: none;
    }
}
