<?php
// includes/device.php
function is_mobile_ua(?string $ua = null): bool {
    $ua = strtolower($ua ?? ($_SERVER['HTTP_USER_AGENT'] ?? ''));
    if ($ua === '') return false;

    // phones
    $phones  = ['iphone','ipod','android','windows phone','wpdesktop','blackberry','bb10','webos','palm',
                'opera mobi','opera mini','ucbrowser','symbian','nokia','tizen','fennec','maemo','mobile'];
    // tablets (treat as mobile)
    $tablets = ['ipad','tablet','kindle','silk','playbook','xoom','sch-i','sm-t','nexus 7','nexus 9','lenovo tab','mi pad'];

    foreach ($phones as $k)  { if (strpos($ua, $k) !== false) return true; }
    foreach ($tablets as $k) { if (strpos($ua, $k) !== false) return true; }
    return false;
}
