/* ══════════════════════════════════════════════════════════════════════
   ATLAS PAGE TURN

   Cross-document view transition for the pages in the navigation bar,
   which read as the sheets of a printed atlas. The outgoing page is
   captured as a snapshot and swung away on a hinge at the left edge, the
   way a sheet turns on the spine of a bound book; the arriving page is
   already in place underneath and is revealed by it.

   This file is linked only by pages that set Page.AtlasPage (see
   Shared/_Public.cshtml, which also owns the reading order), so the
   profile and compare pages hanging off each section keep the plain
   navigation they have always had. A cross-document view transition runs
   only when BOTH documents opt in, so dropping a page from that list is
   all it takes to take it back out of the sequence.

   Browsers without cross-document view transitions ignore every rule in
   this file and navigate exactly the way they do today. There is no
   fallback path to maintain.
   ══════════════════════════════════════════════════════════════════════ */

@media not (prefers-reduced-motion: reduce) {

@view-transition { navigation: auto; }

/* How long a sheet takes to swing. One number, read by all four animations
   below; the phone override further down is the only thing that changes it. */
:root { --atlas-turn: 880ms; }

/* The navbar sits out of the turn. Naming it lifts it out of the page
   snapshot into a group of its own, so it holds still while the sheet
   turns underneath it — the binding of the atlas rather than part of the
   page. Old and new share its geometry exactly, so all that is left to
   animate is the active link moving, which the default cross-fade does. */
.public-navbar { view-transition-name: atlas-nav; }

/* The default root transition is a cross-fade, and the UA stylesheet sets
   up `plus-lighter` blending plus an isolation group to make that look
   right. Both have to be undone before the two snapshots can behave as
   opaque sheets of paper stacked one on the other — left alone, the
   turning page washes out the page beneath it instead of covering it. */
::view-transition-image-pair(root) { isolation: auto; }

::view-transition-old(root),
::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
    backface-visibility: hidden;
}

/* ── Forward: deeper into the atlas ──────────────────────────────────
   The page being left turns away on top. The arriving page holds still
   underneath and only takes the shadow of the sheet passing over it. */
::view-transition-old(root) {
    z-index: 1;
    transform-origin: left center;
    animation: atlas-turn-away var(--atlas-turn) cubic-bezier(.36, .02, .28, 1) both;
}

::view-transition-new(root) {
    z-index: 0;
    animation: atlas-beneath var(--atlas-turn) cubic-bezier(.36, .02, .28, 1) both;
}

/* ── Backward: towards the front of the atlas ────────────────────────
   The same sheet coming back. Now it is the ARRIVING page that turns,
   swinging in from the spine over the page being left behind. */
:root[data-atlas-turn="back"]::view-transition-old(root) {
    z-index: 0;
    animation: atlas-beneath var(--atlas-turn) cubic-bezier(.36, .02, .28, 1) both;
}

:root[data-atlas-turn="back"]::view-transition-new(root) {
    z-index: 1;
    transform-origin: left center;
    animation: atlas-turn-back var(--atlas-turn) cubic-bezier(.36, .02, .28, 1) both;
}

/* Stopping at 90° leaves the sheet edge-on and projected to a line, so it
   vanishes on its own at the moment it stands upright — no back face to
   draw, and nothing mirrored ever shows. The brightness ramp is the light
   falling away as the page lifts off the flat. */
@keyframes atlas-turn-away {
    from { transform: perspective(2200px) rotateY(0deg);   filter: brightness(1); }
    to   { transform: perspective(2200px) rotateY(-90deg); filter: brightness(.7); }
}

@keyframes atlas-turn-back {
    from { transform: perspective(2200px) rotateY(-90deg); filter: brightness(.7); }
    to   { transform: perspective(2200px) rotateY(0deg);   filter: brightness(1); }
}

/* The page underneath: in the shadow of the sheet crossing it, back to
   full light once that sheet is upright and out of the way. */
@keyframes atlas-beneath {
    from { filter: brightness(.86); }
    to   { filter: brightness(1); }
}

/* A full-width sheet has further to swing on a phone than the gesture
   deserves; the same turn reads better a little quicker. */
@media (max-width: 576px) {
    :root { --atlas-turn: 640ms; }
}

}
