/* Unified media viewer (Neo theme). RTL-first, responsive. */
.mv {
    --mv-radius: var(--neo-radius);
    display: grid;
    gap: 1.25rem;
    font-family: var(--font-iransans);
}

.mv > * {
    min-width: 0;
}

@media (min-width: 1024px) {
    .mv {
        grid-template-columns: minmax(0, 1fr) 19rem;
        align-items: start;
    }
}

/* ---------- Stage ---------- */
.mv-viewport {
    position: relative;
    aspect-ratio: 4 / 3;
    background: var(--neo-surface-soft);
    overflow: hidden;
    outline-offset: -2px;
}

@media (min-width: 640px) {
    .mv-viewport {
        aspect-ratio: 16 / 10;
    }
}

.mv-viewport:focus-visible {
    outline: 3px solid var(--neo-accent);
    outline-offset: 3px;
}

.mv-skeleton {
    position: absolute;
    inset: 0;
    background: color-mix(in oklab, var(--neo-primary) 8%, transparent);
    background-size: 200% 100%;
    animation: mv-shimmer 1.4s linear infinite;
    pointer-events: none;
}

.mv-viewport.is-loaded .mv-skeleton {
    display: none;
}

@keyframes mv-shimmer {
    from {
        background-position: 180% 0;
    }
    to {
        background-position: -80% 0;
    }
}

.mv-media {
    position: relative;
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

video.mv-media {
    background: var(--neo-ink);
}

.mv-nav,
.mv-expand {
    position: absolute;
    top: 50%;
    translate: 0 -50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--neo-radius);
    background: var(--neo-surface);
    border: var(--neo-border) solid var(--neo-ink);
    box-shadow: var(--neo-shadow-small);
    backdrop-filter: blur(6px);
    transition: transform 0.16s ease, background 0.16s ease;
    z-index: 2;
}

.mv-nav {
    width: 2.25rem;
    height: 2.25rem;
    font-size: 1.3rem;
}

.mv-nav:hover,
.mv-expand:hover {
    transform: scale(1.07);
}

.mv-prev {
    inset-inline-start: 0.75rem;
}

.mv-next {
    inset-inline-end: 0.75rem;
}

.mv-expand {
    top: auto;
    bottom: 0.75rem;
    inset-inline-end: 0.75rem;
    translate: none;
    width: 2rem;
    height: 2rem;
    font-size: 1.05rem;
}

.mv-countbadge {
    position: absolute;
    bottom: 0.75rem;
    inset-inline-start: 0.75rem;
    z-index: 2;
}

.mv-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-top: var(--neo-border) solid var(--neo-ink);
}

.mv-bar > * {
    min-width: 0;
}

.mv-kicker {
    font-size: 0.7rem;
    font-weight: 700;
    opacity: 0.5;
}

.mv-title {
    margin-top: 0.15rem;
    font-weight: 900;
    font-size: 1.15rem;
    line-height: 1.8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mv-caption {
    margin-top: 0.15rem;
    font-size: 0.8rem;
    opacity: 0.6;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mv-actions {
    display: flex;
    flex-shrink: 0;
    gap: 0.5rem;
}

@media (max-width: 639px) {
    .mv-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .mv-actions {
        width: 100%;
    }
    .mv-actions > * {
        flex: 1 1 0;
    }
}

/* ---------- Filmstrip ---------- */
.mv-stripwrap {
    padding: 1rem;
}

.mv-striphead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
}

.mv-striptitle {
    font-weight: 900;
}

.mv-stripicon {
    font-size: 1.2rem;
    color: var(--neo-primary);
}

.mv-strip {
    display: flex;
    gap: 0.65rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
}

@media (min-width: 1024px) {
    .mv-strip {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        max-height: 30rem;
        overflow-y: auto;
        overflow-x: hidden;
    }
}

.mv-thumb {
    position: relative;
    flex: 0 0 6.5rem;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: var(--neo-radius);
    border: var(--neo-border) solid transparent;
    background: var(--neo-surface-soft);
    scroll-snap-align: start;
    transition: border-color 0.16s ease, transform 0.16s ease;
}

.mv-thumb:hover {
    transform: translateY(-2px);
}

.mv-thumb.is-active {
    border-color: var(--neo-primary);
    box-shadow: var(--neo-shadow-small);
}

.mv-thumbimg {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.72;
    transition: opacity 0.16s ease;
}

.mv-thumb:hover .mv-thumbimg,
.mv-thumb.is-active .mv-thumbimg {
    opacity: 1;
}

.mv-play {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: var(--color-primary-content);
    text-shadow: var(--neo-shadow-small);
    pointer-events: none;
}

.mv-thumbcap {
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    padding: 0.2rem 0.4rem;
    font-size: 0.62rem;
    font-weight: 700;
    text-align: start;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--neo-surface);
    background: color-mix(in oklab, var(--neo-ink) 60%, transparent);
    pointer-events: none;
}

/* ---------- Lightbox ---------- */
.mv-lightbox[hidden] {
    display: none;
}

/* Portaled to <body> on init (see media-viewer.js): escapes main's stacking
 * context (main has z-index:1) so header/footer can never paint above it.
 * Layer order: site chrome (<=9999) < lightbox (60000) < toasts (70000). */
.mv-lightbox {
    position: fixed;
    inset: 0;
    z-index: 60000;
}

.mv-lb-backdrop {
    position: absolute;
    inset: 0;
    background: color-mix(in oklab, var(--neo-ink) 92%, transparent);
}

.mv-lb-box {
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 3.5rem 1rem 1rem;
}

.mv-lb-mediawrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    max-width: min(72rem, 100%);
    width: 100%;
    flex: 1 1 auto;
    overflow: auto;
}

.mv-lb-mediawrap img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--neo-radius);
    cursor: zoom-in;
}

.mv-lb-mediawrap.is-zoomed img {
    max-width: none;
    width: 160%;
    max-height: none;
    cursor: zoom-out;
}

.mv-lb-mediawrap video {
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--neo-radius);
    background: var(--neo-ink);
}

.mv-lb-foot {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    color: var(--neo-surface);
    max-width: 100%;
    min-width: 0;
}

.mv-lb-count {
    font-size: 0.8rem;
    opacity: 0.7;
    white-space: nowrap;
}

.mv-lb-title {
    font-weight: 900;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.mv-lb-tools {
    position: absolute;
    top: 0.9rem;
    inset-inline-end: 0.9rem;
    display: flex;
    gap: 0.5rem;
}

.mv-lb-btn {
    background: var(--neo-surface);
    border: var(--neo-border) solid var(--neo-ink);
    color: var(--neo-text);
    box-shadow: var(--neo-shadow-small);
}

.mv-lb-btn:hover {
    background: var(--neo-accent);
    color: var(--neo-ink);
}

.mv-lb-nav {
    position: absolute;
    top: 50%;
    translate: 0 -50%;
    background: var(--neo-surface);
    border: var(--neo-border) solid var(--neo-ink);
    color: var(--neo-text);
    box-shadow: var(--neo-shadow-small);
}

.mv-lb-prev {
    inset-inline-start: 0.75rem;
}

.mv-lb-next {
    inset-inline-end: 0.75rem;
}

@media (max-width: 639px) {
    .mv-lb-nav {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mv-skeleton {
        animation: none;
    }
    .mv-thumb,
    .mv-nav,
    .mv-expand {
        transition: none;
    }
}
