/* .services — four service cards (spec §5.7). Each card: picture first, then the words, a stack
   headed by "01 Title" (a cluster); desktop puts the picture beside the words (Mitchell 2026-11-16:
   picture first, "01 Title" under it). Never overflow hidden/auto here or around it: it kills the
   sticky stack.
   primitive tried: stack, switcher, with-sidebar for the card; fails: switcher gives the number a
   third of the row, with-sidebar wants two children (services.md "S3 tries"). With the number moved
   beside the title the card has two parts; with-sidebar still fails: it wraps by width, and the
   tablet layout must switch with the picture's <source media>. Side by side from 40em was tried and
   rejected (tall narrow pictures; Mitchell 2026-11-16). */

/* Every card as tall as the tallest: a shorter card stuck over a taller one would leave its bottom
   showing. primitive tried: stack; fails: a flex column cannot give its items one height (grid-auto-rows 1fr). */
.services > div {
  display: grid;
  grid-auto-rows: 1fr;
  gap: var(--space-2xs);
}

/* Solid fill, not see-through white (bg-raised in the HTML): the next card covers this one.
   Rows: the words take the spare height (the list grows: flex-grow in the HTML), so Learn more
   sits at the bottom. */
.services article {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: var(--space-s-md); /* the stack's own gap: picture → words as even as the words' gaps */
  padding: var(--space-md);
}

/* The dotted wave's layer (wave.css) is the picture's own box in the top right, so its fade
   (wave.css's starting values: 20%, from 0 over its left 60%) falls where the old picture's did. */
.services .wave {
  inline-size: var(--services-wave-w);
  aspect-ratio: 640 / 280; /* wave.svg's viewBox */
}

/* The number: Display (Light and line height 1 in the HTML), about 1.6x the title on phones
   (Mitchell 2026-11-16: too large). */
/* lint-allow: heading-role — the h3 is only inside :has(); this rule styles the number span before the title, not a heading; 2026-11-16 */
.services span:has(+ h3) {
  font-family: var(--font-display);
  font-size: var(--step-3);
}

/* primitive tried: switcher, grid (auto-fill); fails: the items go 3 across at 503 wide (1024x768) but stay
   1 down at 1083 wide (1200x1600 tablet): the switch follows the card's layout query, not the list's
   width (measured 2026-11-17). */
.services article ul {
  display: grid;
  gap: var(--space-md);
}
.services article li,
.services article p {
  --icon-size: var(--space-lg);
  --with-icon-space: var(--space-s);
  color: var(--text-muted);
}
.services article li {
  font-size: var(--step--1);
  line-height: 1.45;
}

/* Tablets and desktops: a larger number, title, icons and item text (Mitchell 2026-11-16: the
   title holds its own beside or under a large picture; larger item text). */
@media (width >= 40em) {
  .services span:has(+ h3) {
    font-size: var(--step-4);
  }
  .services h3 {
    font-size: var(--step-3); /* weight: font-semibold in the HTML */
  }
  .services article li,
  .services article p {
    --icon-size: var(--space-xl);
    font-size: var(--step-0);
  }
}

/* Tablets (ruled; = the <source media>): the wide crop. */
@media (width >= 40em) and ((width < 64em) or ((orientation: portrait) and (width < 80em))) {
  .services .frame {
    --d: 6.3;
  }
}

/* Desktop (ruled): picture | words, the picture the card's height, cropped (Mitchell 2026-11-16:
   no empty bands as the text wraps); three items across, each icon above its words. */
@media (width >= 64em) and ((orientation: landscape) or (width >= 80em)) {
  .services {
    --services-peek: calc(var(--space-lg) + var(--step-4) + var(--space-2xs)); /* a covered card shows "01 Title" as a bar */
  }
  .services article {
    --services-tallest: var(--services-tallest-desktop);
    grid-template: auto / minmax(0, 5fr) minmax(0, 7fr);
    column-gap: var(--space-lg);
    padding: var(--space-lg);
  }
  /* One line, so a covered card's bar shows the whole title (Mitchell 2026-11-16: "Interchange" hid).
     Under about 1366 wide the cap wins: 1024 to 1247 wide wrapped "Custom Packaging". */
  .services h3 {
    font-size: var(--services-title-desktop);
  }
  .services .frame {
    align-self: stretch;
  }
  .services article ul {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    column-gap: var(--space-s);
  }
  .services article li,
  .services article p {
    flex-direction: column;
    row-gap: var(--space-xs);
  }
}

/* The sticky stack (ruled: screen with motion allowed; print and reduced motion get the plain list,
   and so do desktop windows under 56em tall: Mitchell 2026-11-16, every title bar shows and every card
   can be read; the stack needs the 4th card's line plus a card, at most 891px (55.7em), measured 1024
   to 5120 wide). Each card sticks under the header, one bar (--services-peek, 0 on phones and tablets)
   lower than the one before; a card taller than the room left sticks higher, so its Learn more is on
   screen before the next card covers it. Keyboard focus lifts its card over the one covering it. */
@media screen and (prefers-reduced-motion: no-preference) and (not ((width >= 64em) and ((orientation: landscape) or (width >= 80em)) and (height < 56em))) {
  /* Each card's two margins add up to one bar less than nothing, so each row is one bar shorter than
     its card: the padding gives the four bars back (the list ends where card 04 ends). */
  .services > div {
    padding-block-end: calc(4 * var(--services-peek, 0px));
  }
  .services article {
    position: sticky;
    inset-block-start: min(var(--header-height) + var(--space-md) + var(--services-i, 0) * var(--services-peek, 0px), 100svb - var(--services-tallest, var(--services-tallest-phone)));
    /* All four leave together (Mitchell 2026-11-16: card 04 slid on over the bars). A sticky card
       stops holding when its margin box meets the end of the list's content box; the last card met
       it on arrival. Margins move that end for each card: i bars down at the start, i + 1 bars back
       at the end. The end margin pulls the next row up as far as that row's start margin pushes its
       card down, so the cards keep the list's gap (Mitchell 2026-11-17: no wide gaps); and card i
       stops holding 3 - i bars above card 04, which is where it sits in the stack. */
    margin-block: calc(var(--services-i, 0) * var(--services-peek, 0px)) calc(-1 * (var(--services-i, 0) + 1) * var(--services-peek, 0px));
  }
  /* lint-allow: unchecked — at rest nothing has focus, so no check state matches it; only a key press reads it: 3 of the 6 Tab / Shift+Tab tests in services_test fail without it (mutated 2026-11-16) */
  .services article:has(:focus-visible) {
    z-index: 1;
  }
}
