* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: monospace;
  position: fixed;
  top: 0;
  left: 0;
}

#game-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: #000;
}

#game-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  margin: 0 auto;
  border-radius: 6px;
  max-width: 100%;
  max-height: 100%;
}

#cutscene-video {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  z-index: 5;
  border-radius: 6px;
}

/* ── Virtual Gamepad ── */
#touch-controls {
  position: fixed;
  bottom: max(env(safe-area-inset-bottom, 4px), 4px);
  right: 0;
  z-index: 10;
  pointer-events: none;
  padding: 0 calc(env(safe-area-inset-right, 8px) + 18px) 0 0;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
}

#touch-controls.hidden {
  display: none;
}

/* ── Utility bar (debug, opacity, hide/show) ── */
.touch-utility {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  padding: 0 0 6px 0;
  pointer-events: auto;
}

.gpad-btn.util {
  background: rgba(180, 120, 255, 0.2);
  border: 1.5px solid rgba(180, 120, 255, 0.45);
  color: rgba(200, 160, 255, 0.9);
  font-size: clamp(9px, 2.4vw, 12px);
  border-radius: 8px;
  padding: 4px 8px;
  min-height: 0;
  width: auto;
}
.gpad-btn.util:active, .gpad-btn.util.pressed {
  background: rgba(180, 120, 255, 0.5);
  border-color: rgba(200, 160, 255, 0.85);
}

/* 3-wide vertically stacked grid */
.touch-grid {
  display: grid;
  grid-template-columns: repeat(3, clamp(44px, 12vw, 56px));
  gap: 4px;
  justify-content: end;
  padding: 6px 0;
  pointer-events: auto;
}

/* Empty spacer cell */
.gpad-btn.empty {
  visibility: hidden;
  pointer-events: none;
  border: none;
  background: none;
}

/* ── Base button ── */
.gpad-btn {
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  transition: background 0.08s, border-color 0.08s, transform 0.06s;
  font-family: 'Noto Sans Mono', monospace;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 0;
  min-height: clamp(40px, 9.5vw, 48px);
}

.gpad-btn:active, .gpad-btn.pressed {
  transform: scale(0.91);
}

/* ── D-pad (green) ── */
.gpad-btn.dpad {
  background: rgba(0, 170, 0, 0.3);
  border: 1.5px solid rgba(0, 255, 0, 0.45);
  color: rgba(0, 255, 0, 0.85);
  font-size: clamp(14px, 4vw, 20px);
}
.gpad-btn.dpad:active, .gpad-btn.dpad.pressed {
  background: rgba(0, 255, 0, 0.45);
  border-color: rgba(0, 255, 0, 0.8);
}

/* Diagonal buttons: slightly subdued */
.gpad-btn.dpad.diag {
  font-size: clamp(11px, 3vw, 15px);
  border-radius: 8px;
  opacity: 0.75;
}
.gpad-btn.dpad.diag:active, .gpad-btn.dpad.diag.pressed {
  opacity: 1;
}

/* D-pad center (interact) */
.gpad-btn.dpad.center {
  background: rgba(0, 170, 0, 0.18);
  border: 1.5px solid rgba(0, 255, 0, 0.22);
  color: rgba(0, 255, 0, 0.55);
  font-size: clamp(10px, 2.5vw, 14px);
}
.gpad-btn.dpad.center:active, .gpad-btn.dpad.center.pressed {
  background: rgba(0, 255, 0, 0.38);
  border-color: rgba(0, 255, 0, 0.7);
}

/* ── Face buttons (SNES colors) ── */
.gpad-btn.face {
  border-radius: 50%;
  aspect-ratio: 1 / 1;
  min-height: 0;
  width: clamp(44px, 12vw, 56px);
  height: clamp(44px, 12vw, 56px);
  font-size: clamp(13px, 3.5vw, 17px);
}

/* A = green */
.gpad-btn.face-a {
  background: rgba(0, 180, 0, 0.3);
  border: 2px solid rgba(0, 255, 0, 0.55);
  color: rgba(0, 255, 0, 0.9);
}
.gpad-btn.face-a:active, .gpad-btn.face-a.pressed {
  background: rgba(0, 255, 0, 0.5);
  border-color: rgba(0, 255, 0, 0.9);
}

/* B = red */
.gpad-btn.face-b {
  background: rgba(200, 0, 0, 0.3);
  border: 2px solid rgba(255, 60, 60, 0.55);
  color: rgba(255, 80, 80, 0.9);
}
.gpad-btn.face-b:active, .gpad-btn.face-b.pressed {
  background: rgba(255, 60, 60, 0.5);
  border-color: rgba(255, 80, 80, 0.9);
}

/* X = blue */
.gpad-btn.face-x {
  background: rgba(0, 80, 220, 0.3);
  border: 2px solid rgba(60, 130, 255, 0.55);
  color: rgba(80, 150, 255, 0.9);
}
.gpad-btn.face-x:active, .gpad-btn.face-x.pressed {
  background: rgba(60, 130, 255, 0.5);
  border-color: rgba(80, 150, 255, 0.9);
}

/* Y = yellow */
.gpad-btn.face-y {
  background: rgba(200, 200, 0, 0.25);
  border: 2px solid rgba(255, 255, 85, 0.55);
  color: rgba(255, 255, 85, 0.9);
}
.gpad-btn.face-y:active, .gpad-btn.face-y.pressed {
  background: rgba(255, 255, 85, 0.5);
  border-color: rgba(255, 255, 85, 0.9);
}

/* ── Shoulder buttons (cyan) ── */
.gpad-btn.shoulder {
  background: rgba(0, 170, 170, 0.25);
  border: 1.5px solid rgba(0, 255, 255, 0.4);
  color: rgba(0, 255, 255, 0.85);
  font-size: clamp(10px, 2.8vw, 13px);
  border-radius: 8px;
}
.gpad-btn.shoulder:active, .gpad-btn.shoulder.pressed {
  background: rgba(0, 255, 255, 0.45);
  border-color: rgba(0, 255, 255, 0.8);
}

/* ── Meta buttons: Start / Select (purple) ── */
.gpad-btn.meta {
  background: rgba(170, 85, 255, 0.2);
  border: 1.5px solid rgba(170, 85, 255, 0.45);
  color: rgba(200, 150, 255, 0.85);
  font-size: clamp(10px, 2.8vw, 13px);
  border-radius: 12px;
}
.gpad-btn.meta:active, .gpad-btn.meta.pressed {
  background: rgba(170, 85, 255, 0.5);
  border-color: rgba(170, 85, 255, 0.85);
}

/* Start button slightly more prominent */
.gpad-btn.meta.start {
  background: rgba(200, 100, 255, 0.25);
  border-color: rgba(200, 120, 255, 0.55);
  color: rgba(220, 170, 255, 0.95);
}

/* ── Landscape: tighten for short screens ── */
@media (orientation: landscape) and (max-height: 500px) {
  #touch-controls {
    padding-bottom: calc(env(safe-area-inset-bottom, 4px) + 8px);
    padding-right: calc(env(safe-area-inset-right, 4px) + 12px);
  }

  .touch-grid {
    grid-template-columns: repeat(3, 38px);
    gap: 3px;
  }

  .gpad-btn {
    min-height: 34px;
  }

  .gpad-btn.face {
    width: 38px;
    height: 38px;
  }
}

/* Touch grid hidden state (via hide button) — utility bar stays visible */
.touch-grid.collapsed {
  display: none;
}

/* Debug panel is now rendered in-game via canvas — no HTML/CSS needed */
