JavaScript (Node.js), 9594 bytes
x=>x.toLowerCase(a=w=/[a-z]/gi).replace(/_/g,g=i=>i>62g=Z=>Z>62?(iZ-52).toString(36):g(aw.exec(x)<{}|2*<g|2*-~i~Z))
JavaScript (Node.js), 125 124 bytes
x=>x.replace(s=/./g,c=>parseInt(c,36)>9?c.toLowerCase(s+=+(c<{})):c=='_'?('0b'+s.slice(4,9)-~9).toString(36,s=s.slice(5)):c)