Nicola Sturgeon's call for a second Scottish independence vote in the wake of the British referendum has generated another constitutional and political headache for the European Union.
Following a meeting of the Scottish cabinet on Saturday, the first minister announced the cabinet would begin “immediate discussions” with the EU institutions and other member states to explore options to protect Scotland’s place in the EU.
Speaking in the House of Commons on Monday, Angus Robertson, the leader of the SNP in Westminster, said his party had "no intention whatsoever of seeing Scotland taken out of Europe".
Sturgeon has said she will convene a meeting of all EU diplomats based in Scotland over the next two weeks in Edinburgh.
The question of whether Scotland can remain a member of the EU should it secede from the UK is highly political and legally complex. The issue came to the fore two years ago during the Scottish independence referendum campaign.
Then, Brussels did its best to evade a definitive answer, though then-European Commission president José Manuel Barroso risked the ire of the Scottish independence movement by telling the BBC it would be "extremely difficult, if not impossible" for Scotland to join the EU.
Agreement of all states
An independent Scotland would have to reapply and secure the agreement of all other member states, he said.
The current regime has so far declined to comment on the implications of the British referendum for calls for continued Scottish membership of the EU. Senior EU officials have confirmed the issue has not been discussed at official level in Brussels since Thursday’s shock decision.
The exact legal position is unclear.
The key issue is whether Scotland would have to apply for EU membership like any other would-be member, as set out in Article 49 of the EU treaty, or could its terms of membership be worked out via Article 48, which allows member states to make amendments - an argument advanced by the Scottish nationalists in 2014.
They argued that Scotland should be "fast-tracked", as it is unfair to compare Scotland, which has been an EU member since 1973 via the UK, to other accession countries like Serbia, Turkey or Montenegro.
But while the EU treaties do not provide for the specific scenario presented by the Scottish question, politically there are huge obstacles to allowing Scotland to “inherit” the United Kingdom’s membership.
Spain, which is fiercely resisting a resurgent Catalan independence movement, would likely oppose the move, though the fact that the call for Scottish EU membership would be triggered this time by the withdrawal by the UK from the EU rather than an independence referendum, would make the issue less politically explosive.
Another potential pitfall is currency. Under EU law, any country that joins the EU must agree to sign up to the single currency (though in reality a number of member states which joined post-euro have yet to adopt the currency).
As it is unclear which currency Scotland would use if it left the United Kingdom – a hugely contentious subject during the Scottish referendum campaign – and given the general distrust towards the euro throughout the UK, the issue could cause headaches in Edinburgh.
Similar legal uncertainties surround the suggestion by Sturgeon over the weekend that the Scottish parliament could block Britain’s exit from the EU, after she said she may consider asking MSPs to withhold their “legislative consent” to the measure.
Some legal experts have said that while the Scottish parliament technically could withdraw consent for the measure, this is not the same as blocking it, as Westminster would have overarching sovereignty.
Again, however, the question could at least be technically tested, though this would have to be completed before the invocation of Article 50, the formal process which governs the exit of a member state from the EU.
With Scotland’s relationship with Britain thrown into turmoil by the decision to leave the EU, solving the Scottish conundrum will be just one of many challenges facing negotiators as they manage Britain’s exit over the coming months and years.