/* ============================================
   ANIMATIONS & MICRO-INTERACTIONS
   ============================================ */

/* Page Transition */
@keyframes pageSlideIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pageSlideInLeft {
  from { opacity: 0; transform: translateX(-30px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes pageSlideInRight {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes bounceIn {
  0% { opacity: 0; transform: scale(0.3); }
  50% { opacity: 1; transform: scale(1.05); }
  70% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes glow {
  0%, 100% { box-shadow: 0 0 5px rgba(59,130,246,0.2); }
  50% { box-shadow: 0 0 20px rgba(59,130,246,0.4); }
}

@keyframes drawLine {
  from { stroke-dashoffset: 1000; }
  to { stroke-dashoffset: 0; }
}

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

@keyframes ripple {
  to { transform: scale(4); opacity: 0; }
}

@keyframes progressFill {
  from { width: 0; }
}

@keyframes rotateIn {
  from { opacity: 0; transform: rotate(-10deg) scale(0.9); }
  to { opacity: 1; transform: rotate(0) scale(1); }
}

@keyframes typewriter {
  from { width: 0; }
  to { width: 100%; }
}

@keyframes blink {
  50% { border-color: transparent; }
}

/* Apply page transitions */
.dashboard,
.study-view,
.topic-detail,
.flashcard-view,
.quiz-view {
  animation: pageSlideIn 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Stagger children with smoother animation */
.stagger-in > * {
  opacity: 0;
  animation: pageSlideIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.stagger-in > *:nth-child(1) { animation-delay: 0.03s; }
.stagger-in > *:nth-child(2) { animation-delay: 0.06s; }
.stagger-in > *:nth-child(3) { animation-delay: 0.09s; }
.stagger-in > *:nth-child(4) { animation-delay: 0.12s; }
.stagger-in > *:nth-child(5) { animation-delay: 0.15s; }
.stagger-in > *:nth-child(6) { animation-delay: 0.18s; }
.stagger-in > *:nth-child(7) { animation-delay: 0.21s; }
.stagger-in > *:nth-child(8) { animation-delay: 0.24s; }
.stagger-in > *:nth-child(9) { animation-delay: 0.27s; }
.stagger-in > *:nth-child(10) { animation-delay: 0.30s; }
.stagger-in > *:nth-child(11) { animation-delay: 0.33s; }
.stagger-in > *:nth-child(12) { animation-delay: 0.36s; }
.stagger-in > *:nth-child(13) { animation-delay: 0.39s; }
.stagger-in > *:nth-child(14) { animation-delay: 0.42s; }

/* Card hover with lift */
.card:hover,
.domain-card:hover,
.topic-card:hover,
.deck-card:hover,
.quick-action:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0,0,0,0.25);
}

/* Button ripple effect */
.btn {
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
  background-image: radial-gradient(circle, rgba(255,255,255,0.25) 10%, transparent 10.01%);
  background-repeat: no-repeat;
  background-position: 50%;
  transform: scale(10);
  opacity: 0;
  transition: transform 0.5s, opacity 0.5s;
}

.btn:active::after {
  transform: scale(0);
  opacity: 1;
  transition: 0s;
}

/* Progress ring animation */
.progress-ring-svg circle:last-child {
  transition: stroke-dashoffset 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Stat counter animation */
.stat-value,
.streak-count,
.results-score,
.card-count,
.summary-stat-value {
  animation: countUp 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Domain card color bar animation */
.domain-card::before {
  transition: height 0.3s ease;
}

.domain-card:hover::before {
  height: 100%;
  opacity: 0.05;
  width: 100%;
}

/* Topic card slide */
.topic-card {
  transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.topic-card:hover {
  transform: translateX(8px);
  border-color: var(--domain-color, var(--border-light));
}

/* Sidebar active indicator animation */
.sidebar-item {
  transition: all 0.2s ease;
}

.sidebar-item.active {
  border-left-color: var(--domain1);
}

.sidebar-item:hover {
  transform: translateX(4px);
}

/* Search box animation */
.search-box input {
  transition: all 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Mode tab pill animation */
.mode-tab {
  transition: all 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.mode-tab.active {
  box-shadow: 0 2px 8px rgba(59,130,246,0.3);
}

/* Weight bar segment hover */
.domain-weight-segment {
  transition: all 0.3s ease;
  position: relative;
}

.domain-weight-segment:hover {
  filter: brightness(1.2);
  transform: scaleY(1.15);
}

/* Flashcard enhanced animation */
.flashcard {
  transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

.flashcard-front,
.flashcard-back {
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.flashcard-container:hover .flashcard:not(.flipped) {
  transform: rotateY(5deg);
}

/* Rating button animations */
.rating-btn {
  transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.rating-btn:hover {
  transform: translateY(-4px) scale(1.02);
}

.rating-btn:active {
  transform: translateY(0) scale(0.98);
}

/* Quiz answer option */
.answer-option {
  transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.answer-option:hover:not([disabled]) {
  transform: translateX(6px);
  border-color: var(--domain1);
}

.answer-option.correct {
  animation: pulse 0.5s ease;
}

.answer-option.incorrect {
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

/* Concept card hover */
.concept-card {
  transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  cursor: default;
}

.concept-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 16px rgba(0,0,0,0.2);
  border-color: var(--domain-color, var(--border-light));
}

/* Formula card glow */
.formula-card {
  transition: all 0.25s ease;
}

.formula-card:hover {
  border-color: var(--domain6);
  box-shadow: 0 0 16px rgba(6,182,212,0.15);
}

/* Mnemonic card */
.mnemonic-card {
  transition: all 0.25s ease;
}

.mnemonic-card:hover {
  transform: translateX(4px);
  box-shadow: 0 4px 12px rgba(139,92,246,0.15);
}

/* Exam tip */
.exam-tip {
  transition: all 0.25s ease;
}

.exam-tip:hover {
  transform: translateX(4px);
  box-shadow: 0 4px 12px rgba(251,191,36,0.15);
}

/* Streak day tooltip */
.streak-day {
  transition: all 0.15s ease;
  cursor: pointer;
}

.streak-day:hover {
  transform: scale(1.4);
  border-radius: 2px;
}

/* Navigation arrows */
.topic-nav-btn {
  transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.topic-nav-btn:hover {
  transform: translateX(4px);
}

.topic-nav-btn.next:hover {
  transform: translateX(-4px);
}

/* Overall progress card */
.overall-progress {
  animation: scaleIn 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Mark as read button */
.btn-success {
  animation: bounceIn 0.4s ease;
}

/* Badge animations */
.reg-badge,
.chapter-badge {
  transition: all 0.2s ease;
}

.reg-badge:hover,
.chapter-badge:hover {
  transform: scale(1.05);
}

/* Diagram SVG animations */
.diagram-container svg rect,
.diagram-container svg polygon {
  transition: all 0.3s ease;
}

.diagram-container svg rect:hover,
.diagram-container svg polygon:hover {
  filter: brightness(1.15);
  transform: scale(1.02);
}

/* Interactive diagram tooltip */
.diagram-container {
  position: relative;
}

.svg-tooltip {
  position: absolute;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-xs);
  color: var(--text-primary);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 10;
  max-width: 250px;
  box-shadow: var(--shadow-lg);
}

.svg-tooltip.visible {
  opacity: 1;
}

/* Content section entrance */
.content-section {
  animation: pageSlideIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.content-section:nth-child(1) { animation-delay: 0.1s; }
.content-section:nth-child(2) { animation-delay: 0.2s; }
.content-section:nth-child(3) { animation-delay: 0.3s; }
.content-section:nth-child(4) { animation-delay: 0.4s; }
.content-section:nth-child(5) { animation-delay: 0.5s; }
.content-section:nth-child(6) { animation-delay: 0.6s; }
.content-section:nth-child(7) { animation-delay: 0.7s; }

/* Smooth scroll indicator */
.scroll-progress {
  position: fixed;
  top: var(--header-height);
  left: var(--sidebar-width);
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--domain1), var(--domain6));
  transform-origin: left;
  z-index: 51;
  transition: transform 0.1s linear;
}

/* Interactive comparison table row hover */
.styled-table tbody tr {
  transition: all 0.2s ease;
}

.styled-table tbody tr:hover td {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* Accordion animation for expandable content */
.accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s ease;
  opacity: 0;
}

.accordion-content.open {
  max-height: 2000px;
  opacity: 1;
}

.accordion-header {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  transition: all 0.2s ease;
}

.accordion-header:hover {
  background: var(--bg-card-hover);
}

.accordion-icon {
  transition: transform 0.3s ease;
}

.accordion-header.open .accordion-icon {
  transform: rotate(180deg);
}

/* Tab content transition */
.tab-content {
  animation: fadeIn 0.3s ease;
}

/* Interactive timeline */
.timeline {
  position: relative;
  padding-left: 30px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 11px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border-color);
}

.timeline-item {
  position: relative;
  margin-bottom: var(--space-lg);
  animation: pageSlideInLeft 0.4s ease backwards;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -23px;
  top: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--domain1);
  background: var(--bg-primary);
  z-index: 1;
}

.timeline-item:hover::before {
  background: var(--domain1);
  box-shadow: 0 0 8px var(--domain1);
}

/* Interactive process steps */
/* Process Flow - Vertical Timeline Layout */
.process-steps {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 16px 0 16px 48px;
  position: relative;
}

/* Vertical connecting line */
.process-steps::before {
  content: '';
  position: absolute;
  left: 22px;
  top: 36px;
  bottom: 36px;
  width: 3px;
  background: linear-gradient(to bottom, var(--domain-color, var(--domain1)), rgba(128,128,128,0.2));
  border-radius: 2px;
}

.process-step {
  display: flex;
  align-items: flex-start;
  position: relative;
}

.process-arrow {
  display: none; /* Hide old horizontal arrows */
}

.process-step-box {
  flex: 1;
  padding: 16px 20px;
  background: linear-gradient(145deg, var(--bg-secondary), var(--bg-tertiary));
  border: 1px solid var(--border-color);
  border-radius: 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  text-align: left;
  transition: all 0.3s cubic-bezier(0.4,0,0.2,1);
  cursor: default;
  position: relative;
  margin-bottom: 12px;
  line-height: 1.55;
  border-left: 3px solid rgba(128,128,128,0.15);
}

.process-step-box:hover {
  border-left-color: var(--domain-color, var(--domain1));
  transform: translateX(4px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

.process-step-box .step-number {
  position: absolute;
  left: -44px;
  top: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--domain-color, var(--domain1)), var(--domain-color, var(--domain1)));
  color: white;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(0,0,0,0.2), 0 0 0 3px rgba(128,128,128,0.08);
  z-index: 2;
}

.process-step-box.decision {
  border-left-color: var(--accent-gold) !important;
  background: linear-gradient(145deg, rgba(251,191,36,0.06), var(--bg-tertiary));
}

.process-step-box.decision .step-number {
  background: linear-gradient(135deg, var(--accent-gold), #D97706);
}

/* Responsive - horizontal on wide screens if few steps */
@media (min-width: 1100px) {
  .process-steps.compact {
    flex-direction: row;
    flex-wrap: wrap;
    padding-left: 0;
    justify-content: center;
    gap: 8px;
  }
  .process-steps.compact::before { display: none; }
  .process-steps.compact .process-step-box {
    text-align: center;
    min-width: 140px;
    max-width: 200px;
    border-left: 1px solid var(--border-color);
    border-top: 3px solid var(--domain-color, var(--domain1));
    margin-bottom: 0;
  }
  .process-steps.compact .process-step-box .step-number {
    position: absolute;
    top: -14px;
    left: 50%;
    transform: translateX(-50%);
  }
  .process-steps.compact .process-arrow {
    display: flex;
    align-items: center;
  }
}

/* Interactive info cards with icons */
.info-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  display: flex;
  gap: var(--space-md);
  transition: all 0.25s ease;
  cursor: pointer;
}

.info-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent-color, var(--domain1));
}

.info-card-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-lg);
  color: white;
  flex-shrink: 0;
}

.info-card-content h4 {
  font-size: var(--font-base);
  font-weight: 600;
  margin-bottom: var(--space-xs);
}

.info-card-content p {
  font-size: var(--font-sm);
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}

/* Expandable detail card */
.detail-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--space-md);
  transition: all 0.25s ease;
}

.detail-card:hover {
  border-color: var(--border-light);
}

.detail-card-header {
  padding: var(--space-md) var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  cursor: pointer;
  transition: background 0.2s ease;
}

.detail-card-header:hover {
  background: var(--bg-card-hover);
}

.detail-card-header h4 {
  flex: 1;
  font-size: var(--font-base);
  font-weight: 600;
}

.detail-card-toggle {
  color: var(--text-dim);
  transition: transform 0.3s ease;
}

.detail-card.open .detail-card-toggle {
  transform: rotate(180deg);
}

.detail-card-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.detail-card.open .detail-card-body {
  max-height: 1000px;
}

.detail-card-body-inner {
  padding: 0 var(--space-lg) var(--space-lg);
  border-top: 1px solid var(--border-color);
  padding-top: var(--space-md);
}

/* Glassmorphism cards */
.glass-card {
  background: rgba(30, 41, 59, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-xl);
}

[data-theme="light"] .glass-card {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(0,0,0,0.08);
}

/* Gradient text */
.gradient-text {
  background: linear-gradient(135deg, var(--domain1), var(--domain6));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Animated background gradient for hero sections */
.hero-gradient {
  background: linear-gradient(-45deg,
    rgba(59,130,246,0.08),
    rgba(139,92,246,0.08),
    rgba(6,182,212,0.08),
    rgba(236,72,153,0.08));
  background-size: 400% 400%;
  animation: gradientShift 15s ease infinite;
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ============================================
   ENHANCED VISUAL ANIMATIONS
   ============================================ */

/* Count-up number animation */
@keyframes countUp {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: scale(1); }
}

/* Slide in from bottom with spring */
@keyframes springUp {
  0% { opacity: 0; transform: translateY(30px) scale(0.95); }
  60% { opacity: 1; transform: translateY(-4px) scale(1.01); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* Slide in from left */
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-24px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Scale pop */
@keyframes scalePop {
  0% { transform: scale(0); }
  70% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* Shimmer loading effect */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Glow pulse */
@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 8px currentColor; }
  50% { box-shadow: 0 0 20px currentColor; }
}

/* Utility classes */
.animate-spring-up { animation: springUp 0.6s var(--ease-spring) forwards; }
.animate-count-up { animation: countUp 0.5s var(--ease-spring) forwards; }
.animate-scale-pop { animation: scalePop 0.4s var(--ease-bounce) forwards; }
.animate-slide-left { animation: slideInLeft 0.4s var(--ease-spring) forwards; }

/* Stagger delays */
.stagger-1 { animation-delay: 0.05s; }
.stagger-2 { animation-delay: 0.1s; }
.stagger-3 { animation-delay: 0.15s; }
.stagger-4 { animation-delay: 0.2s; }
.stagger-5 { animation-delay: 0.25s; }
.stagger-6 { animation-delay: 0.3s; }

/* Card lift hover */
.card-lift {
  transition: transform 0.3s var(--ease-spring), box-shadow 0.3s ease;
}
.card-lift:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

/* Button press effect */
.btn-press:active {
  transform: scale(0.96);
  transition: transform 0.1s ease;
}

/* Shimmer skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-secondary) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

/* Scroll reveal — elements animate when scrolled into view */
.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s var(--ease-spring), transform 0.6s var(--ease-spring);
}
.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Number counter inline style */
.count-value {
  display: inline-block;
  animation: countUp 0.8s var(--ease-spring) forwards;
}

/* Sparkline container */
.sparkline {
  display: inline-block;
  vertical-align: middle;
}
.sparkline svg {
  overflow: visible;
}

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