/* ==========================================================================
   NeuralMorph · AI Progressive Image Generator (60s Auto Engine Style)
   ========================================================================== */

:root {
  --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Cyber & Neural Tech Palette */
  --bg-deep: #07090e;
  --bg-card: rgba(14, 18, 28, 0.82);
  --border-subtle: rgba(255, 255, 255, 0.09);
  --border-glow: rgba(0, 242, 254, 0.35);

  --accent-cyan: #00f2fe;
  --accent-blue: #4facfe;
  --accent-purple: #9945ff;
  --accent-green: #00ffa3;
  --accent-gold: #ffb800;

  --text-primary: #ffffff;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-pill: 9999px;

  --shadow-neon: 0 0 30px rgba(0, 242, 254, 0.3);
  --shadow-card: 0 25px 60px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(255, 255, 255, 0.06);

  /* Animation variable updated by JavaScript */
  --scan-progress: 0%;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Ambient Backdrops */
.ambient-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(140px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
}

.glow-1 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(0, 242, 254, 0.45) 0%, transparent 70%);
  top: -100px;
  left: 10%;
}

.glow-2 {
  width: 550px;
  height: 550px;
  background: radial-gradient(circle, rgba(153, 69, 255, 0.4) 0%, transparent 70%);
  bottom: 0%;
  right: 5%;
}

.glow-3 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(79, 172, 254, 0.3) 0%, transparent 70%);
  top: 40%;
  left: -100px;
}

/* Shell Layout */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  padding: 0 20px;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0 18px;
  border-bottom: 1px solid var(--border-subtle);
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  box-shadow: 0 0 18px rgba(0, 242, 254, 0.4);
}

.brand-icon svg {
  width: 20px;
  height: 20px;
}

.brand-meta {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.4px;
  background: linear-gradient(135deg, #fff 40%, var(--accent-cyan) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-sub {
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--accent-cyan);
}

/* 60s Processing Capsule */
.process-capsule {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(0, 242, 254, 0.25);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-family: var(--font-mono);
  backdrop-filter: blur(10px);
}

.process-capsule.completed {
  border-color: var(--accent-green);
  background: rgba(0, 255, 163, 0.1);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-gold);
  box-shadow: 0 0 8px var(--accent-gold);
  animation: pulse 1.6s infinite;
}

.process-capsule.completed .pulse-dot {
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.3; transform: scale(0.85); }
}

.capsule-label {
  color: var(--text-secondary);
}

.capsule-timer {
  color: var(--accent-gold);
  font-weight: 700;
}

.process-capsule.completed .capsule-timer {
  color: var(--accent-green);
}

/* Main Workspace */
.workspace {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 0 40px;
}

.stage-card {
  width: 100%;
  max-width: 640px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: var(--shadow-card);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Prompt Card Box */
.prompt-box {
  background: rgba(0, 242, 254, 0.04);
  border: 1px solid rgba(0, 242, 254, 0.2);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.prompt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.prompt-tag {
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 800;
  color: var(--accent-cyan);
  letter-spacing: 1px;
}

.engine-tag {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.prompt-content {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.prompt-quote {
  font-size: 16px;
  font-weight: 900;
  color: var(--accent-cyan);
  line-height: 1;
}

.prompt-text {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  line-height: 1.45;
  letter-spacing: -0.2px;
}

/* Stage Header */
.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.status-indicator {
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-gold);
  background: rgba(255, 184, 0, 0.1);
  border: 1px solid rgba(255, 184, 0, 0.3);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  letter-spacing: 0.5px;
}

.status-indicator.completed {
  color: var(--accent-green);
  background: rgba(0, 255, 163, 0.1);
  border-color: rgba(0, 255, 163, 0.3);
}

.res-tag {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* ==========================================================================
   Image Viewport Frame (Fully Adapts to Native Image Ratio)
   ========================================================================== */

.image-viewport {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: max-height 0.3s ease, aspect-ratio 0.3s ease;
}

.layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.layer img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Base / Before Layer */
.layer-before {
  z-index: 1;
}

/* Target / After Layer: Revealed from top to bottom */
.layer-after {
  z-index: 2;
  /* Top to bottom clip-path mask controlled by CSS variable */
  clip-path: inset(0 0 calc(100% - var(--scan-progress, 0%)) 0);
  will-change: clip-path;
}

.layer-tag {
  position: absolute;
  top: 14px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 800;
  backdrop-filter: blur(8px);
  z-index: 5;
  pointer-events: none;
}

.tag-before {
  left: 14px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.tag-after {
  right: 14px;
  background: rgba(0, 242, 254, 0.2);
  color: var(--accent-cyan);
  border: 1px solid rgba(0, 242, 254, 0.4);
}

/* ==========================================================================
   Neural HUD Grid Overlay
   ========================================================================== */

.neural-hud-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 8;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.5s ease;
}

.neural-hud-overlay.hidden {
  opacity: 0;
}

.hud-crosshair {
  position: absolute;
  font-family: var(--font-mono);
  font-size: 18px;
  color: var(--accent-cyan);
  opacity: 0.65;
}

.hud-crosshair.top-left { top: 12px; left: 14px; }
.hud-crosshair.top-right { top: 12px; right: 14px; }
.hud-crosshair.bottom-left { bottom: 12px; left: 14px; }
.hud-crosshair.bottom-right { bottom: 12px; right: 14px; }

.hud-center-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 140px;
  height: 140px;
  border: 1px dashed rgba(0, 242, 254, 0.35);
  border-radius: 50%;
  animation: rotateRing 10s linear infinite;
}

.radar-sweep {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(0, 242, 254, 0.2) 0deg, transparent 60deg);
  animation: rotateRing 3s linear infinite;
}

@keyframes rotateRing {
  to { transform: rotate(360deg); }
}

.hud-text-badge {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(7, 9, 14, 0.85);
  border: 1px solid rgba(0, 242, 254, 0.3);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  gap: 8px;
  backdrop-filter: blur(8px);
}

.hud-spinner {
  width: 10px;
  height: 10px;
  border: 2px solid rgba(0, 242, 254, 0.3);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   Laser Scanning Beam (Laser Line Moving Top-to-Bottom)
   ========================================================================== */

.scanline-beam {
  position: absolute;
  left: 0;
  width: 100%;
  top: var(--scan-progress, 0%);
  transform: translateY(-50%);
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  will-change: top, opacity;
  transition: opacity 0.3s ease;
}

.scanline-beam.active {
  opacity: 1;
}

.beam-glow {
  width: 100%;
  height: 3px;
  background: #ffffff;
  box-shadow: 
    0 0 10px #ffffff,
    0 0 22px var(--accent-cyan),
    0 0 45px var(--accent-blue),
    0 0 80px var(--accent-purple);
  position: relative;
}

.beam-glow::after {
  content: '';
  position: absolute;
  left: 0;
  top: -20px;
  width: 100%;
  height: 40px;
  background: linear-gradient(180deg, 
    rgba(0, 242, 254, 0) 0%, 
    rgba(0, 242, 254, 0.35) 45%, 
    rgba(255, 255, 255, 0.5) 50%, 
    rgba(153, 69, 255, 0.35) 55%, 
    rgba(0, 242, 254, 0) 100%);
  pointer-events: none;
}

.beam-particles {
  position: absolute;
  top: -2px;
  left: 0;
  width: 100%;
  height: 7px;
  background: repeating-linear-gradient(90deg, transparent 0px, rgba(255,255,255,0.7) 4px, transparent 8px, rgba(0,242,254,0.5) 16px);
  background-size: 200% 100%;
  animation: beamParticleSweep 1.2s linear infinite;
  mix-blend-mode: screen;
}

@keyframes beamParticleSweep {
  0% { background-position: 0 0; }
  100% { background-position: -120px 0; }
}

.beam-label {
  position: absolute;
  right: 14px;
  top: -24px;
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 800;
  color: #000;
  background: var(--accent-cyan);
  padding: 2px 7px;
  border-radius: 3px;
  box-shadow: 0 0 12px var(--accent-cyan);
  letter-spacing: 0.5px;
}

/* ==========================================================================
   Split Slider (Before vs After comparison when completed)
   ========================================================================== */

.split-slider-wrap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 20;
  display: none;
  cursor: ew-resize;
}

.split-slider-wrap.active {
  display: block;
}

.split-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.handle-line {
  position: absolute;
  width: 2px;
  height: 100%;
  background: #ffffff;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
}

.handle-circle {
  width: 32px;
  height: 32px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  z-index: 2;
}

.handle-circle svg {
  width: 16px;
  height: 16px;
}

/* ==========================================================================
   Console Drawer & Progress Bar
   ========================================================================== */

.console-drawer {
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.console-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.console-prefix {
  color: var(--accent-cyan);
  font-weight: 800;
}

.console-text {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-track {
  width: 100%;
  height: 5px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-gold), var(--accent-cyan));
  box-shadow: 0 0 10px var(--accent-cyan);
  transition: width 0.3s ease;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.progress-percent-val {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent-cyan);
  font-family: var(--font-mono);
  text-shadow: 0 0 10px rgba(0, 242, 254, 0.4);
}

/* Controls */
.controls-bar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stage-footer-note {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.stage-footer-note svg {
  color: var(--accent-gold);
  flex-shrink: 0;
}

.action-buttons {
  display: flex;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 22px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all 0.2s ease;
}

.btn-generate-glow {
  flex: 1;
  background: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
  color: #050811;
  box-shadow: var(--shadow-neon);
}

.btn-generate-glow:hover {
  transform: translateY(-2px);
}

.btn-outline {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: #fff;
  padding: 14px 20px;
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* Footer */
.app-footer {
  padding: 24px 0 30px;
  text-align: center;
  border-top: 1px solid var(--border-subtle);
  font-size: 12px;
  color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(14, 18, 28, 0.95);
  border: 1px solid var(--accent-cyan);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  backdrop-filter: blur(14px);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
  white-space: nowrap;
  max-width: 90vw;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-10px);
}

/* ==========================================================================
   H5 Mobile Responsive Styles (Mobile / iOS Safari / Android)
   ========================================================================== */

@media (max-width: 640px) {
  body {
    min-height: 100dvh;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .app-shell {
    padding: 0 14px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }

  .app-header {
    padding: 14px 0 12px;
  }

  .brand-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
  }

  .brand-icon svg {
    width: 17px;
    height: 17px;
  }

  .brand-title {
    font-size: 15px;
  }

  .brand-sub {
    font-size: 9px;
    letter-spacing: 0.8px;
  }

  .workspace {
    padding: 10px 0 18px;
  }

  .stage-card {
    padding: 14px 12px;
    border-radius: 16px;
    gap: 12px;
  }

  .prompt-box {
    padding: 9px 12px;
    gap: 4px;
  }

  .prompt-tag, .engine-tag {
    font-size: 9px;
  }

  .prompt-text {
    font-size: 11.5px;
    line-height: 1.45;
  }

  .stage-header {
    gap: 6px;
  }

  .status-indicator {
    font-size: 10px;
    padding: 4px 10px;
  }

  .res-tag {
    font-size: 9.5px;
  }

  .image-viewport {
    border-radius: 12px;
  }

  /* Prevent page scroll while interacting with split slider */
  .split-slider-wrap {
    touch-action: none;
  }

  .split-handle {
    width: 32px;
    height: 32px;
  }

  .handle-circle {
    width: 30px;
    height: 30px;
  }

  .console-drawer {
    padding: 10px 12px;
    gap: 8px;
  }

  .console-header {
    font-size: 11px;
  }

  .console-text {
    font-size: 11px;
  }

  .progress-meta {
    font-size: 10px;
  }

  .progress-percent-val {
    font-size: 12px;
  }

  .controls-bar {
    gap: 10px;
  }

  .stage-footer-note {
    font-size: 11px;
  }

  .action-buttons {
    flex-direction: column;
    gap: 8px;
  }

  .btn {
    width: 100%;
    padding: 12px 16px;
    font-size: 14px;
  }

  .app-footer {
    padding: 16px 0 24px;
    font-size: 10.5px;
  }
}
