For much of the past year, Donald Trump had lived something of a charmed political life.

Sure, he scapegoated Mexican immigrants and Muslims (not some, but all). He lobbed crude insults at a female journalist and one with a disability. He attacked his opponents with monikers such as “Lyin’ Ted” and “Little Marco”, mocked Jeb Bush for being “low energy” and compared Ben Carson to a child molester. He even went after previous Republican presidential nominees, including 2008 nominee John McCain, who he said was no war hero because the North Vietnamese captured him. And he demonstrated, repeatedly, that he was immensely unqualified for the job of president of United States.

Yet none of it seemed to matter to Republican voters. Trump’s poll numbers steadily increased, his primary and caucus victories steadily piled up and one Republican opponent after another fell by the wayside, unable to stop him. Even recent polls showed him neck and neck with the Democratic nominee, Hillary Clinton.

But last week, when Trump launched a vicious and nakedly racist attack against Gonzalo Curiel, the judge in his Trump University fraud case, the halo around Trump began to crack – and it offered a useful reminder as to why Trump has practically no chance of winning the presidency. Quite simply, the Republican electorate looks nothing like the rest of the American electorate.

Trump has systematically alienated the demographic groups that he will need to win the White House

Trump’s broadsides against Judge Curiel certainly crossed a line. The presumptive GOP nominee suggested that the judge’s “bad decisions” against him were not the result of Curiel’s interpretation of the law, but rather because, as Trump put it, he’s a “Mexican” (Curiel was born in Indiana). Since Trump has a harsh view of illegal immigration from Mexico, Trump alleged that Curiel’s ethnic heritage made it impossible for him to offer unbiased judgments on Trump’s case. This is, as even Republicans have pointed out, the textbook definition of racism.

Trump also intimated that Curiel should be investigated and that if he wins the White House he might even retaliate against the judge directly. That he is openly attacking the federal judiciary, as he runs for an office with the responsibility of appointing federal judges, represents a fundamental disrespect for the rule of the law and raises legitimate issues as to whether Trump, as president, would enforce court orders with which he disagrees.

Still, it’s hard to see how Trump’s comments about Curiel were any worse than his earlier comments about Mexican criminals or his proposed Muslim ban. They practically pale next to his sinister pledge to investigate Amazon, because its CEO also owns the Washington Post and Trump has been unhappy with some of that paper’s coverage of him. In the American constitutional system, this would be an impeachable offence.

What has changed is that Trump has shifted his attacks from foreign targets to actual American citizens, making it harder for even Republicans to defend them. Moreover, the context in which they were delivered was completely different. During the Republican primaries, GOP voters were not much concerned about Trump’s xenophobic and bigoted attacks. All of his fellow presidential aspirants were calling for Syrian Muslims to be banned from entering the US, regularly railed against illegal immigration and more than a few implicitly called for the US to commit war crimes in its fight against the Islamic State. Trump just went a step further and there’s significant evidence that they helped him among the Republican rank and file.

But today, Trump is not battling for support among Republican voters – he’s trying to win over Democrats and independents. Rather than facing opponents who were largely unbothered by Trump’s bigotry, he’s now in a fight against Hillary Clinton and the Democratic party. They have a very different view on these matters.

This, in a nutshell, is Trump’s problem: to win the Republican nomination he needed to take extreme positions on a host of issues. He needed to demonise illegal immigration. That strategy doesn’t work among non-Republican voters. Indeed, for all the concerns raised by liberals about the possibility that Trump could win, less attention has been paid to the fact that Trump is a uniquely unpopular figure – strongly disliked by Democrats, independents and even many Republicans.

Facebook Twitter Pinterest Recent polls show that Hillary Clinton scores higher than Trump among women voters by more than 20 points.

Photograph: Julio Cortez/AP

The reason has much to do with demographics: Trump has systematically alienated the demographic groups that he will need to win the White House. Four years ago, when Barack Obama beat Mitt Romney in the presidential election, he won by 5 million votes. Starting from that baseline, Trump needs to win back at least 2.5 million votes just to break even in the popular vote. But to do so he would need to improve on Romney’s dismal 27% support among Hispanic voters. That will be hard for Trump, considering that, according to some polls, he’s viewed unfavourably by more than 80% of Hispanics.

This year, an estimated 30% of the US electorate will be non-white. Trump will likely do worse than Romney and win a small fraction of those votes. Then there are his problems with women voters. In 2012, Obama won them by 11 points over Romney. Recent polls show Clinton winning this group by more than 20 points. Of course, while there are no guarantees that these numbers hold up, if just so long as Clinton does as well as Obama did four years ago, she will be very difficult to beat. Right now, she’s outperforming him.

There is also the Democrats’ advantage in the electoral college, the fact that Trump doesn’t have much campaign money and virtually no campaign infrastructure and the fact that many Republicans are trying to distance themselves from him. Indeed, it’s so hard to see how Trump can win that the real issue for 2016 may not be the White House, but rather Congress, which Republicans currently control and, in the case of an electoral bloodbath for the GOP, could potentially lose. If that were to happen, Hillary Clinton would have a Democratic Congress and the opportunity to push through dozens of pieces of progressive legislation.

Ironically, Trump’s rise, rather than signalling a turn toward nativist, authoritarian politics in the US, could, in the electorate’s rejection of him, usher in a more progressive political era.

Michael A Cohen is author of Live From the Campaign Trail: The Greatest Presidential Campaign Speeches of the 20th Century and How They Shaped Modern America