/* =========================================================
   经典 FC 红白机复古街机风格 - 坦克大战样式表
   完美支持 PC 桌面、手机竖屏与横屏全端自适应
   ========================================================= */

:root {
  --bg-color: #0b0c10;
  --panel-bg: #1f2833;
  --accent-gold: #ffb703;
  --accent-red: #e63946;
  --accent-cyan: #00f5d4;
  --text-main: #ffffff;
  --text-muted: #c5c6c7;
  --border-arcade: #45a29e;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  overflow: hidden;
  touch-action: manipulation;
}

/* 游戏整体自适应容器 */
.game-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 580px;
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  position: relative;
  background-color: #121417;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
}

/* 顶部状态面板 (HUD) */
.hud-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: linear-gradient(180deg, #252a34 0%, #171a21 100%);
  border-bottom: 2px solid #333d4b;
  font-size: 13px;
  font-weight: bold;
  z-index: 10;
  flex-shrink: 0;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.hud-label {
  color: #8d99ae;
  font-size: 11px;
}

.hud-value {
  color: var(--accent-gold);
  font-family: "Courier New", monospace;
  font-size: 14px;
}

.hud-lives {
  color: var(--accent-red);
}

.hud-btn {
  background: #2b303c;
  color: #edf2f4;
  border: 1px solid #485460;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.hud-btn:active {
  background: #3d4655;
  transform: scale(0.95);
}

/* 游戏视口区域 (Canvas) */
.viewport-wrapper {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #000000;
  position: relative;
  overflow: hidden;
  min-height: 0; /* 允许在flex布局中收缩 */
}

#gameCanvas {
  width: min(94vw, 416px, 50vh);
  height: min(94vw, 416px, 50vh);
  background-color: #000000;
  border: 3px solid #2b2d42;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.9);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

/* PC 端控制指南条 (在触屏设备上可自动收缩) */
.desktop-controls-tip {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 4px 10px;
  font-size: 11px;
  color: #8d99ae;
  background: #14171d;
  border-top: 1px solid #222731;
  flex-shrink: 0;
}

.desktop-controls-tip kbd {
  background: #2b303c;
  color: #fff;
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid #576574;
}

/* 手机虚拟控制器面板 */
.touch-controller {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: linear-gradient(180deg, #181b22 0%, #0d0f14 100%);
  border-top: 2px solid #2a2e39;
  flex-shrink: 0;
  user-select: none;
}

/* 虚拟轮盘摇杆 (Virtual Joystick) */
.virtual-joystick {
  position: relative;
  width: 144px;
  height: 144px;
  display: flex;
  justify-content: center;
  align-items: center;
  touch-action: none;
}

.joystick-base {
  position: relative;
  width: 136px;
  height: 136px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #1e2430 0%, #131720 70%, #0d1017 100%);
  border: 3px solid #2e384d;
  box-shadow: inset 0 3px 12px rgba(0, 0, 0, 0.9), 0 4px 15px rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: visible;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.joystick-base.active {
  border-color: var(--accent-gold);
  box-shadow: inset 0 3px 12px rgba(0, 0, 0, 0.9), 0 0 15px rgba(255, 183, 3, 0.4);
}

/* 十字刻度线与方向标识 */
.joystick-crosshair {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  pointer-events: none;
}

.joystick-crosshair::before, .joystick-crosshair::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, 0.08);
}

.joystick-crosshair::before {
  top: 15%;
  bottom: 15%;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
}

.joystick-crosshair::after {
  left: 15%;
  right: 15%;
  top: 50%;
  height: 2px;
  transform: translateY(-50%);
}

.joystick-ring-ticks {
  position: absolute;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.joy-tick {
  position: absolute;
  font-size: 13px;
  color: #55627a;
  font-weight: bold;
  transition: color 0.1s, transform 0.1s, text-shadow 0.1s;
}

.joy-tick.tick-u {
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
}

.joy-tick.tick-d {
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
}

.joy-tick.tick-l {
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
}

.joy-tick.tick-r {
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
}

.joy-tick.tick-u.active {
  color: var(--accent-gold);
  text-shadow: 0 0 8px var(--accent-gold);
  transform: translateX(-50%) scale(1.35);
}

.joy-tick.tick-d.active {
  color: var(--accent-gold);
  text-shadow: 0 0 8px var(--accent-gold);
  transform: translateX(-50%) scale(1.35);
}

.joy-tick.tick-l.active {
  color: var(--accent-gold);
  text-shadow: 0 0 8px var(--accent-gold);
  transform: translateY(-50%) scale(1.35);
}

.joy-tick.tick-r.active {
  color: var(--accent-gold);
  text-shadow: 0 0 8px var(--accent-gold);
  transform: translateY(-50%) scale(1.35);
}

/* 轮盘可拖拽摇杆手柄 (Knob) */
.joystick-knob {
  position: absolute;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #4a5568 0%, #283142 60%, #1a202c 100%);
  border: 2px solid #5d6d88;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.7), inset 0 2px 4px rgba(255, 255, 255, 0.3);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: grab;
  will-change: transform;
  pointer-events: auto;
  transition: transform 0.12s ease-out; /* 释放时平滑弹回原点 */
}

.joystick-knob.dragging {
  cursor: grabbing;
  border-color: var(--accent-gold);
  background: radial-gradient(circle at 35% 35%, #606f88 0%, #354257 60%, #1e2634 100%);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.8), 0 0 10px rgba(255, 183, 3, 0.4);
  transition: none; /* 拖拽时即时响应跟随 */
}

.knob-ring {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.2);
  pointer-events: none;
}

.knob-center {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #ffb703, #d48b00);
  box-shadow: 0 0 6px rgba(255, 183, 3, 0.6);
  pointer-events: none;
}

/* 开火与功能按钮区 */
.action-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.fire-btn {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #ff4d6d, #b5179e);
  border: 3px solid #ff758f;
  box-shadow: 0 6px 15px rgba(239, 71, 111, 0.4), inset 0 2px 5px rgba(255,255,255,0.4);
  color: #ffffff;
  font-weight: bold;
  font-size: 17px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.1s;
}

.fire-btn:active {
  transform: scale(0.92);
  box-shadow: 0 2px 6px rgba(239, 71, 111, 0.6);
  background: radial-gradient(circle at 30% 30%, #e63946, #7209b7);
}

.fire-btn span {
  font-size: 10px;
  opacity: 0.8;
}

/* 地图编辑器工具栏 (浮层) */
.editor-toolbar {
  display: none;
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: rgba(20, 24, 33, 0.96);
  backdrop-filter: blur(8px);
  padding: 10px;
  border-top: 2px solid var(--accent-cyan);
  z-index: 20;
}

.editor-toolbar.active {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.brush-list {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.brush-btn {
  background: #2c3240;
  color: #fff;
  border: 1px solid #4a5568;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.brush-btn.active {
  background: var(--accent-cyan);
  color: #0b0c10;
  font-weight: bold;
  border-color: #fff;
}

.editor-actions {
  display: flex;
  justify-content: space-around;
  gap: 6px;
}

.editor-action-btn {
  flex: 1;
  background: #3a4454;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 8px 4px;
  font-size: 12px;
  cursor: pointer;
  font-weight: bold;
}

.editor-action-btn.primary {
  background: #38b000;
}

.editor-action-btn.danger {
  background: #d90429;
}

/* 统一复古弹窗 (开始界面、GameOver、通关胜利、帮助说明) */
.modal-overlay {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  justify-content: center;
  align-items: center;
  z-index: 50;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: #1a1e26;
  border: 3px solid var(--accent-gold);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.9);
  padding: 24px 20px;
  text-align: center;
  animation: popIn 0.25s ease-out;
}

@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-title {
  font-size: 24px;
  color: var(--accent-gold);
  margin-bottom: 8px;
  font-weight: bold;
  letter-spacing: 1px;
}

.modal-subtitle {
  font-size: 14px;
  color: #c5c6c7;
  margin-bottom: 20px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.menu-btn {
  background: #2b303c;
  color: #ffffff;
  border: 2px solid #485460;
  border-radius: 6px;
  padding: 12px;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.menu-btn:hover, .menu-btn:active {
  background: var(--accent-gold);
  color: #0b0c10;
  border-color: #ffffff;
  transform: translateY(-2px);
}

.menu-btn.primary {
  background: linear-gradient(135deg, #e63946, #b5179e);
  border-color: #ff758f;
}

.menu-btn.primary:hover, .menu-btn.primary:active {
  background: linear-gradient(135deg, #ff4d6d, #7209b7);
  color: #ffffff;
}

/* 说明卡片内的图文列表 */
.help-content {
  text-align: left;
  max-height: 55vh;
  overflow-y: auto;
  padding-right: 6px;
  font-size: 13px;
  line-height: 1.6;
  color: #d8e2dc;
}

.help-content h4 {
  color: var(--accent-gold);
  margin: 12px 0 6px 0;
  border-bottom: 1px solid #333d4b;
  padding-bottom: 2px;
}

.help-content ul {
  padding-left: 18px;
}

/* 针对大屏/横屏模式自适应微调 */
@media (min-height: 800px) {
  #gameCanvas {
    width: min(92vw, 416px, 55vh);
    height: min(92vw, 416px, 55vh);
  }
}
