/*
 * Safe Image Blur stylesheet.
 *
 * Loaded via chrome.scripting.registerContentScripts() with runAt:
 * 'document_start' so it is part of the document's stylesheet origin set
 * before any HTML body content is parsed. The marker class is added by
 * safeImageBlurContent.js as its very first synchronous action, also at
 * document_start, before any <img> element appears in the DOM. This
 * guarantees that every result thumbnail is blurred on first paint -
 * there is no first-paint window where an image is visible.
 *
 * Rules are scoped by html.iboss-image-search so they only take effect on
 * supported image-search pages:
 *   - Google image search (udm=2 or tbm=isch on www.google.com/search)
 *   - Bing image search   (www.bing.com/images/search*)
 *   - Bing video search   (www.bing.com/videos/search*)
 *   - Yandex image search (yandex.com/images/search*)
 *   - DuckDuckGo, Yahoo, Brave image search (see ENGINE_CONFIGS)
 * On regular Web search, Maps, etc. the marker class is never set and
 * these rules are inert.
 *
 * Un-blurring is opt-in: only an <img> tagged data-iboss-image="allow"
 * by JS (after the cloud classifier returns blockUrl=0) gets its filter
 * cleared. UI icons (search-engine logos, account avatar, etc.) are
 * tagged "allow" by JS once it determines they are not result
 * thumbnails.
 *
 * The pointer-events rules block clicks on any element we've tagged
 * data-iboss-image (the result tile, its anchor, its image) until that
 * element is approved. Modern Google Image Search routes thumbnail clicks
 * through jsaction handlers rather than navigation, and Bing's a.iusc
 * anchors trigger the inline preview overlay; pointer-events:none on
 * the tile is what actually prevents the original-image preview from
 * opening for blocked / unclassified results in either UI.
 */

html.iboss-image-search img:not([data-iboss-image="allow"]) {
    filter: blur(28px) !important;
    transition: filter 120ms ease-out;
}

/*
 * Defense-in-depth against revealing the original via the image
 * itself: a not-yet-approved thumbnail must not be draggable (drag to
 * desktop / drag to a new tab loads the full-size source) or
 * selectable. The capture-phase interaction guard in
 * safeImageBlurContent.js is the primary block for clicks and drags;
 * this stops the browser's native image-drag/selection on engines
 * (DuckDuckGo, Yahoo) where the thumbnail is a bare <img>.
 */
html.iboss-image-search img:not([data-iboss-image="allow"]) {
    -webkit-user-drag: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
}

html.iboss-image-search img[data-iboss-image="allow"] {
    filter: none !important;
    transition: filter 120ms ease-out;
}

html.iboss-image-search [data-iboss-image]:not([data-iboss-image="allow"]) {
    pointer-events: none !important;
}

html.iboss-image-search [data-iboss-image="allow"] {
    pointer-events: auto !important;
}

/*
 * Yandex related-query chips (a.Tags-Item) render their thumbnail as a
 * CSS background-image on div.Tags-ItemThumbImage rather than an <img>,
 * so the img-targeted blur rule above can't reach it. Blur the chip's
 * thumbnail until the chip anchor is approved (or while it is still
 * unclassified, matching the fail-safe-blur default of the img rule).
 * The pointer-events rule above already blocks the click on the blocked
 * anchor; this only adds the missing visual blur.
 */
html.iboss-image-search a.Tags-Item:not([data-iboss-image="allow"]) .Tags-ItemThumbImage {
    filter: blur(28px) !important;
    transition: filter 120ms ease-out;
}

html.iboss-image-search a.Tags-Item[data-iboss-image="allow"] .Tags-ItemThumbImage {
    filter: none !important;
    transition: filter 120ms ease-out;
}
