html, body {
  margin: 0;
  height: 100%;
  background: #050308;
  color: #887;
  font-family: "Courier New", monospace;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

#frame {
  position: relative;
  /* 480x270 canvas upscaled 2x, kept pixelated */
  width: min(960px, 96vw);
  aspect-ratio: 16 / 9;
  box-shadow: 0 0 60px rgba(160, 30, 30, 0.25);
}

#game {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  background: #000;
}

/* CRT scanline overlay */
#scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.18) 3px
  );
  mix-blend-mode: multiply;
}

#controls-hint {
  font-size: 12px;
  letter-spacing: 0.5px;
  margin: 0;
}

/* ---- Mobile touch controls ---- */

/* Hide the keyboard hint once on-screen controls are active. */
body.touch-active #controls-hint { display: none; }

/* Overlay spans the viewport but only the buttons capture pointers, so the
   canvas underneath stays visible. */
#touch-controls {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 12px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  box-sizing: border-box;
}

#touch-dpad,
#touch-actions {
  pointer-events: none;
  display: grid;
  gap: 10px;
}

/* Directional cluster: ◀ ▲ ▶ in a row, thumb-reachable bottom-left. */
#touch-dpad { grid-auto-flow: column; align-items: center; }

/* Action cluster: 2x2 grid bottom-right. */
#touch-actions { grid-template-columns: repeat(2, auto); }

.touch-btn {
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(200, 120, 120, 0.55);
  background: rgba(20, 12, 16, 0.45);
  color: #d8c8b8;
  font-family: "Courier New", monospace;
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.touch-btn.active {
  background: rgba(180, 40, 40, 0.55);
  border-color: rgba(255, 180, 160, 0.9);
}

/* Portrait nudge — only meaningful on touch devices. */
#rotate-hint { display: none; }

@media (orientation: portrait) {
  body.touch-active #rotate-hint {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #050308;
    color: #b89;
    font-size: 22px;
    line-height: 1.5;
    text-align: center;
  }
  /* No point showing the controls while we're asking them to rotate. */
  body.touch-active #touch-controls { display: none; }
}
