/**
 * SP-054 + SP-063: Page Load Transitions — Bento Box Entrance
 *
 * Hides staggered rendering during page load.
 * Once app.js init() completes, sections animate in with
 * bento-box puzzle-tile slides in a coordinated cascade.
 *
 * Lifecycle:
 *   1. <body class="page-loading"> — app-container is invisible
 *   2. Splash animation plays over invisible content
 *   3. init() completes — splash.js calls revealSections()
 *   4. body.page-loading removed — sections slide into view
 *   5. Each section has a stagger delay for cascade effect
 *   6. After panels settle, calendar day cells flip in (flipBoard)
 *
 * GPU-accelerated: uses opacity + transform only.
 * Respects prefers-reduced-motion.
 */

/* ── Hide everything during load ── */

body.page-loading .app-container {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Ensure visibility restores with opacity on reveal */
.app-container {
  visibility: visible;
}

/* ── Section pre-reveal state ──
   SP-138: Panel entrance animations DEACTIVATED.
   Panels start visible (no off-screen transforms).
   The .section-revealed class is still added by splash.js/revealSections()
   but triggers no transition — panels appear instantly. */

.section-animate {
  opacity: 0;
  /* SP-138: No will-change, no box-shadow, no directional transforms */
}

/* SP-138: Directional transforms removed — panels appear in-place */
.section-animate.anim-header { }
.section-animate.anim-slide-left { }
.section-animate.anim-slide-right { }
.section-animate.anim-slide-bottom { }
.section-animate.anim-fade-up { }
.section-animate.anim-fade { }

/* ── Revealed state ──
   SP-138: Instant reveal — no transition duration, no stagger delays.
   Panels appear immediately when .section-revealed is added. */

.section-animate.section-revealed {
  opacity: 1;
  transform: none;
  box-shadow: none;
  /* SP-138: 0ms transitions — instant appearance */
  transition: none;
}

/* SP-138: Stagger delays zeroed — all panels appear simultaneously */
.section-animate.section-revealed.stagger-1,
.section-animate.section-revealed.stagger-2,
.section-animate.section-revealed.stagger-3,
.section-animate.section-revealed.stagger-4,
.section-animate.section-revealed.stagger-5,
.section-animate.section-revealed.stagger-6,
.section-animate.section-revealed.stagger-7,
.section-animate.section-revealed.stagger-8 { transition-delay: 0ms; }

/* SP-138: Child cascade deactivated — children appear instantly */
.section-revealed .cascade-child {
  opacity: 1;
  transform: none;
  animation: none;
}

/* @keyframes cascadeIn — SP-138: deactivated (kept for reference)
@keyframes cascadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
*/

/* ══════════════════════════════════════════════════════════
   SP-135: 3-Wave Grouped Entrance Choreography
   ══════════════════════════════════════════════════════════

   Wave 1 (0ms):     Shell panels slide in (existing stagger system above)
                      + Calendar flip-board fires simultaneously
   Wave 2 (~2400ms): Domain cards + Objective cards cascade in
   Wave 3 (~4800ms): Generate controls fade-up + Workflow indicator L->R

   Orchestrated by splash.js _launchWaves(). Classes added via JS:
     .wave-orchestrated  — on .main-content when waves start
     .wave-2-live        — trigger for Wave 2 items
     .wave-3-live        — trigger for Wave 3 items
     .wave-2-item        — on each domain-card and objective-card
     .wave-3-item        — on generate control children + workflow steps
     .wave-3-container   — on .generate-controls
     .wave-3-workflow    — on #workflowIndicator
*/

/* ══════════════════════════════════════════════════════════
   SP-138: Wave 2/3 entrance animations DEACTIVATED.
   All wave items appear instantly — no cascade, no fade-up,
   no workflow L->R reveal. Classes may still be added by JS
   but produce no visual animation.
   ══════════════════════════════════════════════════════════ */

/* SP-138: Wave 2 items visible immediately (no pre-state hide) */
.wave-2-item {
  opacity: 1;
  transform: none;
}

.wave-2-live .wave-2-item {
  animation: none;
}

/* SP-138: Wave 3 items visible immediately */
.wave-3-container > .wave-3-item {
  opacity: 1;
  transform: none;
}

.wave-3-live .wave-3-container > .wave-3-item {
  animation: none;
}

.wave-3-workflow .wave-3-item {
  opacity: 1;
  transform: none;
}

.wave-3-live .wave-3-workflow .wave-3-item {
  animation: none;
}

/* @keyframes fadeUp — SP-138: deactivated
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
*/

/* @keyframes slideInRight — SP-138: deactivated
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0); }
}
*/

/* SP-135: Post-wave re-render guard — still active for safety */
.waves-complete .wave-2-item,
.waves-complete .wave-3-container > .wave-3-item,
.waves-complete .wave-3-workflow .wave-3-item {
  opacity: 1 !important;
  transform: none !important;
  animation: none !important;
}

/* ── Calendar flip-board effect (SP-063) ──
   After panels settle, calendar day cells flip in with 3D rotateX.
   Randomized stagger is applied via JS (Fisher-Yates shuffle). */

.cal-day {
  perspective: 350px;
}

.cal-day.flip-pending {
  opacity: 0;
  transform: rotateX(-90deg);
  transform-origin: top center;
}

.cal-day.flip-in {
  animation: flipBoard 2000ms cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

@keyframes flipBoard {
  0% {
    opacity: 0;
    transform: rotateX(-90deg);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  }
  50% {
    opacity: 1;
    transform: rotateX(15deg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  }
  75% {
    transform: rotateX(-5deg);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
  }
  100% {
    opacity: 1;
    transform: rotateX(0);
    box-shadow: none;
  }
}

/* ── SP-064: Beat 1 — Auth modal on clean background ──
   When auth gate is active on initial load, the auth modal must
   be visible even though panels are still in pre-reveal state.
   This class promotes the modal to position:fixed so it escapes
   the hidden .section-animate parent. Removed after auth resolves.
   (renderer-demo has no auth, but keeping in sync for consistency.) */

.auth-modal-overlay.auth-beat-one {
  position: fixed;
  inset: 0;
  z-index: 10000;
}

/* ── App container fade-in when page-loading is removed ── */

.app-container {
  transition: opacity 200ms ease-out;
}

/* ── Reduced motion: instant, no animation ── */

@media (prefers-reduced-motion: reduce) {
  .section-animate {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
    box-shadow: none !important;
    will-change: auto;
  }

  .section-animate.section-revealed {
    transition: none !important;
    transition-delay: 0ms !important;
  }

  .section-revealed .cascade-child {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }

  /* SP-135: Neutralize all wave pre-states and animations */
  .wave-2-item,
  .wave-2-live .wave-2-item {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
    will-change: auto;
  }

  .wave-3-container > .wave-3-item,
  .wave-3-live .wave-3-container > .wave-3-item {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
    will-change: auto;
  }

  .wave-3-workflow .wave-3-item,
  .wave-3-live .wave-3-workflow .wave-3-item {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
    will-change: auto;
  }

  .cal-day.flip-pending {
    opacity: 1 !important;
    transform: none !important;
  }

  .cal-day.flip-in {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }

  body.page-loading .app-container {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  /* SP-064: Beat 1 auth modal — no animation, instant display */
  .auth-modal-overlay.auth-beat-one {
    animation: none !important;
  }
}

/* ── Print: no transitions ── */

@media print {
  .section-animate {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
    box-shadow: none !important;
  }

  .cal-day.flip-pending,
  .cal-day.flip-in {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }

  /* SP-135: Wave items visible in print */
  .wave-2-item,
  .wave-3-container > .wave-3-item,
  .wave-3-workflow .wave-3-item {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }
}
