RIO DE JANEIRO – In Brazil, the ability to make something out of nothing is so ingrained in the culture that they have an expression for it. "Gambiarra" happens every day in ways large and small, allowing this easygoing society to say: See? We knew all along we could figure it out.

Brazil has never needed that talent more than it did on Friday, when it opened the Rio Olympics in a burst of music and color at Maracana Stadium. The Opening Ceremony had been reworked four times as the country's economic meltdown sliced away at its budget. Amid all of the other worries about the Zika virus, polluted water, security, crime and gridlocked streets, creative director Fernando Meirelles was asked how Rio's show could possibly measure up.

"We have heart,'' he said. "I think that is enough.''

On Friday, a cast of 3,000 pulled off a gambiarra on a global scale — and in the process gave a hint of how Brazil might do the same with the first Olympics held in South America. What the Opening Ceremony lacked in expensive gadgetry, it made up for with the immense spirit and energy that attracted the Summer Games in the first place.

The show featured samba dancers, supermodel Gisele Bundchen, bossa nova classics, giant inflated peace signs and a crowd estimated at 78,000 leaping out of their seats to dance.

It also took a serious turn, making a statement against global warming, while asking athletes to plant seeds for a reforestation project.

As with so many things in Rio, the ceremony carried on long after midnight. The flame lit by marathon runner Vanderlei Cordeiro de Lima, in a modest cauldron backed by a wind-powered sunburst sculpture, was transported to a replica at Pio X Square. Under a shower of fireworks, the second cauldron was ignited to put the heartbeat of the Rio Games in the heart of the city.

The budget restraints did not prevent Rio from staging a high-wattage show, with all of the gaudy excess of its Carnival productions. Carlos Nuzman, president of the Rio 2016 organizing committee, said he was "the proudest man alive'' as Rio shrugged off its troubles and showed off its best self.

"Remember, the children of Brazil do not run from the fight,'' he said, his voice tight with emotion. "Always believe in your dreams. We did not give up ours. We believed, and we did it.''

Meirelles said he hoped the Opening Ceremony would be "a drug for depression in Brazil,'' a celebration of national pride at a time when its many troubles have gained worldwide attention. The economic crises forced the country to steadily reduce its Olympic budget, scaling back on many plans. Without the funds for a typical over-the-top production — Meirelles said his final budget was 1/20th of the $100 million Beijing spent on the 2008 opening — the program showcased Brazil's diversity, soulfulness and innate cool.

Beloved musicians Gilberto Gil and Caetano Veloso performed. Bundchen strutted the length of the stadium floor, portraying one of Brazil's best-known symbols — the Girl from Ipanema — as Daniel Jobim sang the familiar song written by his grandfather, Tom Jobim.

The directors slipped a nod to real-world problems, including deforestation and climate change, into the usual pageant of national history and culture. Meirelles said Brazil's financial problems led them to think about overspending and waste, and how the Olympic ideals mesh with environmental and social concerns. "When 40 percent of the homes in Brazil have no sanitation,'' he said, "you can't really be spending a billion reais for a show.''

Money problems, however, never spoil Brazil's party mood for long. The ceremony gave weary Olympic organizers, athletes and tourists a break from the bad news, as athletes from 205 countries streamed into Rio's landmark stadium.

Brazilians loudly cheered other South American nations and gave a warm welcome to the delegations of independent and refugee athletes, who have received an outpouring of attention and support since arriving in Brazil. The U.S. got a loud reception, too, and a big smile from Secretary of State John Kerry, who stood and took photos with his phone. Swimmer Michael Phelps led a long, long conga line of athletes, wearing a navy blazer with USA in illuminated letters across the back.

Russia's delegation marched in the parade of athletes, though 30 percent of its competitors were disqualified from the Rio Games because of a widespread doping scandal.

Rio — and the Olympics themselves — could not dismiss every problem on Friday. Protesters again faced off with police, who responded with mounted patrols and tear gas. At street corners around the city, trucks full of rifle-toting soldiers stood guard.

With Brazilian President Dilma Rousseff enmeshed in impeachment proceedings, acting President Michel Timer declared the Games open and drew some boos and derisive whistles. And Brazil's best-loved athlete — soccer legend Pele, who was expected to light the cauldron — could not attend because of poor health.

But nothing could suppress the joy in Maracana when the Brazilian delegation — 465 athletes strong — marched into the stadium at the end of the parade, dancing and shooting video of the delirious crowd. "This is the moment of the Cidade Maravilhosa,'' International Olympic Committee President Thomas Bach said. "We have always believed in you.''

With the first big celebration over, Brazil's task now is to keep the gambiarra going for another 16 days, making as much as it can of its moment on the world stage. The mood set on Friday made it seem that anything was possible.

"We love it,'' said U.S. basketball player Carmelo Anthony. "Brazil knows how to party.''

Rachel Blount • 612-673-4389