The 2018 midterm election looked last Tuesday like a serious but not crippling setback for Republicans, with Democrats making significant gains in congressional races but failing to deliver a comprehensive defeat to President Donald Trump and his party.

The picture for Republicans has gotten grimmer since then, as a more complete tally of votes has come in across the country.

What looked at first like a modest Democratic majority in the House has grown into a stronger one: The party has gained 32 seats so far and appears on track to gain between 35 and 40 once all the counting is complete.

And Democratic losses in the Senate look less serious than they did a week ago, after Kyrsten Sinema was declared the winner in Arizona on Monday. It now looks like the party is likely to lose a net of one or two seats, rather than three or four as they feared last Tuesday.

The underlying shifts in the electorate suggest Trump may have to walk a precarious path to re-election in 2020, as several Midwestern states he won in 2016 threaten to slip away and once-red states in the Southwest turn a purpler hue. The president’s strategy of sewing racial division and stoking alarm about immigration failed to lift his party, and Democratic messaging about health care undercut the benefit Republicans hoped to gain from a strong economy.

David Winston, a Republican pollster who advises congressional leaders, said his party should not use victories in the Senate to paper over severe losses with women, young people, independent voters and Latino voters, and Democratic gains with suburbanites and seniors.

“We didn’t lose the Senate, but losing by the margins that we did with a lot of these groups is unsustainable,” Winston said.

There are warning signs for Democrats, too: Trump’s party remains ascendant in rural America, giving Republicans a durable advantage in the Senate, where less-populous states have influence greatly disproportionate to their voting numbers. If Democrats cannot cut into Republicans’ strength in areas far from major cities, they may struggle mightily to take back the upper chamber in 2020.

And Republicans demonstrated a tenacious hold on two of the country’s biggest swing states, Ohio and Florida, giving Trump an important foothold on the presidential map.

Midterms are imperfect guideposts for presidential elections: In 2010, Democrats were defeated across Midwestern swing states and Florida and lost control of the House, only to prevail convincingly in the presidential race two years later. But for now, the big picture of the 2018 midterms is of a country in political flux, changing primarily to Trump’s disadvantage.

At the start of the 2018 election, the shortest path to a Democratic House majority appeared to run through Republican-held districts where Hillary Clinton won more votes than Trump in 2016. Democrats did exceedingly well in those districts and may ultimately capture about 20 of them, chiefly in suburban areas of states like California, Texas, New Jersey and Pennsylvania.

But just as important to the Democratic takeover were at least 17 districts where Trump defeated Clinton, and where voters elected a Democratic member of Congress last week. These seats make up about half the Democrats’ House gains, allowing them to achieve not just the 23-seat gain they needed for a bare majority but also to win control by a comfortable margin.

By winning a broader array of districts, beyond just Clinton-voting seats, Democrats proved that they could build a stronger coalition than they did in 2016 and chip away at the margins of Trump’s electoral base.

Still, Democrats made few inroads into solidly conservative districts. The Trump-voting seats they won were predominantly in the suburbs and exurbs, with enough moderate and college-educated voters to offset Republicans’ strength in the districts’ rural precincts. Democrats may also have a tougher time winning some of these districts in a presidential year, when voter turnout is even higher and partisan polarization can make it even harder for politicians to win on the opposing camp’s traditional turf.

Slow-counting western states

The texture of the midterm results has changed most starkly over the last week in the West, as slow-counting states like Arizona and California have tallied their ballots. Democrats have captured Republican-held Senate seats in Nevada and Arizona, partly offsetting their losses in the heavily white, conservative states where Republicans unseated Democratic senators.

And in California, what looked like a night of incremental Democratic gains has turned into a slow-motion rout for the GOP. Republicans are on track to lose between four and seven seats there, chiefly in the suburbs of Southern California, where even Rep. Dana Rohrabacher, a 30-year incumbent, went down in defeat.

Further down the ballot, there were signs of Democratic gains in historically Republican parts of the Southwest: In Arizona, where Republicans have dominated state politics, Democrats also captured the office of education superintendent, and a second important statewide election — for secretary of state — was still too close to call a week into the count. In Nevada, where Democrats had not won a governor’s race since 1994, they captured the governorship and every other statewide office.

In Texas, Democrats gained at least a dozen seats in the Statehouse and, despite partisan gerrymandering, picked up two congressional seats. Five Republican congressional candidates there who were strongly favored to win ultimately prevailed with less than 52 percent of the vote.

Texas and Arizona are unlikely to be blue states anytime soon, but after years of tilting at the Southwest with little to show for it, Democrats saw real signs that the region is becoming a battleground.

Grant Woods, a former Republican state attorney general in Arizona who recently registered as a Democrat, said Trump and the Republican Party had moved too far right for voters in the Southwest. Woods, who is considering a run for Senate in 2020, said the midterm results were encouraging.

“The extremism of the current Republican Party is a losing strategy for the future,” Woods said. “In the Southwest in particular, where we’re talking about a diverse population and, increasingly, a younger population, people just aren’t going to put up with it.”

A divided Midwest

The best news of the night for Trump may have been his party’s triumph in Ohio. Republicans won the governorship there, along with every partisan statewide election, save one: the Senate race, in which Sherrod Brown, a populist Democrat, was elected to a third term. Historically a swing state, Ohio has been trending steadily toward Republicans and appears fairly secure in Trump’s column at the start of the 2020 campaign.

Two other conservative-leaning states in the Midwest, Indiana and Iowa, showed similar allegiance to the GOP, though Democrats picked up a pair of House seats in Iowa.

Jon Husted, a Republican former speaker of the Ohio House who was elected lieutenant governor, said Democrats in the state were not strong enough in the cities to overcome Republicans’ popularity with rural voters.

“What margins they do run up, we’re able to more than make up in the rural counties,” Husted said.

Other Midwestern swing states, however, were a mirror image of Ohio, with Democrats achieving sweeping wins across Pennsylvania, Michigan, Wisconsin and Minnesota. Two years after Trump won upset victories in three of those states and came close to capturing the fourth — Minnesota — Democrats won every partisan statewide office on the ballot in all of them; they even ousted Gov. Scott Walker in Wisconsin and elected Representative Keith Ellison, an activist liberal who faced accusations of domestic abuse, to the office of attorney general in Minnesota.

The division in the Midwest — between more urban, diverse states and more rural, agricultural states — presents challenges for both parties. Democrats will have a narrower path to the presidency nationwide as long as Ohio leans red. But the peril may be greater for Trump, who could have difficulty in 2020 replicating the regional sweep that made him president in the first place.

The impact of gerrymandering

Republican losses in the House were not nearly as steep as they might have been without the help of favorably drawn congressional districts. Even as Democrats gained at least 32 seats and won a clear majority of the popular vote, they failed to capture even a single seat in three big states with aggressively gerrymandered lines: Ohio, Wisconsin and North Carolina.

In two other big, gerrymandered states, Democrats gained seats — but only a few. They took two Republican-held seats each in Texas and Michigan, but came painfully close in more than half a dozen others where partisan maps insulated Republicans from voters’ anger.

Without the maps on their side, it is easy to imagine Republicans having lost more than 50 House seats. And in states with more neutral maps, Democrats fared far better.

Most illustrative may have been Pennsylvania, where in January a state court struck down the congressional district lines and ordered them redrawn. At the start of the last Congress, under a gerrymandered map, Republicans held 13 of Pennsylvania’s 18 House seats. After the redraw and the election, the House delegation will be split evenly — nine seats for each party.

In most states, Republicans are likely to benefit from these maps again in 2020, but that may be the last time the lines are engineered so helpfully. With the inauguration of Democratic governors in states like Wisconsin and Michigan, Republicans will not have a free hand in redistricting after the 2020 census.