Remember the last time Southern California homebuying was somewhat reasonably affordable?

Say, oh, 2012?

Well, the economy’s improved in the years after the Great Recession ended — locally and nationally — and fortunately for house hunters, mortgage rates haven’t budged much from near historical lows.

So, I wondered: How does Southern California’s shift in five years from modestly affordable to nearly-impossible-to-swallow pricing compare with the rest of the nation? Please note that in many big towns around the nation it’s a struggle to buy a house and remain financially solvent.

Now, homebuying affordability indexes aren’t a perfect gauge of how much you have to stretch to own a home, but they do help portray the comparative challenge. Look at the “Housing Opportunity Index” from National Association of Home Builders and Wells Fargo Bank. It attempts to track what share of a region’s homes can be bought in a fiscally reasonable manner by a household earning the median local income.

My trusty spreadsheet tells me this opportunity index shows roughly four of five Southern California homes sold can’t be comfortably bought by locals in 2017. And not only is Southern California home to three of the least-affordable big U.S. markets, our region has seen some of the nation’s largest drops in affordability since 2012.

Homebuying nationwide also has become more financially challenging. The opportunity index shows an average 59 percent of U.S. homes were affordable to the median-earning household in the year ended in September. That’s down from 75 percent five years earlier.

The reason is fairly simple: The U.S. median sales price rose 43 percent to $252,750 since 2012, while incomes rose 4 percent to $67,425.

How did Southern California markets handle similar price-to-income mismatches? Poorly, when you look at key local metrics ranked among the 75 most active U.S. housing markets since 2012.

Riverside and San Bernardino counties had the region’s biggest loss of affordability — and fifth largest dip nationwide — with 37 percent of homes sold deemed “affordable” by the opportunity index in the past year vs. 75 percent five years ago. That drop moved the Inland Empire to 10th worst today from the 23rd least affordable big metro in 2012.

The “why” is relatively obvious: The current $323,250 median price in Riverside-San Bernardino is up 84 percent while the median household income is down 1 percent from 2012.

In Los Angeles County, 11 percent of homes bought were deemed affordable by the opportunity index — worst among the 75 big metros. Five years ago, it was 47 percent — so, we have the seventh-biggest drop nationwide.

The L.A. homebuying math is ugly: Its $554,500 median home price is up 79 percent since 2012 while median incomes of $63,900 fell 1 percent.

Orange County had the ninth-largest affordability dip in the nation, by my math, with 13 percent of homes sold deemed affordable this year vs. 47 percent five years ago. O.C.’s $680,250 median price is up 66 percent while incomes are up only 3 percent.

Ponder the affordability headache this way, as roughly measured by the opportunity index: Five years ago, the typical Southern California house hunter could afford one-quarter fewer local homes than the national average. This year, the gap for locals has widened to two-thirds fewer affordable options vs. home seekers elsewhere in the nation.

To be fair, it’s a statewide problem. The four markets with the steepest affordability declines in 2012-17 among the 75 top U.S. metros were Stockton, Oakland, Sacramento, and Fresno. No. 6 was San Diego; No. 8 San Jose. That gave California the top nine spots in my ranking of biggest home affordability declines.

Looking back — often with 20/20 economic hindsight — can be frustrating and educational. If you’re kicking yourself for missing a buying opportunity, ask yourself these questions:

Would you have had the financial nerve to buy in 2012, just after a harsh downturn had cost 1-in-12 Californians their jobs?

Did you really want to be an owner with statewide prices down 40 percent from the peak and one-third of California home sales in foreclosure?

Plus, could you even have gotten a mortgage five years ago when financially battered lenders were not in a lending mood?