/* ============================================================
   EMA - DYNAMIC MEDIA POPUPS
   Local, dependency-free, RTL/LTR and dark-mode ready
   ============================================================ */

.ema-dm-popup-root {
    position: fixed;
    inset: 0;
    z-index: 9800;
    pointer-events: none;
}

.ema-dm-popup-stack {
    position: fixed;
    bottom: 5.75rem;
    display: flex;
    flex-direction: column;
    gap: .85rem;
    width: min(100% - 2rem, 31rem);
    max-height: calc(100dvh - 8rem);
    pointer-events: none;
}

.ema-dm-popup-stack:empty,
.ema-dm-popup-stack:not(:has(.ema-dm-popup:not([hidden]))) {
    display: none;
}

.ema-dm-popup-stack-left {
    left: 1rem;
    align-items: flex-start;
}

.ema-dm-popup-stack-center {
    left: 50%;
    align-items: center;
    transform: translateX(-50%);
}

.ema-dm-popup-stack-right {
    right: 1rem;
    align-items: flex-end;
}

.ema-dm-popup[hidden] {
    display: none !important;
}

.ema-dm-popup {
    --ema-popup-gold: #c79a3b;
    --ema-popup-gold-light: #ead39a;
    --ema-popup-ink: #13283a;
    --ema-popup-muted: #5e6c77;
    --ema-popup-surface: rgba(255, 253, 247, .97);

    position: relative;
    width: 100%;
    max-height: min(72dvh, 42rem);
    overflow: hidden auto;
    border: 1px solid rgba(199, 154, 59, .42);
    border-radius: 1.15rem;
    background: var(--ema-popup-surface);
    color: var(--ema-popup-ink);
    box-shadow:
        0 1.5rem 4rem rgba(11, 22, 31, .22),
        0 .25rem 1rem rgba(11, 22, 31, .10),
        inset 0 1px 0 rgba(255, 255, 255, .9);
    opacity: 0;
    pointer-events: auto;
    transform: translateY(1.25rem) scale(.975);
    transform-origin: bottom center;
    transition:
        opacity .28s ease,
        transform .36s cubic-bezier(.22, 1, .36, 1),
        box-shadow .25s ease;
    scrollbar-width: thin;
    scrollbar-color: rgba(199, 154, 59, .65) transparent;
    isolation: isolate;
}

.ema-dm-popup::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    z-index: 4;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--ema-popup-gold), #f0daa2, var(--ema-popup-gold), transparent);
    pointer-events: none;
}

.ema-dm-popup::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(circle at 100% 0, rgba(226, 194, 120, .18), transparent 38%),
        linear-gradient(135deg, rgba(255, 255, 255, .64), transparent 50%);
    pointer-events: none;
}

.ema-dm-popup.is-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.ema-dm-popup.is-closing {
    opacity: 0;
    transform: translateY(.8rem) scale(.98);
    pointer-events: none;
}

.ema-dm-popup:hover {
    box-shadow:
        0 1.75rem 4.5rem rgba(11, 22, 31, .28),
        0 .35rem 1.1rem rgba(11, 22, 31, .12),
        inset 0 1px 0 rgba(255, 255, 255, .9);
}

.ema-dm-popup-small {
    width: min(100%, 20rem);
}

.ema-dm-popup-medium {
    width: min(100%, 25rem);
}

.ema-dm-popup-large {
    width: min(100%, 31rem);
}

.ema-dm-popup-close {
    position: absolute;
    top: .7rem;
    inset-inline-end: .7rem;
    z-index: 8;
    display: grid;
    width: 2.15rem;
    height: 2.15rem;
    padding: 0;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .58);
    border-radius: 50%;
    background: rgba(12, 23, 32, .76);
    color: #fff;
    box-shadow: 0 .35rem .85rem rgba(0, 0, 0, .18);
    cursor: pointer;
    transition: transform .2s ease, background-color .2s ease, border-color .2s ease;
}

.ema-dm-popup-close:hover {
    border-color: var(--ema-popup-gold-light);
    background: #162937;
    transform: rotate(90deg) scale(1.04);
}

.ema-dm-popup-close span {
    display: block;
    margin-top: -2px;
    font-size: 1.45rem;
    font-weight: 300;
    line-height: 1;
}

.ema-dm-popup-media,
.ema-dm-popup-media picture {
    display: block;
    width: 100%;
}

.ema-dm-popup-media {
    position: relative;
    overflow: hidden;
    background: #101820;
    aspect-ratio: 16 / 8.5;
}

.ema-dm-popup-image,
.ema-dm-popup-video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ema-dm-popup-image {
    transition: transform .55s cubic-bezier(.22, .61, .36, 1);
}

.ema-dm-popup:hover .ema-dm-popup-image {
    transform: scale(1.025);
}

.ema-dm-popup-content {
    position: relative;
    z-index: 2;
    padding: 1.15rem 1.25rem 1.25rem;
}

.ema-dm-popup:not(:has(.ema-dm-popup-media)) .ema-dm-popup-content {
    padding-top: 1.45rem;
    padding-inline-end: 3.5rem;
}

.ema-dm-popup-badge {
    display: inline-flex;
    min-height: 1.75rem;
    margin-bottom: .65rem;
    padding: .25rem .7rem;
    align-items: center;
    border: 1px solid rgba(199, 154, 59, .38);
    border-radius: 999px;
    background: rgba(199, 154, 59, .11);
    color: #936b17;
    font-size: .75rem;
    font-weight: 800;
    letter-spacing: .02em;
}

.ema-dm-popup-title {
    margin: 0;
    color: var(--ema-popup-ink);
    font-size: clamp(1.05rem, 2vw, 1.35rem);
    font-weight: 850;
    line-height: 1.4;
    text-wrap: balance;
}

.ema-dm-popup-subtitle {
    margin: .45rem 0 0;
    color: #8a651b;
    font-size: .92rem;
    font-weight: 750;
    line-height: 1.6;
}

.ema-dm-popup-description {
    display: -webkit-box;
    margin: .6rem 0 0;
    overflow: hidden;
    color: var(--ema-popup-muted);
    font-size: .88rem;
    line-height: 1.75;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
}

.ema-dm-popup-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem;
    margin-top: 1rem;
}

.ema-dm-popup-btn {
    display: inline-flex;
    min-height: 2.45rem;
    padding: .55rem 1rem;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: .65rem;
    font-size: .82rem;
    font-weight: 800;
    line-height: 1.2;
    text-decoration: none;
    transition: transform .2s ease, background-color .2s ease, border-color .2s ease;
}

.ema-dm-popup-btn:hover {
    transform: translateY(-2px);
}

.ema-dm-popup-btn-primary {
    background: linear-gradient(135deg, #e4c36f, #b98627);
    color: #182431;
    box-shadow: 0 .45rem 1rem rgba(185, 134, 39, .2);
}

.ema-dm-popup-btn-primary:hover {
    color: #101b24;
}

.ema-dm-popup-btn-secondary {
    border-color: rgba(19, 40, 58, .22);
    background: rgba(255, 255, 255, .52);
    color: var(--ema-popup-ink);
}

.ema-dm-popup-btn-secondary:hover {
    border-color: rgba(199, 154, 59, .65);
    color: var(--ema-popup-ink);
}

.ema-dm-popup-close:focus-visible,
.ema-dm-popup-btn:focus-visible {
    outline: 3px solid #d8b45d;
    outline-offset: 3px;
}

/* Global dark mode */
html[data-theme="dark"] .ema-dm-popup,
html[data-bs-theme="dark"] .ema-dm-popup,
html.dark .ema-dm-popup,
html.dark-mode .ema-dm-popup,
html.theme-dark .ema-dm-popup,
body[data-theme="dark"] .ema-dm-popup,
body[data-bs-theme="dark"] .ema-dm-popup,
body.dark .ema-dm-popup,
body.dark-mode .ema-dm-popup,
body.theme-dark .ema-dm-popup,
.dark-theme .ema-dm-popup {
    --ema-popup-ink: #f7f3e8;
    --ema-popup-muted: #c1c8ce;
    --ema-popup-surface: rgba(13, 24, 34, .97);
    border-color: rgba(213, 174, 82, .46);
    box-shadow:
        0 1.5rem 4rem rgba(0, 0, 0, .46),
        0 .25rem 1rem rgba(0, 0, 0, .3),
        inset 0 1px 0 rgba(255, 255, 255, .06);
}

html[data-theme="dark"] .ema-dm-popup-btn-secondary,
html[data-bs-theme="dark"] .ema-dm-popup-btn-secondary,
body.dark-theme .ema-dm-popup-btn-secondary,
.dark-theme .ema-dm-popup-btn-secondary {
    border-color: rgba(234, 211, 154, .32);
    background: rgba(255, 255, 255, .06);
}

@media (max-width: 767.98px) {
    .ema-dm-popup-root {
        inset: auto .65rem 5.4rem;
        display: flex;
        max-height: calc(100dvh - 7rem);
        flex-direction: column;
        gap: .65rem;
        overflow: visible;
    }

    .ema-dm-popup-stack,
    .ema-dm-popup-stack-left,
    .ema-dm-popup-stack-center,
    .ema-dm-popup-stack-right {
        position: static;
        display: flex;
        width: 100%;
        max-height: none;
        align-items: stretch;
        gap: .65rem;
        transform: none;
    }

    .ema-dm-popup-small,
    .ema-dm-popup-medium,
    .ema-dm-popup-large {
        width: 100%;
    }

    .ema-dm-popup {
        max-height: min(64dvh, 34rem);
        border-radius: 1rem;
    }

    .ema-dm-popup-media {
        aspect-ratio: 16 / 7.7;
    }

    .ema-dm-popup-content {
        padding: .95rem 1rem 1.05rem;
    }

    .ema-dm-popup-description {
        -webkit-line-clamp: 3;
    }
}

@media (max-width: 479.98px) {
    .ema-dm-popup-root {
        inset-inline: .45rem;
    }

    .ema-dm-popup-title {
        font-size: 1.03rem;
    }

    .ema-dm-popup-subtitle {
        font-size: .86rem;
    }

    .ema-dm-popup-description {
        font-size: .82rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ema-dm-popup,
    .ema-dm-popup-close,
    .ema-dm-popup-image,
    .ema-dm-popup-btn {
        transition: none !important;
    }
}
