When Carlos Rafael Rivera got the call that he would be writing the music for “The Queen’s Gambit,” he immediately did two things: He read the Walter Tevis novel, and he took up chess.

More than three years later, the composer’s classically styled music for the Netflix series has become his most widely praised work. But that rich orchestral score wasn’t what writer-director Scott Frank originally envisioned.

Frank initially thought a lone piano could underpin the story of an orphan whose meteoric rise in the chess world is nearly derailed by drug and alcohol abuse.

“The piano was very present in the first episode,” Rivera notes. “By the time she moves out of that world of grays and browns, it becomes a more colorful world, so we had to add instrumentation. It started to hit me: What if her reality in the orphanage is all piano, but when she looks up and plays the games on the ceiling, it’s fully orchestral, like a dream?”

A “classical” approach seemed appropriate, the Miami-based composer affirms. “The game itself is so old, and using the style and techniques of counterpoint would help establish the idea of movement versus counter-movement in the game play,” he reasoned.

Also, because Beth (Anya Taylor-Joy) grows from childhood to young adulthood over the seven hours, no single theme could accommodate the character. “I realized, even before the scripts were shot, that I was going to have to address her addiction,” Rivera says. “She was her own enemy.”

The various chess matches in the series proved to be Rivera’s biggest challenge. “It wasn’t about scoring 20 games differently,” he says. “I was scoring her emotional state. The games were contextual. If she was going to battle it out with Benny [one of her mentors], then there was going to be battle music.”

Says Frank: “Carlos’ music was crucial because the chess sequences had to somehow feel emotional, even if one wasn’t familiar with the game. The score also did a lot of heavy lifting when it came to the interior of Beth Harmon. While the camera was often very close, Carlos’ music somehow conveyed this inner ruin when she was at the bottom, or this soaring release when she found connection or happiness. There were so many chapters in the story, all with their own feeling, and the music was as important at differentiating as the cinematography. I can’t imagine the show working as well as it did without that score.”

Rivera (who won his first Emmy for Frank’s last series, 2017’s Western “Godless”) recorded most of “The Queen’s Gambit” last summer with a 50-piece orchestra in Budapest. Because he wasn’t even sure that would be possible when they first scheduled the dates, Rivera created much of the score in his Miami studio using the best orchestral samples he could find. The final score is a mix of the two. Rivera himself plays the piano throughout.

As for Rivera’s chess playing: “I knew I was bad before I started playing it all the time,” he says. “And now I know how bad I am.”