$html = Get-Content "site\tools.html" -Raw

$colors = @(
    @("var(--violet-100)", "var(--violet-700)"),
    @("var(--pink-bg)", "var(--pink-500)"),
    @("var(--green-bg)", "var(--green)"),
    @("var(--cyan-bg)", "var(--cyan-600)"),
    @("var(--amber-bg)", "var(--amber)"),
    @("var(--brand-google-blue-bg)", "var(--brand-google-blue)")
)

$i = 0
$matches = [regex]::Matches($html, '(?s)<div class="tool-icon"[^>]*>.*?</svg></div>')
$newHtml = $html

# We will loop through the matches in reverse to replace them without breaking indices
for ($j = $matches.Count - 1; $j -ge 0; $j--) {
    $match = $matches[$j]
    
    # We want a deterministic but varied color. Let's just rotate.
    $colorPair = $colors[$j % $colors.Length]
    $bg = $colorPair[0]
    $fg = $colorPair[1]
    
    $oldStr = $match.Value
    
    # Replace the style attribute in this specific match
    $newStr = [regex]::Replace($oldStr, 'style="background:[^"]+"', "style=`"background:$bg;color:$fg;`"")
    
    # Splice it in
    $newHtml = $newHtml.Substring(0, $match.Index) + $newStr + $newHtml.Substring($match.Index + $match.Length)
}

Set-Content -Path "site\tools.html" -Value $newHtml -Encoding UTF8
Write-Host "Made tools.html fully colorful!"
