/* ============================================================================
 * Success / confirmation surface — .ui-sx*
 *   The end of a flow: a check mark, the outcome in words, somewhere to go
 *   next, an optional confetti field and an optional auto-redirect countdown.
 *   Three layouts (hero / split / compact) and two check marks.
 *
 *   The card is a plain elevated surface — no blurred glows or drifting blobs
 *   behind it. Accent-aware via the kit tokens; the mark stays on the --green
 *   family (green = success). Every motion path is reduced-motion safe — see
 *   the block at the foot. Markup comes from success() in components/index
 *   (re-exported).
 * ========================================================================== */

.ui-sx {
  --sx-green: var(--green);
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  background: var(--bg-elevated);   /* Elevated surface for the confirmation and its actions. */
  /* The floating treatment, like every other surface on that step.
     why: docs/foundations.md#elevation */
  border: 1px solid var(--float-edge);
  box-shadow: inset 0 0 0 1px var(--elev-edge, var(--float-edge-inner)), var(--elev-drop);
  isolation: isolate;
}

/* ---- Layout shell -------------------------------------------------------- */
.ui-sx__inner { position: relative; z-index: 1; }
.ui-sx__content { min-width: 0; }
.ui-sx__title {
  color: var(--strong); font-size: var(--text-xl); font-weight: var(--weight-semibold);
  letter-spacing: -.02em; line-height: 1.2; margin: 0;
}
.ui-sx__body {
  color: var(--text); font-size: var(--text-base); line-height: 1.6; margin: 9px 0 0; max-width: var(--prose-caption);
}
.ui-sx__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }

/* hero — centred column, the upgraded default */
.ui-sx--hero { padding: 44px 32px 40px; text-align: center; }
.ui-sx--hero .ui-sx__inner { display: flex; flex-direction: column; align-items: center; }
.ui-sx--hero .ui-sx__visual { margin-bottom: 22px; }
.ui-sx--hero .ui-sx__body { margin-left: auto; margin-right: auto; }
.ui-sx--hero .ui-sx__actions { justify-content: center; }
.ui-sx--hero .ui-sx__check { width: 56px; height: 56px; }

/* split — visual panel beside the copy */
.ui-sx--split .ui-sx__inner {
  display: grid; grid-template-columns: minmax(200px, 300px) 1fr; align-items: stretch;
}
.ui-sx--split .ui-sx__visual {
  display: grid; place-items: center; padding: 40px 24px;
  background: color-mix(in srgb, var(--green) 8%, transparent); /* code-bg: inherit — decorative illustration has no nested focus target. */
  border-right: 1px solid var(--border);
}
.ui-sx--split .ui-sx__check { width: 72px; height: 72px; }
.ui-sx--split .ui-sx__content { padding: 40px 36px; align-self: center; }

/* compact — inline, panel/toast-adjacent */
.ui-sx--compact { padding: 18px 20px; }
.ui-sx--compact .ui-sx__inner { display: flex; align-items: center; gap: 16px; }
.ui-sx--compact .ui-sx__visual { flex: none; }
.ui-sx--compact .ui-sx__check { width: 28px; height: 28px; }
.ui-sx--compact .ui-sx__title { font-size: calc(var(--text-md) + 0.5px); }
.ui-sx--compact .ui-sx__body { font-size: var(--text-sm); margin-top: 3px; }
.ui-sx--compact .ui-sx__actions { margin-top: 0; margin-left: auto; flex: none; }
.ui-sx--compact .ui-sx__content { flex: 1; display: flex; align-items: center; gap: 16px; }
.ui-sx--compact .ui-sx__content > div:first-child,
.ui-sx--compact .ui-sx__title { min-width: 0; }

/* ---- The check mark ------------------------------------------------------ */
/* Two marks, both unmodified Lucide paths at Lucide's own stroke width, in the
   success colour. `line` is the bare check (Lucide `check`), the default. It
   strokes itself on via dash-offset; the path is 22.6 units long, which is what
   the dasharray is tuned to. `circled` is Lucide `circle-check-big` at 20px —
   the kit's label size — for a confirmation that should stay quiet. It is drawn
   at rest, because a 20px mark has nothing to choreograph. */
.ui-sx__check { display: block; }
.ui-sx__tick, .ui-sx__circle {
  fill: none; stroke: var(--sx-green, var(--green)); stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.ui-sx__check--line .ui-sx__tick {
  stroke-dasharray: 23; stroke-dashoffset: 23;
  animation: ui-sx-draw var(--dur-slow) var(--ease-out) forwards;
}
@keyframes ui-sx-draw { to { stroke-dashoffset: 0; } }

/* circled — one small size in every layout, so it reads as a status mark
   rather than an illustration. The split panel narrows to match it. */
.ui-sx--check-circled .ui-sx__check { width: 20px; height: 20px; }
.ui-sx--check-circled.ui-sx--hero .ui-sx__visual { margin-bottom: 12px; }
.ui-sx--check-circled.ui-sx--split .ui-sx__inner { grid-template-columns: minmax(120px, 160px) 1fr; }

/* ---- Confetti (opt-in) --------------------------------------------------- */
.ui-sx__confetti { position: absolute; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }
.ui-sx__piece {
  position: absolute; top: -8%; width: 8px; height: 8px; border-radius: 2px;
  opacity: 0; transform-origin: center;
  animation: ui-sx-fall 2.4s cubic-bezier(.2,.6,.35,1) var(--sx-d, 0s) forwards; /* motion: ambient — fall time is set by the height of the panel, not by an interaction */
  scale: var(--sx-s, 1);
}
.ui-sx__piece--a { background: var(--accent); }
.ui-sx__piece--g { background: var(--green); }
.ui-sx__piece--c { background: var(--cyan); }
.ui-sx__piece--p { background: var(--purple-light); }
.ui-sx__piece--k { background: var(--pink); border-radius: 50%; }
@keyframes ui-sx-fall {
  0%   { opacity: 0; transform: translateY(-10px) rotate(0deg); }
  12%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(340px) rotate(var(--sx-r, 40deg)); }
}

/* ---- Countdown ----------------------------------------------------------- */
/* Registered angle so the conic sweep can actually interpolate (a plain
   conic-gradient background is not animatable). */
@property --sx-a { syntax: "<angle>"; inherits: false; initial-value: 360deg; }
.ui-sx__count { display: inline-flex; align-items: center; gap: 9px; margin-top: 18px; }
.ui-sx--hero .ui-sx__count { justify-content: center; }
.ui-sx__count-ring {
  flex: none; width: 16px; height: 16px; border-radius: 50%;
  background: conic-gradient(var(--green) var(--sx-a, 360deg), var(--surface-2) 0); /* code-bg: inherit — decorative or text-only paint; nothing nested reads a ground from it. */
  mask: radial-gradient(circle, transparent 5px, #000 6px);
  -webkit-mask: radial-gradient(circle, transparent 5px, #000 6px);
  animation: ui-sx-sweep var(--sx-secs, 5s) linear forwards; /* motion: ambient — the caller sets the countdown; the ring just spends it */
}
@keyframes ui-sx-sweep { from { --sx-a: 360deg; } to { --sx-a: 0deg; } }
.ui-sx__count-text { color: var(--text); font-size: var(--text-sm); }
.ui-sx__count-text b { color: var(--text); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }

/* ---- Reduced motion — static check, no confetti / sweep ------------------ */
@media (prefers-reduced-motion: reduce) {
  .ui-sx__check--line .ui-sx__tick { animation: none; stroke-dashoffset: 0; }
  .ui-sx__confetti { display: none; }
  .ui-sx__count-ring { animation: none; background: var(--surface-2); /* code-bg: inherit — decorative or text-only paint; nothing nested reads a ground from it. */ }
}

/* ---- Narrow — split stacks -------------------------------------------- */
@media (max-width: 560px) {
  .ui-sx--split .ui-sx__inner { grid-template-columns: 1fr; }
  .ui-sx--check-circled.ui-sx--split .ui-sx__inner { grid-template-columns: 1fr; }
  .ui-sx--split .ui-sx__visual { border-right: 0; border-bottom: 1px solid var(--border); padding: 32px 24px; }
  .ui-sx--split .ui-sx__content { padding: 28px 26px; text-align: center; }
  .ui-sx--split .ui-sx__actions { justify-content: center; }
  .ui-sx--compact .ui-sx__content { flex-direction: column; align-items: flex-start; gap: 10px; }
  .ui-sx--compact .ui-sx__actions { margin-left: 0; }
}
