/* LBSA UI kit: the animated hex field (LbHexField, lbsa-hexfield.js).

   Parent contract: the field fills its parent (position: absolute; inset: 0) and sits behind the parent's other children
   (z-index below them), so the parent must be a containing block and its own stacking context:
       .menu { position: relative; isolation: isolate; overflow: hidden; background: var(--lb-nav-bg); }
   Put the field first in the parent; the parent's other children paint over it. The parent must not scroll its own content (the field
   would scroll away with it): put a scrolling list inside the isolated parent, not on it. Pointer moves are taken from the closest
   element with data-lb-hex-zone, else from the parent (the field itself has pointer-events: none).

   Layers inside the field: the stage (the static gradient, and the canvas the script adds), then the scrim. The scrim is the host
   background colour (--lb-hex-scrim) at --lb-hex-scrim-min opacity at its lightest and fully opaque at the top and bottom edge: the
   field fades into the surface there. The script limits the brightest (dark host) or darkest (light host) colour it can write from the
   scrim and the text tokens of the preset, so the text keeps its contrast over the brightest possible frame (guardLimit in the script).

   Tokens (override on :root, a theme, or the field's Class):
     --lb-hex-base        tile colour (the script lights it: tops are about 0.7 of it)
     --lb-hex-scrim       the host background the scrim fades to
     --lb-hex-scrim-min   scrim opacity at its lightest, 0..1 (unitless)
     --lb-hex-glow        strength of the static gradient shown while there is no canvas
     --lb-hex-layer       the field's z-index inside its isolated parent */

:root {
  --lb-hex-layer: -1;
  --lb-hex-scrim-min: 0.5;
  --lb-hex-glow: 9%;
  /* the menu (dark in both themes at present): tiles a step lighter than the menu background */
  --lb-hex-base: color-mix(in srgb, var(--lb-nav-bg-2) 92%, var(--lb-nav-text));
  --lb-hex-scrim: var(--lb-nav-bg);
}

[data-theme="dark"] {
  --lb-hex-base: color-mix(in srgb, var(--lb-nav-bg-2) 90%, var(--lb-nav-text));
  --lb-hex-scrim: var(--lb-nav-bg);
}

.lb-hexfield {
  position: absolute;
  inset: 0;
  z-index: var(--lb-hex-layer);
  overflow: hidden;
  pointer-events: none;
  contain: strict;
  user-select: none;
}

/* a field on a page surface instead of the menu: the surface decides, so a light theme gets light tiles */
.lb-hexfield--panel,
.lb-hexfield--hero {
  --lb-hex-base: color-mix(in srgb, var(--lb-surface-3) 82%, var(--lb-surface));
  --lb-hex-scrim: var(--lb-surface);
}

.lb-hexfield__stage {
  position: absolute;
  inset: 0;
}

/* the static gradient: what a menu without WebGL2 (or switched off) shows, and what is under the canvas while it fades in */
.lb-hexfield__stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 60% at 100% 0%, color-mix(in srgb, var(--lb-accent) var(--lb-hex-glow), transparent), transparent 70%),
    radial-gradient(90% 40% at 0% 100%, color-mix(in srgb, var(--lb-accent) calc(var(--lb-hex-glow) * 0.5), transparent), transparent 70%);
  transition: opacity var(--lb-dur-4) var(--lb-ease);
}

/* gone while a live canvas covers it: the contrast guard of the script counts the canvas and the scrim, not this gradient */
.lb-hexfield__stage:has(> .lb-hexfield__canvas.is-live)::before {
  opacity: 0;
}

.lb-hexfield__canvas {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  opacity: 0;
  transition: opacity calc(var(--lb-dur-4) * 3) var(--lb-ease);
}

.lb-hexfield__canvas.is-live {
  opacity: 1;
}

.lb-hexfield__scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    var(--lb-hex-scrim) 0%,
    color-mix(in srgb, var(--lb-hex-scrim) calc(var(--lb-hex-scrim-min) * 100%), transparent) 16%,
    color-mix(in srgb, var(--lb-hex-scrim) calc(var(--lb-hex-scrim-min) * 100%), transparent) 84%,
    var(--lb-hex-scrim) 100%
  );
}

@media (prefers-reduced-motion: reduce) {
  .lb-hexfield__canvas,
  .lb-hexfield__stage::before { transition: none; }
}

/* system colours replace every colour in forced-colors mode and a printout has no use for a moving background */
@media (forced-colors: active), print {
  .lb-hexfield { display: none; }
}
