/* ============================================================
   TYING — DEEP CHOREOGRAPHY
   Phases (driven by .tying.in / .tying.tied / .tying.unfurled):
   0. idle          — empty canvas
   1. .in           — kicker fades, headline words rise
   2. (auto +400ms) — cards fly in from random off-canvas positions
   3. (auto +1200)  — ropes/threads draw down through the cards
   4. (auto +2200) — .tied: cards snap into a tight stack, knot bulges
   5. (auto +3000) — .unfurled: stack opens like a book, sparks pop
   ============================================================ */

.tying {
  position: relative;
  background: #fff;
  padding: 80px 0 100px;
  overflow: hidden;
  border: 0 !important;
}
section:has(+ .tying) { border-bottom: 0 !important; }
.tying + section { border-top: 0 !important; }

/* faint mono "chapter rule" labels in the corners */
.tying::before,
.tying::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 14vw;
  height: 1px;
  background: var(--hair);
  opacity: 0.7;
  pointer-events: none;
}
.tying::before { left: 0; }
.tying::after { right: 0; }

.tying_canvas {
  position: relative;
  height: 360px;
  margin-top: 36px;
}
.tying_canvas_inner { position: relative; width: 100%; height: 100%; }

/* ── headline ───────────────────────────────────────────── */
.tying_q {
  position: relative;
  text-align: center;
  z-index: 5;
  pointer-events: none;
}
.tying_q .kicker {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--voice-positive, var(--brand));
  margin-bottom: 22px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 500ms ease 200ms, transform 500ms ease 200ms;
}
.tying_q .kicker::before,
.tying_q .kicker::after {
  content: '';
  width: 28px; height: 1px;
  background: currentColor;
  opacity: 0.5;
}
.tying_q .progress {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 12px;
  opacity: 0.5;
}
.tying_q .progress span {
  width: 6px; height: 6px; border-radius: 999px;
  background: currentColor; opacity: 0.4;
  transition: opacity 400ms ease, transform 400ms ease;
}
.tying.in .tying_q .progress span.on { opacity: 1; transform: scale(1.3); }

.tying_q h3 {
  margin: 0;
  font-size: clamp(56px, 9vw, 112px);
  font-weight: 600;
  line-height: 0.96;
  letter-spacing: -0.042em;
  color: var(--ink);
  text-wrap: balance;
  max-width: 16ch;
  margin-inline: auto;
}
.tying_q h3 .w {
  display: inline-block;
  opacity: 0;
  transform: translateY(70%) skewY(8deg);
  transition: opacity 700ms cubic-bezier(0.2, 0.9, 0.2, 1),
              transform 800ms cubic-bezier(0.2, 0.9, 0.2, 1);
}
.tying.in .tying_q h3 .w { opacity: 1; transform: translateY(0) skewY(0); }
.tying.in .tying_q h3 .w:nth-child(1) { transition-delay: 350ms; }
.tying.in .tying_q h3 .w:nth-child(2) { transition-delay: 480ms; }
.tying.in .tying_q h3 .w:nth-child(3) { transition-delay: 610ms; }
.tying.in .tying_q h3 .w:nth-child(4) { transition-delay: 740ms; }
.tying.in .tying_q h3 .w:nth-child(5) { transition-delay: 870ms; }
.tying.in .tying_q h3 .w:nth-child(6) { transition-delay: 1000ms; }
.tying.in .tying_q h3 .w:nth-child(7) { transition-delay: 1130ms; }
.tying_q h3 em {
  font-style: italic;
  color: var(--voice-positive, var(--brand));
  font-weight: 600;
  position: relative;
}
.tying_q h3 em::after {
  content: ''; position: absolute;
  left: 0; right: 0; bottom: 4%;
  height: 3px; background: currentColor;
  transform: scaleX(0); transform-origin: left;
  transition: transform 600ms cubic-bezier(0.2, 0.9, 0.2, 1) 1500ms;
}
.tying.in .tying_q h3 em::after { transform: scaleX(1); }

.tying_sub {
  margin: 22px auto 0;
  font-size: 15px; line-height: 1.5;
  color: var(--slate);
  max-width: 52ch;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.02em;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 500ms ease 1700ms, transform 500ms ease 1700ms;
}
.tying.in .tying_sub { opacity: 1; transform: translateY(0); }

/* ── audit-trail rail (single hairline behind the cards) ─
   Replaces the old SVG ropes/chain. A 1px ink rail and a
   small mono chip are the only "background" — present from
   the start, but only emphasized once the cards line up. */
.tying_trail {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 760px;
  height: 1px;
  margin-left: -380px;
  background: var(--hair-2);
  transform-origin: left center;
  transform: scaleX(0.2);
  opacity: 0.5;
  z-index: 1;
  pointer-events: none;
  transition: transform 1100ms cubic-bezier(0.2, 0.9, 0.2, 1) 200ms,
              opacity 600ms ease 200ms,
              background 500ms ease 1500ms;
}
.tying.in .tying_trail { opacity: 0.6; transform: scaleX(0.6); }
.tying.tied .tying_trail { transform: scaleX(0.85); }
.tying.unfurled .tying_trail {
  opacity: 1;
  transform: scaleX(1);
  background: var(--ink);
}
.tying_trail_chip {
  position: absolute;
  left: 50%;
  top: 50%;
  margin-top: 92px;
  transform: translateX(-50%);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--n500);
  white-space: nowrap;
  opacity: 0;
  z-index: 1;
  pointer-events: none;
  transition: opacity 500ms ease, color 500ms ease;
}
.tying.unfurled .tying_trail_chip {
  opacity: 1;
  color: var(--voice-positive, var(--brand));
  transition-delay: 1300ms;
}

/* ── cards ─────────────────────────────────────────────── */
.tying_stack {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 760px;
  height: 200px;
  pointer-events: none;
  z-index: 2;
  perspective: 1400px;
}
.stk_card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 132px;
  height: 162px;
  margin-left: -66px;
  margin-top: -81px;
  background: #fff;
  border: 1px solid var(--hair-2);
  box-shadow: 0 10px 30px -14px rgba(11, 18, 32, 0.22);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0;
  transform-origin: center;
  transition: transform 1000ms cubic-bezier(0.34, 1.4, 0.64, 1),
              opacity 500ms ease,
              box-shadow 600ms ease,
              border-color 400ms ease;
}
.stk_card::before {
  content: attr(data-i);
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--n500);
  opacity: 0;
  transition: opacity 400ms ease, color 220ms ease;
}
.tying.unfurled .stk_card::before { opacity: 0.55; transition: opacity 400ms ease 800ms, color 220ms ease; }
.tying.unfurled .stk_card:hover::before { transition: opacity 220ms ease, color 220ms ease; }
.stk_card .stk_top {
  display: flex; justify-content: space-between; width: 100%;
  font-size: 8px; opacity: 0.5; letter-spacing: 0.16em;
}
.stk_card .stk_label {
  font-size: 12px; letter-spacing: 0.02em;
  text-transform: none;
  line-height: 1.25;
  word-break: break-word;
}
.stk_card .stk_meta {
  display: flex; gap: 6px; flex-wrap: wrap;
  font-size: 8px; opacity: 0.5; letter-spacing: 0.12em;
}
.stk_card .stk_meta b { color: var(--voice-positive, var(--brand)); font-weight: 600; }
.stk_card .stk_dot {
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--orange, #F25C37);
}

/* phase 1 — fragmented: cards drifted apart, off-axis */
.stk_card.s1 { transform: translate(-280px, -32px) rotate(-12deg) scale(0.94); }
.stk_card.s2 { transform: translate(-110px,  44px) rotate(-5deg)  scale(0.97); }
.stk_card.s3 { transform: translate(  40px, -54px) rotate(7deg)   scale(1.00); }
.stk_card.s4 { transform: translate( 200px,  38px) rotate(11deg)  scale(0.95); }
.stk_card.s5 { transform: translate( 320px, -10px) rotate(-3deg)  scale(0.96); }
.tying.in .stk_card { opacity: 1; }
.tying.in .stk_card.s1 { transition-delay: 200ms; }
.tying.in .stk_card.s2 { transition-delay: 320ms; }
.tying.in .stk_card.s3 { transition-delay: 440ms; }
.tying.in .stk_card.s4 { transition-delay: 560ms; }
.tying.in .stk_card.s5 { transition-delay: 680ms; }

/* phase 2 — tied: tight central stack */
.tying.tied .stk_card { transition-delay: 0ms; }
.tying.tied .stk_card.s1 { transform: translate(-12px, -10px) rotate(-3deg); }
.tying.tied .stk_card.s2 { transform: translate( -6px,  -5px) rotate(-1.4deg); }
.tying.tied .stk_card.s3 { transform: translate(   0,    0)   rotate(0deg); }
.tying.tied .stk_card.s4 { transform: translate(  6px,   5px) rotate(1.4deg); }
.tying.tied .stk_card.s5 { transform: translate( 12px,  10px) rotate(3deg); }
.tying.tied .stk_card { box-shadow: 0 14px 40px -18px rgba(11, 18, 32, 0.28); }

/* phase 3 — reconciled: even row sitting on the trail */
.tying.unfurled .stk_card {
  transition: transform 600ms cubic-bezier(0.2, 0.9, 0.2, 1),
              opacity 500ms ease,
              border-color 400ms ease,
              box-shadow 400ms ease,
              filter 300ms ease;
  box-shadow: 0 16px 36px -22px rgba(11, 18, 32, 0.20);
  pointer-events: auto;
  cursor: pointer;
}
.tying.unfurled .stk_card.s1 { --tx: -300px; transform: translate(var(--tx), var(--ty, 0)); }
.tying.unfurled .stk_card.s2 { --tx: -150px; transform: translate(var(--tx), var(--ty, 0)); }
.tying.unfurled .stk_card.s3 { --tx:    0px; transform: translate(var(--tx), var(--ty, 0)); border-color: var(--voice-positive, var(--brand)); }
.tying.unfurled .stk_card.s4 { --tx:  150px; transform: translate(var(--tx), var(--ty, 0)); }
.tying.unfurled .stk_card.s5 { --tx:  300px; transform: translate(var(--tx), var(--ty, 0)); }

/* hover affordances — only active in resolved state */
.tying.unfurled .stk_card::after {
  content: '';
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: -1px;
  height: 2px;
  background: var(--voice-positive, var(--brand));
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 380ms cubic-bezier(0.2, 0.9, 0.2, 1);
}
.tying.unfurled .stk_card:hover {
  --ty: -10px;
  transform: translate(var(--tx), var(--ty)) scale(1.04);
  border-color: var(--voice-positive, var(--brand));
  box-shadow:
    0 28px 50px -22px rgba(11, 18, 32, 0.32),
    0 0 0 1px rgba(0, 110, 255, 0.18);
  z-index: 5;
}
.tying.unfurled .stk_card:hover::after { transform: scaleX(1); }
.tying.unfurled .stk_card:hover::before {
  opacity: 1;
  color: var(--voice-positive, var(--brand));
}
/* dim siblings when one card is being focused */
.tying.unfurled .tying_stack:hover .stk_card:not(:hover) {
  opacity: 0.45;
  filter: saturate(0.6);
}

/* center card breathes — a quiet "this is the source of truth" pulse */
@keyframes centerPulse {
  0%, 100% {
    box-shadow:
      0 16px 36px -22px rgba(11, 18, 32, 0.20),
      0 0 0 0 rgba(0, 110, 255, 0);
  }
  50% {
    box-shadow:
      0 16px 36px -22px rgba(11, 18, 32, 0.20),
      0 0 0 10px rgba(0, 110, 255, 0.06);
  }
}
.tying.unfurled .stk_card.s3 {
  animation: centerPulse 3.2s ease-in-out infinite;
  animation-delay: 1.8s;
}
.tying.unfurled .stk_card.s3:hover { animation: none; }

/* trail "reading head" — a small dot scans the rail repeatedly */
.tying_trail_head {
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: -384px;
  margin-top: -3px;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--voice-positive, var(--brand));
  box-shadow: 0 0 0 4px rgba(0, 110, 255, 0.14);
  opacity: 0;
  z-index: 1;
  pointer-events: none;
  transition: opacity 400ms ease 1500ms;
}
.tying.unfurled .tying_trail_head {
  opacity: 1;
  animation: trailScan 5.6s cubic-bezier(0.65, 0, 0.35, 1) infinite;
  animation-delay: 1.6s;
}
@keyframes trailScan {
  0%   { transform: translateX(0);    opacity: 0; }
  8%   { opacity: 1; }
  92%  { opacity: 1; }
  100% { transform: translateX(768px); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .tying.unfurled .tying_trail_head { animation: none; opacity: 0; }
  .tying.unfurled .stk_card.s3 { animation: none; }
}

/* ── side micro-labels (live narration of phase) ─────── */
.tying_phase {
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--n500);
  white-space: nowrap;
  z-index: 4;
}
.tying_phase .ph_dot {
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--n500); opacity: 0.4;
}
.tying_phase .ph {
  position: absolute;
  left: 50%; top: 0;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 360ms ease;
  white-space: nowrap;
}
.tying_phase .ph.now { opacity: 1; color: var(--ink); }
.tying.in       .tying_phase .ph_in       { opacity: 1; color: var(--ink); }
.tying.tied     .tying_phase .ph_in       { opacity: 0; }
.tying.tied     .tying_phase .ph_tied     { opacity: 1; color: var(--ink); }
.tying.unfurled .tying_phase .ph_tied     { opacity: 0; }
.tying.unfurled .tying_phase .ph_unfurled { opacity: 1; color: var(--voice-positive, var(--brand)); }

/* ── side tickers (left/right vertical type) ─────────── */
.tying_tick {
  position: absolute;
  top: 50%;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--n500);
  opacity: 0.6;
  writing-mode: vertical-rl;
  transform: translateY(-50%) rotate(180deg);
  z-index: 4;
}
.tying_tick.left  { left: 16px; }
.tying_tick.right { right: 16px; transform: translateY(-50%); }

/* ── stage scrubber (mini progress timeline) ──────────── */
.tying_track {
  position: relative;
  margin: 56px auto 0;
  max-width: 540px;
  padding: 0 8px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: center;
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--n500);
}
.tying_track::before {
  content: '';
  position: absolute;
  top: 9px; left: 8%; right: 8%;
  height: 1px;
  background: var(--hair-2);
}
.tying_track .step {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.tying_track .step .dot {
  width: 10px; height: 10px; border-radius: 999px;
  background: #fff;
  border: 1px solid var(--hair-2);
  position: relative; z-index: 1;
  transition: background 400ms ease, border-color 400ms ease, transform 300ms ease;
}
.tying_track .step.active .dot {
  background: var(--ink);
  border-color: var(--ink);
  transform: scale(1.2);
}
.tying_track .step.done .dot {
  background: var(--voice-positive, var(--brand));
  border-color: var(--voice-positive, var(--brand));
}
.tying_track .step.active .lbl { color: var(--ink); }
.tying_track .step.done   .lbl { color: var(--voice-positive, var(--brand)); }

/* ── responsive ───────────────────────────────────────── */
@media (max-width: 920px) {
  .tying { padding: 56px 0 72px; }
  .tying_canvas { height: 280px; margin-top: 24px; }
  .tying_stack { width: 100%; height: 180px; }
  .tying_trail { width: 88%; margin-left: -44%; }
  .stk_card { width: 100px; height: 130px; margin-left: -50px; margin-top: -65px; padding: 10px 12px; font-size: 10px; }
  .stk_card .stk_label { font-size: 11px; }
  .stk_card.s1 { transform: translate(-110px, -28px) rotate(-10deg) scale(0.92); }
  .stk_card.s2 { transform: translate(-50px,  36px) rotate(-4deg)  scale(0.96); }
  .stk_card.s3 { transform: translate(  20px, -40px) rotate(6deg)   scale(1); }
  .stk_card.s4 { transform: translate(  80px,  30px) rotate(9deg)  scale(0.95); }
  .stk_card.s5 { transform: translate( 120px,  -8px) rotate(-3deg) scale(0.94); }
  .tying.unfurled .stk_card.s1 { --tx: -118px; transform: translate(var(--tx), var(--ty, 0)); }
  .tying.unfurled .stk_card.s2 { --tx:  -59px; transform: translate(var(--tx), var(--ty, 0)); }
  .tying.unfurled .stk_card.s3 { --tx:    0;   transform: translate(var(--tx), var(--ty, 0)); }
  .tying.unfurled .stk_card.s4 { --tx:   59px; transform: translate(var(--tx), var(--ty, 0)); }
  .tying.unfurled .stk_card.s5 { --tx:  118px; transform: translate(var(--tx), var(--ty, 0)); }
  .tying.unfurled .stk_card:hover { transform: translate(var(--tx), -8px) scale(1.04); }
  .tying_trail_head { margin-left: calc(-44vw); }
  @keyframes trailScan {
    0%   { transform: translateX(0); opacity: 0; }
    8%   { opacity: 1; }
    92%  { opacity: 1; }
    100% { transform: translateX(88vw); opacity: 0; }
  }
  .tying_trail_chip { font-size: 9px; margin-top: 78px; }
  .tying_q h3 { font-size: 38px; }
  .tying_tick { display: none; }
  .tying_track { display: none; }
  .tying::before, .tying::after { display: none; }
}

/* ============================================================
   STACKING SCROLL — sections "stack" with overlap
   ============================================================ */
.stack_top {
  position: relative;
  margin-top: -28px;
  z-index: 2;
  box-shadow: 0 -18px 40px -28px rgba(11, 18, 32, 0.22);
}
.stack_top::before {
  content: '';
  position: absolute;
  top: -1px; left: 50%;
  transform: translateX(-50%);
  width: 56px; height: 3px;
  background: var(--ink);
}
