Add body classes based on terms from referenced node

I have a node type called (for example) Team, with a term reference to choose colour.

Then I have a node type called Member with a node reference to choose single Team node.

How can I add a body class to the Member pages based on the Team’s colour?

I can easily add classes for the colour to the Team page using context or a template function but can’t find an answer for the Member pages.

Many thanks in advance

Drupal version: 


Source: https://www.drupal.org/taxonomy/term/22/feed