/*
 * HOME feed layout test: masonry cards (feed layout switch "new").
 *
 * Every rule is scoped to the grid the new renderer marks
 * (#gallery-grid.is-feed-new), so the current cards and the my page list
 * (#feed-grid, which shares the .gallery-grid / .prompt-card class names) are
 * untouched. script.js checks --fl-css before rendering new cards, so a failed
 * load of this file keeps the current feed.
 *
 * #gallery-grid.is-masonry   feed-masonry.js placed the cards in .feed-band columns
 * .feed-card-media.is-fit    the image is shown whole on a blurred copy of itself
 *                            (its shape is outside 4:3 .. 9:16, or unknown)
 */
:root {
    --fl-css: 1;
}

/* ---------- Grid and columns ---------- */
#gallery-grid.is-feed-new {
    --feed-gap: 24px;
    display: block;
    perspective: none;
}
/* Before feed-masonry.js runs (or without scripts): a plain grid. */
#gallery-grid.is-feed-new:not(.is-masonry) {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--feed-gap);
    align-items: start;
}
#gallery-grid.is-feed-new .feed-band {
    display: flex;
    align-items: flex-start;
    gap: var(--feed-gap);
}
#gallery-grid.is-feed-new .feed-band + .feed-band {
    margin-top: var(--feed-gap);
}
#gallery-grid.is-feed-new .feed-col {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--feed-gap);
}

/* ---------- Card ---------- */
#gallery-grid.is-feed-new .feed-card {
    border-radius: 12px;
    will-change: auto;
}
#gallery-grid.is-feed-new .feed-card-media {
    position: relative;
    width: 100%;
    overflow: hidden;
    background: #eceef1;
    flex-shrink: 0;
}
#gallery-grid.is-feed-new .feed-card-media.is-video {
    background: #111318;
}
#gallery-grid.is-feed-new .feed-card-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
#gallery-grid.is-feed-new .feed-card-media.is-fit .feed-card-image {
    object-fit: contain;
}
#gallery-grid.is-feed-new .feed-card-backdrop {
    position: absolute;
    top: -24px;
    left: -24px;
    width: calc(100% + 48px);
    height: calc(100% + 48px);
    object-fit: cover;
    filter: blur(20px) saturate(1.15);
    opacity: 0.9;
    display: block;
    pointer-events: none;
}
/* Video preview: script.js puts the looping <video> over the poster while the card is
   near the middle of the screen. It shows once it plays; clicks reach the card below. */
#gallery-grid.is-feed-new .feed-card-media > .pa-video-preview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}
#gallery-grid.is-feed-new .feed-card-media.is-fit > .pa-video-preview {
    object-fit: contain;
}
#gallery-grid.is-feed-new .feed-card-media > .pa-video-preview.is-playing {
    opacity: 1;
}

/* Before / after: the pair keeps its own shape, centered in the card. */
#gallery-grid.is-feed-new .feed-card-ba {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    overflow: hidden;
    background: #0f1115;
}
#gallery-grid.is-feed-new .feed-card-ba:not([style]) {
    top: 0;
    bottom: 0;
    transform: none;
}
#gallery-grid.is-feed-new .feed-card-ba .card-before-after {
    position: absolute;
    inset: 0;
    width: auto;
    height: auto;
}
#gallery-grid.is-feed-new .card-before-after-label {
    top: auto;
    bottom: 10px;
}

/* ---------- Buttons on the image ---------- */
#gallery-grid.is-feed-new .feed-card-actions {
    --feed-actions-edge: 10px;
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    display: flex;
    gap: 8px;
    row-gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: calc(100% - var(--feed-actions-edge) - var(--feed-actions-edge));
}
#gallery-grid.is-feed-new .feed-card-actions .action-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 9px;
    gap: 5px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: #1a1a1a;
    font-size: 15px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}
#gallery-grid.is-feed-new .feed-card-actions .action-btn:hover {
    background-color: #ffffff;
    color: #1a1a1a;
}
#gallery-grid.is-feed-new .feed-card-actions .action-btn:focus-visible {
    outline: 2px solid #007aff;
    outline-offset: 2px;
}
#gallery-grid.is-feed-new .feed-card-actions .favorite-btn.active {
    color: #ff4757;
}
#gallery-grid.is-feed-new .feed-card-actions .bookmark-btn.active {
    color: #00b894;
}
#gallery-grid.is-feed-new .feed-card-actions .action-btn .count {
    font-size: 13px;
    font-weight: 600;
}

/* ---------- Badges: media count, video, audio ---------- */
#gallery-grid.is-feed-new .feed-card-badges {
    position: absolute;
    right: 10px;
    bottom: 10px;
    z-index: 1;
    display: flex;
    gap: 6px;
    pointer-events: none;
}
#gallery-grid.is-feed-new .feed-card-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 8px;
    border-radius: 999px;
    background: rgba(15, 17, 21, 0.66);
    color: #ffffff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
}
/* Newly released in the recommended order (app/lib/feed_order.php). The site's accent, white text. */
#gallery-grid.is-feed-new .feed-card-badge.is-new {
    background: #0062cc;
    letter-spacing: 0.04em;
}

/* ---------- Title: two lines are always reserved (feed-masonry.js relies on it) ---------- */
#gallery-grid.is-feed-new .feed-card-body {
    padding: 12px 14px 14px;
}
#gallery-grid.is-feed-new .feed-card-title {
    margin: 0;
    min-height: 0;
    height: 44px;
    font-size: 15px;
    font-weight: 600;
    line-height: 22px;
}

/* ---------- Skeletons ---------- */
#gallery-grid.is-feed-new .skeleton-card .feed-card-media {
    border-radius: 0;
    background-color: #edf0f4;
}
#gallery-grid.is-feed-new .skeleton-card .feed-card-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 44px;
    box-sizing: content-box;
}
#gallery-grid.is-feed-new .skeleton-card .skeleton-title-line {
    height: 16px;
}

/* ---------- Phone ---------- */
@media (max-width: 768px) {
    /* One column: bigger buttons, 44px touch area around a 40px circle. */
    html:not(.pa-feed-grid-prefer-grid) #gallery-grid.is-feed-new .feed-card-actions {
        --feed-actions-edge: 8px;
        top: 8px;
        right: 8px;
        gap: 4px;
    }
    html:not(.pa-feed-grid-prefer-grid) #gallery-grid.is-feed-new .feed-card-actions .action-btn {
        min-width: 44px;
        height: 44px;
        border: 2px solid transparent;
        background-clip: padding-box;
        box-shadow: none;
        filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.22));
    }

    /* Two columns (the default on phones in this layout). */
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new {
        --feed-gap: 12px;
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new:not(.is-masonry) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    html:not(.pa-feed-grid-prefer-grid) #gallery-grid.is-feed-new:not(.is-masonry) {
        grid-template-columns: minmax(0, 1fr);
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card {
        border-radius: 10px;
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card-actions {
        --feed-actions-edge: 2px;
        top: 2px;
        right: 2px;
        gap: 0;
        row-gap: 4px;
    }
    /* A 34px circle inside a 42px touch area. */
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card-actions .action-btn {
        min-width: 42px;
        height: 42px;
        padding: 0 8px;
        gap: 3px;
        border: 4px solid transparent;
        background-clip: padding-box;
        box-shadow: none;
        filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.22));
        font-size: 13px;
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card-actions .action-btn .count {
        font-size: 11px;
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card-actions .share-btn {
        display: none;
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card-badges {
        right: 6px;
        bottom: 6px;
        gap: 4px;
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card-badge {
        padding: 4px 6px;
        font-size: 10px;
        gap: 3px;
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .card-before-after-label {
        bottom: 6px;
        padding: 3px 6px;
        font-size: 10px;
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .card-before-after-label.before {
        left: 6px;
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .card-before-after-label.after {
        right: 6px;
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .card-before-after-handle {
        width: 22px;
        height: 22px;
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card-body {
        padding: 8px 10px 10px;
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card-title {
        height: 36px;
        font-size: 13px;
        line-height: 18px;
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .skeleton-card .feed-card-body {
        height: 36px;
    }
}

/* ---------- Frosted actions ----------
 * Keep the full button as the hit target; only its decorative surface is smaller.
 * The marker class and hidden surface let old markup/CSS retain the old buttons.
 * Do not use the button's pseudo-elements: the favorite feedback owns both.
 *
 * Smoke glass with white icons on every photo. Most of the darkening comes
 * from backdrop brightness() rather than the colour film, so the photo's
 * colours show through a little while white icons keep about 3:1 even on a
 * white photo. --feed-glass-alpha is the film, set by the state rules below.
 * Without backdrop-filter, --feed-glass-floor thickens the film instead.
 */
#gallery-grid.is-feed-new .feed-glass-actions {
    pointer-events: none; /* Empty row space must not cover comparison dragging. */
}
#gallery-grid.is-feed-new:not(.is-reloading) .feed-glass-actions > .feed-glass-btn {
    pointer-events: auto;
}
html #gallery-grid.is-feed-new .feed-card-actions > .action-btn.feed-glass-btn {
    --feed-glass-inset: 2.5px; /* 31px surface inside the existing 36px target. */
    --feed-glass-alpha: 0.15; /* Count-safe value, also used without :has. */
    box-sizing: border-box;
    flex: 0 0 auto;
    padding: 0 9px;
    border: 0;
    background: transparent;
    box-shadow: none;
    filter: none;
    transform: none; /* The target must also stay still during :active. */
    isolation: isolate;
    overflow: visible;
    white-space: nowrap;
    color: rgba(255, 255, 255, 0.92);
}
html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn > .feed-action-surface[hidden] {
    display: block !important; /* Override [hidden] only for this decoration. */
    position: absolute;
    inset: var(--feed-glass-inset);
    box-sizing: border-box;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: inherit;
    background: rgba(16, 18, 24, calc(var(--feed-glass-floor, 0.38) + var(--feed-glass-alpha)));
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.16);
    pointer-events: none;
    z-index: 0;
}
html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn > i,
html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn > .count {
    position: relative;
    z-index: 2;
    flex: 0 0 auto;
}
html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn > i {
    text-shadow: none;
}
/* A little frost in the white icons. Not on selected ones: the mask would cut their glow. */
html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn:not(.active) > i {
    -webkit-mask-image: linear-gradient(#000 35%, rgba(0, 0, 0, 0.75));
    mask-image: linear-gradient(#000 35%, rgba(0, 0, 0, 0.75));
}
html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn > .count {
    color: #ffffff; /* Selected red/green belongs to the icon, not small text. */
    /* Retain the existing small-count aid separately from the plain icons. */
    text-shadow: -0.5px 0 rgba(0, 0, 0, 0.45),
        0.5px 0 rgba(0, 0, 0, 0.45),
        0 -0.5px rgba(0, 0, 0, 0.45),
        0 0.5px rgba(0, 0, 0, 0.45),
        0 1px 2px rgba(0, 0, 0, 0.2);
}
html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn.is-liked-burst::before {
    z-index: 1;
}
html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn.is-liked-burst::after {
    z-index: 3;
}
html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn > .reaction-burst {
    z-index: 4;
}

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn > .feed-action-surface {
        --feed-glass-floor: 0;
        -webkit-backdrop-filter: blur(8px) saturate(1.6) brightness(0.6);
        backdrop-filter: blur(8px) saturate(1.6) brightness(0.6);
    }
}
@supports selector(:has(*)) {
    html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn:not(.active):not(:has(> .count:not(:empty))) {
        --feed-glass-alpha: 0.12; /* J-2: the thinnest film, so the photo shows through. */
    }
    /* Match the specificity above without duplicating reaction state in JS. */
    @media (hover: hover) and (pointer: fine) {
        html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn:not(.active):not(:has(> .count:not(:empty))):hover {
            --feed-glass-alpha: 0.18;
        }
    }
    html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn:not(.active):not(:has(> .count:not(:empty))):active {
        --feed-glass-alpha: 0.22;
    }
}
@media (hover: hover) and (pointer: fine) {
    html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn:hover {
        --feed-glass-alpha: 0.18;
    }
}
html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn:active {
    --feed-glass-alpha: 0.22;
}
/* Lighter red/green than the old ones: they sit on dark glass now. */
html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn.favorite-btn.active {
    --feed-glass-alpha: 0.17;
    color: #ff6a85;
}
html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn.bookmark-btn.active {
    --feed-glass-alpha: 0.17;
    color: #45dcb2;
}
html #gallery-grid.is-feed-new .feed-card-actions > .action-btn.feed-glass-btn.active:active {
    --feed-glass-alpha: 0.22;
}
html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn:focus-visible {
    outline: none;
}
html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn:focus-visible > .feed-action-surface {
    outline: 2px solid #007aff;
    outline-offset: 0;
    box-shadow: 0 0 0 3px #ffffff;
}

@media (max-width: 768px) {
    html:not(.pa-feed-grid-prefer-grid) #gallery-grid.is-feed-new .feed-card-actions > .action-btn.feed-glass-btn {
        --feed-glass-inset: 5px; /* 34px surface / 44px target, border included. */
        padding: 0 11px;
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card-actions > .action-btn.feed-glass-btn {
        --feed-glass-inset: 6.5px; /* 29px surface / 42px target. */
        max-width: 50%;
        padding: 0 4px;
        flex-wrap: wrap;
        align-content: center;
        row-gap: 0;
        line-height: 1;
    }
    /* Keep the two targets on one row, clear of badges and comparison labels.
     * Very long counts may take their own line INSIDE the 42px target.
     */
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-glass-actions {
        width: calc(100% - 4px);
    }
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn > .count {
        line-height: 1;
    }
    @supports selector(:has(*)) {
        html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn:has(> .count:not(:empty)) > .feed-action-surface {
            left: 2px;
            right: 2px;
            border-radius: 6px;
        }
    }
    @supports not selector(:has(*)) {
        /* Older engines cannot distinguish counts; retain the same safe space. */
        html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn > .feed-action-surface {
            left: 2px;
            right: 2px;
            border-radius: 6px;
        }
    }
}
@media (max-width: 360px) {
    html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card-actions > .action-btn.feed-glass-btn {
        padding: 0;
    }
    @supports selector(:has(*)) {
        html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn:has(> .count:not(:empty)) > .feed-action-surface {
            left: 0;
            right: 0;
            border-width: 0;
            border-radius: 3px;
        }
    }
    @supports not selector(:has(*)) {
        html.pa-feed-grid-prefer-grid #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn > .feed-action-surface {
            left: 0;
            right: 0;
            border-width: 0;
            border-radius: 3px;
        }
    }
}

@media (forced-colors: active) {
    html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn > .feed-action-surface {
        background: ButtonFace;
        border: 1px solid ButtonText !important; /* Also restore narrow count borders. */
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
    html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn > i,
    html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn > .count {
        color: ButtonText;
        text-shadow: none;
    }
    html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn:not(.active) > i {
        -webkit-mask-image: none;
        mask-image: none;
    }
    html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn.active > .feed-action-surface {
        border: 2px solid Highlight !important;
    }
    html #gallery-grid.is-feed-new .feed-card-actions > .feed-glass-btn:focus-visible > .feed-action-surface {
        outline-color: Highlight;
    }
}
