:root {
  --bg: #0f172a;
  --surface: rgba(15, 23, 42, 0.9);
  --surface-solid: #1e293b;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --accent: #f59e0b;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: rgba(148, 163, 184, 0.2);
  --radius: 20px;
  --shadow: 0 25px 50px rgba(3, 7, 18, 0.6);
  --glow: 0 0 30px rgba(59, 130, 246, 0.3);
}

[data-theme="light"] {
  --bg: #f8fafc;
  --surface: rgba(255, 255, 255, 0.95);
  --surface-solid: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --primary: #2563eb;
  --accent: #f59e0b;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --border: rgba(15, 23, 42, 0.15);
  --shadow: 0 20px 40px rgba(15, 23, 42, 0.15);
  --glow: 0 0 25px rgba(37, 99, 235, 0.2);
}

* { 
  box-sizing: border-box; 
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  background: 
    radial-gradient(circle at 20% 20%, rgba(59, 130, 246, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(245, 158, 11, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 40% 40%, rgba(139, 92, 246, 0.05) 0%, transparent 50%),
    linear-gradient(135deg, var(--bg) 0%, #020617 100%);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

button:focus-visible,
.game-button:focus-visible,
.mobile-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px;
}

.header {
  text-align: center;
  margin-bottom: 40px;
}

.title {
  font-size: clamp(2.5rem, 5vw, 4rem);
  margin: 0 0 16px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 50%, var(--primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
  line-height: 1.1;
  filter: drop-shadow(0 4px 12px rgba(59, 130, 246, 0.3));
}

.subtitle {
  color: var(--muted);
  margin: 0;
  font-size: 1.2rem;
  font-weight: 500;
}

.game-interface {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 32px;
  align-items: start;
}

.game-stats {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 32px;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(148, 163, 184, 0.1);
  border-radius: 16px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.stat-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(3, 7, 18, 0.4);
}

.stat-label {
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.game-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  overflow: hidden;
  position: relative;
}

.game-area::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--primary), var(--accent), var(--primary));
  opacity: 0.8;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: calc(var(--radius) - 1px);
}

.info-panels {
  margin-top: 28px;
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.info-card h3 {
  margin-top: 0;
  margin-bottom: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.info-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  display: grid;
  gap: 8px;
}

.controls {
  margin-top: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.game-button {
  padding: 16px 32px;
  border: none;
  border-radius: 16px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  min-width: 140px;
}

.game-button--primary {
  background: linear-gradient(135deg, var(--primary) 0%, #1d4ed8 100%);
  color: white;
  box-shadow: 
    0 8px 25px rgba(59, 130, 246, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.game-button--primary:hover {
  transform: translateY(-3px);
  box-shadow: 
    0 12px 35px rgba(59, 130, 246, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.game-button--secondary {
  background: rgba(148, 163, 184, 0.1);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.3);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.game-button--secondary:hover {
  background: rgba(148, 163, 184, 0.2);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.game-button--accent {
  background: linear-gradient(135deg, var(--accent) 0%, #d97706 100%);
  color: white;
  box-shadow: 
    0 8px 25px rgba(245, 158, 11, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.game-button--accent:hover {
  transform: translateY(-3px);
  box-shadow: 
    0 12px 35px rgba(245, 158, 11, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.game-button:active {
  transform: translateY(-1px);
}

.game-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.mobile-controls {
  display: none;
  margin-top: 20px;
  gap: 12px;
  justify-content: center;
}

.mobile-btn {
  padding: 20px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: var(--shadow);
  width: 60px;
  height: 60px;
}

.mobile-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 25px rgba(3, 7, 18, 0.4);
}

.theme-toggle {
  position: fixed;
  top: 24px;
  right: 24px;
  width: 50px;
  height: 50px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  z-index: 1001;
}

.theme-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 30px rgba(3, 7, 18, 0.5);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
  display: grid;
  place-items: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 40px;
  text-align: center;
  max-width: 500px;
  margin: 0 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
  position: relative;
  overflow: hidden;
}

.overlay-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent), var(--primary));
}

.overlay-title {
  margin: 0 0 20px;
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.overlay-message {
  margin: 0 0 32px;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1.6;
}

.instructions-box {
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 0 0 24px;
  text-align: left;
}

.instructions-box p {
  margin: 8px 0;
  font-size: 0.95rem;
  color: var(--text);
}

.instructions-box p:first-child {
  margin-top: 0;
}

.instructions-box p:last-child {
  margin-bottom: 0;
}

.overlay .controls {
  margin-top: 0;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.slide-up {
  animation: slideUp 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.pulse {
  animation: pulse 2s infinite;
}

/* Responsive Design */
@media (max-width: 1024px) {
  .game-interface {
    grid-template-columns: 1fr;
    gap: 24px;
  }
  
  .game-stats {
    position: static;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 20px;
  }
  
  .title {
    font-size: clamp(2rem, 8vw, 3rem);
  }
  
  .game-stats {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    padding: 20px;
  }
  
  .stat-item {
    flex-direction: column;
    text-align: center;
    padding: 12px 16px;
  }
  
  .stat-value {
    font-size: 1.5rem;
  }
  
  .controls {
    flex-direction: column;
    align-items: center;
  }
  
  .game-button {
    width: 100%;
    max-width: 280px;
  }
  
  .mobile-controls {
    display: flex;
  }
  
  .overlay-content {
    padding: 36px 28px;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 16px;
  }
  
  .game-stats {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 16px;
  }
  
  .stat-item {
    padding: 10px 12px;
  }
  
  .stat-value {
    font-size: 1.3rem;
  }
  
  .overlay-title {
    font-size: 2rem;
  }
  
  .overlay-message {
    font-size: 1.1rem;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --border: rgba(148, 163, 184, 0.5);
    --surface: rgba(15, 23, 42, 0.95);
  }
  
  .game-button {
    border: 2px solid var(--border);
  }
}

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

.stat-item {
  text-align: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 12px;
  padding: 12px;
}

.stat-label {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stat-value {
  font-weight: 800;
  font-size: 1.32rem;
}

.game-container {
  position: relative;
}

#gameCanvas {
  width: 100%;
  height: auto;
  max-height: 70vh;
  background: transparent;
  border-radius: var(--radius);
  border: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: var(--shadow);
  display: block;
}

.game-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.overlay-content {
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: var(--radius);
  padding: 24px 28px;
  text-align: center;
  box-shadow: var(--shadow);
}

.game-button {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  margin: 6px;
  cursor: pointer;
  color: #fff;
  font-family: 'Press Start 2P', 'Inter', sans-serif;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
}

.game-button.primary { background: var(--primary); }
.game-button.secondary { background: var(--accent); }
.hidden { display: none; }

.game-controls,
.game-tips {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.game-controls h3,
.game-tips h3 {
  font-family: 'Press Start 2P', 'Inter', sans-serif;
  letter-spacing: 0.08em;
  margin-top: 0;
}

.control-list,
.powerup-list {
  display: grid;
  gap: 10px;
}

.control-item,
.powerup-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.control-key {
  background: rgba(148, 163, 184, 0.15);
  border: 1px solid rgba(148, 163, 184, 0.3);
  padding: 2px 8px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
}

.powerup-icon {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: var(--muted);
}

.powerup-icon.expand { background: var(--success); }
.powerup-icon.speed { background: var(--warning); }
.powerup-icon.multi { background: var(--primary); }
.powerup-icon.laser { background: var(--danger); }

.mobile-controls {
  display: none;
  gap: 12px;
  margin-top: 16px;
  align-items: center;
  justify-content: center;
}

.mobile-instructions { color: var(--muted); }

.mobile-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 14px;
  border-radius: 12px;
  font-family: 'Press Start 2P', 'Inter', sans-serif;
  letter-spacing: 0.08em;
}

.game-tips ul {
  margin: 0;
  padding-left: 20px;
}

.theme-toggle {
  position: fixed;
  right: 16px;
  bottom: 16px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 12px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

@media (max-width: 960px) {
  .game-interface {
    grid-template-columns: 1fr;
  }

  #gameCanvas {
    max-height: none;
    height: auto;
  }

  .mobile-controls {
    display: flex;
  }
}
