import re

with open('index.html', 'r', encoding='utf-8') as f:
    content = f.read()

# 1. Add class to hero h1
old_h1 = '''<h1 style="font-family: 'Phudu', sans-serif !important; font-size: clamp(2.6rem, 4.2vw, 
62px) !important; font-weight: 600 !important; color: #ffffff !important; text-transform: uppercase; line-height: 62px 
!important; letter-spacing: -0.01em; margin-bottom: 2.2rem; text-shadow: none !important;">'''
new_h1 = '''<h1 class="hero-title" style="font-family: 'Phudu', sans-serif !important; font-size: clamp(2.6rem, 4.2vw, 
62px) !important; font-weight: 600 !important; color: #ffffff !important; text-transform: uppercase; line-height: 62px 
!important; letter-spacing: -0.01em; margin-bottom: 2.2rem; text-shadow: none !important;">'''
content = content.replace(old_h1, new_h1)

# 2. Exclude hero-title from ScrollTrigger in splitHeadingsWordByWord
old_st = '''const words = heading.querySelectorAll(".gsap-heading-word");
            if (words.length > 0) {
                gsap.to(words, {
                    scrollTrigger: {'''
new_st = '''const words = heading.querySelectorAll(".gsap-heading-word");
            if (words.length > 0) {
                if (heading.classList.contains("hero-title")) return; // handled by preloader
                gsap.to(words, {
                    scrollTrigger: {'''
content = content.replace(old_st, new_st)

# 3. Add animation trigger in preloader window load
old_pl = '''timeline.to(preloaderLogo, {
            opacity: 0,
            duration: 0.4,
            ease: "power2.inOut"
        }, "+=0.3")'''
new_pl = '''timeline.to(preloaderLogo, {
            opacity: 0,
            duration: 0.4,
            ease: "power2.inOut"
        }, "+=0.3")
        
        // Trigger hero title animation right as circle expands
        const heroWords = document.querySelectorAll(".hero-title .gsap-heading-word");
        if (heroWords.length > 0) {
            timeline.to(heroWords, {
                opacity: 1,
                y: 0,
                stagger: 0.08,
                duration: 0.7,
                ease: "power4.out"
            }, "-=0.1"); // Start at the same time as the circle expands
        }'''
content = content.replace(old_pl, new_pl)

with open('index.html', 'w', encoding='utf-8') as f:
    f.write(content)

print("Hero title animation fixed.")
