In all the history of American gerrymandering, it must rate as one of the purest expressions of unapologetic partisanship: “I think electing Republicans is better than electing Democrats. So I drew this map to help foster what I think is better for the country,” said the North Carolina representative David Lewis, then chairman of a committee carrying out a court-ordered revision of the state’s election maps.

Lewis was only saying what his colleagues were thinking. But the quote, from 2016, caught the attention of the supreme court justice Elena Kagan, who featured it prominently in her scathing dissent last month when the high court ruled that partisan gerrymandering – the practice of manipulating the contours of voting districts to rig them for one party – “present[s] political questions beyond the reach of the federal courts”.

“The majority goes tragically wrong,” Kagan wrote. Quoting Lewis about what was “better for the country”, she quipped: “You might think that judgment best left to the American people.”

By sidelining itself in the fight over partisan gerrymandering, however, the supreme court did not end the fight. Instead it has moved to the states, including back to North Carolina, where Lewis and fellow Republican legislators are currently on trial for allegedly, by manipulating the maps, violating citizens’ rights to a free and fair vote.

A ruling against the Republicans in North Carolina, analysts say, could be galvanizing, setting off a wave of gerrymandering challenges in other states. But the stakes in North Carolina are special.

The plaintiffs are asking a three-judge panel to throw out the state’s local legislative maps and have them redrawn before the 2020 election, when multiple statewide races – not to mention the presidential race – are expected to produce huge voter turnout. Whichever party wins a state legislative majority in 2020 will get to draw the next set of state maps, using data from the decennial US census; maps that will be the template for the next 10 years of voting in North Carolina.

Not least, a victory in North Carolina court for the Democrats this summer could help the party invigorate voters in a swing state that could decide whether Donald Trump gets four more years in the White House.

“I think the eyes of the nation are watching to see what happens here,” said Bob Phillips, the state director of the advocacy group Common Cause, a plaintiff in the case. “For other states, it might be, ‘Hey, if it can be done in North Carolina, it might be done in your state’. That’s what we tell advocates around the country.”

The gerrymandering trial proceeded on a recent day in the state capital of Raleigh, in a law school room borrowed by the Wake county superior court for the purpose, two blocks from the capitol grounds, where a trio of monuments to the Confederacy, including a 75ft tall obelisk dedicated “to our Confederate dead”, have been the subject of protest recently, but seem unlikely to come down anytime soon.

To say that the trial proceedings were electric would be accurate – for gerrymandering buffs. For three hours, mathematics professor Wesley Pegden testified about how he had created a program to randomly generate trillions of maps of North Carolina state legislative districts that were slightly different from the enacted maps.

With a projected animation on the courtroom walls of a computer furiously redrawing the enacted map, as if it were trying to defeat itself at tic-tac-toe, Pegden demonstrated that only one out of every 100,000 or so hypothetical maps was better for Republicans than the enacted map.

“It’s almost like I could hear the voice of the Republican mapmaker tell me, ‘No, don’t change those lines, they’re exactly where I want them’,” Pegden said. “The maps are among the most carefully crafted maps for Republican partisan advantage which exist.”

The mapmaker whom Pegden heard whispering in his ear would be Thomas Hofeller, “the Michelangelo of the modern gerrymander” per his August 2018 New York Times obituary, whose dramatically estranged daughter last year discovered secret files among personal effects that happened to include a bunch of time-stamped maps allegedly demonstrating how Hofeller had used partisan data to redraw North Carolina legislative districts in 2017. Those maps were now Exhibit A for the plaintiffs’ side.

The partisan makeup of North Carolina’s statehouse over the years seems to bear out Pegden’s assessment of Hofeller’s craftsmanship. Republicans won 64% of state House seats in 2012 with only 52% of the statewide vote. In 2018, Republicans won 49% of the vote and ended up with 55% of the seats. “The maps are impervious to the will of the voters,” the plaintiffs contend.

Job security for Republican elected officials has seemed to produce some peculiar policies. Ninety percent of the Republican lawmakers who voted for a 2016 state law seeking to control which toilet transgender people could use – the notorious “bathroom bill”, repealed after a national boycott and outcry – had either run uncontested in the previous election or won by double-digit margins.

“Things like the bathroom bill, for example, it is my belief that in a more balanced state legislature, that wouldn’t have been such an issue,” said Amy Oseroff, 64, a schoolteacher and a plaintiff in the case who recently attended the trial.

The defense argues that Pegden’s models are flawed, that the Republican advantage has been exaggerated, and that, in any case, partisan gerrymandering is a game both parties play – and is not illegal and the courts should stay out of it.

The lead defense attorney, Phillip Strach, deferred comment to the defendants. Representative Lewis simply said Democrats had failed to field the kind of “pro-business, reasonable-minded” candidates people wanted to vote for.

Lewis called it “a great honor” to be involved in the supreme court case, but he took issue with Justice Kagan’s singling him out in her dissent, arguing for his free speech rights.

“I would submit that Justice Kagan should have recognized that I have a free speech right to say what I think is right, and what I think is best for the country, just like she does,’ he said. “It was disappointing to me that that was not recognized.”

﻿He also insisted the maps were fair and followed “traditional redistricting criteria”.

Meanwhile, the chief justice, John Roberts, took flak in the recent decision for opining that partisan gerrymandering was literally older than the republic, suggesting that its long history made the practice acceptable. But in the last 10 – or even five – years, supercomputers, increasingly granular voter data and the hardening of voters’ partisan identities have totally changed the gerrymandering game. As Kagan put it, “these are not your grandfather’s – let alone the framers’ – gerrymanders.”

Some democracy advocates see a once-in-a-generation opportunity in North Carolina to push redistricting reform through. If Democrats can summon another anti-Trump “blue wave” in 2020, they might succeed, in spite of the maps, at winning control of the legislature and, with it, control of the redistricting process. That could spur Republicans to pursue reform.

“Unfortunately, the Democrats, some of them will say, ‘We can’t wait to win in 2020, take it back and gerrymander the hell out of them’,” said Phillips. “Now, that’s not what I want, but it’s out there, and it’s playing in the minds of the majority party. If you are the majority party and you don’t do reform, one day you might be on the other side of the stick.”