/**
 * Mixx Platform - Spatial Intro Styles
 * 30-second pre-login experience per Master Brief spec
 *
 * Animation principles:
 * - Panels: fade/drift animations (no Z-axis depth)
 * - AI: slow fade teleport (no gliding)
 * - All animations use transform + opacity only (GPU-friendly)
 */

/* ========================================
   VARIABLES
   ======================================== */
:root {
  --intro-ease: cubic-bezier(0.2, 0.9, 0.2, 1);
  --intro-ease-out: cubic-bezier(0.0, 0.0, 0.2, 1);
  --intro-panel-in: 1200ms;
  --intro-panel-out: 800ms;
  --intro-teleport-fade: 160ms;
  --intro-teleport-settle: 200ms;
  --intro-drift-distance: 30px;
}

/* ========================================
   INTRO LAYER
   ======================================== */
#intro-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  /* The page background in the person's theme; the intro's own photos
     cover it while it plays. */
  background: var(--color-bg);
  transition: background 800ms ease;
  overflow: hidden;
}

/* ========================================
   INTRO BACKGROUND SLIDESHOW
   Fullscreen images that crossfade evenly
   across the entire intro duration
   ======================================== */
#intro-bg-slideshow {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}

.intro-bg-slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 1.5s ease-in-out;
  will-change: opacity;
}

.intro-bg-slide.active {
  opacity: 1;
}

.intro-bg-slide img,
.intro-bg-slide video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Video slides: show video by default, hide fallback img */
.intro-bg-slide[data-has-video] .slide-video {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.intro-bg-slide[data-has-video] .slide-fallback {
  position: absolute;
  inset: 0;
  z-index: 0;
}

/* When video fails, JS adds .video-failed → hide video, show img */
.intro-bg-slide.video-failed .slide-video {
  display: none;
}

.intro-bg-slide.video-failed .slide-fallback {
  z-index: 1;
}

/* Dark overlay so AI + text remain readable */
.intro-bg-slide::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

/* Subtle slow zoom (Ken Burns) for visual life */
.intro-bg-slide.active img,
.intro-bg-slide.active video {
  animation: introBgZoom 10s ease-out forwards;
}

@keyframes introBgZoom {
  0% {
    transform: scale(1);
  }
  100% {
    transform: scale(1.06);
  }
}

#intro-layer.intro-visible {
  background: rgba(0, 0, 0, 0);
}

#intro-layer.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 200ms ease, visibility 0ms 200ms;
}

/* Scene container with deep perspective — above slideshow */
#intro-scene {
  position: absolute;
  inset: 0;
  z-index: 1;
  perspective: 1200px;
  perspective-origin: 50% 50%;
  transform-style: preserve-3d;
}

/* ========================================
   MIXX AI — Free-floating avatar that transitions
   between welcome → presenter → login dock
   ======================================== */
#mixx-ai {
  position: fixed;
  z-index: 90;
  pointer-events: none;
  opacity: 0;
  will-change: transform, opacity, left, top, width;
  filter: drop-shadow(0 16px 36px color-mix(in srgb, var(--color-accent) 25%, transparent));
  transform: translate(-50%, -50%);
}

/* Blink-fade transition between positions */
#mixx-ai.ai-blink-out {
  opacity: 0;
  transition: opacity 350ms ease-out;
}

#mixx-ai.ai-blink-in {
  opacity: 1;
  transition: opacity 400ms ease-in;
}

/* Welcome slot — reserves space in the welcome UI for the floating AI */
#welcome-ai-slot {
  width: clamp(90px, 10vw, 150px);
  height: clamp(90px, 10vw, 150px);
  margin: 0 auto 32px;
}

/* Welcome text + buttons sit above the AI layer */
#intro-ui #welcome-text,
#intro-ui #skip-btn,
#intro-ui #begin-btn {
  position: relative;
  z-index: 2;
}

/* ========================================
   MIXX AI PRESENTER — Bottom-left narrator overlay
   Layer 3: stays anchored while scenes change behind
   ======================================== */
.mixx-presenter {
  position: absolute;
  left: 5vw;
  bottom: 6vh;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 22px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: white;
  max-width: 540px;
  z-index: 80;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 400ms ease, transform 400ms var(--intro-ease);
}

.mixx-presenter.visible {
  opacity: 1;
  transform: translateY(0);
}

.mixx-presenter.hidden {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 300ms ease, transform 300ms ease;
}

/* AI icon slot inside presenter — AI floats over this */
.mixx-ai-icon {
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: 16px;
  background: #0a0a0a;
  position: relative;
}

/* AI talk pulse on icon */
.mixx-ai-icon.ai-talking {
  animation: presenterPulse 1.2s ease-in-out infinite;
}

@keyframes presenterPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-accent) 0%, transparent);
  }
  50% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--color-accent) 25%, transparent);
  }
}

/* Transcript text */
.mixx-transcript {
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: var(--font-size-lg);
  line-height: 1.45;
  font-weight: 400;
  max-width: 420px;
  color: rgba(231, 231, 234, 0.94);
}

.mixx-transcript p {
  margin: 0;
}

/* Control buttons cluster */
.mixx-controls {
  display: flex;
  gap: 10px;
  margin-left: auto;
  flex-shrink: 0;
}

.mixx-controls button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(231, 231, 234, 0.7);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.2s ease;
}

.mixx-controls button:hover {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(231, 231, 234, 0.95);
}

.mixx-controls button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--color-accent) 50%, transparent);
  outline-offset: 2px;
}

.mixx-controls #voice-toggle[aria-pressed="false"] {
  color: rgba(231, 231, 234, 0.35);
}

/* ========================================
   UI CONTROLS (WELCOME, BEGIN, SKIP)
   Centered on screen before intro starts
   ======================================== */
#intro-ui {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  will-change: opacity;
  transition: opacity 260ms ease, visibility 0ms linear 260ms;
}

#intro-ui.visible {
  opacity: 1;
  visibility: visible;
  transition: opacity 260ms ease;
}

#intro-ui.fade-out {
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

#welcome-text {
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: 1.2rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text);
  margin-bottom: 28px;
}

/* Sign in — the way in, and the first button anyone sees.
   (#skip-btn: it skips the intro.) The fill role, not a wash of the text role:
   --color-accent is for text, icons and borders; --color-accent-fill carries
   white at 5.1:1. The resting state is the one everybody reads. */
#skip-btn {
  display: block;
  width: 100%;
  height: 46px;
  padding: 0 28px;
  border-radius: 12px;
  border: 1px solid var(--color-accent-fill);
  background: var(--color-accent-fill);
  color: var(--color-on-fill);
  font-family: "DM Sans", system-ui, sans-serif;
  font-weight: 600;
  font-size: var(--font-size-base);
  letter-spacing: 0.1em;
  cursor: pointer;
  pointer-events: auto;
  transition: background var(--duration-fast, 160ms) var(--ease-sharp, ease),
    transform var(--duration-fast, 160ms) var(--ease-sharp, ease);
}

#skip-btn:hover {
  background: var(--color-accent-fill-hover);
  transform: translateY(-1px);
}

#skip-btn:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 3px;
}

#skip-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* "Watch the 30-second intro" — an opt-in text link under Sign in.
   (#begin-btn: it begins the intro.) The text role on the welcome layer's
   page background, above 4.5:1 in either theme; 44px tall for a thumb. */
#begin-btn {
  display: block;
  margin: 16px auto 0;
  min-height: 44px;
  padding: 0 12px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--color-text);
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: var(--font-size-md);
  letter-spacing: 0.02em;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  pointer-events: auto;
  transition: color var(--duration-fast, 160ms) var(--ease-sharp, ease);
}

#begin-btn:hover {
  color: var(--color-accent);
}

#begin-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

#begin-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Subtitle / voice toggle now inside .mixx-presenter — see above */

/* ========================================
   FADE/DRIFT ANIMATIONS
   Panels fade in with subtle directional drift from corners
   ======================================== */

/* ========================================
   LOGIN CARD REVEAL
   ======================================== */
.login-card.intro-hidden {
  opacity: 0;
  transform: scale(0.98) translateZ(-40px);
  pointer-events: none;
  transition: none;
}

.login-card.intro-reveal {
  opacity: 1;
  transform: scale(1) translateZ(0);
  pointer-events: auto;
  transition: opacity 600ms ease, transform 600ms var(--intro-ease);
}

/* AI docked over login card — stays position:fixed, sized by JS */
#mixx-ai.docked {
  width: 72px !important;
  height: auto;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 12px 24px color-mix(in srgb, var(--color-accent) 35%, transparent));
  opacity: 1;
  z-index: 100;
}

/* ========================================
   MAGIC FLASH - One-time effect after docking
   Same effect as Mixx AI button hover
   ======================================== */

/* Keyframes for magic glow burst with brightness flash */
@keyframes loginMagicGlow {
  0% {
    filter: drop-shadow(0 12px 24px color-mix(in srgb, var(--color-accent) 35%, transparent)) brightness(1);
  }
  15% {
    filter: drop-shadow(0 0 15px rgba(255, 255, 255, 0.8))
            drop-shadow(0 0 35px rgba(139, 92, 246, 0.9))
            drop-shadow(0 0 60px color-mix(in srgb, var(--color-accent) 70%, transparent))
            brightness(1.3);
  }
  40% {
    filter: drop-shadow(0 0 8px color-mix(in srgb, var(--color-accent) 50%, transparent))
            drop-shadow(0 0 45px rgba(139, 92, 246, 0.6))
            drop-shadow(0 20px 50px color-mix(in srgb, var(--color-accent) 50%, transparent))
            brightness(1.15);
  }
  100% {
    filter: drop-shadow(0 12px 24px color-mix(in srgb, var(--color-accent) 35%, transparent)) brightness(1);
  }
}

/* Keyframes for scale pop with bounce */
@keyframes loginMagicPop {
  0% {
    transform: translate(-50%, -50%) scale(1);
  }
  25% {
    transform: translate(-50%, -50%) scale(1.18) translateY(-6px);
  }
  50% {
    transform: translate(-50%, -50%) scale(1.05) translateY(-2px);
  }
  75% {
    transform: translate(-50%, -50%) scale(1.08);
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
  }
}

/* Magic flash class - applied after docking */
#mixx-ai.docked.magic-flash {
  animation:
    loginMagicGlow 1.2s ease-out forwards,
    loginMagicPop 0.9s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ========================================
   RESPONSIVE PANELS
   Prevent overlap with center content on small screens
   ======================================== */

@media (max-width: 768px) {

  /* Presenter becomes full-width lower caption on mobile */
  .mixx-presenter {
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    border-radius: 0;
    padding: 14px 16px;
  }

  /* Kept, not hidden: once "Start Intro" is tapped, Skip here is the only
     way out of a minute-long intro. Hiding it committed every phone user to
     the whole thing. */
  .mixx-controls {
    align-self: flex-start;
  }
}

/* Fingertip-sized on touch screens, whatever the width. */
@media (pointer: coarse) {
  .mixx-controls button {
    width: 44px;
    height: 44px;
  }

  /* 32px was too small to hit reliably with a thumb (audit #32). */
  #begin-btn {
    min-height: 44px;
  }
}

/* Location markers on globe */

@keyframes markerPulse {
  0%, 100% {
    transform: translateZ(55px) scale(1);
    opacity: 1;
  }
  50% {
    transform: translateZ(55px) scale(1.4);
    opacity: 0.7;
  }
}

/* ========================================
   REDUCED MOTION
   ======================================== */
@media (prefers-reduced-motion: reduce) {
  :root {
    --intro-panel-in: 1ms;
    --intro-panel-out: 1ms;
    --intro-teleport-fade: 1ms;
    --intro-teleport-settle: 1ms;
  }

  #mixx-ai,
  #intro-ui,
  .login-card {
    animation: none !important;
    transition: opacity 150ms ease !important;
  }

  #mixx-ai.ai-talking {
    animation: none !important;
  }

  .intro-bg-slide img,
  .intro-bg-slide video {
    animation: none !important;
  }

  #skip-btn:hover {
    transform: none;
  }

  .mixx-presenter {
    transition: opacity 150ms ease !important;
    transform: none !important;
  }

  .mixx-ai-icon.ai-talking {
    animation: none !important;
  }

  .intro-bg-slide {
    transition-duration: 0.01ms !important;
  }
}
