:root {
  --bg: #0b0c10;
  --panel: #1b1c22;
  --steel: #6b6f76;
  --accent: #d8a200;
  --field: #000000;
  --text: #e8e8e8;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 0%, #20232c 0%, #07080b 70%);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
  /* 禁止移动端双击缩放和长按选中 */
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.machine {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 12px;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
}

.screen {
  display: flex;
  gap: 2px;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 0;
  background: transparent;
  border-radius: 0;
  border: none;
}

.game-area {
  position: relative;
  background: #000;
  border-radius: 4px;
  line-height: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas#game {
  /* 等比缩放：以视口高度为基准，减去少量边距 */
  height: min(calc(100vh - 24px), calc(100vw - 220px));
  width: min(calc(100vh - 24px), calc(100vw - 220px));
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  background: #000;
  border: 3px solid #34363f;
  border-radius: 6px;
}

/* 画面串流模式：远端视频覆盖 canvas */
.stream-video {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: min(calc(100vh - 24px), calc(100vw - 220px));
  width: min(calc(100vh - 24px), calc(100vw - 220px));
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  border: 3px solid #34363f;
  border-radius: 6px;
  z-index: 5;
  pointer-events: none;
}

body.mobile .stream-video {
  height: min(calc(100vw - 8px), calc(100vh - 180px));
  width: min(calc(100vw - 8px), calc(100vh - 180px));
  border-width: 2px;
}

body.mobile.landscape .stream-video,
body.mobile.sys-landscape .stream-video {
  height: min(calc(100vh - 8px), calc(100vw - 280px));
  width: min(calc(100vh - 8px), calc(100vw - 280px));
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 176px;
  min-width: 160px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: min(calc(100vh - 24px), calc(100vw - 220px));
  overflow-y: auto;
}

.logo {
  font-weight: 900;
  font-size: 30px;
  line-height: 1.05;
  letter-spacing: 2px;
  text-align: center;
  padding: 10px 0;
  color: #ffd34d;
  text-shadow: 0 0 8px rgba(255, 180, 0, 0.5), 2px 2px 0 #7a3b00;
  background: repeating-linear-gradient(
    45deg,
    #1d1f27,
    #1d1f27 8px,
    #20222b 8px,
    #20222b 16px
  );
  border-radius: 8px;
  border: 2px solid #3a3d48;
}

.panel {
  background: var(--panel);
  border: 1px solid #2e3038;
  border-radius: 8px;
  padding: 10px;
}

.panel-title {
  font-size: 12px;
  letter-spacing: 3px;
  color: #8b8f99;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.enemy-icons {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.enemy-icons .e {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #3a3d48;
  border-radius: 2px;
}

.enemy-icons .e.alive {
  background: url("../img/ui/eIcon.png") center / contain no-repeat;
  image-rendering: pixelated;
}

.stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.stat .label {
  font-size: 12px;
  letter-spacing: 2px;
  color: #8b8f99;
}

.stat .value {
  font-size: 22px;
  font-weight: 800;
  color: #ffd34d;
  font-variant-numeric: tabular-nums;
}

.stat .value.flag {
  background: #d8a200;
  color: #1b1c22;
  border-radius: 4px;
  padding: 0 8px;
}

.lives .value {
  color: #ff6b5b;
}

.lives-p2 .label {
  color: #5fd96a;
}

.life-icons {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  justify-content: flex-end;
}

.life-icons .p {
  width: 16px;
  height: 16px;
  background: url("../img/ui/pIcon.png") center / contain no-repeat;
  image-rendering: pixelated;
}

.life-icons .p.p2 {
  filter: hue-rotate(90deg) saturate(1.2);
}

.help ul {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 12px;
  line-height: 1.9;
  color: #aab0bb;
}

.help b {
  color: #e8e8e8;
}

/* =========================================================
 * 竖屏旋转提示（已移除，不再使用）
 * =======================================================*/

.rotate-hint {
  display: none;
}

/* =========================================================
 * 虚拟手柄（默认隐藏，移动端显示）
 * =======================================================*/

.virtual-pad {
  display: none;
}

/* D-Pad */
.vpad-dpad {
  position: relative;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(255, 211, 77, 0.3);
}

.dpad-arrow {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: rgba(255, 211, 77, 0.7);
  width: 40px;
  height: 40px;
}

.dpad-up    { top: 6px;    left: 50%; transform: translateX(-50%); }
.dpad-down  { bottom: 6px; left: 50%; transform: translateX(-50%); }
.dpad-left  { left: 6px;   top: 50%;  transform: translateY(-50%); }
.dpad-right { right: 6px;  top: 50%;  transform: translateY(-50%); }

.dpad-center {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255, 211, 77, 0.15);
  border: 1px solid rgba(255, 211, 77, 0.3);
}

/* 按钮通用 */
.vpad-btn {
  border: none;
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.vpad-fire {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: rgba(255, 80, 60, 0.75);
  color: #fff;
  font-size: 14px;
  letter-spacing: 1px;
  box-shadow: 0 0 16px rgba(255, 80, 60, 0.4);
}

.vpad-fire:active {
  background: rgba(255, 80, 60, 1);
  transform: scale(0.92);
}

.vpad-start,
.vpad-pause,
.vpad-landscape {
  padding: 8px 14px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: #ccc;
  font-size: 11px;
  letter-spacing: 1px;
}

.vpad-landscape {
  font-size: 18px;
  padding: 6px 14px;
}

.vpad-start:active,
.vpad-pause:active,
.vpad-landscape:active {
  background: rgba(255, 211, 77, 0.4);
  color: #fff;
}

/* =========================================================
 * 移动端样式（.mobile 类由 JS 添加到 body）
 * 默认竖屏：游戏上方，虚拟手柄下方
 * =======================================================*/

body.mobile {
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow: hidden;
}

body.mobile .sidebar {
  display: none;
}

body.mobile .machine {
  padding: 4px;
  flex: 0 0 auto;
  width: 100%;
  height: auto;
}

body.mobile .screen {
  height: auto;
  flex-direction: column;
  align-items: center;
}

body.mobile .game-area {
  height: auto;
}

/* 移动端紧凑 HUD */
.mobile-hud {
  display: none;
}

body.mobile .mobile-hud {
  display: flex;
  gap: 12px;
  padding: 4px 8px;
  font-size: 12px;
  color: #aab0bb;
  white-space: nowrap;
}

.mhud-item b {
  color: #ffd34d;
  font-weight: 800;
  margin-left: 2px;
}

.mhud-p2 {
  display: none;
}

.mhud-p2.active {
  display: inline;
}

/* 竖屏时 canvas 按宽度铺满，留出手柄空间 */
body.mobile canvas#game {
  height: min(calc(100vw - 8px), calc(100vh - 180px));
  width: min(calc(100vw - 8px), calc(100vh - 180px));
  border-width: 2px;
}

/* 竖屏时虚拟手柄：左 D-Pad、中 功能键、右 FIRE，横排 */
body.mobile .virtual-pad {
  display: flex;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  pointer-events: none;
}

body.mobile .vpad-left,
body.mobile .vpad-right,
body.mobile .vpad-mid {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

body.mobile .vpad-mid {
  gap: 8px;
}

/* =========================================================
 * 移动端横屏布局（系统横屏 或 手动切换 .landscape）
 * 虚拟手柄覆盖在画面两侧，canvas 居中
 * =======================================================*/

body.mobile.landscape,
body.mobile.sys-landscape {
  flex-direction: row;
  justify-content: center;
  align-items: center;
}

body.mobile.landscape .machine,
body.mobile.sys-landscape .machine {
  flex: 0 0 auto;
  width: auto;
}

body.mobile.landscape canvas#game,
body.mobile.sys-landscape canvas#game {
  height: min(calc(100vh - 8px), calc(100vw - 280px));
  width: min(calc(100vh - 8px), calc(100vw - 280px));
}

body.mobile.landscape .virtual-pad,
body.mobile.sys-landscape .virtual-pad {
  position: fixed;
  inset: 0;
  flex: none;
  width: 100%;
  height: 100%;
  padding: 0 16px;
  padding-bottom: 30px;
  z-index: 100;
  pointer-events: none;
  align-items: flex-end;
}

body.mobile.landscape .vpad-mid,
body.mobile.sys-landscape .vpad-mid {
  gap: 10px;
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  flex-direction: row;
}

/* 横屏时 mobile-hud 固定在屏幕右上角，不影响游戏区域布局 */
body.mobile.landscape .screen,
body.mobile.sys-landscape .screen {
  flex-direction: column;
  align-items: center;
}

body.mobile.landscape .mobile-hud,
body.mobile.sys-landscape .mobile-hud {
  position: fixed;
  right: 8px;
  top: 8px;
  flex-direction: column;
  gap: 6px;
  padding: 6px 10px;
  font-size: 11px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 6px;
  z-index: 200;
  pointer-events: none;
}

/* ---------- 小屏幕 PC（非移动端）：sidebar 移到底部 ---------- */
@media (max-width: 660px) {
  body:not(.mobile) .screen {
    flex-direction: column;
    align-items: center;
  }
  body:not(.mobile) canvas#game {
    height: min(calc(100vw - 24px), calc(100vh - 200px));
    width: min(calc(100vw - 24px), calc(100vh - 200px));
  }
  body:not(.mobile) .stream-video {
    height: min(calc(100vw - 24px), calc(100vh - 200px));
    width: min(calc(100vw - 24px), calc(100vh - 200px));
  }
  body:not(.mobile) .sidebar {
    width: 100%;
    max-width: min(calc(100vw - 24px), calc(100vh - 200px));
    max-height: none;
    flex-direction: row;
    flex-wrap: wrap;
  }
  body:not(.mobile) .logo,
  body:not(.mobile) .panel {
    flex: 1 1 120px;
  }
}
