/* Liquid glass is enabled only for the Glass theme. In Chromium it also refracts what is behind each
   surface; other browsers keep this light frost.
   Load it after the other stylesheets. Content such as cards, chat messages and list rows stays flat,
   and nothing that sits on a glass surface gets glass of its own. */

:root[data-theme="glass"] {
  --lg-fill: rgba(255, 255, 255, 0.026);
  --lg-fill-strong: rgba(7, 9, 16, 0.64);
  --lg-rim: rgba(255, 255, 255, 0.16);
  --lg-sheen: rgba(255, 255, 255, 0.09);
  --lg-lift: 0 22px 48px -22px rgba(0, 0, 0, 0.78), 0 2px 6px rgba(0, 0, 0, 0.22);
  /* A crisp white rim and paired inner reflections give depth without a gray tint. */
  --lg-edge: inset 0 1px 0 rgba(255, 255, 255, 0.28), inset 0 -0.5px 0 rgba(255, 255, 255, 0.09), inset 0 0 0 0.5px rgba(255, 255, 255, 0.13), inset 0 12px 24px -18px rgba(255, 255, 255, 0.3), inset 0 -14px 24px -16px rgba(0, 0, 0, 0.44);
  --lg-shadow: var(--lg-lift), var(--lg-edge);
  --lg-overlay: rgba(3, 4, 8, 0.45);
}

@property --lg-glow {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

/* Dialogs are positioned by the browser, so they are left out here. */
:root[data-theme="glass"] :where(.liquid:not(dialog)) {
  position: relative;
}

:root[data-theme="glass"] .liquid {
  isolation: isolate;
  background: var(--lg-fill);
  border: 1px solid var(--lg-rim);
  box-shadow: var(--lg-shadow);
  /* Before liquid.js runs, and in browsers that can't refract, the glass is frosted instead. */
  -webkit-backdrop-filter: blur(var(--lg-blur, 10px)) saturate(180%);
  backdrop-filter: blur(var(--lg-blur, 10px)) saturate(180%);
}
:root:not([data-theme="glass"]) .liquid {
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}

/* Keep the chat panel translucent so its floating composer can bend and frost
   the colored light and conversation behind it. The panel itself stays unblurred
   because Chromium cannot paint the sandboxed tool iframe through that blur. */
:root[data-theme="glass"] .panel.chat {
  background: rgba(12, 14, 23, 0.76);
  --chat-bg: rgba(13, 15, 24, 0.76);
}

/* The sheen, and a soft light where the pointer is (liquid.js sets --lg-x and --lg-y). */
:root[data-theme="glass"] .liquid::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  pointer-events: none;
  background:
    radial-gradient(220px circle at var(--lg-x, 50%) var(--lg-y, -40%), rgb(255 255 255 / var(--lg-glow)), transparent 70%),
    linear-gradient(155deg, var(--lg-sheen), transparent 34%, transparent 68%, rgb(255 255 255 / var(--lg-sheen-tail, 0.018)));
  transition: --lg-glow 320ms ease;
}
:root[data-theme="glass"] .liquid:hover::before { --lg-glow: 0.08; }
:root[data-theme="glass"] .sidebar.liquid:hover::before,
:root[data-theme="glass"] .lib-toolbar.liquid:hover::before,
:root[data-theme="glass"] dialog.modal.liquid:hover::before { --lg-glow: 0.03; }

/* How frosted each surface is. More where text sits on the glass, less on small controls. */
:root[data-theme="glass"] .sidebar.liquid { --lg-blur: 13px; }
:root[data-theme="glass"] .composer-box.liquid,
:root[data-theme="glass"] .bulk-bar.liquid,
:root[data-theme="glass"] #chatFind.liquid { --lg-blur: 10px; }
:root[data-theme="glass"] .menu.liquid,
:root[data-theme="glass"] .toast.liquid,
:root[data-theme="glass"] dialog.modal.liquid { --lg-blur: 18px; }

/* Menus, toasts and dialogs read best with a denser fill, so text stays legible over busy content. */
:root[data-theme="glass"] .menu.liquid,
:root[data-theme="glass"] .toast.liquid,
:root[data-theme="glass"] dialog.modal.liquid {
  background: var(--lg-fill-strong);
  border-color: var(--lg-rim);
  box-shadow: var(--lg-shadow);
}

/* A dialog refracts the app behind it, so the page is dimmed rather than blurred. */
:root[data-theme="glass"] dialog.modal.liquid::backdrop {
  background: var(--lg-overlay);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* The composer: one glass surface. Its pills and buttons are fills on it, not glass. */
:root[data-theme="glass"] .composer-box.liquid {
  --lg-sheen: rgba(255, 255, 255, 0.09);
  --lg-sheen-tail: 0.025;
  --lg-blur: 10px;
  --lg-rim: rgba(255, 255, 255, 0.18);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.026), rgba(255, 255, 255, 0.006) 48%, rgba(4, 6, 14, 0.12));
  border-color: var(--lg-rim);
  box-shadow: 0 22px 50px -28px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.26), inset 0 -1px 0 rgba(255, 255, 255, 0.06), inset 0 12px 24px -18px rgba(255, 255, 255, 0.32), inset 0 -16px 26px -18px rgba(0, 0, 0, 0.5);
}
:root[data-theme="glass"] .composer-box.liquid:hover::before { --lg-glow: 0.045; }
:root[data-theme="glass"] .composer-box.liquid:focus-within {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--lg-rim));
  box-shadow: 0 22px 50px -28px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.26), inset 0 -1px 0 rgba(255, 255, 255, 0.06), inset 0 12px 24px -18px rgba(255, 255, 255, 0.32), inset 0 -16px 26px -18px rgba(0, 0, 0, 0.5), 0 0 0 4px color-mix(in srgb, var(--accent) 14%, transparent), 0 12px 44px -14px color-mix(in srgb, var(--accent) 42%, transparent);
}

/* The library toolbar floats over the grid as it scrolls by. The cards are bright, so it takes a
   denser fill to keep its labels readable. */
:root[data-theme="glass"] .lib-toolbar.liquid {
  top: 12px;
  margin: 0;
  padding: 8px;
  border-radius: 22px;
  --lg-blur: 12px;
  background: color-mix(in srgb, var(--lg-fill-strong) 60%, transparent);
}
:root[data-theme="glass"] .lib-toolbar.liquid .input,
:root[data-theme="glass"] .lib-toolbar.liquid .field { border-radius: 999px; }

/* Bars and the jump button over the chat log. */
:root[data-theme="glass"] .bulk-bar.liquid,
:root[data-theme="glass"] #chatFind.liquid,
:root[data-theme="glass"] #jumpLatest.liquid { border-radius: 999px; }

/* The floating buttons over the chat log. */
:root[data-theme="glass"] .chat-nav .liquid {
  background: var(--lg-fill);
  border-color: var(--lg-rim);
}
:root[data-theme="glass"] .chat-nav .liquid:hover:not(:disabled) { background: var(--lg-fill-strong); }

/* Every glass control gives a little when pressed. */
:root[data-theme="glass"] .chat-nav .liquid:active:not(:disabled),
:root[data-theme="glass"] .cta .liquid:active { transform: scale(0.96); }
:root[data-theme="glass"] #jumpLatest.liquid:active { transform: translateX(-50%) scale(0.96); }

/* Tooltips are frosted glass too. They are drawn as ::after, so they get the look without refraction. */
:root[data-theme="glass"] [data-tip]::after {
  background: var(--lg-fill-strong);
  border-color: var(--lg-rim);
  box-shadow: var(--lg-shadow);
  -webkit-backdrop-filter: blur(14px) saturate(170%);
  backdrop-filter: blur(14px) saturate(170%);
}

/* Reduced transparency: a solid surface, no blur, no light effects. */
@media (prefers-reduced-transparency: reduce) {
  :root[data-theme="glass"] .liquid,
  :root[data-theme="glass"] [data-tip]::after {
    background: var(--surface-solid);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  :root[data-theme="glass"] .liquid::before { display: none; }
}
