/*
 * Grounds: what lies behind a page. Six layers, each switched on by a class on <html>, alone or
 * together, on any page of the site. They are the lower fidelity of the screens and tape the site
 * remembers: nothing here moves.
 *
 *   ground-light    a pool of blue light at the top left
 *   ground-dither   that pool in six colours with an ordered dither, as 256 colours showed it
 *                   (it takes the place of ground-light, and dithers ground-water too)
 *   ground-grain    tape grain
 *   ground-water    one frozen frame of the homepage's water, tiled across the top
 *   ground-haze     a second pool, violet, low at the right
 *   ground-lines    scanlines
 *
 * A page whose ground is a canvas, as the homepage's is, puts an empty element of class
 * ground-sheet above the canvas: the grain, the haze and the lines are drawn on that. The dither
 * is then the canvas's own business (light.js reads ground-dither).
 *
 * The pictures are drawn by tools/art/ground.py. concepts/ground.html switches the layers on a
 * live page, to try them.
 */
html[class*="ground-"] body {
  background-color: var(--night, #020205);
  background-image: var(--ground-lines, none), var(--ground-grain, none), var(--ground-haze, none), var(--ground-pool, none);
  background-repeat: repeat, repeat, no-repeat, no-repeat;
  background-position: 0 0, 0 0, 0 0, var(--ground-pool-at, 0 0);
  background-size: auto, 160px 160px, auto, var(--ground-pool-size, auto);
}
.ground-sheet {
  position: absolute; z-index: -1; inset: 0; pointer-events: none;
  background-image: var(--ground-lines, none), var(--ground-grain, none), var(--ground-haze, none);
  background-repeat: repeat, repeat, no-repeat;
  background-size: auto, 160px 160px, auto;
}

/* The pool is placed in pixels from the page's top left. A percentage would be taken of the whole
   document's height, and would lift the light out of sight on a long page. */
html.ground-light { --ground-pool: radial-gradient(1200px 680px at 128px -64px, rgba(var(--glow, 133, 143, 250), .34), rgba(var(--glow, 133, 143, 250), .09) 46%, transparent 72%); }
/* The same pool as a picture: twice its shown size, so a dither cell is two pixels square. */
html.ground-dither { --ground-pool: url("/ground/pool.png"); --ground-pool-at: -132px 0; --ground-pool-size: 1140px 440px; }

/* Where a canvas is the ground the pool would lie unseen under it, so it is not fetched. */
html.ground-dither:has(.ground-sheet) { --ground-pool: none; }

html.ground-grain { --ground-grain: url("/ground/grain.png"); }

html.ground-water body::before {
  content: ""; position: absolute; z-index: -1; top: 0; left: 0; right: 0; height: 980px; pointer-events: none;
  background: url("/ground/water.png") 0 0 / 256px 190px; mix-blend-mode: screen;
  -webkit-mask-image: linear-gradient(#000, #000 34%, transparent); mask-image: linear-gradient(#000, #000 34%, transparent);
}
html.ground-water.ground-dither body::before { background-image: url("/ground/water-dither.png"); }

html.ground-haze { --ground-haze: radial-gradient(1000px 700px at 104% 620px, rgba(154, 92, 255, .2), rgba(154, 92, 255, .06) 50%, transparent 74%); }

html.ground-lines { --ground-lines: repeating-linear-gradient(to bottom, rgba(255, 255, 255, .045) 0 1px, transparent 1px 3px); }
