Why not use an existing plugin for that?

https://wordpress.org/plugins/wp-night-mode/

Contact the author and let him get involved.

No need to reinvent the wheel