/*
 * Inner pages: the front page's two photographs, fixed behind the page, each
 * in its own half with a 2px seam of white between them.
 *
 * Only two windows onto them ever show: the strip above the white content
 * card, and — on a page shorter than the screen — the gap above the nav bar.
 * So the photographs are pinned to the top edge, where the strip shows the
 * soft light above the trees, and drawn at least as tall as the screen so the
 * gap is always covered. On a desktop that is the front page's own scale, from
 * the same tokens; it grows only where the screen is taller than the picture
 * would be, which on a phone it always is.
 *
 * Aiming them exactly as the front page does, to put the trees in the same
 * place, was tried: the strip then held the tops of two canopies and half a
 * butterfly, cut off by the card, and the gap showed a second copy of the
 * picture meeting the first in a hard edge.
 *
 * Pseudo-elements rather than a <body> background, which is one image and
 * cannot hold two halves aimed independently. z-index -1 puts them behind
 * everything the page draws.
 */
body:not(.home)::before,
body:not(.home)::after {
    content: '';
    position: fixed;
    top: 0;
    width: calc(50% - 1px);
    height: 100vh;
    z-index: -1;
    background-repeat: no-repeat;
}

body:not(.home)::before {
    left: 0;
    background-image: url('../../img/hintergrund/baum-hand.webp');
    background-size: auto max(var(--bg-hand-size), 100vh);
    background-position: 52% 0;
}

body:not(.home)::after {
    right: 0;
    background-image: url('../../img/hintergrund/baum-buch.webp');
    background-size: auto max(var(--bg-book-size), 100vh);
    background-position: 51.5% 0;
}


/*
 * The document — not <body> — must be the scroll container.
 *
 * `height:100%` plus `overflow-x:hidden` on <body> turned the body into its own
 * nested scrollport: everything past one viewport height was clipped out of the
 * rendered box, window.onscroll stopped firing and window.scrollTo() became a
 * no-op. The horizontal-overflow guard belongs on <html>, where it propagates
 * to the viewport without creating a second scrollport.
 */
html {
    height: 100%;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

body {
    min-height: 100%;
    margin: 0;
}

.content {
    padding-top: 0px;
    min-height: 100vh;
}

/* Small-viewport units account for mobile browser chrome that expands and
   collapses on scroll; 100vh alone overshoots and forces a phantom scroll. */
@supports (min-height: 100svh) {
    .content {
        min-height: 100svh;
    }
}

/*
 * Inner pages carry the sticky return rail, which the front page does not, and
 * it sits in flow *above* .content. A flat 100vh here therefore made the
 * document one rail taller than the viewport, so the composition ran past the
 * fold and the page could be scrolled even before the footer was reached.
 * Subtracting it makes rail + content exactly one screen: the only scroll on a
 * page whose content fits is the one that brings the footer up.
 */
body:not(.home) .content {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - var(--above-content));
}

@supports (min-height: 100svh) {
    body:not(.home) .content {
        min-height: calc(100svh - var(--above-content));
    }
}

/*
 * The nav links point at #content, which is the first thing inside .content and
 * therefore starts exactly one rail down the document. Without this, following
 * one scrolled the page by that much and left it sitting on a stray 62px of
 * upward scroll, with the rail covering the top of the hero band it had just
 * scrolled to. The scroll margin cancels the offset so the anchor resolves to
 * the top of the page — which is where these links have always meant to land.
 */
#content {
    scroll-margin-top: var(--above-content);
}

/* Short pages used to pin their content directly under the logo and leave the
 * whole remainder of the viewport as one empty gap above the nav bar. A single
 * auto block margin splits that leftover space evenly above and below instead,
 * optically centring the content between the logo and the nav bar.
 *
 * It is self-cancelling: a page long enough to fill the viewport has no free
 * space to distribute, so nothing moves and long pages are unaffected. It also
 * replaces the `margin-top:auto` that used to sit on .mainBar — the trailing
 * auto margin already pushes the bar to the bottom, and having both would give
 * three competing auto margins and land the content a third of the way down.
 */
body:not(.home) .content > .bar {
    margin-block: auto;
}

/* Keep the nav bar a fixed distance below the content so the circle and its
 * white glow — which reach up over the bar's top edge — never wash out the last
 * line of a page.
 *
 * This has to sit outside .bar rather than as padding inside it: padding would
 * be part of the box the rule above centres, which pushes the text visibly
 * above centre. As a margin it is excluded from the centred box, so the text
 * ends up optically centred between the logo and the circle, and still clear
 * of the glow when a long page is scrolled to its end.
 */
body:not(.home) .content > .mainBar {
    margin-top: var(--nav-clear);
}

.page-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: var(--z-backdrop);
    transition: opacity 0.4s ease;
}

body.backdrop-active .page-backdrop {
    display: block;
}

body.backdrop-circle .mainBar,
body.backdrop-circle .navcircle-section {
    z-index: var(--z-lifted);
}

.pu-book-wrapper.is-lifted {
    position: fixed;
    z-index: var(--z-lifted);
    outline: none;
    border: none;
}
