/* === Base === */
body {
  background: #0f0f0f;
  color: #eee;
  font-family: "Inter", sans-serif;
  margin: 0;
  padding: 0;
  text-align: center;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Header === */
header {
  padding: 20px;
  background: #161616;
  border-bottom: 1px solid #222;
}

#search {
  margin-top: 10px;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  width: 240px;
  background: #222;
  color: #fff;
  outline: none;
  transition: background 0.2s ease;
}
#search:focus {
  background: #2a2a2a;
}

/* === Main Gallery Grid === */
main {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 20px;
  padding: 20px;
  justify-items: center;
  flex: 1;
  align-content: start;
  /* 1️⃣ Set containment context for absolute elements */
  position: relative; 
}

/* === Image Cards === */
.img-card {
  background: #1b1b1b;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
  width: 100%;
  max-width: 220px;
  border: 2px solid transparent;
}

.img-card:hover {
  transform: scale(1.05);
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.08);
}

/* ✅ Subtle container glow on copy */
.img-card.copied {
  border-color: #00ffae;
  box-shadow: 0 0 20px rgba(0, 255, 174, 0.3);
}

.img-card img {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
}

.img-name {
  padding: 8px;
  font-size: 0.85em;
  background: #111;
  color: #bbb;
  border-top: 1px solid #222;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

/* === Copied Overlay === */
.copied {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 255, 160, 0.08);
  color: #00ffae;
  font-weight: 600;
  font-size: 0.9em;
  border-radius: 12px;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.img-card.copied .copied {
  opacity: 1;
}

/* === Loader & Error Centering (Updated) === */
.loader,
/* Assuming you apply 'error-message' class to your error element */
main > p { 
  /* 2️⃣ Use absolute position relative to the <main> parent */
  position: absolute; 
  /* 3️⃣ Fill the parent area (including padding) */
  top: 0;
  left: 0;
  width: 100%;
  height: 100%; 
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #aaa;
  /* Use the body background to match the outside */
  background: #0f0f0f; 
  z-index: 1000;
  text-align: center;
  /* Reset the grid display if the loader is showing */
  grid-column: 1 / -1; 
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #2a2a2a;
  border-top-color: #00ffae;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

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

/* === Responsive Tweaks === */
@media (max-width: 500px) {
  #search {
    width: 90%;
  }
  main {
    gap: 15px;
    padding: 15px;
  }
  .img-card {
    max-width: 160px;
  }
}
