/* ════════════════════════════════════════════════════════════
   APEX MOTION KIT — v1.0 · 2026-04-30
   Source of truth for every Apex deliverable.
   Drop-in. No framework. Pure CSS + IntersectionObserver.
   ════════════════════════════════════════════════════════════ */

:root {
  --apex-motion-version: 1;

  /* PALETTE — never deviate */
  --void: #000000;
  --ink:  #08090b;
  --cyan: #00f0ff;
  --cyan-glow: rgba(0, 240, 255, 0.40);
  --cyan-line: rgba(0, 240, 255, 0.28);
  --cyan-soft: rgba(0, 240, 255, 0.04);
  --magenta: #ec4899;
  --magenta-rim: rgba(236, 72, 153, 0.35);
  --green: #4ade80;
  --fg-1: rgba(255, 255, 255, 0.92);
  --fg-2: rgba(255, 255, 255, 0.62);
  --muted: rgba(255, 255, 255, 0.40);
  --hairline: rgba(255, 255, 255, 0.06);

  /* MOTION — apex curve */
  --apex-ease: cubic-bezier(0.4, 0, 0.2, 1);
  --apex-fast: 180ms;
  --apex-base: 280ms;
  --apex-slow: 600ms;
}

/* ════════════════════════════════════════════════════════════
   BASE (apply to body of any apex-deliverable)
   ════════════════════════════════════════════════════════════ */

body.apex {
  background: var(--void);
  color: var(--fg-1);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body.apex h1, body.apex h2, body.apex .apex-display {
  font-family: 'Bricolage Grotesque', 'Inter', sans-serif;
  font-weight: 700;
  letter-spacing: -0.01em;
}

body.apex .apex-mono, body.apex code, body.apex .apex-eyebrow,
body.apex .apex-stat, body.apex .apex-label {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

/* ════════════════════════════════════════════════════════════
   1. AMBIENT BG — dual orbs + grid + beam (.apex-bg)
   ════════════════════════════════════════════════════════════ */

.apex-bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background: var(--void);
  overflow: hidden;
}

.apex-bg::before {
  /* 50px scrolling grid */
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 240, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 240, 255, 0.04) 1px, transparent 1px);
  background-size: 50px 50px;
  animation: apex-grid 12s linear infinite;
}

.apex-bg::after {
  /* dual orbs — cyan top-left, magenta-rim bottom-right */
  content: '';
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(circle at 25% 25%, rgba(0, 240, 255, 0.18), transparent 40%),
    radial-gradient(circle at 75% 75%, rgba(236, 72, 153, 0.10), transparent 40%);
  filter: blur(80px);
  mix-blend-mode: screen;
  animation: apex-orb-drift 60s ease-in-out infinite alternate;
}

/* top 1px cyan→violet→cyan beam */
.apex-beam {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 1px;
  z-index: 1000;
  background: linear-gradient(90deg, transparent, var(--cyan), #8b5cf6, var(--cyan), transparent);
  background-size: 200% 100%;
  animation: apex-beam 8s linear infinite;
  pointer-events: none;
}

@keyframes apex-grid {
  from { background-position: 0 0; }
  to   { background-position: 50px 50px; }
}
@keyframes apex-orb-drift {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(-3%, 3%) scale(1.05); }
}
@keyframes apex-beam {
  from { background-position: 0 0; }
  to   { background-position: -200% 0; }
}

/* ════════════════════════════════════════════════════════════
   2. CARD (.apex-card)
   ════════════════════════════════════════════════════════════ */

.apex-card {
  background: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 18px 22px;
  transition:
    transform var(--apex-fast) var(--apex-ease),
    box-shadow var(--apex-fast) var(--apex-ease),
    border-color var(--apex-fast) var(--apex-ease);
}

.apex-card:hover {
  transform: translateY(-1px);
  border-color: var(--cyan-line);
  box-shadow:
    0 0 0 1px var(--magenta-rim),
    0 8px 28px rgba(0, 240, 255, 0.12);
}

@media (hover: none) {
  .apex-card:hover { transform: none; }
}

/* ════════════════════════════════════════════════════════════
   3. LIVE PULSE (.apex-live)
   ════════════════════════════════════════════════════════════ */

.apex-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 600 10px 'JetBrains Mono', ui-monospace, monospace;
  letter-spacing: 0.16em;
  color: var(--green);
  text-transform: uppercase;
}

.apex-live .dot {
  position: relative;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: apex-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.apex-live .dot::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--green);
  animation: apex-ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

@keyframes apex-pulse {
  0%, 100% { opacity: 1;   transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(0.92); }
}
@keyframes apex-ping {
  0%   { transform: scale(1);   opacity: 1; }
  80%, 100% { transform: scale(2.4); opacity: 0; }
}

/* ════════════════════════════════════════════════════════════
   4. TAB GLIDE (.apex-tab + .apex-tab-pill)
   Container has the pill as ::after; positioned via JS
   ════════════════════════════════════════════════════════════ */

.apex-tabs {
  position: relative;
  display: inline-flex;
  gap: 4px;
  border-bottom: 1px solid var(--hairline);
}

.apex-tab {
  position: relative;
  padding: 12px 20px;
  background: none;
  border: none;
  color: var(--fg-2);
  font: 600 11px 'JetBrains Mono', ui-monospace, monospace;
  letter-spacing: 0.16em;
  cursor: pointer;
  transition: color var(--apex-fast) var(--apex-ease);
}

.apex-tab:hover { color: var(--fg-1); }
.apex-tab.active { color: var(--cyan); }

.apex-tab-pill {
  position: absolute;
  bottom: -1px;
  height: 2px;
  background: var(--cyan);
  box-shadow: 0 0 12px var(--cyan-glow);
  transition:
    left 220ms var(--apex-ease),
    width 220ms var(--apex-ease);
  pointer-events: none;
}

/* ════════════════════════════════════════════════════════════
   5. STAT COUNTER (.apex-stat)
   ════════════════════════════════════════════════════════════ */

.apex-stat {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--cyan);
}

/* ════════════════════════════════════════════════════════════
   6. STREAMING SHIMMER (.apex-streaming)
   ════════════════════════════════════════════════════════════ */

.apex-streaming {
  position: relative;
  overflow: hidden;
}

.apex-streaming::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(0, 240, 255, 0.04) 50%,
    transparent
  );
  background-size: 200% 100%;
  animation: apex-shimmer 1.6s linear infinite;
  pointer-events: none;
}

@keyframes apex-shimmer {
  from { background-position: -100% 0; }
  to   { background-position: 100% 0; }
}

/* ════════════════════════════════════════════════════════════
   7. REVEAL (data-apex-reveal) — controlled by JS observer
   ════════════════════════════════════════════════════════════ */

[data-apex-reveal] {
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  transition:
    opacity var(--apex-base) var(--apex-ease),
    transform var(--apex-base) var(--apex-ease);
}

[data-apex-reveal].is-revealed {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* stagger children — JS attaches index, CSS uses transition-delay */
[data-apex-stagger-children] > [data-apex-reveal] {
  transition-delay: calc(var(--apex-i, 0) * 40ms);
}

/* ════════════════════════════════════════════════════════════
   8. WORD REVEAL (data-apex-words) — JS splits + animates
   ════════════════════════════════════════════════════════════ */

[data-apex-words] .apex-word {
  display: inline-block;
  opacity: 0;
  transform: translateY(16px);
  transition:
    opacity var(--apex-base) var(--apex-ease),
    transform var(--apex-base) var(--apex-ease);
  transition-delay: calc(var(--apex-i, 0) * 40ms);
}

[data-apex-words].is-revealed .apex-word {
  opacity: 1;
  transform: translateY(0);
}

[data-apex-words].is-revealed.apex-display .apex-word:last-child {
  text-shadow: 0 0 14px var(--cyan-glow);
}

/* ════════════════════════════════════════════════════════════
   9. VIEW CROSSFADE (.apex-view)
   ════════════════════════════════════════════════════════════ */

.apex-view {
  opacity: 0;
  transform: translateX(12px);
  transition:
    opacity var(--apex-fast) var(--apex-ease),
    transform var(--apex-fast) var(--apex-ease);
  pointer-events: none;
}

.apex-view.active {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.apex-view.exit-left {
  opacity: 0;
  transform: translateX(-12px);
}

/* ════════════════════════════════════════════════════════════
   10. TOAST (.apex-toast)
   ════════════════════════════════════════════════════════════ */

.apex-toast-stack {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.apex-toast {
  background: var(--ink);
  border: 1px solid var(--cyan-line);
  border-radius: 10px;
  padding: 12px 16px;
  font: 500 11px 'JetBrains Mono', ui-monospace, monospace;
  color: var(--fg-1);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 220ms var(--apex-ease), transform 220ms var(--apex-ease);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: 360px;
}

.apex-toast.is-shown {
  opacity: 1;
  transform: translateY(0);
}

.apex-toast.is-exiting {
  opacity: 0;
  transform: translateY(20px);
}

/* ════════════════════════════════════════════════════════════
   ACCESSIBILITY — respect reduced motion
   ════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
