Check the following MDN articles:
prefers-color-scheme media query
theme-color meta tag
meta element and its attributes
Thomas Steiner has written insightful articles on this topic:
Understanding color-scheme on web.dev
Let There Be Darkness (Maybe) on Medium