/* ============================================================================
   portal_fx.css — Portal Experience Engine (Phase 1)
   Scoped under `.pfx` so it never leaks. Edition-aware (reads --bk-a/--bk-b set
   by UnityzmWeb.EditionTheme.cover_vars), platform-aware notifications, and
   GPU-only animations (transform/opacity) that fully disable under
   prefers-reduced-motion. Hand-authored; keep priv/static/assets copy in sync.
   ============================================================================ */

.pfx {
  /* accents resolve to the active edition's brand colour, with safe fallbacks */
  --fx-accent: var(--bk-a, #243f82);
  --fx-accent-2: var(--bk-b, #3253a0);
  --usn-accent: #10b981;          /* USN network green */
  --pfx-dur: 0.42s;               /* edition can override for faster/slower motion */
}

/* ─────────────────────────────────────────────────────────────────────────
   AI LAYER — a branded "sound-wave" pulse radiating from any corner, behind
   the wrapped content. Origin is (--pfx-x, --pfx-y): top-right = 100% 0%,
   bottom-left = 0% 100%, centre = 50% 50%, etc.
   ───────────────────────────────────────────────────────────────────────── */
.pfx-ai { position: relative; isolation: isolate; border-radius: inherit; }
.pfx-ai > .pfx-ai-stage {
  position: absolute; inset: 0; overflow: hidden; pointer-events: none;
  z-index: 0; border-radius: inherit;
}
.pfx-ai > :not(.pfx-ai-stage) { position: relative; z-index: 1; }

/* Gas/nebula puffs — soft blurred clouds that billow out from the source corner
   and dissipate (not crisp concentric rings). */
.pfx-ai-stage i {
  position: absolute;
  left: var(--pfx-x, 100%);
  top: var(--pfx-y, 0%);
  width: 64%; height: 64%;
  border-radius: 50%;
  background: radial-gradient(closest-side,
    color-mix(in oklab, var(--fx-accent) 36%, transparent),
    color-mix(in oklab, var(--fx-accent) 10%, transparent) 52%,
    transparent 74%);
  filter: blur(20px);
  opacity: 0;
  transform: translate(-50%, -50%) scale(.4);
  mix-blend-mode: screen;
  will-change: transform, opacity;
  animation: pfx-gas 7s ease-in-out infinite;
}
.pfx-ai-stage i:nth-child(2) {
  animation-delay: 2.3s;
  background: radial-gradient(closest-side,
    color-mix(in oklab, var(--fx-accent-2) 34%, transparent), transparent 74%);
}
.pfx-ai-stage i:nth-child(3) { animation-delay: 4.5s; }
/* a soft diffuse glow sitting at the source corner */
.pfx-ai-stage::before {
  content: ""; position: absolute;
  left: var(--pfx-x, 100%); top: var(--pfx-y, 0%);
  width: 82%; height: 82%; transform: translate(-50%, -50%);
  background: radial-gradient(closest-side, color-mix(in oklab, var(--fx-accent) 24%, transparent), transparent 70%);
  filter: blur(8px);
  opacity: .55; pointer-events: none;
}
@keyframes pfx-gas {
  0%   { opacity: 0;   transform: translate(-50%, -50%) scale(.4); }
  40%  { opacity: .5; }
  70%  { opacity: .26; transform: translate(-58%, -42%) scale(1.7); }
  100% { opacity: 0;   transform: translate(-64%, -36%) scale(2.5); }
}
.pfx-ai[data-active="false"] .pfx-ai-stage { display: none; }

/* ─────────────────────────────────────────────────────────────────────────
   USN LAYER — wraps a component and animates a live USN-connected state:
   a slow diagonal scan sweep + a pulsing "connected" node badge.
   ───────────────────────────────────────────────────────────────────────── */
.pfx-usn { position: relative; border-radius: inherit; }
.pfx-usn::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  pointer-events: none; z-index: 2; mix-blend-mode: screen;
  background: linear-gradient(115deg, transparent 42%,
              color-mix(in oklab, var(--usn-accent) 26%, transparent) 50%, transparent 58%);
  background-size: 250% 100%;
  animation: pfx-usn-sweep 3.6s linear infinite;
  opacity: .55;
}
@keyframes pfx-usn-sweep { 0% { background-position: 150% 0; } 100% { background-position: -50% 0; } }

.pfx-usn-badge {
  position: absolute; top: 10px; right: 10px; z-index: 3;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px 3px 7px; border-radius: 999px;
  font: 600 9px/1 'JetBrains Mono', ui-monospace, monospace; letter-spacing: .12em; text-transform: uppercase;
  color: var(--usn-accent);
  background: color-mix(in oklab, var(--usn-accent) 12%, transparent);
  border: 1px solid color-mix(in oklab, var(--usn-accent) 35%, transparent);
}
.pfx-usn-badge .dot {
  width: 6px; height: 6px; border-radius: 999px; background: var(--usn-accent);
  box-shadow: 0 0 0 0 color-mix(in oklab, var(--usn-accent) 60%, transparent);
  animation: pfx-usn-ping 1.8s ease-out infinite;
}
@keyframes pfx-usn-ping {
  0%   { box-shadow: 0 0 0 0 color-mix(in oklab, var(--usn-accent) 55%, transparent); }
  70%  { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
/* disconnected: grey, static */
.pfx-usn[data-connected="false"]::after { animation: none; opacity: 0; }
.pfx-usn[data-connected="false"] .pfx-usn-badge { color: #a1a1aa; background: rgba(161,161,170,.12); border-color: rgba(161,161,170,.3); }
.pfx-usn[data-connected="false"] .pfx-usn-badge .dot { background: #a1a1aa; animation: none; }

/* ─────────────────────────────────────────────────────────────────────────
   FLUID MOTION — edition-tuned enter/leave on screen/component change.
   Use with phx-mounted (add .pfx-in) and phx-remove (JS.add_class .pfx-out).
   --pfx-delay staggers a list.
   ───────────────────────────────────────────────────────────────────────── */
.pfx-in  { animation: pfx-in  var(--pfx-dur, .42s) cubic-bezier(.2,.7,.2,1) both; animation-delay: var(--pfx-delay, 0s); }
.pfx-out { animation: pfx-out calc(var(--pfx-dur, .42s) * .6) ease-in both; }
@keyframes pfx-in  { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes pfx-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(-6px) scale(.99); } }

/* ─────────────────────────────────────────────────────────────────────────
   OPTIMISTIC — instant client feedback while the backend reconciles.
   .is-optimistic = pending shimmer; .is-confirmed / .is-failed resolve it.
   ───────────────────────────────────────────────────────────────────────── */
.pfx-optimistic { position: relative; transition: opacity .2s; }
.pfx-optimistic.is-optimistic { overflow: hidden; }
.pfx-optimistic.is-optimistic::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background: linear-gradient(100deg, transparent 30%, color-mix(in oklab, var(--fx-accent) 20%, transparent) 50%, transparent 70%);
  background-size: 200% 100%; animation: pfx-shimmer 1.1s linear infinite;
}
@keyframes pfx-shimmer { 0% { background-position: 140% 0; } 100% { background-position: -40% 0; } }
.pfx-optimistic.is-failed { animation: pfx-shake .35s ease; }
@keyframes pfx-shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.pfx-optimistic.is-confirmed { animation: pfx-confirm .4s ease; }
@keyframes pfx-confirm { 0% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--usn-accent) 55%, transparent); } 100% { box-shadow: 0 0 0 6px transparent; } }

/* ─────────────────────────────────────────────────────────────────────────
   NOTIFICATION ENGINE — platform-aware toast stack. The hook sets
   data-platform on the stack; each platform uses its native pattern.
   ───────────────────────────────────────────────────────────────────────── */
.pfx-notif-stack { position: fixed; z-index: 95; display: flex; flex-direction: column; gap: 10px; pointer-events: none; max-width: min(420px, calc(100vw - 24px)); }
.pfx-notif-stack[data-platform="desktop"] { top: 18px; right: 18px; align-items: flex-end; }
.pfx-notif-stack[data-platform="ios"]     { top: max(12px, env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%); align-items: center; width: min(420px, calc(100vw - 24px)); }
.pfx-notif-stack[data-platform="android"] { left: 12px; right: 12px; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); align-items: stretch; max-width: none; }

.pfx-notif {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 11px;
  padding: 12px 14px; border-radius: 12px; min-width: 240px;
  background: #fff; color: #18181b; border: 1px solid #e4e4e7;
  box-shadow: 0 12px 32px rgba(9,9,11,.16), 0 4px 8px rgba(9,9,11,.06);
  animation: pfx-notif-in .32s cubic-bezier(.2,.8,.2,1) both;
}
.pfx-notif.leaving { animation: pfx-notif-out .26s ease-in both; }
.pfx-notif .pfx-notif-ic { flex: 0 0 auto; width: 22px; height: 22px; border-radius: 999px; display: inline-grid; place-items: center; font-size: 12px; margin-top: 1px; }
.pfx-notif .pfx-notif-bd { min-width: 0; }
.pfx-notif .pfx-notif-bd b { display: block; font: 600 13px/1.3 'Inter', sans-serif; }
.pfx-notif .pfx-notif-bd span { display: block; font: 400 12px/1.45 'Inter', sans-serif; color: #52525b; margin-top: 2px; }
.pfx-notif.ok   { border-left: 3px solid #10b981; }
.pfx-notif.ok   .pfx-notif-ic { background: #ecfdf5; color: #047857; }
.pfx-notif.err  { border-left: 3px solid #ef4444; }
.pfx-notif.err  .pfx-notif-ic { background: #fef2f2; color: #b91c1c; }
.pfx-notif.info { border-left: 3px solid #0ea5e9; }
.pfx-notif.info .pfx-notif-ic { background: #f0f9ff; color: #0284c7; }

/* iOS — translucent, heavily rounded, centred banner */
.pfx-notif-stack[data-platform="ios"] .pfx-notif {
  border-radius: 18px; border: 0; border-left: 0;
  background: color-mix(in oklab, #ffffff 78%, transparent);
  backdrop-filter: saturate(1.6) blur(22px); -webkit-backdrop-filter: saturate(1.6) blur(22px);
  box-shadow: 0 8px 28px rgba(0,0,0,.18); width: 100%;
}
/* Android — Material snackbar: dark, squared, bottom */
.pfx-notif-stack[data-platform="android"] .pfx-notif {
  border-radius: 8px; border: 0; border-left: 0; background: #2b2b2f; color: #fff;
  box-shadow: 0 6px 18px rgba(0,0,0,.4);
}
.pfx-notif-stack[data-platform="android"] .pfx-notif .pfx-notif-bd span { color: rgba(255,255,255,.72); }

/* actionable notifications — dynamic-form choices rendered as buttons */
.pfx-notif-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.pfx-notif-act {
  height: 30px; padding: 0 12px; border-radius: 7px; cursor: pointer;
  font: 600 12px/1 'Inter', sans-serif;
  background: transparent; color: #243f82; border: 1px solid #d4d4d8;
}
.pfx-notif-act:hover { background: #f4f4f5; }
.pfx-notif-act.primary { background: #243f82; color: #fff; border-color: transparent; }
.pfx-notif-act.primary:hover { background: #1d3268; }
html[data-theme="dark"] .pfx-notif-act { color: #adc1e6; border-color: #3f3f46; }
html[data-theme="dark"] .pfx-notif-act:hover { background: rgba(255,255,255,.06); }

/* dynamic mini-form rail — an inline form rendered inside a toast */
.pfx-notif-form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.pfx-notif-form-title { font: 600 12px/1.3 'Inter', sans-serif; color: #18181b; }
.pfx-notif-field { display: flex; flex-direction: column; gap: 3px; }
.pfx-notif-field span { font: 500 10px/1 'Inter', sans-serif; letter-spacing: .04em; text-transform: uppercase; color: #71717a; }
.pfx-notif-field input {
  height: 32px; padding: 0 10px; border-radius: 7px;
  font: 400 13px/1 'Inter', sans-serif; color: #18181b;
  background: #fff; border: 1px solid #d4d4d8; outline: none;
}
.pfx-notif-field input:focus { border-color: var(--fx-accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--fx-accent) 18%, transparent); }
.pfx-notif-form .pfx-notif-act { align-self: flex-start; margin-top: 2px; }
html[data-theme="dark"] .pfx-notif-form-title { color: #fafafa; }
html[data-theme="dark"] .pfx-notif-field span { color: #a1a1aa; }
html[data-theme="dark"] .pfx-notif-field input { color: #fafafa; background: #27272a; border-color: #3f3f46; }

@keyframes pfx-notif-in  { from { opacity: 0; transform: translateY(-10px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes pfx-notif-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(-8px) scale(.98); } }
/* Android slides up from the bottom */
.pfx-notif-stack[data-platform="android"] .pfx-notif { animation-name: pfx-notif-in-up; }
@keyframes pfx-notif-in-up { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

/* dark theme surfaces for desktop/ios cards */
html[data-theme="dark"] .pfx-notif { background: #18181b; color: #fafafa; border-color: #27272a; }
html[data-theme="dark"] .pfx-notif .pfx-notif-bd b { color: #fafafa; }
html[data-theme="dark"] .pfx-notif .pfx-notif-bd span { color: #a1a1aa; }
html[data-theme="dark"] .pfx-notif-stack[data-platform="ios"] .pfx-notif { background: color-mix(in oklab, #18181b 70%, transparent); }

/* ─────────────────────────────────────────────────────────────────────────
   Accessibility — honour reduced motion everywhere (stability + a11y).
   ───────────────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .pfx-ai-stage i, .pfx-usn::after, .pfx-usn-badge .dot,
  .pfx-in, .pfx-out, .pfx-optimistic.is-optimistic::after,
  .pfx-optimistic.is-failed, .pfx-optimistic.is-confirmed,
  .pfx-notif { animation: none !important; }
  .pfx-in { opacity: 1; transform: none; }
}
