KABUL, Afghanistan — More than 18 years after the U.S. invasion toppled Taliban rule in Afghanistan, Washington on Saturday signed a peace agreement with the insurgents to end the costly war and bring American troops home. However, it's far from clear what kind of Afghanistan the U.S. occupation will leave behind.

Washington's deal with the Taliban opens the way for the first negotiations between the militants and the troubled Afghan government, which is dependent on U.S. and other foreign backing. The devil will be in the details as former Taliban fighters and Afghan warlords are likely to jockey for power. Afghans — especially women's rights activists — worry about losing incremental freedoms they've gained since the Taliban were overthrown.

Here's how the agreement was reached, what it says, and what the critical steps are going forward:

MISSED OPPORTUNITIES

Former Afghan President Hamid Karzai says the conflict could have been stopped years ago. In 2010, a top Taliban official, Mullah Abdul Ghani Baradar, let then-President Karzai know he was ready to talk peace. But Washington refused to negotiate with the militants, Karzai later told The Associated Press. Instead, the CIA and Pakistan's counterterrorism forces arrested Baradar in a joint raid.

Baradar was released from a Pakistani jail in 2018 and is now the chief Taliban negotiator. He hammered out the current deal with U.S. peace envoy Zalmay Khalilzad.

The U.S. began covert talks with the Taliban in 2013, first through intermediaries. In September 2018, President Donald Trump appointed Khalilzad to directly negotiate with the Taliban, who had established a political office in the Mideast, in Qatar. But fighting still raged on the ground, even as the two sides got closer to an agreement. In January, the Taliban proposed a temporary cease-fire, which eventually led to Saturday's signing.

___

THE U.S. AND THE TALIBAN, FRIENDS AGAIN?

The agreement calls for a withdrawal of U.S. and NATO troops from Afghanistan but it's unclear if a smaller U.S. counter-terrorism force would be left behind to tackle the local Islamic State affiliate.

IS is a mutual enemy of both the U.S. and the Taliban, and Washington wants the Taliban to help in that fight. It's not without precedent. In the 1980s, the CIA funded Afghan mujahedeen, or Islamic holy warriors, in an insurgency against the Soviet Union. Some of those mujaheddin went on to form the Taliban.

Under the deal, the Taliban have to ensure that areas they control — about half the country at this stage — aren't not used by militant groups to target the U.S. and its allies. But militant watchers are skeptical the Taliban can break their deep ties with groups such as al-Qaida.

The peace deal also calls for negotiations between Afghans on both sides of the conflict over their country's future, and a permanent cease-fire. However, the Taliban so far refused to negotiate directly with the Kabul government, denouncing it as a U.S. puppet, but participated in several rounds of talks with prominent Afghans, including Karzai. The agreement envisions government representatives at the negotiation table, but only as ordinary Afghans.

___

DEFINING AN ISLAMIC AFGHANISTAN

Intra-Afghan talks that are to follow the peace deal are likely to be tougher and far more complicated than U.S.-Taliban negotiations. All sides agree the country should be governed according to "Islamic principles" but almost everything else — including its name, the Republic or Emirate of Afghanistan — will be up for debate.

A big question is how would Afghan women hold on to the rights they have won since the Taliban were toppled, once the militants join the political mainstream. The Taliban say they'd accept a woman's right to education and women working outside the home. But the Taliban, as well as many in the Kabul administration, want women's rights to abide what they call Islamic principles, the definition of which hasn't been spelled out.

Amending or rewriting the constitution is a possibility but that would open up other issues too, such as free speech. Afghanistan's different ethnic and religious groups have often vied for dominance. Minority Shiites will likely want assurances that constitutional protection for all sects remains in place.

___

THE DAY AFTER PEACE

Even if both sides agree on all these issues, Afghanistan might not be ready for the day after peace. Thousands of Taliban fighters, as well as heavily armed militiamen loyal to different Afghan warlords who have become powerful in 18 years of alliance with the West, may not want to put down their guns and abide by the deal.

After the Taliban fell in 2001, powerful warlords and corrupt officials seeking revenge drove thousands of Taliban to flee to the mountains and take up arms once again.

Afghans also fear an outbreak of fighting among rival warlords could plunge the country into new chaos like in the early 1990s, when warring groups killed tens of thousands of mostly civilians, leading to the arrival of the Taliban.