.mg-container,
.mg-container *,
.mg-modal-overlay,
.mg-modal-overlay * {
    box-sizing: border-box;
}

.mg-container {
    width: 100%;
    max-width: 100%;
    background: transparent;
    padding: 0;
    margin: 0;
    font-family: sans-serif;
}

.mg-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: rgba(0, 0, 0, 0.3);
    overflow: hidden;
    border-radius: 6px;
    margin-bottom: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.mg-main-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
    display: block;
    box-sizing: border-box;
    transition: opacity 0.2s ease-in-out;
    z-index: 1;
}

.mg-main-image.mg-visible {
    opacity: 1;
    z-index: 1;
}

.mg-main-image.mg-hidden {
    opacity: 0;
    z-index: 0;
    pointer-events: none;
}

.mg-iframe-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    display: none;
    /* Hidden by default */
}

.mg-iframe-container.active {
    display: block;
}

.mg-iframe-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* Modal specific overrides */
.mg-modal-gallery .mg-iframe-container {
    position: static;
    grid-area: 1 / 1;
    width: 100%;
    height: 100%;
    display: none;
    align-items: center;
    justify-content: center;
}

.mg-modal-gallery .mg-iframe-container.active {
    display: flex;
}

.mg-modal-gallery .mg-iframe-container iframe {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    max-height: 85vh;
    max-width: 151.1vh;
    /* 85vh * 16/9 */
    margin: 0 auto;
}

.mg-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border: none;
    padding: 15px 12px;
    font-size: 20px;
    cursor: pointer;
    z-index: 10;
    transition: background 0.2s, transform 0.1s;
    user-select: none;
    line-height: 1;
}

.mg-nav-btn:hover {
    background: rgba(0, 0, 0, 0.9);
}

.mg-nav-btn:active {
    transform: translateY(-50%) scale(0.95);
}

.mg-nav-btn.mg-prev {
    left: 0;
    border-radius: 4px;
}

.mg-nav-btn.mg-next {
    right: 0px;
    border-radius: 4px;
}

.mg-thumbs-row {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding: 3px 0 10px 0;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: #4a5b6c #1b2838;
}

.mg-thumbs-row::-webkit-scrollbar {
    height: 8px;
}

.mg-thumbs-row::-webkit-scrollbar-track {
    background: #1b2838;
    border-radius: 4px;
}

.mg-thumbs-row::-webkit-scrollbar-thumb {
    background-color: #4a5b6c;
    border-radius: 4px;
}

.mg-thumbs-row::-webkit-scrollbar-thumb:hover {
    background-color: #66c0f4;
}

.mg-thumb {
    width: 110px;
    height: 65px;
    object-fit: cover;
    flex-shrink: 0;
    cursor: pointer;
    border-radius: 0;
    border: 2px solid transparent;
    transition: all 0.2s;
    opacity: 1;
    background: #000;
}

.mg-thumb:hover {
    opacity: 1;
    border-color: rgba(255, 255, 255, 0.3);
}

.mg-thumb.mg-active {
    border-color: #fff;
    opacity: 1;
    transform: translateY(-2px);
}

.mg-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    height: 100%;
    background: rgba(14, 19, 27, 0.95);
    z-index: 9999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 0;
    margin: 0;
    backdrop-filter: blur(5px);
}

.mg-modal-overlay.mg-open {
    display: flex;
}

.mg-modal-close-btn {
    position: absolute;
    top: 20px;
    right: 30px;
    background: none;
    border: none;
    color: #8a9ba8;
    font-size: 40px;
    cursor: pointer;
    z-index: 10000;
    line-height: 1;
    transition: color 0.2s;
}

.mg-modal-close-btn:hover {
    color: #fff;
}

.mg-modal-gallery {
    width: 100%;
    max-width: 98vw;
    height: 96vh;
    display: flex;
    flex-direction: column;
    box-shadow: none;
    pointer-events: none;
}

.mg-modal-gallery .mg-stage {
    flex-grow: 1;
    cursor: default;
    background: transparent;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 0 !important;
}

.mg-gallery-wrapper {
    display: flex;
    align-items: stretch;
    justify-content: center;
    max-width: 100%;
    max-height: 100%;
    pointer-events: auto;
}

.mg-modal-gallery .mg-nav-btn {
    position: static;
    transform: none;
    width: 25px;
    /* Narrower buttons */
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    padding: 0;
    font-size: 24px;
    height: auto;
    z-index: 10;
    transition: background 0.2s;
    border-radius: 0;
}

.mg-modal-gallery .mg-nav-btn:hover {
    background: rgba(0, 0, 0, 0.8);
}

.mg-modal-gallery .mg-nav-btn.mg-prev {
    border-radius: 4px;
}

.mg-modal-gallery .mg-nav-btn.mg-next {
    border-radius: 8px;
}

.mg-image-stack {
    display: grid;
    position: relative;
    max-height: 100%;
    width: 100%;
    min-width: 0;
    flex: 1;
    /* Center the content so if standard stretch makes it tall, content floats in middle */
    align-items: center;
    justify-items: center;
}

.mg-modal-gallery .mg-main-image {
    position: static;
    grid-area: 1 / 1;
    width: 100%;
    height: 100%;
    max-height: 85vh;
    max-width: 100%;
    object-fit: contain;
    display: block;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}


.mg-modal-gallery .mg-thumbs-row {
    justify-content: center;
    margin-top: 5px;
    flex-shrink: 0;
    pointer-events: auto;
}

.mg-modal-overlay div {
    box-sizing: border-box;
}