.PHONY: help serve size validate tidy ascii clean

help: ## Show this help
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
	  awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[36m%-12s\033[0m %s\n", $$1, $$2}'

serve: ## Start a local static server on :8000
	@command -v python3 >/dev/null 2>&1 && \
	  python3 -m http.server 8000 || \
	  (command -v npx >/dev/null 2>&1 && npx --yes http-server -p 8000) || \
	  echo "Install python3 or node to serve locally."

size: ## Report file sizes
	@echo "HTML:"
	@find . -maxdepth 2 -name "*.html" -printf "  %-30p %s bytes\n"
	@echo
	@echo "CSS:"
	@find static/css -name "*.css" -printf "  %-30p %s bytes\n"
	@echo
	@echo "Images (svg):"
	@find static/img -name "*.svg" -printf "  %-30p %s bytes\n"

validate: ## Quick HTML sanity check (counts opening vs closing tags)
	@for f in *.html; do \
	  open=$(grep -oE '<[a-zA-Z][a-zA-Z0-9-]*' "$$f" | grep -vE '^<(br|hr|img|input|meta|link|source|area|base|col|embed|param|track|wbr|!--)' | sed 's/^<//' | sort -u); \
	  close=$$(grep -oE '</[a-zA-Z][a-zA-Z0-9-]*' "$$f" | sed 's/^<\///' | sort -u); \
	  echo "$$f"; \
	  diff <(echo "$$open") <(echo "$$close") || true; \
	done

tidy: ## Run html-tidy on every .html
	@for f in *.html; do echo "--- $$f ---"; tidy -e -q $$f || true; done

ascii: ## Regenerate the body-rain ASCII art (needs chafa)
	@mkdir -p static/ascii
	chafa -f symbols -c none -s 240x60 --symbols ascii --animate off \
	  static/img/og-image-bg.svg > static/ascii/rain.txt
	@echo "Regenerated static/ascii/rain.txt (from static/img/og-image-bg.svg)"

clean: ## Remove build artefacts
	@rm -rf bin/ node_modules/ dist/
