if a person commits adultery in his or her heart, thinking and speaking of adultery without actually commiting a physical act, let’s say like a sexual phantasy, is that a mortal or venial sin?
must one confess every venial or is that optional, so to speak?
Thoughts and words can be mortal sins. In fact, they are probably the most common mortal sins. Whether one person’s specific sexual fantasies are mortal sins is a complicated question that cannot really be anwered by anyone here over the internet. You should talk to your confessor about this. If the thoughts are completely involuntary, its almost certainly not mortal. If not involuntary, but not totally voluntary - hard to say.
To me, and not everyone here will agree with this, the sexual thoughts are not as dangerous as some other thoughts. Thoughts of hate, arrogance, superiority, greed, obsession with power, etc, are more likely to drive charity and love from your heart and close your heart to God. But sexual thoughts, especially obsessive ones, can also do that.
Mortal and venial are useful but extremely rough and broad categories. The key to understanding the effect of a particular sin is to examine its impact on your relationship with God. This is not something that most people are well equipped to do, which is why we have tried to create categories instead. If this sin is driving you from God, leading to rejection of God and holiness in your life, its a grave matter for you. Sexual thoughts can do this by causing you to focus on things that you know are wrong. These thoughts can cause your to turn your mind from God to be away from His sight so that you can think about things you know He doesn’t want you to do.
God does not expect you to be perfect (although we should try). He does expect that we not deliberately move away from Him. If the thoughts you are referring to are doing that, you should work on stopping that behavior.
Habitual behavior cannot always be halted overnight. Just as it takes dedication and practice to develop the mental and physical habits that allow an athlete to consistently make a free throw, its takes dedication and practice to develop the mental discipline to exercise your sexual faculties in a healthy way. Individual failures are not as important as a true dedication to improving. God knows your heart and will understand if you are really trying to improve. In other words, be careful because you can fool yourself on this point, but you can’t fool Him. Examine your conscience, try to understand what you are doing and why, and whether you think it is something that is reducing your ability to welcome God into your heart and your life. If you find that it is (and it sounds like you already know the answer to that), work on doing better. The “why” part is often the key to success, I think.
The most important step is admitting this is something you need to work on, congrats on passing that step! The rest aren’t easy, but they are doable. Luck and grace on your journey.