/* Keep mobile navigation outside the document scroller.
   This avoids an intermittent WebKit/iOS bug where a fixed element starts
   moving with the page after the visual viewport is resized or restored. */
@media (max-width: 768px) {
  html {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overscroll-behavior: none;
  }

  body.authed {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  /* Use the visible browser height; inherited 100vh includes browser chrome. */
  body.authed #app {
    display: block;
    width: 100%;
    height: 100%;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  body.authed #main {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    scroll-padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 16px);
  }

  body.authed #bottom-nav {
    position: fixed !important;
    inset: auto 0 0 0 !important;
    width: 100%;
    max-width: 100vw;
    margin: 0;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    isolation: isolate;
  }
}

/* Installed iOS apps can report a shorter dynamic viewport with viewport-fit=cover.
   Anchor the navigation to a full-height body instead of that fixed viewport. */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 768px) {
    html.standalone-pwa {
      height: 100vh;
    }

    html.standalone-pwa body.authed {
      position: relative;
      height: 100vh;
      min-height: 0;
    }

    html.standalone-pwa body.authed #app {
      height: 100%;
    }

    html.standalone-pwa body.authed #bottom-nav {
      position: absolute !important;
      inset: auto 0 0 0 !important;
      transform: none;
      -webkit-transform: none;
    }
  }
}
