Kansas is a state entirely controlled by Republicans now and one that voted for President Trump in 2016 by 20 points. And yet in a couple of weeks, voters there could elect a Democrat to be their governor for the first time in eight years — just in time to have a hand in the upcoming redistricting battle that could shape control of the state for the next decade.

That there is such a tight race is more a reflection of Republican control of the state for the past eight years than any major shift in conservative Kansas to the left.

Kansas has been struggling for years with massive budget shortfalls. Those have cut deep into budgets for roads, schools and hospitals in a way that’s hard for the average Kansan to miss.

Most attribute that to former governor Sam Brownback’s experiment to cut taxes to spur economic growth. The promised growth didn’t happen, and last year the Republican legislature overrode a Brownback veto to pass a tax increase, the largest in state history, and end his “real live experiment” in conservative governing.

Brownback left office shortly after that to work in President Trump’s administration, leaving behind a fiscal crisis and approval ratings in the teens to 20s. Since then, Republicans have arguably done everything wrong to try to get over the Brownback drama and keep control of the governor’s mansion.

With the help of President Trump, Republican voters nominated a controversial, not-particularly-well-liked candidate, Kansas Secretary of State Kris Kobach, over the sitting governor.

Days before the primary, Trump jumped in and endorsed Kobach over Gov. Jeff Colyer, despite the fact that some Republicans didn’t see evidence that Kobach could win either the primary or the general election.

Kobach won that primary by a few hundred votes, and Republicans watching the race from Washington weren’t happy.

"If Kobach is the nominee, Republicans face an uphill battle,” said one Republican insider at the time.

Republicans' fears have so far become reality. Polls show Democrat Laura Kelly and Kobach running about even, with a third-party candidate, Greg Orman, taking about 9 percent of the vote (mostly from the Democrat, theorize election watchers).

Kobach has struggled to get out from under the Brownback legacy, but he also brings new baggage. Kobach is perhaps best known nationally and in Kansas as the voter-fraud guy. Voter ID laws are popular in Republican states, but Kobach took that to a new level in the past two years.

He helped lead Trump’s voter-fraud commission, which crashed and burned less than a year into its existence without finding evidence of Trump’s conspiratorial claim that millions of people voted illegally in the presidential election. During the primary, a federal judge ordered Kobach to pay more than $26,000, citing his “contemptuous behavior” in a voting rights case in Kansas.

All that drama left many Republican voters with a distaste for Kobach, marking him as someone willing to spin a factually dubious project to become a national figure.

“That’s not incredibly popular in Kansas,” said Bob Beatty, a political scientist and election watcher at Washburn University. “Especially among those moderate Republicans. They want good government. They don’t want crusades.”

Democrats in Kansas agree that the race is basically about everything they’re not. That’s evidenced on the campaign trail, where Kelly — a decidedly less flashy character than Kobach — talks about how, as a legislator in the state Senate, she helped push the tax increase package that was a rebuke to Brownback. Her catchiest line is calling Kobach “Sam Brownback on steroids.”

Her campaign has gotten some serious momentum in the final weeks after being endorsed by every living former Republican governor of Kansas, save Brownback.

Kobach is doubling down on Trump, trying to drum up his and the president’s shared base. One analyst watching the race said Trump’s approval is about 50 percent, which isn’t nearly as high as other conservative states — but at least the president is more popular than Kobach now, who polls in the 30 and 40 percent favorability rating.

The consensus in Kansas is that if there weren’t a third-party candidate in the race, Kelly would have a much better shot at winning. Orman shows no sign that he will drop out, despite public and private calls for him to do so. That means, Beatty said, that Kelly will probably need to win over moderate Republicans who voted for Trump but don’t like Kobach, and that she’ll probably have to turn out Democratic support in the one congressional district that voted for Hillary Clinton in 2016.

Her path to victory isn’t impossible, though. Democrats have won statewide in Kansas before, most recently when Kathleen Sebelius won the governor’s race in 2002 and 2006. And in 2014, Democrat Paul Davis came close to unseating Brownback.

“A lot of people think of Kansas as this very red state, but it’s just not as red as many people think,” said Dave Trabert, president of the conservative-leaning Kansas Policy Institute, who acknowledges that public perception of the Brownback tax cuts could cost Kobach the race.

But Kobach has been very lucky this election cycle, with a Trump endorsement timed at just the right minute to help him win the primary. If his luck holds, he could eke out another win, even if a majority of Kansans vote for Kelly or Orman.

“So he could be governor with over half of Kansas not wanting him to be,” Beatty said.

That would save Republicans embarrassment in this conservative state and eliminate Democrats' chances to try to shape its electoral districts for the near future.