/* -- Glass -----------------------
  The Sketch shared styles "Glass" and "Glass (Secondary)", as classes
    .glass            gray 20% fill, 16px background blur, soft outer and inner glows
    .glass-secondary  dark gray (#202020) 20% fill, 32px background blur, wide faint inner glow (the dialog sheet)
  (The dock's white-fill pills are the "Dock" style: not reusable, built in dock.js.)
  Both also get a 2px gradient rim in overlay blend from glass.js.

  Usage
    <head>       <link rel="stylesheet" href="/lib/styles/glass.css">
    <body> end   <script src="/lib/styles/glass.js"></script>
    class="glass" or class="glass-secondary" on any element, which needs its own position and size

  Notes
  - Fixed: fill, blur, glows, rim. Only the radius and the scale are per element
  - Customizable: --glass-radius (in --u units, default 1.25) and --s (scale, default 1, e.g. on mobile)
  - Every length is a multiple of --u, which is 1rem times --s. --s inherits, so a nested glass element scales with its parent. Sketch scales the pills on mobile but not the rim, so the rim stays 2 canvas px
  - Keep the rim's container free of transform / z-index / position: fixed, or the overlay blend can't see the page behind it
*/

.glass, .glass-secondary {
  --u: calc(var(--s, 1) * 1rem);
  border-radius: calc(var(--glass-radius, 1.25) * var(--u));   /* the layer's radius, not part of the style */
}
/* Glass: gray 20%, 16px background blur, glow 0 0 48 @12%, inner glow 24 @32%. */
.glass {
  background: rgba(128,128,128,0.2);
  backdrop-filter: blur(calc(0.833 * var(--u)));
  -webkit-backdrop-filter: blur(calc(0.833 * var(--u)));
  box-shadow:
    0 0 calc(2.5 * var(--u)) rgba(255,255,255,0.12),
    inset 0 0 calc(1.25 * var(--u)) rgba(255,255,255,0.32);
}
/* Glass (Secondary): #202020 20%, 32px background blur, glow 0 0 48 @12%, inner glow 128 @16%. */
.glass-secondary {
  background: rgba(32,32,32,0.2);
  backdrop-filter: blur(calc(1.667 * var(--u)));
  -webkit-backdrop-filter: blur(calc(1.667 * var(--u)));
  box-shadow:
    0 0 calc(2.5 * var(--u)) rgba(255,255,255,0.12),
    inset 0 0 calc(6.667 * var(--u)) rgba(255,255,255,0.16);
}

/* Rim light. Each rim is a sibling svg placed after its surface, because a backdrop-filter
   element is an isolated group and a rim nested inside would blend only against the pill's own
   fill. glass.js sizes and positions it over the surface. Keep the rim's container free of
   transform / z-index / position:fixed, or the overlay blend stops seeing the page behind. */
.glass-rim {
  position: absolute;
  left: 0; top: 0; width: 0; height: 0;
  pointer-events: none;
  mix-blend-mode: overlay;
}
/* Inside a <dialog> the rim is wrapped in a popover (see glass.js): its own top-layer element, so the
   overlay blend sits on the wrapper, in the root stacking context, instead of isolating the dialog.
   The UA popover styles (inset 0, margin auto, border, padding, background) are all reset. */
.glass-rim-pop {
  position: fixed; inset: auto; left: 0; top: 0; width: 0; height: 0;
  margin: 0; padding: 0; border: 0; background: none; overflow: visible;
  pointer-events: none; mix-blend-mode: overlay;
}
.glass-rim-pop .glass-rim { position: static; display: block; width: 100%; height: 100%; mix-blend-mode: normal; }
