You can add some theme logic to change the background color of the selected tab whenever the theme changes by using a ternary operator within the className attribute.
Smooth Change Transitions
To create these smooth change transitions, I used the Layout-Transition functionality from Framer Motion. Here I used a layoutId to achieve the desired outcome: