The problem
When I joined a legacy project, the main stylesheet was a single 10,000‑line file. It grew organically, with developers adding selectors like .header .nav ul li a or #mainContent .article p.intro . Over time the specificity ballooned, and a tiny change in one place would unexpectedly break the layout elsewhere. The build process was fast, but every time I opened the file I felt a little lost.
Why specificity matters
High specificity makes it hard to predict which rule wins. If you have a rule that uses an ID selector ( #sidebar .widget ) and another that uses three class selectors ( .sidebar .widget .active ), the ID rule will always win, even if the class rule is later in the file. This forces developers to add !important or create even more specific selectors just to get a single change to apply. The result is a cascade that is fragile and difficult to debug.
A step‑by‑step refactor
I decided to take a small, incremental approach instead of ripping the stylesheet apart.…