/* Light Glass Button - IGM's build of Originkit's component; see light-glass-button.js.
   Defaults are Originkit's tuned look: a 40px label on clear glass, a 6px edge, a soft light that follows the
   pointer. Set the custom properties on the .lgb element itself.

   The glass recipe is fixed in the original and fixed here (it is not a setting):
     face    backdrop blur 20px, saturate 180%, brightness 108%, 16% of --lgb-fill as the tint
     edge    backdrop saturate 220%, brightness 140% - no blur, the edge samples the page sharp
     shadow  0 8px 24px rgba(0,0,0,.18)
   Every length below is multiplied by --lgb-k, so --lgb-scale resizes the whole button, glass included. */
.lgb{
  --lgb-scale:1;                 /* the whole button: 1 is the designed size, .5 is half */
  --lgb-fit:1;                   /* the script lowers this when the button is wider than its parent */
  --lgb-k:calc(var(--lgb-scale) * var(--lgb-fit));

  --lgb-fill:#FFFFFF;            /* the glass tint colour; only 16% of it lands, whatever its own alpha */
  --lgb-text:#FFFFFF;
  --lgb-tint:.16;
  --lgb-size:40px;
  --lgb-font:Inter,system-ui,-apple-system,"Segoe UI",sans-serif;
  --lgb-weight:500;
  --lgb-pad-y:40px; --lgb-pad-x:64px;
  --lgb-gap:12px; --lgb-icon:24px;
  --lgb-round:38;                /* corner, in % of the biggest possible radius: 100 is a pill, 0 is square */
  --lgb-blur:20px;

  --lgb-stroke:6px;              /* edge width; 0 removes the edge */
  --lgb-stroke-a:rgba(255,255,255,.55);   /* resting edge: a gradient from A to B ... */
  --lgb-stroke-b:rgba(255,255,255,.25);
  --lgb-stroke-angle:180deg;
  --lgb-stroke-solid:rgba(255,255,255,.45);  /* ... or, with data-stroke="solid", this one colour */
  --lgb-light:rgba(255,255,255,.45);         /* the colour of the light (read once, by the script) */
  --lgb-focus:var(--lgb-text);

  --lgb-sw:calc(var(--lgb-stroke) * var(--lgb-k));
  /* The script measures the box and writes the exact radius here. Before it runs, and without it, this is
     the same number worked out from the label's line height and the padding (true while the button is
     wider than it is tall). */
  --lgb-r:calc((var(--lgb-size) * 1.5 + var(--lgb-pad-y) * 2) * var(--lgb-k) / 2 * var(--lgb-round) / 100);
  --mx:50%; --my:50%;            /* the light's place, in % of the face; the script moves them */

  position:relative; display:inline-flex; flex:none; vertical-align:middle;
  min-width:calc(80px * var(--lgb-k)); min-height:calc(40px * var(--lgb-k));
  /* No overflow:hidden here. The edge grows outward and would be shaved off. */
  border-radius:var(--lgb-r);
  box-shadow:0 calc(8px * var(--lgb-k)) calc(24px * var(--lgb-k)) rgba(0,0,0,.18);
}

/* The face: the glass itself. No will-change on it: that would promote it to its own layer, and a promoted
   element's backdrop-filter clips to the box rectangle instead of the corner radius. */
.lgb-face{
  box-sizing:border-box; flex:1 1 auto; display:flex; align-items:center; justify-content:center;
  position:relative; z-index:1; overflow:hidden; margin:0;
  padding:calc(var(--lgb-pad-y) * var(--lgb-k)) calc(var(--lgb-pad-x) * var(--lgb-k));
  border:0; border-radius:var(--lgb-r);
  color:var(--lgb-text); white-space:nowrap; text-decoration:none;
  cursor:pointer; user-select:none; -webkit-user-select:none;
  touch-action:manipulation; -webkit-tap-highlight-color:transparent;
  background:rgba(255,255,255,var(--lgb-tint));
  -webkit-backdrop-filter:blur(calc(var(--lgb-blur) * var(--lgb-k))) saturate(180%) brightness(108%);
  backdrop-filter:blur(calc(var(--lgb-blur) * var(--lgb-k))) saturate(180%) brightness(108%);
}
/* The colour is a tint, never a plate: its own alpha is dropped and --lgb-tint decides how much lands. */
@supports (color:rgb(from red r g b / .5)){
  .lgb-face{background:rgb(from var(--lgb-fill) r g b / var(--lgb-tint))}
}
.lgb-face:focus-visible{outline:3px solid var(--lgb-focus); outline-offset:calc(var(--lgb-sw) + 3px)}
.lgb-face:focus:not(:focus-visible){outline:none}

/* The light inside the glass, under the label. The script paints its gradients and drives its opacity. */
.lgb-light{
  position:absolute; inset:0; z-index:0; opacity:0; pointer-events:none;
  border-radius:var(--lgb-r); mix-blend-mode:screen;
}

.lgb-content{
  position:relative; z-index:1; display:inline-flex; align-items:center;
  gap:calc(var(--lgb-gap) * var(--lgb-k));
}
.lgb[data-icon-side="right"] .lgb-content{flex-direction:row-reverse}
.lgb-icon{display:block; flex:none; width:calc(var(--lgb-icon) * var(--lgb-k)); height:calc(var(--lgb-icon) * var(--lgb-k)); pointer-events:none}
.lgb-icon svg{display:block; width:100%; height:100%}
.lgb-label{
  font-family:var(--lgb-font); font-weight:var(--lgb-weight);
  font-size:calc(var(--lgb-size) * var(--lgb-k)); line-height:1.5em; letter-spacing:0em; text-align:left;
}

/* The edge, built rather than stroked: one box a stroke-width bigger than the face on every side, masked to
   the band between its border box and content box. The mask also clips the ring's own backdrop-filter, so
   the edge can sample the page sharper and brighter than the face. Both rings ignore the pointer. */
.lgb-stroke,.lgb-strokelight{
  position:absolute; inset:calc(var(--lgb-sw) * -1);
  border-radius:calc(var(--lgb-r) + var(--lgb-sw)); padding:var(--lgb-sw);
  pointer-events:none;
  -webkit-mask-image:linear-gradient(#000 0 0),linear-gradient(#000 0 0);
  mask-image:linear-gradient(#000 0 0),linear-gradient(#000 0 0);
  -webkit-mask-clip:border-box,content-box; mask-clip:border-box,content-box;
  -webkit-mask-composite:xor; mask-composite:exclude;
}
.lgb-stroke{
  z-index:3;
  background:linear-gradient(var(--lgb-stroke-angle),var(--lgb-stroke-a),var(--lgb-stroke-b));
  -webkit-backdrop-filter:saturate(220%) brightness(140%);
  backdrop-filter:saturate(220%) brightness(140%);
}
.lgb[data-stroke="solid"] .lgb-stroke{background:var(--lgb-stroke-solid)}
/* The travelling hot spot on the edge, aimed at the light. The script paints it and sets --la, --lw. */
.lgb-strokelight{z-index:4; opacity:0; mix-blend-mode:screen; --la:0; --lw:30}

/* A browser that cannot blur the page behind: the tint carries the contrast alone, and nothing is filtered. */
@supports not ((backdrop-filter:blur(2px)) or (-webkit-backdrop-filter:blur(2px))){
  .lgb{--lgb-tint:.62}
  .lgb-face,.lgb-stroke{-webkit-backdrop-filter:none; backdrop-filter:none}
}
