/* MSW Gallery TAG 1.1.1 */
.mod-mswtaggallery {
    display: inline-flex;
    max-width: 100%;
    flex-direction: column;
    align-items: center;
    gap: .32rem;
    vertical-align: middle;
}

.mod-mswtaggallery-align-left {
    align-items: flex-start;
    text-align: left;
}

.mod-mswtaggallery-align-center {
    align-items: center;
    text-align: center;
}

.mod-mswtaggallery-align-right {
    align-items: flex-end;
    text-align: right;
}

.mod-mswtaggallery-button,
.mod-mswtaggallery-icon,
.msw-mtg-item,
.msw-mtg-close {
    cursor: pointer;
}

.mod-mswtaggallery-button {
    max-width: 100%;
    white-space: nowrap;
}

.mod-mswtaggallery-icons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--msw-mtg-icon-gap, 6px);
    margin: 0;
    padding: 0;
    line-height: 1;
}

.mod-mswtaggallery-align-left .mod-mswtaggallery-icons {
    justify-content: flex-start;
}

.mod-mswtaggallery-align-right .mod-mswtaggallery-icons {
    justify-content: flex-end;
}

.mod-mswtaggallery-icon {
    display: inline-flex;
    width: calc(var(--msw-mtg-icon-size, 24px) + 6px);
    height: calc(var(--msw-mtg-icon-size, 24px) + 6px);
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: #666;
    text-decoration: none;
}

.mod-mswtaggallery-icon svg {
    display: block;
    width: var(--msw-mtg-icon-size, 24px);
    height: var(--msw-mtg-icon-size, 24px);
    overflow: visible;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.65;
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
}

.mod-mswtaggallery-icon {
    transition: color .22s ease, transform .22s ease, filter .22s ease;
    transform-origin: center;
}

.mod-mswtaggallery-icon-mask {
    display: block;
    width: var(--msw-mtg-icon-size, 24px);
    height: var(--msw-mtg-icon-size, 24px);
    color: inherit;
    pointer-events: none;
}

.mod-mswtaggallery-icon-mask img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    margin: 0;
    border: 0;
    object-fit: contain;
    pointer-events: none;
}

/* Colora Auto e Moto tramite la loro trasparenza. La classe viene aggiunta dal JS
   solo quando il browser conferma il supporto alle maschere CSS. */
.msw-mtg-mask-supported .mod-mswtaggallery-icon-mask {
    background-color: currentColor;
    -webkit-mask-image: var(--msw-mtg-icon-image);
    mask-image: var(--msw-mtg-icon-image);
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-size: contain;
    mask-size: contain;
}

.msw-mtg-mask-supported .mod-mswtaggallery-icon-mask img {
    opacity: 0;
}

/* Le immagini Auto e Moto sono gli stessi disegni preparati come PNG. */
.mod-mswtaggallery-icon-auto {
    width: calc(var(--msw-mtg-icon-size, 24px) * 1.7 + 6px);
}

.mod-mswtaggallery-icon-auto .mod-mswtaggallery-icon-mask {
    width: calc(var(--msw-mtg-icon-size, 24px) * 1.7);
    height: var(--msw-mtg-icon-size, 24px);
}

.mod-mswtaggallery-icon-moto {
    width: calc(var(--msw-mtg-icon-size, 24px) * 1.42 + 6px);
}

.mod-mswtaggallery-icon-moto .mod-mswtaggallery-icon-mask {
    width: calc(var(--msw-mtg-icon-size, 24px) * 1.42);
    height: var(--msw-mtg-icon-size, 24px);
}

.mod-mswtaggallery-icon:hover,
.mod-mswtaggallery-icon:focus-visible {
    color: var(--cassiopeia-color-primary, var(--bs-primary, #c93636)) !important;
    background: transparent;
    box-shadow: none;
    text-decoration: none;
    transform: scale(1.10);
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .16));
}

.mod-mswtaggallery-icon:hover svg,
.mod-mswtaggallery-icon:focus-visible svg {
    stroke: currentColor !important;
}

/* Fallback hover/focus per i PNG Auto e Moto quando le CSS mask non sono disponibili. */
html:not(.msw-mtg-mask-supported) .mod-mswtaggallery-icon:hover .mod-mswtaggallery-icon-mask img,
html:not(.msw-mtg-mask-supported) .mod-mswtaggallery-icon:focus-visible .mod-mswtaggallery-icon-mask img {
    filter: brightness(0) saturate(100%) invert(24%) sepia(92%) saturate(2511%) hue-rotate(346deg) brightness(90%) contrast(91%) !important;
}

/* Sequenza continua condivisa: icone rosse, una sola voce alla volta.
   La stessa classe viene usata dal plugin per alternare anche Indietro e Avanti. */
.mod-mswtaggallery-icon.msw-attention-active {
    color: var(--cassiopeia-color-primary, var(--bs-primary, #c93636)) !important;
    transform: scale(1.14);
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .18));
}

.mod-mswtaggallery-icon.msw-attention-active svg {
    stroke: currentColor !important;
}

/* Fallback per browser senza CSS mask: colora realmente i PNG in rosso. */
html:not(.msw-mtg-mask-supported) .mod-mswtaggallery-icon.msw-attention-active .mod-mswtaggallery-icon-mask img {
    filter: brightness(0) saturate(100%) invert(24%) sepia(92%) saturate(2511%) hue-rotate(346deg) brightness(90%) contrast(91%) !important;
}

.mod-mswtaggallery-icon:focus-visible {
    outline: 1px dotted currentColor;
    outline-offset: 2px;
}

html.msw-mtg-open,
body.msw-mtg-open {
    overflow: hidden;
}

.msw-mtg-overlay[hidden] {
    display: none !important;
}

.msw-mtg-overlay {
    position: fixed;
    inset: 0;
    z-index: 100100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: rgba(0, 0, 0, .72);
}

.msw-mtg-panel {
    box-sizing: border-box;
    width: auto;
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    margin: auto;
    padding: 0 14px 14px;
    overflow: auto;
    overscroll-behavior: contain;
    border-radius: 5px;
    background: #fff;
    box-shadow: 0 14px 45px rgba(0, 0, 0, .38);
}

.msw-mtg-header {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 48px;
    margin-bottom: 12px;
    padding: 8px 0;
    border-bottom: 1px solid #d7d7d7;
    background: #fff;
}

.msw-mtg-title {
    min-width: 0;
    margin: 0;
    color: #4d4d4d;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.msw-mtg-close {
    flex: 0 0 auto;
    min-height: 30px;
    padding: .28rem .7rem;
    border: 1px solid #777;
    border-radius: 3px;
    background: #f4f4f4;
    color: #222;
    font-size: .82rem;
    line-height: 1.1;
}

.msw-mtg-close:hover,
.msw-mtg-close:focus-visible {
    background: #e7e7e7;
}

.msw-mtg-close:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.msw-mtg-grid {
    box-sizing: border-box;
    display: flex;
    width: auto;
    max-width: 100%;
    flex-wrap: wrap;
    align-items: flex-start;
    align-content: flex-start;
    justify-content: center;
    gap: 12px;
    margin-inline: auto;
    padding: 0;
}

.msw-mtg-item {
    position: relative;
    box-sizing: border-box;
    display: block;
    flex: 0 0 var(--msw-mtg-thumb-width, 250px);
    width: var(--msw-mtg-thumb-width, 250px);
    max-width: 100%;
    margin: 0;
    overflow: hidden;
    border-radius: 4px;
    background: #eee;
    color: inherit;
    text-decoration: none;
}

.msw-mtg-item img {
    display: block;
    width: 100%;
    height: auto;
    margin: 0;
    border: 0;
    object-fit: contain;
}

.msw-mtg-item:hover,
.msw-mtg-item:focus-visible {
    outline: 2px solid #333;
    outline-offset: 2px;
}

.msw-mtg-empty {
    flex: 1 0 100%;
    margin: 1rem;
    text-align: center;
}

.msw-mtg-click-hand {
    position: absolute;
    right: 7px;
    bottom: 6px;
    z-index: 2;
    display: block;
    width: 72px;
    height: 72px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #fff;
    pointer-events: none;
    transform: rotate(-45deg);
    transform-origin: 50% 70%;
    filter:
        drop-shadow(1px 1px 0 rgba(0, 0, 0, .95))
        drop-shadow(-1px -1px 0 rgba(0, 0, 0, .72))
        drop-shadow(0 2px 3px rgba(0, 0, 0, .55));
    animation: msw-mtg-hand-tap 1.15s ease-in-out infinite;
}

.msw-mtg-click-hand svg {
    display: block;
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

@keyframes msw-mtg-hand-tap {
    0%, 100% { transform: translate3d(0, 0, 0) rotate(-45deg) scale(1); }
    45% { transform: translate3d(-4px, -6px, 0) rotate(-45deg) scale(.94); }
    70% { transform: translate3d(0, 0, 0) rotate(-45deg) scale(1.03); }
}

@media (prefers-reduced-motion: reduce) {
    .msw-mtg-click-hand {
        animation: none;
    }

    .mod-mswtaggallery-icon {
        transition: none;
    }

    .mod-mswtaggallery-icon.msw-attention-active {
        transform: none;
        filter: none;
    }
}

@media (max-width: 767.98px) {
    .mod-mswtaggallery {
        gap: .28rem;
    }

    .mod-mswtaggallery-icons {
        gap: var(--msw-mtg-icon-gap, 6px);
    }

    .mod-mswtaggallery-icon {
        width: calc(var(--msw-mtg-icon-size-mobile, 20px) + 6px);
        height: calc(var(--msw-mtg-icon-size-mobile, 20px) + 6px);
    }

    .mod-mswtaggallery-icon svg {
        width: var(--msw-mtg-icon-size-mobile, 20px);
        height: var(--msw-mtg-icon-size-mobile, 20px);
        stroke-width: 1.75;
    }


    .mod-mswtaggallery-icon-auto {
        width: calc(var(--msw-mtg-icon-size-mobile, 20px) * 1.7 + 6px);
    }

    .mod-mswtaggallery-icon-auto .mod-mswtaggallery-icon-mask {
        width: calc(var(--msw-mtg-icon-size-mobile, 20px) * 1.7);
        height: var(--msw-mtg-icon-size-mobile, 20px);
    }

    .mod-mswtaggallery-icon-moto {
        width: calc(var(--msw-mtg-icon-size-mobile, 20px) * 1.42 + 6px);
    }

    .mod-mswtaggallery-icon-moto .mod-mswtaggallery-icon-mask {
        width: calc(var(--msw-mtg-icon-size-mobile, 20px) * 1.42);
        height: var(--msw-mtg-icon-size-mobile, 20px);
    }

    .msw-mtg-overlay {
        padding: 4px;
    }

    .msw-mtg-panel {
        width: calc(100vw - 8px);
        max-width: calc(100vw - 8px);
        max-height: calc(100vh - 8px);
        padding: 0 5px 7px;
        border-radius: 2px;
    }

    .msw-mtg-header {
        min-height: 40px;
        margin-bottom: 5px;
        padding: 5px 2px;
    }

    .msw-mtg-title {
        font-size: .86rem;
    }

    .msw-mtg-close {
        min-height: 27px;
        padding: .2rem .48rem;
        font-size: .74rem;
    }

    .msw-mtg-grid {
        width: 100% !important;
        gap: 4px;
    }

    .msw-mtg-item {
        flex: 0 0 var(--msw-mtg-mobile-basis, calc(16.666667% - 3.333333px));
        width: var(--msw-mtg-mobile-basis, calc(16.666667% - 3.333333px));
        max-width: none;
        border-radius: 1px;
    }

    .msw-mtg-click-hand {
        right: 2px;
        bottom: 2px;
        width: 48px;
        height: 48px;
    }
}
