@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@500;800&display=swap');

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

html, body {
  width: 100%; height: 100%;
  background: #000;
  overflow: hidden;
  font-family: 'Orbitron', 'Arial Black', sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#game-container { position: relative; width: 100%; height: 100%; }
#game-canvas { display: block; width: 100%; height: 100%; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 18px 26px;
  pointer-events: none;
  z-index: 5;
}
.hud-label {
  display: block; font-size: 10px; letter-spacing: 3px;
  color: #5ee6ff; opacity: .7;
}
#score, #level {
  font-size: 28px; font-weight: 800; color: #fff;
  text-shadow: 0 0 12px rgba(94, 230, 255, .8);
}
#lives-box { display: flex; gap: 8px; }
.life-icon {
  width: 26px; height: 26px;
  background-size: contain; background-repeat: no-repeat; background-position: center;
  filter: drop-shadow(0 0 6px rgba(94, 230, 255, .7));
}

/* ---------- Power-ups / Boss / Alerts ---------- */
#powerup-box { margin-top: 6px; display: flex; flex-direction: column; gap: 2px; }
.pu-tag {
  font-size: 10px; font-weight: 800; letter-spacing: 2px;
  padding: 2px 6px; border-radius: 3px; width: max-content;
  background: rgba(0, 20, 30, .6);
}
.pu-triple { color: #ffa040; text-shadow: 0 0 8px #ffa040; }
.pu-shield { color: #40e0ff; text-shadow: 0 0 8px #40e0ff; }
.pu-slow   { color: #c080ff; text-shadow: 0 0 8px #c080ff; }
.pu-rapid  { color: #ffd700; text-shadow: 0 0 8px #ffd700; }

#boss-bar-wrap {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  width: 320px; text-align: center; z-index: 5; pointer-events: none;
}
#boss-bar-bg {
  margin-top: 4px; height: 10px; border: 1px solid rgba(255, 80, 60, .6);
  border-radius: 5px; overflow: hidden; background: rgba(20, 0, 0, .5);
}
#boss-bar {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #ff3020, #ff8040);
  box-shadow: 0 0 12px rgba(255, 60, 30, .8);
  transition: width .25s ease;
}
#boss-bar-wrap .hud-label { color: #ff7050; }

#alert-banner {
  position: absolute; top: 18%; left: 50%; transform: translateX(-50%);
  font-size: 26px; font-weight: 800; letter-spacing: 8px;
  color: #ff4030; text-shadow: 0 0 18px rgba(255, 60, 30, .9);
  z-index: 6; pointer-events: none;
  animation: alertblink .4s steps(2) infinite;
}
@keyframes alertblink { 50% { opacity: .15; } }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 22px;
  background: radial-gradient(ellipse at center, rgba(5,10,25,.55) 0%, rgba(0,0,5,.88) 100%);
  z-index: 10;
}
.hidden { display: none; }

.title {
  font-size: 72px; font-weight: 800; text-align: center; line-height: 1.05;
  color: #fff; letter-spacing: 8px;
  text-shadow: 0 0 20px #2bd9ff, 0 0 60px rgba(43, 217, 255, .5);
  animation: pulse 2.4s ease-in-out infinite;
}
.title.small { font-size: 52px; }
@keyframes pulse {
  0%, 100% { text-shadow: 0 0 20px #2bd9ff, 0 0 60px rgba(43,217,255,.5); }
  50%      { text-shadow: 0 0 30px #2bd9ff, 0 0 90px rgba(43,217,255,.8); }
}

.subtitle { color: #8fa6c8; font-size: 14px; letter-spacing: 4px; }

.controls-hint { text-align: center; color: #b9c8e0; font-size: 13px; line-height: 2; letter-spacing: 1px; }
.controls-hint b { color: #5ee6ff; }

.big-btn {
  font-family: inherit; font-size: 20px; font-weight: 800; letter-spacing: 6px;
  padding: 16px 54px;
  color: #001018; background: linear-gradient(180deg, #6ff0ff, #18a8d8);
  border: none; border-radius: 6px; cursor: pointer;
  box-shadow: 0 0 24px rgba(43, 217, 255, .55);
  transition: transform .12s ease, box-shadow .12s ease;
}
.big-btn:hover { transform: scale(1.06); box-shadow: 0 0 40px rgba(43, 217, 255, .9); }
.big-btn:active { transform: scale(.97); }

.final-score, .best-score { color: #fff; font-size: 22px; letter-spacing: 3px; }
.final-score span { color: #5ee6ff; font-weight: 800; }
.best-score { font-size: 15px; color: #8fa6c8; }
.best-score span { color: #ffd166; font-weight: 800; }

/* ---------- Combo / lives / vignette / upgrades / mode buttons ---------- */
#combo {
  font-size: 22px; font-weight: 800; min-height: 26px;
  color: #ffd166; text-shadow: 0 0 10px rgba(255, 209, 102, .9);
}
#combo.t2 { color: #ffd166; }
#combo.t3 { color: #ff9040; font-size: 26px; text-shadow: 0 0 14px rgba(255, 144, 64, .95); }
#combo.t5 { color: #ff5030; font-size: 30px; text-shadow: 0 0 18px rgba(255, 80, 48, 1); animation: alertblink .35s steps(2) infinite; }

#lives-wrap { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
#lives-box, #lives-box2 { display: flex; gap: 8px; }

#vignette {
  position: absolute; inset: 0; pointer-events: none; z-index: 4;
  box-shadow: inset 0 0 140px 40px rgba(255, 30, 20, .45);
  animation: vigpulse 1.1s ease-in-out infinite;
}
@keyframes vigpulse {
  0%, 100% { opacity: .45; }
  50%      { opacity: 1; }
}

.btn-row { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.big-btn.alt {
  color: #002010; background: linear-gradient(180deg, #79ffb0, #18c068);
  box-shadow: 0 0 24px rgba(60, 230, 140, .5);
}
.big-btn.alt2 {
  color: #201600; background: linear-gradient(180deg, #ffd970, #d89018);
  box-shadow: 0 0 24px rgba(255, 200, 60, .5);
}

#upgrade-row { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; padding: 0 16px; }
.upg-card {
  font-family: inherit; cursor: pointer;
  width: 220px; min-height: 130px; padding: 18px 14px;
  border-radius: 10px; border: 2px solid rgba(94, 230, 255, .5);
  background: rgba(8, 25, 40, .8);
  color: #fff; text-align: center;
  transition: transform .12s ease, box-shadow .12s ease;
}
.upg-card:hover { transform: scale(1.05); box-shadow: 0 0 26px rgba(43, 217, 255, .7); border-color: #6ff0ff; }
.upg-card b { display: block; color: #5ee6ff; font-size: 15px; letter-spacing: 2px; margin-bottom: 10px; }
.upg-card span { font-size: 12px; color: #b9c8e0; line-height: 1.6; font-weight: 500; }

@media (max-width: 740px) {
  .upg-card { width: 150px; min-height: 110px; padding: 12px 8px; }
  .upg-card b { font-size: 12px; }
  .upg-card span { font-size: 10px; }
  #combo { font-size: 16px; }
}

/* ---------- Arcade pack: nova, sectors, hangar, records ---------- */
#nova-wrap { margin-top: 8px; width: 130px; }
#nova-bg {
  height: 8px; margin-top: 3px; border-radius: 4px; overflow: hidden;
  border: 1px solid rgba(94, 230, 255, .4); background: rgba(0, 20, 30, .5);
}
#nova-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #2bd9ff, #b0f5ff);
  box-shadow: 0 0 10px rgba(43, 217, 255, .9);
}
#nova-bar.ready { animation: alertblink .4s steps(2) infinite; background: linear-gradient(90deg, #fff, #6ff0ff); }

#sector-label { display: block; font-size: 9px; letter-spacing: 2px; color: #8fa6c8; margin-top: 2px; }
#sector-banner {
  position: absolute; top: 26%; left: 50%; transform: translateX(-50%);
  font-size: 22px; font-weight: 800; letter-spacing: 7px; width: max-content;
  color: #aef; text-shadow: 0 0 16px rgba(94, 230, 255, .9);
  z-index: 6; pointer-events: none;
}
#hud.flicker { animation: hudflick .12s steps(2) infinite; }
@keyframes hudflick { 50% { opacity: .55; } }

#hangar { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.ship-card {
  font-family: inherit; cursor: pointer;
  width: 150px; padding: 12px 10px 14px;
  border-radius: 10px; border: 2px solid rgba(94, 230, 255, .3);
  background: rgba(8, 25, 40, .7); color: #fff; text-align: center;
  transition: transform .12s ease, border-color .12s ease;
}
.ship-card:hover { transform: scale(1.05); }
.ship-card.selected { border-color: #6ff0ff; box-shadow: 0 0 22px rgba(43, 217, 255, .6); }
.ship-card.locked { opacity: .65; }
.ship-card img { width: 64px; height: 64px; object-fit: contain; }
.ship-card b { display: block; color: #5ee6ff; font-size: 13px; letter-spacing: 2px; margin: 6px 0 4px; }
.ship-card span { font-size: 10px; color: #b9c8e0; line-height: 1.5; display: block; }
.ship-card .cost { color: #ffd166; font-weight: 800; margin-top: 6px; }
#credits-line { color: #ffd166; font-size: 13px; letter-spacing: 3px; }
#credits-line span { font-weight: 800; }

.big-btn.ghostbtn {
  color: #8fa6c8; background: rgba(10, 30, 45, .5);
  border: 2px solid rgba(94, 230, 255, .35); box-shadow: none;
}

#ach-list {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px; max-width: 720px; padding: 0 18px; max-height: 46vh; overflow-y: auto;
}
.ach-item {
  border: 1px solid rgba(94, 230, 255, .3); border-radius: 8px;
  padding: 10px 12px; background: rgba(8, 25, 40, .7);
}
.ach-item b { color: #ffd166; font-size: 12px; letter-spacing: 2px; display: block; }
.ach-item span { color: #b9c8e0; font-size: 11px; }
.ach-item.locked { opacity: .4; filter: grayscale(1); }
#stats-line { color: #8fa6c8; font-size: 12px; letter-spacing: 2px; text-align: center; line-height: 1.8; }

#ach-toast {
  position: absolute; top: 12%; left: 50%; transform: translateX(-50%);
  padding: 10px 22px; border-radius: 8px; width: max-content;
  background: rgba(8, 25, 40, .9); border: 1px solid #ffd166;
  color: #ffd166; font-size: 14px; font-weight: 800; letter-spacing: 3px;
  z-index: 7; pointer-events: none;
  box-shadow: 0 0 24px rgba(255, 209, 102, .5);
}

.tc-nova {
  width: 64px; height: 64px;
  border-color: rgba(176, 245, 255, .55); color: #b0f5ff; font-size: 24px;
}

@media (max-width: 740px) {
  .ship-card { width: 104px; padding: 8px 6px 10px; }
  .ship-card img { width: 40px; height: 40px; }
  #hangar { gap: 8px; }
  #sector-banner { font-size: 14px; letter-spacing: 4px; }
  #nova-wrap { width: 100px; }
}

/* ---------- Touch controls (shown only on touch devices) ---------- */
#touch-controls, #tc-top { display: none; }

body.touch #touch-controls {
  display: flex; justify-content: space-between; align-items: flex-end;
  position: absolute; left: 0; right: 0;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  padding: 0 calc(14px + env(safe-area-inset-left, 0px)) 0 calc(14px + env(safe-area-inset-right, 0px));
  z-index: 8; pointer-events: none;
}
#tc-left, #tc-right { display: flex; gap: 14px; align-items: flex-end; }

.touch-btn {
  pointer-events: auto;
  width: 76px; height: 76px; border-radius: 50%;
  border: 2px solid rgba(94, 230, 255, .45);
  background: rgba(10, 30, 45, .35);
  color: #5ee6ff; font-size: 26px; font-family: inherit;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
  touch-action: none;
}
.touch-btn:active, .touch-btn.held {
  background: rgba(60, 200, 255, .35);
  border-color: rgba(160, 240, 255, .9);
}
.tc-fire {
  width: 92px; height: 92px;
  border-color: rgba(255, 120, 80, .55);
  color: #ff8050; font-size: 34px;
}
.tc-fire:active, .tc-fire.held {
  background: rgba(255, 110, 60, .3);
  border-color: rgba(255, 180, 140, .9);
}
.tc-small { width: 84px; height: 84px; }

body.touch #tc-top {
  display: flex; gap: 10px;
  position: absolute; top: calc(12px + env(safe-area-inset-top, 0px));
  left: 50%; transform: translateX(-50%);
  z-index: 8;
}
.tc-mini {
  pointer-events: auto;
  width: 40px; height: 40px; border-radius: 8px;
  border: 1px solid rgba(94, 230, 255, .4);
  background: rgba(10, 30, 45, .35);
  color: #5ee6ff; font-size: 16px; font-family: inherit;
}
.tc-mini.off { color: #5e6a7a; border-color: rgba(120, 130, 150, .3); }

/* tighter HUD + titles on small screens */
body.touch .controls-hint { display: none; }
@media (max-width: 740px) {
  .title { font-size: 44px; letter-spacing: 4px; }
  .title.small { font-size: 34px; }
  #hud { padding: 12px 14px; }
  #score, #level { font-size: 20px; }
  .life-icon { width: 20px; height: 20px; }
  #boss-bar-wrap { width: 200px; top: 10px; }
  #alert-banner { font-size: 15px; letter-spacing: 4px; width: max-content; }
  .big-btn { font-size: 17px; padding: 14px 40px; }
}
body.touch #boss-bar-wrap { top: calc(58px + env(safe-area-inset-top, 0px)); }
