/* ==========================================
   Smooth Animations
   ========================================== */

/* ==========================================
   Base Transition Utilities
   ========================================== */
:root {
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out-back: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-in-out-circ: cubic-bezier(0.85, 0, 0.15, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;
  --duration-slower: 600ms;
}

/* ==========================================
   Page Transitions
   ========================================== */
.content {
  animation: pageEnter var(--duration-slow) var(--ease-out-expo);
}

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

/* Skeleton fade out when content loads */
.skeleton-loader {
  animation: skeletonPulse 1.5s ease-in-out infinite;
}

@keyframes skeletonPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ==========================================
   Scroll-triggered Fade In
   ========================================== */
.fade-in-up {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity var(--duration-slow) var(--ease-out-expo),
              transform var(--duration-slow) var(--ease-out-expo);
}

.fade-in-up.visible {
  opacity: 1;
  transform: translateY(0);
}

.fade-in-left {
  opacity: 0;
  transform: translateX(-30px);
  transition: opacity var(--duration-slow) var(--ease-out-expo),
              transform var(--duration-slow) var(--ease-out-expo);
}

.fade-in-left.visible {
  opacity: 1;
  transform: translateX(0);
}

.fade-in-right {
  opacity: 0;
  transform: translateX(30px);
  transition: opacity var(--duration-slow) var(--ease-out-expo),
              transform var(--duration-slow) var(--ease-out-expo);
}

.fade-in-right.visible {
  opacity: 1;
  transform: translateX(0);
}

.fade-in-scale {
  opacity: 0;
  transform: scale(0.95);
  transition: opacity var(--duration-slow) var(--ease-out-expo),
              transform var(--duration-slow) var(--ease-out-expo);
}

.fade-in-scale.visible {
  opacity: 1;
  transform: scale(1);
}

/* ==========================================
   Staggered Card Animations (Home Page)
   ========================================== */
.card-grid .card {
  opacity: 0;
  transform: translateY(40px);
  animation: cardEnter var(--duration-slower) var(--ease-out-expo) forwards;
}

.card-grid .card:nth-child(1) { animation-delay: 0.1s; }
.card-grid .card:nth-child(2) { animation-delay: 0.2s; }
.card-grid .card:nth-child(3) { animation-delay: 0.3s; }
.card-grid .card:nth-child(4) { animation-delay: 0.4s; }

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

/* Hero stats staggered animation */
.hero-stat {
  opacity: 0;
  transform: translateY(20px);
  animation: statEnter var(--duration-slow) var(--ease-out-expo) forwards;
}

.hero-stat:nth-child(1) { animation-delay: 0.3s; }
.hero-stat:nth-child(2) { animation-delay: 0.4s; }
.hero-stat:nth-child(3) { animation-delay: 0.5s; }

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

/* Checklist items staggered */
.checklist li {
  opacity: 0;
  transform: translateX(-20px);
  animation: checklistEnter var(--duration-normal) var(--ease-out-expo) forwards;
}

.checklist li:nth-child(1) { animation-delay: 0.5s; }
.checklist li:nth-child(2) { animation-delay: 0.6s; }
.checklist li:nth-child(3) { animation-delay: 0.7s; }
.checklist li:nth-child(4) { animation-delay: 0.8s; }
.checklist li:nth-child(5) { animation-delay: 0.9s; }

@keyframes checklistEnter {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ==========================================
   Enhanced Hover Effects
   ========================================== */

/* Cards */
.card {
  transition: transform var(--duration-normal) var(--ease-out-back),
              box-shadow var(--duration-normal) var(--ease-out-expo),
              border-color var(--duration-fast) ease;
}

.card:hover {
  transform: translateY(-6px);
  box-shadow: 0 20px 40px rgba(37, 99, 235, 0.15);
}

.card:active {
  transform: translateY(-2px);
  transition-duration: var(--duration-fast);
}

/* Card icon bounce on hover */
.card:hover .card-icon {
  animation: iconBounce 0.5s var(--ease-out-back);
}

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

/* Sidebar items */
.sidebar-item {
  transition: background var(--duration-fast) ease,
              color var(--duration-fast) ease,
              border-color var(--duration-fast) ease,
              transform var(--duration-fast) ease;
}

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

.sidebar-item:active {
  transform: translateX(2px);
}

/* Sidebar item number pulse on hover */
.sidebar-item:hover .sidebar-item-number {
  animation: numberPulse 0.3s var(--ease-out-expo);
}

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

/* Buttons */
.playground-btn {
  transition: all var(--duration-fast) var(--ease-out-expo);
}

.playground-btn:hover {
  transform: translateY(-1px);
}

.playground-btn:active {
  transform: translateY(0);
}

.playground-btn.run:hover {
  box-shadow: 0 4px 12px rgba(48, 105, 152, 0.3);
}

/* Lesson navigation buttons */
.lesson-nav-btn {
  transition: all var(--duration-normal) var(--ease-out-expo);
}

.lesson-nav-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.15);
}

.lesson-nav-btn:hover svg {
  animation: arrowBounce 0.4s var(--ease-out-expo);
}

.lesson-nav-btn.prev:hover svg {
  animation: arrowBounceLeft 0.4s var(--ease-out-expo);
}

@keyframes arrowBounce {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(4px); }
}

@keyframes arrowBounceLeft {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(-4px); }
}

/* Toolbar buttons */
.toolbar-btn {
  transition: all var(--duration-fast) var(--ease-out-expo);
}

.toolbar-btn:hover {
  transform: scale(1.05);
}

.toolbar-btn:active {
  transform: scale(0.95);
}

/* Dark mode toggle rotation */
#dark-mode-toggle:hover svg {
  animation: sunRotate 0.5s var(--ease-out-expo);
}

@keyframes sunRotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(180deg); }
}

/* Bookmark button */
.bookmark-btn {
  transition: all var(--duration-fast) var(--ease-out-expo);
}

.bookmark-btn:hover {
  transform: scale(1.05);
}

.bookmark-btn:active {
  transform: scale(0.95);
}

.bookmark-btn.active svg {
  animation: heartBeat 0.4s var(--ease-out-back);
}

@keyframes heartBeat {
  0%, 100% { transform: scale(1); }
  25% { transform: scale(1.2); }
  50% { transform: scale(0.95); }
  75% { transform: scale(1.1); }
}

/* ==========================================
   Interactive Elements
   ========================================== */

/* Links with underline animation */
.content a {
  position: relative;
  text-decoration: none;
  border-bottom: none;
}

.content a::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--primary);
  transition: width var(--duration-normal) var(--ease-out-expo);
}

.content a:hover::after {
  width: 100%;
}

/* Code block hover glow */
.content pre {
  transition: box-shadow var(--duration-normal) ease;
}

.content pre:hover {
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.3),
              0 8px 24px rgba(0, 0, 0, 0.2);
}

/* Python playground hover */
.python-playground {
  transition: box-shadow var(--duration-normal) ease,
              transform var(--duration-normal) var(--ease-out-expo);
}

.python-playground:hover {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* Graphviz diagram hover */
.graphviz-diagram {
  transition: box-shadow var(--duration-normal) ease,
              transform var(--duration-normal) var(--ease-out-expo);
}

.graphviz-diagram:hover {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  transform: scale(1.01);
}

/* Table row hover */
.content tr {
  transition: background var(--duration-fast) ease;
}

/* Blockquote hover */
.content blockquote {
  transition: transform var(--duration-normal) var(--ease-out-expo),
              box-shadow var(--duration-normal) ease;
}

.content blockquote:hover {
  transform: translateX(4px);
  box-shadow: -4px 0 0 var(--primary);
}

/* Details/Summary expand animation */
.content details {
  transition: box-shadow var(--duration-normal) ease;
}

.content details[open] {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.content details summary {
  transition: all var(--duration-fast) ease;
}

.content details summary::marker {
  transition: transform var(--duration-normal) ease;
}

/* ==========================================
   Modal Animations
   ========================================== */
.figure-modal-overlay,
.search-modal-overlay {
  animation: overlayFadeIn var(--duration-normal) ease;
}

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

.figure-modal,
.search-modal {
  animation: modalSlideIn var(--duration-slow) var(--ease-out-expo);
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Figure tabs */
.figure-tab {
  transition: all var(--duration-fast) ease;
}

.figure-tab:hover {
  transform: translateY(-2px);
}

/* ==========================================
   Progress Bar Animation
   ========================================== */
.progress-fill {
  transition: width 0.8s var(--ease-out-expo);
}

/* Animated gradient on progress bar */
@keyframes progressShine {
  from { background-position: -200% center; }
  to { background-position: 200% center; }
}

.progress-fill {
  background: linear-gradient(
    90deg,
    var(--primary) 0%,
    var(--secondary) 50%,
    var(--primary) 100%
  );
  background-size: 200% 100%;
  animation: progressShine 3s linear infinite;
}

/* ==========================================
   Scroll-triggered Section Headers
   ========================================== */
.content h2 {
  position: relative;
  overflow: hidden;
}

.content h2::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.6s var(--ease-out-expo);
}

.content h2.visible::before {
  width: 100%;
}

/* ==========================================
   Hero Section Enhancements
   ========================================== */
.hero {
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 60%);
  animation: heroGlow 10s ease-in-out infinite;
}

@keyframes heroGlow {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(10%, 10%); }
  50% { transform: translate(-5%, 15%); }
  75% { transform: translate(-10%, 5%); }
}

.hero h1 {
  animation: heroTitleEnter 0.8s var(--ease-out-expo);
}

@keyframes heroTitleEnter {
  from {
    opacity: 0;
    transform: translateY(30px);
    filter: blur(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}

.hero > p {
  animation: heroTextEnter 0.8s var(--ease-out-expo) 0.2s both;
}

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

/* ==========================================
   Loading Spinner Enhancement
   ========================================== */
.playground-loading .spinner {
  animation: spinnerRotate 1s linear infinite,
             spinnerPulse 2s ease-in-out infinite;
}

@keyframes spinnerRotate {
  to { transform: rotate(360deg); }
}

@keyframes spinnerPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ==========================================
   Copy Button Success Animation
   ========================================== */
.copy-code-btn.copied {
  animation: copySuccess 0.3s var(--ease-out-back);
}

@keyframes copySuccess {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* ==========================================
   Reading Progress Bar
   ========================================== */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: transparent;
  z-index: 1000;
  pointer-events: none;
}

#reading-progress .reading-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.1s ease-out;
  box-shadow: 0 0 10px var(--primary);
}

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

  .fade-in-up,
  .fade-in-left,
  .fade-in-right,
  .fade-in-scale {
    opacity: 1;
    transform: none;
  }

  .card-grid .card,
  .hero-stat,
  .checklist li {
    opacity: 1;
    transform: none;
    animation: none;
  }
}
