:root {
  --nes-red: #e52521;
  --nes-gold: #ffd800;
  --nes-blue: #1a53c9;
  --nes-dark: #10131c;
  --cabinet-bg: #181c28;
  --cabinet-border: #2c3347;
  --text-light: #f4f6fb;
  --text-muted: #9aa4bf;
}

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

body {
  min-height: 100vh;
  background: radial-gradient(circle at 50% 15%, #232b45 0%, #0d1018 70%);
  color: var(--text-light);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.arcade-shell {
  width: 100%;
  max-width: 860px;
  background: linear-gradient(180deg, #1e2436 0%, #141824 100%);
  border: 2px solid var(--cabinet-border);
  border-radius: 18px;
  padding: 16px 20px 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* ---- Top HUD Bar ---- */
.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #0c0f18;
  border: 1px solid #262e45;
  border-radius: 10px;
  padding: 10px 16px;
  margin-bottom: 12px;
  font-family: "Courier New", Consolas, monospace;
}

.hud-stats {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
}

.hud-item {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.hud-label {
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 700;
}

.hud-value {
  font-size: 18px;
  font-weight: 800;
  color: #ffffff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
}

.hud-value.gold {
  color: var(--nes-gold);
}

.hud-value.power {
  font-family: "Segoe UI", "PingFang SC", sans-serif;
  font-size: 14px;
  color: #7ee8fa;
}

.hud-actions {
  display: flex;
  gap: 8px;
}

.mini-btn {
  background: #232a3d;
  border: 1px solid #384361;
  color: #e2e8f8;
  padding: 6px 11px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}

.mini-btn:hover {
  background: #303a54;
}

.mini-btn:active {
  transform: scale(0.95);
}

/* ---- Stage Canvas Viewport ---- */
.stage-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 800 / 480;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  border: 3px solid #090b10;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8), 0 8px 24px rgba(0, 0, 0, 0.5);
}

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

/* ---- Overlays ---- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(8, 12, 22, 0.66);
  backdrop-filter: blur(2px);
  padding: 20px;
  text-align: center;
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.title-banner {
  background: linear-gradient(180deg, #e52521 0%, #a81512 100%);
  border: 4px solid #ffd800;
  border-radius: 14px;
  padding: 16px 34px;
  box-shadow: 0 10px 0 #590c0a, 0 18px 34px rgba(0, 0, 0, 0.65);
  margin-bottom: 18px;
}

.title-banner h1 {
  font-family: "Courier New", Consolas, monospace;
  font-size: 38px;
  font-weight: 900;
  letter-spacing: 3px;
  color: #fff6d6;
  text-shadow: 3px 3px 0 #5e0c0a, -1px -1px 0 #ffd800;
  line-height: 1.1;
}

.title-banner .subtitle {
  margin-top: 6px;
  font-size: 13px;
  letter-spacing: 2px;
  color: #ffe885;
  font-weight: 700;
}

.hi-score-pill {
  font-family: "Courier New", monospace;
  font-size: 14px;
  font-weight: 700;
  color: var(--nes-gold);
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 216, 0, 0.4);
  padding: 5px 14px;
  border-radius: 999px;
  margin-bottom: 18px;
}

.btn-primary {
  background: linear-gradient(180deg, #ffdd22 0%, #f5a600 100%);
  color: #361900;
  border: 2px solid #fff3a1;
  border-radius: 10px;
  padding: 12px 34px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 5px 0 #9e5d00, 0 10px 20px rgba(0, 0, 0, 0.45);
  transition: transform 0.1s, filter 0.15s;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #9e5d00;
}

.level-select {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-level {
  background: rgba(16, 23, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #e8eefc;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn-level:hover {
  background: rgba(45, 76, 150, 0.85);
  border-color: var(--nes-gold);
  transform: translateY(-1px);
}

.overlay-card {
  background: rgba(14, 18, 30, 0.92);
  border: 2px solid #3c486b;
  border-radius: 14px;
  padding: 26px 40px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.65);
}

.overlay-card h2 {
  font-family: "Courier New", monospace;
  font-size: 30px;
  margin-bottom: 10px;
  color: var(--nes-gold);
}

.overlay-card p {
  color: #cbd5f0;
  margin-bottom: 18px;
  font-size: 15px;
}

.overlay-btn-row {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-secondary {
  background: #27314a;
  color: #f0f4ff;
  border: 1px solid #48567d;
  border-radius: 10px;
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.btn-secondary:hover {
  background: #334061;
}

/* ---- Bottom Controls Help & Touch Pad ---- */
.controls-footer {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 0 4px;
}

.key-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

kbd {
  display: inline-block;
  background: #22293d;
  border: 1px solid #3f4b6e;
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  font-family: "Courier New", monospace;
  font-size: 11.5px;
  color: #f3f6ff;
  margin: 0 2px;
}

/* Virtual Touch Controls (shown on touch/small screens or toggleable) */
.touch-pad {
  display: none;
  margin-top: 14px;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 6px 4px 2px;
}

.touch-group {
  display: flex;
  gap: 10px;
}

.touch-btn {
  width: 56px;
  height: 52px;
  border-radius: 12px;
  border: 2px solid #3c4869;
  background: #1f263a;
  color: #ffffff;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  touch-action: none;
}

.touch-btn.action-jump {
  background: #c92420;
  border-color: #ff6e6a;
  width: 72px;
}

.touch-btn.action-fire {
  background: #d97706;
  border-color: #fbbf24;
  width: 64px;
}

.touch-btn.active {
  transform: scale(0.93);
  filter: brightness(1.25);
}

body.embed-mode {
  background: #06080f;
  padding: 12px 24px 16px;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

body.embed-mode .arcade-shell {
  width: min(1060px, 100%, calc((100vh - 86px) * 800 / 480));
  max-width: 100%;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
}

body.embed-mode .controls-footer {
  display: none;
}

body.embed-mode .hud-bar {
  margin-bottom: 10px;
  padding: 8px 16px;
  background: rgba(14, 17, 26, 0.92);
  border-color: rgba(255, 255, 255, 0.09);
}

body.embed-mode .stage-frame {
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.72);
}

@media (max-width: 780px) {
  .arcade-shell {
    padding: 10px;
  }
  .hud-stats {
    gap: 12px;
  }
  .hud-value {
    font-size: 15px;
  }
  .title-banner h1 {
    font-size: 24px;
  }
  .touch-pad {
    display: flex;
  }
}
