Rule clarification about debt mechanics
It is a common mistake to think of treasure as cards you play in order to buy something. Instead, it is important to remember that playing a Treasure card is almost just like playing an Action card that produces coin when played (such as Market or Legionary). Playing a Silver simply adds $2 to your pool of coins you can spend this turn, just like playing a Market adds $1.

So at the start of your buy phase, you will play all the Treasure cards you want to play this turn (which more often than not is just all of the Treasure cards in your hand). Then you will buy the card or cards that you want, and if you have leftover coin after doing so, you can use it to pay off debt.

This has the practical effect of being able to spend $4 to buy an Engineer just as if it cost $4 instead of 4 debt; but the actual steps you are taking is to first buy Engineer for $0, taking 4 debt, and then spending $4 to pay off that 4 debt.