/* ============================================================
   Liquid Glass — reusable frosted/refracting surface
   Technique: https://kube.io/blog/liquid-glass-css-svg/
   Extracted from the United Charitable v4 homepage mockup (2026-07).

   Usage
   -----
   1. Paste the SVG filter from liquid-glass.svg once per page (anywhere
      in <body>; it renders nothing).
   2. Add class="lg" to any element that should be glass.
   3. Optional modifiers: .lg--pill (bar/nav), .lg--panel (drawer/sheet),
      .lg--subtle (light touch), .lg--dark (glass over dark ground).

   Requirements
   ------------
   - The element needs something BEHIND it to refract (a photo, gradient,
     page content). Glass over a flat solid colour looks like nothing.
   - Keep text on glass at 4.5:1+ against the lightest area behind it.
   ============================================================ */

:root {
  --lg-tint: 255 255 255;      /* surface colour, space-separated RGB   */
  --lg-alpha: 0.52;            /* surface opacity — lower = more glassy */
  --lg-blur: 7px;              /* blur applied AFTER refraction         */
  --lg-blur-fallback: 18px;    /* blur where the SVG filter can't run   */
  --lg-saturate: 1.35;         /* backdrop colour boost                 */
  --lg-radius: 20px;
  --lg-edge: 255 255 255;      /* rim highlight colour                  */
  --lg-edge-alpha: 0.75;
  --lg-shadow: 10px 34px rgba(10, 42, 73, 0.16);
}

.lg {
  position: relative;
  border-radius: var(--lg-radius);
  overflow: hidden;
  background: rgb(var(--lg-tint) / var(--lg-alpha));
  border: 1px solid rgb(var(--lg-edge) / 0.7);
  /* Fallback first: engines without SVG-in-backdrop-filter keep this. */
  -webkit-backdrop-filter: blur(var(--lg-blur-fallback)) saturate(var(--lg-saturate));
  /* Refraction + blur. The filter bends the backdrop at the bezel. */
  backdrop-filter: url(#lg-filter) blur(var(--lg-blur)) saturate(var(--lg-saturate));
  box-shadow:
    0 var(--lg-shadow),
    inset 0 1px 0 rgb(var(--lg-edge) / var(--lg-edge-alpha));
}

/* iOS/Safari cannot run SVG filters in backdrop-filter, and because the
   unprefixed declaration above wins over the -webkit- one they would get NO
   glass at all. -webkit-touch-callout is iOS-only, so Chromium is untouched.

   Beyond restoring the blur, this fakes the refracting bezel with pure CSS: a
   masked rim carrying its OWN backdrop-filter — brighter, more saturated and
   less blurred than the centre — which reads as light bending at a lens edge.
   Tune the rim with --lg-rim (thickness) and --lg-rim-bright. */
@supports (-webkit-touch-callout: none) {
  .lg {
    backdrop-filter: blur(var(--lg-blur-fallback)) saturate(var(--lg-saturate));
  }
  /* OPT-IN (add class="lg lg--rim"). Tested on iPhone it can read as a hard
     border ring rather than a bezel, especially on small surfaces — try it,
     don't assume it. Larger panels tolerate it better than pills. */
  .lg--rim::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    border-radius: inherit;
    padding: var(--lg-rim, 13px);
    -webkit-backdrop-filter: blur(3px) brightness(var(--lg-rim-bright, 1.12)) saturate(1.7);
    backdrop-filter: blur(3px) brightness(var(--lg-rim-bright, 1.12)) saturate(1.7);
    /* keep only the border region: full box XOR content box */
    -webkit-mask: linear-gradient(#000, #000) content-box, linear-gradient(#000, #000);
    -webkit-mask-composite: xor;
    mask-image: linear-gradient(#000, #000), linear-gradient(#000, #000);
    mask-clip: content-box, border-box;
    mask-composite: exclude;
  }
  .lg--pill { --lg-rim: 8px; }
  .lg--dark { --lg-rim-bright: 0.92; }   /* darken instead of lighten */
}

/* Firefox has backdrop-filter but not SVG filters in it — same treatment. */
@supports (-moz-appearance: none) {
  .lg {
    backdrop-filter: blur(var(--lg-blur-fallback)) saturate(var(--lg-saturate));
  }
}

/* ---------- Modifiers ---------- */

/* Floating bar / nav pill */
.lg--pill {
  --lg-radius: 999px;
  --lg-alpha: 0.58;
  --lg-blur: 5px;
  --lg-blur-fallback: 22px;
  --lg-saturate: 1.6;
  --lg-shadow: 12px 32px rgba(10, 42, 73, 0.14);
}

/* Side sheet / drawer — heavier, since content sits on it */
.lg--panel {
  --lg-alpha: 0.86;
  --lg-blur-fallback: 24px;
  --lg-saturate: 1.4;
}

/* Barely-there glass for large surfaces */
.lg--subtle {
  --lg-alpha: 0.3;
  --lg-blur: 4px;
  --lg-blur-fallback: 10px;
  --lg-saturate: 1.2;
  --lg-edge-alpha: 0.4;
}

/* Glass over a dark ground (dark hero, video) */
.lg--dark {
  --lg-tint: 12 22 38;
  --lg-alpha: 0.35;
  --lg-edge-alpha: 0.28;
  --lg-shadow: 12px 36px rgba(0, 0, 0, 0.35);
  color: #fff;
}

/* ---------- Optional extras ---------- */

/* Specular sheen: a lit top-left corner. Add class="lg lg--sheen".
   Skip it when the element already has bright content in that corner. */
.lg--sheen::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(133deg,
    rgb(255 255 255 / 0.4) 0%,
    rgb(255 255 255 / 0.1) 22%,
    rgb(255 255 255 / 0) 46%);
}

/* Physical hover for interactive glass. Add class="lg lg--lift". */
.lg--lift { transition: transform .18s ease, box-shadow .18s ease; }
.lg--lift:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 44px rgba(10, 42, 73, 0.2),
              inset 0 1px 0 rgb(var(--lg-edge) / 0.85);
}

@media (prefers-reduced-motion: reduce) {
  .lg--lift { transition: none; }
  .lg--lift:hover { transform: none; }
}
