/* GRANDE LOWLANDS – safe areas for the installed app (edge to edge).
 *
 * Same rules that were tested on journal.html, now shared by every page.
 * The sticky header reserves the space for the status bar / camera cutout
 * itself, and its sticky offset matches the space reserved on the page, so
 * the header stands still instead of sliding up on the first scroll.
 *
 * The 1100px breakpoint matches site-header.css, where the header switches
 * to its compact menu layout.
 *
 * Requires viewport-fit=cover in each page's viewport meta. On a device with
 * no cutout every inset is 0px and nothing changes. */

:root {
  --gl-safe-top: env(safe-area-inset-top, 0px);
  --gl-safe-right: env(safe-area-inset-right, 0px);
  --gl-safe-bottom: env(safe-area-inset-bottom, 0px);
  --gl-safe-left: env(safe-area-inset-left, 0px);
}

/* Insets are physical sides; this site uses left-to-right layout. */
body {
  padding-inline: var(--gl-safe-left) var(--gl-safe-right);
  padding-bottom: var(--gl-safe-bottom);
}

/* Pages without the shared sticky header (the start page) reserve the space
   on the page itself, so nothing ends up under the camera cutout there. */
body:not(:has(> .gl-header.gl-sticky)) { padding-top: var(--gl-safe-top); }

@media (max-width: 1100px) {
  .gl-header.gl-sticky.menu-ready {
    padding-top: calc(5px + var(--gl-safe-top));
    min-height: calc(54px + var(--gl-safe-top));
  }
  html:has(.gl-sticky.menu-ready) {
    scroll-padding-top: calc(65px + var(--gl-safe-top));
  }
  .gl-header.gl-sticky.menu-ready .gl-nav {
    max-height: calc(100dvh - 60px - var(--gl-safe-top) - var(--gl-safe-bottom));
  }
  /* Before the menu script has run: reserve the space on the page instead,
     and move the sticky offset down by exactly the same amount. */
  body:has(> .gl-header.gl-sticky:not(.menu-ready)) { padding-top: var(--gl-safe-top); }
  .gl-header.gl-sticky:not(.menu-ready) { top: var(--gl-safe-top); }
}

@media (min-width: 1101px) {
  body { padding-top: var(--gl-safe-top); }
  .gl-header.gl-sticky { top: var(--gl-safe-top); }
  html:has(.gl-sticky) { scroll-padding-top: calc(130px + var(--gl-safe-top)); }
}

/* Installed with the system status bar still drawn (standalone) part of the
   inset is already taken by that bar, so a little less has to be reserved.
   In full screen there is no status bar at all, so the whole inset is needed
   to keep the header clear of the camera cutout — hence standalone only. */
@media (max-width: 1100px) and (orientation: portrait) and (display-mode: standalone) {
  :root { --gl-safe-top: max(0px, calc(env(safe-area-inset-top, 0px) - 12px)); }
}

/* Phones in the installed app, portrait: the camera cutout sits in the status
   bar strip that the app already draws over, and reserving it again leaves a
   tall empty band above the header. Tested on the journal page, now shared:
   keep the compact header here. Remove this block to reserve the space. */
@media (max-width: 480px) and (orientation: portrait) and (display-mode: standalone),
       (max-width: 480px) and (orientation: portrait) and (display-mode: fullscreen) {
  .gl-header.gl-sticky.menu-ready {
    padding-top: 5px;
    min-height: 54px;
  }
  body:not(:has(> .gl-header.gl-sticky)) { padding-top: 0; }
  body:has(> .gl-header.gl-sticky:not(.menu-ready)) { padding-top: 0; }
  .gl-header.gl-sticky:not(.menu-ready) { top: 0; }
}
