/*
 * Blur All Page Images stylesheet.
 *
 * Companion to safeImageBlur.css, but for the general-page image blur
 * feature (BLUR_ALL_PAGE_IMAGES_ENABLE) rather than the search-engine
 * layer. Loaded via chrome.scripting.registerContentScripts() with
 * runAt: 'document_start' on <all_urls> so it is part of the document's
 * stylesheet origin set before any HTML body content is parsed. The
 * marker class html.iboss-blur-all-images is added by
 * blurAllImagesContent.js as its very first synchronous action, also at
 * document_start, before any <img> element appears in the DOM. This
 * guarantees that every image is blurred on first paint - there is no
 * first-paint window where an image is visible.
 *
 * Un-blurring is opt-in: only an <img> or <video> tagged
 * data-iboss-image="allow" by JS (after the local NSFW classifier
 * approves it - for a <video> that means classifying its poster image -
 * or after the size-gate auto-allows a sub-threshold icon/sprite) gets
 * its filter cleared. Everything else stays blurred.
 *
 * The marker class is scoped so the rules are inert on every page until
 * the content script confirms the feature is enabled and adds it; on a
 * tab where the master switch is off the class is never set (or is
 * removed at runtime) and these rules do nothing.
 *
 * This feature deliberately shares the data-iboss-image attribute with
 * the search-engine layer (safeImageBlur.css): the content scripts
 * never run the general-page and search-engine pipelines on the same
 * frame (blurAllImagesContent.js yields on search-engine pages), so the
 * attribute has a single owner per frame and "allow" means the same
 * thing to both stylesheets.
 */

/*
 * <video> policy: only the still matters. A <video> is blurred when it
 * declares a poster image that hasn't been approved yet (the poster is a
 * still that could be adult), or when it was explicitly blocked (adult
 * poster / caption). A <video> with NO poster attribute - the YouTube /
 * HTML5 player, hover-preview previews, and ad players, which paint from
 * a blob/MSE source rather than an http poster - is NEVER blurred here:
 * blurring it made videos unplayable and suppressed the play button.
 * The video's still in search results is a separate <img> (handled by
 * the img rule above) or the poster handled below, so adult stills are
 * still blurred; we just don't cripple live playback.
 */
html.iboss-blur-all-images img:not([data-iboss-image="allow"]),
html.iboss-blur-all-images video[poster]:not([data-iboss-image="allow"]),
html.iboss-blur-all-images video[data-iboss-image="block"] {
    filter: blur(28px) !important;
    transition: filter 120ms ease-out;
}

/*
 * Defense-in-depth against revealing the original via the image itself:
 * a not-yet-approved image 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 blurAllImagesContent.js is the
 * primary block for clicks, drags, and the right-click "Save image as"
 * context menu; this stops the browser's native image-drag/selection.
 * Applied to a <video> only while it is blurred (poster-bearing and
 * not-yet-approved, or blocked) - never to a playable posterless player.
 */
html.iboss-blur-all-images img:not([data-iboss-image="allow"]),
html.iboss-blur-all-images video[poster]:not([data-iboss-image="allow"]),
html.iboss-blur-all-images video[data-iboss-image="block"] {
    -webkit-user-drag: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
}

html.iboss-blur-all-images img[data-iboss-image="allow"],
html.iboss-blur-all-images video[data-iboss-image="allow"] {
    filter: none !important;
    transition: filter 120ms ease-out;
}

/*
 * Suppress interaction only on media that is actually blocked: a blocked
 * <img> and a blocked <video> (adult poster/caption). Pending images and
 * pending poster-videos rely on the capture-phase JS guard instead (it
 * only fires on a poster-bearing, not-yet-approved video), so a posterless
 * player keeps working - its play button must remain clickable.
 */
html.iboss-blur-all-images img[data-iboss-image]:not([data-iboss-image="allow"]),
html.iboss-blur-all-images video[data-iboss-image="block"] {
    pointer-events: none !important;
}

/*
 * Do NOT force pointer-events:auto on an approved image/video. The
 * suppress rule above only ever sets pointer-events:none on
 * :not([data-iboss-image="allow"]) elements, so once a media is
 * "allow" our none no longer applies and there is nothing to undo -
 * the element keeps whatever pointer-events the PAGE authored. Forcing
 * auto !important here would override a page that deliberately sets
 * pointer-events:none (mouse-following cursor overlays, hit-test
 * shields, decorative layers) - e.g. PBS Kids' create-a-drawing game
 * paints a #ghost-cursor span under the pointer with pointer-events:
 * none; overriding it to auto makes that span swallow every click, so
 * drawing and every control go dead.
 */

/*
 * CSS background-image thumbnails (ad-widget tiles, tube-site posters
 * rendered as a background on an otherwise-empty element instead of an
 * <img>/<video>).
 *
 * Two triggers:
 *   - [style*="background-image"]:empty - an inline background-image on
 *     an empty element. This matches at document_start, so these blur
 *     before first paint just like <img>/<video>. :empty is required:
 *     filter:blur blurs the whole subtree, so blurring a text-bearing
 *     element would hide its text - empty elements have none to lose.
 *   - [data-iboss-bg] - the marker the content script sets once it
 *     detects (via getComputedStyle) that an element paints a
 *     background-image. This is the only way to catch CLASS-based
 *     backgrounds, which a stylesheet can't select; there is a brief
 *     post-detection window before the marker lands (unlike the inline
 *     case there is no pre-paint guarantee for class-based backgrounds).
 *
 * Un-blur is opt-in via data-iboss-image="allow" exactly as for images.
 */
html.iboss-blur-all-images [style*="background-image"]:empty:not([data-iboss-image="allow"]),
html.iboss-blur-all-images [data-iboss-bg]:not([data-iboss-image="allow"]) {
    filter: blur(28px) !important;
    transition: filter 120ms ease-out;
    -webkit-user-drag: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
    pointer-events: none !important;
}

html.iboss-blur-all-images [data-iboss-bg][data-iboss-image="allow"] {
    filter: none !important;
    transition: filter 120ms ease-out;
}

/*
 * Education-benign fail-OPEN.
 *
 * When the content script determines the frame is confidently benign AND
 * reads as a learning site (educationContextDetected), it adds
 * data-iboss-page-edu-benign="1" to <html>. On such a page blurring must be
 * off completely (matches the education bypass, but auto-detected). The base
 * rules above fail CLOSED - they blur every img/background that is not
 * explicitly data-iboss-image="allow" - which pins a tile the pipeline never
 * got to resolve: one that never loaded, was never fetched (a responsive
 * hero <img> whose variant the browser skipped), or is otherwise pending.
 * These rules flip that default to fail OPEN for anything NOT affirmatively
 * blocked: only data-iboss-image="block" keeps blurring here, and on an
 * education-benign page even those are relaxed to "allow" by the content
 * script's strong/marginal reconciliation, so genuine adult tiles are still
 * covered while benign navigational/hero art is revealed. Higher specificity
 * than the base rules (extra attribute selector) so it wins with !important.
 */
html.iboss-blur-all-images[data-iboss-page-edu-benign="1"] img:not([data-iboss-image="block"]),
html.iboss-blur-all-images[data-iboss-page-edu-benign="1"] video[poster]:not([data-iboss-image="block"]),
html.iboss-blur-all-images[data-iboss-page-edu-benign="1"] [style*="background-image"]:empty:not([data-iboss-image="block"]),
html.iboss-blur-all-images[data-iboss-page-edu-benign="1"] [data-iboss-bg]:not([data-iboss-image="block"]) {
    filter: none !important;
    transition: filter 120ms ease-out;
}
