PARKLAND, Fla. -- The teenager accused of using a semi-automatic rifle to kill 17 people at a Florida high school confessed to carrying out one of the nation's deadliest school shootings and concealing extra ammunition in his backpack, according to a sheriff's department report released Thursday.

Nikolas Cruz told investigators that he shot students in the hallways and on the grounds of Marjory Stoneman Douglas High School in Parkland, north of Miami, the report from the Broward County Sheriff's Office said.

Cruz told officers he brought more loaded magazines to the school and kept them hidden in the backpack until he got on campus.

The gunman fired into five classrooms -- four on the first floor of the school and one on the second floor, Broward County Sheriff Scott Israel said.

When he was done shooting, the assailant dropped his AR-15 rifle and the backpack containing the ammunition and ran out of the building, attempting to blend in with fleeing students, Israel said.

After the rampage, the suspect headed to a Wal-Mart and bought a drink at a Subway restaurant before walking to a McDonald's. He was taken into custody about 40 minutes after leaving the McDonald's, the sheriff said.

A day after the attack, a fuller portrait emerged of the shooter, a loner who had worked at a dollar store, joined the school's ROTC program and posted photos of weapons on Instagram. At least one student said classmates joked that Cruz would "be the one to shoot up the school."

Cruz, a 19-year-old orphan whose mother died last year, was charged with murder Thursday in the assault that devastated this sleepy community on the edge of the Everglades. It was the nation's deadliest school attack since a gunman assaulted an elementary school in Newtown, Connecticut, more than five years ago.

Meanwhile, students struggled to describe the violence that ripped through their classrooms just before the school day ended.

Catarina Linden, a 16-year-old sophomore, said she was in an advanced math class Wednesday when the gunfire began.

"He shot the girl next to me," she said, adding that when she finally was able to leave the classroom, the air was foggy with gun smoke. "I stepped on so many shell casings. There were bodies on the ground, and there was blood everywhere."

Among the dead were a football coach who also worked as a security guard, a senior who planned to attend Lynn University and an athletic director who was active in his Roman Catholic church.

Some bodies remained inside the high school Thursday as authorities analyzed the crime scene. Thirteen wounded survivors were still hospitalized, including two in critical condition.

Authorities have not described any specific motive, except to say that Cruz had been kicked out of the high school, which has about 3,000 students and serves an affluent suburb where the median home price is nearly $600,000. Students who knew him described a volatile teenager whose strange behaviour had caused others to end friendships with him.

Cruz was ordered held without bond at a brief court hearing. He wore an orange jumpsuit with his hands cuffed at his waist. His attorney did not contest the order and had her arm around Cruz during the short appearance. Afterward, she called him a "broken human being."

He was being held under a suicide watch, Executive Chief Public Defender Gordon Weekes told reporters.

Wednesday's shooting was the 17th incident of gunfire at an American school this year. Of the 17 incidents, one involved a suicide, two involved active shooters who killed students, two involved people killed in arguments and three involved people who were shot but survived. Nine involved no injuries at all.

As the criminal case began to take shape, President Donald Trump, in an address to the nation, promised to "tackle the difficult issue of mental health," but avoided any mention of guns. Trump, who owns a private club in Palm Beach, about 40 miles from Parkland, said he planned to visit the grieving community.

He did not answer shouted questions about guns as he left the room.

Trump, who did not speak publicly immediately after the shooting, weighed in on Twitter early Thursday, calling the suspect "mentally disturbed" and stressing that it was important to "report such instances to authorities, again and again!"

In the case of Cruz, at least one person did report him.

FBI agent Rob Lasky said the FBI investigated a 2017 YouTube comment that said "I'm going to be a professional school shooter." But the agency could not identify the person who made the comment, which was from an account using the name Nikolas Cruz. It was left on a YouTube video of a vlogger and bail bondsman from Louisiana named Ben Bennight.

In a Buzzfeed article , Bennight said he called the FBI, and agents came out to talk with him. They called him again Wednesday.

Officials were also investigating whether authorities missed other warning signs about Cruz' potentially violent nature.

He had been expelled from the school for "disciplinary reasons," said Broward County Sheriff Scott Israel, who said he did not know the specifics.

One student said Cruz had been abusive to his ex-girlfriend and that his expulsion was over a fight with her new boyfriend.

Math teacher Jim Gard told the Miami Herald that Cruz may have been identified as a potential threat before Wednesday's attack. Gard believes the school had sent out an email warning teachers that Cruz should not be allowed on campus with a backpack.

The leader of a white nationalist militia called the Republic of Florida said Cruz was a member of his group and had participated in exercises in Tallahassee. Jordan Jereb said he had only a brief interaction a few years ago with Cruz. The group wants Florida to become its own white ethno-state.

Neither the Leon County Sheriff's Office in Tallahassee nor the Southern Poverty Law Center could confirm any link between Cruz and the militia.

Cruz's mother, Lynda Cruz, died of pneumonia Nov. 1, and his father died previously, according to the arrest affidavit.

Two federal law enforcement officials said the Smith & Wesson M&P15 .223 was purchased legally last year at Sunrise Tactical Gear in Florida.

------

Lush reported from St. Petersburg, Florida.

------

Associated Press writers Alina Hartounian in Phoenix, Freida Frisaro, Curt Anderson, and Joshua Replogle in Miami, Sadie Gurman in Washington, Mike Balsamo in Los Angeles and Bernard McGhee in Atlanta contributed to this report.