/* Opt-in: the other users of HeaderBarComponent retain their existing layout. */
body.mobile-viewport-page {
    --treesy-viewport-height: 100vh;
    --treesy-header-height: calc(55px + env(safe-area-inset-top, 0px));
}
@supports (height: 100dvh) {
    body.mobile-viewport-page { --treesy-viewport-height: 100dvh; }
}
/* viewport-fit=cover also exposes safe areas on wide iPads/standalone windows. */
body.mobile-viewport-page header-bar-component .header {
    box-sizing: border-box;
    height: var(--treesy-header-height);
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: max(10px, env(safe-area-inset-left, 0px));
    padding-right: max(10px, env(safe-area-inset-right, 0px));
    transition: height .18s ease;
}
/* Complete landscape frames and colored headers share the safe content bounds.
   The side strips retain the page background, including during area transitions. */
body.mobile-viewport-page.forest-new-page #area-viewport {
    top: var(--treesy-header-height);
    height: calc(var(--treesy-viewport-height) - var(--treesy-header-height) - env(safe-area-inset-bottom, 0px));
    bottom: auto;
    left: env(safe-area-inset-left, 0px);
    right: env(safe-area-inset-right, 0px);
}
/* Fixed-position landscape pickers use display-relative safe boundaries. */
body.mobile-viewport-page forest-columns-component .fn-board {
    --fn-safe-area-left: env(safe-area-inset-left, 0px);
    --fn-safe-area-right: env(safe-area-inset-right, 0px);
}
body.mobile-viewport-page #area-feedback { top: calc(var(--treesy-header-height) + 9px); }
body.mobile-viewport-page .containerTrees { padding-top: calc(var(--treesy-header-height) + 5px); }
body.mobile-viewport-page #treeHalfLeft,
body.mobile-viewport-page #treeHalfRight { height: calc(var(--treesy-viewport-height) - var(--treesy-header-height)); }
@media (max-width: 900px), (max-height: 600px) and (pointer: coarse) {
    body.mobile-viewport-page {
        --treesy-card-top: calc(var(--treesy-viewport-height) * .39 - 47px);
        /* Reserve the next button (54px), lower controls (32px) and safe area. */
        --treesy-drop-max-height: max(64px, calc(var(--treesy-viewport-height) - var(--treesy-card-top) - 86px - env(safe-area-inset-bottom, 0px)));
    }
    body.mobile-viewport-page header-bar-component .header {
        padding-left: max(5px, env(safe-area-inset-left, 0px));
        padding-right: max(5px, env(safe-area-inset-right, 0px));
    }
    html[data-header-compact] body.mobile-viewport-page {
        --treesy-header-height: calc(44px + env(safe-area-inset-top, 0px));
    }
    body.mobile-viewport-page header-bar-component[data-scroll-compact] .logo { height: 22px; }
    body.mobile-viewport-page header-bar-component[compact-mobile] inbox-component {
        left: max(8px, env(safe-area-inset-left, 0px));
        top: calc(env(safe-area-inset-top, 0px) + (var(--treesy-header-height) - env(safe-area-inset-top, 0px) - 32px) / 2);
    }
}
/* A low viewport needs the flatter header even before the first gesture. */
@media (max-height: 600px) and (orientation: landscape) and (pointer: coarse) {
    body.mobile-viewport-page {
        --treesy-header-height: calc(44px + env(safe-area-inset-top, 0px));
        --treesy-card-top: calc(var(--treesy-header-height) + 8px);
    }
    html[data-header-compact] body.mobile-viewport-page { --treesy-header-height: calc(40px + env(safe-area-inset-top, 0px)); }
    body.mobile-viewport-page header-bar-component[compact-mobile] .logo { height: 22px; }
    body.mobile-viewport-page header-bar-component[data-scroll-compact] .logo { height: 20px; }
    body.mobile-viewport-page .fn-landscape-header { padding-block: 4px; }
    body.mobile-viewport-page .fn-landscape-content { padding-block: 4px; }
}
@media (prefers-reduced-motion: reduce) {
    body.mobile-viewport-page header-bar-component .header { transition: none; }
}

/* Safari's browser chrome follows native document scrolling. An application
   locked to the viewport, with nested vertical scrollers, cannot request it. */
@media (pointer: coarse) and (max-width: 900px), (pointer: coarse) and (max-height: 600px) {
    body.native-scroll-page:not(.forest-new-page),
    body.native-scroll-page.forest-new-page[data-native-area="published"] {
        --treesy-page-scroll: 1;
        height: auto;
        min-height: 100dvh;
        overflow: visible;
        overscroll-behavior: auto;
        overflow-anchor: none;
    }
    html:has(> body.native-scroll-page:not(.forest-new-page)),
    html:has(> body.native-scroll-page.forest-new-page[data-native-area="published"]) {
        height: auto;
        overflow-x: clip;
        overflow-y: auto;
        overscroll-behavior: auto;
    }
    body.native-scroll-page:not(.forest-new-page) .containerTrees { padding-top: 0; }
    body.native-scroll-page.forest-new-page[data-native-area="published"] #area-viewport {
        position: relative;
        inset: auto;
        height: auto;
        min-height: calc(100dvh - var(--treesy-header-height));
        box-sizing: border-box;
        margin-top: var(--treesy-header-height);
        margin-left: env(safe-area-inset-left, 0px);
        margin-right: env(safe-area-inset-right, 0px);
        overflow: clip;
        padding-bottom: 0;
    }
    body.native-scroll-page[data-native-area="published"] .area-pane[data-view="published"] {
        position: relative;
        inset: auto;
    }
    body.native-scroll-page[data-native-area="published"] forest-columns-component { height: auto; padding-bottom: calc(var(--fn-dock-height) + env(safe-area-inset-bottom, 0px)); }
    body.native-scroll-page[data-native-area="published"] .fn-board {
        flex: none;
        align-items: flex-start;
    }
    body.native-scroll-page[data-native-area="published"] .fn-column {
        overflow: visible;
        height: auto;
    }
    /* A horizontal board establishes its own scrollport. Its section headers
       travel with the document; the shared application header stays fixed. */
    body.native-scroll-page[data-native-area="published"] .fn-landscape-header { position: relative; }
}

/* Forest's centered logo and header keep their size while scrolling in every area.
   Climber retains the opt-in scroll-compact behavior above. */
@media (max-width: 900px), (max-height: 600px) and (pointer: coarse) {
    html body.mobile-viewport-page.forest-new-page { --treesy-header-height: calc(55px + env(safe-area-inset-top, 0px)); }
    body.mobile-viewport-page.forest-new-page header-bar-component[compact-mobile] .logo,
    body.mobile-viewport-page.forest-new-page header-bar-component[data-scroll-compact] .logo { height: 30px; }
}
@media (max-height: 600px) and (orientation: landscape) and (pointer: coarse) {
    html body.mobile-viewport-page.forest-new-page { --treesy-header-height: calc(44px + env(safe-area-inset-top, 0px)); }
}
