/* 🌙 Global Layout (Enhanced Background + Unified Body) */
body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  font-family: 'Segoe UI', sans-serif;
  text-align: center;
  color: #eaeaea;

  /* 🎨 Combined Background (Gradient + Pattern) */
  background:
    radial-gradient(circle at top left, #1a1c2c, #0f1116),
    url("https://www.transparenttextures.com/patterns/cubes.png");
  background-blend-mode: overlay;
  background-repeat: repeat;
  background-size: 200px;
  opacity: 0.98;

  /* ✨ Smooth transition on theme switch */
  transition: background 0.6s ease-in-out, color 0.4s ease-in-out;
}

/* 🌌 Header Section */
header {
  position: relative;
  overflow: hidden;
  padding: 20px 0 10px;
  background: transparent;
}

/* 🌀 Full Visible Header GIF (Fixed) */
#header-gif {
  position: relative;
  width: 100%;
  height: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.4);
  border-bottom: 2px solid rgba(0, 255, 200, 0.15);
  box-shadow: 0 2px 12px rgba(0, 255, 200, 0.2);
  border-radius: 0 0 10px 10px;
}

#header-gif img {
  width: 100%;
  height: auto;
  max-height: 180px; /* Keeps GIF proportional and fully visible */
  object-fit: contain; /* Show full GIF */
  object-position: center;
  opacity: 0.85;
  filter: brightness(0.9) contrast(1.05) saturate(1.1);
  transition: opacity 0.6s ease-in-out;
}

/* ✨ Header Title & Subtitle */
header h1 {
  color: #00ffc8;
  font-size: 2.3rem;
  margin: 12px 0 5px;
  letter-spacing: 1px;
  text-shadow: 0 0 10px rgba(0, 255, 200, 0.6);
  animation: headerFade 2s ease-in-out;
}

header p {
  margin-top: 4px;
  color: #bfbfbf;
  font-size: 1.05rem;
  letter-spacing: 0.3px;
}

@keyframes headerFade {
  from { opacity: 0; transform: translateY(-15px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 🎛️ Controls (Compact, Polished Design) */
#controls {
  margin: 20px 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

select, button {
  background: #00adb5;
  border: none;
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.25s ease;
  box-shadow: 0 0 6px rgba(0, 255, 200, 0.3);
  min-width: 130px;
  text-transform: capitalize;
}

button:hover, select:hover {
  background: #00ffbb;
  color: #000;
  box-shadow: 0 0 10px #00ffbb;
  transform: translateY(-1.5px);
}

button:active, select:active {
  transform: scale(0.97);
}

/* 🧠 Status Bar */
#status {
  margin: 10px 0;
  font-weight: 500;
  color: #ccc;
  font-size: 1rem;
  letter-spacing: 0.5px;
}
#status span {
  color: #00ffc8;
  font-weight: 600;
}

/* 🧩 Grid Visualization */
#grid {
  display: grid;
  justify-content: center;
  align-content: center;
  margin: 25px auto;
  gap: 6px;
  width: 90vw;
  max-width: 750px;
  aspect-ratio: 1 / 1;
  border-radius: 15px;
  transition: all 0.3s ease;
  grid-template-columns: repeat(var(--cols, 15), 1fr);
  grid-template-rows: repeat(var(--rows, 15), 1fr);
}

/* 🌟 Rounded Cell Design */
.cell {
  border: none;
  background: linear-gradient(145deg, #1f2024, #2b2c31);
  font-size: clamp(10px, 1.5vw, 14px);
  text-align: center;
  color: #d3d3d3;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  box-shadow:
    inset 1px 1px 3px rgba(255,255,255,0.05),
    2px 2px 5px rgba(0,0,0,0.6);
  transition: background 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
}

.cell:hover {
  transform: scale(1.1);
  background: linear-gradient(145deg, #292a2f, #1e1f23);
  box-shadow:
    inset 1px 1px 4px rgba(255,255,255,0.1),
    3px 3px 7px rgba(0,0,0,0.7);
}

/* 🎨 Cell States */
.cell.start {
  background: #00ff88;
  box-shadow: 0 0 15px #00ff88;
  border-radius: 50%;
  animation: glow 1.5s infinite alternate;
}
.cell.end {
  background: #ff005c;
  box-shadow: 0 0 15px #ff005c;
  border-radius: 50%;
  animation: glow 1.5s infinite alternate;
}
.cell.wall {
  background: #444;
  border-radius: 12px;
}
.cell.visited-bfs {
  background: #0077ff;
  border-radius: 12px;
  animation: pulse 1s infinite alternate;
}
.cell.path-bfs {
  background: #00ffff;
  box-shadow: 0 0 12px #00ffff;
  border-radius: 12px;
  animation: glow 1.2s infinite alternate;
}
.cell.visited-dijkstra {
  background: #ffb700;
  border-radius: 12px;
  animation: pulse 1s infinite alternate;
}
.cell.path-dijkstra {
  background: #ffee00;
  box-shadow: 0 0 12px #ffee00;
  border-radius: 12px;
  animation: glow 1.2s infinite alternate;
}

/* ✨ Animations */
@keyframes glow {
  from { box-shadow: 0 0 4px rgba(255,255,255,0.3); }
  to { box-shadow: 0 0 14px rgba(255,255,255,0.8); }
}

@keyframes pulse {
  from { opacity: 0.8; transform: scale(1); }
  to { opacity: 1; transform: scale(1.08); }
}

/* ⏳ Loader GIF */
#loader {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.75);
  padding: 25px;
  border-radius: 12px;
  z-index: 1000;
  text-align: center;
  backdrop-filter: blur(5px);
  box-shadow: 0 0 20px rgba(0,255,200,0.4);
}

#loader img {
  width: 80px;
  height: 80px;
}
#loader p {
  color: #00ffc8;
  font-weight: bold;
  margin-top: 10px;
}

/* 🚫 No Path Popup */
#noPathPopup {
  position: fixed;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.85);
  padding: 25px;
  border-radius: 12px;
  text-align: center;
  z-index: 1100;
  box-shadow: 0 0 15px #ff4d6d;
  backdrop-filter: blur(8px);
}
#noPathPopup img {
  width: 130px;
  height: 130px;
}
#noPathPopup p {
  color: #ff4d6d;
  font-weight: bold;
  margin-top: 10px;
  font-size: 1rem;
}

/* 🌠 Footer */
footer {
  background: rgba(0,0,0,0.65);
  padding: 15px 0;
  color: #ccc;
  font-size: 0.95rem;
  text-align: center;
  margin-top: 40px;
  border-top: 1px solid #222;
}

footer img {
  width: 80px;
  height: 80px;
  display: block;
  margin: 10px auto 0;
  filter: brightness(0.9);
  transition: transform 0.3s ease, filter 0.3s ease;
}

footer img:hover {
  transform: scale(1.1);
  filter: brightness(1.1);
}

/* 📱 Mobile Responsive Tweaks */
@media (max-width: 800px) {
  #grid {
    width: 95vw;
    max-width: 400px;
    gap: 1px;
  }

  #header-gif img {
    max-height: 120px; /* smaller GIF height for mobile */
  }

  select, button {
    font-size: 13px;
    padding: 8px 12px;
    min-width: 110px;
  }

  header h1 {
    font-size: 1.8rem;
  }

  .cell {
    font-size: clamp(9px, 2vw, 13px);
  }

  footer img {
    width: 65px;
    height: 65px;
  }
}
