Capital gains on sale of house

How do I figure capital gains when the house was built from scratch?  Parents bought land for $25,000 25 years ago.  Then built house on said land using $150,000 from a 401k.  Parents divorced in 2009.  Mom retained house and refi to be in her name only.  Step dad died in 2017.  Mom sold house in 2024 for $490,000.  At time of sale she had a mortgage from the refi in 2009 of $146,000.  Used proceeds to purchase another home.  Is the cost basis $25,000 + $150,000 + any improvements done like a new deck, furnace and AC?  Then subtract that from the $490,000 minus all the realtor fees associated with the sale?

 

Mom is 77 and her income is about $38,000 annually from SSI and a couple pensions.  Will she even have to worry about capital gains since she is under the $47,000 income for capital gains?