There's a whole bunch of unfixed issues with the way spoilers are implemented in the Stack Exchange CSS:
They don't work for code blocks (at least not on sites using prettify).
On older sites, they don't work for images (but on beta sites they do).
When editing, they don't work for links (but outside the editor they do).
On beta sites, they make inline code look awful (but on SO they don't).
Perhaps the biggest issue is that the styling is wildly inconsistent between sites, and so are the bugs in it. Some bugs only appear on beta sites, while other bugs appear on SO, but not on beta sites.
Besides, the whole approach currently used for spoiler hiding — that is, styling everything inside spoilers to look like the background, and then restyling it on :hover
to look normal again — is fundamentally backwards, and will keep generating bugs as the spoiler styles inevitably fail to keep up with changes to other styles.
It should be possible to fix all these issues at once by scrapping the current spoiler styles and replacing them with something more reliable and maintainable. I have suggested two such options in my own answers below, and I also welcome any alternative suggestions.
Note that this bug report is specifically about the CSS styling of spoiler blocks. It's not meant to cover the various known issues with Markdown parsing inside spoilers, nor issues with spoiler visibility on mobile devices. Those are separate bugs, and need separate fixes.