When you cast a spell, choose what level you cast it at. If you want to cast cure light wounds at 9th level, go ahead.
Targets save as normal, you apply the effects as normal.
Then you lose mana.
You start with mana = max hp.
The mana you lose is XdY, where:
X = the level of the spell you cast it at
Y = your HD size (or, if you're the kind of person that multiclasses, shame on you, you use the highest HD you have hahaha; but, since I am merciful, if you have only 1 level in fighter and cast a level 2 spell, "use up" your figher HD first, and then you can use your next highest HD size; so 1d10+1d6 mana).
However, don't count any die that comes up its max value.
So a level 1 wizard with 7 mana casts fireball (presuming the character somehow knows the spell). It's a level 3 spell. That means 3d6 mana loss after the spell takes effect. Death save time.
Mod to taste.
* you lose maximum hp and don't track a separate pool of mana; this way clerics can't be a mana fountain
* make a check to avoid mana loss