/* H5 safe layout v1
 * Every rule is gated by body.h5-safe-layout.
 * The gate script never adds that class while a game marker exists.
 */
:root {
  --h5-safe-top: env(safe-area-inset-top, 0px);
  --h5-safe-bottom: env(safe-area-inset-bottom, 0px);
  --h5-tabbar-height: 50px;
  --h5-bottom-clearance: calc(var(--h5-tabbar-height) + var(--h5-safe-bottom) + 16px);
}

body.h5-safe-layout,
body.h5-safe-layout #app {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

html.h5-safe-layout-active,
body.h5-safe-layout {
  min-height: 100%;
}

body.h5-auth-page,
body.h5-auth-page #app,
body.h5-auth-page #app > * {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 100dvh;
  min-height: 100svh;
  box-sizing: border-box;
  overflow-x: hidden;
}

body.h5-auth-page #app > * {
  padding-top: var(--h5-safe-top);
  padding-bottom: var(--h5-safe-bottom);
}

body.h5-auth-page [class*="login"],
body.h5-auth-page [class*="Login"],
body.h5-auth-page [class*="register"],
body.h5-auth-page [class*="Register"] {
  box-sizing: border-box;
  max-width: 100vw;
}

body.h5-auth-page .van-popup,
body.h5-auth-page [role="dialog"] {
  max-width: 100vw;
  box-sizing: border-box;
}

body.h5-safe-layout .h5-safe-page {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
}

body.h5-safe-layout .h5-safe-scroll {
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: none;
  padding-bottom: var(--h5-bottom-clearance);
  scroll-padding-bottom: var(--h5-bottom-clearance);
}

body.h5-safe-layout input,
body.h5-safe-layout textarea,
body.h5-safe-layout select {
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  font-size: max(16px, 1em);
}

body.h5-safe-layout .van-popup {
  max-width: 100vw;
  box-sizing: border-box;
  overscroll-behavior: contain;
}

body.h5-safe-layout .van-popup--bottom {
  max-height: calc(100dvh - var(--h5-safe-top));
  padding-bottom: var(--h5-safe-bottom);
}

body.h5-safe-layout .van-dialog {
  width: min(calc(100vw - 32px), 420px);
  max-width: calc(100vw - 32px);
}

body.h5-safe-layout .h5-safe-tabbar {
  min-height: var(--h5-tabbar-height);
  padding-bottom: var(--h5-safe-bottom);
  box-sizing: content-box;
}

body.h5-safe-layout .h5-safe-action-footer {
  position: sticky;
  bottom: 0;
  z-index: 30;
  width: 100%;
  box-sizing: border-box;
  padding: 12px 16px calc(12px + var(--h5-safe-bottom));
  background: #fff;
}

body.h5-safe-layout .h5-safe-action-row {
  display: flex;
  gap: 12px;
  width: 100%;
}

body.h5-safe-layout .h5-safe-action-row > button,
body.h5-safe-layout .h5-safe-action-row > a {
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  box-sizing: border-box;
  touch-action: manipulation;
}

body.h5-safe-layout button,
body.h5-safe-layout a,
body.h5-safe-layout [role="button"] {
  touch-action: manipulation;
}

@supports (padding-bottom: constant(safe-area-inset-bottom)) {
  body.h5-safe-layout {
    --h5-safe-top: constant(safe-area-inset-top);
    --h5-safe-bottom: constant(safe-area-inset-bottom);
  }
}

@media (max-height: 520px) {
  body.h5-safe-layout {
    --h5-tabbar-height: 46px;
  }
}
