@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

:root {
  color-scheme: dark;
  --font-pixel: 'Press Start 2P', 'Courier New', monospace;
  --font-body: system-ui, -apple-system, sans-serif;
  
  --bg-dark: #0a0a1a;
  --bg-gradient: linear-gradient(135deg, #0a0a1a 0%, #1a1a3a 50%, #0a0a1a 100%);
  --panel: rgba(20, 20, 50, 0.9);
  --panel-border: #4a4a8a;
  --panel-glow: rgba(100, 100, 255, 0.3);
  
  --accent: #00ffaa;
  --accent-glow: rgba(0, 255, 170, 0.5);
  --accent-strong: #ff4466;
  --accent-warn: #ffaa00;
  
  --text-primary: #f0f0ff;
  --text-muted: #8888aa;
  
  --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px var(--panel-glow);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  touch-action: none;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: var(--font-body);
  padding: 0.5rem;
}

/* Animated background grid */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: 
    linear-gradient(rgba(100, 100, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(100, 100, 255, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  animation: gridMove 20s linear infinite;
}

@keyframes gridMove {
  0% { transform: translate(0, 0); }
  100% { transform: translate(40px, 40px); }
}

.page-shell {
  width: 100%;
  max-width: 600px;
  height: 100%;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--shadow-soft), var(--shadow-glow);
  backdrop-filter: blur(10px);
}

/* HUD - Score, Level, Lives */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
}

.stat-group {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.stat-label {
  font-family: var(--font-pixel);
  font-size: 0.5rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.stat-value {
  font-family: var(--font-pixel);
  font-size: 0.9rem;
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent-glow);
}

.lives-display {
  display: flex;
  gap: 0.2rem;
}

.heart {
  color: var(--accent-strong);
  text-shadow: 0 0 8px rgba(255, 68, 102, 0.6);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.heart.lost {
  opacity: 0.2;
  transform: scale(0.8);
}

.btn-group {
  display: flex;
  gap: 0.5rem;
}

.primary-btn, .secondary-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  font-family: var(--font-pixel);
  font-size: 0.55rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.primary-btn {
  background: linear-gradient(135deg, #00cc88, #00ffaa);
  color: #0a0a1a;
  box-shadow: 0 4px 0 #009966, 0 0 20px var(--accent-glow);
}

.primary-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #009966, 0 0 30px var(--accent-glow);
}

.primary-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #009966, 0 0 15px var(--accent-glow);
}

.secondary-btn {
  background: rgba(100, 100, 150, 0.3);
  color: var(--text-primary);
  border: 1px solid var(--panel-border);
}

.secondary-btn:hover:not(:disabled) {
  background: rgba(100, 100, 150, 0.5);
}

.primary-btn:disabled, .secondary-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.large-btn {
  padding: 0.8rem 1.5rem;
  font-size: 0.7rem;
}

.btn-icon {
  font-size: 0.8em;
}

/* Game Frame */
#game-frame {
  position: relative;
  flex: 1;
  min-height: 0;
  border: 3px solid var(--panel-border);
  border-radius: 12px;
  background: #000;
  box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.8), var(--shadow-glow);
  overflow: hidden;
}

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

/* Overlay */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 26, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.3s ease;
  z-index: 10;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-content {
  text-align: center;
  padding: 2rem;
  max-width: 90%;
}

.overlay h2 {
  font-family: var(--font-pixel);
  font-size: clamp(1rem, 4vw, 1.5rem);
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
  margin-bottom: 1rem;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.overlay p {
  font-size: clamp(0.8rem, 2.5vw, 1rem);
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.overlay-controls {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}

.control-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.key {
  display: inline-block;
  padding: 0.3rem 0.5rem;
  background: rgba(100, 100, 150, 0.3);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  font-family: var(--font-pixel);
  font-size: 0.55rem;
  color: var(--text-primary);
}

.mobile-hint {
  display: none;
}

@media (pointer: coarse) {
  .mobile-hint {
    display: flex;
  }
}

/* Instructions Footer */
.instructions {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0.5rem;
}

.instructions strong {
  color: var(--accent);
}

/* Responsive Adjustments */
@media (max-width: 480px) {
  .page-shell {
    padding: 0.5rem;
    border-radius: 12px;
  }

  .hud {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
  }

  .stat-group {
    justify-content: space-around;
  }

  .btn-group {
    justify-content: center;
  }

  .primary-btn, .secondary-btn {
    flex: 1;
    justify-content: center;
  }

  .instructions {
    font-size: 0.65rem;
  }
}

@media (max-height: 600px) {
  .page-shell {
    gap: 0.3rem;
  }

  .hud {
    padding: 0.4rem 0.6rem;
  }

  .instructions {
    display: none;
  }
}

/* Landscape phone */
@media (max-height: 500px) and (orientation: landscape) {
  .page-shell {
    flex-direction: row;
    flex-wrap: wrap;
    max-width: 100%;
  }

  .hud {
    width: 100%;
    flex-direction: row;
  }

  #game-frame {
    flex: 1;
    min-width: 0;
  }

  .instructions {
    display: none;
  }
}

/* Win/Lose specific styles */
.overlay h2.win {
  color: var(--accent);
}

.overlay h2.lose {
  color: var(--accent-strong);
}

/* Particle effect container */
.particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

/* Achievement Notification */
.achievement-notification {
  position: absolute;
  top: 10%;
  right: 20px;
  z-index: 15;
  pointer-events: none;
  transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55), opacity 0.5s ease;
}

.achievement-notification.hidden {
  opacity: 0;
  transform: translateX(400px);
}

.achievement-content {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.95), rgba(255, 200, 0, 0.95));
  border: 2px solid #ffd700;
  border-radius: 12px;
  box-shadow: 0 0 30px rgba(255, 215, 0, 0.6), 0 4px 20px rgba(0, 0, 0, 0.4);
  min-width: 280px;
}

.achievement-icon {
  font-size: 2rem;
  animation: achievementPulse 1s ease-in-out infinite;
}

@keyframes achievementPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2) rotate(10deg); }
}

.achievement-info {
  flex: 1;
}

.achievement-title {
  font-family: var(--font-pixel);
  font-size: 0.7rem;
  color: #0a0a1a;
  font-weight: bold;
  margin-bottom: 0.3rem;
}

.achievement-desc {
  font-size: 0.65rem;
  color: #333;
  line-height: 1.3;
}

/* Boss Health Bar */
.boss-health-bar {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: 80%;
  max-width: 400px;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.8);
  border: 2px solid #ff0000;
  border-radius: 8px;
  transition: opacity 0.3s ease;
}

.boss-health-bar.hidden {
  opacity: 0;
  pointer-events: none;
}

.boss-label {
  font-family: var(--font-pixel);
  font-size: 0.6rem;
  color: #ff0000;
  text-align: center;
  margin-bottom: 0.3rem;
  text-shadow: 0 0 10px #ff0000;
}

.health-bar-container {
  width: 100%;
  height: 20px;
  background: rgba(50, 50, 50, 0.8);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #333;
}

.health-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff0000, #ff6666, #ff0000);
  width: 100%;
  transition: width 0.3s ease;
  box-shadow: 0 0 20px rgba(255, 0, 0, 0.6);
  animation: healthPulse 2s ease-in-out infinite;
}

@keyframes healthPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(5px);
  transition: opacity 0.3s ease;
}

.modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 16px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-soft), var(--shadow-glow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 2px solid var(--panel-border);
}

.modal-header h2 {
  font-family: var(--font-pixel);
  font-size: 1rem;
  color: var(--accent);
  margin: 0;
}

.close-btn {
  background: none;
  border: none;
  font-size: 2rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.close-btn:hover {
  color: var(--accent-strong);
}

.modal-body {
  padding: 1.5rem;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-item:last-child {
  border-bottom: none;
}

.stat-item .stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.stat-item .stat-value {
  font-family: var(--font-pixel);
  font-size: 0.9rem;
  color: var(--accent);
}

.achievements-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--panel-border);
}

.achievements-section h3 {
  font-family: var(--font-pixel);
  font-size: 0.8rem;
  color: var(--accent);
  margin-bottom: 1rem;
}

.achievements-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.8rem;
}

.achievement-badge {
  padding: 0.8rem;
  background: rgba(0, 255, 170, 0.1);
  border: 1px solid var(--accent);
  border-radius: 8px;
  text-align: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.achievement-badge.unlocked {
  background: rgba(0, 255, 170, 0.2);
  border-color: var(--accent);
  box-shadow: 0 0 15px rgba(0, 255, 170, 0.3);
}

.achievement-badge.locked {
  opacity: 0.4;
  filter: grayscale(1);
}

.achievement-badge-icon {
  font-size: 2rem;
  margin-bottom: 0.3rem;
}

.achievement-badge-name {
  font-family: var(--font-pixel);
  font-size: 0.5rem;
  color: var(--text-primary);
  line-height: 1.2;
}

/* Combo Display */
.combo-display {
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.combo-display.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(-20px);
}

.combo-text {
  font-family: var(--font-pixel);
  font-size: clamp(0.8rem, 3vw, 1.2rem);
  color: var(--accent-warn);
  text-shadow: 
    0 0 10px var(--accent-warn),
    0 0 20px var(--accent-warn),
    0 0 30px var(--accent-warn);
  animation: comboPulse 0.5s ease-out;
}

@keyframes comboPulse {
  0% { transform: scale(0.5); opacity: 0; }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

/* Power-up Display */
.powerup-display {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.powerup-display.hidden {
  opacity: 0;
}

.powerup-text {
  font-family: var(--font-pixel);
  font-size: clamp(0.7rem, 2.5vw, 1rem);
  color: var(--accent);
  text-shadow: 
    0 0 10px var(--accent-glow),
    0 0 20px var(--accent-glow);
  padding: 0.5rem 1rem;
  background: rgba(0, 255, 170, 0.2);
  border: 2px solid var(--accent);
  border-radius: 8px;
  animation: powerupSlide 0.5s ease-out;
}

@keyframes powerupSlide {
  0% { transform: translateY(-30px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}
