Javascript is used for the Gnome shell and it’s doing a fine job there. And if you paired javascript to something like Tk (as in Tcl/Tk), I guess it would be fine too. The web primitives are just horrible for desktop uses.
That's what PDF is for. CSS is for documents, but namely documents for screens, and on screens you want consistency with all the things on that same screen.
> there’s a load of templates (and frameworks) on the internet if you want a standard set of components.
But not a great way to use them. You can make anything work when you have low-level primitives, so it is not a case that it cannot be done, but that's missing the forest for the trees. You can also program a computer by flipping toggle switches, yet we developed better tools (e.g. programming languages) because sometimes its nice to have more comfortable abstractions.
But then CSS came along and threw out the baby with the bathwater, returning us back to the bare primitives, forcing entities to redo all that work again. Except this time CSS didn't offer a good mechanism to wrap up that hard work in a nice API bow, so everyone ended up getting pushed into having to redo that same hard work every time they started a new project, leading to a bunch of poor, inconsistent, and often downright wacky implementations.
To be fair, the problem isn't CSS per se, it is just that it is much too low-level for all but the small number of entities focused on the aforementioned hard problems and browsers failed to offer anything higher-level for the rest of us. Javascript has tried taking on a stand-in role for the lack of the higher-level abstraction being natively offered by the browser, but that comes with its own limitations so it isn't always a viable choice, not to mention that having to resort to using a full programming environment completely defeats the purpose of having CSS.
CSS gets all the hate because it is more often than not the wrong tool for the job but the only tool available at hand.