:root {
    --close-area-idx: 1;
    --label-idx: 2;
    --tooltip-idx: 3;
}

.tooltip-wrapper {
    display: inline;
}

.tooltip-wrapper > .tooltip {
    display: none;
    max-width: 350px;
    white-space: normal;
}

.tooltip-wrapper > p {
    display: inline;
}


.tooltip {
    z-index: var(--tooltip-idx);
    y: 1.3em;

    position: absolute;

    p:first-of-type {
        margin-top: 0;
    }
    p:last-of-type {
        margin-bottom: 0;
    }
}

.tooltipped {
    position: relative;
    cursor: help;
    z-index: var(--label-idx);
}

.tooltip-wrapper > input {
    border: 0;
    clip: rect(0 0 0 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
}

.tooltip-wrapper input:focus ~ .tooltip {
    display: block;
}

.tooltip-wrapper input:focus ~ .close-area {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0;

    z-index: var(--close-area-idx);
}

/* Restore paragraph behaviour */
.tooltip {
  display: inline-block;
  span {
    display: inline-block;
    br {
      height: 0.5em;
      display: block;
    }
  }
}

/* Hide recursive tooltips */
.tooltip {
  .tooltip {
    display: none;
  }
  .tooltip-wrapper {
    input {
      display: none
    }
  }
  .tooltipped {
    cursor: unset;
  }
}
