def remove_comments(css):
    """Remove all CSS comment blocks."""
    iemac, preserve = False, False
    comment_start = css.find('/*')
    while comment_start >= 0:
        preserve = css[comment_start + 2:comment_start + 3] == '!'
        comment_end = css.find('*/', comment_start + 2)
        if comment_end < 0:
            if not preserve:
                css = css[:comment_start]
                break
        elif comment_end >= comment_start + 2:
            if css[comment_end - 1] == '\\':
                comment_start = comment_end + 2
                iemac = True
            elif iemac:
                comment_start = comment_end + 2
                iemac = False
            elif not preserve:
                css = css[:comment_start] + css[comment_end + 2:]
            else:
                comment_start = comment_end + 2
        comment_start = css.find('/*', comment_start)
    return css
