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

:root {
  --accent-color:  #f43f5e;
  --accent-glow:   rgba(244,63,94,0.6);
  --warning-color: #fbbf24;
  --text-primary:  #f8fafc;
  --text-secondary:#cbd5e1;
  --glass-bg:      rgba(30,41,59,0.3);
  --glass-border:  rgba(255,255,255,0.1);
}

@keyframes gradientShift {
  0%,100% { background-position: 0% 50%; }
  50%     { background-position: 100% 50%; }
}
@keyframes pulseGlow {
  0%,100% { box-shadow: 0 0 20px var(--accent-glow); }
  50%     { box-shadow: 0 0 40px var(--accent-glow), 0 0 60px var(--accent-glow); }
}
@keyframes float {
  0%,100% { transform: translateY(0px); }
  50%     { transform: translateY(-10px); }
}
@keyframes slideUp {
  from { opacity:0; transform:translateY(30px); }
  to   { opacity:1; transform:translateY(0); }
}
@keyframes scaleIn {
  from { opacity:0; transform:scale(0.8); }
  to   { opacity:1; transform:scale(1); }
}
@keyframes fadeIn {
  from { opacity:0; }
  to   { opacity:1; }
}
@keyframes progressShine {
  to { left:100%; }
}
@keyframes cardPop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}

body {
  font-family: "Nunito", sans-serif;
  background: linear-gradient(135deg,#0a0e1a 0%,#1e1b4b 25%,#312e81 50%,#1e1b4b 75%,#0a0e1a 100%);
  background-size: 400% 400%;
  animation: gradientShift 15s ease infinite;
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(244,63,94,0.1) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

#gameContainer {
  width: 100%;
  max-width: 1000px;
  text-align: center;
  padding: 20px;
  position: relative;
  z-index: 1;
  animation: slideUp 0.6s ease-out;
}

h1 {
  font-family: "Righteous", cursive;
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  background: linear-gradient(135deg,#f43f5e,#ec4899,#a855f7,#ec4899,#f43f5e);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 1.5rem;
  animation: gradientShift 4s ease infinite, float 3s ease-in-out infinite;
  filter: drop-shadow(0 0 30px rgba(244,63,94,0.5));
  letter-spacing: 2px;
}

.hud {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: 0 10px;
  animation: slideUp 0.6s ease-out 0.1s both;
}

.stat {
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(180%);
  padding: 1rem 1.8rem;
  border-radius: 16px;
  border: 1px solid var(--glass-border);
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  transition: all 0.3s cubic-bezier(0.4,0,0.2,1);
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg,transparent,rgba(255,255,255,0.1),transparent);
  transition: left 0.5s;
}
.stat:hover::before { left: 100%; }
.stat:hover {
  transform: translateY(-2px);
  border-color: rgba(255,255,255,0.2);
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}
.stat span {
  color: var(--warning-color);
  font-size: 1.5rem;
  font-weight: 900;
  text-shadow: 0 0 10px rgba(251,191,36,0.5);
}

#waveProgress {
  transition: width 0.5s cubic-bezier(0.4,0,0.2,1);
  box-shadow: 0 0 20px rgba(74,222,128,0.6), inset 0 1px 3px rgba(255,255,255,0.3);
  position: relative;
  overflow: hidden;
}
#waveProgress::after {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg,transparent,rgba(255,255,255,0.3),transparent);
  animation: progressShine 2s infinite;
}

canvas {
  width: 100%;
  max-width: 900px;
  height: 500px;
  background: linear-gradient(180deg,#87ceeb 0%,#e0f2f7 60%,#f0e68c 100%);
  border-radius: 24px;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.8),
              0 0 0 1px rgba(255,255,255,0.1),
              inset 0 2px 4px rgba(255,255,255,0.1);
  cursor: crosshair;
  display: block;
  margin: 20px auto;
  border: 3px solid rgba(255,255,255,0.15);
  touch-action: none;
  animation: scaleIn 0.6s ease-out 0.2s both;
  transition: transform 0.3s ease;
}
canvas:hover { transform: scale(1.01); }

button[data-proj] {
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(180%);
  color: var(--text-primary);
  border: 2px solid var(--glass-border);
  padding: 1rem 1.5rem;
  border-radius: 16px;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: "Nunito", sans-serif;
  transition: all 0.3s cubic-bezier(0.4,0,0.2,1);
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  position: relative;
  overflow: hidden;
}
button[data-proj].projectile-active {
  background: linear-gradient(135deg,var(--accent-color),#ec4899);
  border-color: var(--accent-color);
  box-shadow: 0 0 30px var(--accent-glow), 0 15px 40px rgba(244,63,94,0.5);
  animation: pulseGlow 2s ease-in-out infinite;
}
button[data-proj]:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
  filter: grayscale(80%);
}

.proj-grid {
  display: grid;
  grid-template-columns: repeat(4,1fr);
  gap: 10px;
}

.proj-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 1rem 0.75rem;
  background: var(--glass-bg);
  border: 2px solid var(--glass-border);
  border-radius: 16px;
  cursor: pointer;
  color: var(--text-primary);
  font-family: "Nunito", sans-serif;
  transition: all 0.25s cubic-bezier(0.4,0,0.2,1);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  position: relative;
  overflow: hidden;
}
.proj-card::before {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 0; height: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  transform: translate(-50%,-50%);
  transition: width 0.5s, height 0.5s;
}
.proj-card:hover::before { width: 250px; height: 250px; }
.proj-card:hover {
  transform: translateY(-4px) scale(1.04);
  border-color: rgba(244,63,94,0.5);
  box-shadow: 0 12px 32px rgba(244,63,94,0.3);
}
.proj-card.selected {
  background: linear-gradient(135deg,var(--accent-color),#ec4899);
  border-color: var(--accent-color);
  box-shadow: 0 0 28px var(--accent-glow), 0 12px 32px rgba(244,63,94,0.5);
  animation: pulseGlow 2s ease-in-out infinite, cardPop 0.3s ease-out;
}
.proj-emoji { font-size: 2rem; line-height: 1; }
.proj-name  { font-weight: 800; font-size: 0.85rem; }
.proj-desc  { font-size: 0.7rem; opacity: 0.75; font-weight: 600; }

.btn {
  background: linear-gradient(135deg,var(--accent-color),#ec4899);
  color: white;
  border: none;
  padding: 1.2rem 3rem;
  font-size: 1.3rem;
  font-weight: 800;
  border-radius: 16px;
  cursor: pointer;
  margin: 10px;
  transition: all 0.3s cubic-bezier(0.4,0,0.2,1);
  box-shadow: 0 10px 30px rgba(244,63,94,0.4);
  position: relative;
  overflow: hidden;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-family: "Nunito", sans-serif;
}
.btn::before {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 0; height: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  transform: translate(-50%,-50%);
  transition: width 0.6s, height 0.6s;
}
.btn:hover:not(:disabled)::before { width: 400px; height: 400px; }
.btn:hover:not(:disabled) {
  transform: translateY(-5px) scale(1.05);
  box-shadow: 0 20px 50px rgba(244,63,94,0.6);
}
.btn:active:not(:disabled) { transform: translateY(-2px) scale(1.02); }
.btn:disabled,
.start-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none !important;
  filter: grayscale(60%);
  box-shadow: none;
  pointer-events: none;
}

#startScreen,
#gameOverScreen,
#upgradeScreen {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.4s ease-out;
}

.screen-content {
  background: var(--glass-bg);
  backdrop-filter: blur(40px) saturate(180%);
  padding: 3rem;
  border-radius: 24px;
  max-width: 640px;
  width: 90%;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.8),
              0 0 0 1px rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.1);
  animation: scaleIn 0.5s cubic-bezier(0.4,0,0.2,1);
}
.screen-content h2  { animation: slideUp 0.6s ease-out 0.2s both; }
.screen-content p   { animation: slideUp 0.6s ease-out 0.3s both; }
.screen-content div { animation: slideUp 0.6s ease-out 0.4s both; }

.hidden { display: none !important; }

@media (max-width: 760px) {
  canvas { height: 400px; }
  .screen-content { padding: 2rem; margin: 20px; }
  .hud { justify-content: center; }
  .proj-grid { grid-template-columns: repeat(2,1fr); }
  button[data-proj] { padding: 0.8rem 1rem; font-size: 0.95rem; }
}