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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #1a1a2e;
  overflow: hidden;
  touch-action: none;
}

#game-container {
  width: 100vw;
  height: 100vh;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

#game-container canvas {
  display: block;
}

/* UI Overlay */
#ui-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 10;
}

#ui-overlay > * {
  pointer-events: auto;
}

/* Top Bar */
#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0) 100%);
}

#level-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

#level-name {
  color: #fff;
  font-size: 18px;
  font-weight: 600;
}

.badge {
  background: #4a4a8a;
  color: #fff;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  text-transform: uppercase;
}

.badge.tutorial { background: #3498db; }
.badge.easy { background: #2ecc71; }
.badge.medium { background: #f39c12; }
.badge.hard { background: #e74c3c; }
.badge.expert { background: #9b59b6; }

#stats {
  display: flex;
  gap: 20px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-label {
  color: #aaa;
  font-size: 11px;
  text-transform: uppercase;
}

.stat-value {
  color: #fff;
  font-size: 24px;
  font-weight: 700;
}

/* Control Buttons */
#controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  gap: 10px;
}

.control-btn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: #fff;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.2s ease;
  backdrop-filter: blur(5px);
}

.control-btn:hover {
  background: rgba(255,255,255,0.25);
  transform: scale(1.1);
}

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

.control-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.control-btn:disabled:hover {
  transform: none;
  background: rgba(255,255,255,0.15);
}

/* Modals */
.modal {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: linear-gradient(145deg, #2a2a4a, #1a1a2e);
  border-radius: 20px;
  padding: 30px 40px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.1);
}

.modal-content.wide {
  max-width: 600px;
}

.modal-content h2 {
  color: #fff;
  margin-bottom: 20px;
  font-size: 28px;
}

/* Stars */
#stars-container {
  margin: 20px 0;
}

.star {
  font-size: 48px;
  color: #333;
  text-shadow: 0 0 10px rgba(0,0,0,0.5);
  transition: all 0.3s ease;
}

.star.earned {
  color: #ffd700;
  text-shadow: 0 0 20px rgba(255,215,0,0.5);
  animation: starPop 0.3s ease forwards;
}

@keyframes starPop {
  0% { transform: scale(0); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* Result Stats */
.result-stats {
  color: #ccc;
  margin: 20px 0;
}

.result-stats p {
  margin: 8px 0;
  font-size: 16px;
}

.result-stats span {
  color: #fff;
  font-weight: 600;
}

/* Buttons */
.primary-btn, .secondary-btn {
  padding: 12px 30px;
  border: none;
  border-radius: 25px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  margin: 5px;
}

.primary-btn {
  background: linear-gradient(145deg, #4a4a8a, #3a3a6a);
  color: #fff;
}

.primary-btn:hover {
  background: linear-gradient(145deg, #5a5a9a, #4a4a7a);
  transform: translateY(-2px);
}

.secondary-btn {
  background: transparent;
  color: #aaa;
  border: 1px solid #444;
}

.secondary-btn:hover {
  color: #fff;
  border-color: #666;
}

/* Level Grid */
#level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin: 20px 0;
  max-height: 400px;
  overflow-y: auto;
}

.level-btn {
  width: 60px;
  height: 60px;
  border: 2px solid #444;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  color: #fff;
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.level-btn:hover:not(:disabled) {
  border-color: #666;
  background: rgba(255,255,255,0.1);
  transform: scale(1.05);
}

.level-btn.completed {
  border-color: #2ecc71;
  background: rgba(46,204,113,0.1);
}

.level-btn.current {
  border-color: #3498db;
  background: rgba(52,152,219,0.2);
}

.level-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.level-btn .mini-stars {
  font-size: 10px;
  color: #ffd700;
  margin-top: 2px;
}

/* Mobile Controls */
#mobile-controls {
  position: absolute;
  bottom: 80px;
  left: 20px;
  width: 120px;
  height: 120px;
}

#mobile-controls.hidden {
  display: none;
}

.dpad-btn {
  position: absolute;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(5px);
}

.dpad-btn:active {
  background: rgba(255,255,255,0.4);
}

.dpad-btn.up { top: 0; left: 40px; }
.dpad-btn.down { bottom: 0; left: 40px; }
.dpad-btn.left { top: 40px; left: 0; }
.dpad-btn.right { top: 40px; right: 0; }

/* Responsive */
@media (max-width: 600px) {
  #top-bar {
    padding: 8px 12px;
  }

  #level-name {
    font-size: 14px;
  }

  .stat-value {
    font-size: 18px;
  }

  #controls {
    bottom: 15px;
    right: 15px;
  }

  .control-btn {
    width: 40px;
    height: 40px;
  }

  #level-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .level-btn {
    width: 50px;
    height: 50px;
    font-size: 16px;
  }
}

/* Particle effects area */
.particle {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
}

/* Loading screen */
#loading-screen {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #1a1a2e;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 200;
}

#loading-screen h1 {
  color: #fff;
  margin-bottom: 20px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255,255,255,0.1);
  border-top-color: #4a4a8a;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ASCII Mini-map */
#mini-map {
  position: absolute;
  bottom: 15px;
  left: 15px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(68, 136, 255, 0.8);
  border-radius: 8px;
  padding: 10px;
  padding-top: 28px;
  pointer-events: auto;
  z-index: 50;
}

#mini-map.hidden {
  display: none;
}

#mini-map-close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  background: rgba(255, 100, 100, 0.8);
  border: none;
  border-radius: 4px;
  color: white;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#mini-map-close:hover {
  background: rgba(255, 50, 50, 1);
}

#mini-map-show {
  position: absolute;
  bottom: 15px;
  left: 15px;
  background: rgba(68, 136, 255, 0.8);
  border: 1px solid rgba(68, 136, 255, 1);
  border-radius: 6px;
  color: white;
  font-size: 12px;
  font-weight: bold;
  padding: 8px 12px;
  cursor: pointer;
  z-index: 50;
  pointer-events: auto;
}

#mini-map-show:hover {
  background: rgba(68, 136, 255, 1);
}

#mini-map-show.hidden {
  display: none;
}

#mini-map-text {
  font-family: 'Courier New', Consolas, monospace;
  font-size: 16px;
  line-height: 18px;
  color: #fff;
  margin: 0;
  user-select: text;
  cursor: text;
  letter-spacing: 2px;
}

#mini-map-legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(68, 136, 255, 0.4);
  font-family: 'Courier New', Consolas, 'Lucida Console', Monaco, monospace;
  font-size: 10px;
  color: #aaa;
}
