.gallery-search-shell {
    margin: 34px auto 18px;
    padding-top: 8px;
    width: min(100%, 1200px);
    position: relative;
    z-index: 10;
}

.gallery-search-shell form {
    margin: 0;
}

.gallery-search-shell .search-container {
    max-width: 520px;
    padding-top: 12px;
    padding-bottom: 12px;
    width: min(100%, 520px);
    box-sizing: border-box;
}

#gallery {
    --gallery-pink: #fb7299;
    --gallery-pink-soft: rgba(251, 114, 153, 0.14);
    --gallery-blue: #00a1d6;
    --gallery-blue-soft: rgba(0, 161, 214, 0.12);
    padding: clamp(16px, 2vw, 28px);
    background: transparent;
    min-width: 0;
}

#gallery .gallery-shell {
    display: grid;
    gap: 18px;
    min-width: 0;
}

#gallery .gallery-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 16px;
    padding: 16px;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background:
        linear-gradient(135deg, var(--gallery-pink-soft), transparent 58%),
        linear-gradient(315deg, var(--gallery-blue-soft), transparent 62%),
        color-mix(in srgb, var(--card-bg) 88%, transparent);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    position: relative;
    z-index: 1;
}

#gallery .gallery-header__copy {
    display: grid;
    align-content: start;
    gap: 6px;
    min-width: 0;
}

#gallery .gallery-header__badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--gallery-pink);
    background: rgba(251, 114, 153, 0.12);
    border: 1px solid rgba(251, 114, 153, 0.22);
}

#gallery .gallery-header__badge ion-icon {
    font-size: 1rem;
}

#gallery .gallery-header__subtitle {
    margin: 0;
    color: var(--text-secondary, var(--text-primary));
    opacity: 0.9;
    max-width: 68ch;
    line-height: 1.45;
    font-size: 0.92rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

#gallery .gallery-header__stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(86px, 1fr));
    gap: 10px;
    align-content: start;
}

#gallery .gallery-stat-card {
    display: grid;
    gap: 2px;
    align-content: center;
    justify-items: center;
    min-height: 76px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
}

#gallery .gallery-stat-card__value {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-primary);
}

#gallery .gallery-stat-card__label {
    font-size: 0.72rem;
    color: var(--text-secondary, var(--text-primary));
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

#gallery .gallery-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    column-gap: 18px;
    row-gap: 42px;
    align-items: stretch;
}

#gallery .gallery-item {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 12px;
    padding: 12px;
    border-radius: 18px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 40%),
        var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.10);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    overflow: clip;
    height: 100%;
    content-visibility: auto;
    contain-intrinsic-size: 320px 520px;
}

#gallery .gallery-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 18px 38px rgba(0, 0, 0, 0.14);
    border-color: rgba(251, 114, 153, 0.18);
}

#gallery .gallery-item:not(.is-visible) .gallery-frame {
    transform: translateY(6px);
    opacity: 0.96;
}

#gallery .gallery-frame {
    position: relative;
    border-radius: 14px;
    overflow: hidden;
    aspect-ratio: 16 / 10;
    background:
        radial-gradient(circle at 15% 10%, rgba(251, 114, 153, 0.18), transparent 55%),
        radial-gradient(circle at 100% 100%, rgba(0, 161, 214, 0.16), transparent 55%),
        rgba(0, 0, 0, 0.12);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
    transition: transform 0.2s ease;
}

#gallery .gallery-frame::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.08), transparent 30%, rgba(0, 0, 0, 0.16));
}

#gallery .gallery-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.28s ease, filter 0.28s ease;
    display: block;
    will-change: transform;
}

#gallery .gallery-item:hover .gallery-image {
    filter: saturate(1.05);
    transform: scale(1.03);
}

#gallery .gallery-frame__overlay {
    position: absolute;
    inset: 10px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    flex-wrap: wrap;
    z-index: 1;
    pointer-events: none;
}

#gallery .gallery-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 999px;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    background: rgba(17, 18, 23, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(4px);
}

#gallery .gallery-pill ion-icon {
    font-size: 0.9rem;
}

#gallery .gallery-pill--accent {
    background: linear-gradient(135deg, rgba(251, 114, 153, 0.82), rgba(0, 161, 214, 0.82));
    border-color: rgba(255, 255, 255, 0.22);
}

#gallery .gallery-count-badges {
    position: absolute;
    right: 0;
    bottom: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
}

#gallery .gallery-count-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 28px;
    padding: 4px 8px;
    border-radius: 999px;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    background: rgba(17, 18, 23, 0.62);
    border: 1px solid rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(4px);
}

#gallery .gallery-count-badge ion-icon {
    font-size: 0.85rem;
    flex-shrink: 0;
}

#gallery .gallery-count-badge.is-active {
    background: rgba(251, 114, 153, 0.82);
    border-color: rgba(255, 255, 255, 0.24);
}

#gallery .gallery-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    text-align: left;
}

#gallery .gallery-title {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.02rem;
    font-weight: 700;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: calc(1.35em * 2);
}

#gallery .gallery-item .description {
    margin: 0;
    color: var(--text-secondary, var(--text-primary));
    opacity: 0.9;
    font-size: 0.9rem;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: calc(1.45em * 3);
}

#gallery .tags {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 6px;
    margin-top: 2px;
    min-height: 28px;
    align-content: flex-start;
    overflow: hidden;
}

#gallery .tag {
    display: inline-flex;
    align-items: center;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: color-mix(in srgb, var(--text-primary) 88%, white);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
        rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.10);
    cursor: default;
    transition: transform 0.18s ease, border-color 0.18s ease;
}

#gallery .tag:hover {
    transform: translateY(-1px);
    border-color: rgba(0, 161, 214, 0.22);
}

#gallery .gallery-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: auto;
    padding-top: 4px;
}

#gallery .action-btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
    min-height: 40px;
    min-width: 0;
    padding: 8px 8px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
        rgba(255, 255, 255, 0.02);
    color: var(--text-primary, #333);
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background-color 0.18s ease;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
}

#gallery .action-btn ion-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

#gallery .like-text,
#gallery .action-state-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

#gallery .like-count,
#gallery .comment-count {
    flex-shrink: 0;
}

#gallery .action-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(0, 161, 214, 0.22);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.10);
}

#gallery .like-btn.liked {
    color: #fff;
    border-color: rgba(251, 114, 153, 0.5);
    background:
        linear-gradient(180deg, rgba(251, 114, 153, 0.88), rgba(251, 114, 153, 0.72)),
        rgba(251, 114, 153, 0.75);
    box-shadow: 0 10px 22px rgba(251, 114, 153, 0.22);
}

#gallery .like-btn.liked ion-icon {
    color: #fff;
}

#gallery .like-count,
#gallery .comment-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.35em;
    padding: 0 2px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    line-height: 1.35;
}

#gallery .gallery-count-badge .like-count,
#gallery .gallery-count-badge .comment-count {
    background: rgba(255, 255, 255, 0.12);
}

#gallery .gallery-count-badge.is-active .like-count {
    background: rgba(255, 255, 255, 0.2);
}

#gallery .comment-btn:hover {
    border-color: rgba(0, 161, 214, 0.28);
}

#gallery .relay-btn:hover {
    border-color: rgba(251, 114, 153, 0.28);
}

#gallery .pagination {
    margin-top: 34px;
    padding: 10px 14px;
    border-radius: 14px;
    border: 1px solid color-mix(in srgb, var(--text-primary, #111) 10%, transparent);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02)),
        color-mix(in srgb, var(--card-bg, #fff) 88%, transparent);
    backdrop-filter: blur(6px);
    box-shadow: 0 10px 24px color-mix(in srgb, var(--shadow-color, rgba(0, 0, 0, 0.18)) 55%, transparent);
    gap: 8px;
    flex-wrap: wrap;
}

#gallery .pagination a,
#gallery .pagination span {
    margin: 0;
}

#gallery .pagination a {
    border-radius: 10px;
    border-color: color-mix(in srgb, var(--text-primary, #111) 12%, transparent);
    color: var(--text-primary);
    background: color-mix(in srgb, var(--card-bg, #fff) 92%, transparent);
}

#gallery .pagination a:hover {
    background: rgba(0, 161, 214, 0.2);
    border-color: rgba(0, 161, 214, 0.3);
    color: #fff;
}

#gallery .pagination-count {
    color: var(--text-primary);
    opacity: 0.95;
}

:root[data-theme="light"] #gallery .pagination {
    border-color: rgba(0, 0, 0, 0.08);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(248, 250, 253, 0.84)),
        rgba(255, 255, 255, 0.84);
    box-shadow:
        0 10px 28px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

:root[data-theme="light"] #gallery .pagination a {
    background: rgba(255, 255, 255, 0.86);
    border-color: rgba(0, 0, 0, 0.08);
}

:root[data-theme="light"] #gallery .pagination a:hover {
    background: color-mix(in srgb, var(--accent-color, #007bff) 16%, white);
    border-color: color-mix(in srgb, var(--accent-color, #007bff) 26%, transparent);
    color: var(--text-primary);
}

@supports not (overflow: clip) {
    #gallery .gallery-item {
        overflow: hidden;
    }
}

@media (max-width: 920px) {
    .gallery-search-shell {
        margin: 24px auto 14px;
        padding-top: 6px;
    }

    #gallery .gallery-header {
        grid-template-columns: 1fr;
    }

    #gallery .gallery-header__stats {
        width: 100%;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 680px) {
    .gallery-search-shell {
        margin: 16px auto 12px;
        padding-top: 4px;
        z-index: 10;
        width: calc(100% - 24px);
        max-width: none;
        box-sizing: border-box;
    }

    .gallery-search-shell .search-container {
        max-width: 100%;
        width: 100%;
        padding-top: 11px;
        padding-bottom: 11px;
    }

    #gallery {
        padding: 12px;
    }

    #gallery .gallery-container {
        grid-template-columns: 1fr;
        row-gap: 30px;
        min-width: 0;
    }

    #gallery .gallery-item {
        padding: 10px;
        border-radius: 16px;
        min-width: 0;
        position: relative;
        margin-bottom: 0;
    }

    #gallery .gallery-item:not(:last-child) {
        margin-bottom: 14px;
    }

    #gallery .gallery-header {
        padding: 14px;
        border-radius: 16px;
    }

    #gallery .gallery-frame__overlay {
        inset: 8px;
    }

    #gallery .gallery-actions {
        grid-template-columns: 1fr;
    }

    #gallery .pagination {
        margin-top: 24px;
    }
}

@media (max-width: 420px) {
    .gallery-search-shell {
        width: calc(100% - 20px);
        margin-top: 12px;
    }

    #gallery {
        padding: 10px;
    }

    #gallery .gallery-header {
        gap: 12px;
        padding: 12px;
    }

    #gallery .gallery-header__subtitle {
        font-size: 0.86rem;
        -webkit-line-clamp: 3;
    }

    #gallery .gallery-stat-card {
        min-height: 66px;
        padding: 8px 10px;
    }

    #gallery .gallery-stat-card__value {
        font-size: 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    #gallery .gallery-item,
    #gallery .gallery-frame,
    #gallery .gallery-image,
    #gallery .tag,
    #gallery .action-btn {
        transition: none;
    }

    #gallery .gallery-item:hover,
    #gallery .gallery-item:hover .gallery-image,
    #gallery .tag:hover,
    #gallery .action-btn:hover {
        transform: none;
    }
}
