:root {
  --bg-color: #0f1115;
  --card-bg: #181b21;
  --text-primary: #ffffff;
  --text-secondary: #9ca3af;
  --accent-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  --accent-hover: linear-gradient(135deg, #4338ca 0%, #6d28d9 100%);
  --border-color: #2d3139;
  --success-color: #10b981;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 1.125rem;
  background-color: var(--bg-color);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem;
}

.container {
  width: 100%;
  max-width: 1024px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 0;
}

h1 {
  font-size: 4rem;
  font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
  letter-spacing: -0.05em;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1rem;
  max-width: 600px;
  margin: 0 auto;
}

/* Hide elements when files are present */
body.has-files .subtitle,
body.has-files .features-list {
  display: none;
}

/* Reduce header margin when files are present */
body.has-files header {
  margin-bottom: 0.5rem;
}

/* Reduce app-card padding when files are present */
body.has-files .app-card {
  padding-top: 1rem;
}

.features-list {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.feature-tag {
  background: rgba(255, 255, 255, 0.05);
  padding: 0.75rem 1.5rem;
  border-radius: 9999px;
  font-size: 1.1rem;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  transition: all 0.3s ease;
  cursor: default;
}

.feature-tag:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
  color: var(--text-primary);
  border-color: #7c3aed;
}

/* Main Card */
.app-card {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 1.5rem;
  padding: 1.5rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Upload Area */
/* Upload Area Container (Unified) */
.drop-zone {
  border: 2px dashed var(--border-color);
  border-radius: 1rem;
  padding: 1rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  background-color: rgba(255, 255, 255, 0.02);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: #7c3aed;
  background-color: rgba(124, 58, 237, 0.05);
}

.upload-prompt {
  padding: 2rem 0;
  pointer-events: none;
  /* Let clicks pass through to drop-zone */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.upload-prompt svg {
  width: 3rem;
  height: 3rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.upload-prompt p {
  margin: 0;
  color: var(--text-secondary);
}

.upload-prompt .text-sm {
  font-size: 0.875rem;
}

.upload-prompt .text-xs {
  font-size: 0.75rem;
  opacity: 0.7;
}

.upload-prompt .text-indigo-400 {
  color: #818cf8;
}

/* Results Grid */
.results-container {
  display: grid;
  gap: 1rem;
  width: 100%;
}

@media (min-width: 1200px) {
  .results-container {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 768px) and (max-width: 1199px) {
  .results-container {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 767px) {
  .results-container {
    grid-template-columns: 1fr;
  }
}

.drop-icon {
  width: 96px;
  height: 96px;
  margin-bottom: 1.5rem;
  opacity: 0.8;
}

.drop-text h3 {
  font-size: 2rem;
  margin-bottom: 1rem;
}

.drop-text p {
  color: var(--text-secondary);
  font-size: 1.2rem;
}

/* Global Actions */
.global-actions {
  display: flex;
  padding: 0 1rem;
  margin-bottom: 0.25rem;
  /* Space below button */
}

/* Results Container (Grid) */
.results-container {
  display: grid;
  /* Auto-fit columns: nice minimum width, stretch to fill */
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  width: 100%;
}

@media (min-width: 1200px) {
  .container {
    max-width: 1400px;
    /* Keep container expansion for large screens */
  }
}

/* Image Card */
.image-card {
  background-color: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: fadeIn 0.3s ease-out;
  height: 100%;
  /* Ensure consistent height in row */
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Canvas Wrapper inside Card */
.image-wrapper {
  position: relative;
  background-color: #000;
  border-radius: 0.5rem;
  overflow: hidden;
  /* Checkboard pattern */
  background-image:
    linear-gradient(45deg, #1f2329 25%, transparent 25%),
    linear-gradient(-45deg, #1f2329 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1f2329 75%),
    linear-gradient(-45deg, transparent 75%, #1f2329 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4 / 3;
  /* Fixed aspect ratio wrapper */
}

.image-wrapper canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

/* Card Controls */
.card-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
  margin-top: auto;
  /* Push to bottom */
}

.card-options {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
}

.control-group {
  width: 100%;
}

.control-group select {
  width: 100%;
  padding: 0.5rem;
  font-size: 0.9rem;
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.slider-group label {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.slider-group input[type="range"] {
  width: 100%;
}

.actions {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}

.actions .btn {
  flex: 1;
  justify-content: center;
  padding: 0.5rem;
  font-size: 0.9rem;
}

#alphaValue {
  color: var(--text-primary);
  font-weight: 600;
  margin-left: 0.25rem;
}

.btn {
  padding: 1rem 2rem;
  border-radius: 0.75rem;
  font-weight: 600;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  outline: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn svg {
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
  stroke-width: 2px;
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4);
}

.btn-secondary {
  background-color: rgba(255, 255, 255, 0.1);
  color: white;
}

.btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.15);
}

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

select {
  background-color: var(--bg-color);
  color: white;
  border: 1px solid var(--border-color);
  padding: 1rem 1.5rem;
  border-radius: 0.75rem;
  font-size: 1.1rem;
  outline: none;
}

/* Comparison Overlay */
.comparison-overlay {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  padding: 0.5rem 1rem;
  border-radius: 2rem;
  font-size: 0.9rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 5;
}

.image-wrapper:hover .comparison-overlay {
  opacity: 1;
}

/* Loading Overlay */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 17, 21, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  backdrop-filter: blur(4px);
  display: none;
  /* Toggled via JS */
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-left-color: #7c3aed;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

footer {
  margin-top: auto;
  text-align: center;
  color: var(--text-secondary);
  font-size: 1.1rem;
  padding: 2rem 0;
}

footer a {
  color: #7c3aed;
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

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



/* Lightbox */
.lightbox {
  display: none;
  position: fixed;
  z-index: 9999;
  padding-top: 50px;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(5px);
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.lightbox-content {
  margin: auto;
  display: block;
  max-width: 90%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  user-select: none;
  -webkit-user-select: none;
}

.lightbox-caption {
  margin: 1rem auto;
  display: block;
  width: 80%;
  max-width: 700px;
  text-align: center;
  color: #ccc;
  padding: 10px 0;
}

.lightbox-close {
  position: absolute;
  top: 15px;
  right: 35px;
  color: #f1f1f1;
  font-size: 40px;
  font-weight: bold;
  transition: 0.3s;
  cursor: pointer;
  z-index: 1001;
}

.lightbox-close:hover,
.lightbox-close:focus {
  color: #bbb;
  text-decoration: none;
  cursor: pointer;
}