Agree that Casablanca is not worth a stop (unless you really have to pass through). Fes and Marrakech are where you want to be.
Note that flights on low cost airlines (there are several) between Morocco and Spain (and other places in western Europe) are super-cheap and easy, but they generally do not go every day (typically every 2 or 3), so plan carefully.
I'm not sure that flying directly in to or out of Morocco is going to save you any money - compare total costs. It might save you some time, though...which could be even more constrained...
You have (at best) 11 full usable days (not counting days spend flying to/from Toronto) - and that's assuming you recover quickly and are not a zombie on your first post-arrival day there. Then, you're going between Span and Morocco (once, maybe twice), so you're down to just 9 (or maybe 10) days when you're not flying somewhere. It takes time to get between major destinations in Morocco, too (the train between Fes and Marrakech consumes pretty much a whole day; getting out to the deep desert takes a day, then a day back). My point is, you have pretty limited time. I think you can do your trip (more or less) as you're planning, but you need to guard against doing too much moving around.
Ideally, it would be great to add a few days to your trip if you can possibly. If not...well, you get a few days in Spain and a few days in Morocco. Nothing wrong with that, but there's so much to see/do in each country...