/* ==========================================================================
   Sorting Algorithm ASMR - Styling
   ========================================================================== */

:root {
  --bg-dark: #0a0b10;
  --surface-glass: rgba(18, 20, 30, 0.75);
  --surface-glass-border: rgba(255, 255, 255, 0.08);
  --surface-dock: rgba(14, 16, 24, 0.85);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-cyan: #38bdf8;
  --accent-purple: #a855f7;
  --accent-pink: #ec4899;
  --accent-amber: #fbbf24;
  --accent-emerald: #34d399;
  --accent-gradient: linear-gradient(135deg, #38bdf8 0%, #818cf8 50%, #c084fc 100%);
  --bar-default-top: #818cf8;
  --bar-default-bottom: #3b82f6;
  --bar-compare: #fbbf24;
  --bar-swap: #f43f5e;
  --bar-pivot: #38bdf8;
  --bar-sorted: #10b981;
}

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

body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  position: relative;
  user-select: none;
}

/* Ambient dynamic background lighting */
.ambient-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(circle at 20% 15%, rgba(56, 189, 248, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 80% 85%, rgba(168, 85, 247, 0.08) 0%, transparent 45%),
    radial-gradient(circle at 50% 50%, rgba(236, 72, 153, 0.04) 0%, transparent 50%);
}

/* Header */
.app-header {
  position: relative;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 28px;
  background: rgba(10, 11, 16, 0.85);
  border-bottom: 1px solid var(--surface-glass-border);
  backdrop-filter: blur(16px);
  gap: 16px;
}

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

.nav-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 7px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--surface-glass-border);
  border-radius: 9999px;
  transition: all 0.2s ease;
}

.nav-back-btn:hover {
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateX(-2px);
}

.title-group h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-group h1 span {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.sound-control-group {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.03);
  padding: 6px 12px;
  border-radius: 9999px;
  border: 1px solid var(--surface-glass-border);
}

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

.glass-select {
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-main);
  background: rgba(20, 24, 36, 0.9);
  border: 1px solid var(--surface-glass-border);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

.glass-select:focus, .glass-select:hover {
  border-color: rgba(255, 255, 255, 0.25);
}

.glass-select option {
  background: #12141f;
  color: var(--text-main);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, color 0.15s;
}

.icon-btn:hover {
  color: var(--text-main);
  transform: scale(1.1);
}

.volume-slider-wrapper {
  display: flex;
  align-items: center;
  width: 70px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
  cursor: pointer;
  transition: background 0.2s;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-main);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
  cursor: pointer;
  transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Visualizer Container */
.visualizer-container {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 28px 28px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* Stats HUD */
.hud-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-glass);
  border: 1px solid var(--surface-glass-border);
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 0.82rem;
  backdrop-filter: blur(12px);
}

.stat-label {
  color: var(--text-muted);
  font-weight: 500;
}

.stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--text-main);
}

.stat-value.highlight {
  color: var(--accent-cyan);
}

.stat-value.status-indicator {
  color: var(--accent-amber);
}

.stat-value.status-indicator.sorted {
  color: var(--accent-emerald);
}

/* Canvas Wrapper */
.canvas-wrapper {
  flex: 1;
  min-height: 380px;
  background: var(--surface-glass);
  border: 1px solid var(--surface-glass-border);
  border-radius: 20px;
  backdrop-filter: blur(16px);
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
}

#sortCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Bottom Control Dock */
.control-dock {
  margin-top: 20px;
  background: var(--surface-dock);
  border: 1px solid var(--surface-glass-border);
  border-radius: 18px;
  padding: 16px 24px;
  backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 18px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.dock-section {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.dock-divider {
  width: 1px;
  height: 36px;
  background: var(--surface-glass-border);
}

/* Buttons */
.dock-btn {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.dock-btn.primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}

.dock-btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.dock-btn.secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border-color: var(--surface-glass-border);
}

.dock-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

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

/* Dock Input Groups */
.dock-input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.slider-group {
  min-width: 120px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.slider-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: var(--accent-cyan);
  font-weight: 600;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 20px;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: #141724;
  border: 1px solid var(--surface-glass-border);
  border-radius: 20px;
  width: 100%;
  max-width: 480px;
  padding: 24px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.6);
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-header h3 {
  font-size: 1.2rem;
  font-weight: 700;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

textarea#customArrayInput {
  width: 100%;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  padding: 12px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--surface-glass-border);
  border-radius: 10px;
  color: var(--text-main);
  outline: none;
  resize: vertical;
  margin-bottom: 18px;
}

textarea#customArrayInput:focus {
  border-color: var(--accent-cyan);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Audio Tip */
.audio-tip {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 34, 52, 0.9);
  border: 1px solid var(--surface-glass-border);
  padding: 8px 18px;
  border-radius: 9999px;
  font-size: 0.8rem;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 200;
  transition: opacity 0.5s ease;
}

.audio-tip.hidden {
  opacity: 0;
}

@media (max-width: 900px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .header-right {
    width: 100%;
    justify-content: space-between;
  }
  .dock-divider {
    display: none;
  }
  .control-dock {
    flex-direction: column;
    align-items: stretch;
  }
  .dock-section {
    justify-content: space-between;
  }
}
