Hello I use the following function to check
function verificaUserAgent() {
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    $iphone = strpos($user_agent, "iPhone");
    $android = strpos($user_agent, "Android");
    $palmpre = strpos($user_agent, "webOS");
    $ipod = strpos($user_agent, "iPod");
    $berry = strpos($user_agent, "BlackBerry");
    $symbian = strpos($user_agent, "Symbian");
    $windowsphone = strpos($user_agent, "Windows Phone");
    if ($iphone || $android || $palmpre || $ipod || $berry || $symbian || $windowsphone == true) {
        return true;
    } else {
        return false;
    }
}
So in my HTML I do as follows to use the function return
<html class="<?= verificaUserAgent() === true ? 'mobile' : 'desktop' ?>">
In turn in your LESS or CSS file I create a main style class .mobile and another .desktop then I put all the different styles inside those classes
I hope I can help hug!
							
							
						 
Ever heard of Sinergi Browserdetector ? Maybe I can help
– Andrews Gomes
I’ll look into it, thanks friend, but I wanted to try a solution without downloading anything external
– user169113