/* Beeldfamilie (Rubber Ducky Studio): one treatment for every photo on the page, so phone photos from Google or
   Instagram and stock photos become one family. Turn it on with <body data-beeld="zwartwit|duotoon|toon|warm|koel">
   (a section, card or photo may carry its own data-beeld, also "uit"). Colours come from the brand sheet:
   --beeld-donker / --beeld-licht (duotoon; default --inkt / --papier), --beeld-toon / --beeld-sterkte (toon).
   zwartwit, warm and koel are plain CSS filters (cheap, they work without the JS). duotoon and toon need
   beeldfamilie.js: it builds an SVG filter from the variables; until then a CSS stand-in shows.
   The JS also evens out each photo (brightness, contrast, saturation) towards the family; see KAART.md. */

/* 1. The treatments. Each sets the filter list and its "colour back" twin with the same functions in the same order,
      so the hover back to the real colours can transition. */
[data-beeld="zwartwit"], [data-beeld="zwart-wit"] { /* zwart-wit: as playbook/merkblad.md writes it */
  --beeld-filter: grayscale(1) contrast(1.05) brightness(1.02);
  --beeld-filter-0: grayscale(0) contrast(1) brightness(1);
}
/* warm and koel: a common cast, loud photos calmed (saturate below 1) and a hint of matte (contrast just below 1):
   together with the evening out per photo this is what makes stock and phone photos one set */
[data-beeld="warm"] {
  --beeld-filter: sepia(.28) saturate(.8) contrast(.98) brightness(1.03);
  --beeld-filter-0: sepia(0) saturate(1) contrast(1) brightness(1);
}
/* cool: invert, a little sepia, invert back turns the warm cast into a cool one (blue-grey shadows, white whites)
   without turning the colours themselves; the twin keeps both inverts at 1 (invert(.5) would be flat grey) */
[data-beeld="koel"] {
  --beeld-filter: invert(1) sepia(.3) invert(1) saturate(.78) contrast(.98) brightness(1.03);
  --beeld-filter-0: invert(1) sepia(0) invert(1) saturate(1) contrast(1) brightness(1);
}
/* duotoon and toon: stand-ins until the JS has built the SVG filter (and for a page without the JS) */
[data-beeld="duotoon"] {
  --beeld-filter: grayscale(1) contrast(1.08);
  --beeld-filter-0: grayscale(0) contrast(1);
}
[data-beeld="toon"] {
  --beeld-filter: sepia(.25) saturate(.9);
  --beeld-filter-0: sepia(0) saturate(1);
}
/* a section, card or photo that keeps its real colours inside a treated page */
[data-beeld="uit"] {
  --beeld-filter: saturate(1);
  --beeld-filter-0: saturate(1);
}

/* 2. What gets treated: img, video and elements marked data-beeld-foto (a background photo: put it on the layer that
      carries the background, never on a wrapper with text, or the text is filtered too). Not: data-beeld-uit,
      logos (src with "logo", data-logo) and SVG icons. :where() keeps this at zero specificity, so a filter the demo
      or a component sets on an image wins (to darken a photo behind text, use --beeld-extra instead).
      --beeld-b/-c/-s: per photo, set by the JS (evening out); --beeld-svg: the SVG filter of duotoon and toon. */
:where([data-beeld] :is(img, video, [data-beeld-foto]), :is(img, video, [data-beeld-foto])[data-beeld]):where(:not(
  [data-beeld-uit], [data-beeld-uit] *, [data-logo], [data-logo] *,
  img[src*="logo" i], img[srcset*="logo" i], img[src*=".svg" i], img[src^="data:image/svg" i])) {
  filter: brightness(var(--beeld-b, 1)) contrast(var(--beeld-c, 1)) saturate(var(--beeld-s, 1)) var(--beeld-svg, var(--beeld-filter)) var(--beeld-extra,);
}

/* 3. Optional: data-beeld-hover="kleur" on a photo or card: the real colours come back under the mouse (desktop only).
      CSS treatments transition here; duotoon and toon (data-beeld-svg, set by the JS) are tweened by the JS. */
@media (hover: hover) and (pointer: fine) {
  :where([data-beeld-hover="kleur"] :is(img, video, [data-beeld-foto]), :is(img, video, [data-beeld-foto])[data-beeld-hover="kleur"]) {
    transition: filter .7s cubic-bezier(.22, .61, .36, 1);
  }
  :where([data-beeld-hover="kleur"]:is(:hover, :focus-within) :is(img, video, [data-beeld-foto]), :is(img, video, [data-beeld-foto])[data-beeld-hover="kleur"]:hover):where([data-beeld] *, [data-beeld]):where(:not(
    [data-beeld-svg], [data-beeld-uit], [data-beeld-uit] *, [data-logo], [data-logo] *,
    img[src*="logo" i], img[srcset*="logo" i], img[src*=".svg" i], img[src^="data:image/svg" i])) {
    filter: brightness(1) contrast(1) saturate(1) var(--beeld-filter-0) var(--beeld-extra,);
  }
}

/* 4. Optional grain over the whole page: --beeld-korrel from 0 (off, default) to 1. A fixed layer with a static
      noise tile (plain alpha, no blend mode: cheap while scrolling). Uses body::before; a demo with its own grain
      leaves --beeld-korrel at 0. */
body[data-beeld]::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  pointer-events: none;
  opacity: calc(var(--beeld-korrel, 0) * .16);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='k'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 1.6 -.3 0 0 0 1.6 -.3 0 0 0 1.6 -.3 0 0 0 0 1'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23k)'/%3E%3C/svg%3E") 0 0 / 180px 180px;
}

/* 5. Less motion: the treatment stays (it is not an animation); only the hover fade goes */
@media (prefers-reduced-motion: reduce) {
  :where([data-beeld-hover] :is(img, video, [data-beeld-foto]), :is(img, video, [data-beeld-foto])[data-beeld-hover]) { transition: none; }
}
