/* Final Polished Version: Compact Grid, Robust Blur, 'Unbounded' Font */
@import url('https://fonts.googleapis.com/css2?family=Unbounded:wght@400;500;600;700&display=swap');

:root {
  /* Redesign V4: Maximum Clarity & Structure */
  --bg-accent: #c084fc; /* Tailwind purple-400 */
  --bg-accent-glow: rgba(192, 132, 252, 0.6);
  --bg-overlay: linear-gradient(145deg, #1e192d, #2a2341); /* Opaque, dark gradient */
  --bg-surface: #3a3155;
  --bg-border: rgba(192, 132, 252, 0.3);
  --bg-text-primary: #f5f3ff;
  --bg-text-secondary: #a7a0c4;
  --bg-radius: 12px;
}

/* Blur effect removed by user request */

.bg-selector-container {
  font-family: 'Unbounded', sans-serif;
  width: 100%;
  margin-top: 20px;
  position: relative;
}

/* Backdrop für geöffnetes Overlay */
.bg-selector-container::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
  backdrop-filter: blur(4px);
}

.bg-selector-container.selection-active::before {
  opacity: 1;
  visibility: visible;
}

.bg-selector-label {
  font-size: 13px; font-weight: 600; color: var(--bg-text-secondary);
  margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.5px;
}

.bg-grid-trigger {
  position: relative; display: flex; align-items: center; width: 100%;
  height: 75px; padding: 0 20px; border: 1px solid var(--bg-border);
  border-radius: var(--bg-radius); cursor: pointer; background-size: cover;
  background-position: center; overflow: hidden;
  transition: border-color 0.2s ease, transform 0.2s ease;
}
.bg-grid-trigger:hover { border-color: var(--bg-accent); transform: scale(1.01); }

.bg-grid-trigger::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(90deg, rgba(30, 31, 34, 0.85) 0%, rgba(30, 31, 34, 0.6) 60%, transparent 100%);
  z-index: 1;
}

.bg-grid-trigger-name {
  position: relative; z-index: 2; font-weight: 700; font-size: 18px;
  color: var(--bg-text-primary); text-shadow: 0 1px 5px rgba(0,0,0,0.5);
  font-family: 'Unbounded', sans-serif;
}

.bg-grid-overlay {
  visibility: hidden; opacity: 0; position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) scale(0.92) translateY(10px);
  width: min(600px, calc(100vw - 40px));
  max-height: min(500px, calc(100vh - 140px));
  background-image: var(--bg-overlay);
  z-index: 1000; display: flex; flex-direction: column;
  padding: 20px;
  transition: opacity 0.3s, visibility 0.3s, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--bg-radius);
  border: 1px solid var(--bg-border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(192, 132, 252, 0.1);
  transform-origin: 50% 100%;
}

@media (max-width: 768px) {
  .bg-grid-overlay {
    width: calc(100vw - 32px);
    max-height: calc(100vh - 120px);
    bottom: 16px;
    padding: 16px;
  }
}

.bg-selector-container.selection-active .bg-grid-overlay {
  visibility: visible;
  opacity: 1;
  transform: translateX(-50%) scale(1) translateY(0);
}

.bg-grid-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 15px;
  padding-bottom: 15px;
  border-bottom: 1px solid rgba(192, 132, 252, 0.2);
  flex-shrink: 0;
}

.bg-grid-header h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  flex-grow: 1; /* Allow title to take space */
  text-align: center; /* Center title for symmetry */
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.bg-grid-footer {
  margin-top: 20px;
  display: flex;
  justify-content: center; /* Center button for symmetry */
}

.bg-grid-close-btn {
  font-family: 'Unbounded', sans-serif; /* Ensure font */
  padding: 10px 20px;
  background-image: linear-gradient(to right, var(--bg-accent) 0%, #a855f7 51%, var(--bg-accent) 100%);
  background-size: 200% auto;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.bg-grid-close-btn:hover {
  background-position: right center; /* change the direction of the change here */
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.3), 0 0 15px var(--bg-accent-glow);
}

/* Improved grid design */
.bg-grid {
  flex-grow: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  overflow-y: auto;
  padding: 12px;
  max-height: 360px;
  min-height: 200px;
}

/* Responsive Grid */
@media (max-width: 768px) {
  .bg-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-height: 320px;
  }
}

@media (max-width: 480px) {
  .bg-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    max-height: 280px;
  }
}

/* Custom Scrollbar Styling */
.bg-grid::-webkit-scrollbar {
  width: 6px;
}
.bg-grid::-webkit-scrollbar-track {
  background: transparent;
}
.bg-grid::-webkit-scrollbar-thumb {
  background-color: var(--bg-surface);
  border-radius: 3px;
}
.bg-grid::-webkit-scrollbar-thumb:hover {
  background-color: var(--bg-accent);
}

.bg-grid-item {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  cursor: pointer;
  overflow: hidden;
  transition: all 0.25s ease;
  border: 2px solid rgba(192, 132, 252, 0.15);
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.bg-grid-item:hover:not(.selected) {
  transform: translateY(-3px);
  border-color: rgba(192, 132, 252, 0.5);
  box-shadow: 0 6px 16px rgba(192, 132, 252, 0.2), 0 2px 8px rgba(0, 0, 0, 0.3);
}

.bg-grid-item.selected {
  border-color: var(--bg-accent);
  border-width: 3px;
  outline: 2px solid var(--bg-accent);
  outline-offset: 2px;
  box-shadow: 0 0 20px var(--bg-accent-glow), 0 4px 12px rgba(0, 0, 0, 0.3);
}

.bg-grid-item.selected:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 25px var(--bg-accent-glow), 0 6px 16px rgba(0, 0, 0, 0.4);
}

.bg-grid-item::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 70%;
  background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, transparent 100%);
  z-index: 1;
  transition: opacity 0.2s ease;
}

.bg-grid-item:hover::before {
  opacity: 0.8;
}

.bg-grid-item-thumb {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  z-index: 0;
  transition: filter 0.3s ease;
}

.bg-grid-item:hover .bg-grid-item-thumb {
  filter: brightness(1.15);
}

.bg-grid-item-name {
  font-family: 'Unbounded', sans-serif;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 2;
  font-size: 11px;
  font-weight: 600;
  color: var(--bg-text-primary);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 8px 4px;
  background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.7) 70%, transparent 100%);
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}

.bg-grid-item.selected .bg-grid-item-name {
  color: var(--bg-text-primary);
  font-weight: 600;
}

/* Checkmark verstecken */
.bg-grid-item-checkmark {
  display: none;
}


