/* Site Insight cards with drawings (site/snippets/blocks/sicards.php, bulk
   fixes B5, 2026-11-29): a row of cards, each with its own small drawing
   (site/snippets/sf/draw/, 160 x 120, the shared dg-, cw- and pb- classes in
   blocks.css). Two layouts: steps (numbered) and routes (with a link at the
   foot). Linked by the block itself (peanut_page_css), once per page. Every
   selector names a sicards class. Tokens only.

   A2: the cards in a row share one height (grid stretch), their drawing
   panels one height (a fixed ratio), so numbers and titles start on one
   line; the body stretches and the link sits at the foot.

   Finished by default (no script, reduced motion, ?fx=off, print): every
   drawing whole. With motion each drawing waits for motion.js's .is-in
   (data-play) and draws itself in once. Transform, opacity and stroke only,
   so nothing moves the layout. */

@layer blocks {
  .sicards__grid {
    display: grid;
    gap: var(--space-4);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .sicards__card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    background: var(--color-white);
    border: var(--border);
    border-radius: var(--radius-sm);
    color: var(--color-ink);
  }

  /* the drawing's panel: one fixed height, so every panel in a row is the same height
     and every number and title below it starts on one line */
  .sicards__art {
    display: grid;
    place-items: center;
    height: 9rem;
    padding: var(--space-1) var(--space-2);
    background: var(--color-paper);
    border-block-end: var(--border);
  }

  .sicards__art .ds-draw {
    width: auto;
    max-width: 100%;
    height: 100%;
  }

  .sicards__body {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    padding: var(--space-3);
  }

  .sicards__num {
    margin: 0 0 var(--space-2);
    font-family: var(--font-heading);
    font-size: var(--step-4);
    font-weight: var(--weight-display);
    line-height: 1;
  }

  .sicards__name {
    margin: 0;
    font-family: var(--font-heading);
    font-size: var(--step-1);
    font-weight: var(--weight-heading);
    line-height: var(--leading-heading);
  }

  .sicards__text {
    margin: var(--space-2) 0 0;
    font-size: var(--text-body);
    line-height: var(--leading-body);
  }

  /* the link at the foot of the card, whatever the text's length */
  .sicards__more {
    margin: auto 0 0;
    padding-block-start: var(--space-3);
  }

  .sicards__outro {
    max-width: var(--measure);
    margin: var(--space-5) auto 0;
    text-align: center;
  }

  /* steps: three across from 48rem */
  @media (min-width: 48rem) {
    .sicards--steps .sicards__grid {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .sicards--steps.sicards--n2 .sicards__grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  /* routes: three cards go three across from 48rem, like the steps (never two and one alone);
     two or four go two across from 40rem, and four go four across from 64rem */
  @media (min-width: 40rem) {
    .sicards--routes:not(.sicards--n3) .sicards__grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  @media (min-width: 48rem) {
    .sicards--routes.sicards--n3 .sicards__grid {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }

  @media (min-width: 64rem) {
    .sicards--routes.sicards--n4 .sicards__grid {
      grid-template-columns: repeat(4, minmax(0, 1fr));
    }
  }

  @media print {
    .sicards__card {
      break-inside: avoid;
    }
  }
}

@layer motion {
  @media screen and (prefers-reduced-motion: no-preference) {
    /* the tier hero's draw-in on load is off for these drawings: they draw in when they come into view */
    html[data-fx~="diagrams"] .sicards .ds-draw :is(.dg-line, .dg-ring, .dg-node, .dg-label) {
      animation: none;
    }

    /* waiting for the scroll (only with motion.js's observer, keys diagrams and map, so a drawing is never left hidden) */
    html.js-motion[data-fx~="diagrams"][data-fx~="map"] .sicards__art[data-play]:not(.is-in) :is(.ds-a, .ds-b, .ds-c) {
      opacity: 0;
    }

    html.js-motion[data-fx~="diagrams"][data-fx~="map"] .sicards__art[data-play]:not(.is-in) .dg-line {
      stroke-dasharray: 1;
      stroke-dashoffset: 1;
    }

    html.js-motion[data-fx~="diagrams"][data-fx~="map"] .sicards__art[data-play].is-in :is(.ds-a, .ds-b, .ds-c) {
      animation: sicards-settle 520ms var(--ease) both;
    }

    html.js-motion[data-fx~="diagrams"][data-fx~="map"] .sicards__art[data-play].is-in .ds-a { animation-delay: calc(var(--sicards-delay, 0ms) + 150ms); }
    html.js-motion[data-fx~="diagrams"][data-fx~="map"] .sicards__art[data-play].is-in .ds-b { animation-delay: calc(var(--sicards-delay, 0ms) + 450ms); }
    html.js-motion[data-fx~="diagrams"][data-fx~="map"] .sicards__art[data-play].is-in .ds-c { animation-delay: calc(var(--sicards-delay, 0ms) + 750ms); }

    html.js-motion[data-fx~="diagrams"][data-fx~="map"] .sicards__art[data-play].is-in .dg-line {
      stroke-dasharray: 1;
      animation: sicards-draw 800ms var(--ease) calc(var(--sicards-delay, 0ms) + 300ms) both;
    }

    /* cards that come into view together start one after the other */
    .sicards__card:nth-child(2) .sicards__art { --sicards-delay: 200ms; }
    .sicards__card:nth-child(3) .sicards__art { --sicards-delay: 400ms; }
    .sicards__card:nth-child(4) .sicards__art { --sicards-delay: 600ms; }

    /* routes: a lift on hover and on keyboard focus inside, where the pointer can hover */
    @media (hover: hover) {
      .sicards--routes .sicards__card {
        transition: transform var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
      }

      .sicards--routes .sicards__card:is(:hover, :focus-within) {
        transform: translateY(-3px);
        box-shadow: var(--shadow-hard);
      }
    }
  }

  @keyframes sicards-settle {
    from {
      opacity: 0;
      transform: translateY(6px);
    }
  }

  @keyframes sicards-draw {
    from {
      stroke-dashoffset: 1;
    }

    to {
      stroke-dashoffset: 0;
    }
  }
}
