If we want to figure this out, we will have to go back to the beginning, that is, to the story of Cain and Abel... After all, sometimes the best way to move forward is to go backwards.
Genesis 4:3-8;
"3 And in process of time it came to pass, that Cain brought of the fruit of the ground an offering unto Jehovah. 4 And Abel, he also brought of the firstlings of his flock and of the fat thereof. And Jehovah had respect unto Abel and to his offering: 5 but unto Cain and to his offering he had not respect. And Cain was very wroth, and his countenance fell. 6 And Jehovah said unto Cain, Why art thou wroth? and why is thy countenance fallen? 7 If thou doest well, shall it not be lifted up? and if thou doest not well, sin coucheth at the door; and unto thee shall be its desire; but do thou rule over it. 8 And Cain told Abel his brother. And it came to pass, when they were in the field, that Cain rose up against Abel his brother, and slew him. 9 And Jehovah said unto Cain, Where is Abel thy brother? And he said, I know not: am I my brother’s keeper? 10 And he said, What hast thou done? the voice of thy brother’s blood crieth unto me from the ground." (ASV)
The most essential verse here in understanding 1 John 3:12 is Genesis 4:7. Notice how God explicitly tells Cain what would be the product of him doing good(his disposition would be lifted, his spirits raised), but how God doesn't tell Cain what would be the product of him NOT doing good. He merely states a fact, sort of a reminder for Cain. And then He tells Cain what he must do... He doesn't even give an "or else."; He just reminds Cain and tells him what to do and then (ambiguously) leaves it at that... "But if you don't do good, well, just remember that sin is crouching at the door, and it wants you; so master it." God never finishes the thought! He just gives an ambiguous statement... So, what's going on? Well, actually, the thought was finished. We're supposed to see that with the coming events, detailed for us in verses 8-9.
So, let's remember; sin is lurking close by, it wants to devour Cain, and Cain is supposed to not let that happen by conquering it instead. So, let's now see what happens in verses 8-9;
"8 And Cain told Abel his brother. And it came to pass, when they were in the field, that Cain rose up against Abel his brother, and slew him. 9 And Jehovah said unto Cain, Where is Abel thy brother? And he said, I know not: am I my brother’s keeper?"
Wow, so Cain murdered his brother... and then he lied to God about it! (And in a rather unremorseful and impertinent manner at that.) What do you think? Did Cain conquer sin like he was supposed to... or did he let it devour him? Remember, it was not as though Cain was incapable of conquering sin; if he was, then God would never have commanded him to do so in the first place! Indeed, sin devoured him wholly, and it did so because he wanted it to(if I truly don't want something to happen, and I'm fully capable of preventing it, then it follows that I'll prevent! Simple as that).
Now, let's go back to 1 John 3:12 and read the context. 1 John 3:7-12;
"Little children, make sure no one deceives you; the one who practices righteousness is righteous, just as He is righteous; 8 the one who practices sin is of the devil; for the devil has been sinning from the beginning. The Son of God appeared for this purpose, to destroy the works of the devil. 9 No one who has been born of God practices sin, because His seed remains in him; and he cannot sin continually, because he has been born of God. 10 By this the children of God and the children of the devil are obvious: anyone who does not practice righteousness is not of God, nor the one who does not love his brother and sister. 11 For this is the message which you have heard from the beginning, that we are to love one another; 12 not as Cain, who was of the evil one and murdered his brother. And for what reason did he murder him? Because his own deeds were evil, but his brother’s were righteous." (NASB)
The "one who practices sin is of the devil"? What's up with that? Well, what does it mean to "practice"? Here is what Merriam-Webster defines "practice" as "to do (something) regularly or constantly as an ordinary part of your life." You see, because we are imperfect humans, sin is always "crouching at the door"; it always desires us, 24/7, 365 days a year. And we have two choices; let it devour us by desiring it back(as Cain desired to murder his own innocent flesh and blood), or conquer it and not let it control our lives. You see, "conquering" sin doesn't mean ridding yourself of sin entirely, because that's impossible, and God knows that(thus God, who loves us, wouldn't give us a command to do so); conquering sin is about not permitting it to conquer you! Either you conquer sin, or it conquers you. To let it conquer you is to let it be a part of your life, to let it be made manifest in the things you do and say, and (just as importantly) in your mind and heart; this is the one who "practices sin" and "is of the devil". Conquering sin means doing the opposite; not letting it be an integral part of your life, i.e. not practicing it(as the children of the devil do as stated in verse 10). And, above all, that means LOVING your brother! This is the "message which you have heard from the beginning." Cain did not love his brother; he let sin devour him, which then led him to hate his brother, and that hatred is precisely what led Cain to murder him(every serious action you take stems from an underlying condition of the heart).
This is what verse 12 of 1 John 3 means. "And for what reason did he murder him? Because his own deeds were evil, but his brother’s were righteous." The evil deeds of Cain was hating his brother! It didn't have anything to do with his sacrifice of fruit(that is to say, the unrighteousness in and of itself hadn't to do with what kind of sacrifice he gave or how he gave it. The events apropos the sacrifices[of both him and his brother] were certainly the root cause of said unrighteousness, but the "evil deeds" were not of the sacrifice). It had to do with Cain hating his own brother. Love and hate are not things you do per se, but more about conditions of the heart. And yet, John is saying that to love your brother is to be righteous, and therefore to be born of God! And to hate your brother is to be unrighteous, and therefore not be born of God! You may not be doing anything to the person, but it doesn't matter, because it's one and the same as if you were doing something. Cain killed his brother because his own deeds were evil, i.e. Cain hated his brother, and hatred never leads to anything good; in the case of Cain, it led to the murder of his own brother. THIS is what it means to be of the wicked one; to let sin devour you by allowing it be ingrained at the fundamental level(your mind and heart), consequently making it an integral part of what you speak and what you carry out, i.e. your lifestyle as a whole.
Hope this helps, and have a wonderful day! Take care. :)