/*
 * Glossary tooltips inside the leaflet body - ported from v2
 * (euphoria/hmvc-modules/bugiardino/assets/css/glossario.css).
 *
 * Markup comes from App\Support\GlossaryLinker:
 *   span.glossary-tooltip > span.glossary-link > a          the word in the text
 *                         > span.glossary-tooltip-content   the hover card
 */

.glossary-tooltip {
    display: inline;
    position: relative;
    z-index: 999;
}

/* Trigger text */

.glossary-tooltip a {
    cursor: pointer;
    display: inline-block;
    border: 0 !important;
}

/* v2 gave the trigger no affordance at all - a dotted underline marks it as explainable
   without making it look like an ordinary in-content link. */
.glossary-tooltip .glossary-link a {
    color: inherit;
    text-decoration: underline dotted;
    text-underline-offset: 2px;
}

/* Gap filler: keeps :hover alive while the pointer travels from word to card. */

.glossary-tooltip::after {
    content: '';
    position: absolute;
    width: 360px;
    height: 20px;
    bottom: 100%;
    left: 50%;
    pointer-events: none;
    transform: translateX(-50%);
}

@media (hover: hover) {
    .glossary-tooltip:hover::after {
        pointer-events: auto;
    }
}

/* No pointer travel on touch: the gap filler would only swallow taps. */
@media (hover: none) {
    .glossary-tooltip::after {
        display: none;
    }
}

/* Tooltip */

.glossary-tooltip-content {
    position: absolute;
    z-index: 9999;
    width: 360px;
    max-width: 90vw;
    left: 50%;
    margin: 0 0 20px -180px;
    bottom: 100%;
    text-align: left;
    box-shadow: -5px -5px 15px rgba(48, 54, 61, 0.2);
    background: #2a3035;
    border-radius: 4px;
    opacity: 0;
    cursor: default;
    pointer-events: none;
    transform: translate3d(0, -10px, 0);
    transition: opacity 0.3s, transform 0.3s;
}

/* Pointer devices: the card follows the hover. Touch devices get `.is-open`, toggled by
   js/glossario.js on the first tap (the second tap then opens the glossary page). */
@media (hover: hover) {
    .glossary-tooltip:hover .glossary-tooltip-content,
    .glossary-tooltip:focus-within .glossary-tooltip-content {
        pointer-events: auto;
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

.glossary-tooltip.is-open .glossary-tooltip-content {
    pointer-events: auto;
    opacity: 1;
    transform: translate3d(0, 0, 0);
}

/* Arrow */

.glossary-tooltip-content::after {
    content: '';
    top: 100%;
    left: 50%;
    border: solid transparent;
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
    border-top-color: #2a3035;
    border-width: 10px;
    margin-left: -10px;
}

/* Tooltip content */

.glossary-tooltip-text {
    display: block;
    padding: 1.31em 1.21em 1.21em 1.31em;
    color: #fff;
    font-size: 0.9rem;
    line-height: 1.4;
}

.glossary-tooltip-text a {
    color: #fff;
    font-weight: bold;
    text-decoration: underline;
}

/* Touch layout
 *
 * No pointer to follow: the card is centred on the screen at 90% of the available width and
 * only the arrow tracks the tapped word. js/glossario.js sets the three custom properties on
 * the .glossary-tooltip element when the card opens.
 */

@media (hover: none) {
    .glossary-tooltip-content {
        width: var(--glossary-width, 90vw);
        max-width: none;
        left: 0;
        margin: 0 0 20px 0;
        transform: translate3d(var(--glossary-offset-x, 0px), -10px, 0);
    }

    .glossary-tooltip.is-open .glossary-tooltip-content {
        transform: translate3d(var(--glossary-offset-x, 0px), 0, 0);
    }

    .glossary-tooltip-content::after {
        left: var(--glossary-arrow-x, 50%);
    }
}
