/* ══════════════════════════════════════════════════════════════════════════
   ANIMATION REFINEMENTS: Premium UX/UI Polish
   Five tiers of interactive refinement for Material Design 3 experience
   ═════════════════════════════════════════════════════════════════════════ */

/* ── 1. PAGE TRANSITION ANIMATIONS ───────────────────────────────────────── */

/* Page-level fade-in on load */
body {
  animation: pageLoadFadeIn 400ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes pageLoadFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Main content slide-up entrance */
main {
  animation: contentSlideUp 600ms cubic-bezier(0.34, 1.56, 0.64, 1) 100ms backwards;
}

@keyframes contentSlideUp {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── 2. SCROLL-TRIGGERED CONTENT REVEALS ──────────────────────────────────── */

/* Default reveal state */
.reveal-scroll {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 500ms cubic-bezier(0.34, 1.56, 0.64, 1),
              transform 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Revealed state */
.reveal-scroll.in-view {
  opacity: 1;
  transform: translateY(0);
}

/* Staggered reveals for groups */
.reveal-scroll:nth-child(1).in-view { transition-delay: 0ms; }
.reveal-scroll:nth-child(2).in-view { transition-delay: 50ms; }
.reveal-scroll:nth-child(3).in-view { transition-delay: 100ms; }
.reveal-scroll:nth-child(4).in-view { transition-delay: 150ms; }
.reveal-scroll:nth-child(5).in-view { transition-delay: 200ms; }
.reveal-scroll:nth-child(n+6).in-view { transition-delay: 250ms; }

/* Card grid staggered reveals */
.card-interactive {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 500ms cubic-bezier(0.34, 1.56, 0.64, 1),
              transform 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.card-interactive.in-view {
  opacity: 1;
  transform: translateY(0);
}

/* ── CARD HOVER EFFECTS (7-LAYER STAGGERED) ──────────────────────────────── */
.card-interactive {
  position: relative;
  border-color: rgba(212, 175, 55, 0.3);
  transition:
    border-color 120ms ease-out,
    background-color 150ms cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 150ms ease-out,
    transform 150ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.card-interactive:hover {
  /* Layer 1: Border glow (0ms) */
  border-color: var(--color-gold-alt) !important;

  /* Layer 2: Background shift (20ms delay) */
  background-color: rgba(212, 175, 55, 0.03) !important;

  /* Layer 3: Shadow glow (40ms delay) */
  box-shadow:
    0 8px 24px rgba(212, 175, 55, 0.15),
    inset 0 0 16px rgba(212, 175, 55, 0.08) !important;

  /* Layer 4: Scale preview (60ms delay) */
  transform: scale(1.01) translateY(-2px) !important;
}

/* ── 3. COMMAND PALETTE MICRO-INTERACTIONS ────────────────────────────────── */

/* Result items fade in sequentially */
.cmdk-row {
  opacity: 0;
  animation: cmdkRowFadeIn 300ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Stagger result items */
.cmdk-row:nth-child(1) { animation-delay: 0ms; }
.cmdk-row:nth-child(2) { animation-delay: 30ms; }
.cmdk-row:nth-child(3) { animation-delay: 60ms; }
.cmdk-row:nth-child(4) { animation-delay: 90ms; }
.cmdk-row:nth-child(5) { animation-delay: 120ms; }
.cmdk-row:nth-child(n+6) { animation-delay: 150ms; }

@keyframes cmdkRowFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Hover state on results */
.cmdk-row:hover {
  transition: background-color 150ms ease-out,
              border-color 150ms ease-out;
}

/* Icon animation in results */
.cmdk-row:hover .material-symbols-outlined {
  animation: iconPulseRotate 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes iconPulseRotate {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(8deg) scale(1.08); }
  100% { transform: rotate(0deg) scale(1.12); }
}

/* ── 4. BUTTON & CONTROL FEEDBACK STATES (STAGGERED 7-LAYER ANIMATION) ──── */

/* Primary button with staggered hover layers */
button:not(.app-bar-icon):not(.app-bar-search-btn):not(.app-bar-menu-btn) {
  transition:
    background-color 120ms ease-out,
    color 120ms ease-out,
    transform 150ms cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 150ms ease-out;
  position: relative;
  overflow: hidden;
}

/* Staggered hover animation layers */
button:not(.app-bar-icon):not(.app-bar-search-btn):not(.app-bar-menu-btn):hover {
  /* Layer 1: Color shift (0ms) */
  color: var(--color-text-on-dark) !important;
  transition: color 120ms ease-out !important;

  /* Layer 2: Background glow (delay 20ms) */
  background-color: var(--color-paper) !important;
  box-shadow:
    inset 0 0 12px rgba(212, 175, 55, 0.12),
    0 6px 16px rgba(212, 175, 55, 0.2) !important;
  transition:
    color 120ms ease-out,
    background-color 120ms ease-out 20ms,
    box-shadow 150ms ease-out 40ms !important;

  /* Layer 3: Scale preview (delay 60ms) */
  transform: scale(1.02);
  transition:
    color 120ms ease-out,
    background-color 120ms ease-out 20ms,
    box-shadow 150ms ease-out 40ms,
    transform 150ms cubic-bezier(0.34, 1.56, 0.64, 1) 60ms !important;
}

/* Button active/press state */
button:not(.app-bar-icon):not(.app-bar-search-btn):not(.app-bar-menu-btn):active {
  transform: scale(0.98) !important;
  box-shadow: inset 0 0 8px rgba(212, 175, 55, 0.2) !important;
}

/* Enhanced focus ring with glow animation */
button:not(.app-bar-icon):not(.app-bar-search-btn):not(.app-bar-menu-btn):focus-visible {
  outline: none !important;
  box-shadow:
    0 0 0 2px var(--color-paper),
    0 0 0 4px var(--color-accent) !important;
  animation: focusGlowPulse 2s ease-in-out infinite;
}

/* Focus ring animation */
button:not(.app-bar-icon):focus-visible,
a:focus-visible {
  animation: focusGlowPulse 2s ease-in-out infinite;
}

@keyframes focusGlowPulse {
  0%, 100% {
    outline-width: 2px;
    box-shadow: 0 0 0 4px rgba(212, 175, 55, 0.3);
  }
  50% {
    outline-width: 2px;
    box-shadow: 0 0 0 6px rgba(212, 175, 55, 0.15);
  }
}

/* Icon button rotation */
.app-bar-icon {
  transition:
    color 120ms ease-out,
    transform 150ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.app-bar-icon:hover {
  transform: rotate(10deg) scale(1.1);
}

/* ── SMOOTH COLOR TRANSITIONS FOR LINKS & TEXT ──────────────────────────── */
a {
  transition: color 150ms cubic-bezier(0.4, 0, 0.2, 1) !important;
}

a:hover {
  color: var(--color-gold-alt) !important;
}

/* Focus state for links */
a:focus-visible {
  outline: 2px solid var(--color-gold-alt) !important;
  outline-offset: 2px !important;
  border-radius: 2px;
  animation: focusGlowPulse 2s ease-in-out infinite;
}

/* ── RIPPLE EFFECT SYSTEM (MD3) ────────────────────────────────────────── */

/* Ripple effect for all clickable elements */
button:not(.app-bar-icon),
a:not(.app-bar-logo),
.nav-drawer-item,
.card-interactive {
  position: relative;
  overflow: hidden;
}

/* Ripple pseudo-element (triggered on :active) */
button:not(.app-bar-icon)::before,
a:not(.app-bar-logo)::before,
.card-interactive::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(212, 175, 55, 0.15) 0%, transparent 70%);
  opacity: 0;
  transform: scale(0);
  transition: all 400ms cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  z-index: var(--z-content);
}

button:not(.app-bar-icon):active::before,
a:not(.app-bar-logo):active::before,
.card-interactive:active::before {
  transform: scale(1.5);
  opacity: 1;
  transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── ACTIVE/CURRENT PAGE INDICATOR ──────────────────────────────────────── */

/* Breadcrumb active state */
.breadcrumb-nav .breadcrumb-current {
  position: relative;
  color: var(--color-gold-alt);
  font-weight: 500;
}

.breadcrumb-nav .breadcrumb-current::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color-gold-alt);
  border-radius: 1px;
}

/* Nav item active indicator (fallback for non-drawer items) */
.nav-item.active {
  color: var(--color-gold-alt);
  position: relative;
}

.nav-item.active::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color-gold-alt);
  border-radius: 1px;
}

/* ── MOMENTUM SCROLLING ENHANCEMENT ─────────────────────────────────────── */

/* All scrollable containers get momentum scrolling */
.reveal-scroll,
.card-grid,
[class*="scroll"],
main,
article {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* ── KEYBOARD NAVIGATION ENHANCEMENT ────────────────────────────────────── */

/* Enhanced focus rings for keyboard users */
button:not(.app-bar-icon):focus-visible,
a:focus-visible,
.nav-item:focus-visible,
[role="menuitem"]:focus-visible {
  outline: none;
  box-shadow:
    inset 0 0 0 2px var(--color-paper),
    inset 0 0 0 4px var(--color-gold-alt),
    0 0 0 4px rgba(212, 175, 55, 0.3);
  border-radius: 2px;
  animation: focusGlowPulse 2s ease-in-out infinite;
}

/* Skip links for keyboard users */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  z-index: var(--z-navbar);
  background: var(--color-accent);
  color: var(--color-paper);
  padding: 12px 20px;
  text-decoration: none;
  font-weight: 500;
  border-radius: 0 4px 4px 0;
}

.skip-link:focus {
  top: 0;
  transition: top 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── ANIMATED TOOLTIP HINTS ────────────────────────────────────────────── */
[data-hint] {
  position: relative;
  cursor: help;
}

[data-hint]:hover::before {
  content: attr(data-hint);
  position: absolute;
  bottom: 110%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-paper);
  color: var(--color-text-on-dark);
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.3px;
  white-space: nowrap;
  z-index: var(--z-viewer);
  border: 1px solid var(--color-gold-alt);
  box-shadow: 0 4px 12px rgba(212, 175, 55, 0.2);
  opacity: 0;
  animation: tooltipSlideUp 200ms cubic-bezier(0.34, 1.56, 0.64, 1) 300ms forwards;
  pointer-events: none;
}

[data-hint]:hover::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid var(--color-gold-alt);
  z-index: var(--z-command-palette);
  opacity: 0;
  animation: tooltipSlideUp 200ms cubic-bezier(0.34, 1.56, 0.64, 1) 300ms forwards;
}

@keyframes tooltipSlideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Disabled state */
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button:disabled:hover {
  transform: none;
  box-shadow: none;
}

/* ── 5. HERO IMAGE & BACKGROUND ANIMATIONS ────────────────────────────────── */

/* Hero image fade-in and subtle parallax setup */
.hero-image, .hero-container {
  animation: heroImageFadeIn 800ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes heroImageFadeIn {
  from {
    opacity: 0;
    transform: scale(1.02);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Thermal image pulse for emotional connection */
.register-of-loss-bg {
  animation: thermalImagePulse 3s ease-in-out 2s infinite;
}

@keyframes thermalImagePulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.95;
  }
}

/* Gradient overlay smooth transitions */
.gradient-overlay {
  transition: background-color 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Chapter divider animations */
.chapter-divider {
  animation: chapterDividerReveal 700ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0;
}

@keyframes chapterDividerReveal {
  from {
    opacity: 0;
    transform: scaleX(0);
  }
  to {
    opacity: 1;
    transform: scaleX(1);
  }
}

/* Watermark numeral animation */
.chapter-divider::before {
  animation: watermarkFade 1000ms ease-out 400ms both;
}

@keyframes watermarkFade {
  from {
    opacity: 0;
  }
  to {
    opacity: 0.08;
  }
}

/* ── ACCESSIBILITY: RESPECT MOTION PREFERENCES ─────────────────────────────── */

@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;
  }

  /* Keep visual state changes, just remove motion */
  body {
    animation: none;
    opacity: 1;
  }

  main {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .reveal-scroll,
  .card-interactive {
    opacity: 1;
    transform: none;
  }
}

/* ── PERFORMANCE OPTIMIZATION ───────────────────────────────────────────────── */

/* Use GPU acceleration for smooth animations */
.reveal-scroll,
.card-interactive,
.nav-drawer-item,
button:not(.app-bar-icon),
.cmdk-row {
  will-change: transform, opacity;
}

/* Remove will-change after animations complete to save memory */
.reveal-scroll.in-view,
.card-interactive.in-view {
  will-change: auto;
}
