Simply put: it's not possible to detect mobile devices using only css
As technology advances, distinguishing between mobile and desktop browsers is becoming increasingly difficult even with javascript.
Rather than focusing on the device being used, it's more important to consider how your content will adapt to different screen sizes and orientations. If a user's device supports the full desktop experience due to its high resolution, don't hinder their experience by trying too hard to identify their device.
Instead of categorizing styles as solely "mobile or desktop," prioritize whether they are visually appealing and functional at specific sizes and orientations by utilizing max-width and max-height queries along with orientation checks.
By following this approach, not only will you improve the experience for mobile users but also for desktop users who may have unexpected resolutions (such as older users who adjust resolution instead of font size).
NOTE: In rare cases where you absolutely need to display something specifically for mobile, modernizr can be utilized to target touch devices with custom styles.