/* ================================================================
   FACE TRANSFORM LOADER - ThumbnailBuilder v2
   "AI Transforming Your Face Into Viral Thumbnails"
   ================================================================ */

:root {
  /* Brand Colors */
  --ftl-bg: #0a0a12;
  --ftl-surface: rgba(15, 15, 25, 0.95);
  --ftl-primary: #8B5CF6;
  --ftl-secondary: #06B6D4;
  --ftl-accent: #F59E0B;
  --ftl-success: #10B981;
  --ftl-glow: #A78BFA;

  /* Text */
  --ftl-text: #FFFFFF;
  --ftl-text-dim: #94A3B8;
  --ftl-text-muted: #64748B;

  /* Animation Timings */
  --ftl-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ftl-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ==========================================
   KEYFRAME ANIMATIONS
   ========================================== */

@keyframes ftlFaceFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.02); }
}

@keyframes ftlFaceGlow {
  0%, 100% {
    box-shadow:
      0 0 30px rgba(139, 92, 246, 0.4),
      0 0 60px rgba(139, 92, 246, 0.2),
      inset 0 0 40px rgba(139, 92, 246, 0.1);
  }
  50% {
    box-shadow:
      0 0 50px rgba(139, 92, 246, 0.6),
      0 0 100px rgba(139, 92, 246, 0.4),
      inset 0 0 60px rgba(139, 92, 246, 0.2);
  }
}

@keyframes ftlMorphPulse {
  0% { transform: scale(1) rotate(0deg); opacity: 0.3; }
  25% { transform: scale(1.1) rotate(90deg); opacity: 0.5; }
  50% { transform: scale(1.2) rotate(180deg); opacity: 0.3; }
  75% { transform: scale(1.1) rotate(270deg); opacity: 0.5; }
  100% { transform: scale(1) rotate(360deg); opacity: 0.3; }
}

@keyframes ftlScanLine {
  0% { top: 0%; opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { top: 100%; opacity: 0; }
}

@keyframes ftlParticleRise {
  0% {
    transform: translateY(0) translateX(var(--particle-x)) scale(0);
    opacity: 0;
  }
  20% { opacity: 1; transform: translateY(-20px) translateX(var(--particle-x)) scale(1); }
  80% { opacity: 1; }
  100% {
    transform: translateY(-120px) translateX(calc(var(--particle-x) * 2)) scale(0.5);
    opacity: 0;
  }
}

@keyframes ftlRingExpand {
  0% { transform: scale(0.8); opacity: 0.8; }
  100% { transform: scale(2); opacity: 0; }
}

@keyframes ftlSparkle {
  0%, 100% { transform: scale(1) rotate(0deg); opacity: 1; }
  50% { transform: scale(1.5) rotate(180deg); opacity: 0.5; }
}

@keyframes ftlStageEnter {
  0% { transform: translateY(10px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

@keyframes ftlProgressPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@keyframes ftlSuccessExplode {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

@keyframes ftlThumbnailReveal {
  0% {
    clip-path: inset(0 100% 0 0);
    opacity: 0;
  }
  100% {
    clip-path: inset(0 0 0 0);
    opacity: 1;
  }
}

@keyframes ftlTypewriter {
  from { width: 0; }
  to { width: 100%; }
}

/* ==========================================
   CONTAINER & OVERLAY
   ========================================== */

.ftl-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: var(--ftl-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s var(--ftl-ease), visibility 0.4s;
}

.ftl-overlay--visible {
  opacity: 1;
  visibility: visible;
}

.ftl-overlay--hiding {
  opacity: 0;
}

.ftl-container {
  width: 100%;
  max-width: 500px;
  padding: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

/* ==========================================
   FACE TRANSFORMATION AREA
   ========================================== */

.ftl-face-area {
  position: relative;
  width: 180px;
  height: 180px;
}

/* The actual face image */
.ftl-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  animation: ftlFaceFloat 4s ease-in-out infinite, ftlFaceGlow 3s ease-in-out infinite;
  border: 3px solid rgba(139, 92, 246, 0.5);
}

.ftl-face__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Placeholder if no face image */
.ftl-face__placeholder {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--ftl-primary) 0%, var(--ftl-secondary) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ftl-face__placeholder-icon {
  width: 60px;
  height: 60px;
  color: rgba(255, 255, 255, 0.8);
}

/* Morphing rings around face */
.ftl-morph-ring {
  position: absolute;
  inset: -20px;
  border: 2px solid transparent;
  border-radius: 50%;
  border-top-color: var(--ftl-primary);
  border-bottom-color: var(--ftl-secondary);
  animation: ftlMorphPulse 4s linear infinite;
}

.ftl-morph-ring--2 {
  inset: -35px;
  animation-delay: -1s;
  border-top-color: var(--ftl-secondary);
  border-bottom-color: var(--ftl-accent);
}

.ftl-morph-ring--3 {
  inset: -50px;
  animation-delay: -2s;
  border-top-color: var(--ftl-accent);
  border-bottom-color: var(--ftl-primary);
}

/* Scan line effect */
.ftl-scan-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--ftl-primary) 20%,
    var(--ftl-secondary) 50%,
    var(--ftl-primary) 80%,
    transparent 100%
  );
  box-shadow: 0 0 20px var(--ftl-primary);
  animation: ftlScanLine 2s linear infinite;
  opacity: 0;
}

.ftl-overlay--scanning .ftl-scan-line {
  opacity: 1;
}

/* Expanding rings on complete */
.ftl-expand-ring {
  position: absolute;
  inset: 0;
  border: 2px solid var(--ftl-success);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}

.ftl-overlay--complete .ftl-expand-ring {
  animation: ftlRingExpand 1.5s var(--ftl-ease) forwards;
}

.ftl-overlay--complete .ftl-expand-ring:nth-child(2) {
  animation-delay: 0.2s;
}

.ftl-overlay--complete .ftl-expand-ring:nth-child(3) {
  animation-delay: 0.4s;
}

/* Particles */
.ftl-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

.ftl-particle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ftl-primary);
  bottom: 50%;
  left: 50%;
  opacity: 0;
}

.ftl-overlay--active .ftl-particle {
  animation: ftlParticleRise 3s linear infinite;
}

.ftl-particle:nth-child(1) { --particle-x: -30px; animation-delay: 0s; background: var(--ftl-primary); }
.ftl-particle:nth-child(2) { --particle-x: 25px; animation-delay: 0.3s; background: var(--ftl-secondary); }
.ftl-particle:nth-child(3) { --particle-x: -15px; animation-delay: 0.6s; background: var(--ftl-accent); }
.ftl-particle:nth-child(4) { --particle-x: 40px; animation-delay: 0.9s; background: var(--ftl-primary); }
.ftl-particle:nth-child(5) { --particle-x: -45px; animation-delay: 1.2s; background: var(--ftl-secondary); }
.ftl-particle:nth-child(6) { --particle-x: 10px; animation-delay: 1.5s; background: var(--ftl-success); }
.ftl-particle:nth-child(7) { --particle-x: -25px; animation-delay: 1.8s; background: var(--ftl-accent); }
.ftl-particle:nth-child(8) { --particle-x: 35px; animation-delay: 2.1s; background: var(--ftl-primary); }

/* ==========================================
   STAGE INDICATOR
   ========================================== */

.ftl-stages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

.ftl-stage {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  opacity: 0.4;
  transform: translateX(-10px);
  transition: all 0.4s var(--ftl-ease);
}

.ftl-stage--active {
  opacity: 1;
  transform: translateX(0);
  background: rgba(139, 92, 246, 0.1);
  border-color: rgba(139, 92, 246, 0.3);
}

.ftl-stage--complete {
  opacity: 0.7;
  transform: translateX(0);
}

.ftl-stage__icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ftl-text-dim);
  flex-shrink: 0;
  transition: all 0.3s var(--ftl-ease);
}

.ftl-stage--active .ftl-stage__icon {
  background: linear-gradient(135deg, var(--ftl-primary), var(--ftl-secondary));
  color: white;
  animation: ftlProgressPulse 1.5s ease-in-out infinite;
}

.ftl-stage--complete .ftl-stage__icon {
  background: var(--ftl-success);
  color: white;
}

.ftl-stage__icon svg {
  width: 18px;
  height: 18px;
}

.ftl-stage__content {
  flex: 1;
  min-width: 0;
}

.ftl-stage__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ftl-text);
  margin: 0;
}

.ftl-stage--active .ftl-stage__title {
  color: var(--ftl-glow);
}

.ftl-stage__detail {
  font-size: 12px;
  color: var(--ftl-text-muted);
  margin: 2px 0 0 0;
  overflow: hidden;
  white-space: nowrap;
}

.ftl-stage--active .ftl-stage__detail {
  color: var(--ftl-text-dim);
}

/* ==========================================
   PROGRESS BAR
   ========================================== */

.ftl-progress {
  width: 100%;
  max-width: 320px;
}

.ftl-progress__track {
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.ftl-progress__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--ftl-primary), var(--ftl-secondary), var(--ftl-accent));
  background-size: 200% 100%;
  border-radius: 3px;
  width: 0%;
  transition: width 0.5s var(--ftl-ease);
  position: relative;
}

.ftl-progress__fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
  animation: ftlProgressPulse 1.5s ease-in-out infinite;
}

.ftl-progress__text {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: var(--ftl-text-dim);
}

.ftl-progress__percent {
  font-weight: 600;
  color: var(--ftl-text);
  font-variant-numeric: tabular-nums;
}

.ftl-progress__eta {
  color: var(--ftl-text-muted);
}

/* ==========================================
   MESSAGE / STATUS
   ========================================== */

.ftl-message {
  text-align: center;
  padding: 0 20px;
}

.ftl-message__main {
  font-size: 18px;
  font-weight: 600;
  color: var(--ftl-text);
  margin: 0 0 4px 0;
}

.ftl-message__sub {
  font-size: 13px;
  color: var(--ftl-text-muted);
  margin: 0;
}

/* ==========================================
   CANCEL BUTTON
   ========================================== */

.ftl-cancel {
  padding: 10px 24px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: var(--ftl-text-dim);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ftl-cancel:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--ftl-text);
  border-color: rgba(255, 255, 255, 0.2);
}

/* ==========================================
   SUCCESS STATE
   ========================================== */

.ftl-success {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: ftlSuccessExplode 0.5s var(--ftl-spring);
}

.ftl-overlay--complete .ftl-success {
  display: flex;
}

.ftl-overlay--complete .ftl-stages,
.ftl-overlay--complete .ftl-progress,
.ftl-overlay--complete .ftl-cancel {
  display: none;
}

.ftl-success__icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ftl-success), #059669);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 40px rgba(16, 185, 129, 0.5);
}

.ftl-success__icon svg {
  width: 40px;
  height: 40px;
  color: white;
}

.ftl-success__text {
  font-size: 20px;
  font-weight: 700;
  color: var(--ftl-text);
}

/* ==========================================
   THUMBNAIL PREVIEW (shown on success)
   ========================================== */

.ftl-preview {
  display: none;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 16/9;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: ftlThumbnailReveal 0.8s var(--ftl-ease) forwards;
}

.ftl-overlay--complete .ftl-preview {
  display: block;
}

.ftl-preview__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ==========================================
   ERROR STATE
   ========================================== */

.ftl-error {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.ftl-overlay--error .ftl-error {
  display: flex;
}

.ftl-overlay--error .ftl-stages,
.ftl-overlay--error .ftl-progress,
.ftl-overlay--error .ftl-cancel,
.ftl-overlay--error .ftl-message {
  display: none;
}

.ftl-error__icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #EF4444;
}

.ftl-error__icon svg {
  width: 30px;
  height: 30px;
}

.ftl-error__title {
  font-size: 18px;
  font-weight: 600;
  color: var(--ftl-text);
  margin: 0;
}

.ftl-error__message {
  font-size: 14px;
  color: var(--ftl-text-muted);
  margin: 0;
  max-width: 300px;
}

.ftl-error__retry {
  padding: 12px 28px;
  background: linear-gradient(135deg, var(--ftl-primary), var(--ftl-secondary));
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ftl-error__retry:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 30px rgba(139, 92, 246, 0.4);
}

/* ==========================================
   RESPONSIVE
   ========================================== */

@media (max-width: 480px) {
  .ftl-container {
    padding: 24px;
    gap: 24px;
  }

  .ftl-face-area {
    width: 140px;
    height: 140px;
  }

  .ftl-morph-ring { inset: -15px; }
  .ftl-morph-ring--2 { inset: -25px; }
  .ftl-morph-ring--3 { inset: -35px; }

  .ftl-stage {
    padding: 10px 12px;
    gap: 10px;
  }

  .ftl-stage__icon {
    width: 28px;
    height: 28px;
  }

  .ftl-stage__title {
    font-size: 13px;
  }

  .ftl-message__main {
    font-size: 16px;
  }
}

/* ==========================================
   ACCESSIBILITY
   ========================================== */

.ftl-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .ftl-face,
  .ftl-morph-ring,
  .ftl-scan-line,
  .ftl-particle,
  .ftl-expand-ring,
  .ftl-progress__fill::after {
    animation: none;
  }

  .ftl-stage {
    transition: none;
  }
}
