.gallery-container {
    max-width: 1200px;
    margin: 0 auto;
    margin-bottom: 16px;
}

.gallery-header {
    text-align: center;
    margin-bottom: 40px;
}

.gallery-header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    color: var(--primary-font-color);
}

.gallery-header p {
    font-size: 1.1rem;
    color: var(--primary-font-color);
    opacity: 0.8;
}

.gallery-filters {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 30px;
}

.filter-btn {
    padding: 8px 16px;
    border: 2px solid var(--border-color);
    background: var(--body-bg);
    color: var(--primary-font-color);
    border-radius: 20px;
    cursor: pointer;
    transition: background-color var(--ui-dur) var(--ui-ease), color var(--ui-dur) var(--ui-ease), border-color var(--ui-dur) var(--ui-ease), transform var(--ui-dur) var(--ui-ease), box-shadow var(--ui-dur) var(--ui-ease);
    font-size: 0.9rem;
    font-weight: 500;
}

.filter-btn:hover,
.filter-btn.active {
    background: var(--primary-font-color);
    color: var(--body-bg);
    border-color: var(--primary-font-color);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    grid-auto-rows: 200px;
    gap: 20px;
    grid-auto-flow: dense;
}

/*
  Neutralize global `.clickable-image` styles (repo posts) for the gallery.
  The gallery tiles already have their own framing.
*/
.gallery-container .clickable-image {
    border: 0 !important;
    box-shadow: none !important;
    transform: none !important;
}

.gallery-container .clickable-image:hover {
    border: 0 !important;
    box-shadow: none !important;
    transform: none !important;
}

.gallery-item {
    position: relative;
    display: flex;
    border-radius: 15px;
    overflow: hidden;
    cursor: pointer;
    transition: transform var(--ui-dur) var(--ui-ease), box-shadow var(--ui-dur) var(--ui-ease);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .gallery-item {
    border: 1px solid rgba(61, 68, 77, 0.5);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

[data-theme="dark"] .gallery-item:hover {
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--ui-dur) var(--ui-ease);
    /* Kurangi biaya rendering offscreen */
    content-visibility: auto;
    contain-intrinsic-size: 300px 200px;
}

.gallery-item:hover img {
    transform: scale(1.03);
}

/*
    Safety net: ensure gallery thumbnails always fill the tile.
    (Prevents global `.clickable-image` rules or lazy-load placeholder sizing from leaving empty space.)
*/
.gallery-item>img.clickable-image {
    display: block;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    flex: 1 1 auto;
}

.gallery-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    color: #ffffff;
    padding: 20px 15px 15px;
    transform: translateY(100%);
    transition: transform var(--ui-dur) var(--ui-ease);
}

[data-theme="dark"] .gallery-overlay {
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.9));
}

.gallery-item:hover .gallery-overlay {
    transform: translateY(0);
}

.gallery-title {
    font-size: 1rem;
    font-weight: 600;
    display: block;
    margin-bottom: 5px;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}

.gallery-description {
    font-size: 0.85rem;
    opacity: 0.9;
    display: block;
    line-height: 1.3;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
}

/* Size variations untuk layout yang lebih menarik */
.gallery-item.large {
    grid-column: span 2;
    grid-row: span 2;
}

.gallery-item.medium {
    grid-column: span 1;
    grid-row: span 2;
}

.gallery-item.small {
    grid-column: span 1;
    grid-row: span 1;
}

/* Random positioning untuk efek abstrak */
.gallery-item:nth-child(3n) {
    grid-column: span 1;
    grid-row: span 1;
}

.gallery-item:nth-child(5n) {
    grid-column: span 2;
    grid-row: span 1;
}

.gallery-item:nth-child(7n) {
    grid-column: span 1;
    grid-row: span 2;
}

/* Responsive design */
@media (max-width: 768px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        grid-auto-rows: 150px;
        gap: 15px;
    }

    .gallery-item.large,
    .gallery-item.medium {
        grid-column: span 1;
        grid-row: span 1;
    }

    .gallery-header h1 {
        font-size: 2rem;
    }

    /* Hide button filters on mobile, show select */
    .gallery-filters {
        display: none;
    }

    .gallery-filters-mobile {
        display: block;
        text-align: center;
        margin-bottom: 30px;
    }

    .filter-select {
        padding: 10px 16px;
        border: 2px solid var(--border-color);
        background: var(--body-bg);
        color: var(--primary-font-color);
        border-radius: 8px;
        font-size: 1rem;
        cursor: pointer;
        transition: border-color var(--ui-dur) var(--ui-ease);
        min-width: 100%;
    }

    .filter-select:focus {
        outline: none;
        border-color: var(--accent-color);
    }
}

@media (min-width: 769px) {
    .gallery-filters-mobile {
        display: none;
    }
}

@media (max-width: 480px) {
    .gallery-grid {
        grid-template-columns: 1fr;
        grid-auto-rows: 200px;
    }

    .gallery-item {
        grid-column: span 1 !important;
        grid-row: span 1 !important;
    }
}

/* Dark mode compatibility */
[data-theme="dark"] .gallery-item {
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .gallery-item:hover {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
}

/* Loading animation */
.gallery-item img {
    opacity: 0;
    animation: fadeIn var(--ui-dur) var(--ui-ease) forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

/* Staggered animation untuk efek yang lebih smooth */
.gallery-item:nth-child(1) {
    animation-delay: 0.1s;
}

.gallery-item:nth-child(2) {
    animation-delay: 0.2s;
}

.gallery-item:nth-child(3) {
    animation-delay: 0.3s;
}

.gallery-item:nth-child(4) {
    animation-delay: 0.4s;
}

.gallery-item:nth-child(5) {
    animation-delay: 0.5s;
}

.gallery-item:nth-child(6) {
    animation-delay: 0.6s;
}

.gallery-item:nth-child(7) {
    animation-delay: 0.7s;
}

.gallery-item:nth-child(8) {
    animation-delay: 0.8s;
}

.gallery-item:nth-child(9) {
    animation-delay: 0.9s;
}

.gallery-item:nth-child(10) {
    animation-delay: 1.0s;
}

.gallery-item:nth-child(11) {
    animation-delay: 1.1s;
}

.gallery-item:nth-child(12) {
    animation-delay: 1.2s;
}

/* Image fallback for gallery items */
.gallery-item .image-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f0f0f0 0%, #e8e8e8 100%);
    border-radius: 15px;
}

.gallery-item .image-fallback::before {
    content: '📸';
    font-size: 3rem;
    opacity: 0.3;
}
