:root {
  --bm-mobile-top-inset: env(safe-area-inset-top, 0px);
}

/* iOS 主屏幕 Web App 的系统模糊可能越过 safe-area-inset-top。 */
@supports (-webkit-touch-callout: none) {
  @media (display-mode: standalone) and (orientation: portrait) and (max-width: 767px) {
    :root {
      --bm-mobile-top-inset: calc(env(safe-area-inset-top, 0px) + 24px);
    }
  }
}

@media (max-width: 767px), (max-width: 1000px) and (max-height: 500px) and (pointer: coarse) {
  :is(header, nav)[data-mobile-topbar] {
    position: sticky;
    top: 0;
    padding-top: calc(var(--bm-topbar-base-padding, 0px) + var(--bm-mobile-top-inset));
    /* 主题用 !important 管理外壳底色，顶栏也需要覆盖其半透明背景。 */
    background: var(--bm-topbar-background, #f8f7ff) !important;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    z-index: var(--bm-topbar-z-index, 20);
  }

  .home-site-header,
  .home-boot-shell__header {
    --bm-topbar-background: var(--bm-page-bg, #f9fafb);
  }

  .home-boot-shell__header {
    box-sizing: border-box;
    height: calc(64px + var(--bm-mobile-top-inset));
  }

  [data-profile-site-header] { --bm-topbar-z-index: 40; }
  .library-header { --bm-topbar-z-index: 30; }
  .designer-publish-page { --bm-publish-topbar-inset: var(--bm-mobile-top-inset); }
  .designer-publish-page > .topbar { --bm-topbar-z-index: 1001; }

  body[data-page='guide'] {
    --guide-menu-top: calc(72px + var(--bm-mobile-top-inset));
  }

  .orders-page {
    --pb-sticky-header-inset: var(--bm-mobile-top-inset);
  }

  #order-site-header {
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }
}
