:root {
    --container-padding: 1em;
    --gallery-gap: 0.5em;
    --gallery-items-per-row: 1;
    --gallery-item-border-radius: 0.4em;
    --gallery-caption-bg-color: hsl(0 0% 0% / 90%);
    --gallery-caption-text-color: white;
    --control-button-bg: rgba(0, 0, 0, 0.6);
    --control-button-color: white;
    --control-button-hover-bg: rgba(255, 0, 0, 0.8);
    --control-button-size: 30px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

.d4-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gallery-gap);
    width: 100%
}

.d4-gallery img {
    max-width: 100%;
    height: auto;
    vertical-align: middle;
    border-radius: var(--gallery-item-border-radius);
    aspect-ratio: 3 / 2;
    object-fit: cover;
}

.d4-gallery .g-item {
    position: relative;
    overflow: hidden;
    border-radius: var(--gallery-item-border-radius);
    flex: 0 0 calc(
            (100% - (var(--gallery-gap) * (var(--gallery-items-per-row) - 1))) /
            var(--gallery-items-per-row)
    );
    min-width: 24%;
}

.d4-gallery .g-item figure {
    margin: 0;
}

.d4-gallery .g-item .title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.d4-gallery .g-item-title {
    position: absolute;
    width: 100%;
    left: 0;
    top: 0;
    background: linear-gradient(180deg,rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0) 100%);
    padding: 10px;
    display: flex;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    justify-content: space-evenly;
}

.d4-gallery .g-item:hover .g-item-title {
    opacity: 1;
    pointer-events: auto;
}

.d4-gallery .g-item-title-text {
    color: rgb(255 255 255 / 65%);
}

.d4-gallery .g-item-controls {
    position: absolute;
    width: 100%;
    left: 0;
    bottom: 0;
    background: linear-gradient(0deg,rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0) 100%);
    padding: 10px;
    display: flex;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    justify-content: space-evenly;
}

.d4-gallery .g-item-controls i {
    font-size: 12px;
}

.d4-gallery .g-item:hover .g-item-controls {
    opacity: 1;
    pointer-events: auto;
}

.d4-gallery .g-item-controls .control-button {
    width: var(--control-button-size);
    height: var(--control-button-size);
    background: var(--control-button-bg);
    color: var(--control-button-color);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.3s ease;
}

.d4-gallery .g-item-controls .control-button:hover {
    background: var(--control-button-hover-bg);
}

.d4-gallery .g-item.g-item-add {
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px dashed #ccc;
    padding: 4rem;
    cursor: pointer;
    background: #ffffff;
    background-position: center center;
    background-repeat: no-repeat;
    max-width: 100%;
    height: auto;
    vertical-align: middle;
    border-radius: var(--gallery-item-border-radius);
    aspect-ratio: 3 / 2;
    object-fit: cover;
    flex-direction: column;
    gap: 0.5rem;
    color: #666666;
    transition: 0.3s ease;
}

.d4-gallery .g-item.g-item-add:hover i {
    color: #405189;
}

.g-item.uploading figure {
    position: relative;
}

.g-item.uploading figure .overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* Grey overlay with 50% transparency */
    pointer-events: none; /* Allow interaction with underlying elements if needed */
    z-index: 1; /* Ensures the overlay is above the content */
}

/* Responsive adjustments */
@media (min-width: 1024px) {
    :root {
        --gallery-items-per-row: 4;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    :root {
        --gallery-items-per-row: 3;
    }
}

@media (min-width: 540px) and (max-width: 767px) {
    :root {
        --gallery-items-per-row: 2;
    }
}
