Until recently, the custody battle over 3-year-old Gus was playing out only in a Los Angeles courtroom and on the pages of celebrity gossip magazines.

Now the fight has moved to the California state Capitol, where “Lost Boys” actor Jason Patric is trying to change state law to allow sperm donors, in certain situations, to become legal parents and share custody of the children that result from their seed.

Patric’s former girlfriend, massage therapist Danielle Schreiber, is fighting the bill, arguing that the law protects her as the child’s only legal parent because she never married Patric and used a medical procedure to conceive.

Both sides have hired a slew of lobbyists who are arguing over how a bill inspired by a tumultuous Hollywood romance will affect other California families that rely on sperm donors to have children.

The fight reflects the modern state of child-rearing, where many heterosexual couples never marry, some lesbian couples conceive with sperm donated by a male friend, and relationships — gay and straight — frequently dissolve after children are born.

Proponents of Senate Bill 115 say it will close a legal loophole that forbids certain sperm donors from being recognized as fathers when an unmarried woman is impregnated with their sperm.

The other side says the proposal could grant parenting rights to sperm donors against the wishes of a child’s legal parents. They say the bill is an attempt by Patric to overturn a court ruling that he lost.

“This bill should never be heard by the Legislature,” said Richard Harris, a lobbyist representing Schreiber and her family.

State Sen. Jerry Hill, a San Mateo Democrat, said the custody fight of the Hollywood couple has raised the profile of his bill, but that it addresses a broader issue.

“All that case did is highlight that there is a problem that the court defined,” Hill said.

He said he’s sponsoring the bill because the judge’s ruling pointed out confusion resulting from another measure two years ago, which sought to give lesbian parents more rights, making it more difficult for sperm donors to claim they’re ­parents.

The courts interpreted that law to mean that Patric should be treated as a sperm donor, not a parent, and gave full custody to the mother.

The latest legislation would allow a man whose donated semen impregnates an unmarried woman to petition the courts for parenting rights by proving his devotion to the child.

“The issue isn’t whether Jason Patric gets custody. The issue is that you have the right to at least get that consideration,” said Paula Treat, a lobbyist who has been retained by Patric’s custody lawyer.

“He wasn’t in love with the boy’s mother, but he’s in love with the little boy.”