/**
 * Typography Animation Integration
 * Seamlessly integrates modern typography with existing animations.css
 * Ensures compatibility and enhanced user experience
 * 
 * Features:
 * - Smooth typography animations
 * - Content reveal animations
 * - Scroll-triggered typography effects
 * - Performance optimizations
 * - Compatibility with existing animation system
 */

/* ===== CONTENT ANIMATION INTEGRATION ===== */
/* Enhanced content animations that work with existing system */
.entry-content, .article-content, .prose {
    /* Ensure compatibility with existing scroll animations */
    transform-origin: center top;
    backface-visibility: hidden;
    will-change: transform, opacity;
    
    /* Smooth entrance animation */
    opacity: 0;
    animation: modernContentFadeIn 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.2s both;
}

@keyframes modernContentFadeIn {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    60% {
        opacity: 0.8;
        transform: translateY(8px) scale(0.98);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ===== HEADING STAGGER ANIMATIONS ===== */
/* Progressive heading reveals similar to existing animation patterns */
.entry-content h1, .article-content h1, .prose h1 {
    opacity: 0;
    animation: headingReveal 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.4s both;
}

.entry-content h2, .article-content h2, .prose h2 {
    opacity: 0;
    animation: headingReveal 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.6s both;
}

.entry-content h3, .article-content h3, .prose h3 {
    opacity: 0;
    animation: headingReveal 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.8s both;
}

@keyframes headingReveal {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.9);
        filter: blur(4px);
    }
    50% {
        opacity: 0.7;
        transform: translateY(5px) scale(0.95);
        filter: blur(1px);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0px);
    }
}

/* ===== PARAGRAPH STAGGER ANIMATIONS ===== */
/* Paragraphs fade in progressively */
.entry-content p, .article-content p, .prose p {
    opacity: 0;
    animation: paragraphFadeIn 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) 1s both;
}

.entry-content p:nth-child(2), .article-content p:nth-child(2), .prose p:nth-child(2) {
    animation-delay: 1.1s;
}

.entry-content p:nth-child(3), .article-content p:nth-child(3), .prose p:nth-child(3) {
    animation-delay: 1.2s;
}

.entry-content p:nth-child(4), .article-content p:nth-child(4), .prose p:nth-child(4) {
    animation-delay: 1.3s;
}

.entry-content p:nth-child(n+5), .article-content p:nth-child(n+5), .prose p:nth-child(n+5) {
    animation-delay: 1.4s;
}

@keyframes paragraphFadeIn {
    0% {
        opacity: 0;
        transform: translateY(15px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== INTERACTIVE ELEMENT ANIMATIONS ===== */
/* Enhanced hover animations for content elements */
.entry-content a, .article-content a, .prose a {
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.entry-content a::before, .article-content a::before, .prose a::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background: linear-gradient(90deg, hsl(var(--primary)), hsl(var(--secondary)));
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.entry-content a:hover::before, .article-content a:hover::before, .prose a:hover::before {
    width: 100%;
}

/* Blockquote entrance animation */
.entry-content blockquote, .article-content blockquote, .prose blockquote {
    opacity: 0;
    transform: translateX(-20px) scale(0.95);
    animation: blockquoteSlideIn 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94) 1.5s both;
}

@keyframes blockquoteSlideIn {
    0% {
        opacity: 0;
        transform: translateX(-20px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

/* List item stagger animation */
.entry-content ul li, .article-content ul li, .prose ul li,
.entry-content ol li, .article-content ol li, .prose ol li {
    opacity: 0;
    transform: translateX(-10px);
    animation: listItemFadeIn 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

.entry-content ul li:nth-child(1), .article-content ul li:nth-child(1), .prose ul li:nth-child(1),
.entry-content ol li:nth-child(1), .article-content ol li:nth-child(1), .prose ol li:nth-child(1) {
    animation-delay: 1.6s;
}

.entry-content ul li:nth-child(2), .article-content ul li:nth-child(2), .prose ul li:nth-child(2),
.entry-content ol li:nth-child(2), .article-content ol li:nth-child(2), .prose ol li:nth-child(2) {
    animation-delay: 1.7s;
}

.entry-content ul li:nth-child(3), .article-content ul li:nth-child(3), .prose ul li:nth-child(3),
.entry-content ol li:nth-child(3), .article-content ol li:nth-child(3), .prose ol li:nth-child(3) {
    animation-delay: 1.8s;
}

.entry-content ul li:nth-child(n+4), .article-content ul li:nth-child(n+4), .prose ul li:nth-child(n+4),
.entry-content ol li:nth-child(n+4), .article-content ol li:nth-child(n+4), .prose ol li:nth-child(n+4) {
    animation-delay: 1.9s;
}

@keyframes listItemFadeIn {
    0% {
        opacity: 0;
        transform: translateX(-10px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ===== IMAGE AND MEDIA ANIMATIONS ===== */
/* Enhanced image entrance animations */
.entry-content img, .article-content img, .prose img {
    opacity: 0;
    transform: scale(0.9);
    animation: imageZoomIn 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) 2s both;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes imageZoomIn {
    0% {
        opacity: 0;
        transform: scale(0.9);
        filter: blur(4px);
    }
    100% {
        opacity: 1;
        transform: scale(1);
        filter: blur(0px);
    }
}

.entry-content img:hover, .article-content img:hover, .prose img:hover {
    transform: scale(1.02);
    filter: brightness(1.05) contrast(1.05);
}

/* Table animations */
.entry-content table, .article-content table, .prose table {
    opacity: 0;
    transform: translateY(20px);
    animation: tableSlideUp 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) 2.2s both;
}

@keyframes tableSlideUp {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== SCROLL-TRIGGERED ANIMATIONS ===== */
/* Enhanced scroll animations that work with existing system */
.scroll-animate-content {
    opacity: 0;
    transform: translateY(50px);
    transition: all 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.scroll-animate-content.in-view {
    opacity: 1;
    transform: translateY(0);
}

/* Reading progress enhancements */
.reading-progress {
    opacity: 0;
    animation: progressBarFadeIn 0.5s ease-out 3s both;
    transform-origin: left center;
}

@keyframes progressBarFadeIn {
    0% {
        opacity: 0;
        transform: scaleX(0);
    }
    100% {
        opacity: 1;
        transform: scaleX(1);
    }
}

/* ===== COMPATIBILITY WITH EXISTING ANIMATIONS ===== */
/* Ensure our typography animations don't conflict with existing ones */
.animate-fade-in .entry-content,
.animate-fade-in .article-content,
.animate-fade-in .prose {
    animation-delay: 0.2s !important;
}

.animate-fade-up .entry-content,
.animate-fade-up .article-content,
.animate-fade-up .prose {
    animation-delay: 0.3s !important;
}

/* Work with existing business card animations */
.business-card .entry-content,
.business-card .article-content,
.business-card .prose {
    animation-delay: 0.1s !important;
    animation-duration: 0.4s !important;
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */
/* GPU acceleration for smooth animations */
.entry-content *, .article-content *, .prose * {
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Optimize for 60fps animations */
.entry-content h1, .entry-content h2, .entry-content h3,
.article-content h1, .article-content h2, .article-content h3,
.prose h1, .prose h2, .prose h3 {
    will-change: transform, opacity;
}

.entry-content p, .article-content p, .prose p {
    will-change: transform, opacity;
}

/* Clean up will-change after animations complete */
.entry-content.animations-complete *,
.article-content.animations-complete *,
.prose.animations-complete * {
    will-change: auto;
}

/* ===== REDUCED MOTION SUPPORT ===== */
@media (prefers-reduced-motion: reduce) {
    /* Disable all typography animations for users who prefer reduced motion */
    .entry-content, .article-content, .prose,
    .entry-content *, .article-content *, .prose * {
        animation: none !important;
        transition: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
    
    /* Keep basic hover effects but make them instant */
    .entry-content a, .article-content a, .prose a {
        transition: color 0.1s ease;
    }
    
    .entry-content img:hover, .article-content img:hover, .prose img:hover {
        transform: none;
        transition: none;
    }
}

/* ===== MOBILE OPTIMIZATION ===== */
@media screen and (max-width: 768px) {
    /* Faster animations on mobile for better performance */
    .entry-content, .article-content, .prose {
        animation-duration: 0.4s !important;
        animation-delay: 0.1s !important;
    }
    
    .entry-content h1, .article-content h1, .prose h1,
    .entry-content h2, .article-content h2, .prose h2,
    .entry-content h3, .article-content h3, .prose h3 {
        animation-duration: 0.3s !important;
        animation-delay: 0.2s !important;
    }
    
    .entry-content p, .article-content p, .prose p {
        animation-duration: 0.25s !important;
        animation-delay: 0.3s !important;
    }
    
    /* Disable complex hover effects on mobile */
    .entry-content a::before, .article-content a::before, .prose a::before {
        display: none;
    }
}

/* ===== INTERSECTION OBSERVER INTEGRATION ===== */
/* For JavaScript-triggered animations */
.content-section {
    opacity: 0;
    transform: translateY(30px);
    transition: all 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.content-section.visible {
    opacity: 1;
    transform: translateY(0);
}

.content-section.visible .entry-content,
.content-section.visible .article-content,
.content-section.visible .prose {
    animation-play-state: running;
}

/* ===== PRINT COMPATIBILITY ===== */
@media print {
    /* Disable all animations for print */
    .entry-content, .article-content, .prose,
    .entry-content *, .article-content *, .prose * {
        animation: none !important;
        transition: none !important;
        opacity: 1 !important;
        transform: none !important;
        filter: none !important;
    }
}

/* ===== DARK MODE ANIMATION ADJUSTMENTS ===== */
@media (prefers-color-scheme: dark) {
    /* Slightly different animation timing for dark mode */
    .entry-content, .article-content, .prose {
        animation-timing-function: cubic-bezier(0.23, 1, 0.320, 1);
    }
    
    /* Enhanced glow effects for dark mode */
    .entry-content h1:hover, .article-content h1:hover, .prose h1:hover,
    .entry-content h2:hover, .article-content h2:hover, .prose h2:hover {
        text-shadow: 0 0 10px hsl(var(--primary) / 0.3);
        transition: text-shadow 0.3s ease;
    }
}

/* ===== LOADING STATE MANAGEMENT ===== */
/* Handle loading states gracefully */
.content-loading .entry-content,
.content-loading .article-content,
.content-loading .prose {
    animation-play-state: paused;
}

.content-loaded .entry-content,
.content-loaded .article-content,
.content-loaded .prose {
    animation-play-state: running;
}

/* ===== HIGH REFRESH RATE OPTIMIZATION ===== */
@media screen and (min-resolution: 120dpi) {
    /* Smoother animations for high refresh rate displays */
    .entry-content, .article-content, .prose {
        animation-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    }
    
    .entry-content *, .article-content *, .prose * {
        transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    }
}