:root {
  color-scheme: dark;
  /* Base Colors */
  --bg-body: #020617;
  --bg-surface: #0f172a;
  --bg-card: #1e293b;
  --bg-glass: rgba(15, 23, 42, 0.7);
  
  /* Accents */
  --primary: #38bdf8;
  --primary-glow: rgba(56, 189, 248, 0.5);
  --secondary: #818cf8;
  --accent-gradient: linear-gradient(135deg, #38bdf8 0%, #818cf8 100%);
  
  /* Text */
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  /* Borders & Shadows */
  --border-subtle: rgba(148, 163, 184, 0.1);
  --border-highlight: rgba(56, 189, 248, 0.3);
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --shadow-glow: 0 0 20px rgba(56, 189, 248, 0.15);
  
  /* Radius */
  --radius-full: 9999px;
  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  
  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration: 300ms;
  
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: #020617;
  color: var(--text-main);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* --- Header --- */
.app-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 1.5rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 50;
}

/* --- Hero Section --- */
.hero-section {
  position: relative;
  padding: 10rem 1.5rem 6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
}

.hero-glow {
  position: absolute;
  top: -50%;
  left: 50%;
  transform: translateX(-50%);
  width: 140%;
  height: 1000px;
  background: 
    radial-gradient(circle at 50% 50%, rgba(56, 189, 248, 0.15), transparent 50%),
    radial-gradient(circle at 20% 30%, rgba(129, 140, 248, 0.1), transparent 40%),
    radial-gradient(circle at 80% 40%, rgba(56, 189, 248, 0.1), transparent 40%);
  filter: blur(60px);
  z-index: 0;
  pointer-events: none;
  opacity: 0.8;
}

.hero-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1200px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hero-title {
  font-size: clamp(3rem, 6vw, 5rem);
  font-weight: 800;
  line-height: 1.1;
  margin: 0 0 1.5rem;
  letter-spacing: -0.03em;
  color: #fff;
  text-shadow: 0 0 40px rgba(56, 189, 248, 0.2);
}

.text-gradient {
  background: linear-gradient(135deg, #fff 0%, #38bdf8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
}

.hero-subtitle {
  font-size: clamp(1.1rem, 2vw, 1.35rem);
  color: #94a3b8;
  max-width: 640px;
  margin: 0 0 4rem;
  font-weight: 400;
  letter-spacing: 0.01em;
}

/* --- Search & Filter --- */
.search-container {
  width: 100%;
  max-width: 720px;
  margin-bottom: 3rem;
  position: relative;
}

.search-container::before {
  content: '';
  position: absolute;
  inset: -2px;
  background: linear-gradient(90deg, #38bdf8, #818cf8, #38bdf8);
  background-size: 200% 100%;
  border-radius: 9999px;
  z-index: -1;
  opacity: 0;
  transition: opacity 0.3s ease;
  animation: shimmer 3s linear infinite;
}

.search-container:focus-within::before {
  opacity: 0.5;
}

@keyframes shimmer {
  0% { background-position: 0% 0%; }
  100% { background-position: 200% 0%; }
}

.search-field-large {
  display: flex;
  align-items: center;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 9999px;
  padding: 1rem 2rem;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(16px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.search-field-large:focus-within {
  background: rgba(15, 23, 42, 0.8);
  border-color: rgba(56, 189, 248, 0.5);
  box-shadow: 0 8px 30px rgba(56, 189, 248, 0.15);
  transform: translateY(-2px);
}

.search-icon-large {
  font-size: 1.4rem;
  margin-right: 1.25rem;
  opacity: 0.8;
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.3));
}

#searchInput {
  flex: 1;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  outline: none;
  width: 100%;
  font-weight: 500;
}

#searchInput::placeholder {
  color: #64748b;
  font-weight: 400;
}

.filter-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  width: 100%;
}

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  max-width: 900px;
}

.tag-button {
  background: rgba(30, 41, 59, 0.4);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tag-button:hover {
  background: rgba(30, 41, 59, 0.8);
  color: var(--text-main);
  transform: translateY(-2px);
}

.tag-button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #000;
  font-weight: 600;
  box-shadow: 0 0 15px var(--primary-glow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  color: #fff;
  text-shadow: 0 0 20px rgba(56, 189, 248, 0.3);
}

.brand-icon {
  font-size: 1.5rem;
  filter: drop-shadow(0 0 8px rgba(253, 224, 71, 0.4));
}

.data-source {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-full);
  background: rgba(30, 41, 59, 0.4);
  border: 1px solid var(--border-subtle);
  transition: all 0.2s ease;
}

.data-source:hover {
  background: rgba(30, 41, 59, 0.8);
  border-color: rgba(56, 189, 248, 0.3);
  color: var(--text-main);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.15);
}

.source-label {
  opacity: 0.8;
}

.source-name {
  font-weight: 600;
  background: linear-gradient(135deg, #38bdf8 0%, #818cf8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.actions-row {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.ghost-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  transition: color 0.2s;
}

.ghost-btn:hover {
  color: var(--text-main);
  background: rgba(255,255,255,0.05);
}

/* --- Gallery --- */
main {
  padding: 0 2rem 4rem;
  max-width: 1600px;
  margin: 0 auto;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 2rem;
}

.prompt-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all var(--duration) var(--ease-out);
  border: 1px solid transparent;
  position: relative;
  cursor: pointer;
}

.prompt-card:hover {
  transform: translateY(-8px);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  border-color: var(--border-highlight);
  z-index: 1;
}

.prompt-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  transition: transform 0.5s ease;
}

.prompt-card:hover img {
  transform: scale(1.05);
}

.card-body {
  padding: 1.25rem;
  background: linear-gradient(to bottom, rgba(30,41,59,0), rgba(30,41,59,1));
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  backdrop-filter: blur(4px);
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  color: var(--text-main);
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tag-chip {
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(4px);
  border-radius: var(--radius-sm);
  color: var(--text-main);
}

.card-meta {
  display: none; /* Cleaner look */
}

.card-placeholder {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}

/* --- Modal --- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(12px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal:not(.hidden) {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: #0f172a;
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 24px;
  width: 100%;
  max-width: 1200px; /* Wider for split view */
  height: 85vh; /* Fixed height */
  overflow: hidden; /* Prevent outer scroll */
  position: relative;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
}

.modal-header {
  flex-shrink: 0;
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
  padding: 1.5rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: 10;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.modal-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
  background: linear-gradient(to right, #fff, #cbd5e1);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.modal-source {
  font-size: 0.9rem;
  color: #64748b;
}

.modal-source a {
  color: #38bdf8;
  text-decoration: none;
  transition: color 0.2s;
}

.modal-source a:hover {
  color: #7dd3fc;
  text-decoration: underline;
}

.modal-close {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  margin-left: 1rem;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  transform: rotate(90deg);
}

.modal-body {
  display: flex;
  flex: 1;
  overflow: hidden; /* Internal scrolling */
}

.modal-left {
  width: 45%;
  background: rgba(0, 0, 0, 0.2);
  border-right: 1px solid rgba(148, 163, 184, 0.1);
  padding: 2rem;
  overflow-y: auto;
}

.modal-right {
  width: 55%;
  padding: 2rem;
  overflow-y: auto;
}

.modal-section {
  margin-bottom: 3rem;
}

.modal-section:last-child {
  margin-bottom: 0;
}

.modal-section h3 {
  font-size: 1rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-section h3::before {
  content: '';
  display: block;
  width: 4px;
  height: 16px;
  background: #38bdf8;
  border-radius: 2px;
}

/* Image Grid in Modal */
.image-grid {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.image-grid img {
  width: 100%;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: transform 0.3s ease;
}

.image-grid img:hover {
  transform: scale(1.02);
  border-color: rgba(56, 189, 248, 0.5);
}

/* Prompt Block */
.prompt-block {
  background: #1e293b;
  border: 1px solid rgba(148, 163, 184, 0.1);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.prompt-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
  color: #94a3b8;
  font-size: 0.85rem;
  font-family: 'Inter', sans-serif;
}

.copy-btn {
  background: rgba(56, 189, 248, 0.1);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.2);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.copy-btn:hover {
  background: rgba(56, 189, 248, 0.2);
  transform: translateY(-1px);
}

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

pre {
  margin: 0;
  padding: 1.25rem;
  white-space: pre-wrap;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.95rem;
  color: #e2e8f0;
  line-height: 1.7;
  overflow-x: auto;
}

/* Tags in Modal */
.modal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.modal-tags .tag-chip {
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid rgba(148, 163, 184, 0.2);
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  color: #cbd5e1;
}

/* Description */
.description-block {
  background: rgba(30, 41, 59, 0.3);
  border-left: 4px solid #38bdf8;
  padding: 1rem 1.5rem;
  border-radius: 0 8px 8px 0;
  color: #cbd5e1;
  line-height: 1.8;
}

/* Scrollbar for modal content */
.modal-left::-webkit-scrollbar,
.modal-right::-webkit-scrollbar {
  width: 8px;
}
.modal-left::-webkit-scrollbar-track,
.modal-right::-webkit-scrollbar-track {
  background: transparent;
}
.modal-left::-webkit-scrollbar-thumb,
.modal-right::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.2);
  border-radius: 4px;
}
.modal-left::-webkit-scrollbar-thumb:hover,
.modal-right::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.4);
}

/* --- Utilities --- */
.hidden { display: none !important; }

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-surface);
  border: 1px solid var(--primary);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-glow);
  z-index: 200;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .app-header {
    padding: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .data-source {
    font-size: 0.75rem;
    padding: 0.4rem 0.75rem;
    width: 100%;
    justify-content: center;
  }

  .hero-section {
    padding-top: 6rem;
  }
  
  .hero-title {
    font-size: 2.5rem;
  }
  
  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
  }
  
  .prompt-card img {
    aspect-ratio: 3/4; /* Taller cards on mobile look nice */
  }
  
  .card-body {
    padding: 0.75rem;
  }
  
  .modal-content {
    padding: 1.5rem;
  }
}

/* --- Sidebar Handle (Mobile Default: Hidden) --- */
.sidebar-handle {
  display: none;
}

/* --- Desktop Sidebar (Floating Tags) --- */
@media (min-width: 1200px) {
  .sidebar-handle {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    right: 0;
    color: #94a3b8;
    transition: all 0.3s ease;
  }

  .handle-icon {
    width: 24px;
    height: 24px;
    color: #38bdf8;
    filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.4));
    animation: pulse 3s infinite ease-in-out;
  }

  .handle-text {
    font-size: 0.85rem;
    writing-mode: vertical-rl;
    text-orientation: upright;
    letter-spacing: 0.3em;
    font-weight: 500;
    color: #cbd5e1;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  }
  
  @keyframes pulse {
    0%, 100% { opacity: 0.8; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.1); }
  }

  .filter-bar {
    position: fixed;
    right: 0; /* Stick to edge */
    top: 50%;
    transform: translateY(-50%);
    width: 60px; /* Collapsed width */
    max-height: 80vh;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-right: none; /* Merge with edge */
    border-radius: 24px 0 0 24px;
    padding: 1.5rem 0; /* Remove horizontal padding in collapsed state */
    z-index: 40;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    align-items: stretch;
    gap: 1rem;
    overflow: hidden; /* Hide content when collapsed */
    transition: width 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.3s;
    cursor: pointer;
  }

  .filter-bar:hover {
    width: 300px; /* Expanded width */
    background: rgba(15, 23, 42, 0.9);
    padding: 1.5rem; /* Restore padding */
    border-radius: 24px; /* Detach from edge slightly if desired, or keep 24px 0 0 24px */
    right: 1rem; /* Float out a bit */
    border-right: 1px solid rgba(255, 255, 255, 0.08);
  }

  /* Hide handle on hover */
  .filter-bar:hover .sidebar-handle {
    opacity: 0;
    pointer-events: none;
  }

  /* Content Visibility */
  .tag-filter,
  .actions-row {
    opacity: 0;
    transform: translateX(20px);
    transition: all 0.3s ease;
    pointer-events: none;
    width: 260px; /* Fixed width for content to prevent squishing */
  }

  .filter-bar:hover .tag-filter,
  .filter-bar:hover .actions-row {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
    transition-delay: 0.1s;
  }

  /* Scrollbar only when expanded */
  .filter-bar:hover {
    overflow-y: auto;
  }

  .filter-bar::-webkit-scrollbar {
    width: 4px;
  }
  
  .filter-bar::-webkit-scrollbar-track {
    background: transparent;
  }
  
  .filter-bar::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.2);
    border-radius: 4px;
  }

  .tag-filter {
    flex-direction: row;
    justify-content: flex-start;
    flex-wrap: wrap;
    margin-top: 1rem; /* Space for where handle was */
  }

  .tag-button {
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
    background: rgba(30, 41, 59, 0.6);
    width: auto;
    flex-grow: 0;
    white-space: nowrap;
  }
  
  .tag-button:hover {
    background: rgba(56, 189, 248, 0.15);
    color: #38bdf8;
    border-color: rgba(56, 189, 248, 0.3);
  }

  .tag-button.active {
    background: #38bdf8;
    color: #0f172a;
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.4);
  }

  .actions-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    margin-top: auto; /* Push to bottom if space allows */
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
  }

  .clear-filter-btn {
    width: 100%;
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.6rem;
  }
  
  .clear-filter-btn:hover {
    background: rgba(248, 113, 113, 0.15);
    color: #f87171;
  }

  .result-stats {
    text-align: center;
    font-size: 0.8rem;
    color: #64748b;
    white-space: nowrap;
  }
  
  .hero-section {
    padding-bottom: 2rem;
  }
}
