/* ============================================================
   STAGE STEPS — «How it works» on /stage (StageSteps.astro)
   Requires: tokens.css, page.css, patterns.css (.block-head), surface.css, gallery.css

   Ported from the Webflow embed embed/stage-embed.html; why it behaves this way —
   EMBED-ISSUES.md §14–15.
   From 992 px: the section is a scroll track (height set by the script: steps × 120vh + 100vh); inside it a
   sticky card under the menu — the accordion on the left (5 of 12 columns, 4 from 1280), the slides on the right.
   Up to 991 px (tablet included): a Gallery in one fixed frame — each step a slide, its text above its picture,
   the bars under the frame. Each picture carries its own fill (--slide-bg), framed by the card's grey on every width.
   Motion: the slide, the highlight and the step's text change in place — the Toggle character (tokens.css).
   ============================================================ */

.stage-steps {
  --motion-dur: var(--duration-toggle);
  --motion-ease: var(--ease-toggle);
  --steps-ease: var(--motion-ease);
  --steps-dur: var(--motion-dur);
  position: relative; /* the gap above comes from .block-head's own margin (patterns.css) — not doubled here */
}

/* ── Sticky frame ── */
.stage-steps__sticky {
  position: sticky;
  top: var(--nav-height);
  height: calc(100vh - var(--nav-height));
  padding-bottom: var(--space-md);
  box-sizing: border-box;
}
.stage-steps__sticky > .container { height: 100%; display: flex; flex-direction: column; }
.stage-steps__sticky .stage-steps__card { flex: 1; min-height: 0; }

/* Still copy (StageSteps still — the /design-system catalog): no scroll track, the frame in the page flow; the
   card at least three quarters of the screen, as the sticky card reads on a page, and taller when the longest
   step needs it (the script sizes it, as on the page) */
.stage-steps--still .stage-steps__sticky { position: static; height: auto; }
@media (min-width: 62rem) { .stage-steps--still .stage-steps__card { min-height: 75vh; } }

/* ── Card: a panel surface ── */
.stage-steps__card {
  display: flex;
  height: 100%;
  box-sizing: border-box;
  border-radius: var(--radius-lg);
  background: var(--color-bg-grey);
  overflow: hidden;
}

/* ── Left: the steps ── */
.stage-steps__accordion {
  position: relative;
  flex: 0 0 41.67%;
  box-sizing: border-box;
  padding: var(--space);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
@media (min-width: 80rem) { .stage-steps__accordion { flex-basis: 33.33%; } }

/* The dark plate under the active step: moved by the script, so it slides between steps */
.stage-steps__highlight {
  position: absolute;
  top: 0;
  left: var(--space);
  right: var(--space);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  pointer-events: none;
  transition: transform var(--steps-dur) var(--steps-ease), height var(--steps-dur) var(--steps-ease);
}

.stage-steps__step {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  width: 100%;
  min-height: 0;
  flex: 0 1 auto;
  padding: var(--space-sm);
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--color-text-grey-on-grey);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.stage-steps__step.is-active { flex: 1 1 0; padding-bottom: var(--space); }
.stage-steps__step.is-active,
.stage-steps__step.is-read { color: var(--color-text); }
.stage-steps__num, .stage-steps__title { transition: color var(--steps-dur) var(--steps-ease); }
.stage-steps__num { flex-shrink: 0; }
.stage-steps__step:focus-visible { outline: var(--border-thin) solid var(--color-text); outline-offset: calc(-1 * var(--border-thin)); }

.stage-steps__content { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; gap: var(--space-xs); }
.stage-steps__desc, .stage-steps__note {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
}
.stage-steps__desc { color: var(--color-text); }
.stage-steps__note { color: var(--color-text-grey); margin-top: auto; }
.stage-steps__step.is-active .stage-steps__desc { max-height: 12rem; opacity: 1; }
.stage-steps__step.is-active .stage-steps__note { max-height: 8rem; opacity: 1; }
.stage-steps__step.is-active :is(.stage-steps__desc, .stage-steps__note) {
  transition: max-height var(--steps-dur) var(--steps-ease), opacity calc(var(--steps-dur) * 0.75) var(--steps-ease);
}

/* ── Right: the slides ── */
.stage-steps__visual {
  position: relative;
  flex: 1;
  overflow: hidden;
  /* the pictures sit in a frame of the card's grey: 8 from the card edge, radius 16 − 8 */
  margin: var(--space-xs) var(--space-xs) var(--space-xs) 0;
  border-radius: var(--radius-sm);
}
.stage-steps__slide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg) var(--space);
  background: var(--slide-bg);
  transform: translateY(101%); /* 101: see place() in StageSteps.astro */
  transition: transform var(--steps-dur) var(--steps-ease);
  will-change: transform;
}
.stage-steps__slide:first-child { transform: none; }
.stage-steps__slide picture { display: contents; }
.stage-steps__slide img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-md);
}

/* Phone and tablet part (Gallery), hidden on desktop */
.stage-steps__phone { display: none; }

/* ── Up to 991 px: a Gallery (gallery.css) in one fixed frame — each step a slide, its text on a plate of the page
   colour over its picture on its own ground; the bars under the frame ── */
@media (max-width: 61.9375rem) {
  .stage-steps__sticky { position: static; height: auto; padding-bottom: 0; }
  .stage-steps__card { display: none; }
  .stage-steps__phone { display: block; }
  .stage-steps .stage-steps__frame.card { padding: var(--space-xs) var(--space-xs) 0; } /* the card's grey, 8 around */
  .stage-steps__ptext {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-sm) var(--space);
    border-radius: var(--radius-sm); /* nested in the 16 card with 8 of margin */
    background: var(--color-bg);
    color: var(--color-text);
  }
  .stage-steps__mob-num { flex-shrink: 0; }
  .stage-steps__mob-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--space-xs); }
  .stage-steps__mob-body p { margin: 0; max-width: var(--measure-lead); } /* tablets: the plate spans the frame, the line stays readable */
  .stage-steps__mob-note { color: var(--color-text-grey); margin-top: var(--space-xs); }
  .stage-steps__ppic { margin-top: var(--space-xs); border-radius: var(--radius-sm) var(--radius-sm) 0 0; overflow: hidden; background: var(--slide-bg); }
  .stage-steps__ppic picture { display: contents; }
  .stage-steps .gallery__dots { color: var(--color-text); }
}
/* Tablets (768–991): one landscape frame for every picture, the picture fits inside it — a portrait step does not
   set the height */
@media (min-width: 48rem) and (max-width: 61.9375rem) {
  .stage-steps__ppic { display: flex; align-items: center; justify-content: center; aspect-ratio: 2202 / 1422; padding: var(--space-md); }
  .stage-steps__ppic img { display: block; width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--radius-md); }
}
/* Phones: the picture runs off the right edge of the slide, 24 of air above it (flush to the top the interface
   screenshots read cramped) */
@media (max-width: 47.9375rem) {
  .stage-steps__ppic { padding-top: var(--space); }
  .stage-steps__ppic img { display: block; width: 96.4%; height: auto; margin-left: 3.6%; border-radius: var(--radius-md) 0 0 0; }
  /* pictures framed inside the image (3 and 5): half the offset, so the frame sits near the middle */
  .stage-steps__ppic--centered img { margin-left: 1.8%; }
}

/* No transitions for a jump (first paint, mode switch) and with reduced motion */
.is-still .stage-steps__slide, .is-still .stage-steps__highlight { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .stage-steps__slide, .stage-steps__highlight,
  .stage-steps__step.is-active :is(.stage-steps__desc, .stage-steps__note) { transition: none; }
}

/* The course lesson link: a caption of the card — 16 under it, Paragraph SM. It sits inside
   the sticky frame, so on desktop it stays on screen while the steps scroll; the card gives it the room. */
.stage-steps__more { flex: none; margin-top: var(--space-sm); text-align: center; }
.stage-steps__more .link-arrow { --tap-pad: max(0rem, (2.75rem - 1lh) / 2); display: inline-block; padding-block: var(--tap-pad); margin-block: calc(var(--space-xxs) - var(--tap-pad)); } /* a 44 touch area; the margin keeps the link where the 4 padding put it */
/* play mark before the lesson link: a triangle drawn in CSS from the text colour, sized from the text */
.stage-steps__play {
  display: inline-block;
  width: 0.7em;
  height: 0.8em;
  margin-right: 0.4em;
  vertical-align: -0.05em;
  background: currentColor;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}
