.gallery {
    --gallery-cols: 2;
    padding: 15px;
    column-gap: 15px;
    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 15px;
    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%;
}

.not-found-container {
    column-span: all;
    width: 100%;
    text-align: center;
    padding: 40px 20px;
    background: var(--surface);
    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: 10px;
    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: 10px;
    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);
}

.image-container.reveal {
    opacity: 1;
    transform: translateY(0);
}

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

.image-container img {
    width: 100%;
    display: block;
    transition: transform 0.4s ease;
}

.image-container:hover img {
    transform: scale(1.03);
}

.image-container.is-new::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 10px;
    padding: 2px;
    background: linear-gradient(45deg, #ff00cc, #3333ff, #00ffcc, #ff00cc);
    background-size: 300% 300%;
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    z-index: 2;
    animation: gradientBorder 3s ease infinite;
    transition: opacity 0.4s ease;
}

.highlight-just-uploaded::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 10px;
    padding: 3px;
    background: linear-gradient(45deg, #ff00cc, #3333ff, #00ffcc, #ff00cc);
    background-size: 300% 300%;
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    z-index: 20;
    animation: gradientBorder 2s ease infinite;
    opacity: 1;
    transition: opacity 1s ease-out;
}

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

@keyframes gradientBorder {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.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;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 15px;
    color: white;
}

.image-container:hover .hover-overlay {
    opacity: 1;
}

.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));
}

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

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

.fav-btn svg {
    width: 100%;
    height: 100%;
    fill: transparent;
    stroke: white;
    stroke-width: 2px;
    transition: 0.2s;
}

.fav-btn.is-fav svg {
    fill: var(--fav);
    stroke: var(--fav);
}

.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: none;
    transition: 0.3s;
    opacity: 1;
}

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

.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 {
    display: none;
    position: absolute;
    top: 40px;
    right: 10px;
    background: var(--surface);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 15px var(--shadow);
    z-index: 10;
    border: 1px solid var(--border);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px) scale(0.95);
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    transform-origin: top right;
}

.dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    display: block;
}

.dropdown button {
    width: 100%;
    padding: 12px 20px;
    background: none;
    border: none;
    text-align: right;
    border-radius: 0;
    font-size: 14px;
}

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

.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;
}