:root {
  --bg-color: #070614;
  --panel-bg: rgba(14, 12, 36, 0.85);
  --neon-cyan: #00f0ff;
  --neon-magenta: #ff007f;
  --neon-green: #39ff14;
  --neon-yellow: #ffe600;
  --neon-gold: #ffaa00;
  --text-color: #f0f6fc;
  --font-main: 'Orbitron', 'Rajdhani', sans-serif;
  --font-pixel: 'Press Start 2P', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: var(--font-main);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

#appContainer {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at center, #151030 0%, #05040d 100%);
}

#gameViewport {
  position: relative;
  width: min(100vw, 900px);
  height: min(100vh, 700px);
  aspect-ratio: 9 / 7;
  box-shadow: 0 0 40px rgba(0, 240, 255, 0.25), 0 0 80px rgba(255, 0, 127, 0.15);
  border-radius: 12px;
  overflow: hidden;
  background-color: #000;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* CRT Overlay */
.crt-effect {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(
    rgba(18, 16, 16, 0) 50%, 
    rgba(0, 0, 0, 0.25) 50%
  ), linear-gradient(
    90deg,
    rgba(255, 0, 0, 0.03),
    rgba(0, 255, 0, 0.01),
    rgba(0, 0, 255, 0.03)
  );
  background-size: 100% 4px, 6px 100%;
  z-index: 10;
}

/* Glassmorphism Panel */
.glass-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid rgba(0, 240, 255, 0.4);
  box-shadow: inset 0 0 20px rgba(0, 240, 255, 0.15), 0 10px 30px rgba(0, 0, 0, 0.8);
  border-radius: 16px;
  padding: 2rem;
  max-width: 90%;
  width: 580px;
  text-align: center;
}

/* Overlay Screens */
.overlay-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20;
  background: rgba(4, 3, 12, 0.85);
  animation: fadeIn 0.3s ease-out;
}

.hidden {
  display: none !important;
}

/* Typography & Titles */
.title-container {
  margin-bottom: 1.5rem;
}

.ufo-logo-anim {
  font-size: 3.5rem;
  animation: floatUfo 2.5s ease-in-out infinite alternate;
  filter: drop-shadow(0 0 15px var(--neon-cyan));
}

@keyframes floatUfo {
  0% { transform: translateY(-8px) rotate(-3deg); }
  100% { transform: translateY(8px) rotate(3deg); }
}

.game-title {
  font-family: var(--font-pixel);
  font-size: 1.8rem;
  color: #fff;
  text-shadow: 0 0 10px var(--neon-cyan), 0 0 20px var(--neon-cyan);
  letter-spacing: 2px;
  margin-top: 0.5rem;
}

.game-subtitle {
  font-size: 0.9rem;
  color: var(--neon-magenta);
  font-weight: 700;
  letter-spacing: 2px;
  margin-top: 0.5rem;
}

.screen-heading {
  font-family: var(--font-pixel);
  font-size: 1.5rem;
  color: var(--neon-cyan);
  text-shadow: 0 0 10px var(--neon-cyan);
  margin-bottom: 0.5rem;
}

.danger-text {
  color: var(--neon-magenta) !important;
  text-shadow: 0 0 10px var(--neon-magenta) !important;
}

.success-text {
  color: var(--neon-green) !important;
  text-shadow: 0 0 10px var(--neon-green) !important;
}

.sub-heading {
  color: #a0aec0;
  font-size: 0.95rem;
  letter-spacing: 1px;
  margin-bottom: 1.5rem;
}

/* Instructions Box */
.instructions-box {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 8px;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.controls-guide {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 1rem;
  text-align: left;
  font-size: 0.85rem;
}

kbd {
  background: #1e1b4b;
  border: 1px solid var(--neon-cyan);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: monospace;
  color: var(--neon-cyan);
  box-shadow: 0 2px 0 rgba(0, 240, 255, 0.4);
}

/* Arcade Buttons */
.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  width: 100%;
}

.menu-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.btn-arcade {
  font-family: var(--font-main);
  font-weight: 700;
  font-size: 1rem;
  padding: 0.85rem 1.5rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  letter-spacing: 1.5px;
  transition: all 0.15s ease;
  position: relative;
  overflow: hidden;
  text-transform: uppercase;
}

.btn-arcade.primary {
  background: linear-gradient(135deg, var(--neon-cyan) 0%, #0088ff 100%);
  color: #000;
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.5);
}

.btn-arcade.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 25px rgba(0, 240, 255, 0.8);
}

.btn-arcade.secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(0, 240, 255, 0.4);
  color: var(--text-color);
}

.btn-arcade.secondary:hover {
  background: rgba(0, 240, 255, 0.15);
  border-color: var(--neon-cyan);
}

.btn-arcade.danger {
  background: rgba(255, 0, 127, 0.2);
  border: 1px solid var(--neon-magenta);
  color: #fff;
}

.btn-arcade.danger:hover {
  background: var(--neon-magenta);
  color: #000;
  box-shadow: 0 0 20px var(--neon-magenta);
}

.btn-arcade.small {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

.golden-btn {
  background: linear-gradient(135deg, var(--neon-yellow) 0%, var(--neon-gold) 100%) !important;
  color: #000 !important;
  box-shadow: 0 0 25px rgba(255, 170, 0, 0.8) !important;
}

/* HUD Overlay */
.hud-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.6rem;
  z-index: 15;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: rgba(5, 4, 15, 0.75);
  backdrop-filter: blur(8px);
  padding: 0.5rem 1rem;
  border-radius: 10px;
  border: 1px solid rgba(0, 240, 255, 0.25);
  gap: 0.8rem;
}

.hud-stat {
  display: flex;
  flex-direction: column;
}

.hud-beam-stat {
  flex: 1;
  max-width: 180px;
}

.top-beam-track {
  height: 8px !important;
  margin-top: 2px;
}

.hud-beam-ready {
  font-size: 0.65rem;
  color: var(--neon-cyan);
  font-family: var(--font-pixel);
}

.top-boss-bar {
  width: 80%;
  max-width: 450px;
  margin-top: 0.4rem;
  background: rgba(5, 4, 15, 0.85);
  border-color: var(--neon-magenta);
}

.hud-center {
  align-items: center;
}

.hud-right {
  align-items: flex-end;
}

.hud-label {
  font-size: 0.65rem;
  color: #8a99ad;
  letter-spacing: 1px;
  font-weight: 700;
}

.hud-value {
  font-family: var(--font-pixel);
  font-size: 1.1rem;
  color: var(--neon-cyan);
  text-shadow: 0 0 8px var(--neon-cyan);
  margin-top: 2px;
}

.level-badge {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.level-sub {
  font-size: 0.75rem;
  color: var(--neon-magenta);
  font-weight: 700;
}

.lives-container {
  display: flex;
  gap: 6px;
  font-size: 1.2rem;
  margin-top: 2px;
}

.ufo-life-icon {
  filter: drop-shadow(0 0 6px var(--neon-green));
}

.ufo-life-icon.lost {
  opacity: 0.25;
  filter: grayscale(100%);
}

.hud-bar-container {
  background: rgba(5, 4, 15, 0.75);
  backdrop-filter: blur(6px);
  padding: 0.5rem 0.8rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.bar-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: #d1d5db;
}

.bar-track {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  transition: width 0.1s linear;
}

.beam-fill {
  background: linear-gradient(90deg, var(--neon-magenta), var(--neon-cyan));
  box-shadow: 0 0 10px var(--neon-cyan);
}

.boss-fill {
  background: linear-gradient(90deg, #ff0055, #ff5500);
  box-shadow: 0 0 10px #ff0055;
}

.hud-pause-btn {
  position: absolute;
  top: 0.8rem;
  right: 1rem;
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--neon-cyan);
  color: var(--neon-cyan);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
}

/* Modals & Level Select */
.modal-card {
  max-width: 680px;
  width: 95%;
}

.modal-sub {
  font-size: 0.85rem;
  color: #94a3b8;
  margin-bottom: 1rem;
}

.level-grid-container {
  max-height: 300px;
  overflow-y: auto;
  padding-right: 5px;
  margin-bottom: 1.5rem;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(55px, 1fr));
  gap: 8px;
}

.level-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  border-radius: 6px;
  padding: 0.6rem 0;
  font-family: var(--font-pixel);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.level-btn:hover:not(.locked) {
  background: var(--neon-cyan);
  color: #000;
  box-shadow: 0 0 12px var(--neon-cyan);
}

.level-btn.boss-lvl {
  border-color: var(--neon-magenta);
  color: var(--neon-magenta);
}

.level-btn.locked {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Embed Code Box */
.embed-code-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.code-textarea {
  width: 100%;
  background: #000;
  border: 1px solid var(--neon-cyan);
  color: var(--neon-green);
  font-family: monospace;
  padding: 0.8rem;
  border-radius: 6px;
  resize: none;
  font-size: 0.8rem;
}

.embed-preview-info {
  text-align: left;
  font-size: 0.8rem;
  color: #cbd5e1;
  margin-bottom: 1.5rem;
}

/* Victory Screen Styling */
.victory-card {
  max-width: 650px;
  border-color: var(--neon-gold);
  box-shadow: 0 0 40px rgba(255, 170, 0, 0.4);
}

.victory-title {
  font-family: var(--font-pixel);
  font-size: 1.4rem;
  color: var(--neon-yellow);
  text-shadow: 0 0 15px var(--neon-gold);
  margin-top: 0.5rem;
}

.pulse-glow {
  animation: pulseGlow 1.5s infinite alternate;
}

@keyframes pulseGlow {
  0% { text-shadow: 0 0 10px var(--neon-gold); }
  100% { text-shadow: 0 0 25px var(--neon-yellow), 0 0 40px #ff5500; }
}

.victory-subtitle {
  font-size: 0.85rem;
  color: var(--neon-magenta);
  margin-top: 0.4rem;
  font-weight: 700;
}

.victory-animation-area {
  width: 100%;
  height: 180px;
  margin: 1rem 0;
  background: #000;
  border-radius: 10px;
  border: 1px solid var(--neon-gold);
  overflow: hidden;
}

.stats-summary {
  background: rgba(0, 0, 0, 0.4);
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
  padding-bottom: 4px;
}

.stat-row strong {
  color: var(--neon-cyan);
}

.golden .stat-row strong {
  color: var(--neon-yellow);
}

.rank-title {
  color: var(--neon-green) !important;
}

/* Touch Overlay for Mobile / Embed */
.touch-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100px;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0.8rem;
  z-index: 18;
}

.touch-dpad, .touch-actions {
  pointer-events: auto;
  display: flex;
  gap: 0.8rem;
}

.touch-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(0, 240, 255, 0.15);
  border: 1.5px solid var(--neon-cyan);
  color: #fff;
  font-size: 1.1rem;
  font-weight: bold;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(4px);
  opacity: 0.55;
  transition: opacity 0.15s, background 0.15s;
}

.touch-btn:hover, .touch-btn:active {
  opacity: 1.0;
  background: var(--neon-cyan);
  color: #000;
}

.fire-btn {
  background: rgba(255, 0, 127, 0.2);
  border-color: var(--neon-magenta);
  width: 58px;
  height: 58px;
}

.fire-btn:hover, .fire-btn:active {
  background: var(--neon-magenta);
}

.beam-btn {
  background: rgba(255, 230, 0, 0.2);
  border-color: var(--neon-yellow);
  font-size: 0.75rem;
}

/* Footer Credit */
.app-footer {
  position: absolute;
  bottom: 0.4rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  color: #94a3b8;
  letter-spacing: 1px;
  z-index: 30;
  text-align: center;
  pointer-events: auto;
  font-family: var(--font-main);
}

.aprox-link {
  color: var(--neon-cyan);
  text-decoration: none;
  font-weight: 700;
  transition: all 0.2s ease;
  text-shadow: 0 0 6px rgba(0, 240, 255, 0.6);
}

.aprox-link:hover {
  color: var(--neon-green);
  text-shadow: 0 0 12px var(--neon-green);
  text-decoration: underline;
}

.embed-footer {
  bottom: 0.2rem;
  font-size: 0.72rem;
  background: rgba(5, 4, 15, 0.75);
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid rgba(0, 240, 255, 0.2);
}

.high-score-preview {
  margin-top: 1.2rem;
  font-size: 0.85rem;
  color: var(--neon-yellow);
  letter-spacing: 1px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

@media (max-width: 600px) {
  .game-title { font-size: 1.3rem; }
  .ufo-logo-anim { font-size: 2.5rem; }
  .controls-guide { grid-template-columns: 1fr; }
  .hud-value { font-size: 0.9rem; }
  .glass-panel { padding: 1.2rem; }
}
