/* The Windee worked example (layouts/partials/windee-walkthrough.html).

   The resting layout is the complete one: each step followed by its screen.
   That is what script blocked, reduced motion, phones and short screens get.
   Only a wide, tall screen with script pins the track: main.js writes --seq
   and --seq-p onto [data-sequence], and every rule reading them is in the
   last media block, so nothing outside it can hide a step. The panels'
   contents are in windee-walkthrough-panels.css, which loads after this. */

.wr-walkthrough {
  /* Five screens of scroll for the five steps the contract fixes. */
  --walkthrough-screens: 5;
  --walkthrough-columns: minmax(0, 5fr) minmax(0, 6fr);
  --walkthrough-gap: var(--space-7);
  --walkthrough-bar: 2.75rem;
  --walkthrough-icon: 1.125rem;
  --walkthrough-person: 2rem;
  --walkthrough-file: 3rem;
  --walkthrough-file-tall: 3.75rem;

  padding-block: var(--windee-space-section);
}

/* Five day columns and an avatar inside a 320px phone. */
@media (max-width: 29.99rem) {
  .wr-walkthrough { --walkthrough-person: 1.75rem; }
}

/* ---------- Steps, stacked ---------- */

.wr-walkthrough__track { margin-block-start: var(--space-7); }

.wr-walkthrough__steps {
  display: grid;
  gap: var(--space-8);
}

.wr-walkthrough__step {
  display: grid;
  gap: var(--space-5);
}

@media (min-width: 48rem) {
  .wr-walkthrough__step {
    grid-template-columns: var(--walkthrough-columns);
    column-gap: var(--walkthrough-gap);
    align-items: start;
  }
}

.wr-walkthrough__text {
  padding-inline-start: var(--space-4);
  border-inline-start: 2px solid var(--windee-fill);
}

.wr-walkthrough__time {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
  color: var(--color-accent-text);
}

.wr-walkthrough__title {
  margin-block-start: var(--space-1);
  font-size: var(--windee-text-step);
  font-weight: var(--weight-semibold);
  line-height: var(--windee-leading-step);
}

.wr-walkthrough__body {
  max-inline-size: 40ch;
  margin-block-start: var(--space-2);
  color: var(--color-ink-soft);
}

/* ---------- The screen beside each step ---------- */

.wr-walkthrough__panel,
.wr-walkthrough__frame {
  max-inline-size: var(--windee-width-window);
  border: 1px solid var(--color-border);
  border-radius: var(--windee-radius-window);
  background: var(--color-surface);
  box-shadow: var(--windee-shadow-window);
}

.wr-walkthrough__panel {
  min-inline-size: 0;
  padding: clamp(var(--space-4), 3vw, var(--space-5));
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}

/* Window chrome and progress rail exist only for the pinned sequence. */
.wr-walkthrough__frame,
.wr-walkthrough__rail { display: none; }

/* ---------- Pinned sequence ----------
   64rem wide so text and window sit side by side with room; 40rem tall so the
   tallest panel fits one screen under the sticky header. A shorter screen
   keeps the stacked layout rather than clipping a step. */

@media (min-width: 64rem) and (min-height: 40rem) and (prefers-reduced-motion: no-preference) {
  .js .wr-walkthrough__track {
    block-size: calc(var(--walkthrough-screens) * 100svh);
    margin-block-start: 0;
  }

  .js .wr-walkthrough__stage {
    position: sticky;
    inset-block-start: 0;
    display: grid;
    align-content: center;
    block-size: 100svh;
  }

  /* Every step occupies the same cell, so the row is as tall as the tallest
     and the frame behind the panels never changes size between steps. */
  .js .wr-walkthrough__grid,
  .js .wr-walkthrough__steps {
    display: grid;
    grid-template-columns: var(--walkthrough-columns);
    gap: var(--space-6) var(--walkthrough-gap);
  }

  .js .wr-walkthrough__steps,
  .js .wr-walkthrough__step { grid-area: 1 / 1 / 2 / 3; }

  .js .wr-walkthrough__frame {
    display: block;
    grid-area: 1 / 2;
  }

  .js .wr-walkthrough__bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    block-size: var(--walkthrough-bar);
    padding-inline: var(--space-4);
    border-block-end: 1px solid var(--windee-rule-soft);
    color: var(--color-ink-soft);
    font-size: var(--text-sm);
  }

  .js .wr-walkthrough__mark {
    inline-size: var(--walkthrough-icon);
    block-size: var(--walkthrough-icon);
    fill: none;
    stroke: var(--windee-fill);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .js .wr-walkthrough__step {
    align-items: center;
    /* 0 for the current step, 1 for every other: --seq is an integer. */
    --away: min(1, max(var(--seq, 0) - var(--i), var(--i) - var(--seq, 0)));
  }

  /* The index --away measures against. Set here, not as a style attribute,
     because the CSP drops inline styles (see home.css). */
  .js .wr-walkthrough__step:nth-child(1) { --i: 0; }
  .js .wr-walkthrough__step:nth-child(2) { --i: 1; }
  .js .wr-walkthrough__step:nth-child(3) { --i: 2; }
  .js .wr-walkthrough__step:nth-child(4) { --i: 3; }
  .js .wr-walkthrough__step:nth-child(5) { --i: 4; }

  .js .wr-walkthrough__text,
  .js .wr-walkthrough__panel {
    opacity: calc(1 - var(--away));
    transform: translate3d(0, calc(var(--away) * var(--space-4)), 0);
    transition:
      opacity var(--motion-base) var(--ease),
      transform var(--motion-base) var(--ease);
  }

  .js .wr-walkthrough__title { font-size: var(--text-xl); }
  .js .wr-walkthrough__body { font-size: var(--text-md); }

  /* The frame draws the surface; the panel only sets its contents inside it. */
  .js .wr-walkthrough__panel {
    align-self: start;
    padding: calc(var(--walkthrough-bar) + var(--space-5)) var(--space-5) var(--space-5);
    border: 0;
    background: none;
    box-shadow: none;
  }

  /* The answer is in the DOM whole; it is only uncovered, top to bottom. */
  .js .wr-walkthrough__answer {
    clip-path: inset(0 0 calc(var(--away) * 100%) 0);
    transition: clip-path calc(var(--motion-slow) * 2) var(--ease) var(--motion-base);
  }

  .js .wr-walkthrough__sources,
  .js .wr-walkthrough__job--new {
    opacity: calc(1 - var(--away));
    transition: opacity var(--motion-base) var(--ease) var(--motion-slow);
  }

  .js .wr-walkthrough__line {
    stroke-dasharray: 1;
    stroke-dashoffset: var(--away);
    transition: stroke-dashoffset calc(var(--motion-slow) * 2) var(--ease);
  }

  .js .wr-walkthrough__rail {
    display: block;
    grid-column: 1 / -1;
    block-size: 2px;
    background: var(--windee-rule-soft);
  }

  .js .wr-walkthrough__rail::after {
    content: "";
    display: block;
    block-size: 100%;
    background: var(--windee-fill);
    transform: scaleX(var(--seq-p, 0));
    transform-origin: left;
  }
}
