/* Galactic Breakout DELUXE - Styles */

/* CSS Variables */
:root {
  --bg: #0b1020;
  --panel: #0f172a;
  --panel-2: #0b1320;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #38bdf8;
  --good: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  --sai-top: env(safe-area-inset-top, 0px);
  --sai-right: env(safe-area-inset-right, 0px);
  --sai-bottom: env(safe-area-inset-bottom, 0px);
  --sai-left: env(safe-area-inset-left, 0px);
}

/* Reset & Base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Poppins', system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, #0b1020, #0f172a 55%, #0a0f1f);
}

/* Container */
#gameContainer {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 10% -10%, #1f2937 0%, transparent 60%),
              radial-gradient(1000px 500px at 110% 10%, #0b1320 0%, transparent 60%),
              linear-gradient(160deg, #0b1020, #0f172a 55%, #0a0f1f);
}

/* Canvas */
#gameCanvas {
  display: block;
  background: transparent;
  box-shadow: var(--shadow);
  border-radius: 8px;
}

/* Disable pointer events on game container when overlay is visible */
#overlay[style*="display: flex"] ~ #gameContainer,
#overlay[style*="display: flex"] ~ #gameContainer * {
  pointer-events: none;
}

/* HUD */
.hud {
  position: fixed;
  top: 0;
  top: max(0px, var(--sai-top));
  left: 0;
  right: 0;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(0px, var(--sai-top)) max(20px, var(--sai-right)) 0 max(20px, var(--sai-left));
  background: rgba(10, 15, 31, 0.7);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 100;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
}

.hud-label {
  color: var(--muted);
  font-size: 14px;
}

.hud-value {
  color: var(--accent);
}

/* Mute Button */
.mute-btn {
  background: rgba(56, 189, 248, 0.15);
  border: 2px solid rgba(56, 189, 248, 0.4);
  color: var(--accent);
  font-size: 20px;
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.mute-btn:hover {
  background: rgba(56, 189, 248, 0.25);
  border-color: var(--accent);
  transform: scale(1.05);
}

.mute-btn:active {
  transform: scale(0.95);
}

/* Active Power-ups Display */
#activePowerups {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  z-index: 100;
}

.powerup-badge {
  position: relative;
  width: 50px;
  height: 50px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.powerup-timer {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.8);
  transition: width 0.1s linear;
}

/* Overlay */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

/* Menu */
.menu, .mode-select, .pause-menu, .gameover, .achievements, .settings, .stats-view {
  position: relative;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 40px;
  box-shadow: var(--shadow), 0 0 40px rgba(56, 189, 248, 0.15);
  text-align: center;
  max-width: 600px;
  width: 100%;
  overflow: hidden;
}

/* Menu animated corner decorations */
.menu::before, .menu::after,
.mode-select::before, .mode-select::after {
  content: '';
  position: absolute;
  width: 60px;
  height: 60px;
  border: 3px solid var(--accent);
  pointer-events: none;
  animation: pulse-border 2s ease-in-out infinite;
}

.menu::before {
  top: 10px;
  left: 10px;
  border-right: none;
  border-bottom: none;
  border-top-left-radius: 12px;
}

.menu::after {
  bottom: 10px;
  right: 10px;
  border-left: none;
  border-top: none;
  border-bottom-right-radius: 12px;
}

.mode-select::before {
  top: 10px;
  right: 10px;
  border-left: none;
  border-bottom: none;
  border-top-right-radius: 12px;
}

.mode-select::after {
  bottom: 10px;
  left: 10px;
  border-right: none;
  border-top: none;
  border-bottom-left-radius: 12px;
}

@keyframes pulse-border {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* Animated scanline overlay on menus (BUG FIX: moved from ::after to separate element) */
.scanline-overlay {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(56, 189, 248, 0.03) 0px,
    rgba(56, 189, 248, 0.03) 1px,
    transparent 1px,
    transparent 2px
  );
  pointer-events: none;
  z-index: 0;
  animation: scanlines 8s linear infinite;
}

@keyframes scanlines {
  0% { transform: translateY(0); }
  100% { transform: translateY(20px); }
}

.menu h1 {
  position: relative;
  font-size: 48px;
  margin-bottom: 10px;
  background: linear-gradient(135deg, var(--accent), #0ea5e9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 0 30px rgba(56, 189, 248, 0.5);
  animation: title-glow 3s ease-in-out infinite;
}

@keyframes title-glow {
  0%, 100% { filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.5)); }
  50% { filter: drop-shadow(0 0 20px rgba(56, 189, 248, 0.8)); }
}

/* Menu particle canvas background */
.menu-particles {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.6;
  z-index: 0;
}

.menu h1,
.menu .subtitle,
.menu .menu-buttons,
.menu .high-score {
  position: relative;
  z-index: 1;
}

.subtitle {
  color: var(--muted);
  margin-bottom: 30px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 20px 0;
}

.btn {
  position: relative;
  padding: 14px 24px;
  border: 2px solid rgba(56, 189, 248, 0.3);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.1), rgba(56, 189, 248, 0.05));
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.1),
              inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Animated shine effect on buttons */
.btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: left 0.5s;
}

.btn:hover::before {
  left: 100%;
}

.btn:hover {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.2), rgba(56, 189, 248, 0.1));
  transform: translateY(-3px);
  box-shadow: 0 0 30px rgba(56, 189, 248, 0.4),
              0 5px 15px rgba(0, 0, 0, 0.3),
              inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn:active {
  transform: translateY(-1px);
  box-shadow: 0 0 15px rgba(56, 189, 248, 0.3);
}

.btn.primary {
  background: linear-gradient(180deg, #22c55e, #16a34a);
  border: 2px solid #22c55e;
  color: #fff;
  box-shadow: 0 0 30px rgba(34, 197, 94, 0.3),
              0 5px 15px rgba(0, 0, 0, 0.3),
              inset 0 1px 0 rgba(255, 255, 255, 0.2);
  animation: primary-pulse 2s ease-in-out infinite;
}

@keyframes primary-pulse {
  0%, 100% {
    box-shadow: 0 0 30px rgba(34, 197, 94, 0.3),
                0 5px 15px rgba(0, 0, 0, 0.3),
                inset 0 1px 0 rgba(255, 255, 255, 0.2);
  }
  50% {
    box-shadow: 0 0 40px rgba(34, 197, 94, 0.5),
                0 5px 20px rgba(0, 0, 0, 0.4),
                inset 0 1px 0 rgba(255, 255, 255, 0.3);
  }
}

.btn.primary:hover {
  background: linear-gradient(180deg, #26d362, #18b550);
  border-color: #26d362;
  box-shadow: 0 0 50px rgba(34, 197, 94, 0.6),
              0 7px 20px rgba(0, 0, 0, 0.4),
              inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  animation: none;
}

/* Mode Selection */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin: 20px 0;
}

.mode-card {
  position: relative;
  padding: 20px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 2px solid rgba(56, 189, 248, 0.2);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2),
              inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* Animated corner indicators on mode cards */
.mode-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 20px;
  height: 20px;
  border-top: 3px solid var(--accent);
  border-left: 3px solid var(--accent);
  border-top-left-radius: 12px;
  opacity: 0;
  transition: opacity 0.3s;
}

.mode-card::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 20px;
  height: 20px;
  border-bottom: 3px solid var(--accent);
  border-right: 3px solid var(--accent);
  border-bottom-right-radius: 12px;
  opacity: 0;
  transition: opacity 0.3s;
}

.mode-card:hover::before,
.mode-card:hover::after {
  opacity: 1;
}

.mode-card:hover {
  border-color: var(--accent);
  transform: translateY(-6px) scale(1.02);
  box-shadow: 0 12px 30px rgba(56, 189, 248, 0.3),
              0 0 40px rgba(56, 189, 248, 0.2),
              inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.mode-card:active {
  transform: translateY(-4px) scale(1.01);
}

.mode-card h3 {
  position: relative;
  margin-bottom: 8px;
  color: var(--accent);
  text-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
  transition: all 0.3s;
}

.mode-card:hover h3 {
  text-shadow: 0 0 15px rgba(56, 189, 248, 0.8);
  transform: scale(1.05);
}

.mode-card p {
  font-size: 14px;
  color: var(--muted);
  transition: color 0.3s;
}

.mode-card:hover p {
  color: var(--text);
}

/* Shop */
.shop-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.coin-display {
  font-size: 24px;
  font-weight: 700;
  color: var(--warn);
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin: 20px 0;
  max-height: 400px;
  overflow-y: auto;
}

.shop-card {
  padding: 16px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  transition: all 0.2s;
}

.shop-card.owned {
  border-color: var(--good);
  opacity: 0.7;
}

.shop-card.locked {
  opacity: 0.5;
}

.shop-card h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

.shop-card p {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}

.owned-badge {
  color: var(--good);
  font-weight: 600;
}

/* Achievements */
.achievement-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 20px 0;
  max-height: 400px;
  overflow-y: auto;
}

.achievement-card {
  padding: 16px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  text-align: center;
}

.achievement-card.unlocked {
  border-color: var(--good);
}

.achievement-card.locked {
  opacity: 0.5;
}

.achievement-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.achievement-card h3 {
  font-size: 14px;
  margin-bottom: 4px;
}

.achievement-card p {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.achievement-reward {
  font-size: 12px;
  color: var(--warn);
  font-weight: 600;
}

/* Achievement Notification */
.achievement-notification {
  position: fixed;
  top: 80px;
  right: -400px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 2px solid var(--good);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 12px;
  align-items: center;
  z-index: 300;
  transition: right 0.5s ease;
}

.achievement-notification.show {
  right: 20px;
}

.achievement-title {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
}

.achievement-name {
  font-size: 16px;
  font-weight: 600;
  margin-top: 4px;
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin: 20px 0;
}

.stat, .stat-card {
  padding: 16px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  text-align: center;
}

.stat-label {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin: 20px 0;
}

.high-score {
  margin-top: 20px;
  font-size: 18px;
  color: var(--warn);
}

/* Settings */
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin: 20px 0;
  text-align: left;
}

.setting {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting label {
  font-size: 14px;
  color: var(--muted);
}

.setting input[type="range"] {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  outline: none;
}

.setting select {
  padding: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}

/* Home Button */
.homeBtn {
  position: fixed;
  top: max(20px, var(--sai-top));
  left: max(20px, var(--sai-left));
  padding: 10px 16px;
  min-height: 44px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}

.homeBtn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-2px);
}

/* Mobile Breakpoints */
@media (max-width: 768px) {
  .hud {
    padding: max(0px, var(--sai-top)) max(12px, var(--sai-right)) 0 max(12px, var(--sai-left));
    height: 54px;
  }
  .hud-label { font-size: 11px; }
  .hud-value { font-size: 14px; }
  input, select, textarea { font-size: 16px !important; }
}

@media (max-width: 414px) {
  .hud {
    flex-wrap: wrap;
    height: auto;
    padding-bottom: 6px;
  }
  .hud-item { min-width: 60px; }
  #activePowerups { font-size: 13px; right: max(8px, var(--sai-right)); }
}

@media (max-width: 375px) {
  .hud-label { font-size: 10px; }
  .hud-value { font-size: 13px; }
  .homeBtn { padding: 8px 12px; font-size: 13px; }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  button, .btn, .homeBtn, .mute-btn { min-height: 48px; min-width: 48px; }
  #touchHelper { bottom: max(20px, var(--sai-bottom)); }
}

/* Animations */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

@keyframes glow {
  0%, 100% {
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
  }
  50% {
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.8);
  }
}

/* Responsive */
@media (max-width: 900px) {
  .mode-grid, .shop-grid {
    grid-template-columns: 1fr;
  }

  .achievement-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .hud {
    font-size: 14px;
    padding: 0 10px;
    height: 50px;
  }

  .hud-item {
    font-size: 13px;
    gap: 4px;
  }

  .hud-label {
    font-size: 11px;
  }

  #activePowerups {
    bottom: 70px;
    gap: 6px;
  }

  .powerup-badge {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
}

@media (max-width: 600px) {
  .achievement-grid {
    grid-template-columns: 1fr;
  }

  .menu, .mode-select, .pause-menu, .gameover, .achievements, .settings, .stats-view {
    padding: 20px;
    max-width: 95%;
  }

  .menu h1 {
    font-size: 32px;
  }

  .btn {
    padding: 16px 20px;
    font-size: 16px;
    min-height: 48px;
  }

  .mode-card {
    padding: 16px;
    min-height: 100px;
  }

  .shop-card {
    padding: 12px;
  }

  .hud {
    flex-wrap: wrap;
    height: auto;
    padding: 8px;
    gap: 4px;
  }

  .hud-item {
    font-size: 12px;
  }

  .homeBtn {
    padding: 8px 12px;
    font-size: 13px;
    top: 10px;
    left: 10px;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
  .btn {
    min-height: 48px;
    padding: 16px 20px;
  }

  .mode-card, .shop-card, .achievement-card {
    min-height: 80px;
  }

  input[type="range"] {
    height: 30px;
  }

  select {
    min-height: 44px;
    font-size: 16px;
  }
}

/* Prefers Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
