/* Convergence widget.
   Dark card with a 320x240 SVG stage. Three tracks (stroke-dasharray
   base + stroke-dashoffset animated pulse) converge into a halo'd core,
   which then emits one outbound pulse after the inbound ones arrive.
   All animation is CSS-only; reduced-motion stops every keyframe. */

.widget-convergence {
  --wc-teal: var(--brand-teal);
  --wc-blue: var(--brand-blue);
  --wc-surface: var(--surface-dark-999, #0a0a0c);
  --wc-line: color-mix(in oklch, var(--on-dark-foreground) 18%, transparent);
  --wc-line-soft: color-mix(in oklch, var(--on-dark-foreground) 8%, transparent);
  --wc-muted: var(--on-dark-muted-foreground);
  --wc-fg: var(--on-dark-foreground);

  min-width: 0;
  width: 100%;
}

.widget-convergence__card {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 0.5rem;
  padding: 0.875rem 0.875rem 0.75rem;
  background: linear-gradient(
    180deg,
    color-mix(in oklch, var(--wc-surface) 95%, transparent) 0%,
    color-mix(in oklch, var(--wc-surface) 98%, transparent) 100%
  );
  border: 1px solid color-mix(in oklch, var(--wc-fg) 10%, transparent);
  border-radius: var(--radius-lg);
  box-shadow:
    0 1px 0 color-mix(in oklch, var(--wc-fg) 6%, transparent) inset,
    0 16px 40px -20px rgb(0 0 0 / 45%);

  /* On-dark token scope so nested text + icons read correctly without
     relying on an enclosing card. */
  color: var(--wc-fg);
  --color-foreground: var(--wc-fg);
  --color-muted-foreground: var(--wc-muted);
  --color-border: var(--wc-line);
}

/* --- Head row ------------------------------------------------------- */

.widget-convergence__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.125rem 0.25rem;
}

.widget-convergence__tag {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: var(--font-weight-medium);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--wc-fg);
}

.widget-convergence__tag-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--wc-teal);
  box-shadow:
    0 0 0 3px color-mix(in oklch, var(--wc-teal) 22%, transparent),
    0 0 10px color-mix(in oklch, var(--wc-teal) 55%, transparent);
  animation: wc-tag-breathe 2.6s ease-in-out infinite;
}

.widget-convergence__status {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--wc-muted);
}

/* --- SVG stage ------------------------------------------------------ */

.widget-convergence__stage {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 320 / 240;
  background:
    radial-gradient(circle at 50% 50%,
      color-mix(in oklch, var(--wc-teal) 10%, transparent) 0%,
      transparent 55%),
    color-mix(in oklch, var(--wc-surface) 92%, transparent);
  border-radius: var(--radius-md);
  border: 1px solid color-mix(in oklch, var(--wc-fg) 7%, transparent);
  overflow: visible;
}

.widget-convergence__grid path {
  stroke: var(--wc-line-soft);
  stroke-width: 1;
  fill: none;
}

/* --- Tracks + pulses ------------------------------------------------ */

.widget-convergence__track {
  fill: none;
  stroke: color-mix(in oklch, var(--wc-teal) 22%, transparent);
  stroke-width: 2;
  stroke-linecap: round;
}
.widget-convergence__track--out {
  stroke: url(#wc-out-stroke);
  stroke-opacity: 0.5;
}

/* A pulse is the same path rendered with a short dash that rides the
   full length. For a path of length L, a dasharray of "gap_size pulse_size"
   where `gap_size >= L` keeps only one dash visible at a time. We animate
   stroke-dashoffset from L+pulse_size to 0 so the dash enters from the
   start and exits at the end. Path-lengths below are approximate; the
   animation uses large enough values to cover any variation. */

.widget-convergence__pulse {
  fill: none;
  stroke: var(--wc-teal);
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-dasharray: 26 260;
  filter: drop-shadow(0 0 4px color-mix(in oklch, var(--wc-teal) 65%, transparent));
}

.widget-convergence__pulse--1 {
  animation: wc-pulse 4.4s linear infinite;
  animation-delay: 0s;
}
.widget-convergence__pulse--2 {
  animation: wc-pulse 4.4s linear infinite;
  animation-delay: 0.55s;
}
.widget-convergence__pulse--3 {
  animation: wc-pulse 4.4s linear infinite;
  animation-delay: 1.1s;
}

/* Outbound pulse fires a beat after the third inbound arrives, so the
   eye reads "ingest → converge → emit." Uses the blue half of the
   gradient via a dedicated stroke (see --out). */
.widget-convergence__pulse--out {
  stroke: var(--wc-blue);
  stroke-dasharray: 22 220;
  animation: wc-pulse-out 4.4s linear infinite;
  animation-delay: 1.85s;
  filter: drop-shadow(0 0 4px color-mix(in oklch, var(--wc-blue) 70%, transparent));
}

@keyframes wc-pulse {
  from { stroke-dashoffset: 290; }
  to   { stroke-dashoffset: 0; }
}
@keyframes wc-pulse-out {
  from { stroke-dashoffset: 240; }
  to   { stroke-dashoffset: 0; }
}

/* --- Core + halo ---------------------------------------------------- */

.widget-convergence__halo {
  transform-origin: 160px 120px;
  transform-box: fill-box;
  animation: wc-halo-breathe 3.8s ease-in-out infinite;
}

.widget-convergence__core {
  fill: var(--wc-teal);
  filter: drop-shadow(0 0 8px color-mix(in oklch, var(--wc-teal) 70%, transparent));
}

.widget-convergence__core-inner {
  fill: #ffffff;
  opacity: 0.9;
}

@keyframes wc-halo-breathe {
  0%, 100% { opacity: 0.85; transform: scale(1);   }
  50%      { opacity: 1;    transform: scale(1.15); }
}

/* --- Origin dots + terminus ---------------------------------------- */

.widget-convergence__origins circle {
  fill: color-mix(in oklch, var(--wc-teal) 60%, white);
  filter: drop-shadow(0 0 3px color-mix(in oklch, var(--wc-teal) 55%, transparent));
  animation: wc-origin-blink 2.2s ease-in-out infinite;
}
.widget-convergence__origins circle:nth-child(1) { animation-delay: 0s; }
.widget-convergence__origins circle:nth-child(2) { animation-delay: 0.4s; }
.widget-convergence__origins circle:nth-child(3) { animation-delay: 0.8s; }

.widget-convergence__terminus {
  fill: var(--wc-blue);
  filter: drop-shadow(0 0 6px color-mix(in oklch, var(--wc-blue) 70%, transparent));
  animation: wc-terminus 4.4s ease-in-out infinite;
  animation-delay: 3.1s;
}

@keyframes wc-origin-blink {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}
@keyframes wc-terminus {
  0%, 65%  { r: 5;   opacity: 0.7; }
  72%      { r: 8;   opacity: 1; }
  85%      { r: 5;   opacity: 0.9; }
  100%     { r: 5;   opacity: 0.7; }
}

/* --- Labels --------------------------------------------------------- */

.widget-convergence__label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  fill: var(--wc-muted);
}
.widget-convergence__label--out {
  fill: color-mix(in oklch, var(--wc-blue) 70%, white);
}

/* --- Meter strip ---------------------------------------------------- */

.widget-convergence__meters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  padding: 0.5rem 0.375rem 0;
  border-top: 1px solid color-mix(in oklch, var(--wc-fg) 7%, transparent);
}

.widget-convergence__meter {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.25rem 0.375rem;
}

.widget-convergence__meter-label {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--wc-muted);
}

.widget-convergence__meter-value {
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  font-weight: var(--font-weight-medium);
  color: var(--wc-fg);
  letter-spacing: -0.01em;
}

/* --- Head dot breathe ---------------------------------------------- */

@keyframes wc-tag-breathe {
  0%, 100% {
    box-shadow:
      0 0 0 3px color-mix(in oklch, var(--wc-teal) 22%, transparent),
      0 0 10px color-mix(in oklch, var(--wc-teal) 55%, transparent);
  }
  50% {
    box-shadow:
      0 0 0 5px color-mix(in oklch, var(--wc-teal) 14%, transparent),
      0 0 16px color-mix(in oklch, var(--wc-teal) 70%, transparent);
  }
}

/* --- Reduced motion ------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .widget-convergence__tag-dot,
  .widget-convergence__halo,
  .widget-convergence__origins circle,
  .widget-convergence__terminus,
  .widget-convergence__pulse,
  .widget-convergence__pulse--out {
    animation: none;
  }
  /* Park the pulses mid-path so the still image still reads as a flow. */
  .widget-convergence__pulse { stroke-dashoffset: 160; }
  .widget-convergence__pulse--out { stroke-dashoffset: 140; }
}
