/* position comes from projected container pixels in js/popups.js */
.feature-popup {
    /* aligns the pointer and scale animation with the projected feature */
    --popup-origin-x: 50%;

    position: absolute;
    z-index: 3;
    box-sizing: border-box;

    /* 24px preserves a 12px gutter on both sides of narrow containers */
    width: min(280px, calc(100% - 24px));
    padding: 14px;
    color: #20252b;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(31, 41, 51, 0.12);
    border-radius: 12px;
    box-shadow:
        0 12px 32px rgba(20, 28, 38, 0.16),
        0 2px 8px rgba(20, 28, 38, 0.08);
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px) scale(0.97);
    transform-origin: var(--popup-origin-x) 100%;
    transition:
        opacity 160ms ease,
        transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: opacity, transform;
}

.feature-popup::after {
    content: '';
    position: absolute;

    /* half the pointer width keeps its center on --popup-origin-x */
    left: calc(var(--popup-origin-x) - 6px);
    bottom: -7px;
    box-sizing: border-box;
    width: 12px;
    height: 12px;
    background: #fff;
    border-right: 1px solid rgba(31, 41, 51, 0.12);
    border-bottom: 1px solid rgba(31, 41, 51, 0.12);
    transform: rotate(45deg);
}

.feature-popup.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* hover preview hugs its text and must never sit under the pointer */
.feature-popup--preview {
    width: auto;
    max-width: min(280px, calc(100% - 24px));
    padding: 9px 12px;
}

.feature-popup--preview.is-open {
    pointer-events: none;
}

.feature-popup.is-offscreen {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.feature-popup--below {
    transform: translateY(-6px) scale(0.97);
    transform-origin: var(--popup-origin-x) 0;
}

/* flip the pointer when JS places the popup below its feature */
.feature-popup--below::after {
    top: -7px;
    bottom: auto;
    border: 0;
    border-top: 1px solid rgba(31, 41, 51, 0.12);
    border-left: 1px solid rgba(31, 41, 51, 0.12);
}

.feature-popup--below.is-open {
    transform: translateY(0) scale(1);
}

.feature-popup__close {
    position: absolute;
    top: 7px;
    right: 7px;
    display: grid;
    width: 27px;
    height: 27px;
    padding: 0;
    place-items: center;
    color: #66717d;
    background: transparent;
    border: 0;
    border-radius: 50%;
    font: 21px/1 system-ui, sans-serif;
    cursor: pointer;
    transition: color 120ms ease, background-color 120ms ease;
}

.feature-popup__close:hover {
    color: #20252b;
    background: rgba(31, 41, 51, 0.07);
}

.feature-popup__close:focus-visible {
    outline: 2px solid #1a5f9e;
    outline-offset: 1px;
}

.cam-popup {
    font: 13px/1.4 system-ui, sans-serif;
}

.cam-popup strong {
    display: block;
    margin-bottom: 4px;
    padding-right: 24px;
    color: #17202a;
    font-size: 14px;
    line-height: 1.3;
}

.cam-meta {
    margin-bottom: 2px;
    color: #555;
}

.cam-thumb {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: 140px;
    object-fit: contain;
    margin: 8px 0;
    background: #e9edf0;
    border-radius: 4px;
}

.cam-popup a {
    display: inline-block;
    margin-top: 7px;
    color: #1a5f9e;
    font-weight: 600;
    text-decoration: none;
}

.cam-popup a:hover {
    text-decoration: underline;
}

@media (prefers-reduced-motion: reduce) {
    .feature-popup {
        transition: none;
    }
}
