html, body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 100%;
  min-height: -webkit-fill-available;
  padding: 0;
  margin: 0;
  border: 0;
  overflow: hidden;
  /* 清屏纯黑：横屏多出来的边不再露蓝或白 */
  background-color: #000;
  cursor: default;
  text-align: left;
  font-family: Helvetica, Verdana, Arial, sans-serif;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
}

body, canvas, div {
  outline: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -khtml-user-select: none;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  -webkit-touch-callout: none;
}

/* user-select 会继承到 input；none 时小米/华为等自带浏览器点输入框不弹输入法 */
input, textarea {
  -moz-user-select: text;
  -webkit-user-select: text;
  -ms-user-select: text;
  user-select: text;
  touch-action: manipulation;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

canvas {
  background-color: #000;
  display: block;
}

#GameDiv,
#Cocos3dGameContainer,
#GameCanvas {
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100% !important;
  height: 100% !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  transform: none !important;
  -webkit-transform: none !important;
  background: #000 !important;
  background-color: #000 !important;
}

#GameDiv {
  overflow: hidden;
  inset: 0 !important;
}

/* 手机竖握强制横屏（Adapt.ts LANDSCAPE_LOCK 下竖握时挂 sg-rotated）：GameDiv 宽=屏高、高=屏宽，顺时针转 90° 后盖满屏幕 */
/* translateZ(0)：华为/小米/UC 等自带浏览器在父级 CSS rotate 下 WebGL 易整屏黑，须独立合成层 */
html.sg-rotated #GameDiv {
  left: 100vw !important;
  top: 0 !important;
  right: auto !important;
  bottom: auto !important;
  width: 100vh !important;
  width: 100dvh !important;
  height: 100vw !important;
  max-width: none !important;
  max-height: none !important;
  transform-origin: 0 0 !important;
  -webkit-transform-origin: 0 0 !important;
  transform: rotate(90deg) translateZ(0) !important;
  -webkit-transform: rotate(90deg) translateZ(0) !important;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

html.sg-rotated #Cocos3dGameContainer,
html.sg-rotated #GameCanvas {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  /* 覆盖上方 transform:none：画布必须有自己的合成层，否则部分安卓内核黑屏 */
  transform: translate3d(0, 0, 0) !important;
  -webkit-transform: translate3d(0, 0, 0) !important;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* 软键盘弹出：用开输时冻结的像素尺寸，禁止 100vh/100dvh 被键盘压矮导致画布挤压 */
html.sg-keyboard #GameDiv,
html.sg-keyboard #Cocos3dGameContainer,
html.sg-keyboard #GameCanvas {
  width: var(--sg-frame-w, 100%) !important;
  height: var(--sg-frame-h, 100%) !important;
  max-width: none !important;
  max-height: none !important;
}

html.sg-keyboard.sg-rotated #GameDiv {
  width: var(--sg-frame-w, 100dvh) !important;
  height: var(--sg-frame-h, 100vw) !important;
}

/* 键盘期间底色保持纯黑，避免浏览器把输入区衬成白边 */
html.sg-keyboard,
html.sg-keyboard body {
  background-color: #000 !important;
  overflow: hidden !important;
}

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