Layered structure and complex mechanochemistry underlie strength and versatility in a bacterial adhesive