I answered a very similar question not too long ago. I think the answer may be of help
https://www.reddit.com/r/AskHistorians/comments/iff73l/how_did_spain_go_from_controlling_most_of_south/