I understand how to load spells from my primary and secondary school to the spell deck. I understand how to load treasure cards to the spell deck. What I don't understand is how to control what spells come up during combat. It appears to be totally random. Many times I have needed a certain spell to come up, but of course it didn't.
Is there a way to control this? Is there some rhyme or reason to it?
Whenever there is an opening in your hand, the game picks a card uniformly at random from among those that are in your main deck but aren't already in your hand and haven't already been successfully played, and adds that card to your hand. The main deck includes both the cards that you manually pick, as well as cards that you automatically gain from equipped items. If you have three copies of a particular card in your deck, it counts those as three independent cards for this purpose.
This continues until there are no cards remaining in your main deck. At this point, it leaves an opening in your hand. You can choose to draw a card manually at this point, which will cause it to draw a card uniformly at random from your sideboard. You cannot get a card from your sideboard until you have six or fewer cards remaining in your main deck. The game does not draw automatically from the sideboard to prevent you from accidentally wasting treasure cards without meaning to.
At the start of a battle, you have seven openings in your hand, so it picks a card at random in this manner seven consecutive times. When you play a card, if successful, the card is removed for the duration of the battle. This creates an opening in your hand, so the game draws another card for you. If you play a card and it fizzles, the card is returned to your deck, which creates an opening so the game has to draw another card, but the card that just fizzled can be drawn again during the same battle.
Any card from your main deck that is successfully played will be returned to your main deck upon the conclusion of the battle. Any card from your sideboard that is successfully played is destroyed. Any card from your sideboard that fizzles is returned to your sideboard.
Knowing that the cards are chosen uniformly at random lets you compute the probability that a given card will be drawn at a given time. Having more copies of a particular card makes it more likely that that particular card will be drawn, and less likely that other cards will be drawn. Choose your cards to be about as common in your deck as the probability you wish to draw them in battle. Note that drawing other cards early on makes it more likely that the cards you haven't yet drawn will show up later; conversely, if you draw a card at the start, you can't possibly redraw that particular card unless you play it and it fizzles.
Combat is not about finding a strategy that is guaranteed to win. It is about finding a strategy that will win with high probability.