.gallery {
    --gallery-cols: 2;
    --gallery-gap: 15px;
    padding: var(--gallery-gap);
    column-gap: var(--gallery-gap);
    column-count: var(--gallery-cols);
    min-height: 70vh;
    position: relative;
}

.gallery[data-size="small"] {
    --gallery-cols: 2;
}

.gallery[data-size="medium"] {
    --gallery-cols: 2;
}

.gallery[data-size="large"] {
    --gallery-cols: 1;
}

.gallery.gallery-flow-rows {
    display: block;
    column-count: auto;
    column-gap: 0;
}

.gallery.gallery-flow-rows .gallery-masonry-section {
    display: grid;
    grid-template-columns: repeat(var(--gallery-cols), minmax(0, 1fr));
    grid-auto-flow: row dense;
    grid-auto-rows: 10px;
    gap: 10px;
    align-items: start;
    margin-bottom: 10px;
}

.gallery.gallery-flow-rows .gallery-masonry-section:last-of-type {
    margin-bottom: 0;
}

.gallery.gallery-flow-rows .image-container,
.gallery.gallery-flow-rows .skeleton-card {
    margin-bottom: 0;
    width: 100%;
    align-self: start;
    height: auto;
}

.gallery.gallery-flow-rows .gallery-date-header,
.gallery.gallery-flow-rows .gallery-match-header,
.gallery.gallery-flow-rows .gallery-load-more-hint {
    display: block;
    width: 100%;
}

.gallery.gallery-flow-rows .gallery-load-more-hint {
    margin-top: 4px;
}

@media (min-width: 600px) {
    .gallery[data-size="small"] {
        --gallery-cols: 4;
    }

    .gallery[data-size="medium"] {
        --gallery-cols: 3;
    }

    .gallery[data-size="large"] {
        --gallery-cols: 2;
    }
}

@media (min-width: 1000px) {
    .gallery[data-size="small"] {
        --gallery-cols: 6;
    }

    .gallery[data-size="medium"] {
        --gallery-cols: 4;
    }

    .gallery[data-size="large"] {
        --gallery-cols: 3;
    }
}

@media (min-width: 1600px) {
    .gallery[data-size="small"] {
        --gallery-cols: 8;
    }

    .gallery[data-size="medium"] {
        --gallery-cols: 6;
    }

    .gallery[data-size="large"] {
        --gallery-cols: 4;
    }
}

.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-muted);
    font-size: 22px;
    text-align: center;
    width: 100%;
    height: 60vh;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    background:
        radial-gradient(circle 16vh at calc(50% - 3vh) calc(50% - 12vh), rgba(255, 71, 87, 0.25) 0%, transparent 100%),
        radial-gradient(circle 16vh at calc(50% + 12vh) calc(50% - 3vh), rgba(46, 213, 115, 0.25) 0%, transparent 100%),
        radial-gradient(circle 16vh at calc(50% + 3vh) calc(50% + 12vh), rgba(30, 144, 255, 0.25) 0%, transparent 100%),
        radial-gradient(circle 16vh at calc(50% - 12vh) calc(50% + 3vh), rgba(255, 165, 2, 0.25) 0%, transparent 100%);
}

.not-found-container {
    column-span: all;
    width: 100%;
    text-align: center;
    padding: 40px 20px;
    background: radial-gradient(circle at center, var(--surface-hover) 0%, var(--surface) 100%);
    border-radius: 10px;
    border: 1px solid var(--border);
    margin-bottom: 20px;
    box-sizing: border-box;
}

.skeleton-card {
    background: var(--surface);
    border-radius: 10px;
    height: 250px;
    margin-bottom: var(--gallery-gap, 15px);
    break-inside: avoid;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
    opacity: 0.7;
    width: 100%;
}

.skeleton-card[style*="aspect-ratio"] {
    height: auto;
}

@keyframes skeleton-pulse {
    0% {
        background: var(--surface);
    }

    50% {
        background: var(--surface-hover);
    }

    100% {
        background: var(--surface);
    }
}

.gallery-date-header {
    column-span: all;
    width: 100%;
    border-bottom: 1px solid var(--border);
    margin: 35px 0 15px;
    padding-bottom: 8px;
    color: #9ca3af;
    font-size: 0.95em;
    display: flex;
    align-items: center;
    break-inside: avoid;
    letter-spacing: 0.5px;
}

.gallery-date-header:first-child {
    margin-top: 5px;
}

.gallery-match-header {
    column-span: all;
    width: 100%;
    margin: 25px 0 15px;
    padding-bottom: 8px;
    color: #9ca3af;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    break-inside: avoid;
    border-bottom: 1px dashed var(--border);
}

.gallery-match-header.exact {
    color: var(--accent);
    border-bottom: 1px solid var(--accent);
}

.gallery-load-more-hint {
    column-span: all;
    width: 100%;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    padding: 18px 0 8px;
    break-inside: avoid;
}

.image-container {
    break-inside: avoid;
    margin-bottom: var(--gallery-gap, 15px);
    position: relative;
    cursor: pointer;
    border-radius: 10px;
    overflow: hidden;
    background: var(--surface);
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94), transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    height: auto !important;
}

.image-container.menu-open {
    overflow: visible !important;
    z-index: 50;
}

.image-container.menu-open img,
.image-container.menu-open .hover-overlay {
    border-radius: 10px;
}

.image-container.reveal {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94), 
                transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

@media (hover: hover) {
    .image-container.reveal:hover {
        transform: translateY(-2px);
        box-shadow: 0 16px 32px var(--shadow);
        z-index: 2;
    }
}

.image-container.removing {
    transform: scale(0.5);
    opacity: 0;
    margin-bottom: 0 !important;
    transition: all 0.4s ease-out;
}

.image-container img {
    display: block;
    width: 100%;
    height: auto !important;
    aspect-ratio: auto !important;
    transition: transform 0.6s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.5s ease-out;
    opacity: 0;
}

.image-container img.loaded {
    opacity: 1;
}

@media (hover: hover) {
    .image-container:hover img {
        transform: scale(1.02);
    }
}

.image-container.is-new::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 10px;
    border: 2px solid var(--accent);
    pointer-events: none;
    z-index: 2;
}

.highlight-just-uploaded::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 10px;
    border: 2px solid var(--accent);
    pointer-events: none;
    z-index: 20;
    opacity: 1;
    transition: opacity 1s ease-out;
}

.highlight-just-uploaded.fading::after {
    opacity: 0;
}

.new-images-separator {
    column-span: all;
    width: 100%;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    padding: 10px 0;
    margin: 10px 0 40px;
    border: none;
    background: transparent;
    break-inside: avoid;
    transition: opacity 0.4s ease, transform 0.4s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.new-images-separator::before,
.new-images-separator::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border);
    margin: 0 15px;
}

.hover-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, transparent 60%);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.4s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 15px;
    color: white;
}

@media (hover: hover) {
    .image-container:hover .hover-overlay {
        opacity: 1;
        transform: scale(1.03);
    }
}

.image-container.menu-open .hover-overlay {
    opacity: 1;
    transform: scale(1.03);
    z-index: 10;
}

.fav-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 22px;
    height: 22px;
    cursor: pointer;
    z-index: 5;
    transition: 0.2s;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.8));
}

@media (hover: hover) {
    .fav-btn:hover {
        transform: scale(1.15);
    }

    .image-container:hover .fav-btn {
        opacity: 1;
    }
}

@keyframes heart-pop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.35);
    }

    100% {
        transform: scale(1);
    }
}

.fav-btn svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: white;
    stroke-width: 2;
    transition: all 0.3s;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

.fav-btn.is-fav svg {
    fill: var(--fav);
    stroke: var(--fav);
    animation: heart-pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ba-badge {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 6px;
    border-radius: 50%;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    pointer-events: auto;
    transition: 0.3s;
    opacity: 1;
}

.ba-badge svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.private-badge {
    position: absolute;
    top: 12px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 6px;
    border-radius: 50%;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: 0.3s;
    opacity: 1;
}

.private-badge svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.menu-dots {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 24px;
    cursor: pointer;
    padding: 0 10px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    z-index: 5;
}

.dropdown {
    pointer-events: none;
    position: absolute;
    top: 40px;
    right: 10px;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 10;
    border: 1px solid var(--border);
    opacity: 0;
    visibility: hidden;
    overflow: hidden;
    transform: translateY(-5px) scale(0.95);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease, visibility 0.3s;
    transform-origin: top right;
}

.dropdown.show {
    pointer-events: auto;
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    box-shadow: 0 4px 20px var(--shadow);
}

.dropdown button {
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: none;
    text-align: right;
    font-size: 14px;
    margin-bottom: 2px;
}

.dropdown button:last-child {
    margin-bottom: 0;
}

.dropdown button.del {
    color: var(--danger);
}

@media (hover: hover) {
    .dropdown .dp-option:hover {
        background: var(--surface-hover);
        color: var(--accent);
    }

    .dropdown button.del:hover {
        background: var(--danger);
        color: white;
    }
}

.flying-heart {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    transition: transform 2.2s cubic-bezier(0.25, 1, 0.3, 1), opacity 2.2s ease;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
    transform-origin: center center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flying-heart-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z'/%3E%3C/svg%3E");
    -webkit-mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z'/%3E%3C/svg%3E");
    mask-size: contain;
    mask-repeat: no-repeat;
    mask-position: center;
}

body.selection-mode-active {
    -webkit-user-select: none;
    user-select: none;
}

body.selection-mode-active .fav-btn,
body.selection-mode-active .menu-dots {
    display: none !important;
}