:root {
  color-scheme: dark;
  --bg: #05080d;
  --panel: #0d141d;
  --line: #1d2b3a;
  --text: #e6edf6;
  --muted: #7f93a8;
  --accent: #4cc2ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 14px calc(18px + env(safe-area-inset-bottom));
  background: radial-gradient(circle at 50% 0%, #0d2334 0%, var(--bg) 60%);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "PingFang SC", monospace;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  width: min(94vw, 520px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 横屏时用可用高度反推宽度，保证画布完整可见（画布 224:256 ≈ 1:1.143）；
   非画布部分（hud + bar + 间距 + 安全区）约 150px，桌面仍受 520px 上限约束 */
@media (orientation: landscape) {
  .stage {
    width: min(94vw, 520px, calc((100dvh - 150px) / 1.143));
  }
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  letter-spacing: 1px;
}

.hud-item {
  padding: 6px 8px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.hud-label {
  display: block;
  font-size: 9px;
  color: var(--muted);
}

.hud-item strong {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.screen {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

canvas#game {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* 轻微 CRT 扫描线，只做观感，不吃点击 */
.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.05) 0 1px,
    transparent 1px 3px
  );
  opacity: 0.5;
  mix-blend-mode: overlay;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  text-align: center;
  background: rgba(3, 7, 12, 0.82);
  backdrop-filter: blur(2px);
}

.overlay[hidden] {
  display: none;
}

.overlay-title {
  margin: 0;
  font-size: clamp(18px, 5vw, 26px);
  letter-spacing: 3px;
}

.overlay-text {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
  white-space: pre-line;
}

.btn {
  font: inherit;
  cursor: pointer;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: 9px;
}

.btn.primary {
  background: var(--accent);
  color: #04121c;
  font-weight: 700;
}

.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.btn:active {
  transform: translateY(1px);
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.back {
  color: var(--muted);
  text-decoration: none;
}

.back:hover {
  color: var(--accent);
}

.touch {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 0 max(14px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  pointer-events: none;
}

/* 左手拇指管移动，右手拇指管开火 */
.touch > * {
  pointer-events: auto;
}

.touch-move {
  display: flex;
  gap: 10px;
  padding: 6px;
  border: 1px solid rgba(120, 200, 255, 0.14);
  border-radius: 22px;
  background: rgba(8, 16, 24, 0.35);
  touch-action: none;
}

.touch-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 74px;
  height: 62px;
  padding: 0;
  font: inherit;
  font-size: 20px;
  color: var(--text);
  background: rgba(10, 20, 30, 0.55);
  border: 1px solid rgba(120, 200, 255, 0.28);
  border-radius: 14px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition:
    background 0.08s ease,
    border-color 0.08s ease,
    transform 0.08s ease;
}

.touch-btn.active {
  background: rgba(76, 194, 255, 0.38);
  border-color: #4cc2ff;
  transform: scale(0.97);
}

.touch-btn.fire {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 2px;
  background: #14324a;
  border-color: #2c5d80;
  color: var(--accent);
}

@media (pointer: coarse) {
  .touch {
    display: flex;
  }
}

/* 横屏时控件缩小一点，避开画面 */
@media (orientation: landscape) {
  .touch-btn {
    width: 64px;
    height: 54px;
    font-size: 18px;
  }

  .touch-btn.fire {
    width: 84px;
    height: 84px;
    font-size: 14px;
  }
}
