Use wp_add_inline_style to add code to before wp_head?

Yes, that should be doable. Just enqueue your inline styles with callback hooked to wp_enqueue_scripts and priority set to 0 (assuming other styles are loader later / lower priority / bigger number). You also need to register a dummy handle to which you attach the inline styles to, so no other styles are loaded before them.

function my_pre_theme_assets() {
    wp_register_style( 'dummy-handle', false );
    wp_enqueue_style( 'dummy-handle' );
    wp_add_inline_style( 'dummy-handle', '* { color: red; }' );
}
add_action( 'wp_enqueue_scripts', 'my_pre_theme_assets', 0 );

Dummy handle idea seen here, wp_add_inline_script without dependency