/* Reset & base */
:root {
  --bg1: #05070a;
  --bg2: #0a1220;
  --hud: #e6f3ff;
  --accent: #78c6ff;
  --accent2: #ff6578;
  --scan: rgba(255,255,255,0.04);
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(60% 60% at 50% 35%, #101628 0%, #080b12 60%, black 100%);
  color: white;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  overflow:hidden;
  border:none;
  /* prevent iOS rubber band in iframes a bit */
  overscroll-behavior: none;
}

/* Frame */
.frame {
  position: relative;
  width: min(96vw, 560px, calc(96vh * 0.70));
  margin: calc(10px + var(--safe-top)) auto calc(10px + var(--safe-bottom));
  padding: 16px 16px 0;
  border: 2px solid #2b3550;
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,.6), inset 0 0 40px rgba(10,20,40,.6);
  background: linear-gradient(180deg, var(--bg2), var(--bg1));
}

.viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;          /* 480×640 logical playfield */
  background: black;
  border: 1px solid #3d4a6a;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 40px rgba(0,0,0,.7);
}

/* Make the canvas and gesture layer fill the viewport */
.viewport > #game,
.viewport > #gestureLayer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Canvas */
#game {
  display: block;
  image-rendering: pixelated;
  border-radius: 12px;
  background: black;
  border: 1px solid #3d4a6a;
  box-shadow: inset 0 0 40px rgba(0,0,0,.7);
  /* critical for touch: don’t let browser scroll/zoom gestures steal events */
  touch-action: none;
}

/* The gesture layer is invisible but captures touches */
#gestureLayer {
  background: transparent;
  touch-action: none;   /* allow multi-touch without browser panning */
  /* pointer-events stays enabled (default) to receive gestures */
}

/* HUD */
.hud {
  position: absolute;
  left: 0; right: 0;
  top: 6px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  pointer-events: none;
  padding: 0 12px;
  font-weight: 700;
  text-shadow: 0 1px 0 #000, 0 0 8px rgba(120,198,255,.4);
}
.hud-left, .hud-right {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--hud);
  font-size: 12px;
}
.hud-right { justify-content: flex-end; }
.hud-center {
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 2px;
}
#score { min-width: 72px; text-align: right; }
#lives { display: inline-flex; gap: 6px; }
.life {
  width: 14px; height: 14px;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 14px solid var(--accent);
  filter: drop-shadow(0 0 4px rgba(120,198,255,.6));
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,.55);
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  border-radius: 12px;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.overlay h1, .overlay h2 {
  margin: 0 0 8px 0;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 2px 0 #000, 0 0 16px rgba(120,198,255,.6);
}
.overlay p { margin: 4px 0 16px; color: #b9c6e0; }
.overlay .help {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  color: #d2def5;
  opacity: .9;
}

.ui-btn {
  background: linear-gradient(180deg,#20345a,#16223d);
  border: 1px solid #5b7fb4;
  color: #dff2ff;
  padding: 14px 18px;              /* bigger tap target */
  border-radius: 12px;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,.4), inset 0 0 16px rgba(120,198,255,.2);
  touch-action: manipulation;      /* reduce delay on mobile */
}
.ui-btn:hover { filter: brightness(1.08); }
.ui-btn:active { transform: translateY(1px); }

/* Mobile controls */
#touchControls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 0 calc(12px + var(--safe-bottom));
}
.pad { display: flex; gap: 10px; justify-content: center; }
#touchControls button {
  min-width: 96px;
  min-height: 56px;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(120,198,255,.45);
  color: #dff2ff;
  border-radius: 12px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  font-weight: 700;
  touch-action: manipulation;
}
#touchControls button:active { background: rgba(255,255,255,.18); }

/* Hide mobile controls on large screens (gestures still work) */
@media (min-width: 720px) {
  #touchControls { display: none; }
}
