/*
 * Critique glass material: the one implementation of the glass tiers and their a11y fallbacks.
 * Built only on --cq-* vars from generated/tokens.css (pages) or generated/tokens.host.css
 * (shadow roots), so it never names a theme and never selects :root, html or body.
 *
 *   .cq-glass-regular  text-bearing glass; every text block on it needs .cq-guard
 *   .cq-glass-clear    no body text and no verdict color on it (launcher capsule, chips, decor)
 *   .cq-glass-solid    opaque surface; also what the other tiers fall back to
 *   .cq-glass-card     the verdict card: light glass; every text block on it needs .cq-guard
 *                      (the card takes the host theme from its mount)
 *   .cq-specular       optional moving highlight (::before); set --cq-mx / --cq-my
 *   .cq-guard          legibility guard: blurred scrim + text-shadow under a text block
 *   .cq-indicator      verdict tag glyph on a solid disc; [data-verdict] sets its color
 *   .cq-status-dot     solid disc with a verdict-colored inner circle; [data-verdict] + aria-label
 *   .cq-tip            hover/focus tooltip (GlassTip): the source-dot tooltip's solid glass chip
 *
 * Every glass surface is its own stacking context, so the specular and guard pseudo-elements
 * (z-index: -1) paint above the glass background and below its content.
 */

.cq-glass-regular,
.cq-glass-clear,
.cq-glass-solid,
.cq-glass-card {
  position: relative;
  isolation: isolate;
  border: 1px solid var(--cq-glass-border);
  box-shadow: 0 0 0 1px var(--cq-glass-edge), var(--cq-rim-inset), var(--cq-elevation-2);
  color: var(--cq-fg);
  font-family: var(--cq-font-sans);
  letter-spacing: var(--cq-tracking-body);
  -webkit-font-smoothing: antialiased;
}

.cq-glass-regular {
  background: var(--cq-glass-regular-tint);
  -webkit-backdrop-filter: blur(var(--cq-glass-regular-blur)) saturate(var(--cq-glass-regular-saturate));
  backdrop-filter: blur(var(--cq-glass-regular-blur)) saturate(var(--cq-glass-regular-saturate));
}

.cq-glass-clear {
  background: var(--cq-glass-clear-tint);
  -webkit-backdrop-filter: blur(var(--cq-glass-clear-blur)) saturate(var(--cq-glass-clear-saturate));
  backdrop-filter: blur(var(--cq-glass-clear-blur)) saturate(var(--cq-glass-clear-saturate));
}

.cq-glass-solid {
  background: var(--cq-glass-solid);
  border-color: var(--cq-glass-solid-border);
}

.cq-glass-card {
  background: var(--cq-glass-card-tint);
  /* Guards on the card take its hue (lum-tint1). */
  --cq-guard-scrim: var(--cq-glass-card-scrim);
  /* Top highlight, inner glow, an edge ring that holds on white pages, then the lift. */
  box-shadow: inset 0 1px 0 var(--cq-glass-card-highlight), inset 0 0 24px var(--cq-glass-card-glow), 0 0 0 1px var(--cq-glass-edge), var(--cq-elevation-3);
  -webkit-backdrop-filter: blur(var(--cq-glass-card-blur)) saturate(var(--cq-glass-card-saturate));
  backdrop-filter: blur(var(--cq-glass-card-blur)) saturate(var(--cq-glass-card-saturate));
}

/* Light-tracking rim: a 1px masked ring brightest where the light (--cq-mx/--cq-my) falls. */
.cq-glass-regular::after,
.cq-glass-clear::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  pointer-events: none;
  background: radial-gradient(120% 120% at var(--cq-mx, 18%) var(--cq-my, 0%),
    var(--cq-rim-hi), var(--cq-rim-mid) 52%, var(--cq-rim-lo));
  -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 exclude, linear-gradient(#000 0 0);
}

.cq-specular::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(140px 90px at var(--cq-mx, 25%) var(--cq-my, 0%),
    var(--cq-specular-color), transparent 70%);
}

.cq-guard {
  position: relative;
  isolation: isolate;
  text-shadow: var(--cq-guard-text-shadow);
}

.cq-guard::before {
  content: "";
  position: absolute;
  inset: -3px -8px;
  z-index: -1;
  border-radius: var(--cq-radius-inner);
  background: var(--cq-guard-scrim);
  filter: blur(var(--cq-glass-guard-blur));
  pointer-events: none;
}

/*
 * Verdict color never sits on bare glass: the disc keeps every verdict at 3:1 or better.
 * The verdict comes from [data-verdict], never a bg-<verdict> utility: this file is unlayered,
 * so the disc background would win over the utility.
 */
.cq-indicator,
.cq-status-dot {
  display: inline-grid;
  place-items: center;
  border-radius: var(--cq-radius-capsule);
  background: var(--cq-indicator-bg);
  box-shadow: 0 0 0 1px var(--cq-line);
}

/* Tag glyphs: an icon drawn in currentColor takes the verdict color. */
.cq-indicator[data-verdict=credible] { color: var(--cq-verdict-credible); }
.cq-indicator[data-verdict=unverified] { color: var(--cq-verdict-unverified); }
.cq-indicator[data-verdict=unreliable] { color: var(--cq-verdict-unreliable); }
.cq-indicator[data-verdict=info] { color: var(--cq-verdict-info); }

/* Status dot: give it an aria-label naming the worst verdict. */
.cq-status-dot {
  width: var(--cq-indicator-dot-size);
  height: var(--cq-indicator-dot-size);
  flex: none;
}

.cq-status-dot::after {
  content: "";
  box-sizing: border-box;
  width: var(--cq-indicator-dot-inner);
  height: var(--cq-indicator-dot-inner);
  border-radius: 50%;
}

.cq-status-dot[data-verdict=credible]::after { background: var(--cq-verdict-credible); }
.cq-status-dot[data-verdict=unverified]::after { background: var(--cq-verdict-unverified); }
.cq-status-dot[data-verdict=unreliable]::after { background: var(--cq-verdict-unreliable); }
.cq-status-dot[data-verdict=info]::after { background: var(--cq-verdict-info); }

/* Two-tone focus ring from tokens; replaces the element's own box-shadow while focused. */
.cq-focus-ring:focus-visible {
  outline: none;
  box-shadow: var(--cq-focus-shadow);
}

/* ---------- fallbacks ---------- */

/* No backdrop-filter: translucent tint would sit on raw page content, so go solid. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .cq-glass-regular,
  .cq-glass-clear,
  .cq-glass-card {
    background: var(--cq-glass-solid);
    border-color: var(--cq-glass-solid-border);
  }
  .cq-guard {
    text-shadow: none;
  }
  .cq-guard::before {
    display: none;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .cq-glass-regular,
  .cq-glass-clear,
  .cq-glass-card {
    background: var(--cq-glass-solid);
    border-color: var(--cq-glass-solid-border);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .cq-glass-regular::after,
  .cq-glass-clear::after,
  .cq-specular::before,
  .cq-guard::before {
    display: none;
  }
  .cq-guard {
    text-shadow: none;
  }
}

/* Verdict colors switch to their -hc variants in the generated token CSS. */
@media (prefers-contrast: more) {
  .cq-glass-regular,
  .cq-glass-clear,
  .cq-glass-solid,
  .cq-glass-card {
    background: var(--cq-glass-solid);
    border-color: var(--cq-fg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .cq-glass-regular::after,
  .cq-glass-clear::after,
  .cq-specular::before,
  .cq-guard::before {
    display: none;
  }
  .cq-guard {
    text-shadow: none;
  }
}

@media (forced-colors: active) {
  .cq-glass-regular,
  .cq-glass-clear,
  .cq-glass-solid,
  .cq-glass-card {
    background: Canvas;
    color: CanvasText;
    border: 1px solid CanvasText;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .cq-glass-regular::after,
  .cq-glass-clear::after,
  .cq-specular::before,
  .cq-guard::before {
    display: none;
  }
  .cq-guard {
    text-shadow: none;
  }
  /* System colors win (no forced-color-adjust: none); the glyph shape and aria-label carry the verdict. */
  .cq-indicator,
  .cq-status-dot {
    border: 2px solid CanvasText;
  }
  .cq-indicator {
    color: CanvasText;
  }
  /* Backgrounds are forced to Canvas, so the inner circle is a border that fills it. */
  .cq-status-dot::after {
    background: none;
    border: calc(var(--cq-indicator-dot-inner) / 2) solid CanvasText;
  }
  /* Forced colors drop box-shadow, so the focus ring becomes a system-color outline. */
  .cq-focus-ring:focus-visible {
    outline: 2px solid Highlight;
    outline-offset: var(--cq-focus-ring-offset);
  }
}

/* Tooltip (src/@/components/ui/GlassTip.tsx): the same chip as the card's source-dot tooltip
 * (.critique-source-tip), placed by Radix in a portal. Radix sets data-state; it waits for the
 * close animation before unmounting. */
.cq-tip {
  z-index: var(--cq-z-top);
  width: max-content;
  max-width: min(280px, calc(100vw - 16px));
  padding: 6px var(--cq-space-2);
  border-radius: var(--cq-radius-chip);
  background: var(--cq-glass-solid);
  border: 1px solid var(--cq-glass-edge);
  box-shadow: var(--cq-elevation-2);
  color: var(--cq-fg);
  font-family: var(--cq-font-sans);
  font-size: var(--cq-text-xs);
  line-height: var(--cq-leading-xs);
  font-weight: var(--cq-weight-medium);
  letter-spacing: var(--cq-tracking-body);
  pointer-events: none;
  user-select: none;
  animation: cq-tip-in var(--cq-dur-card-fade-in) var(--cq-ease-standard);
}

.cq-tip[data-state=closed] {
  animation: cq-tip-out var(--cq-dur-card-fade-out) var(--cq-ease-standard) forwards;
}

@keyframes cq-tip-in {
  from {
    opacity: 0;
  }
}

@keyframes cq-tip-out {
  to {
    opacity: 0;
  }
}

@media (forced-colors: active) {
  .cq-tip {
    border-color: CanvasText;
    background: Canvas;
    color: CanvasText;
  }
}

/* Never animate glass layers; under reduced motion nothing on them transitions at all. */
@media (prefers-reduced-motion: reduce) {
  .cq-glass-regular,
  .cq-glass-clear,
  .cq-glass-solid,
  .cq-glass-regular::after,
  .cq-glass-clear::after,
  .cq-specular::before,
  .cq-tip,
  .cq-tip[data-state=closed] {
    transition: none;
    animation: none;
  }
}
