To the last point, courts do actually try to solve this.
The goal of the
https://en.wikipedia.org/wiki/Abstraction-Filtration-Compari... that gets used is, in fact, to abstract things, eliminate the non-copyrightable parts, and try to see if any important stuff is left.
Wikipedia actually has a fairly good explanation of it in practice.
So they are actually trying, and the real problem is that existing copyright law, for literary works, is just not a match for how software tends to actually be developed, which is that "most code is worthless, there is very little that really should be protected".
(and before people argue that it could be millions of lines, the US, thankfully, refuses to have a sweat of the brow doctrine)