UK, EU - or both? Scotland's options after Brexit
Scotland may face a choice between two unions following the Brexit vote, having endorsed membership of both the UK and the EU in recent referendums. Having travelled to Brussels, BBC Scotland's political correspondent Glenn Campbell analyses the options open to Scotland.
It was an extraordinary scene.
MEPs from left, right and centre rose to their feet and applauded.
The standing ovation was for the Scottish National Party MEP Alyn Smith.
He had just argued that by voting remain, Scotland had not let the EU down.
And he appealed to his colleagues in the European Parliament: "Do not let Scotland down now".
At that moment it was clear that Mr Smith's boss, Nicola Sturgeon, would receive a sympathetic hearing in Brussels.
Hostility to SNP independence ambitions from some key EU figures like Jose Manuel Barosso was a feature of the 2014 referendum.
But as one high-ranking official in the European Commission put it to me "the emotional response has changed" following the Brexit vote.
Now, a change in mood is not the same as a change in policy and there is no guarantee that one will follow the other.
No one is promising Scotland a special deal with the EU, whether as part of the UK or as an independent country.
The former Belgian prime minister Guy Verhofstadt has suggested Scotland should be allowed to stay in the EU but that would be for member states to decide.
They are well aware of the distinctive approach the Scottish government is taking.
Ireland's prime minister, Enda Kenny, put Nicola Sturgeon's case to all EU leaders, including David Cameron at the European Council summit.
The first minister has been able to speak directly with other important EU figures including the European Parliament president, Martin Schulz and the president of the EU commission, Jean-Claude Juncker.
The European Council president, Donald Tusk - who chaired the summit - decided it would not be appropriate to meet the first minister at this point.
Otherwise, the access she has had is impressive.
As president Juncker put it: "Scotland has earned the right to be heard in Brussels".
Nicola Sturgeon has repeatedly said she wants to look at all options to preserve Scotland's relationship with the EU, including access to the single market.
But it's not clear what these options are. At this stage, there appear to be three broad areas of possibility.
Option 1 - the UK deal
If the new UK prime minister triggers the withdrawal process, a new relationship between the UK (including Scotland) and the EU will also need to be negotiated.
David Cameron has promised the devolved administrations in Scotland, Wales and Northern Ireland will be involved in this process. The UK could potentially seek concessions for Scotland.
We simply don't know what form any new UK-EU deal would take and whether or not it would include access to the single market.
If it does, the German chancellor Angela Merkel is among those who has made clear the UK would need to continue to accept the free movement of people.
That could be difficult for a Brexit supporting prime minister to agree. But not all the candidates were part of the Leave campaign.
Option 2 - a special arrangement
Some have argued that the UK could withdraw from the EU, whilst allowing parts of its territory such as Scotland and Gibraltar to remain.
This is sometimes called the "reverse Greenland" option because Denmark was able to retain its EU status when part of its territory - Greenland - withdrew.
It's not clear how this would work in practice if Scotland also stayed in the UK.
Such an arrangement would raise questions about Scotland's use of Sterling as its currency and its access to the UK's single market and travel area.
Issues that would also need to be addressed with Scottish independence.
Spain's acting prime minister, Mariano Rajoy, seemed to be attempting to close down this option when he said: "if the UK leaves, Scotland leaves".
Spain is worried about accommodating Scotland in any way that might give encouragement to those seeking greater autonomy for Catalonia.
Option 3 - independence
Nicola Sturgeon has made clear that revisiting the question of Scottish independence is another possibility. Indeed, she has said a second referendum is "highly likely".
She wants the option to call the vote during the Brexit negotiations, in the hope that a "Yes" vote would result in continued EU membership, rather than Scotland having to apply from outside.
It's not clear how the EU would deal with such an unprecedented set of circumstances.
As ever, it would be for member states to decide.
They can be very creative, as they were when Germany reunified and the former East Germany automatically became part of the EU.
If a country like Spain was reluctant to agree a special process for Scotland it would have to weigh that against other interests such as access to Scottish fishing waters.
Nicola Sturgeon has said independence may turn out to be the "only way" to secure Scotland's EU relationship but that she is open-minded to alternatives.
She is unlikely to make a decision on indyref2 without knowing more about the UK's proposed relationship with the EU and what other options, if any, are available.
The SNP has previously indicated there would only be a second referendum if public support for independence was clear.
What is apparent is that the proposition would be very different to 2014. Keeping the UK and the EU would not be an option.
With Brexit, Scottish independence becomes a choice between two unions - the UK and the EU.