First, restore your previous masterpage so you can see the gear icon again. Second use Developer Tool (F12) and select the gear icon to see what classes is in play. If it's just the gear icon missing your solution is there. Search for the classes and ID's in your custom CSS to find the solution.
In Office 365 the gear icon looks like this:
<button type="button" class="o365cs-nav-item o365cs-nav-button o365cs-topnavText ms-bgc-tdr-h o365button" role="menuitem" aria-expanded="false" title="Open the Settings menu to access personal and app settings" id="O365_MainLink_Settings" aria-label="Open the Settings menu to access personal and app settings" aria-haspopup="true"><span class="owaimg ms-Icon ms-Icon--Settings ms-icon-font-size-17"> </span></button>