I’VE just had this horrible nightmare. I dreamt Theresa May called a snap election and the UK was now governed by Northern Ireland’s extremist Democratic Unionist Party (DUP). Plus, the SNP suffered a spectacular electoral defeat at the hands of a revived, reactionary Tory Party.

Oops. It wasn’t a dream after all. So what went wrong? Much as I recommend we all keep our heads and regroup for the next election – it’s coming sooner rather than later – I think we delude ourselves in the national movement if we don’t view GE2017 as a setback. True, the SNP are still the government in Scotland, still won more councils in May than last time, and still retain the vast majority of Scotland’s Westminster seats. But like war, politics manoeuvre and we’ve been out-manoeuvred.

That said, the over-riding conclusion to be drawn from the General Election is that the United Kingdom (sic) is in an even deeper structural crisis than before June 8. And Britain’s difficulty is Scotland’s opportunity. The Conservatives have served as the main British ruling-class representative since the rise of parliamentary democracy in the early 19th century.

The Tories have always been ideologically flexible enough to include most shades of right-wing and property interests inside their ranks – industry, landed aristocracy, the City of London – while simultaneously deluding swathes of working people to vote for them using the blandishment of British nationalism.

However, last Thursday marked the beginnings of the death agony of Toryism and with it the British state it protects. Outside the short two years of the Cameron government, the Conservatives last achieved a solid Westminster majority in 1992 – a whole quarter of a century ago. They remain fatally divided over Brexit yet face powerful populist forces to their right – think Nigel Farage and the billionaire Aaron Banks – willing to exploit Tory differences by mobilising the English working class on English nationalist lines.

Although Theresa May was seemingly 20 points ahead of Labour in the polls in April, launching an election campaign simply opened up all the contradictions inherent in the Tory Party. Result: after a decade of austerity, a revolt by the country’s youth gave Corbyn’s populist Labour an extra 10 per cent poll share, the biggest swing since Clement Attlee in 1945. In fact, polls this weekend have Labour ahead and likely to win any new election. Expect this Labour lead to be maintained as inflation bites into real incomes.

Meanwhile, the very act of the Tories embracing the DUP as a de facto coalition partner has propelled national and constitutional questions back into the very heart of British politics.

So much for all that Scottish Tory guff about “getting on with the day job” of governing. Now let’s watch what happens over “who gets what” powers after Brexit – or indeed, what the Brexit deal should be. The scene is set for parliamentary chaos.

Which brings us neatly to Scotland. Despite last week’s setback, the increasing instability of the British state is our opportunity to seize Scottish independence. However, as the negative results of the election show, a crisis can take you backwards as well as forwards.

Between the 2015 and 2017 Westminster elections, the SNP mislaid half a million votes, 200,000 of which were down to people simply failing to turn up at the polls. You can’t explain the latter by tactical voting between the big Unionist parties. Nor can you say it is simple voter fatigue – look at the Corbyn success in England.

Many of our lost SNP voters – particularly working-class ones – were pro-Brexit. It could just be that the national movement is split on attitudes to the EU and we’ll have to lump it. However, as I said repeatedly during the campaign, the SNP leadership did little to address the concerns of our pro-indy, pro-Brexit supporters. To square this circle, the party may have to shift towards a Norwegian solution: Scotland outside the EU but inside the single market (which also solves the riddle of keeping post-Brexit England as our largest trading partner).

Also, we lost votes to Labour, partly as a result of the Corbyn effect and partly because Scottish Labour cynically triangulated the SNP government by accusing it of imposing Tory austerity.

Of course, anyone who thinks the dull and truculent Scottish Labour apparatus really has moved to our left is suffering delusions. Even in the middle of the General Election, Kezia Dugdale happily snubbed Corbyn’s rally in Glasgow.

However, we made life easier for Scottish Labour by failing to respond to the rise of Corbyn’s amazing anti-austerity movement in England. A decade in government has made the SNP a mite cautious. That is not a dramatic criticism. As an economist, I still marvel at the deftness of John Swinney, when Finance Secretary, in keeping the Scottish economy afloat during the global crisis.

Yet no-one could say the SNP government has been over radical.

True, we needed to balance competing interests to build the Yes coalition. But what happened to genuine devolution to local government? What is the point of legislating for the right of communities to buy land if you erect a legal apparatus that rejects their applications? (And then sticks them with a hefty legal bill, as happened to the good folk of Cockenzie, in East Lothian). And where is our long-promised National Investment Bank?

With the rise of Corbyn, the SNP government needed to move to the left. Given the actual rise of a Frankenstein Tory right in Scotland, we were hardly risking anything. Besides, this morning we might have been celebrating a Corbyn government backed by the votes of nearly 59 SNP MPs.

Finally – as I know to my cost as a candidate – the SNP “message” during this election was all over the shop. We started in the aftermath of the EU vote by focusing on indyref2. Remember the “national conversation” on Europe and independence launched in late 2016? It felt like a stunt. Internally, a new “Growth Commission” was set up to prepare the way for a separate Scottish currency after independence – it has yet to report. By the spring, after May set her face against a second independence referendum, the SNP seemed to relegate indyref2 to a long-term Scottish response to any hard Brexit deal. That was sensible enough. But after a snap General Election was called, the party’s message shifted yet again – to the tepid “stronger for Scotland” at Westminster theme.

Meanwhile, Labour and (especially) the Ruth Davidson Party continued to agitate against a referendum as the basis of their own vacuous campaigns.

For the record, I was happy to fight on the SNP record at Westminster – it was exemplary and won’t be emulated by our anonymous replacements. But then again, this was hardly the stuff of an election being fought on the doorsteps over Tory austerity. We needed to outgun Corbyn and we didn’t. Our move to lift the cap on public sector wages came too late and looked opportunistic.

Where next? Heads up, folks: Theresa May is political toast.

The Tories have no way of getting a Brexit deal through Westminster unless Jeremy Corbyn is run over by a bus. Which means there will be another General Election soon. Let’s get it right this time.