/* Foldable screens, Two pages and Left / right (fold.js). Only pages that split on a foldable link this. */

/* Left / right: each single-column block's wrapper carries its halves (data-sb-fold-*) and nothing else, so the
   page lays out as it always did wherever it is not split. */
.sb-fold-block {
    display: contents;
}

/* The shell: the page itself stays loaded underneath, hidden and inert, so nothing is lost on unfold. */
html.sb-fold-on,
html.sb-fold-on body {
    overflow: hidden !important;
}

html.sb-fold-on body {
    visibility: hidden;
    /* Out of the flow, so the document is exactly one screen and cannot scroll under the halves. An #anchor
       followed inside a half (the gallery's lightbox) scrolls every ancestor in Safari, and Safari places the
       segments in document coordinates: the page underneath moved and took the halves off screen. fold.js
       puts the scroll back on unfold. */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
}

.sb-fold {
    position: fixed;
    inset: 0;
    z-index: 2147483647;
    margin: 0;
    padding: 0;
    background: #fff; /* what a half shows until its page has been checked */
    visibility: visible;
}

.sb-fold__frame {
    position: absolute;
    display: block;
    margin: 0;
    padding: 0;
    border: 0;
    background: #fff;
}

/* Hidden, so neither seen nor tappable nor focusable, until fold.js has checked where it landed. */
.sb-fold__frame--pending {
    visibility: hidden;
}

/* The hinge band: between the first segment's far edge and the second's near edge. */
.sb-fold__hinge {
    position: absolute;
    background: #000;
    pointer-events: none;
}

.sb-fold--book .sb-fold__hinge {
    top: 0;
    bottom: 0;
    left: calc(var(--sb-fold-1-x, env(viewport-segment-left 0 0)) + var(--sb-fold-1-w, env(viewport-segment-width 0 0)));
    width: calc(var(--sb-fold-2-x, env(viewport-segment-left 1 0)) - var(--sb-fold-1-x, env(viewport-segment-left 0 0)) - var(--sb-fold-1-w, env(viewport-segment-width 0 0)));
}

.sb-fold--tabletop .sb-fold__hinge {
    left: 0;
    right: 0;
    top: calc(var(--sb-fold-1-y, env(viewport-segment-top 0 0)) + var(--sb-fold-1-h, env(viewport-segment-height 0 0)));
    height: calc(var(--sb-fold-2-y, env(viewport-segment-top 0 1)) - var(--sb-fold-1-y, env(viewport-segment-top 0 0)) - var(--sb-fold-1-h, env(viewport-segment-height 0 0)));
}

/* Each frame is one half, from the browser's own segment boxes. The --sb-fold-* properties are only ever
   set by fold.js's test hook, which gives explicit boxes where no fold can be emulated.
   A half never reaches past the screen: Safari (27.1) measures a segment to the end of the document, not of
   the screen, so its far edge is also held to the shell's own box. */
.sb-fold--book .sb-fold__frame--1,
.sb-fold--tabletop .sb-fold__frame--1 {
    left: var(--sb-fold-1-x, env(viewport-segment-left 0 0));
    top: var(--sb-fold-1-y, env(viewport-segment-top 0 0));
    width: min(var(--sb-fold-1-w, env(viewport-segment-width 0 0)), 100% - var(--sb-fold-1-x, env(viewport-segment-left 0 0)));
    height: min(var(--sb-fold-1-h, env(viewport-segment-height 0 0)), 100% - var(--sb-fold-1-y, env(viewport-segment-top 0 0)));
}

.sb-fold--book .sb-fold__frame--2 {
    left: var(--sb-fold-2-x, env(viewport-segment-left 1 0));
    top: var(--sb-fold-2-y, env(viewport-segment-top 1 0));
    width: min(var(--sb-fold-2-w, env(viewport-segment-width 1 0)), 100% - var(--sb-fold-2-x, env(viewport-segment-left 1 0)));
    height: min(var(--sb-fold-2-h, env(viewport-segment-height 1 0)), 100% - var(--sb-fold-2-y, env(viewport-segment-top 1 0)));
}

.sb-fold--tabletop .sb-fold__frame--2 {
    left: var(--sb-fold-2-x, env(viewport-segment-left 0 1));
    top: var(--sb-fold-2-y, env(viewport-segment-top 0 1));
    width: min(var(--sb-fold-2-w, env(viewport-segment-width 0 1)), 100% - var(--sb-fold-2-x, env(viewport-segment-left 0 1)));
    height: min(var(--sb-fold-2-h, env(viewport-segment-height 0 1)), 100% - var(--sb-fold-2-y, env(viewport-segment-top 0 1)));
}

/* The second page: what exists once per screen shows in the first half only. Consent is a cookie and
   chat history is localStorage, so both halves share them anyway. */
html[data-sb-fold-frame="2"] #chagent-root,
html[data-sb-fold-frame="2"] #sc-banner,
html[data-sb-fold-frame="2"] .sc-reopen,
html[data-sb-fold-frame="2"] .sp-overlay,
html[data-sb-fold-frame="2"] .se-hint {
    display: none !important;
}

/* One header per screen. Tabletop: the second half has none (its bar would sit on the hinge). Book: the
   header's own setting (sb-header--fold-*) says what the second page's bar shows: the cart, so the two bars
   read as one header with the cart at its far end; an empty bar in the header's colours; or no bar.
   Where there is no bar, what sticks below a header starts at the top. */
html[data-sb-fold-frame="2"][data-sb-fold-posture="tabletop"] .sb-header,
html[data-sb-fold-frame="2"] .sb-header--fold-none,
html[data-sb-fold-frame="2"] body > .site-header {
    display: none !important;
}

html[data-sb-fold-frame="2"][data-sb-fold-posture="tabletop"],
html[data-sb-fold-frame="2"]:has(.sb-header--fold-none),
html[data-sb-fold-frame="2"]:has(body > .site-header) {
    --sb-header-h: 0px !important;
}

html[data-sb-fold-frame="2"][data-sb-fold-posture="book"] .sb-header__logo,
html[data-sb-fold-frame="2"][data-sb-fold-posture="book"] .sb-header__nav,
html[data-sb-fold-frame="2"][data-sb-fold-posture="book"] .sb-header__toggle,
html[data-sb-fold-frame="2"][data-sb-fold-posture="book"] .sb-header__cta,
html[data-sb-fold-frame="2"][data-sb-fold-posture="book"] .sb-mobile-menu,
html[data-sb-fold-frame="2"][data-sb-fold-posture="book"] .sb-header--fold-bar .sb-header__actions {
    display: none !important;
}

/* Set by fold.js once the second page's bar is seen to carry the cart. */
html[data-sb-fold-frame="1"][data-sb-fold-cart] .sb-header__cart {
    display: none !important;
}

/* Left / right: both halves are this page, so the footer shows once, at the end of the content half: the left page
   in Book, the bottom half in Tabletop. The half script (Static_Builder_Fold::half_script) names the half on the
   root before the body is parsed. Two pages keeps each page's own footer. */
html[data-sb-fold-half="book 2"] body > .sb-footer,
html[data-sb-fold-half="book 2"] body > .site-footer,
html[data-sb-fold-half="tabletop 1"] body > .sb-footer,
html[data-sb-fold-half="tabletop 1"] body > .site-footer {
    display: none !important;
}

/* A full popup locks the body's scroll as it opens; hidden here, it must not lock this half. */
html[data-sb-fold-frame="2"] body:has(> .sp-overlay) {
    overflow: auto !important;
}
