:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --fg: #10131a;
  --muted: #6b7280;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10131a;
    --fg: #f4f5f7;
    --muted: #9aa3b2;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 -apple-system, system-ui, sans-serif;
  /* The canvas handles its own gestures; the page must not pan or bounce. */
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* The 3D canvas fills the panel and bleeds under the device's own chrome. */
#stage {
  position: fixed;
  inset: 0;
}

#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* Three has no text and no hit-testing, so every control and readout is a DOM
   element sitting over the canvas. The layer itself is transparent to touch —
   only its children take input — otherwise it would swallow every tap meant
   for the world behind it. */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  /* Keeps controls clear of the notch and the home indicator. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#hud > * { pointer-events: auto; }

.hud-button {
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 50%;
  background-color: color-mix(in srgb, var(--fg) 12%, transparent);
  background-position: center;
  background-repeat: no-repeat;
  background-size: 55%;
  /* Icons are published as CSS variables by registerIcons(): a button asks for
     one with `style="background-image: var(--icon-play)"`. */
}

.hud-button:active { transform: scale(0.94); }

.hud-text {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--fg);
}


/* 触屏控制：左侧摇杆 + 右下角开火按钮。
   绝对定位的子元素以 #hud 的内边距边缘为准，不会被内边距推出去，
   所以安全区要在这里自己加回来。 */
.joystick {
  position: absolute;
  left: calc(env(safe-area-inset-left) + 22px);
  bottom: calc(env(safe-area-inset-bottom) + 38px);
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: rgba(10, 16, 22, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(6px);
  touch-action: none;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.33);
  border: 1px solid rgba(255, 255, 255, 0.5);
  transform: translate(-50%, -50%);
}

.hud-button {
  background-color: rgba(10, 16, 22, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(6px);
}

.hud-fire {
  background-color: rgba(216, 63, 46, 0.55);
  border-color: rgba(255, 200, 190, 0.45);
}

/* ---- 横屏 ---- */

/* 触屏设备竖屏时提示转横屏。做成屏幕顶部的一条小药丸：预览窗口竖着
   打不开横屏时也不挡玩——纯提示，几秒后自己淡出，转过屏就消失。 */
#rotate-overlay {
  display: none;
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(10, 16, 22, 0.55);
  color: #f4f5f7;
  font-size: 14px;
  letter-spacing: 2px;
  pointer-events: none;
  backdrop-filter: blur(6px);
  animation: rotate-hint-fade 5s ease forwards;
}

#rotate-overlay .rotate-icon {
  width: 22px;
  height: 22px;
  background: var(--icon-rotate-ccw) center / contain no-repeat;
  animation: rotate-hint 2.4s ease-in-out infinite;
}

@keyframes rotate-hint-fade {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes rotate-hint {
  0%, 55% { transform: rotate(0deg); }
  80%, 100% { transform: rotate(90deg); }
}

@media (orientation: portrait) and (any-pointer: coarse) {
  #rotate-overlay { display: flex; }
}

/* 触屏按钮：位置和大小全部交给这里，好按横屏高度重新编排。
   布局原则（手机横屏，右手拇指为圆心）：
     内圈 · 开火（最大）、蹲下、跳跃   —— 抬指就到，按住不放最久
     外圈 · 换弹、手雷、开镜           —— 轻点用，不常按
   左手只干两件事：左下摇杆走路；摇杆正上方一排「切枪 / 安放」。
   所有尺寸都乘 --u，矮屏（多数手机横屏只有 360–400px 高）自动收一号，
   免得按钮扎到血量数字和小地图上。#hud 的内边距不含安全区，这里自己加回来。 */
.touch-mode {
  --u: 1;
}

@media (max-height: 420px) { .touch-mode { --u: 0.86; } }
@media (max-height: 370px) { .touch-mode { --u: 0.78; } }

.touch-mode .hud-button {
  position: absolute;
  /* 拇指滑出按钮也不滚动页面 / 不触发缩放 */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-mode .btn-fire {
  right: calc(env(safe-area-inset-right) + 18px * var(--u));
  bottom: calc(env(safe-area-inset-bottom) + 18px * var(--u));
  width: calc(100px * var(--u));
  height: calc(100px * var(--u));
  background-size: 44%;
}

.touch-mode .btn-crouch {
  right: calc(env(safe-area-inset-right) + 126px * var(--u));
  bottom: calc(env(safe-area-inset-bottom) + 24px * var(--u));
  width: calc(64px * var(--u));
  height: calc(64px * var(--u));
  background-size: 46%;
}

.touch-mode .btn-jump {
  right: calc(env(safe-area-inset-right) + 24px * var(--u));
  bottom: calc(env(safe-area-inset-bottom) + 138px * var(--u));
  width: calc(64px * var(--u));
  height: calc(64px * var(--u));
  background-size: 46%;
}

.touch-mode .btn-reload {
  right: calc(env(safe-area-inset-right) + 116px * var(--u));
  bottom: calc(env(safe-area-inset-bottom) + 124px * var(--u));
  width: calc(56px * var(--u));
  height: calc(56px * var(--u));
  background-size: 52%;
}

.touch-mode .btn-grenade {
  right: calc(env(safe-area-inset-right) + 200px * var(--u));
  bottom: calc(env(safe-area-inset-bottom) + 34px * var(--u));
  width: calc(56px * var(--u));
  height: calc(56px * var(--u));
  background-size: 52%;
}

.touch-mode .btn-scope {
  right: calc(env(safe-area-inset-right) + 200px * var(--u));
  bottom: calc(env(safe-area-inset-bottom) + 108px * var(--u));
  width: calc(56px * var(--u));
  height: calc(56px * var(--u));
  background-size: 46%;
}

/* 摇杆：离左下角留一手宽，拇指自然落点就在这里 */
.touch-mode .joystick {
  left: calc(env(safe-area-inset-left) + 16px * var(--u));
  bottom: calc(env(safe-area-inset-bottom) + 16px * var(--u));
  width: calc(132px * var(--u));
  height: calc(132px * var(--u));
}

.touch-mode .joystick-knob {
  width: calc(64px * var(--u));
  height: calc(64px * var(--u));
}

.touch-mode .btn-switch {
  left: calc(env(safe-area-inset-left) + 20px * var(--u));
  bottom: calc(env(safe-area-inset-bottom) + 156px * var(--u));
  width: calc(56px * var(--u));
  height: calc(56px * var(--u));
  background-size: 50%;
}

/* 安放 / 拆除要按住四五秒，给大一号、放在摇杆右上方的舒适区 */
.touch-mode .btn-bomb {
  left: calc(env(safe-area-inset-left) + 88px * var(--u));
  bottom: calc(env(safe-area-inset-bottom) + 152px * var(--u));
  width: calc(64px * var(--u));
  height: calc(64px * var(--u));
  background-size: 46%;
}

/* 设置里的"大"：整体放大一号。锚点跟着各按钮的方向走，放大不挪窝。 */
html.big-ui .touch-mode .hud-button {
  transform-origin: bottom right;
  transform: scale(1.22);
}

html.big-ui .touch-mode .hud-button:active {
  transform: scale(1.1);
}

html.big-ui .touch-mode .btn-switch,
html.big-ui .touch-mode .btn-bomb {
  transform-origin: bottom left;
}

html.big-ui .touch-mode .joystick {
  transform: scale(1.22);
  transform-origin: bottom left;
}


/* 小地图：圆角切出圆形雷达，挂在右上角、消灭数下面 */
.minimap-canvas {
  position: absolute;
  right: calc(env(safe-area-inset-right) + 14px);
  top: calc(env(safe-area-inset-top) + 48px);
  width: 128px;
  height: 128px;
  border-radius: 50%;
  pointer-events: none;
}


/* 全屏沉浸模式：雷达挪到左边。右上角要留给消灭数和退出键，
   左边那列只有生命/护甲/金币三个数字，雷达从它们下面开始挂。 */
html.fs-mode .minimap-canvas {
  right: auto;
  left: calc(env(safe-area-inset-left) + 14px);
  top: calc(env(safe-area-inset-top) + 92px);
}

/* 手机横屏全屏时屏幕矮，雷达缩一号，别压到左下摇杆 */
@media (max-height: 480px) {
  html.fs-mode .minimap-canvas {
    width: 104px;
    height: 104px;
    top: calc(env(safe-area-inset-top) + 88px);
  }
}


/* 对局中的退出按钮：桌面挂在雷达正下方（原来和雷达重叠，被雷达盖住了）。
   手机上躲开小地图，放到消灭数左边的空白带。 */
.btn-quit {
  position: absolute;
  right: calc(env(safe-area-inset-right) + 14px);
  top: calc(env(safe-area-inset-top) + 186px);
  z-index: 9;
}

.btn-quit-hint {
  position: absolute;
  right: calc(env(safe-area-inset-right) + 14px);
  top: calc(env(safe-area-inset-top) + 220px);
  z-index: 9;
}

.touch-mode .btn-quit {
  right: calc(env(safe-area-inset-right) + 150px * var(--u));
  top: calc(env(safe-area-inset-top) + 8px * var(--u));
  z-index: 9;
}

/* 手机横屏全屏时雷达去了左边，退出按钮也不用再躲，回到右上角 */
html.fs-mode .btn-quit {
  top: calc(env(safe-area-inset-top) + 46px);
  right: calc(env(safe-area-inset-right) + 14px);
}

html.fs-mode.touch-mode .btn-quit {
  top: calc(env(safe-area-inset-top) + 8px * var(--u));
  right: calc(env(safe-area-inset-right) + 150px * var(--u));
}

@media (max-height: 420px) {
  /* 手机横屏：提示文字挤，直接藏掉，按钮自己够显眼 */
  .touch-mode .btn-quit-hint { display: none !important; }
}


/* 结算画面淡入 */
@keyframes menu-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
