Amir, an engineering master’s student standing outside Tehran University, had thought about going into digital marketing, but worried that Iran’s government would restrict Instagram, as it had other apps. He had considered founding a start-up, but foresaw American sanctions and raging inflation blocking his way.

Every time he tried to plan, it seemed useless, said Amir, who at first would not give his real name. He was afraid of his country, he said, and he wanted to leave after graduation.

“I’m a person who’s 24 years old, and I can’t imagine my life when I’m 45,” he said. “I can’t imagine a good future for myself or for my country. Every day, I’m thinking about leaving. And every day, I’m thinking about, if I leave my country, what will happen to my family?”

This is life now for many educated urbanites in Tehran, the capital, who once pushed for loosening social restrictions and opening Iran to the world, and who saw the 2015 nuclear deal with the United States as a reason for hope.

But three years ago, President Donald J. Trump reneged on the agreement and reimposed harsh economic sanctions, leaving these Iranians feeling burned by the Americans and isolated under a newly elected president at home who is antithetical to their values — a hard-liner vowing further defiance of the West.

After years of sanctions, mismanagement and the pandemic, it is easy to put numbers to Iran’s economic struggles. Since 2018, many prices have more than doubled, living standards have skidded and poverty has spread, especially among rural Iranians. All but the wealthiest have been brought low.

But there is no statistic for middle-class Iranians’ uncertainty and increasingly pinched aspirations. Their darkening mood can best be measured in missed milestones — in the rush to leave the country after graduation, in delayed marriages and declining birthrates.

In conversations around Tehran during a recent visit, Iranians wavered between faith and despair, hope and practicality, wondering how to make the best of a situation beyond their control.

In Tehran for the day to run errands — he needed a phone, she had government paperwork — Bardja Ariafar, 19, and Zahra Saberi, 24, sat on a bench in Daneshjoo Park, exercising one of the subtle social freedoms Iranians have carved out under the strict theocracy in recent years. Despite a ban on gender mixing in public, men and women now sit together in the open.

The friends work at Digikala, the Amazon of Iran, sorting goods in a warehouse in Karaj, a suburb now full of ex-Tehran residents seeking cheaper rents. Mr. Ariafar said he was supplementing his income as a computer programmer. Ms. Saberi, like many overqualified young Iranians, had not found a job that would let her use her Persian literature degree.