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

:root {
  --bg-dark: #050507;
  --bg-card: #0f0f12;
  --bg-hover: #1a1a1f;
  --accent-1: #c9a0dc;
  --accent-2: #ff6b8a;
  --accent-3: #00d4ff;
  --accent-gradient: linear-gradient(135deg, #c9a0dc 0%, #ff6b8a 50%, #00d4ff 100%);
  --text-primary: #e8e8ec;
  --text-secondary: #8a8a94;
  --border-color: #2a2a32;
}

body {
  font-family: 'JetBrains Mono', monospace;
  background-color: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

.film-grain {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%' height='100%' filter='url(%23noise)'/%3E%3C/svg%3E");
  animation: grainShift 0.5s steps(1) infinite;
}

@keyframes grainShift {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-1px, 1px); }
  50% { transform: translate(1px, -1px); }
  75% { transform: translate(-1px, -1px); }
}

.app-container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
  position: relative;
}

/* Header */
.header {
  text-align: center;
  padding: 40px 20px;
  margin-bottom: 40px;
  background: linear-gradient(180deg, rgba(201, 160, 220, 0.08) 0%, transparent 100%);
  border-radius: 16px;
  border: 1px solid var(--border-color);
  position: relative;
  overflow: hidden;
}

.header::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 200%;
  height: 2px;
  background: var(--accent-gradient);
  animation: shimmer 3s linear infinite;
}

@keyframes shimmer {
  0% { transform: translateX(0); }
  100% { transform: translateX(50%); }
}

.header-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-icon {
  position: relative;
  width: 56px;
  height: 56px;
}

.logo-icon svg {
  width: 100%;
  height: 100%;
  color: var(--accent-1);
}

.ai-sparkle {
  position: absolute;
  top: -8px;
  right: -8px;
  font-size: 20px;
  animation: sparkle 2s ease-in-out infinite;
}

@keyframes sparkle {
  0%, 100% { opacity: 1; transform: scale(1) rotate(0deg); }
  50% { opacity: 0.6; transform: scale(1.2) rotate(15deg); }
}

.title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(2.5rem, 8vw, 4rem);
  letter-spacing: 0.15em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: titleGlow 3s ease-in-out infinite alternate;
}

@keyframes titleGlow {
  0% { filter: drop-shadow(0 0 10px rgba(201, 160, 220, 0.3)); }
  100% { filter: drop-shadow(0 0 20px rgba(255, 107, 138, 0.4)); }
}

.tagline {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 300;
  letter-spacing: 0.1em;
}

/* Section Titles */
.section-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.4rem;
  letter-spacing: 0.2em;
  color: var(--text-secondary);
  margin-bottom: 20px;
  text-align: center;
}

/* Upload Section */
.upload-section {
  margin-bottom: 40px;
}

.upload-zone {
  border: 2px dashed var(--border-color);
  border-radius: 16px;
  padding: 60px 40px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  position: relative;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent-1);
  background: rgba(201, 160, 220, 0.05);
  transform: translateY(-2px);
}

.upload-icon-wrapper {
  position: relative;
}

.upload-icon {
  width: 80px;
  height: 80px;
  color: var(--text-secondary);
  opacity: 0.6;
}

.sparkle-overlay {
  position: absolute;
  top: -10px;
  right: -10px;
  font-size: 24px;
  animation: sparkle 2s ease-in-out infinite;
}

.upload-text {
  font-size: 1.1rem;
  color: var(--text-primary);
}

.upload-subtext {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.upload-formats {
  font-size: 0.75rem;
  color: var(--text-secondary);
  opacity: 0.6;
}

.api-badge {
  margin-top: 12px;
  padding: 6px 16px;
  background: rgba(255, 200, 0, 0.1);
  border: 1px solid rgba(255, 200, 0, 0.3);
  border-radius: 20px;
  font-size: 0.75rem;
  color: #ffc800;
}

/* Preview */
.preview-container {
  position: relative;
  max-width: 400px;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.preview-image {
  width: 100%;
  display: block;
}

.remove-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.remove-btn:hover {
  background: var(--accent-2);
  border-color: var(--accent-2);
}

/* Style Section */
.style-section {
  margin-bottom: 30px;
}

.style-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.style-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.style-card:hover {
  border-color: var(--accent-1);
  transform: translateY(-2px);
}

.style-card.active {
  border-color: var(--accent-1);
  background: rgba(201, 160, 220, 0.1);
  box-shadow: 0 0 20px rgba(201, 160, 220, 0.2);
}

.style-preview {
  width: 100%;
  aspect-ratio: 16/9;
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}

.warm-preview { background: linear-gradient(135deg, #d4a574 0%, #c98747 50%, #8b5a2b 100%); }
.cool-preview { background: linear-gradient(135deg, #4a90a4 0%, #2d6b77 50%, #1a4a5e 100%); }
.noir-preview { background: linear-gradient(135deg, #4a4a4a 0%, #1a1a1a 50%, #000000 100%); }
.vintage-preview { background: linear-gradient(135deg, #c9b896 0%, #a89070 50%, #7a6650 100%); }
.scifi-preview { background: linear-gradient(135deg, #00d4ff 0%, #7c3aed 50%, #ff006e 100%); }
.epic-preview { background: linear-gradient(135deg, #1a1a2e 0%, #4a4e69 50%, #9a8c98 100%); }

.style-name {
  font-size: 0.8rem;
  color: var(--text-primary);
  font-weight: 500;
}

.style-desc {
  font-size: 0.65rem;
  color: var(--text-secondary);
  line-height: 1.3;
}

/* Context Section */
.context-section {
  margin-bottom: 30px;
  text-align: center;
}

.context-input {
  width: 100%;
  max-width: 500px;
  padding: 14px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.context-input:focus {
  outline: none;
  border-color: var(--accent-1);
}

.context-input::placeholder {
  color: var(--text-secondary);
}

.context-hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 8px;
  opacity: 0.7;
}

/* Generate Button */
.generate-btn {
  display: block;
  width: 100%;
  max-width: 450px;
  margin: 0 auto 40px;
  padding: 20px 40px;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.5rem;
  letter-spacing: 0.15em;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-secondary);
  cursor: not-allowed;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.generate-btn.active {
  background: var(--accent-gradient);
  background-size: 200% 200%;
  animation: gradientMove 3s ease infinite;
  border-color: transparent;
  color: #fff;
  cursor: pointer;
}

@keyframes gradientMove {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.generate-btn.active:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 40px rgba(201, 160, 220, 0.4);
}

.generate-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none !important;
}

.btn-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
}

.loader-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Progress Section */
.progress-section {
  margin-bottom: 30px;
}

.progress-frames {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.progress-frame {
  width: 36px;
  height: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--text-secondary);
  transition: all 0.3s ease;
}

.progress-frame.complete {
  background: var(--accent-1);
  border-color: var(--accent-1);
  color: #fff;
}

.progress-frame.generating {
  border-color: var(--accent-2);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 138, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(255, 107, 138, 0); }
}

/* Grid Section */
.grid-section {
  margin-bottom: 40px;
}

.frames-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 30px;
}

.frame-wrapper {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border-color);
  animation: fadeIn 0.4s ease forwards;
  opacity: 0;
  transform: scale(0.95);
  background: var(--bg-card);
}

.frame-wrapper.generating {
  border-color: var(--accent-2);
  animation: fadeIn 0.4s ease forwards, pulse 1s ease-in-out infinite;
}

@keyframes fadeIn {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.frame-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.frame-wrapper:hover .frame-image {
  transform: scale(1.05);
}

.frame-loading {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.frame-spinner {
  width: 30px;
  height: 30px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent-1);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.frame-error {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.frame-error button {
  padding: 6px 14px;
  background: var(--accent-2);
  border: none;
  border-radius: 4px;
  color: #fff;
  font-family: inherit;
  font-size: 0.7rem;
  cursor: pointer;
}

.frame-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 24px;
  height: 24px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-primary);
}

.frame-label {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 4px;
  font-size: 0.55rem;
  color: var(--accent-1);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.frame-hover-text {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
  font-size: 0.7rem;
  text-align: center;
  color: var(--text-secondary);
  opacity: 0;
  transition: opacity 0.3s;
}

.frame-wrapper:hover .frame-hover-text {
  opacity: 1;
}

/* Action Bar */
.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

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

.action-btn svg {
  width: 18px;
  height: 18px;
}

.action-btn.primary {
  background: var(--accent-gradient);
  border: none;
  color: #fff;
}

.action-btn.primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 5px 20px rgba(201, 160, 220, 0.3);
}

.action-btn.secondary {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.action-btn.secondary:hover:not(:disabled) {
  border-color: var(--accent-1);
  color: var(--accent-1);
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeInFast 0.2s ease;
}

@keyframes fadeInFast {
  from { opacity: 0; }
  to { opacity: 1; }
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  color: var(--text-primary);
  font-size: 28px;
  cursor: pointer;
  transition: all 0.2s;
}

.lightbox-close:hover {
  border-color: var(--accent-1);
  color: var(--accent-1);
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 50px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  color: var(--text-primary);
  font-size: 32px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-nav:hover {
  border-color: var(--accent-1);
  color: var(--accent-1);
}

.lightbox-nav.prev { left: 20px; }
.lightbox-nav.next { right: 20px; }

.lightbox-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  max-width: 90vw;
  max-height: 85vh;
}

.lightbox-image {
  max-width: 100%;
  max-height: 65vh;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.lightbox-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

.lightbox-frame-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.frame-number {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.frame-type {
  color: var(--accent-1);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.lightbox-actions {
  display: flex;
  gap: 12px;
}

.regenerate-frame-btn,
.download-frame-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.regenerate-frame-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.regenerate-frame-btn:hover {
  border-color: var(--accent-1);
  color: var(--accent-1);
}

.download-frame-btn {
  background: var(--accent-gradient);
  color: #fff;
}

.download-frame-btn:hover {
  transform: translateY(-2px);
}

/* Footer */
.footer {
  padding: 30px 20px;
  text-align: center;
  border-top: 1px solid var(--border-color);
  margin-top: 40px;
}

.film-strip {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 15px 0;
}

.film-hole {
  width: 12px;
  height: 8px;
  background: var(--border-color);
  border-radius: 2px;
  animation: filmMove 2s ease-in-out infinite alternate;
}

@keyframes filmMove {
  0% { opacity: 0.5; }
  100% { opacity: 1; }
}

.footer-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.footer-text a {
  color: var(--accent-1);
  text-decoration: none;
}

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

.footer-powered {
  font-size: 0.7rem;
  color: var(--text-secondary);
  opacity: 0.7;
}

/* Responsive */
@media (max-width: 600px) {
  .app-container {
    padding: 15px;
  }

  .header {
    padding: 25px 15px;
  }

  .logo-section {
    flex-direction: column;
    gap: 10px;
  }

  .logo-icon {
    width: 44px;
    height: 44px;
  }

  .upload-zone {
    padding: 40px 20px;
  }

  .upload-icon {
    width: 60px;
    height: 60px;
  }

  .style-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .style-card {
    padding: 10px;
  }

  .style-desc {
    display: none;
  }

  .frames-grid {
    gap: 4px;
  }

  .frame-badge {
    width: 20px;
    height: 20px;
    font-size: 0.6rem;
    top: 4px;
    left: 4px;
  }

  .frame-label {
    display: none;
  }

  .action-bar {
    flex-direction: column;
  }

  .action-btn {
    width: 100%;
    justify-content: center;
  }

  .lightbox-nav.prev { left: 10px; }
  .lightbox-nav.next { right: 10px; }

  .lightbox-actions {
    flex-direction: column;
    width: 100%;
  }

  .regenerate-frame-btn,
  .download-frame-btn {
    width: 100%;
  }
}