Even as it launches waves of terrorist attacks around the globe, the Islamic State is quietly preparing its followers for the eventual collapse of the caliphate it proclaimed with great fanfare two years ago.

In public messages and in recent actions in Syria, the group’s leaders are acknowledging the terrorist organization’s declining fortunes on the battlefield while bracing for the possibility that its remaining strongholds could fall.

At the same time, the group, which is also known as ISIS or ISIL, is vowing to press on with its recent campaign of violence, even if the terrorists themselves are driven underground. U.S. counterterrorism experts believe the masscasualty attacks in Istanbul and Baghdad in the past month were largely a response to military reversals in Iraq and Syria.

Such terrorist acts are likely to continue and even intensify, at least initially, analysts say, as the group evolves from a quasi-state with territorial holdings to a shadowy and diffuse network with branches and cells on at least three continents.

‘ENERGY AND UNPREDICTABILITY’

Indeed, while the loss of a physical sanctuary would constitute a major blow to the Islamic State – severely limiting, for example, its ability to raise money, train recruits or plan complex terrorist operations – the group’s highly decentralized nature ensures that it will remain dangerous for some time to come, according to current and former U.S. officials and terrorism experts.

“Where al-Qaida was hierarchical and somewhat controlled, these guys are not. They have all the energy and unpredictability of a populist movement,” said Michael Hayden, the retired Air Force general who headed the CIA from 2006 to 2009.

Islamic State officials, in public statements and in interviews, insist that the group’s “caliphate” project remains viable while also acknowledging that military setbacks have forced a change in strategy.

“While we see our core structure in Iraq and Syria under attack, we have been able to expand and have shifted some of our command, media and wealth structure to different countries,” a longtime Islamic State operative, speaking through an Internet-based audio service, said in an interview.

“We do have, every day, people reaching out and telling us they want to come to the caliphate,” said the operative, who agreed to speak to a Western journalist on the condition that his name and physical location not be revealed. “But we tell them to stay in their countries and rather wait to do something there.”

But signs of desperation are mounting weekly inside the caliphate, which shrank by another 12 percent in the first six months of 2016, according to according to a report last week by IHS Inc., an analysis and consulting firm.

A series of communiques issued in the Islamic State’s Syrian enclave last month closed down Internet cafes in one province and ordered the destruction of TVs and satellite dishes in another.

The orders, billed as an effort to eliminate a tool for “disseminating infidel beliefs,” effectively cut off access to news from the outside world.

SIGNALS OF A COMING DOWNFALL

More signals of a coming downfall are contained in statements issued by Islamic State officials over the past six weeks, a period that saw the group’s fighters retreating across multiple fronts, from Fallujah in central Iraq to the Syrian-Turkish border.

A remarkable editorial last month in al-Naba, the Islamic State’s weekly Arabic newsletter, offered a gloomy assessment of the caliphate’s prospects, acknowledging the possibility that all its territorial holdings could ultimately be lost.

Just two years ago, jihadist leaders heralded the start of a glorious new epoch in the world’s history with the establishment of their Islamic “caliphate,” which at the time encompassed most of eastern Syria and a vast swath of northern and western Iraq, a combined territory roughly the size of Great Britain.

The editorial, titled, “The Crusaders’ Illusions in the Age of the Caliphate,” sought to rally the group’s followers by insisting that the Islamic State would continue to survive, even if all its cities fell to the advancing “crusaders” – the separate Western- and Russian-backed forces arrayed against them.

“The crusaders and their apostate clients are under the illusion that … they will be able to eliminate all of the Islamic State’s provinces at once, such that it will be completely wiped out and no trace of it will be left,” the article states. In reality, the group’s foes “will not be able to eliminate it by destroying one of its cities or besieging another of them, or by killing a soldier, an emir or an imam,” it says.

The editorial asserts that the “whole world . . . has changed” with the creation of a theocratic enclave that has “shown all of mankind what the true Islamic state is like.”

“If they want to achieve true victory – they will not, God willing – they will have to wait a long time: until an entire generation of Muslims that was witness to the establishment of the Islamic State and the return of the caliphate . . . is wiped out.”

The same themes were repeated in an otherwise upbeat sermon by the Islamic State’s official spokesman, Abu Muhammad al-Adnani, marking the start of Ramadan observances. Adnani’s missive attracted international attention because of its call for a global terrorism campaign during the Muslim holy month. But Adnani also appeared to be preparing his followers for heavy losses.

At one point he evoked one of the darkest chapters in the Islamic State’s history, when the group – then known as the Islamic State of Iraq – was all but destroyed in 2008 by a combination of forces, including the U.S. troop surge and the “Anbar Awakening,” a revolt against the Islamists by Sunni Arab tribes.