ON DECEMBER 12th, as Alabamans headed to the polls to choose a new senator, Tawanna Dunagan stood on Graymont Avenue in downtown Birmingham holding up a Doug Jones sign, exhorting passers-by to vote for the Democratic candidate. She had opted for Alabama Democrats in past elections, but 2017, she said, felt different: “People out here are voting like Obama’s on the ballot.”

One month earlier Virginia saw turnout hit a 20-year high in its governor’s election, and there too the Democrat (Ralph Northam) won. In fact, although Democrats won just two of the seven special elections to the House and Senate in 2017, they outperformed expectations in all of them. At year’s end they enjoy an 11-point advantage over Republicans on a generic ballot. In Alabama, Donald Trump now has a net favourability rating of zero, despite winning the state by 28 points in 2016. Data such as these suggest that the midterms of 2018 could be a wave election for Democrats—but thanks to gerrymandering and their voters’ concentration in urban centres, translating enthusiasm into congressional majorities may prove difficult.

Though Alabama’s electorate is smaller, more conservative and less educated than Virginia’s, the two elections offer similar lessons. First, Democrats appear more motivated than Republicans. Turnout surged in liberal northern Virginia, and the big cities and black-majority counties of Alabama. In Alabama turnout fell in majority-white, rural areas; that was not as true in Virginia, but Democrats banked enough votes in urban centres to cancel out the Republican showing in rural areas.

In both states, non-white and young voters broke decisively for Democrats. Mr Jones won 96% of black voters—and 98% of black women, while Mr Northam took 80% of Virginia’s non-white voters. Both candidates won majorities of voters younger than 45, decisively lost voters 65 and older and barely lost voters between the ages of 45 and 65. That should worry Republicans: Americans born since 1980 have taken over from baby-boomers as America’s largest generation, and 43% of millennial adults are non-white. Republicans are appealing to a dying generation at the expense of a growing one.

Republicans should also worry about their slipping hold on the suburbs. Mr Jones decisively won Alabama’s five biggest cities and their surrounding counties, three of which Mr Trump won by 13 points or more. Republicans may take some comfort from the unique toxicity of Mr Jones’s opponent, Roy Moore; their primary voters will not always stump for a preening bigot accused of molesting teenage girls.

But Mr Northam doubled the previous Democratic governor’s margin in the suburbs of Washington, DC. Earlier in 2017 Democrats nearly stole a seat in the deeply Republican Atlanta suburbs. With Steve Bannon, Mr Trump’s former chief strategist and campaign architect, threatening to back challengers to Republicans he deems insufficiently loyal to Mr Trump, the types of Republicans who can win moderate and independent voters may find themselves incapable of surviving primaries.

Statewide victories do not always translate into success in congressional districts. Democrats dilute their vote by living near each other in big cities. Gerrymandering also hurts; Alan Abramowitz, a political scientist, predicts that Democrats need to win 52% of the votes nationally to win a House majority. And Democrats face an unfavourable Senate map: they have to flip two Republican seats and retain all 26 of their own, including ten in states that Mr Trump won, to take the chamber. That is a tall order, even if people keep voting like Mr Obama is on the ballot.