:root {
  --bg: #0f1220;
  --panel: #171a2c;
  --text: #e6e9f5;
  --accent: #6ac8ff;
  --accent-glow: rgba(106, 200, 255, 0.3);
  --muted: #8a90aa;
  --danger: #ff5d73;
  --success: #7cffb9;
  --warning: #ffd166;
  --purple: #a18bff;
  --pink: #ff9ce6;
}

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

html, body { 
  height: 100%; 
  overflow-x: hidden;
}

body {
  margin: 0;
  background: 
    radial-gradient(1400px 1000px at 70% -10%, #1d2142 0%, #0f1220 40%, #0b0e1a 100%) fixed,
    linear-gradient(45deg, rgba(29, 33, 66, 0.3) 0%, transparent 100%);
  color: var(--text);
  font: 14px/1.6 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 80%, rgba(106, 200, 255, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(161, 139, 255, 0.1) 0%, transparent 50%);
  pointer-events: none;
  z-index: -1;
}

/* Enhanced top navigation */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: linear-gradient(180deg, rgba(22, 26, 45, 0.95), rgba(15, 18, 32, 0.95));
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(46, 51, 90, 0.6);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 25px rgba(0, 0, 0, 0.4);
}

.brand {
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-shadow: 0 0 25px var(--accent-glow);
  font-size: 1.5em;
  position: relative;
}

.brand::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  border-radius: 2px;
}

.hud {
  display: flex;
  gap: 20px;
  align-items: center;
}

.hud span {
  color: var(--text);
  font-weight: 600;
  background: rgba(255, 255, 255, 0.08);
  padding: 8px 16px;
  border-radius: 25px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  min-width: 100px;
  text-align: center;
}

.hud span:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.actions .label {
  margin-right: 8px;
  color: var(--muted);
  font-size: 0.9em;
  font-weight: 500;
}

.actions select {
  background: rgba(15, 20, 36, 0.9);
  color: var(--text);
  border: 1px solid rgba(64, 78, 137, 0.7);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 0.95em;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  min-width: 100px;
}

.actions select:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(106, 200, 255, 0.3);
  transform: translateY(-1px);
}

.actions select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(106, 200, 255, 0.2);
}

.actions select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.actions button {
  background: var(--accent);
  color: #08111a;
  border: 0;
  border-radius: 12px;
  padding: 12px 20px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 0 #3aa0d6;
  transition: all 0.2s ease;
  font-size: 0.95em;
  position: relative;
  overflow: hidden;
}

.actions button::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 ease;
}

.actions button:hover::before {
  left: 100%;
}

.actions button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #3aa0d6;
}

.actions button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 0 #3aa0d6;
}

.actions button#soundBtn {
  background: var(--success);
  box-shadow: 0 4px 0 #35b67c;
  color: #0a291a;
}

.actions button#soundBtn:hover {
  box-shadow: 0 6px 0 #35b67c;
}

.actions button#soundBtn.muted {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 0 #d07886;
}

.actions button#soundBtn.muted:hover {
  box-shadow: 0 6px 0 #d07886;
}

.canvas-wrap {
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
}

.canvas-wrap::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-glow), transparent);
  border-radius: 1px;
}

canvas {
  max-width: min(92vw, 600px);
  max-height: 92vh;
  background: 
    radial-gradient(900px 700px at 50% 0%, #12162a 0%, #0c0f1e 70%),
    linear-gradient(180deg, rgba(29, 33, 66, 0.3) 0%, transparent 30%);
  border: 2px solid rgba(46, 51, 90, 0.8);
  border-radius: 20px;
  box-shadow: 
    0 15px 40px rgba(0, 0, 0, 0.5),
    inset 0 2px 4px rgba(255, 255, 255, 0.1);
}

.help {
  color: var(--muted);
  text-align: center;
  padding: 12px 20px 24px;
  font-size: 0.95em;
  background: rgba(255, 255, 255, 0.03);
  margin: 0 auto;
  max-width: 600px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.rules {
  max-width: min(92vw, 600px);
  margin: 0 auto 32px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(46, 51, 90, 0.6);
  border-radius: 16px;
  padding: 20px 24px;
  color: #d8deef;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
}

.rules h3 {
  margin: 8px 0 16px;
  font-size: 1.2em;
  color: var(--accent);
  text-align: center;
  font-weight: 700;
  text-shadow: 0 0 15px var(--accent-glow);
}

.rules ul {
  margin: 0;
  padding-left: 24px;
  list-style: none;
}

.rules li {
  margin: 12px 0;
  padding-left: 8px;
  border-left: 3px solid var(--accent);
  position: relative;
}

.rules li::before {
  content: '•';
  position: absolute;
  left: -12px;
  color: var(--accent);
  font-size: 1.2em;
}

.rules strong {
  color: var(--accent);
  font-weight: 600;
}

/* Game over modal styles */
.game-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.game-modal.visible {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: linear-gradient(135deg, #1a1f38, #13172b);
  border: 2px solid rgba(106, 200, 255, 0.3);
  border-radius: 20px;
  padding: 32px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 
    0 20px 60px rgba(0, 0, 0, 0.6),
    inset 0 2px 8px rgba(255, 255, 255, 0.1);
  transform: scale(0.9);
  transition: transform 0.3s ease;
}

.game-modal.visible .modal-content {
  transform: scale(1);
}

.modal-title {
  font-size: 2em;
  font-weight: 800;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-message {
  font-size: 1.1em;
  margin-bottom: 24px;
  color: var(--muted);
}

.modal-button {
  background: var(--accent);
  color: #08111a;
  border: none;
  border-radius: 12px;
  padding: 12px 32px;
  font-size: 1.1em;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 0 #3aa0d6;
}

.modal-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #3aa0d6;
}

.modal-button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 0 #3aa0d6;
}

/* Responsive design */
@media (max-width: 768px) {
  .top-bar {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 12px;
  }
  
  .brand {
    font-size: 1.2em;
  }
  
  .hud {
    gap: 12px;
    order: 3;
    width: 100%;
    justify-content: center;
  }
  
  .hud span {
    font-size: 0.9em;
    padding: 6px 12px;
    min-width: auto;
  }
  
  .actions {
    gap: 8px;
  }
  
  .actions select,
  .actions button {
    padding: 8px 12px;
    font-size: 0.9em;
    min-width: auto;
  }
  
  .canvas-wrap {
    padding: 16px;
  }
  
  canvas {
    border-radius: 16px;
  }
  
  .rules {
    margin: 0 16px 24px;
    padding: 16px 20px;
  }
  
  .help {
    padding: 8px 16px 20px;
    margin: 0 16px;
  }
}

@media (max-width: 480px) {
  .top-bar {
    padding: 8px 12px;
  }
  
  .brand {
    font-size: 1.1em;
  }
  
  .hud {
    gap: 8px;
  }
  
  .hud span {
    font-size: 0.8em;
    padding: 4px 8px;
  }
  
  .actions {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .actions select,
  .actions button {
    padding: 6px 10px;
    font-size: 0.85em;
  }
  
  .rules h3 {
    font-size: 1.1em;
  }
  
  .rules li {
    font-size: 0.9em;
  }
}

/* Animation keyframes */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes glow {
  0%, 100% { box-shadow: 0 0 20px rgba(106, 200, 255, 0.3); }
  50% { box-shadow: 0 0 30px rgba(106, 200, 255, 0.6); }
}

/* Special effects for game elements */
.score-update {
  animation: pulse 0.3s ease;
}

.level-up {
  animation: glow 1s ease-in-out infinite;
}
