Sorry for the none responsive spam below.
Your earnest money check is like a security deposit that says you'll hold up your end of the contract or the seller can keep the money. Now, the goal is not to lose the money and the best way to protect yourself from having this happen is to use a great agent and pay attention to the time lines of your contract. you'll likely have an inspection or due diligence time frame to make sure the house, area, HOA are all acceptable. Once you waive your contingencies, your earnest money will be at risk.
Earnest money is typically held in a trust account by the Realtor's office or an Escrow company. There are strict rules that must be followed by whoever holds it and how and when it can be released.
If you complete the purchase, it's applied to your down payment or closing costs. If your rescind your deal, the seller "may" try to claim some, but if you are legitimately allowed to get out of the deal they can't. If the push it, there will be a process to resolve the issue.
Talk to your agent for the best, most local answer.