WASHINGTON — The ghost of Justice Antonin Scalia often hangs over the Supreme Court, perhaps never more so than as the justices struggle with the case of the Christian baker who refused to make a wedding cake for a same-sex marriage.

Scalia often spoke of his strong Catholic faith. But he also believed the courts should not grant religious exemptions to the laws everyone must follow.

A person's right to religious freedom does not "excuse him from compliance with an otherwise valid law," Scalia wrote in 1990 for a 5-4 majority that included then-new Justice Anthony M. Kennedy. The "political process," not courts, should decide such questions, he said. Although some religious claims might fail, he wrote, "that unavoidable consequence of democratic government must be preferred to a system in which each conscience is a law unto itself."

Scalia's words and views are revered, especially on the right, but his 1990 opinion looms uncomfortably over the court these days as conservative Christians seek a religious exemption from anti-discrimination laws adopted in liberal states.

Jack Phillips, the owner of Masterpiece Cakeshop near Denver, went to court seeking an exemption from a Colorado civil rights law that requires public businesses to serve all customers. The federal Civil Rights Act forbids discrimination based on race, gender, religion and nationality but not sexual orientation. Only 20 states have joined Colorado in extending anti-discrimination protection to gays and lesbians. No state in the South has adopted such a law.

Phillips says he believes the Bible restricts marriage to a man and a woman and it would be sinful for him to help celebrate the marriage of two men by making them a custom cake.

But in his long legal battle, his lawyers have been obliged to argue his case as mostly about the freedom of speech and "expressive conduct." They described him as a "cake artist," rather like a painter or a sculptor. This would be so even if he were making a plain white cake with no words or symbols, they argued.

During Tuesday's argument, the liberal justices said that claim sounds far-fetched and without limits. If a cake maker is engaged in expressive conduct, why not a dress designer, a hairstylist, an architect or a makeup artist, they asked. The examples were endless. "We would cause chaos" and "undermine every civil rights law" if the court buys that argument, Justice Stephen G. Breyer said.

When the state's lawyer rose to defend the law, the argument shifted abruptly, and the court's conservatives, led by Chief Justice John G. Roberts Jr. and Justice Samuel A. Alito Jr., focused on religion.

Roberts asked about the Catholic Legal Services: If it offers free legal help, could it be required to help arrange a same-sex marriage? Alito wondered whether Colorado could "compel a religious college to provide married student housing for a married same-sex couple." By their questions and comments, the court's conservatives made clear they believe it is wrong for the government to force a believer to violate his religious conscience.

Before Scalia's 1990 opinion, the high court often granted religious exemptions based on the First Amendment protection for the "free exercise" of religion. The justices had long said the government can and must accommodate believers when possible.

In the most famous case, the court during World War II said the children of Jehovah's Witnesses might not be forced to salute and pledge their allegiance to the American flag. If the court rules for the Colorado baker, its opinion probably will rely on that case, West Virginia vs. Barnette, because it involved freedom of expression and freedom of religion.

Since the 1990s, however, when Scalia was skeptical of religious exemptions, the ideological sides have shifted. Then, the court's three staunch liberals — Justices William Brennan, Thurgood Marshall and Harry Blackmun — dissented from the ruling in Employment Division vs. Smith, calling Scalia's opinion a "wholesale overturning of settled law" for protecting religious freedom. The case before the court arose when two Native Americans were fired for having used peyote during a religious ceremony. State officials said peyote was classified as an illegal drug, and the liberal justices said it could be viewed like communal wine in church.

These days, by contrast, conservatives including President Donald Trump see "religious liberty" as being under constant threat, and they have called for more legal protection for Christians who object to government policies. The administration joined in support of the Colorado baker.

Despite the shift in political thinking, Scalia's opinion stills stands, and it has shaped the law on religious freedom. Congress tried to overturn the ruling in the Religious Freedom Restoration Act in 1993. Adopted on a nearly unanimous vote, it said the "government shall not substantially burden a person's exercise of religion."

But the court, with Kennedy and Scalia again in the lead, struck back in 1997 and ruled the religious freedom law might not be enforced against states and cities. In a case called City of Boerne vs. Flores, they said Congress did not have the power to expand the "free exercise of religion" and apply it to the states.

Kennedy sounded torn on what to do now. At first, he said it would be an "affront to the gay community" if the court rules for the Colorado baker.

But 30 minutes later, Kennedy seemed open to doing just that. He said some Colorado officials displayed "hostility to religion."

When Kennedy pressed on, a lawyer for American Civil Liberties Union answered with a surprising twist. What if the Christian baker had to "attend that wedding and help cut the cake?" Kennedy asked.

That's not at issue here, said the ACLU's David Cole. However, "in a future case that involved physical participation in a religious ceremony that an individual deeply opposed, the court might create a new doctrine not governed by Smith," he said, referring to Scalia's 1990 opinion. The court might want to say that "compelling somebody to engage in a religious ceremony" violates their rights to the free exercise of religion, he said.

The chief justice quickly intervened. "Is that a modification of Smith?" he asked. "It sounds like an overruling of Smith."

The exchange suggested the justices are not ready to reconsider their precedents on religion and instead will split 5-4 on the odd question of whether making a wedding cake involves protected free speech.