/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: #f8f9fa;
  color: #333;
  line-height: 1.6;
}

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

/* Header */
header {
  text-align: center;
  margin-bottom: 30px;
}

h1 {
  font-size: 2.5rem;
  color: #2c3e50;
  margin-bottom: 8px;
  font-weight: 600;
}

.subtitle {
  color: #6c757d;
  font-size: 1.1rem;
}

/* Controls */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  padding: 20px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  flex-wrap: wrap;
  gap: 20px;
}

.control-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 120px;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background-color: #007bff;
  color: white;
}

.btn-primary:hover {
  background-color: #0056b3;
}

.btn-success {
  background-color: #28a745;
  color: white;
}

.btn-success:hover {
  background-color: #1e7e34;
}

.btn-warning {
  background-color: #ffc107;
  color: #333;
}

.btn-warning:hover {
  background-color: #e0a800;
}

.btn-secondary {
  background-color: #6c757d;
  color: white;
}

.btn-secondary:hover {
  background-color: #545b62;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #495057;
}

.speed-control label {
  font-weight: 500;
  white-space: nowrap;
}

#speedSlider {
  width: 120px;
}

#speedValue {
  font-weight: 600;
  color: #007bff;
  min-width: 45px;
}

/* Visualizer */
.visualizer {
  background: white;
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  margin-bottom: 30px;
}

.algorithm-info {
  margin-bottom: 25px;
  text-align: center;
}

.current-action {
  font-size: 1.2rem;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 10px;
  min-height: 30px;
  padding: 8px;
  background-color: #f8f9fa;
  border-radius: 8px;
}

.progress-info {
  display: flex;
  justify-content: center;
  gap: 30px;
  color: #6c757d;
  font-size: 14px;
}

.progress-info strong {
  color: #007bff;
}

/* Array visualization */
.array-container {
  position: relative;
  margin: 30px 0;
}

.indicators {
  display: flex;
  justify-content: center;
  height: 25px;
  margin-bottom: 5px;
  align-items: flex-end;
}

.indicator {
  flex: 1;
  max-width: 50px;
  text-align: center;
  font-size: 18px;
  color: #dc3545;
  animation: bounce 1s ease-in-out infinite;
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-8px);
  }
  60% {
    transform: translateY(-4px);
  }
}

.bars {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: 300px;
  padding: 20px;
  background-color: #f8f9fa;
  border-radius: 8px;
  gap: 2px;
  border: 1px solid #dee2e6;
}

.bar {
  flex: 1;
  max-width: 50px;
  background-color: #6c757d;
  border-radius: 4px 4px 0 0;
  position: relative;
  transition: all 0.3s ease;
  min-height: 20px;
}

.bar::after {
  content: attr(data-value);
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  font-weight: 600;
  color: #495057;
}

.bar.comparing {
  background-color: #ffc107;
  transform: scale(1.05);
}

.bar.swapped {
  background-color: #fd7e14;
  animation: swap-flash 0.6s ease;
}

.bar.sorted {
  background-color: #28a745;
}

@keyframes swap-flash {
  0% { transform: scale(1.05); }
  50% { transform: scale(1.15); background-color: #e83e8c; }
  100% { transform: scale(1.05); }
}

.position-labels {
  display: flex;
  justify-content: center;
  margin-top: 10px;
  gap: 2px;
}

.position-label {
  flex: 1;
  max-width: 50px;
  text-align: center;
  font-size: 11px;
  color: #6c757d;
  font-weight: 500;
}

/* Explanation */
.explanation {
  margin-top: 25px;
  padding-top: 20px;
  border-top: 1px solid #dee2e6;
}

.explanation h3 {
  color: #2c3e50;
  margin-bottom: 10px;
  font-size: 1.1rem;
}

#stepExplanation {
  color: #495057;
  font-size: 15px;
  line-height: 1.5;
  padding: 12px;
  background-color: #f8f9fa;
  border-radius: 8px;
  border-left: 4px solid #007bff;
}

/* Statistics */
.statistics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  background: white;
  padding: 20px;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: #007bff;
  margin-bottom: 5px;
}

.stat-label {
  color: #6c757d;
  font-size: 14px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Footer and Legend */
footer {
  text-align: center;
  margin-top: 30px;
}

.legend {
  display: flex;
  justify-content: center;
  gap: 30px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #6c757d;
  font-size: 14px;
}

.legend-color {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid #dee2e6;
}

.legend-color.comparing {
  background-color: #ffc107;
}

.legend-color.swapped {
  background-color: #fd7e14;
}

.legend-color.sorted {
  background-color: #28a745;
}

/* Responsive design */
@media (max-width: 768px) {
  .container {
    padding: 15px;
  }

  h1 {
    font-size: 2rem;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .control-group {
    justify-content: center;
  }

  .btn {
    min-width: auto;
    flex: 1;
  }

  .progress-info {
    flex-direction: column;
    gap: 8px;
  }

  .bars {
    height: 250px;
    padding: 15px;
  }

  .legend {
    gap: 15px;
  }

  .statistics {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .stat-value {
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  .bars {
    gap: 1px;
  }
  
  .bar {
    max-width: 40px;
  }
  
  .bar::after {
    font-size: 10px;
  }
}