/* ==========================================================================
   Liquid Glass
   A CSS/SVG port of the layering model used by rdev/liquid-glass-react:
     layer 0  .lg-refract  — backdrop displaced through an SVG map (refraction)
     layer 1  .lg::before  — inner gloss / bloom
     layer 2  .lg-hl       — cursor-tracked specular blob
     layer 3  .lg::after   — 1px specular rim (conic, masked to the border)
     layer 4  .lg-in       — content
   Refraction needs backdrop-filter: url(); browsers without it fall back to a
   saturated frosted blur, which still reads as glass.
   ========================================================================== */

:root {
  --lg-radius: 24px;
  --lg-blur: 16px;
  --lg-sat: 180%;
  --lg-bright: 1.05;
  --lg-tint: rgba(255, 255, 255, 0.055);
  --lg-rim-strong: rgba(255, 255, 255, 0.9);
  --lg-rim-soft: rgba(255, 255, 255, 0.62);
  --lg-gloss: 0.26;
  --lg-shadow: 0 2px 8px rgba(3, 7, 18, 0.14), 0 18px 46px -14px rgba(3, 7, 18, 0.5);
  --lg-shadow-hover: 0 4px 14px rgba(3, 7, 18, 0.18), 0 30px 70px -18px rgba(3, 7, 18, 0.6);

  --spring: cubic-bezier(0.34, 1.44, 0.58, 1);
  --spring-soft: cubic-bezier(0.22, 1.2, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

[data-theme="light"] {
  --lg-tint: rgba(255, 255, 255, 0.55);
  --lg-rim-strong: rgba(255, 255, 255, 0.98);
  --lg-rim-soft: rgba(255, 255, 255, 0.7);
  --lg-gloss: 0.5;
  --lg-sat: 155%;
  --lg-bright: 1.02;
  --lg-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 14px 38px -16px rgba(15, 23, 42, 0.22);
  --lg-shadow-hover: 0 3px 10px rgba(15, 23, 42, 0.08), 0 26px 60px -20px rgba(15, 23, 42, 0.3);
}

/* SVG filter host: present in the DOM, never painted. */
.lg-svg {
  position: fixed;
  width: 0;
  height: 0;
  pointer-events: none;
  opacity: 0;
}

/* --------------------------------------------------------------- base glass */

.lg {
  position: relative;
  isolation: isolate;
  border-radius: var(--lg-r, var(--lg-radius));
  background: var(--lg-tint);
  -webkit-backdrop-filter: blur(var(--lg-blur)) saturate(var(--lg-sat)) brightness(var(--lg-bright));
  backdrop-filter: blur(var(--lg-blur)) saturate(var(--lg-sat)) brightness(var(--lg-bright));
  box-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.2),
    inset 0 -1px 0 0 rgba(255, 255, 255, 0.07),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    var(--lg-shadow);
  transition:
    transform 0.6s var(--spring),
    box-shadow 0.5s var(--ease-out),
    background 0.4s ease,
    border-radius 0.6s var(--spring);
}

/* layer 1 — inner gloss. Screen blend keeps it from muddying the backdrop. */
.lg::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
  pointer-events: none;
  mix-blend-mode: screen;
  background:
    radial-gradient(125% 85% at 18% -12%, rgba(255, 255, 255, var(--lg-gloss)), rgba(255, 255, 255, 0) 58%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0) 42%, rgba(255, 255, 255, 0.055) 100%);
}

/* layer 3 — the specular rim. This is the detail that sells the material:
   light does not wrap a lens evenly, so the highlight is conic, not uniform. */
.lg::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: inherit;
  padding: 1px;
  pointer-events: none;
  opacity: 0.85;
  background: conic-gradient(
    from 135deg,
    rgba(255, 255, 255, 0) 0deg,
    var(--lg-rim-strong) 52deg,
    rgba(255, 255, 255, 0) 122deg,
    rgba(255, 255, 255, 0) 214deg,
    var(--lg-rim-soft) 292deg,
    rgba(255, 255, 255, 0) 356deg
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  transition: opacity 0.45s var(--ease-out);
}

/* layer 4 — content sits above every optical layer. */
.lg-in {
  position: relative;
  z-index: 4;
}

/* Buttons and pills keep flat markup, so lift their children directly. */
.lg-btn > *,
.lg-pill > * {
  position: relative;
  z-index: 4;
}

.lg-btn > .lg-hl,
.lg-btn > .lg-refract,
.lg-pill > .lg-hl,
.lg-pill > .lg-refract {
  z-index: 2;
}

.lg-pill > .lg-in {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

[hidden] {
  display: none !important;
}

/* Refraction layer kept in the DOM for optional experiments, but never painted.
   The channel-split displacement map produced red/green rim artefacts. */
.lg-refract {
  display: none !important;
}

/* layer 2 — cursor-tracked specular blob (rdev's "elasticity" highlight). */
.lg-hl {
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  mix-blend-mode: screen;
  background: radial-gradient(
    circle 160px at var(--lg-mx, 50%) var(--lg-my, 50%),
    rgba(255, 255, 255, 0.34),
    rgba(255, 255, 255, 0.08) 45%,
    rgba(255, 255, 255, 0) 72%
  );
  transition: opacity 0.4s var(--ease-out);
}

.lg--elastic {
  --lg-tx: 0px;
  --lg-ty: 0px;
  transform: translate3d(var(--lg-tx), var(--lg-ty), 0);
}

.lg--elastic:hover {
  box-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.3),
    inset 0 -1px 0 0 rgba(255, 255, 255, 0.1),
    inset 0 0 0 1px rgba(255, 255, 255, 0.14),
    var(--lg-shadow-hover);
}

.lg--elastic:hover > .lg-hl {
  opacity: 1;
}

.lg--elastic:hover::after {
  opacity: 1;
}

/* Glass sitting over bright imagery needs a darker interior to stay legible. */
.lg--over-light {
  --lg-tint: rgba(255, 255, 255, 0.14);
  box-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.4),
    inset 0 0 0 1px rgba(255, 255, 255, 0.18),
    inset 0 0 40px -10px rgba(0, 0, 0, 0.35),
    var(--lg-shadow);
}

/* ------------------------------------------------------------------ buttons */

.lg-btn {
  --lg-r: 999px;
  --lg-blur: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.82rem 1.5rem;
  border: 0;
  font: inherit;
  font-size: 0.945rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.lg-btn:active {
  transform: translate3d(var(--lg-tx, 0), var(--lg-ty, 0), 0) scale(0.965);
  transition-duration: 0.12s;
}

.lg-btn .ico {
  transition: transform 0.5s var(--spring);
}

.lg-btn:hover .ico {
  transform: translateX(3px);
}

/* Accent-filled glass: the tint carries brand colour instead of pure white. */
.lg-btn--accent {
  --lg-tint: color-mix(in srgb, var(--accent) 78%, transparent);
  color: #0b0f17;
  font-weight: 700;
}

.lg-btn--accent::before {
  --lg-gloss: 0.42;
}

.lg-btn--accent:hover {
  --lg-tint: color-mix(in srgb, var(--accent) 92%, transparent);
}

.lg-btn--sm {
  padding: 0.55rem 1rem;
  font-size: 0.86rem;
}

.lg-btn--icon {
  padding: 0;
  width: 2.55rem;
  height: 2.55rem;
  flex: 0 0 auto;
}

.lg-btn--icon:hover .ico {
  transform: none;
}

/* --------------------------------------------------------------- containers */

.lg-card {
  --lg-r: 22px;
}

.lg-panel {
  --lg-r: 30px;
  --lg-blur: 22px;
}

.lg-pill {
  --lg-r: 999px;
  --lg-blur: 10px;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.42rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* Focus ring drawn outside the glass so it survives the masks above. */
.lg-btn:focus-visible,
.lg[tabindex]:focus-visible,
.lg-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* Refraction is heavy; the browser needs a hint on things that move. */
.lg--elastic,
.lg-btn {
  will-change: transform;
}

@media (prefers-reduced-motion: reduce) {
  .lg,
  .lg-btn,
  .lg::after,
  .lg-hl {
    transition-duration: 0.01ms !important;
  }

  .lg--elastic {
    transform: none !important;
  }
}
