/* ============================================================
   STAR IMPACT — retro space shooter
   Vanilla CSS · dark arcade theme · fully responsive
   ============================================================ */

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

:root {
  --bg1: #0a0e27;
  --bg2: #12183a;
  --accent: #00d4ff;
  --accent2: #667eea;
  --accent3: #764ba2;
  --danger: #ff4d6d;
  --gold: #ffd166;
  --font: "Courier New", ui-monospace, Menlo, Consolas, monospace;
}

html, body {
  height: 100%;
  background: radial-gradient(circle at 50% 20%, #141a3a 0%, var(--bg1) 60%, #05070f 100%);
  color: #e8ecff;
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

body { display: flex; align-items: center; justify-content: center; }

/* --- Layout wrapper keeps a true 16:9 and centers --- */
.game-wrap {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
  max-height: 100vh;
  max-width: 1100px;
  background: #05070f;
  box-shadow: 0 0 60px rgba(0, 212, 255, 0.15), inset 0 0 0 2px rgba(102, 126, 234, 0.25);
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: transparent;
  touch-action: none;
}

/* --- HUD --- */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  z-index: 6;
  font-size: clamp(10px, 1.6vw, 15px);
  letter-spacing: 1px;
  pointer-events: none;
  text-shadow: 0 0 8px rgba(0, 212, 255, 0.6);
}
.hud-left, .hud-right { display: flex; align-items: center; gap: 10px; }
.hud-item { color: #9fb0ff; }
.hud-item b { color: #fff; }
.hud-item.lives { color: var(--danger); letter-spacing: 2px; font-size: 1.1em; }

.icon-btn {
  pointer-events: auto;
  background: rgba(102, 126, 234, 0.15);
  border: 1px solid rgba(0, 212, 255, 0.4);
  color: #fff;
  border-radius: 8px;
  width: 34px; height: 30px;
  font-size: 14px;
  cursor: pointer;
  transition: background .2s, transform .1s;
}
.icon-btn:hover { background: rgba(0, 212, 255, 0.25); }
.icon-btn:active { transform: scale(0.92); }

/* --- Boss bar --- */
.boss-bar {
  position: absolute;
  top: 40px; left: 50%;
  transform: translateX(-50%);
  width: min(70%, 520px);
  z-index: 6;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.boss-bar.show { display: flex; }
.boss-name { font-size: 11px; color: var(--danger); letter-spacing: 3px; text-shadow: 0 0 8px var(--danger); }
.boss-bar-track {
  width: 100%; height: 10px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255, 77, 109, 0.6);
  border-radius: 6px; overflow: hidden;
}
.boss-bar-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #ff4d6d, #ffd166);
  transition: width .15s linear;
}

/* --- Overlays --- */
.overlay {
  position: absolute; inset: 0;
  z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5, 7, 15, 0.82);
  backdrop-filter: blur(3px);
  padding: 16px;
}
.overlay.hidden { display: none; }

.panel {
  text-align: center;
  padding: clamp(18px, 4vw, 38px);
  border: 2px solid rgba(0, 212, 255, 0.35);
  border-radius: 16px;
  background: linear-gradient(160deg, rgba(102,126,234,0.12), rgba(118,75,162,0.08));
  box-shadow: 0 0 40px rgba(0, 212, 255, 0.2);
  max-width: 460px; width: 100%;
}

.title {
  font-size: clamp(28px, 7vw, 56px);
  font-weight: 800;
  letter-spacing: 4px;
  color: #fff;
  text-shadow: 0 0 12px var(--accent), 0 0 28px var(--accent2);
  animation: flicker 3s infinite;
}
.title.small { font-size: clamp(22px, 5vw, 38px); }
@keyframes flicker { 0%,92%,100%{opacity:1} 93%{opacity:.6} 95%{opacity:1} 97%{opacity:.7} }

.tagline { margin: 10px 0 18px; color: #9fb0ff; font-size: clamp(11px, 2vw, 15px); }

.how {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 14px;
  margin: 8px 0 20px;
  font-size: clamp(10px, 1.8vw, 13px);
}
.how div { display: flex; justify-content: space-between; gap: 8px; background: rgba(255,255,255,0.05); padding: 7px 10px; border-radius: 8px; }
.how b { color: var(--accent); }
.how span { color: #cdd6ff; }

.btn {
  display: inline-block;
  margin: 6px 5px 0;
  padding: 12px 26px;
  font-family: var(--font);
  font-weight: 700;
  font-size: clamp(13px, 2.2vw, 16px);
  letter-spacing: 2px;
  color: #fff;
  background: rgba(255,255,255,0.06);
  border: 2px solid rgba(0, 212, 255, 0.5);
  border-radius: 10px;
  cursor: pointer;
  transition: transform .12s, box-shadow .2s, background .2s;
}
.btn:hover { background: rgba(0, 212, 255, 0.15); box-shadow: 0 0 18px rgba(0,212,255,.35); }
.btn:active { transform: scale(0.95); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent2), var(--accent3));
  border-color: transparent;
  box-shadow: 0 6px 20px rgba(102,126,234,.5);
}
.btn.primary:hover { box-shadow: 0 8px 26px rgba(0,212,255,.6); }

.hint { margin-top: 14px; font-size: 11px; color: #6f7bb5; }
.score-line { margin: 6px 0; font-size: clamp(13px, 2.4vw, 17px); color: #cdd6ff; }
.score-line b { color: var(--gold); }
.new-high { color: var(--gold); margin: 10px 0; letter-spacing: 2px; animation: flicker 1.2s infinite; }
.hidden { display: none !important; }

/* --- Level banner --- */
.banner {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 8;
  font-size: clamp(20px, 5vw, 40px);
  font-weight: 800; letter-spacing: 4px;
  color: #fff;
  text-shadow: 0 0 14px var(--accent), 0 0 30px var(--accent3);
  pointer-events: none;
  animation: bannerPop .4s ease-out;
  text-align: center;
}
@keyframes bannerPop { from { opacity: 0; transform: translate(-50%,-50%) scale(.6);} to {opacity:1; transform: translate(-50%,-50%) scale(1);} }

/* --- Touch controls --- */
.touch {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 7;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 14px 18px;
  pointer-events: none;
}
.touch .dpad {
  position: relative;
  width: 132px; height: 132px;
  pointer-events: none;
}
.tbtn {
  pointer-events: auto;
  position: absolute;
  width: 44px; height: 44px;
  border-radius: 10px;
  background: rgba(102,126,234,0.28);
  border: 1px solid rgba(0,212,255,0.5);
  color: #fff; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  touch-action: none;
  transition: background .1s, transform .05s;
}
.tbtn:active, .tbtn.active { background: rgba(0,212,255,0.5); transform: scale(0.9); }
.dpad .up    { top: 0;   left: 44px; }
.dpad .left  { top: 44px; left: 0; }
.dpad .right { top: 44px; left: 88px; }
.dpad .down  { top: 88px; left: 44px; }
.tbtn.fire {
  position: static;
  width: 84px; height: 84px;
  border-radius: 50%;
  font-size: 15px; font-weight: 800; letter-spacing: 1px;
  background: radial-gradient(circle at 40% 35%, rgba(255,77,109,.65), rgba(118,75,162,.55));
  border: 2px solid rgba(255, 209, 102, 0.7);
}

/* show touch controls on touch / small screens */
@media (hover: none) and (pointer: coarse) {
  .touch { display: none; }   /* mobile uses drag-to-move + auto-fire instead of buttons */
}
body.touch-mode .touch { display: none; }

.back-home {
  position: absolute;
  left: 10px; bottom: 8px;
  z-index: 6;
  font-size: 11px;
  color: #7f8bc7;
  text-decoration: none;
  background: rgba(0,0,0,.25);
  padding: 4px 8px; border-radius: 6px;
}
.back-home:hover { color: var(--accent); }

/* when touch controls visible, nudge home link so it doesn't overlap dpad */
@media (hover: none) and (pointer: coarse) {
  .back-home { bottom: auto; top: 6px; left: 50%; transform: translateX(-50%); }
}
