/* combat_morph.css — Viewport morph transitions for combat enter/exit (BG108).
 *
 * Foundation only: the overlay provides the enter/exit flash + palette shift.
 * When combat-morph is OFF (Ultrastation flag unset) this file has zero visual
 * effect — all rules are scoped to class-gated selectors.
 *
 * z-index sits above the game pane (same as status_fx) but below modals:
 *   game pane ~10 → combat-morph ~62 → status-fx 60 wait — morph sits at 62
 *   (ordered above status_fx so morph frames status_fx, not the reverse).
 *
 * pointer-events: none throughout — never intercept player input.
 */

/* =========================================================================
   Overlay
   ========================================================================= */

#combat-morph-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 62;           /* above status-fx-overlay (60), below dialogs */
  overflow: hidden;
  /* Invisible by default; transitions are driven by class additions */
  opacity: 0;
  transition: opacity 0.4s ease;
  will-change: opacity;
}

/* =========================================================================
   Enter — combat-start transition
   ========================================================================= */

/* Phase 1: sharp white-hot flash (ENTER_FLASH_MS = 80 ms).
   Fast-in via the short 0.06s transition override. */
#combat-morph-overlay.morph-enter-flash {
  transition: opacity 0.06s ease-in;
  background: rgba(255, 245, 220, 0.62);
  opacity: 1;
}

/* Phase 2: morph-in — warm desaturate-to-combat-palette overlay fades in. */
#combat-morph-overlay.morph-enter {
  transition: opacity 0.38s ease-out;
  background: radial-gradient(ellipse at center,
              rgba(180, 30, 20, 0.06) 0%,
              rgba(120, 15, 10, 0.20) 100%);
  opacity: 1;
}

/* =========================================================================
   Exit — return to exploration palette
   ========================================================================= */

#combat-morph-overlay.morph-exit {
  transition: opacity 0.5s ease-in-out;
  background: radial-gradient(ellipse at center,
              rgba(80, 160, 80, 0.06) 0%,
              rgba(40, 100, 40, 0.12) 100%);
  opacity: 1;
  animation: morphExit 0.5s ease-in-out forwards;
}

@keyframes morphExit {
  0%   { opacity: 1; }
  60%  { opacity: 0.7; }
  100% { opacity: 0; }
}

/* =========================================================================
   Body-level combat-mode class
   Framing: when in combat, a thin red border reinforces the viewport shell.
   Scoped so only the viewport wrapper gets the combat frame.
   ========================================================================= */

/* BU27 (2026-06-11): the real viewport DOM is `#pixel-viewport` (container) +
   `#viewport-canvas` (canvas) — see viewport.js. The original selectors
   (#viewport-wrapper / .viewport-shell / #game-viewport / canvas#viewport)
   match NOTHING in the live markup, so the sustained combat frame never
   rendered on staging ("nothing there"). Target the real ids; keep the
   legacy selectors as harmless fallbacks for any future layout. */
body.combat-mode #pixel-viewport,
body.combat-mode #viewport-canvas,
body.combat-mode #viewport-wrapper,
body.combat-mode .viewport-shell,
body.combat-mode #game-viewport,
body.combat-mode canvas#viewport {
  /* HP-reactive frame: a SUBTLE red outline at full HP (just signals "combat
   * mode"), intensifying to a hard violent-red frame as the player is hurt.
   * --combat-danger (0..1) is set per turn by combat_tint.js from player HP. */
  box-shadow: 0 0 0 2px rgba(200, 30, 20, calc(0.16 + 0.55 * var(--combat-danger, 0))),
              0 0 18px 4px rgba(200, 30, 20, calc(0.06 + 0.34 * var(--combat-danger, 0)));
  transition: box-shadow 0.38s ease;
}

/* =========================================================================
   Accessibility — reduced-motion: kill all animation, keep static tints.
   ========================================================================= */

@media (prefers-reduced-motion: reduce) {
  #combat-morph-overlay {
    transition: opacity 0.15s ease !important;
    animation: none !important;
  }
  #combat-morph-overlay.morph-enter-flash {
    background: rgba(255, 245, 220, 0.30);
  }
  #combat-morph-overlay.morph-enter {
    background: rgba(140, 20, 15, 0.10);
  }
  #combat-morph-overlay.morph-exit {
    animation: none !important;
    background: rgba(60, 140, 60, 0.08);
  }
  body.combat-mode #pixel-viewport,
  body.combat-mode #viewport-canvas,
  body.combat-mode #viewport-wrapper,
  body.combat-mode .viewport-shell,
  body.combat-mode #game-viewport,
  body.combat-mode canvas#viewport {
    transition: box-shadow 0.15s ease;
  }
}
