After the surprise gubernatorial victory of Republican Larry Hogan in Maryland, pundits wondered how such an upset could happen in a state long dominated by Democrats.

But how blue is Maryland?

Sure, there are twice as many registered Democrats as Republicans here — but a majority of those Democrats live in the densely populated Washington suburbs and Baltimore. On either side, west toward the Allegheny mountains and east toward the Atlantic, are sprawling rural counties where residents tend to be much more conservative — tourists excepted. The Mason-Dixon line stretches across the state from east to west, close to the northern border.

This is a state where Heather Mizeur, a Democratic gubernatorial hopeful who campaigned on the idea of legalizing marijuana to fund pre-kindergarten for all 3- and 4-year-olds, won more than 21 percent of primary votes. And it’s a state where Michael Anthony Peroutka was elected this week to the Anne Arundel County Council, even as a video circulated showing him singing “Dixie” at a conference of the League of the South, a white supremacist group in which he was involved for years.

If you look at the lawbooks, Maryland appears pretty left-leaning. Under the leadership of Gov. Martin O’Malley (D) over the past eight years, lawmakers abolished the death penalty, legalized gay marriage, imposed some of the most strict gun-control measures in the country and extended a number of rights to undocumented immigrants, allowing some to get driver’s licenses or pay the in-state college tuition rate. Just this year, the General Assembly extended legal protections to transgender individuals, decriminalized possession of small amounts of marijuana and increased the minimum wage.

But many of those pieces of legislation were watered down and passed by thin margins.

Take the minimum wage, for example: O’Malley introduced legislation calling for the state’s base wage to increase to $10.10 by January 2017. This was the governor’s top priority for his last year in office, yet he struggled to get lawmakers — not just Republicans, but also many Democrats — behind the idea.

The legislation that finally passed stretches the time frame to July 2018 and doesn’t allow for automatic additional increases. Tipped workers will not see an increase in their base pay, and employers may pay a lower “training wage” to workers under the age of 20 for their first six months.

The changes angered many activists. They pointed to other liberal strongholds, like Connecticut and the District, where lawmakers were able to do more, sooner for their lowest-paid residents.

“In a state as progressive as Maryland, we frequently don’t see the progressiveness reflected in our elected officials,” Gustavo Torres, president of CASA in Action, which advocates for immigrant communities, said at a rally in early May. “We can face our greatest challenges from those who are supposed to be standing with us.”

Baltimore Sun columnist Dan Rodricks criticized Maryland Democrats in March for acting quickly to make it easier for the state’s wealthiest residents to pay less in estate taxes — and then dragging their feet on the minimum-wage increase.

The headline on his column would have also worked Wednesday morning, after Election Day:

“With Democrats like these, who needs GOP?”