(CNN) ISIS is on the back foot.
Nearly three years since the group's elusive leader Abu Bakr al-Baghdadi declared a self-styled Islamic State in Iraq and Syria, ISIS is reeling from losses across its so-called "caliphate."
It is fast losing its grip on Mosul, its biggest hub in Iraq, and its de-facto capital in Syria -- Raqqa -- is all but surrounded.
But it's not just territory that the militant group is losing.
Over the last six months, ISIS has seen its finances slashed, media operations crippled and several high-ranking leaders killed or captured.
The Syrian Democratic Forces -- an alliance of Kurds and Arab tribes -- are approaching the outskirts of Raqqa, and the battle will begin within "days," the French defense minister said Friday.
While the fight against ISIS is far from won, the lines of this war are slowly being redrawn. As the group is driven from key cities and villages in what was once its self-proclaimed caliphate, ISIS is evolving from territorial to ideological threat.
So what could ISIS 2.0 look like?
Before he was killed in a drone strike last year, ISIS spokesman Abu Mohammed al-Adnani said that potential setbacks in Mosul and Raqqa would not spell the group's end: "No: defeat is losing the will and the desire to fight."
For some ISIS fighters, there will be no escape from the battles of Mosul and Raqqa. Nor do they want one. Urged on by the messages of al-Adnani and al-Baghdadi, they will embrace martyrdom in the alleyways of Mosul and the wide expanses of the Jazeera desert. Most of those who fight to the death are likely to be foreign fighters, if past experience is any guide. Moroccans, Tunisians and Chechens will be among them.
Since its inception, ISIS has prepared for the 'day after' the caliphate. Its battle cry has long been "Baqiya wa tatamaddad," or "remain and expand." While its expansion may take generations, the group's leadership is ready for a stateless Islamic State. Top commanders and hardcore fighters will likely remain in Iraq and Syria, forming an underground resistance.
ISIS has cultivated deep roots in Sunni parts of Iraq (less so in Syria where many jihadists regard it as an interloper). Over the past decade, the group has developed networks skilled at raising money, obtaining weapons and clandestine organization across a wide swathe of Iraq -- from Diyala in the east to Rutbah close to the Jordanian border.
Even as it is under pressure in Mosul, ISIS remains active in many of these places, and is capable of carrying out suicide bombings in Baghdad, Tikrit and elsewhere. It has shown resilience in Syria, looking to establish footholds far from its Raqqa headquarters. In some ways, it is returning to what it does best -- agile attacks, mobility and surprise.
As ISIS' fortunes decline, some militants may try to switch allegiance to other groups. In Syria, these include the former al Qaeda affiliate Jabhat Fateh al Sham. But there's a long history of bad blood between the two groups, which had a bitter and public falling out three years ago. Few in the ISIS hierarchy would contemplate such a move.
In Iraq, there are precious few alternatives for ISIS militants because the group has systematically attacked rivals in the region.
Even so, ISIS' decline is an opportunity for al Qaeda in Iraq, Syria and beyond. Terrorism expert Bruce Hoffman suggests some militants will see al Qaeda as the only option for continuing their struggle. ISIS traces its origins to an al Qaeda franchise in Iraq (AQI).
At least 75% of ISIS fighters have been killed since the US-led coalition launched airstrikes in Iraq and Syria, according to US officials. By last December, they estimate ISIS' ranks had winnowed to between 12,000 and 15,000.
It is extraordinarily difficult to estimate how many foreign fighters remain in the region. But far fewer foreign fighters have been able to reach the 'promised land' in the last year than previously.
The most worrying possibility for the West is that these foreign fighters, finding survival in Iraq and Syria difficult post-caliphate, might return home to carry out lone-wolf style attacks -- as well as recruit new members and revive underground networks.
They will try to use migrant routes and often will travel alone. The travel patterns of those involved in the Paris and Brussels attacks uncovered deep flaws in the tracking of such individuals among European security services. While it's now much harder for foreign fighters to travel through Turkey, as migrant flows have slowed, an unknown number have slipped through the cracks.
It only takes a handful of individuals to cross the Mediterranean, or travel through the Balkans undetected, for a European city to be vulnerable to another devastating assault.
As and when Raqqa falls, the logistical and financial help for such operatives will have to find another home. (Recent attacks in Brussels and Istanbul both appear to have been co-ordinated from Raqqa).
Even so, in the age of encryption, sympathizers are able to find ways to communicate securely with ISIS leadership. The Uzbek national who carried out the New Year's Eve attack on a nightclub in Istanbul had never been to Syria, but communicated with commanders through the encrypted chat app Telegram, according to testimony he provided Turkish prosecutors.
Turkey, given its proximity to Syria and Iraq and its use as a logistical rear-base by ISIS, may be especially vulnerable.
"Turkish government complacency has allowed the threat to grow, as have purges of experienced counterterrorism professionals, including those after last year's failed coup," according to Ahmet Yayla, a former counterterrorism chief in Turkey.
Rather than risk going home, some ISIS members may try to reach new jihadist pastures.
There's evidence indicating that hundreds have already reached other ISIS-controlled provinces, or wilayats, especially in Libya, which (until last year) appeared to be the leadership's Plan B.
Across the world, from Russia's North Caucasus to Nigeria, militant groups have pinned their flags to the ISIS banner over the last three years. Some comprise a few dozen men hiding in mountains and jungles; others have been sophisticated and well funded, with close links to ISIS' head office. Still others are hardened insurgent groups capable of inflicting heavy casualties on armies.
One such group is the Islamic State in Northern Sinai (ISNS), which has inflicted hundreds of casualties on Egyptian security forces since affiliating itself with ISIS in 2014.
It recently told Christians to leave the Sinai and boasted setting up checkpoints in the middle of a coastal town, al-Arish. It also claimed responsibility for the bombing of the Russian airliner that exploded in mid-air, crashing in the Sinai Peninsula in November 2015.
ISNS is unlikely to be able to seize and hold territory in Sinai, but does not seem close to defeat -- despite a determined offensive by the Egyptian military.
Some ISIS fighters now in Syria and Iraq may try to join ISNS and other active affiliates, much as al Qaeda fighters moved to Iraq and Yemen after 9/11. They will try to use migrant routes and often will travel alone. But they will take with them skills learned in years of combat.
Perhaps the least predictable among those who make up ISIS 2.0 are the virtual adherents, those radicalized online and nursing a range of grievances who turn to random acts of violence.
Two deadly attacks in the US -- on an Orlando nightclub and in San Bernardino -- fell into this category. As did the truck attack in Nice last year, and smaller ISIS-inspired attacks across Europe.
They were carried out by individuals with little understanding of ISIS' ideology, deep personal grudges and no direct contact with the group's hierarchy. But that didn't prevent ISIS from declaring the perpetrators "soldiers of the Caliphate."
These individuals, radicalized by what they read and hear, pose a continuing danger, especially in societies where high-powered weapons are easy to come by.
These lone wolves pose a sporadic but serious challenge to the US and Europe. By definition, they have few if any co-conspirators. They take inspiration from social media sermons and lectures like those of Anwar al-Awlaki, who even since his death has inspired well over a dozen plots in the West.
US President Donald Trump has promised to "bomb the s***" out of ISIS. This might be feasible amid the crumbling holdouts of the caliphate, but as the remnants of ISIS go underground or escape, the apocalyptic mindset they have come to represent will live on. It -- or something very similar -- will find a host among Sunni in the Middle East who feel persecuted, and among a few young and alienated Muslims in western societies who seek purpose and revenge against wrongs perceived and real.
"The Islamic State is on the back foot militarily, it's losing territory," Charlie Winter, senior fellow at the International Centre for the Study of Radicalisation and Political Violence at King's College London, who has studied ISIS propaganda for years, told CNN. "Even if ISIS loses Mosul and Raqqa, the ideology will live on."