In terms of what your legal options are, you will need to consult a lawyer licensed in your local jurisdiction. This options vary by city, county, state, and country - to a rather tremendous extent.
However, I can tell you that any decent lawyer will explain to you that almost no legal proceeding is fast, cheap, or painless. Voluntary agreements are almost always the best outcome, yet at the same time your #1 enemy is your own emotions, pigheadedness, and attachment to the details of the situation that seem important to you yet may be of no legal consequence or consideration. Many people also tend to think the reality of the justice system is fairer and more reasonable than it really turns out to be. Mediation is good - get your details sorted and your emotions as under control as possible before you get in there.
When you talk to a lawyer, you will need to have available copies of the primary legal documents, and usefully detailed information about what you could prove if you needed to do so. For instance, they will certainly need a copy of the legally registered deed of the property (which will state how ownership has been recorded), as well as information about how the lien is registered (the mortgage - who is listed and what words are used). If the lawyer would tell you that what you put into the property could be important, they would need to know what you actually have receipts for, how detailed the receipts are, at least rough totals of what money you put in over what time period, etc. (they probably don't care about your time, effort, or sentimental attachment to anything).
Speaking to a lawyer even before mediation is generally a good idea if the money on the line is significant, as having superior knowledge of your legal rights and likelihood of prevailing in court (as well as the time and cost that would likely involve if it came to that) will help you make an informed decision and have a clear case story to present in mediation.
Finally, regardless of what you are told, realize that many lawyers are naturally biased into being overconfident or downplaying risks, as it can generate more fees - but in my experience unless they see huge dollar signs, most lawyers I've talked to are surprisingly honest and upfront in matters like this as they know how messy things can get and they have no desire to make you think it'll be easy and cheap when it really won't be. Still, I tend to assume estimates of costs of legal action tend to be too low, and the true likelihood of success is also lower than they estimate, to try to encourage you to also not enter into costly, time-consuming, and painful litigation that is not actually in your best interests.