import re
from pathlib import Path

root = Path('.')
css_text = (root / 'style.css').read_text(encoding='utf-8')
selectors = set()
for block in css_text.split('{'):
    header = block.strip().split('\n')[-1].strip()
    if not header or '}' in header:
        continue
    parts = [p.strip() for p in header.split(',') if p.strip()]
    for part in parts:
        tokens = re.findall(r'([.#][A-Za-z0-9_-]+)', part)
        selectors.update(tokens)

files = [p for p in root.rglob('*') if p.suffix in {'.php', '.html', '.js', '.css'} and 'dist' not in str(p) and 'lucky-spin' not in str(p) and p.name != 'unused_css_scan.py']
content = [p.read_text(encoding='utf-8', errors='ignore') for p in files]
used = set()
for sel in selectors:
    token = sel[1:]
    pattern = re.compile(r'\b' + re.escape(token) + r'\b')
    for txt in content:
        if pattern.search(txt):
            used.add(sel)
            break
unused = sorted(selectors - used)
print('Total selectors:', len(selectors))
print('Used:', len(used))
print('Unused:', len(unused))
for s in unused:
    print(s)
