import re

def modify_html():
    with open('index.html', 'r', encoding='utf-8') as f:
        content = f.read()
    
    # 1. Header fix: position: absolute -> position: fixed
    content = re.sub(
        r'(<header class="header js-header" style="[^"]*)position: absolute;',
        r'\1position: fixed;',
        content
    )
    
    # 2. Hero grid responsive class
    # Replace inline grid styles with hero-grid-layout class
    content = re.sub(
        r'<div class="hero-grid" style="position: relative; z-index: 10; width: 100%; padding: 2.2rem 3rem 2.8rem 3rem; display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 3.5rem; align-items: flex-end; box-sizing: border-box; overflow: hidden !important;">',
        r'<div class="hero-grid hero-grid-layout">',
        content
    )

    # 3. Add js-hero-text to the left column for GSAP animation
    content = re.sub(
        r'<!-- Left Column: Eyebrow, Title & Buttons -->\n(\s*)<div style="display: flex; flex-direction: column; justify-content: flex-end;">',
        r'<!-- Left Column: Eyebrow, Title & Buttons -->\n\1<div class="js-hero-text" style="display: flex; flex-direction: column; justify-content: flex-end;">',
        content
    )
    
    # Also add js-hero-text to the right column
    content = re.sub(
        r'<!-- Right Column: Subtitle Paragraph & Stats Counter Strip -->\n(\s*)<div style="display: flex; flex-direction: column; justify-content: flex-end;">',
        r'<!-- Right Column: Subtitle Paragraph & Stats Counter Strip -->\n\1<div class="js-hero-text" style="display: flex; flex-direction: column; justify-content: flex-end;">',
        content
    )
    
    # 4. Word of God section background
    # Add the sketch-bg.png
    content = re.sub(
        r'<section id="bible-quote-section" style="(padding: 7rem 0; background-color: #0a0a0a; background-image: repeating-linear-gradient[^;]+;)',
        r'<section id="bible-quote-section" style="\1 background-image: url(\'assets/images/sketch-bg.png\'), repeating-linear-gradient(45deg, rgba(255,255,255,0.02) 0px, rgba(255,255,255,0.02) 2px, transparent 2px, transparent 12px); background-size: cover, auto; background-position: center, center; background-blend-mode: overlay, normal;',
        content
    )

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

def modify_css():
    with open('css/styles.css', 'r', encoding='utf-8') as f:
        content = f.read()

    hero_css = """
/* ===== HERO GRID RESPONSIVE LAYOUT ===== */
.hero-grid-layout {
    position: relative; 
    z-index: 10; 
    width: 100%; 
    padding: 2.2rem 3rem 2.8rem 3rem; 
    display: grid; 
    grid-template-columns: 1.15fr 0.85fr; 
    gap: 3.5rem; 
    align-items: flex-end; 
    box-sizing: border-box; 
    overflow: hidden !important;
}

@media (max-width: 991px) {
    .hero-grid-layout {
        grid-template-columns: 1fr;
        gap: 2rem;
        padding: 6rem 1.5rem 2rem 1.5rem; /* more padding top to clear header */
    }
    
    .hero-grid-layout h1 {
        font-size: clamp(2.2rem, 8vw, 3rem) !important;
        line-height: 1.1 !important;
        margin-bottom: 1.5rem !important;
    }
    
    .hero-buttons-row {
        gap: 1rem !important;
    }
    
    .hero-grid-layout > div:nth-child(2) > p {
        font-size: 14px !important;
        line-height: 22px !important;
        margin-bottom: 1.5rem !important;
    }
    
    .hero-grid-layout > div:nth-child(2) > div {
        /* Stats strip */
        padding-top: 1rem !important;
        grid-template-columns: 1fr 1fr 1fr !important;
        gap: 0.5rem;
    }
    
    .hero-grid-layout > div:nth-child(2) > div > div {
        padding-right: 0.5rem !important;
        padding-left: 0.5rem !important;
    }
    
    .hero-grid-layout > div:nth-child(2) > div > div:first-child {
        padding-left: 0 !important;
    }
    
    .hero-grid-layout > div:nth-child(2) > div > div > div:first-child {
        font-size: 1.6rem !important;
    }
    
    .hero-grid-layout > div:nth-child(2) > div > div > div:last-child {
        font-size: 0.6rem !important;
    }
}

@media (max-width: 575px) {
    .hero-grid-layout > div:nth-child(2) > div {
        grid-template-columns: 1fr !important;
        border-top: none !important;
        gap: 1rem;
    }
    
    .hero-grid-layout > div:nth-child(2) > div > div {
        border-right: none !important;
        border-top: 1px solid rgba(255, 255, 255, 0.25);
        padding: 0.8rem 0 0 0 !important;
    }
}
"""
    if "HERO GRID RESPONSIVE LAYOUT" not in content:
        with open('css/styles.css', 'a', encoding='utf-8') as f:
            f.write(hero_css)

modify_html()
modify_css()
print("Done")
