Republicans in Congress withstood for months the political turmoil of Donald Trump at the top of their ticket, confident of holding their majorities in the House and Senate despite his unconventional candidacy.
And for a while it appeared that, with smart campaigns and strong fundraising, their optimism was justified.
But Republicans are increasingly worried now that the race has spun beyond their control. They're issuing pessimistic warnings that Trump has become such a down-ballot drag that the election could flip control of the Senate to Democrats and shrink the GOP's margin in the House.
It's not just Trump's behavior — including allegations of past sexual assault and his refusal to say he would accept the Nov. 8 election outcome — that is making Republican candidates worry.
Democrats have seized the opening, so confident as Hillary Clinton widens her presidential lead that her super PAC has started spending campaign cash in key Senate battlegrounds, with more being considered for the House races.
Republican operatives in congressional races see no easy way to reverse the slide in the time remaining. Nonpartisan analysts agree.
"I used to think there was a narrow path for them to hold on by their fingernails, but I no longer believe that's true," said Jennifer Duffy, who analyzes races for the nonpartisan Cook Political Report. "It's not a pretty picture."
Republicans are prepared for a worst-case scenario, particularly in the Senate, where Democrats need to pick up four seats to flip the chamber if Clinton wins the White House, or five if she doesn't. The math was already in the Democrats' favor because twice as many Republicans as Democrats are up for election this year.
The best hope is that Republicans can stem their losses with candidates who heeded early warnings not to hitch their prospects to Trump's volatile presidential campaign.
Senators like Rob Portman in Ohio and Charles E. Grassley in Iowa have been campaigning like big-city mayors, focusing on local issues and polishing their own brands.
They and others, including Sen. Marco Rubio in Florida and Sen. John McCain in Arizona, have built field operations separate from Trump's apparatus, and appear poised to keep their seats.
But Republican senators who have agonized most over the nominee — toggling between support for and distance from Trump — are among those now seriously in jeopardy.
Sen. Patrick J. Toomey in Pennsylvania declined to take a definitive stance on Trump. New Hampshire Sen. Kelly Ayotte is struggling to shore up her base after abandoning Trump over his lewd comments. Both are being hit with ads bolstering their Democratic challengers — Katie McGinty in Pennsylvania and New Hampshire Gov. Maggie Hassan.
At the same time, Democrats are cutting their losses elsewhere and shifting resources to expand the battleground to Republican terrain. Money is flowing to Missouri, where Republican Sen. Roy Blunt faces an unexpectedly strong challenge from Democratic Secretary of State Jason Kander, and North Carolina, where Republican Sen. Richard Burr is trailing Deborah Ross, a former member of the state General Assembly.
Long-struggling Sens. Mark Kirk (R-Ill.) and Ron Johnson (R-Wis.) seemed poised for defeat.
"Overall, it's a miracle we're even in this thing right now," said one Republican Senate strategist, who like other political operatives interviewed for this story was granted anonymity to frankly assess the situation. "How could it get worse? But it always does."
Republicans say the problems for candidates in Congress go beyond Trump's controversial behavior to the rapidly deteriorating political climate after this wild-ride election year.
Many donors and voters tend to view the presidential campaign as finished now that public polling puts Clinton so far ahead of Trump, they warn, and that is depressing fundraising and may dampen turnout.
Big money flowed to Republicans from donors including the billionaire Koch brothers and casino magnate Sheldon Adelson, who invested more in Congress than the presidential race. But it has not been enough to keep pace in the final stretch.
The Senate Leadership Fund, the main PAC for Republican senators, spent more than $100 million this year with its combined groups, a record as they sought to confront the PAC run by allies of Democratic Sen. Harry Reid of Nevada, the minority leader.
"We are up against a perfect storm of spending from Democratic groups and donors who believe the presidential race is done," said the leader of the organization, Steven Law, a former top aide to Senate Majority Leader Mitch McConnell of Kentucky, in a statement.
House Republicans hope they are on sturdier ground because their 30-seat margin gives them one of the biggest majorities in years. Also few seats are actually competitive thanks to gerrymandering that has left most districts either solidly Republican or solidly Democrat.
But they sounded the alarms in a rushed series of interventions last week.
Rob Simms, executive director of the National Republican Congressional Committee, warned of the "increasingly precarious" situation as leaders urged lawmakers to pony up funds for embattled colleagues.
"We could run the risk of facing substantial losses," Simms wrote in a memo to House Republicans on the day of the final presidential debate. "The national environment is beginning to create uncertainty in several of these races, as legitimate questions are now being asked about whether the unprecedented unfavorability of the presidential candidates will lead to depressed turnout."
House Speaker Paul D. Ryan (R-Wis.), who publicly announced this month he would no longer campaign for Trump, has been stumping across the country to save his majority.
House Majority Leader Kevin McCarthy of Bakersfield convened a pep-talk conference call last week that resulted in a few lawmakers transferring campaign cash to their peers.
Picking up 30 seats to flip the House remains a "tall order," as one Democratic operative put it, but Rep. Nancy Pelosi of San Francisco, the minority leader, expects a diminished GOP, suggesting whichever party wins control will have a single-digit majority.
"We're in good shape," she said.
For many Republicans, the situation now is sadly reminiscent of a lesson they'd learned years ago, after the party put forward firebrand candidates and tea party favorites who did well in GOP primaries but faltered when facing a broader audience in the general election.
Republicans took the Senate majority in 2014, partly by blocking such candidates. They employed the same strategy this year.
Now with Trump, the controversial candidate is at the top of the ticket, once again threatening their majority.
"You don't need this superstar quarterback, but you don't want someone who doesn't know the playbook, who throws the other players under the bus," said one GOP operative. "It doesn't mean we can't prevail. It just means it's that much harder."