/*
 * Word-linked image popover
 * --------------------------------------------------------------------------
 * A word marked in the editor as
 *     <span class="img-pop" data-img-src="URL">word</span>
 * shows a floating image preview on hover (desktop) or tap (mobile).
 * It never navigates anywhere — it only pops the image up.
 */

.img-pop {
    cursor: pointer;
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dotted var(--color-primary, #6d5efc);
    border-radius: 3px;
    padding: 0 1px;
    transition: background 0.15s ease, color 0.15s ease;
}
.img-pop:hover,
.img-pop.img-pop-active {
    background: color-mix(in srgb, var(--color-primary, #6d5efc) 14%, transparent);
    color: var(--color-primary, #6d5efc);
}

/* tiny picture glyph after the word so readers know it opens an image */
.img-pop::after {
    content: "";
    display: inline-block;
    width: 0.7em;
    height: 0.7em;
    margin-inline-start: 0.22em;
    vertical-align: -0.02em;
    background-color: currentColor;
    opacity: 0.6;
    -webkit-mask: var(--img-pop-glyph) no-repeat center / contain;
    mask: var(--img-pop-glyph) no-repeat center / contain;
}
:root {
    --img-pop-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M21 3H3a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h18a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2zM8.5 7a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3zM5 19l4-5 3 3.6L15 13l4 6H5z'/%3E%3C/svg%3E");
}

/* ── Floating preview ─────────────────────────────────────────────────────── */
.img-pop-popup {
    position: fixed;
    z-index: 100060;
    max-width: min(90vw, 460px);
    padding: 6px;
    border-radius: 14px;
    background: rgba(20, 20, 28, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 22px 60px -12px rgba(0, 0, 0, 0.6),
                0 2px 8px rgba(0, 0, 0, 0.3);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    backdrop-filter: blur(14px) saturate(140%);
    opacity: 0;
    transform: translateY(6px) scale(0.98);
    transition: opacity 0.16s ease, transform 0.16s cubic-bezier(0.22, 1, 0.36, 1);
    pointer-events: none;          /* desktop: never eat hover of the page */
}
.img-pop-popup.img-pop-show {
    opacity: 1;
    transform: translateY(0) scale(1);
}
/* Mobile/touch: center on screen, near full-width with a fixed gutter each side. */
.img-pop-popup.img-pop-touch {
    pointer-events: none;   /* only interactive while shown (see below) */
    left: 16px;
    right: 16px;
    top: 50%;
    width: auto;
    max-width: none;
    transform: translateY(-50%) scale(0.98);
}
.img-pop-popup.img-pop-touch.img-pop-show {
    transform: translateY(-50%) scale(1);
    pointer-events: auto;
}
.img-pop-popup.img-pop-touch .img-pop-frame { min-height: 120px; }
.img-pop-popup.img-pop-touch img { width: 100%; max-height: 78vh; }

/* Dim backdrop behind the centered mobile preview. */
.img-pop-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100059;
    background: rgba(8, 8, 12, 0.55);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.16s ease, visibility 0.16s ease;
}
.img-pop-backdrop.img-pop-backdrop-show { opacity: 1; visibility: visible; }

.img-pop-frame {
    position: relative;
    min-width: 120px;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.img-pop-popup img {
    display: block;
    max-width: 100%;
    max-height: 60vh;
    border-radius: 9px;
    object-fit: contain;
}
.img-pop-popup.img-pop-loading img { visibility: hidden; }

/* loading spinner */
.img-pop-spinner {
    position: absolute;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
    animation: imgPopSpin 0.7s linear infinite;
    opacity: 0;
    pointer-events: none;
}
.img-pop-popup.img-pop-loading .img-pop-spinner { opacity: 1; }
@keyframes imgPopSpin { to { transform: rotate(360deg); } }

/* close affordance — only meaningful on touch */
.img-pop-close {
    position: absolute;
    top: -10px;
    inset-inline-end: -10px;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: #fff;
    color: #111;
    font-size: 18px;
    line-height: 1;
    font-weight: 700;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
.img-pop-popup.img-pop-touch .img-pop-close { display: flex; }

@media (prefers-reduced-motion: reduce) {
    .img-pop-popup { transition: opacity 0.12s ease; transform: none; }
    .img-pop-popup.img-pop-show { transform: none; }
    /* keep vertical centering on mobile even with reduced motion */
    .img-pop-popup.img-pop-touch,
    .img-pop-popup.img-pop-touch.img-pop-show { transform: translateY(-50%); }
    .img-pop-spinner { animation-duration: 1.4s; }
}
