I want to use a slippy map with any library, but I want to limit roads to show only motorways, trunks, and primary roads (by the OSM classification of them). Is this even possible? I can’t find any documentation on it anywhere.
You need tiles containing only those roads you are interested in.
You can look at the list of existing tile servers.
If there is not one that fulfil your needs, you will have to set up one yourself. see https://switch2osm.org/serving-tiles/
In addition to the switch2osm guide (which is more about setting up a server than designing a style) have a look at https://ircama.github.io/osm-carto-tutorials/ and https://github.com/gravitystorm/openstreetmap-carto/blob/master/DOCKER.md .
One thing that you will need to do is to decide whether you want to start from scratch or modify an existing style. It’s probably easiest to modify an existing one, and OSM’s “standard” style may not be the best place to start from as it’s quite complicated.
I’m not aware of a worked example for editing a particular style to achieve the effect that you want, but briefly, “carto” styles have a number of layers defined in a project.mml file and if you remove layers from that they’ll disappear from the rendered map.