Mysql : foreign key relative to multiple tables
FOREIGN KEYs have severe limitations.  I think you have exceeded them.

Complex data structures cannot depend on FKs for integrity, your code is required.

Suggest that you build Stored Routines and/or subroutines in your application language, and encapsulate the integrity constraints there.  And build a clean API into the routines to make it easy for the clients to achieve their goals while the routine achieves the integrity goals.