I've noticed that when I am attacked while offline and I lose 100%, I don't lose all of my gold and mana.
I have a tendency to get a little nervous if I have 8 hours left in a worker's job and I have high reserves of gold and mana laying around. This makes me want to spend some of my gems on either a shield or to just finish the job early so I can spend my currency on the next job.
What determines how much of my gold and mana is at risk to an attacking player?