.gallery .box,
figure {
    position: relative;
}

.gallery,
figure {
    overflow: hidden;
}

.gallery {
    margin: 10px auto;
    max-width: 768px;
}

.gallery .box {
    float: left;
    width: 100%;
    padding-bottom: 100%;
}

@media only screen and (min-width: 365px) {
    .gallery .box {
        width: 50%;
        padding-bottom: 50%;
    }
}

@media only screen and (min-width: 480px) {
    .gallery .box {
        width: 33.333%;
        padding-bottom: 33.333%;
    }
}

@media only screen and (min-width: 9999px) {
    .gallery .box {
        width: 25%;
        padding-bottom: 25%;
    }
}

.fancy-figure:not(.caption-effect-appear) figcaption,
.gallery.hover-effect-zoom .img,
.gallery.hover-transition figure,
.gallery:not(.caption-effect-appear) figcaption {
    -webkit-transition: .3s ease-in-out;
    -moz-transition: .3s ease-in-out;
    -o-transition: .3s ease-in-out;
    transition: .3s ease-in-out;
}

.gallery figure {
    position: absolute;
    left: 5px;
    right: 5px;
    top: 5px;
    bottom: 5px;
}

/* Keep gallery image links positioned inside their gallery tiles only. */
.gallery .img,
.gallery figure a {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
}

.gallery.hover-effect-grow figure:hover,
.gallery.hover-effect-zoom figure:hover .img {
    transform: scale(1.05);
}

.gallery.hover-effect-shrink figure:hover {
    transform: scale(.95);
}

.gallery.hover-effect-slidedown figure:hover {
    transform: translateY(5px);
}

.gallery.hover-effect-slideup figure:hover {
    transform: translateY(-5px);
}

.gallery .img {
    top: 0;
    background-size: cover;
    background-position: 50% 50%;
    background-repeat: no-repeat;
}

.fancy-figure.caption-position-none figcaption,
.gallery img,
.gallery.caption-position-none figcaption {
    display: none;
}

/* Keep this scoped to gallery links, not ordinary post-image links. */
.gallery figure a {
    top: 0;
}

.fancy-figure figcaption,
.gallery figcaption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, .5);
    color: #fff;
    text-align: center;
    font-size: 75%;
    opacity: 1;
    cursor: pointer;
}

.fancy-figure.caption-position-center figcaption,
.gallery.caption-position-center figcaption {
    top: 0;
    padding: 40% 5px;
}

.fancy-figure.caption-position-bottom figcaption,
.gallery.caption-position-bottom figcaption {
    padding: 5px;
}

.fancy-figure.caption-effect-appear figure:not(:hover) figcaption,
.fancy-figure.caption-effect-fade figure:not(:hover) figcaption,
.gallery.caption-effect-appear figure:not(:hover) figcaption,
.gallery.caption-effect-fade figure:not(:hover) figcaption {
    background: rgba(0, 0, 0, 0);
    opacity: 0;
}

.fancy-figure.caption-effect-slide.caption-position-bottom figure:not(:hover) figcaption,
.gallery.caption-effect-slide.caption-position-bottom figure:not(:hover) figcaption {
    margin-bottom: -100%;
}

.fancy-figure.caption-effect-slide.caption-position-center figure:not(:hover) figcaption,
.gallery.caption-effect-slide.caption-position-center figure:not(:hover) figcaption {
    top: 100%;
}

figcaption p {
    margin: auto;
}

/* Gallery column counts */
.gallery.gallery-columns-1 .box {
    width: 100%;
    padding-bottom: 100%;
}

.gallery.gallery-columns-2 .box {
    width: 50%;
    padding-bottom: 50%;
}

.gallery.gallery-columns-3 .box {
    width: 33.333%;
    padding-bottom: 33.333%;
}

.gallery.gallery-columns-4 .box {
    width: 25%;
    padding-bottom: 25%;
}

/* Generated galleries using direct Hugo figure shortcodes */
.gallery {
    clear: both;
}

.gallery > figure {
    position: relative;
    float: left;
    left: auto;
    right: auto;
    top: auto;
    bottom: auto;
    height: auto;
    padding: 5px;
    margin: 0;
    box-sizing: border-box;
}

/* Preserve configurable column counts */
.gallery.gallery-columns-1 > figure {
    width: 100%;
}

.gallery.gallery-columns-2 > figure {
    width: 50%;
}

.gallery.gallery-columns-3 > figure {
    width: 33.333%;
}

.gallery.gallery-columns-4 > figure {
    width: 25%;
}

/* Show images in generated galleries */
.gallery > figure img {
    display: block;
    width: 100%;
    height: auto;
}