/* START TOOLTIP STYLES */
[cmplz-tooltip] {
  position: relative; /* opinion 1 */
  cursor: pointer;
}

/* Applies to all tooltips */
[cmplz-tooltip]::before,
[cmplz-tooltip]::after {
  text-transform: none;
  font-size: 13px;
  user-select: none;
  pointer-events: none;
  position: absolute;
  display: none;
  opacity: 0;
}

[cmplz-tooltip]::before {
  content: '';
  border: 5px solid transparent; /* opinion 4 */
  z-index: 1001; /* absurdity 1 */
}

[cmplz-tooltip]::after {
  content: attr(cmplz-tooltip); /* magic! */
  font-weight:normal;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 1ch 1.5ch;
  border-radius: .3ch;
  box-shadow: 0 1em 2em -.5em rgba(0, 0, 0, 0.35);
  background: #333;
  color: #fff;
  z-index: 1000; /* absurdity 2 */
  width: min(100vw, 45ch);
  text-align:left;
}

/* Make the tooltips respond to hover */
[cmplz-tooltip]:hover::before,
[cmplz-tooltip]:hover::after {
  display: block;
}

/* Make the tooltips respond to focus */
[cmplz-tooltip]:focus::before,
[cmplz-tooltip]:focus::after {
  display: block;
}



/* don't show empty tooltips */
[cmplz-tooltip='']::before,
[cmplz-tooltip='']::after {
  display: none !important;
}

/* FLOW: UP */
[cmplz-tooltip]:not([flow])::before,
[cmplz-tooltip][flow^="up"]::before {
  bottom: calc(100% + 5px);
  border-bottom-width: 0;
  border-top-color: #333;
}

[cmplz-tooltip]:not([flow])::after,
[cmplz-tooltip][flow^="up"]::after {
  bottom: calc(100% + 10px);
}

[cmplz-tooltip]:not([flow])::before,
[cmplz-tooltip]:not([flow])::after,
[cmplz-tooltip][flow^="up"]::before,
[cmplz-tooltip][flow^="up"]::after {
  left: 50%;
  transform: translate(-50%, -.5em);
}

/* FLOW: DOWN */
[cmplz-tooltip][flow^="down"]::before {
  top: 17px;
  border-top-width: 0;
}

[cmplz-tooltip][flow^="down"]::after {
  top: calc(100% + 5px);
}

[cmplz-tooltip][flow^="down"]::before,
[cmplz-tooltip][flow^="down"]::after {
  left: 50%;
  transform: translate(-50%, .5em);
}

/* FLOW: LEFT */
[cmplz-tooltip][flow^="left"]::before {
  top: 50%;
  border-right-width: 0;
  border-left-color: #333;
  left: calc(0em - 5px);
  transform: translate(-.5em, -50%);
}

[cmplz-tooltip][flow^="left"]::after {
  top: 50%;
  right: calc(100% + 5px);
  transform: translate(-.5em, -50%);
}

/* FLOW: RIGHT */
[cmplz-tooltip][flow^="right"]::before {
  top: 10px;
  border-left-width: 0;
  border-right-color: #333;
  right: calc(0em - 23px);
  transform: translate(.5em, -50%);
}

[cmplz-tooltip][flow^="right"]::after {
  top: 10px;
  left: calc(100% + 23px);
  transform: translate(.5em, -50%);
  min-width:150px;
}

/* KEYFRAMES */
@keyframes tooltips-vert {
  to {
	opacity: .9;
	transform: translate(-50%, 0);
  }
}

@keyframes tooltips-horz {
  to {
	opacity: .9;
	transform: translate(0, -50%);
  }
}

/* FX All The Things */
[cmplz-tooltip]:not([flow]):hover::before, [cmplz-tooltip]:not([flow]):focus::before,
[cmplz-tooltip]:not([flow]):hover::after, [cmplz-tooltip]:not([flow]):focus::after,
[cmplz-tooltip][flow^="up"]:hover::before, [cmplz-tooltip][flow^="up"]:focus::before,
[cmplz-tooltip][flow^="up"]:hover::after, [cmplz-tooltip][flow^="up"]:focus::after,
[cmplz-tooltip][flow^="down"]:hover::before, [cmplz-tooltip][flow^="down"]:focus::before,
[cmplz-tooltip][flow^="down"]:hover::after, [cmplz-tooltip][flow^="down"]:focus::after {
  animation: tooltips-vert 300ms ease-out forwards;
}

[cmplz-tooltip][flow^="left"]:hover::before, [cmplz-tooltip][flow^="left"]:focus::before,
[cmplz-tooltip][flow^="left"]:hover::after, [cmplz-tooltip][flow^="left"]:focus::after,
[cmplz-tooltip][flow^="right"]:hover::before, [cmplz-tooltip][flow^="right"]:focus::before,
[cmplz-tooltip][flow^="right"]:hover::after, [cmplz-tooltip][flow^="right"]:focus::after {
  animation: tooltips-horz 300ms ease-out forwards;
}
