* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: #111216;
  color: #e9e6dc;
  font-family: 'Press Start 2P', monospace;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 8px;
  width: 100%;
}
.hud {
  width: min(calc(100vw - 16px), calc((100dvh - 120px) * 256 / 224), 1024px);
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}
.hud b { color: #ffd34d; font-weight: normal; }
.hud-right { display: flex; align-items: center; gap: 12px; }
.fs-btn {
  font: inherit; font-size: 14px; line-height: 1; color: #e9e6dc;
  background: #2a2c35; border: 2px solid #44475a; border-radius: 6px;
  padding: 4px 6px; cursor: pointer;
}
.fs-btn:hover, .fs-btn:focus-visible { background: #44475a; outline: none; }

/* Full screen: the wrap fills the screen, help text hides, canvas gets more room */
.wrap:fullscreen { background: #111216; justify-content: center; height: 100%; }
body.fs .wrap { position: fixed; inset: 0; z-index: 10; background: #111216; justify-content: center; }
body.fs .help { display: none; }
body.fs .hud, body.fs canvas { width: min(calc(100vw - 16px), calc((100dvh - 48px) * 256 / 224)); }
canvas {
  display: block;
  width: min(calc(100vw - 16px), calc((100dvh - 120px) * 256 / 224), 1024px);
  aspect-ratio: 256 / 224;
  image-rendering: pixelated;
  background: #000;
  border: 2px solid #2a2c35;
}
.help { font-size: 9px; color: #8a8d99; text-align: center; line-height: 1.6; }

.touch { display: none; width: 100%; max-width: 480px; justify-content: space-between; align-items: center; padding: 4px 12px; }
.touch button {
  font: inherit; color: #e9e6dc; background: #2a2c35; border: 2px solid #44475a; border-radius: 10px;
  touch-action: none;
}
.touch button:active, .touch button.on { background: #44475a; }
.dpad { display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(3, 52px); gap: 4px; }
.dpad .up { grid-area: 1 / 2; }
.dpad .left { grid-area: 2 / 1; }
.dpad .right { grid-area: 2 / 3; }
.dpad .down { grid-area: 3 / 2; }
.actions { display: flex; align-items: center; gap: 16px; }
.actions .fire { width: 92px; height: 92px; border-radius: 50%; background: #8c2f1b; border-color: #c4532f; font-size: 12px; }
.actions .small { width: 44px; height: 44px; font-size: 10px; }

@media (pointer: coarse) {
  .touch { display: flex; }
  .help { display: none; }
  .hud, canvas { width: min(calc(100vw - 16px), calc((100dvh - 300px) * 256 / 224)); }
  body.fs .hud, body.fs canvas { width: min(calc(100vw - 16px), calc((100dvh - 250px) * 256 / 224)); }
}
