/* ===== PATHFINDING VISUALIZER STYLES ===== */

.visualizer-container {
  display: grid;
  grid-template-columns: 3fr 1.2fr;
  gap: 1.5rem;
  margin-top: 2rem;
  margin-bottom: 2rem;
}

.visualizer-main-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.visualizer-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Glass Card */
.visualizer-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 1.5rem;
  backdrop-filter: blur(10px);
  box-shadow: var(--glass-shadow);
  position: relative;
  overflow: hidden;
}

.visualizer-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: var(--gradient-1);
}

/* Legend Styling */
.legend-card::before {
  background: var(--gradient-3);
}

.legend-container {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-around;
  align-items: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.legend-node {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: white;
}

.start-node-legend {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

.target-node-legend {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

.wall-node-legend {
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.weight-node-legend {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
}

.unvisited-node-legend {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.visited-node-legend {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.8) 0%, rgba(124, 58, 237, 0.8) 100%);
  box-shadow: 0 0 8px rgba(6, 182, 212, 0.4);
}

.shortest-path-legend {
  background: linear-gradient(135deg, #facc15 0%, #eab308 100%);
  box-shadow: 0 0 8px rgba(234, 179, 8, 0.6);
}

/* Canvas Area */
.canvas-wrapper {
  position: relative;
  background: rgba(10, 10, 26, 0.6);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  overflow: auto; /* Enable scroll on small screens */
  padding: 0.5rem;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
}

.grid-canvas {
  display: grid;
  grid-template-columns: repeat(50, 1fr);
  grid-template-rows: repeat(22, 1fr);
  gap: 1px;
  width: 100%;
  min-width: 900px; /* Ensures grid layout stays readable and square on mobile */
  user-select: none;
  background-color: rgba(255, 255, 255, 0.02);
}

/* Cell Elements */
.grid-cell {
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.04);
  background-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, border-color 0.2s ease;
  cursor: cell;
  position: relative;
}

.grid-cell i {
  font-size: 0.8rem;
  color: white;
  pointer-events: none;
}

/* Start/Target hover changes */
.grid-cell.cell-start {
  cursor: grab;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.6);
  border-color: #10b981;
  z-index: 10;
}

.grid-cell.cell-start:active {
  cursor: grabbing;
}

.grid-cell.cell-target {
  cursor: grab;
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.6);
  border-color: #ef4444;
  z-index: 10;
}

.grid-cell.cell-target:active {
  cursor: grabbing;
}

/* Wall cell styling & animation */
.grid-cell.cell-wall {
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%) !important;
  border-color: rgba(255, 255, 255, 0.1);
  animation: wallAnimation 0.3s ease-out forwards;
}

@keyframes wallAnimation {
  0% {
    transform: scale(0.3);
    border-radius: 50%;
    background-color: #1e1b4b;
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1.0);
    border-radius: 0;
  }
}

/* Weight cell styling & animation */
.grid-cell.cell-weight {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%) !important;
  border-color: rgba(255, 255, 255, 0.1);
  animation: weightAnimation 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
  z-index: 5;
}

@keyframes weightAnimation {
  0% {
    transform: scale(0.2);
  }
  70% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1.0);
  }
}

/* Visited cells styling & animation */
.grid-cell.cell-visited {
  border-color: rgba(6, 182, 212, 0.2);
  animation: visitedAnimation 1.2s ease-out forwards;
}

@keyframes visitedAnimation {
  0% {
    transform: scale(0.3);
    background-color: rgba(6, 182, 212, 0.1);
    border-radius: 100%;
  }
  40% {
    background-color: rgba(124, 58, 237, 0.4);
  }
  75% {
    transform: scale(1.15);
    background-color: rgba(6, 182, 212, 0.7);
  }
  100% {
    transform: scale(1.0);
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.7) 0%, rgba(124, 58, 237, 0.7) 100%);
  }
}

/* Shortest Path cells styling & animation */
.grid-cell.cell-shortest-path {
  border-color: #facc15;
  z-index: 8;
  animation: shortestPathAnimation 0.6s ease-out forwards;
}

@keyframes shortestPathAnimation {
  0% {
    transform: scale(0.3);
    background-color: rgba(250, 204, 21, 0.3);
    border-radius: 100%;
  }
  50% {
    transform: scale(1.2);
    background-color: rgba(234, 179, 8, 0.8);
  }
  100% {
    transform: scale(1.0);
    background: linear-gradient(135deg, #facc15 0%, #eab308 100%);
    box-shadow: 0 0 12px rgba(234, 179, 8, 0.8);
  }
}

/* Controls & Sidebars */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.control-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
}

.control-group label span.val-display {
  color: var(--accent);
  font-family: "Fira Code", monospace;
}

.control-input {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  color: var(--text-primary);
  padding: 0.65rem 0.8rem;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  width: 100%;
  transition: all 0.2s;
}

.control-input:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 2px rgba(167, 139, 250, 0.2);
}

.control-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Sliders */
input[type="range"].slider-custom {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  outline: none;
  transition: background 0.3s;
}

input[type="range"].slider-custom::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary-light);
  cursor: pointer;
  transition: transform 0.1s ease;
  box-shadow: 0 0 6px rgba(124, 58, 237, 0.5);
}

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

/* Buttons */
.btn-control-row {
  display: flex;
  gap: 0.5rem;
}

.btn-control {
  flex: 1;
  padding: 0.75rem 0.5rem;
  font-weight: 600;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

/* Drawing tools mode-grid */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.mode-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 0.6rem;
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.mode-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.mode-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--text-primary);
  box-shadow: 0 0 10px rgba(124, 58, 237, 0.35);
}

/* Complexity Grid */
.complexity-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-top: 1rem;
}

.complexity-card-mini {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 0.75rem;
}

.complexity-card-mini h5 {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
}

.complexity-card-mini p {
  font-family: "Fira Code", monospace;
  font-size: 0.95rem;
  color: var(--accent);
  font-weight: 600;
}

/* Hero changes specific to pathfinding visualizer page */
.hero.visualizer-hero {
  min-height: 45vh;
  padding: 7rem 1rem 2rem;
}

.typing-text_pathfinding {
  color: var(--accent);
  font-weight: 600;
}

/* Execution Log Panel */
.log-panel {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 0.75rem;
  max-height: 120px;
  overflow-y: auto;
  font-family: "Fira Code", monospace;
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.log-entry {
  color: var(--text-secondary);
}

.log-entry.info {
  color: var(--accent);
}

.log-entry.visit {
  color: var(--primary-light);
}

.log-entry.success {
  color: #10b981;
}

/* Stats Styling */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.stat-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 0.75rem;
  text-align: center;
}

.stat-card h5 {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.stat-card p {
  font-family: "Fira Code", monospace;
  font-size: 1.2rem;
  color: var(--accent);
  font-weight: 700;
}

/* Responsive Grid overrides */
@media (max-width: 1024px) {
  .visualizer-container {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .btn-control-row {
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .btn-control-row {
    flex-direction: column;
  }
}
