/* THE BLUE PENCIL · texture layer 1: paper grain
   Loads after the part css (pack_tool.py LAYER_CSS); remove the layer by deleting its <link>.
   JC's values (15 Nov 2026): grain on the DESK only (html, body), behind the boxes. The page, cards, sheets,
   .frame, .ruled and [data-overlay] keep their own flat fill, so they carry no grain and their ruling is the
   signed one, untouched (the "on the boxes too" path is not built). Speck colour is the theme's --ink
   (neutral, not ultramarine); style is the dense soft tint (the mock's grainURL(c, a, false)).
   A data: SVG cannot read CSS variables (R7), so each theme bakes its own tile: the colour is that theme's
   --ink, the feColorMatrix alpha is --grain-a / .8 (the dense recipe: fractal noise alpha peaks near .8, so the
   drawn tint peaks near --grain-a). check_texture.py measures what is drawn; tests/test_grain.py holds the
   baked numbers to the tokens. The one web-address-looking string here is the SVG namespace, which a data:
   SVG needs to render at all; nothing is ever requested.

   data-plain: the attribute a writing surface carries (the capture editor inherits this contract; an author's
   own sentences never sit on texture). Grain is only ever the own background of <html> and <body>, so nothing
   inside a [data-plain] surface can get grain; the surface paints its own opaque page fill (as every writing
   surface does), so the desk's grain cannot show through it either. An <html> or <body> that carries
   data-plain drops the desk grain itself. */
:root {
  --grain-a: .065; /* grain strength: the drawn tint's peak alpha. Measured on the Pencil desk it lowers the average by
                      about 10 levels per channel; words and marks on it still pass; the disabled edge falls to about 2.78:1 on
                      the mean and takes the WCAG 1.4.11 disabled-control exemption (JC, 15 Nov 2026) */
  --gs: 2.5;       /* speck size: the 160px tile drawn at 2.5x, so one tile period is 400px */
  --grain-img: url("data:image/svg+xml;utf8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20width%3D'160'%20height%3D'160'%3E%3Cfilter%20id%3D'n'%20x%3D'0'%20y%3D'0'%20width%3D'100%25'%20height%3D'100%25'%20color-interpolation-filters%3D'sRGB'%3E%3CfeTurbulence%20type%3D'fractalNoise'%20baseFrequency%3D'.8'%20numOctaves%3D'2'%20seed%3D'7'%20stitchTiles%3D'stitch'%2F%3E%3CfeColorMatrix%20values%3D'0%200%200%200%200.071%20%200%200%200%200%200.075%20%200%200%200%200%200.094%20%200%200%200%200.081%200'%2F%3E%3C%2Ffilter%3E%3Crect%20width%3D'100%25'%20height%3D'100%25'%20filter%3D'url(%23n)'%2F%3E%3C%2Fsvg%3E"); /* Pencil: the Pencil --ink at --grain-a / .8 */
  --grain-img-cool: url("data:image/svg+xml;utf8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20width%3D'160'%20height%3D'160'%3E%3Cfilter%20id%3D'n'%20x%3D'0'%20y%3D'0'%20width%3D'100%25'%20height%3D'100%25'%20color-interpolation-filters%3D'sRGB'%3E%3CfeTurbulence%20type%3D'fractalNoise'%20baseFrequency%3D'.8'%20numOctaves%3D'2'%20seed%3D'7'%20stitchTiles%3D'stitch'%2F%3E%3CfeColorMatrix%20values%3D'0%200%200%200%200.153%20%200%200%200%200%200.259%20%200%200%200%200%200.710%20%200%200%200%200.081%200'%2F%3E%3C%2Ffilter%3E%3Crect%20width%3D'100%25'%20height%3D'100%25'%20filter%3D'url(%23n)'%2F%3E%3C%2Fsvg%3E"); /* comparison only, never applied: the ultramarine tint JC turned down */
}

/* the desk: html and body both paint it (kit.css lines 7 and 9), so both carry the grain over their desk colour.
   Equal-or-higher specificity than kit.css's html / body, and later, so this wins without touching kit.css. */
html:not([data-plain]), html:not([data-plain]) > body:not([data-plain]) {
  background-image: var(--grain-img);
  background-size: calc(160px * var(--gs)) calc(160px * var(--gs));
}

/* forced colours and print: no grain (the desk colour and every ruling stay as signed) */
@media (forced-colors: active) {
  html:not([data-plain]), html:not([data-plain]) > body:not([data-plain]) { background-image: none; }
}
@media print {
  html:not([data-plain]), html:not([data-plain]) > body:not([data-plain]) { background-image: none; }
}
