“The Edge of Seventeen,” a fresh and funny look at the emotional perils of being a high schooler, may be a “Pretty in Pink” for a new smartphone-addicted group of teenagers.

It also marks the directing debut of a major new talent in Kelly Fremon Craig, who also wrote the story about an awkward adolescent (Hailee Steinfeld), whose life gets shaken up after her best friend starts dating her older brother. Craig polished her script and slid behind the camera under the mentorship of James L. Brooks, the legendary co-creator of “The Simpsons” and “The Mary Tyler Moore Show,” as well as the director of such film hits as “Broadcast News” and “Terms of Endearment.”

“The Edge of Seventeen” will close out the Toronto Intl. Film Festival before opening in November via STX Entertainment. Brooks and Craig talked to Variety about their writing processes, why the film needed to be R-rated, and Donald Trump.

Why did you decide to collaborate?

James L. Brooks: The script was in there, but it was actually the first meeting we had, just talking about it. I don’t know what was said or anything, except for this: As she was leaving, she turned around and said, “Nobody will ever work as hard as I will.” It seemed such a moment of somebody telling you a core truth about them that it was beguiling. Have I ever used that word? What was the last time I used that word? I want to look up beguiling now.

Kelly Fremon Craig: Jim was the person I had admired forever.

What was the writing process like?

Brooks: We’d meet. We’d talk. We’d bullshit. Then a second draft arrived that was an important writer’s voice.

How did you make sure you were representing teenagers accurately?

Craig: I did six months of interviewing high school kids. Anybody who knew a teenager, I was like, please can I talk to your teenager? And those interviews would turn into little therapy sessions. I hung out at high schools. Went to a high school dance. I tried to be a fly on the wall.

How has technology changed high school life?

Craig: Quite a bit, obviously. But the core things that everybody’s worried about are just the same. High school was always a fishbowl. Everyone knew everything about everybody and you always felt like you were looked at, and now, you’ve got everybody on social media where you’re really being watched all the time and that’s so weird. In a way, it’s making everybody this age a little lonelier because we’re all  putting these edited versions of ourselves and how we want to be seen out there, when the truth is everybody is a lot of different things. Everybody’s messed up, but all we see is beautiful filtered pictures of people having more fun than us. That’s particularly tough and isolating at this age, when you don’t realize that’s not the truth.

Were John Hughes’ films an inspiration?

Craig: Only in that certain movies like “The Breakfast Club,” and other movies, like “Swingers” or “Say Anything,” allowed me to see my life reflected in them.

Did you get any pushback on the R-rating?

Brooks: It could never be anything else. Once you read the script, it’s the only way it can be.

Studios don’t make a lot of smaller, character-driven dramas anymore. Was it hard to get this made?

Brooks: Yeah, it was. But I never questioned we’d get it made. I always believe you can’t kill good movies, because somebody’s in some room and will die unless it gets made.

Are you concerned that studios aren’t backing these types of movies?

Brooks: Except that this year might be a great year. Here in Toronto, there are all these people telling me titles of movies that I have to see.  This could be an uplifting, optimistic, the good guys win year.

There’s been a lot of talk about gender diversity, and this is a film that was written and directed by a woman. Are things getting more equitable?

Brooks: This was a wonderful writer, and I just wanted to support that script.

Craig: It feels like it’s getting better. It feels like more opportunities are coming and maybe because it’s become a conversation, that’s part of why they’re happening.

What is your writing process?

Craig: I am definitely one of those people that as soon as I put my hands on the keys something clicks in. Some ideas strike you in the shower, but mostly it’s just showing up to the laptop, not knowing how I’m going to get where.

Brooks: I have a terrible process. Me and avoidance hang out.

Michelle Obama recently said that “The Mary Tyler Moore Show” was one of her favorite programs. What’s your reaction to that?

Brooks: I did not see that. Yippee! We tried to get her on “The Simpsons” and we couldn’t. We finally got a note that said “good try,” because we were so aggressive.

Why do you think “The Mary Tyler Moore Show” still resonates?

Brooks: I don’t know that it still does. So much of it is roulette. For that show great people walked through that door and kept on coming as we added characters.

We were very lucky because the time we came on everything was happening around us. The whole female revolution thing was happening. It was great for stories, it seeped in. Our timing and what was happening to the culture was great.

“The Simpsons” will have had 625 episodes by the time it ends its current renewal contract. Have you watched and been involved with every episode?

Brooks: Yeah, I’ve been in the story conversations. There might have been a time when I was shooting a movie, I’d be out of the loop for awhile.

Why has that show endured?

Brooks: Being animated helps. The thing is so much bigger than any one of us that we all serve it. You walk on there, you think we were killing ourselves for a pilot. Nobody’s lazy and we can have a crazy new thing and do it. We can go into a new form. We sit around and have an idea for a theatrical short and we do it, and it’s silent and there’s no dialogue. It’s crazy how much we get to keep being innocent because we’re doing something that we’ve never done before.

“Broadcast News” turns 30 next year. Do you feel like the issues you were dramatizing are still taking place in the news landscape?

Brooks: I feel that what those people in that picture were trying to keep alive, has died. Journalism has become a target of abuse. If there was one thing you could leave behind that you’ve written, for me it would be the devil speech in that movie — where Albert Brooks says he’s not going to have a tail. In this case, he looks exactly like the devil and he’s running for president.

Do you see parallels with the media’s treatment of Donald Trump and what Brooks was discussing?

Brooks: It’s terrifying. The other day, it occurred to me, and I actually wrote it down, that he’s a bear in a dumpster and it’s like we’re in there some place in that dumpster as he decides what to eat and not to eat. Throwing it over his shoulder. [Chuckles.] I hope you’re not a Republican.

Will you collaborate again?

Craig: I hope so.

Brooks: Yeah, we just got bloody in the center of the ring. We’ve talked about it. Kelly’s the real deal.