$htmlFiles = Get-ChildItem -Path "C:\Users\Calum\.gemini\antigravity\scratch\SunflowerTrucksStatic" -Recurse -Filter "*.html"

foreach ($file in $htmlFiles) {
    $content = Get-Content $file.FullName -Raw

    # 1. Inject the hamburger button before the <nav> element
    if ($content -notmatch 'class="hamburger"') {
        $hamburgerMarkup = "`n        <button class=""hamburger"" aria-label=""Toggle navigation"">`n            <span></span>`n            <span></span>`n            <span></span>`n        </button>`n        <nav>"
        $content = $content -replace '<nav>', $hamburgerMarkup
    }

    # 2. Inject the script tag before </body>
    if ($content -notmatch 'main\.js') {
        # Check depth for relative path
        $depth = ($file.FullName.Substring("C:\Users\Calum\.gemini\antigravity\scratch\SunflowerTrucksStatic".Length) -split '\\').Length - 2
        
        $scriptPath = "assets/js/main.js"
        if ($depth -gt 0) {
            $prefix = ""
            for ($i = 0; $i -lt $depth; $i++) { $prefix += "../" }
            $scriptPath = $prefix + $scriptPath
        }

        $scriptTag = "`n    <script src=""$scriptPath""></script>`n</body>"
        $content = $content -replace '</body>', $scriptTag
    }

    Set-Content -Path $file.FullName -Value $content -NoNewline
}
Write-Host "Updated all HTML files with mobile navigation."
