/* ============================================================================
   Connily presence signature — "Meniscus"
   ----------------------------------------------------------------------------
   THE single source of truth for the presence signature. Every value below is
   the locked design spec (design_handoff_presence_signature/meniscus.css,
   handed over 2026-08-19). Do not retune by eye; change the spec first.

   The signature means "Connily is working here". It is never a character or
   mascot. Colours are the existing site CTA blues, not new colours:
     #5856DB = connily-landing --color-skin-indigo   (primary buttons / CTA)
     #B9B8F4 = connily-landing --color-skin-indigo-light

   CONSUMERS
     - connily-app: imported from app/globals.css. React wrapper:
       components/connily/presence.tsx. Demo: /internal/presence.
     - marketing static-render pipeline (ig-gen / render-ig): render-ig.sh
       copies this file into the build dir before rendering; cards link it as
       ../presence.css. Same classes, same file.

   USAGE — the host surface must be position:relative and have a border-radius.
   Drop the signature in as the LAST child and tell it the host's radius:

     <div class="review-card" style="position:relative;border-radius:16px">
       ...card content...
       <div class="cn-presence" data-state="travelling" data-size="card"
            style="--cn-radius:16px">
         <i class="cn-presence__bloom"></i>
         <i class="cn-presence__layer cn-presence__layer--glow"><i class="cn-presence__ring"><i class="cn-presence__head"></i></i></i>
         <i class="cn-presence__layer cn-presence__layer--line"><i class="cn-presence__ring"><i class="cn-presence__head"></i></i></i>
       </div>
     </div>

   The 4-node shape is load-bearing (masked-ring construction). Do not flatten
   it to one element with a box-shadow/outline — that is a border, not a
   signature. In the app use <Presence/> which writes the nodes.

   ATTRIBUTES
     data-state = travelling | thinking | landing | authored
     data-size  = full | card | inline
     data-still = present: freeze at the state's readable peak frame
                  (marketing screenshots / static export)
   CUSTOM PROPERTIES (set on .cn-presence)
     --cn-radius     REQUIRED. Must equal the host surface's border-radius.
     --cn-glow-gain  0.6 tight (default / shipping value), 1 standard, 1.5 wide
     --cn-speed      1 (default). Higher = faster. Never ship above 1.
   ========================================================================== */

:root {
  --cn-blue: #5856db; /* charge — Connily primary indigo (site CTA blue) */
  --cn-light: #b9b8f4; /* head tip — indigo light */
}

.cn-presence {
  /* inset -1px and radius +1px deliberately: the signature must cover the
     host's own anti-aliased rounded corner, or a 1px sliver of the host
     background shows OUTSIDE the line and reads as a stray white border. */
  position: absolute;
  inset: -1px;
  border-radius: calc(var(--cn-radius, 16px) + 1px);
  overflow: hidden;
  pointer-events: none;
  isolation: isolate;

  --cn-glow-gain: 0.6;
  --cn-speed: 1;
  --cn-rest-line: rgba(88, 86, 219, 0.26);
  --cn-rest-glow: rgba(88, 86, 219, 0.1);
}

/* ---- scale range ---------------------------------------------------------
   The line steps between three fixed weights. Only the glow scales.        */
.cn-presence[data-size="full"] {
  --cn-band: 3px;
  --cn-glow: calc(9px * var(--cn-glow-gain));
  --cn-blur: calc(11px * var(--cn-glow-gain));
  --cn-lap: calc(3.4s / var(--cn-speed));
  --cn-bloom: calc(24px * var(--cn-glow-gain));
}
.cn-presence[data-size="card"] {
  --cn-band: 2.5px;
  --cn-glow: calc(3.5px * var(--cn-glow-gain));
  --cn-blur: calc(4px * var(--cn-glow-gain));
  --cn-lap: calc(2.8s / var(--cn-speed));
  --cn-bloom: calc(9px * var(--cn-glow-gain));
}
.cn-presence[data-size="inline"] {
  --cn-band: 2px;
  --cn-glow: calc(2px * var(--cn-glow-gain));
  --cn-blur: calc(2.5px * var(--cn-glow-gain));
  --cn-lap: calc(2.8s / var(--cn-speed));
  --cn-bloom: calc(5px * var(--cn-glow-gain));
}

/* ---- layers -------------------------------------------------------------- */
.cn-presence__layer {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--cn-radius, 16px) + 1px);
}
.cn-presence__layer--glow {
  filter: blur(var(--cn-blur));
  opacity: 0.72;
}

/* The ring: a rounded rect whose interior is masked out, leaving only a band.
   padding = band width, so content-box XOR border-box == the band itself. */
.cn-presence__ring {
  position: absolute;
  inset: 1px;
  border-radius: var(--cn-radius, 16px);
  padding: var(--cn-band);
  overflow: hidden;
  background: var(--cn-rest-line);
  -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;
}
.cn-presence__layer--glow .cn-presence__ring {
  padding: calc(var(--cn-band) + var(--cn-glow));
  background: var(--cn-rest-glow);
}

/* The head: an oversized square carrying a conic gradient, rotating behind
   the ring mask. 265% guarantees it covers the corners of any aspect ratio. */
.cn-presence__head {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 265%;
  height: 265%;
  transform: translate(-50%, -50%);
}

/* Light bleeding inward from the boundary. Never fills the surface. */
.cn-presence__bloom {
  position: absolute;
  inset: 1px;
  border-radius: var(--cn-radius, 16px);
  box-shadow: inset 0 0 calc(var(--cn-bloom) * 2.2) rgba(88, 86, 219, 0.09);
}

/* ---- state: travelling ---------------------------------------------------
   Head runs clockwise. The only state that carries direction.             */
.cn-presence[data-state="travelling"] .cn-presence__layer--line .cn-presence__head,
.cn-presence[data-state="landing"] .cn-presence__layer--line .cn-presence__head {
  background: conic-gradient(
    from 0deg,
    rgba(88, 86, 219, 0) 0 42%,
    rgba(88, 86, 219, 0.45) 72%,
    #5856db 90%,
    #b9b8f4 98.5%,
    rgba(185, 184, 244, 0) 100%
  );
}
.cn-presence[data-state="travelling"] .cn-presence__layer--glow .cn-presence__head,
.cn-presence[data-state="landing"] .cn-presence__layer--glow .cn-presence__head {
  background: conic-gradient(
    from 0deg,
    rgba(88, 86, 219, 0) 0 36%,
    rgba(88, 86, 219, 0.3) 66%,
    rgba(88, 86, 219, 0.8) 88%,
    rgba(185, 184, 244, 0.95) 98%,
    rgba(185, 184, 244, 0) 100%
  );
}
.cn-presence[data-state="travelling"] .cn-presence__head {
  animation: cn-spin var(--cn-lap) linear infinite;
  animation-delay: -0.62s;
}

/* Wide-thin surfaces (inline pills): the standard ~209deg trail spans both
   long edges of a 10:1 strip at once, reading as two heads circulating in
   opposite directions (Robert, 2026-08-26). Tighter ~79deg arc keeps one
   lit segment on screen through most of the lap. Same colour ramp, same
   speed - only the trail length changes, and only at this size. */
/* And no glow copy at this size while travelling: the blurred dark-indigo
   layer extends OUTSIDE the hairline, and on a small pill against a white
   modal it reads as a dirty smudge under the border, not light (Robert's
   second review, 2026-08-26). The sharp 2px band carries the travelling
   light alone; thinking keeps its glow (it breathes in place and never
   reads as a moving blob). */
.cn-presence[data-size="inline"][data-state="travelling"] .cn-presence__layer--glow,
.cn-presence[data-size="inline"][data-state="landing"] .cn-presence__layer--glow {
  display: none;
}
/* Tracer, not trail. The maths that killed the first attempt: on a 7.5:1
   pill the corner sits at ~82deg from vertical, so any arc wider than
   ~15deg lights the top and bottom edges as two DISCONNECTED segments in
   the middle of the strip - which reads as two heads. A ~36deg arc stays
   a single connected light: a short comet on a long edge, bending around
   the corner at the ends. Verified frame-by-frame at 0/90/180/270deg. */
.cn-presence[data-size="inline"][data-state="travelling"] .cn-presence__layer--line .cn-presence__head,
.cn-presence[data-size="inline"][data-state="landing"] .cn-presence__layer--line .cn-presence__head {
  background: conic-gradient(
    from 0deg,
    rgba(88, 86, 219, 0) 0 90%,
    rgba(88, 86, 219, 0.45) 93%,
    #5856db 97%,
    #b9b8f4 99.5%,
    rgba(185, 184, 244, 0) 100%
  );
}
.cn-presence[data-size="inline"][data-state="travelling"] .cn-presence__layer--glow .cn-presence__head,
.cn-presence[data-size="inline"][data-state="landing"] .cn-presence__layer--glow .cn-presence__head {
  background: conic-gradient(
    from 0deg,
    rgba(88, 86, 219, 0) 0 74%,
    rgba(88, 86, 219, 0.3) 85%,
    rgba(88, 86, 219, 0.8) 94%,
    rgba(185, 184, 244, 0.95) 99%,
    rgba(185, 184, 244, 0) 100%
  );
}

/* ---- state: thinking -----------------------------------------------------
   Head parks at -40deg. Line, glow and bloom brighten together, 2.2s.     */
.cn-presence[data-state="thinking"] .cn-presence__layer--line .cn-presence__head {
  background: conic-gradient(
    from -40deg,
    rgba(88, 86, 219, 0) 0 38%,
    rgba(88, 86, 219, 0.3) 70%,
    #5856db 90%,
    #b9b8f4 100%
  );
}
.cn-presence[data-state="thinking"] .cn-presence__layer--glow .cn-presence__head {
  background: conic-gradient(
    from -40deg,
    rgba(88, 86, 219, 0) 0 32%,
    rgba(88, 86, 219, 0.28) 66%,
    rgba(88, 86, 219, 0.8) 90%,
    rgba(185, 184, 244, 0.9) 100%
  );
}
.cn-presence[data-state="thinking"] .cn-presence__layer,
.cn-presence[data-state="thinking"] .cn-presence__bloom {
  animation: cn-breathe calc(2.2s / var(--cn-speed)) ease-in-out infinite;
}
.cn-presence[data-state="thinking"] .cn-presence__bloom {
  box-shadow: inset 0 0 calc(var(--cn-bloom) * 2.2) rgba(88, 86, 219, 0.14);
}

/* ---- state: landing ------------------------------------------------------
   One shot, ~1.5s, never loops. Ends by handing over to authored.
   Re-trigger by setting data-state="" then back to "landing" on next frame. */
.cn-presence[data-state="landing"] .cn-presence__head {
  animation: cn-spin calc(1.5s / var(--cn-speed)) linear 1 both;
}
.cn-presence[data-state="landing"] .cn-presence__layer--line {
  animation: cn-settle calc(1.5s / var(--cn-speed)) ease-out 1 both;
}
.cn-presence[data-state="landing"] .cn-presence__layer--glow,
.cn-presence[data-state="landing"] .cn-presence__bloom {
  animation: cn-flash calc(1.5s / var(--cn-speed)) ease-out 1 both;
}

/* ---- state: authored -----------------------------------------------------
   Provenance, not activity. The origin corner alone. No motion, ever.
   This is the most-seen form: it persists indefinitely on finished work.   */
.cn-presence[data-state="authored"] .cn-presence__ring {
  background: transparent;
}
.cn-presence[data-state="authored"] .cn-presence__head {
  left: 0;
  top: 0;
  width: 42%;
  height: 42%;
  transform: none;
  animation: none;
  background: linear-gradient(135deg, #b9b8f4, #5856db 48%, rgba(88, 86, 219, 0) 80%);
}
.cn-presence[data-state="authored"] .cn-presence__layer--glow {
  opacity: 0.5;
}
.cn-presence[data-state="authored"] .cn-presence__bloom {
  box-shadow: inset 0 0 calc(var(--cn-bloom) * 2.2) rgba(88, 86, 219, 0.06);
}

/* ---- keyframes ----------------------------------------------------------- */
@keyframes cn-spin {
  from {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}
@keyframes cn-breathe {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 1;
  }
}
@keyframes cn-settle {
  0% {
    opacity: 0.2;
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0.34;
  }
}
@keyframes cn-flash {
  0% {
    opacity: 0;
  }
  16% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* ---- still form (data-still) --------------------------------------------
   The spec's static-export recipe: pause at the state's readable peak, not
   at keyframe 0 (the trough looks broken). Used for marketing screenshots
   and the demo's frozen-frame check.
     travelling — keeps its own -0.62s delay: lit head, tail decaying behind
     thinking   — -1.1s into the 2.2s breath = the peak
     landing    — -0.27s into the 1.5s one-shot = the flooded boundary
     authored   — already static                                            */
.cn-presence[data-still] .cn-presence__head,
.cn-presence[data-still] .cn-presence__layer,
.cn-presence[data-still] .cn-presence__bloom {
  animation-play-state: paused !important;
}
.cn-presence[data-still][data-state="thinking"] .cn-presence__layer,
.cn-presence[data-still][data-state="thinking"] .cn-presence__bloom {
  animation-delay: -1.1s;
}
.cn-presence[data-still][data-state="landing"] .cn-presence__head,
.cn-presence[data-still][data-state="landing"] .cn-presence__layer--line,
.cn-presence[data-still][data-state="landing"] .cn-presence__layer--glow,
.cn-presence[data-still][data-state="landing"] .cn-presence__bloom {
  animation-delay: -0.27s;
}

/* ---- reduced motion -----------------------------------------------------
   Mandatory. Falls back to the authored mark. Never strobe, never dim-loop.
   The [data-cn-motion="reduce"] ancestor hook is the same fallback forced
   programmatically (demo toggle / static contexts). KEEP THE TWO BLOCKS IN
   LOCKSTEP — identical declarations, different trigger.                    */
@media (prefers-reduced-motion: reduce) {
  .cn-presence .cn-presence__head,
  .cn-presence .cn-presence__layer,
  .cn-presence .cn-presence__bloom {
    animation: none !important;
  }
  .cn-presence .cn-presence__ring {
    background: transparent;
  }
  .cn-presence .cn-presence__head {
    left: 0;
    top: 0;
    width: 42%;
    height: 42%;
    transform: none;
    background: linear-gradient(135deg, #b9b8f4, #5856db 48%, rgba(88, 86, 219, 0) 80%) !important;
  }
}
[data-cn-motion="reduce"] .cn-presence .cn-presence__head,
[data-cn-motion="reduce"] .cn-presence .cn-presence__layer,
[data-cn-motion="reduce"] .cn-presence .cn-presence__bloom {
  animation: none !important;
}
[data-cn-motion="reduce"] .cn-presence .cn-presence__ring {
  background: transparent;
}
[data-cn-motion="reduce"] .cn-presence .cn-presence__head {
  left: 0;
  top: 0;
  width: 42%;
  height: 42%;
  transform: none;
  background: linear-gradient(135deg, #b9b8f4, #5856db 48%, rgba(88, 86, 219, 0) 80%) !important;
}
