The Cosmos skin has CSS selectors targeting `.CodeMirror`. This class will be removed when CodeMirror 6 is fully rolled out (T259059) which is slated to happen by MW 1.46 (May–June 2026).
As far as I can tell, [[ https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/skins/Cosmos/+/2c707bcf89765636de06af0f4dd0727499226b30/resources/skinStyles/ext.CodeMirror.visualEditor.less | ext.CodeMirror.visualEditor.less ]] shouldn't be needed //at all// after the CM6 rollout. CodeMirror + 2017 editor styles in CM6 should be the same in every skin (unless you want to change them).
I'm not sure about [[ https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/skins/Cosmos/+/2c707bcf89765636de06af0f4dd0727499226b30/resources/extensions/CodeMirror.visualEditor/darkTheme.less | CodeMirror.visualEditor/darkTheme.less ]]. CM6 has dark mode built-in, which can be activated by adding the `.skin-theme-clientpref-night` class to the `html` element, just like Vector 2022. Or, you could wait for T163533 which will allow you to pick which theme you want to be used in CodeMirror (by default). Themese (T163533) likely won't come until after MW 1.46, however.
See the [[ https://www.mediawiki.org/wiki/Extension:CodeMirror#Migration_guide | CodeMirror 6 migration guide ]] for more general info.