WHAT happens if America wakes up the morning after the presidential election and finds the result is still in doubt?

What if the outcome hinges on a razor-thin margin in just one or two states?

This is the ultimate nightmare scenario. It could lead to weeks of uncertainty, with Hillary Clinton and Donald Trump both refusing to concede and ending up in court.

That might sound far fetched, but it's happened before. In 2000, the result of the election was up in the air until December 12, more than a month after the votes were cast. It was only settled by the US Supreme Court, which effectively gave the presidency to George W. Bush in a contentious 5-4 vote.

The court case in 2000 revolved around the crucial swing state of Florida, which Mr Bush had seemingly won by just a few hundred votes. His opponent, Al Gore, demanded a manual recount, and the case eventually made its way to the country's highest court.

If that happens again this time, there will be an extra twist. Due to the death of Justice Antonin Scalia earlier this year, the Supreme Court is currently missing a member, so there are only eight justices - raising the possibility of a tied 4-4 ruling.

That would leave a lower federal or state court ruling in place, with no definitive judgment from the Supreme Court and no real chance of a gracious concession from either candidate.

“It would be Bush v. Gore, with a twist,” said one election law expert, law professor Richard Hasen at the University of California at Irvine.

“I call it the nightmare scenario,” said University of Kentucky law professor Joshua Douglas.

Sixteen years ago, the court was divided along ideological lines. It voted 5-4 on whether to get involved in the case at all, and then voted the same way to stop Florida’s state court-ordered recount and hand Mr Bush the election.

The five conservative justices appointed by Republican presidents sided with the Republican nominee, Mr Bush, while the four more liberal justices appointed by Democrats would have ruled for the Democrat, Mr Gore. With Justice Scalia gone, the court is deadlocked, with four conservative justices and four liberal ones.

The odds of history repeating itself in Florida or elsewhere are long, but it’s hard to discount any possibility, however remote, in a campaign that already has seen Democratic lawsuits alleging voter suppression and Republican claims the election will be rigged.

The reason a tied Supreme Court vote is even possible stems from another aspect of this unusual election year, the Senate Republicans’ refusal to act on President Barack Obama’s nomination of Judge Merrick Garland as Justice Scalia's replacement.

Any decision to seek a recount or otherwise contest the election results would depend on the margin in any one state and its potential for affecting the national outcome. In 2000, neither Mr Bush nor Mr Gore could muster an Electoral College majority of 270 votes without Florida.

“For candidates who lose by a fraction of a percent, even up to 1.5 percent, they will at least explore their options for seeking a recount or challenging the results in a particular state,” said Michael Morley, a law professor at Barry University in Orlando, Florida.

If an initial recount didn't settle things, a lawsuit could follow, with appeals possible all the way to the Supreme Court.

At this point, it’s impossible to know who might go to court and in which state, what the issue might be and who might benefit if justices were evenly divided. A tie is a win for the person who already has prevailed in the lower court.

But for some who already are dismayed about the extended Supreme Court vacancy since Justice Scalia’s death, a tie would have broad implications beyond the election.

“I worry about a 4-4 tie because it would undermine the court’s legitimacy,” Prof Douglas said.

A Supreme Court appeal also would raise another delicate question. Would Justice Ruth Bader Ginsburg participate after the controversial comments she made about Donald Trump in July?

She told AP then that she didn’t want to think about the possibility of Trump being elected, and later called him a “faker” in an interview with CNN. Soon afterward, she said her comments were ill-advised and apologized.

Federal law requires a judge to be recused from any case in which their impartiality “might reasonably be questioned.” But at Supreme Court level, Ginsberg would have to rule herself out. That seems unlikely.

Let's hope the election isn't too close.