/* ==========================================================================
   X·ARENA Design System Tokens & Motion Framework
   Crafted with Emil Kowalski Design Engineering Principles (emil-design-eng)
   ========================================================================== */

:root {
  /* Colors & Palette */
  --bg-main: #040405;
  --bg-surface: #0a0a0c;
  --bg-card: rgba(18, 18, 22, 0.75);
  --bg-card-hover: rgba(26, 26, 32, 0.85);
  --border-subtle: rgba(39, 39, 42, 0.7);
  --border-highlight: rgba(63, 63, 70, 0.9);
  
  /* Brand Accent Colors */
  --cyan: #06b6d4;
  --cyan-glow: rgba(6, 182, 212, 0.35);
  --amber: #f59e0b;
  --amber-glow: rgba(245, 158, 11, 0.35);
  --violet: #8b5cf6;
  --violet-glow: rgba(139, 92, 246, 0.35);
  --danger: #ef4444;

  /* Typography */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Emil Kowalski Custom Easing Curves */
  /* Strong ease-out for UI interactions (instant feedback) */
  --ease-out-emil: cubic-bezier(0.23, 1, 0.32, 1);
  /* Strong ease-in-out for on-screen movement */
  --ease-in-out-emil: cubic-bezier(0.77, 0, 0.175, 1);
  /* Drawer & Popover smooth curve */
  --ease-drawer-emil: cubic-bezier(0.32, 0.72, 0, 1);

  /* Animation Speeds */
  --dur-fast: 160ms;
  --dur-normal: 220ms;
  --dur-slow: 350ms;
}

/* Global Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: #e4e4e7;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   1. Emil Kowalski Button & Press Principles
   Rule: Always specify exact properties (no transition: all)
   Rule: scale(0.97) on :active for tactile feedback
   ========================================================================== */
.btn-craft {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.1rem;
  border-radius: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: #d4d4d8;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  /* Specific properties with custom ease-out */
  transition: transform var(--dur-fast) var(--ease-out-emil),
              border-color var(--dur-normal) ease,
              background var(--dur-normal) ease,
              color var(--dur-normal) ease,
              box-shadow var(--dur-normal) ease;
}

.btn-craft:hover {
  border-color: rgba(6, 182, 212, 0.5);
  color: #ffffff;
  background: rgba(39, 39, 42, 0.7);
}

.btn-craft:active {
  transform: scale(0.97);
}

.btn-cyan {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.25), rgba(6, 182, 212, 0.1));
  border-color: rgba(6, 182, 212, 0.5);
  color: #ffffff;
}

.btn-cyan:hover {
  border-color: var(--cyan);
  box-shadow: 0 0 20px var(--cyan-glow);
}

.btn-amber {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.25), rgba(245, 158, 11, 0.1));
  border-color: rgba(245, 158, 11, 0.5);
  color: #ffffff;
}

.btn-amber:hover {
  border-color: var(--amber);
  box-shadow: 0 0 20px var(--amber-glow);
}

/* ==========================================================================
   2. Origin-Aware Popovers & Dropdowns
   Rule: Never animate from scale(0). Start from scale(0.95) with opacity: 0.
   Rule: Popovers must scale from trigger location (transform-origin: top left/right).
   ========================================================================== */
.popover-origin-aware {
  position: absolute;
  top: 115%;
  left: 0;
  z-index: 60;
  background: #18181b;
  border: 1px solid var(--border-highlight);
  border-radius: 12px;
  padding: 0.5rem;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
  transform-origin: top left;
  transform: scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: transform var(--dur-fast) var(--ease-out-emil),
              opacity var(--dur-fast) var(--ease-out-emil);
}

.popover-origin-aware.open {
  transform: scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* ==========================================================================
   3. Blur-Masked Crossfade (State / Value Switching)
   Rule: Use filter: blur(2-4px) during crossfades to bridge visual jumps.
   ========================================================================== */
.blur-crossfade {
  display: inline-block;
  transition: filter var(--dur-normal) ease,
              opacity var(--dur-normal) ease,
              transform var(--dur-normal) var(--ease-out-emil);
}

.blur-crossfade.updating {
  filter: blur(4px);
  opacity: 0.2;
  transform: scale(0.96);
}

/* ==========================================================================
   4. Asymmetric Hold-To-Confirm Pattern
   Rule: Press is slow/deliberate (2s linear), release is fast (200ms ease-out).
   ========================================================================== */
.hold-action-btn {
  position: relative;
  overflow: hidden;
}

.hold-progress-overlay {
  position: absolute;
  inset: 0;
  background: rgba(239, 68, 68, 0.25);
  clip-path: inset(0 100% 0 0);
  /* Release: Fast 200ms ease-out */
  transition: clip-path 200ms var(--ease-out-emil);
}

.hold-action-btn:active .hold-progress-overlay {
  /* Pressing: Slow & deliberate 2s linear */
  clip-path: inset(0 0 0 0);
  transition: clip-path 2s linear;
}

/* ==========================================================================
   5. Staggered Entrance Animations
   Rule: Keep stagger delays short (30-50ms) between list items.
   ========================================================================== */
.stagger-parent .stagger-child {
  opacity: 0;
  transform: translateY(10px);
}

.stagger-parent.active .stagger-child {
  animation: staggerFadeIn 250ms var(--ease-out-emil) forwards;
}

.stagger-parent.active .stagger-child:nth-child(1) { animation-delay: 0ms; }
.stagger-parent.active .stagger-child:nth-child(2) { animation-delay: 40ms; }
.stagger-parent.active .stagger-child:nth-child(3) { animation-delay: 80ms; }
.stagger-parent.active .stagger-child:nth-child(4) { animation-delay: 120ms; }
.stagger-parent.active .stagger-child:nth-child(5) { animation-delay: 160ms; }
.stagger-parent.active .stagger-child:nth-child(6) { animation-delay: 200ms; }

@keyframes staggerFadeIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================================================
   6. Sonner Toast Notifications
   ========================================================================== */
.toast-viewport {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 250;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  pointer-events: none;
}

.toast-item {
  pointer-events: auto;
  background: #18181b;
  border: 1px solid var(--cyan);
  color: #ffffff;
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  transform: translateY(100%);
  opacity: 0;
  transition: transform var(--dur-slow) var(--ease-out-emil),
              opacity var(--dur-slow) var(--ease-out-emil);
}

.toast-item.visible {
  transform: translateY(0);
  opacity: 1;
}

/* Accessibility: Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
