* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  background: #0c1018;
  color: #e8eef7;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", Segoe UI, sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

#game-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage {
  position: relative;
  aspect-ratio: 3 / 2;
  width: min(100vw, 150vh, 900px);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
  border: 2px solid #2a3346;
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
}

/* 触摸设备（手机/Pad）：画布铺满整个屏幕，格子数按屏幕比例重算 */
body.touch #stage {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  aspect-ratio: auto;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

canvas#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #11161f;
  image-rendering: pixelated;
}

/* HUD */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 8px 12px;
  pointer-events: none;
  font-size: 14px;
  text-shadow: 0 1px 2px #000;
  background: linear-gradient(180deg, rgba(0,0,0,0.55), rgba(0,0,0,0));
}

.hud-row {
  display: flex;
  gap: 18px;
  align-items: center;
  margin: 2px 0;
  flex-wrap: wrap;
}

#hud-hp { color: #6ee787; font-weight: 700; }
#hud-wave { color: #ffd866; font-weight: 700; }
#hud-weapon { color: #79c0ff; font-weight: 700; }
#hud-tip { color: #9aa7bd; font-size: 12px; }

/* 遮罩 */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 9, 16, 0.82);
  backdrop-filter: blur(2px);
  z-index: 10;
}

.overlay.hidden { display: none; }

.panel {
  width: 78%;
  max-width: 560px;
  background: #161d2b;
  border: 1px solid #2a3346;
  border-radius: 14px;
  padding: 26px 30px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.panel h1 {
  font-size: 30px;
  margin-bottom: 12px;
}

.panel p {
  color: #c4cde0;
  line-height: 1.6;
  margin-bottom: 12px;
}

.rules {
  list-style: none;
  text-align: left;
  display: inline-block;
  margin: 6px auto 18px;
  color: #aebbd2;
  line-height: 1.9;
  font-size: 14px;
}

.rules b { color: #ffd866; }

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 12px 28px;
  font-size: 16px;
  font-weight: 700;
  color: #0c1018;
  background: linear-gradient(180deg, #ffd866, #f0b429);
  transition: transform .08s ease, filter .15s ease;
}

button:hover { filter: brightness(1.08); }
button:active { transform: scale(0.96); }

#end-title.win { color: #6ee787; }
#end-title.lose { color: #ff6b6b; }

/* ===== 触屏虚拟按钮 ===== */
.touch-controls {
  display: none; /* 默认隐藏，触摸设备才显示 */
  position: absolute;
  inset: 0;
  pointer-events: none; /* 仅按钮可点 */
  z-index: 5;
}
body.touch .touch-controls { display: block; }

.tb {
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(20, 28, 42, 0.55);
  color: #e8eef7;
  border-radius: 14px;
  font-size: clamp(20px, 4.5vw, 30px);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.tb:active { background: rgba(255, 216, 102, 0.35); }

/* 摇杆（左下） */
.joystick {
  position: absolute;
  left: 2.5%;
  bottom: 3%;
  width: clamp(140px, 30vw, 200px);
  height: clamp(140px, 30vw, 200px);
  pointer-events: auto;
  touch-action: none;
}

.joy-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.22);
  background: radial-gradient(circle at 50% 50%, rgba(20,28,42,0.35), rgba(20,28,42,0.6));
  backdrop-filter: blur(2px);
  touch-action: none;
}

.joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 38%;
  height: 38%;
  margin: -19% 0 0 -19%;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(255, 216, 102, 0.55);
  box-shadow: 0 2px 10px rgba(0,0,0,0.45);
  pointer-events: none;
  will-change: transform;
}

/* 动作键（右下） */
.actions {
  position: absolute;
  right: 2.5%;
  bottom: 3%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
}
.actions .weapon {
  width: clamp(54px, 12vw, 72px);
  height: clamp(54px, 12vw, 72px);
}
.actions .fire {
  width: clamp(72px, 16vw, 96px);
  height: clamp(72px, 16vw, 96px);
  background: rgba(255, 77, 79, 0.5);
  font-size: clamp(26px, 6vw, 40px);
}
.actions .pause {
  width: clamp(48px, 10vw, 60px);
  height: clamp(48px, 10vw, 60px);
}
