Details of "public opinion" happiness penalty calculation?

I'm wondering if anybody knows the details of how the "public opinion" happiness penalty for ideological pressure is calculated.

Here are the parts I'm pretty sure I understand:

  • The penalty applies when you have an ideology, and another player has a different ideology, and their ideology is more popular than yours.
  • "More popular than yours" means the other player is more influential over you (via their tourism vs. your culture) than you are over them.
  • This means that both culture (to make it harder for other civs to become influential over you) and tourism (to become more influential over other civs) help protect you from the penalty.

Parts I'm not sure of:

  • How big is the penalty, or what's the calculation for it, exactly? I know the generalities, but I don't understand it well enough to be able to actually calculate what the penalty would be in a given set of circumstances.
  • Does the size of the penalty vary continuously with ratio of attacker tourism to defender culture? Or does it have discrete thresholds at levels of influence ("exotic", "familiar", etc.)?
  • Does the size of the penalty vary based on difficulty? Map size? Game pace? Something else I'm forgetting?
  • Does the penalty stack if multiple civs with a different ideology are more influential over you than you are over them, or do you only eat the biggest single penalty? Or maybe the biggest penalty for each of the two other ideologies?
  • If there's a civ with the same ideology as you who's influential over you, does that apply a protective effect via applying pressure toward your own ideology? Or are civs of your own ideology completely ignored?
  • How does the ideological pressure from the "World Ideology" resolution interact with the rest of the system?

Thanks!

edit I think I found the answers, see comments.