Specific Shadow Casting for Puzzle Game

I am trying to create a 3D puzzle game where shadows are a part of the mechanic. For that I need to control which lights cause which objects to cast shadows.
Specifically, it's like this:
There are two light Sources, A and B. Also there's the player and an NPC. Additionally there is just regular level geometry. Both lights shall cause the level geometry to cast shadows. However, the Player shall only cast Shadow from light source A and the NPC only from light Source B.
I attached an image to visualize the Problem. L is a piece of level geometry, for example a pillar or a tree. the two light sources cause it to cast two shadows. But the Player P only casts a shadow from the blue light source and the NPC only from the red light source.
Both light sources and both characters will be moving dynamically in the game, so baking is not an option.
I am currently using the build-in render pipeline but could switch to universal if it is necessary for this to work.

Does anyone have any suggestion how to do this?

Thank you all in advance :)

8582356--1149928--Puzzle Shadow Problem.png

Sorry that I didn't include this in the original post.
I am aware of layers and can get this to work with layers. However, I am weary of layers because you can only have 32 of those and that appears to me to be really not a lot. What if I have 5 different NPCs at some point and each gets their own individual light source? Am I to use up 5 layers just for that then? As Layers are so limited, I want to be cautious in how I spend those and so I am looking for an alternative to using layers and layer masks.

Your concept sounds intriguing! Dynamic shadow casting can definitely add a unique layer to gameplay, especially in a puzzle environment. The challenge of having specific objects respond to specific light sources is something I've seen a few developers tackle in the past.

One potential solution might involve utilizing layers or tags and scripting the interaction between specific light sources and objects based on these layers. However, be prepared for performance implications, especially if you have multiple dynamic objects and lights interacting.

During those inevitable development breaks when you're letting ideas marinate, have you considered exploring different gaming experiences? I recently read a review about Solitaire Cash. I found myself wondering, how does solitaire cash work? It turns out it's a competitive twist on classic solitaire where you can earn real cash. It's a fascinating evolution of a timeless game.

Light layers might be what you are looking for: