/* page-transition.css — the split curtain between pages.
 *
 * One file for both locales, loaded site-wide from
 * components/layout/default.blade.php.
 *
 * THE OPENING IS PURE CSS. The panels animate away on every page load with no
 * script involved, so a failure to load page-transition.js leaves the site
 * perfectly usable rather than hidden behind a navy screen. JavaScript only
 * closes the curtain, on the way out.
 *
 * Direction: the panels are `is-start` / `is-end` rather than left / right, so
 * they leave towards the reading edges in both languages.
 */

.ul-ptrans {
    --pt-ease: cubic-bezier(.76, 0, .24, 1);
    --pt-open: .85s;
    --pt-close: .42s;

    /* How long the closed curtain is held before it parts. Shared by the panels
       and by the caption over them, so the two cannot drift apart. */
    --pt-hold: .45s;

    position: fixed;
    inset: 0;
    z-index: 9998;

    /* Once the panels are gone the overlay must not eat clicks. It is turned
       back on only while leaving. */
    pointer-events: none;
}

/* ── panels ─────────────────────────────────────────────────────────────── */

.ul-ptrans-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 1;

    /* 51%, not 50%: two halves that meet exactly can show a hairline of the
       page between them on fractional device pixel ratios. */
    width: 51%;

    background: var(--ul-primary);
    will-change: transform;

    animation-duration: var(--pt-open);
    animation-timing-function: var(--pt-ease);

    /* `both`, not `forwards`. The backwards half is what matters: during the
       delay below the panel must already be holding the animation's FIRST
       keyframe — closed. With `forwards` it would instead sit at its own
       resting transform, which is off-screen, so the curtain would be absent
       for 450ms and then snap shut just to open again. */
    animation-fill-mode: both;

    /* A short hold before the panels part. Without it the animation starts the
       instant this element is styled — which on a page whose HTML takes fifteen
       seconds to arrive is long before there is anything behind the curtain to
       reveal, so it opens onto a blank page and the effect is wasted. */
    animation-delay: var(--pt-hold);
}


/* The RESTING transform is off-screen — the same place the opening animation
   finishes. That is what makes closing possible: `.is-leaving` sets
   `animation: none`, and without a matching resting value the panel would snap
   to centre before the transition could take hold, so the curtain would appear
   instantly instead of sliding in. */
.ul-ptrans-panel.is-start {
    inset-inline-start: 0;
    transform: translateX(-101%);
    animation-name: ul-ptrans-open-start;
}

.ul-ptrans-panel.is-end {
    inset-inline-end: 0;
    transform: translateX(101%);
    animation-name: ul-ptrans-open-end;
}

/* Physical directions inside the keyframes, mirrored by a [dir] rule below —
   a keyframe cannot use a logical property. */
@keyframes ul-ptrans-open-start {
    from { transform: translateX(0); }
    to   { transform: translateX(-101%); }
}

@keyframes ul-ptrans-open-end {
    from { transform: translateX(0); }
    to   { transform: translateX(101%); }
}

/* In Arabic `is-start` sits on the right, so it leaves to the right. The
   resting transform has to mirror with the animation or the pair would close
   from the wrong sides. */
[dir="rtl"] .ul-ptrans-panel.is-start {
    transform: translateX(101%);
    animation-name: ul-ptrans-open-end;
}

[dir="rtl"] .ul-ptrans-panel.is-end {
    transform: translateX(-101%);
    animation-name: ul-ptrans-open-start;
}

/* NOTHING opens unless the visitor came from one of our own pages — see the
   note in page-transition.blade.php.
 *
 * The resting transform is already off-screen, so withholding the animation is
 * enough: a cold arrival gets no curtain at all, rather than one that has to be
 * animated out of the way of a page that is still loading.
 *
 * Placed AFTER the [dir] rules and written out per panel — at (0,4,0) it beats
 * `[dir="rtl"] .ul-ptrans-panel.is-start` on specificity rather than on source
 * order. An earlier version sat above them at equal specificity and quietly
 * lost, so the curtain kept opening on first visits. */
.ul-ptrans:not(.is-return) .ul-ptrans-panel.is-start,
.ul-ptrans:not(.is-return) .ul-ptrans-panel.is-end {
    animation: none;
}

/* ── arriving ───────────────────────────────────────────────────────────── */

/* The crest and the page's name are held while the curtain is still closed,
   then fade as it parts. Without this an arrival was a bare navy screen: the
   body is only switched on by `.is-leaving`, which belongs to the page being
   left, never to the one being opened.
 *
 * The delay matches the panels' hold exactly, so the caption is readable for
 * the whole time the curtain is shut and starts leaving with it, not after. */
/* Longer than it looks like it needs to be. The panels ease out of a slow
   start, so 250ms after they begin they have travelled under a tenth of their
   width — a short fade emptied the curtain while it still looked shut. This
   runs on past that, so the caption leaves WITH the curtain rather than before
   it. */
/* The exact reverse of the entrance, so leaving a page and arriving at the next
   one are visibly one gesture played forwards and then backwards.
 *
 * Reversed in all four respects, not just opacity:
 *   blur      14px -> 0        becomes  0 -> 14px
 *   scale     .92  -> 1        becomes  1 -> .92
 *   duration  .5s              stays    .5s
 *   easing    cubic-bezier(.22, 1, .36, 1)
 *             becomes cubic-bezier(.64, 0, .78, 0)
 *
 * A curve is reversed by swapping its control points and subtracting each
 * coordinate from 1: (x1,y1,x2,y2) becomes (1-x2, 1-y2, 1-x1, 1-y1). Both y
 * values here are 1, so BOTH become 0 — the trailing 0 is not a typo, and
 * writing 1 there instead leaves the exit lagging a third behind the entrance
 * at its midpoint, which is measurable and was in fact the first attempt.
 * The result turns the entrance's decelerate-into-place into an
 * accelerate-away. */
.ul-ptrans.is-return .ul-ptrans-body {
    opacity: 1;
    animation: ul-ptrans-caption-out .5s cubic-bezier(.64, 0, .78, 0)
               calc(var(--pt-hold) + .1s) forwards;
}

@keyframes ul-ptrans-caption-out {
    from {
        opacity: 1;
        filter: blur(0);
        transform: translateY(-50%) scale(1);
    }

    to {
        opacity: 0;
        filter: blur(14px);
        transform: translateY(-50%) scale(.92);
    }
}

/* ── the middle ─────────────────────────────────────────────────────────── */

/* Hidden by default — that is the state for a cold arrival, where there is no
   curtain at all. It is turned on both when leaving (below) and when arriving
   from one of our own pages, so the visitor never faces a bare colour field. */
.ul-ptrans-body {
    position: absolute;
    inset-inline: 0;
    top: 50%;

    /* Above the panels. Both are positioned with an automatic z-index, so
       without this they would be ordered by their position in the markup —
       which happens to be right today, and would silently stop being right the
       moment someone reorders the element. */
    z-index: 2;

    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 0 24px;
    text-align: center;
    opacity: 0;
    transition: opacity .3s ease;
}

.ul-ptrans-mark {
    width: clamp(56px, 6vw, 78px);
    height: auto;
    display: block;
}

.ul-ptrans-label {
    color: #fff;
    font-size: clamp(17px, 2vw, 26px);
    font-weight: 700;
    line-height: 1.35;
    max-width: 22ch;
    text-wrap: balance;
}

/* ── the creeping bar ───────────────────────────────────────────────────── */

.ul-ptrans-bar {
    position: absolute;
    inset-inline: 0;
    top: 0;
    height: 3px;
    overflow: hidden;
}

.ul-ptrans-bar i {
    display: block;
    height: 100%;
    width: 0;
    background: var(--ul-c3);
    box-shadow: 0 0 10px rgba(254, 190, 53, .8);
}

/* ── leaving ────────────────────────────────────────────────────────────── */

/* (0,3,0) against the (0,2,0) opening rules, so it wins on specificity rather
   than on source order. */
.ul-ptrans.is-leaving {
    pointer-events: auto;
}

/* THE CLOSING MOTION IS NOT HERE — it is driven by element.animate() in
   page-transition.js.
 *
 * The reason is determinism, not a proven CSS failure. Closing means starting
 * from wherever the finished opening animation left the panel, and CSS has two
 * awkward ways to express that: cancel the filled animation and transition the
 * transform (the transition has no reliable start value), or declare a second
 * @keyframes and hope the engine treats it as a new animation rather than a
 * continuation. WAAPI states both endpoints outright, so neither question
 * arises. nav-curtain.js animates from JS for the same reason.
 *
 * Worth recording because it cost time: both CSS attempts LOOKED broken when
 * tested in the app's preview pane, which reports `document.hidden === true`.
 * A hidden document does not tick animations — it jumps them straight to their
 * end state, so every approach appears to snap. Nothing about motion can be
 * measured there by timing. What does work is scrubbing: pause the animation,
 * set `currentTime` by hand and read the geometry back. */

/* The caption waits for the curtain to actually meet before it arrives.
 *
 * It used to fade in alongside the panels, which put the crest and the page's
 * name over a page that was still half uncovered — the text appeared to float
 * on the page rather than on the curtain. The delay is exactly the panels'
 * travel, so it begins on the frame they close.
 *
 * `both` matters: the backwards half holds the first keyframe — invisible and
 * blurred — through the delay. Without it the caption would sit fully visible
 * for those 420ms and then jump back to blurred to animate in. */
.ul-ptrans.is-leaving .ul-ptrans-body {
    animation: ul-ptrans-caption-in .5s cubic-bezier(.22, 1, .36, 1) var(--pt-close) both;
}

/* translateY(-50%) is repeated in both keyframes on purpose — it is what
   centres the block, and a transform in a keyframe replaces the declared one
   rather than adding to it. Dropping it here would slide the caption down by
   half its own height for the length of the animation. */
@keyframes ul-ptrans-caption-in {
    from {
        opacity: 0;
        filter: blur(14px);
        transform: translateY(-50%) scale(.92);
    }

    to {
        opacity: 1;
        filter: blur(0);
        transform: translateY(-50%) scale(1);
    }
}

/* Decelerating and stopping at 92%: the bar cannot know when a 17-second
   response will arrive, so it must never claim to be finished. It is filled the
   rest of the way only when the next page actually paints — which happens by
   this element being replaced wholesale. */
.ul-ptrans.is-leaving .ul-ptrans-bar i {
    animation: ul-ptrans-creep 14s cubic-bezier(.08, .72, .18, 1) forwards;
}

@keyframes ul-ptrans-creep {
    0%   { width: 0; }
    12%  { width: 32%; }
    35%  { width: 58%; }
    65%  { width: 78%; }
    100% { width: 92%; }
}

@media (max-width: 575px) {
    .ul-ptrans-body {
        gap: 15px;
    }

    .ul-ptrans-label {
        font-size: 16px;
        max-width: 18ch;
    }
}
