/* ===== CSS RESET & VARIABLES ===== */
:root {
  /* Color Variables - Dark Theme (Default) */
  --primary: #e53e3e;
  --primary-dark: #c53030;
  --primary-light: #fc8181;
  --secondary: #3182ce;
  --accent: #ed8936;
  --danger: #f56565;
  --success: #38a169;
  --warning: #ecc94b;
  --info: #4299e1;
  
  /* Background Colors */
  --dark: #0f172a;
  --dark-light: #1e293b;
  --darker: #020617;
  --light: #f8fafc;
  
  /* Text Colors */
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  
  /* Border & Shadow */
  --border-color: rgba(255, 255, 255, 0.1);
  --border-radius-sm: 8px;
  --border-radius: 12px;
  --border-radius-lg: 16px;
  --border-radius-xl: 20px;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  
  /* Spacing */
  --space-xs: 0.5rem;
  --space-sm: 1rem;
  --space-md: 1.5rem;
  --space-lg: 2rem;
  --space-xl: 3rem;
  --space-2xl: 4rem;
  
  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 300ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 500ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Theme Override */
body.light-mode {
  --dark: #ffffff;
  --dark-light: #f1f5f9;
  --darker: #f8fafc;
  --light: #0f172a;
  
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  
  --border-color: rgba(0, 0, 0, 0.1);
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 10px 10px -5px rgba(0, 0, 0, 0.02);
  --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
}

/* ===== BASE STYLES ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--dark);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition);
}

/* ===== BACKGROUND ANIMATION ===== */
.background-animation {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  overflow: hidden;
}

.gradient-circle {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.15;
  animation: float 20s infinite alternate ease-in-out;
}

.circle-1 {
  width: min(500px, 80vw);
  height: min(500px, 80vw);
  background: linear-gradient(135deg, var(--primary), #ed8936);
  top: -150px;
  right: -100px;
  animation-delay: 0s;
}

.circle-2 {
  width: min(400px, 70vw);
  height: min(400px, 70vw);
  background: linear-gradient(135deg, var(--secondary), #4299e1);
  bottom: -150px;
  left: -100px;
  animation-delay: -5s;
  animation-direction: alternate-reverse;
}

.circle-3 {
  width: min(300px, 60vw);
  height: min(300px, 60vw);
  background: linear-gradient(135deg, var(--accent), #e53e3e);
  top: 40%;
  left: 70%;
  animation-delay: -10s;
}

@keyframes float {
  0%, 100% { 
    transform: translate(0, 0) scale(1); 
  }
  33% { 
    transform: translate(-40px, -40px) scale(1.1); 
  }
  66% { 
    transform: translate(40px, 40px) scale(0.9); 
  }
}

/* ===== NAVBAR ===== */
.navbar {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 1000;
  padding: 0.75rem 0;
}

body.light-mode .navbar {
  background: rgba(255, 255, 255, 0.85);
}

.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  padding: 0.5rem 0;
}

.logo i {
  font-size: 1.75rem;
  color: var(--primary);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo span {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: var(--transition);
  padding: 0.5rem 0.75rem;
  border-radius: var(--border-radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
}

.nav-links a:hover {
  color: var(--primary);
  background: rgba(229, 62, 62, 0.1);
}

.nav-links a i {
  font-size: 1rem;
}

/* Theme Toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  background: var(--dark-light);
  border: 1px solid var(--border-color);
  padding: 0.25rem;
  border-radius: 50px;
  cursor: pointer;
  position: relative;
  width: 56px;
  height: 28px;
  transition: var(--transition);
}

body.light-mode .theme-toggle {
  background: #e2e8f0;
}

.theme-toggle i {
  font-size: 0.875rem;
  color: var(--text-primary);
  z-index: 2;
  position: relative;
  padding: 0 0.25rem;
}

.theme-toggle .toggle-circle {
  position: absolute;
  left: 3px;
  top: 3px;
  width: 22px;
  height: 22px;
  background: var(--primary);
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: var(--shadow);
}

body.light-mode .theme-toggle .toggle-circle {
  transform: translateX(28px);
}

/* ===== MAIN CONTENT ===== */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1rem;
  min-height: calc(100vh - 140px);
}

/* ===== HERO SECTION ===== */
.hero-section {
  max-width: 800px;
  margin: 0 auto;
}

.hero-title {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 1rem;
  text-align: center;
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.highlight {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  position: relative;
}

.highlight::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  opacity: 0.5;
  border-radius: 2px;
}

.hero-subtitle {
  font-size: 1.125rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
  text-align: center;
}

/* ===== UPLOAD AREA ===== */
.upload-area {
  background: var(--dark-light);
  border: 3px dashed var(--border-color);
  border-radius: var(--border-radius-xl);
  padding: 3rem 1.5rem;
  margin: 2rem auto;
  position: relative;
  transition: var(--transition);
  cursor: pointer;
  text-align: center;
}

.upload-area:hover, .upload-area.dragover {
  border-color: var(--primary);
  background: rgba(229, 62, 62, 0.05);
  transform: translateY(-2px);
}

.upload-icon {
  font-size: 3rem;
  color: var(--primary);
  margin-bottom: 1.5rem;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.upload-area h3 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.upload-area p {
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.file-types {
  display: inline-block;
  background: rgba(255, 255, 255, 0.05);
  padding: 0.5rem 1rem;
  border-radius: 50px;
  font-size: 0.875rem;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

#imageInput {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* ===== PREVIEW SECTION ===== */
.preview-section {
  background: var(--dark-light);
  border-radius: var(--border-radius-xl);
  padding: 1.5rem;
  margin: 2rem 0;
}

.preview-section h3 {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--border-color);
}

.preview-section h3 i {
  color: var(--primary);
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  min-height: 150px;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state p {
  font-size: 1rem;
}

.image-item {
  position: relative;
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.image-item:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.image-item img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
}

.image-overlay {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  gap: 0.5rem;
}

.remove-btn {
  width: 32px;
  height: 32px;
  background: rgba(239, 68, 68, 0.9);
  color: white;
  border: none;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.875rem;
}

.remove-btn:hover {
  background: #dc2626;
  transform: scale(1.1);
}

.image-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.8);
  padding: 0.75rem;
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: white;
}

/* ===== CONTROLS ===== */
.controls {
  background: var(--dark-light);
  border-radius: var(--border-radius-xl);
  padding: 1.5rem;
  margin: 2rem 0;
}

.control-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.control-item {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.control-item label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.control-item label i {
  color: var(--primary);
}

.control-item select {
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 0.75rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: var(--transition);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23e53e3e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 16px;
  padding-right: 2.5rem;
}

.control-item select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(229, 62, 62, 0.1);
}

.control-item select option {
  background: var(--dark);
  color: var(--text-primary);
}

/* ===== BUTTONS ===== */
.action-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  padding: 0.875rem 1.75rem;
  border: none;
  border-radius: var(--border-radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: var(--transition);
  min-width: 160px;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 4px 15px rgba(229, 62, 62, 0.3);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(229, 62, 62, 0.4);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 2px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--primary);
  transform: translateY(-2px);
}

.btn i {
  font-size: 1rem;
}

/* ===== FEATURES ===== */
.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  margin-top: 3rem;
}

.feature {
  text-align: center;
  padding: 1.5rem;
  background: var(--dark-light);
  border-radius: var(--border-radius-lg);
  transition: var(--transition);
}

.feature:hover {
  transform: translateY(-5px);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
}

.feature i {
  font-size: 2rem;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.feature h4 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.feature p {
  color: var(--text-muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

/* ===== FOOTER ===== */
.footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  background: var(--dark);
  margin-top: auto;
}

.footer p {
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.footer i {
  color: var(--danger);
  margin: 0 0.25rem;
}

.footer a {
  color: var(--primary);
  text-decoration: none;
  transition: var(--transition);
}

.footer a:hover {
  color: var(--primary-light);
  text-decoration: underline;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--success);
  color: white;
  padding: 1rem 1.5rem;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-xl);
  transform: translateY(100px);
  opacity: 0;
  transition: var(--transition);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 350px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.error {
  background: var(--danger);
}

.toast.info {
  background: var(--info);
}

.toast.warning {
  background: var(--warning);
  color: #000;
}

.toast i {
  font-size: 1.25rem;
}

/* ===== LOADING STATE ===== */
.loading {
  position: relative;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-left: -10px;
  margin-top: -10px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== PROGRESS BAR ===== */
.progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 0.5rem;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  width: 0%;
  transition: width 0.3s ease;
  border-radius: 3px;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
  .hero-title {
    font-size: 2rem;
  }
  
  .hero-subtitle {
    font-size: 1rem;
  }
  
  .nav-links {
    gap: 0.5rem;
  }
  
  .nav-links a {
    padding: 0.5rem;
    font-size: 0.75rem;
  }
  
  .nav-links a span {
    display: none;
  }
  
  .control-group {
    grid-template-columns: 1fr;
  }
  
  .action-buttons {
    flex-direction: column;
  }
  
  .btn {
    width: 100%;
  }
  
  .features {
    grid-template-columns: 1fr;
  }
  
  .image-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
  
  .toast {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    max-width: none;
  }
}

@media (max-width: 480px) {
  .hero-title {
    font-size: 1.75rem;
  }
  
  .upload-area {
    padding: 2rem 1rem;
  }
  
  .upload-icon {
    font-size: 2.5rem;
  }
  
  .upload-area h3 {
    font-size: 1.25rem;
  }
  
  .preview-section {
    padding: 1rem;
  }
  
  .controls {
    padding: 1rem;
  }
  
  .feature {
    padding: 1rem;
  }
}

/* ===== PRINT STYLES ===== */
@media print {
  .navbar,
  .upload-area,
  .controls,
  .features,
  .footer,
  .theme-toggle,
  .action-buttons {
    display: none !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
  
  .main-content {
    padding: 0 !important;
  }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  
  .gradient-circle {
    animation: none !important;
  }
  
  .upload-icon {
    animation: none !important;
  }
}

/* ===== UTILITY CLASSES ===== */
.hidden {
  display: none !important;
}

.show {
  display: block !important;
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mt-5 { margin-top: 2rem; }

.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mb-5 { margin-bottom: 2rem; }