/* Behind the scenes: production steps and the set-to-still board */

.chapter--workflow {
  --wf-forest: #24312a;
  --wf-forest-raised: #2d3c33;
  --wf-cream: #f5f0e6;
  --wf-cream-muted: #c9c2b5;
  --wf-line: rgba(245, 240, 230, 0.18);
  --wf-line-strong: rgba(245, 240, 230, 0.36);
  /* Edge color of the walkthrough poster, so letterboxing disappears */
  --wf-poster-ground: #49544e;
  /* Warm sand mats mount the film and stills like prints on a production board.
     Browsers decode the film's cream differently, so the mount is a distinct tone. */
  --wf-mount: var(--paper-warm);
  --wf-mat: clamp(5px, 0.9vw, 11px);
  --wf-mat-still: clamp(4px, 0.5vw, 6px);
  --wf-rail: 2px;
}

/* Four production steps */

.wf-steps {
  --wf-step-gap: clamp(1rem, 2.4vw, 1.75rem);
  /* How far a number rule runs on into the next step (set where steps share a row) */
  --wf-run: 0px;
  --wf-row-gap: clamp(1.4rem, 3vw, 2rem);
  --wf-rule-close: var(--c-aimi);
  list-style: none;
  counter-reset: wf-step;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--wf-row-gap) var(--wf-step-gap);
  margin: clamp(1.5rem, 3.2vw, 2.6rem) 0 clamp(2.4rem, 5vw, 4rem);
  padding: 0;
}

.wf-step {
  counter-increment: wf-step;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "glyph"
    "num"
    "title"
    "text";
  align-content: start;
  position: relative;
  min-width: 0;
}

/* Number on a process rule; in rows the rule runs on into the next step */
.wf-step::before {
  content: counter(wf-step, decimal-leading-zero);
  grid-area: num;
  margin-block: 0.85rem 0.35rem;
  font: 670 1.05rem/1 var(--font-display);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--c-aimi);
  background: linear-gradient(var(--rule-strong), var(--rule-strong)) right center / calc(100% - 2.2em) 1px no-repeat;
}

/* Steps 02 and 03 are shown up close in the board below: their rules turn cherry
   and join into one bracket, then a plain rule carries on to step 04. */
.wf-step:nth-child(2)::before {
  background: linear-gradient(var(--wf-rule-close), var(--wf-rule-close)) right center / calc(100% - 2.2em) 2px no-repeat;
}

.wf-step:nth-child(3)::before {
  background:
    linear-gradient(var(--wf-rule-close), var(--wf-rule-close)) 2.2em center / calc(100% - 2.2em - var(--wf-run)) 2px no-repeat,
    linear-gradient(var(--rule-strong), var(--rule-strong)) right center / calc(100% - 2.2em) 1px no-repeat;
}

.wf-step h3 {
  grid-area: title;
  font-size: clamp(1.14rem, 1.6vw, 1.34rem);
  line-height: 1.2;
  text-wrap: balance;
  overflow-wrap: break-word;
}

.wf-step p {
  grid-area: text;
  margin: 0.5rem 0 0;
  max-width: 38ch;
  font-size: 0.94rem;
  line-height: 1.55;
  color: var(--ink-muted);
  overflow-wrap: break-word;
}

.wf-glyph {
  grid-area: glyph;
  display: block;
  width: 100%;
  max-width: 22rem;
  height: auto;
  aspect-ratio: 8 / 5;
  border-radius: var(--r-control);
  background: var(--wf-forest);
}

/* Glyph drawing, on the forest tile */
.wf-g-line { fill: rgba(245, 240, 230, 0.78); }
.wf-g-wave rect { fill: rgba(245, 240, 230, 0.62); }
.wf-g-gap { fill: rgba(245, 240, 230, 0.3); }
.wf-g-aimi { fill: var(--c-aimi-dark); }
.wf-g-basil { fill: var(--c-basil-dark); }
.wf-g-charlie { fill: var(--c-charlie-dark); }
.wf-g-tie { fill: var(--wf-forest); }
.wf-g-wall,
.wf-g-bracket {
  fill: none;
  stroke: rgba(245, 240, 230, 0.78);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.wf-g-furniture { fill: rgba(245, 240, 230, 0.14); }
.wf-g-cone {
  fill: rgba(245, 240, 230, 0.12);
  stroke: rgba(245, 240, 230, 0.5);
  stroke-width: 1.25;
  stroke-linejoin: round;
}
.wf-g-cam { fill: var(--wf-cream); }
.wf-g-thirds {
  fill: none;
  stroke: rgba(245, 240, 230, 0.2);
  stroke-width: 1;
  stroke-dasharray: 2 3;
}
.wf-g-floor {
  fill: none;
  stroke: rgba(245, 240, 230, 0.4);
  stroke-width: 1.5;
}
.wf-g-clip { fill: rgba(245, 240, 230, 0.32); }
.wf-g-clip--alt { fill: rgba(245, 240, 230, 0.58); }
.wf-g-caption { fill: var(--wf-cream); }
.wf-g-audio {
  fill: none;
  stroke: var(--c-basil-dark);
  stroke-width: 1.75;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.wf-g-playhead {
  fill: none;
  stroke: var(--c-aimi-dark);
  stroke-width: 2;
}
.wf-g-playhead-cap { fill: var(--c-aimi-dark); }
.wf-g-card {
  fill: rgba(245, 240, 230, 0.1);
  stroke: rgba(245, 240, 230, 0.5);
  stroke-width: 1.25;
}
.wf-g-perspective,
.wf-g-feed {
  fill: none;
  stroke: rgba(245, 240, 230, 0.6);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.wf-g-feed { stroke: var(--c-aimi-dark); stroke-width: 2; }

/* Stacked, steps 02 and 03 keep their pairing: one cherry bracket runs down
   their edge, through the gap between them. */
@container (max-width: 19.99rem) {
  .wf-step:nth-child(2),
  .wf-step:nth-child(3) {
    padding-inline-start: 0.85rem;
    border-inline-start: 2px solid var(--wf-rule-close);
  }

  .wf-step:nth-child(2)::after {
    content: "";
    position: absolute;
    inset-block-start: 100%;
    inset-inline-start: -2px;
    width: 2px;
    height: var(--wf-row-gap);
    background: var(--wf-rule-close);
  }
}

/* Side-by-side tile and text in a mid-width single column */
@container (min-width: 20rem) and (max-width: 33.99rem) {
  .wf-step {
    --wf-tile: 7.5rem;
    grid-template-columns: minmax(0, var(--wf-tile)) minmax(0, 1fr);
    grid-template-areas:
      "glyph num"
      "glyph title"
      "glyph text";
    column-gap: 1.1rem;
  }

  .wf-step::before { margin-block-start: 0.1rem; }

  /* A cherry link from tile 02 down to tile 03 keeps the pair together */
  .wf-step:nth-child(2)::after {
    content: "";
    position: absolute;
    inset-block: calc(var(--wf-tile) * 5 / 8 + 0.45rem) calc(0.45rem - var(--wf-row-gap));
    inset-inline-start: calc(var(--wf-tile) / 2 - 1px);
    width: 2px;
    border-radius: 1px;
    background: var(--wf-rule-close);
  }
}

@container (min-width: 34rem) {
  .wf-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .wf-step:nth-child(odd) { --wf-run: calc(var(--wf-step-gap) - 0.6rem); }
  .wf-step::before { margin-inline-end: calc(-1 * var(--wf-run)); }
}

/* Two by two: low tiles keep the overview lighter than the board below */
@container (min-width: 34rem) and (max-width: 53.99rem) {
  .wf-glyph { max-width: none; aspect-ratio: 5 / 2; }
}

@container (min-width: 54rem) {
  .wf-steps { grid-template-columns: repeat(4, minmax(0, 1fr)); }

  .wf-step:not(:last-child) { --wf-run: calc(var(--wf-step-gap) - 0.6rem); }
}

/* Set to still board */

.wf-board {
  container: wf-board / inline-size;
  padding: clamp(14px, 3.4vw, 2.5rem);
  border-radius: var(--r-photo);
  background: var(--wf-forest);
  color: var(--wf-cream);
}

.wf-board ::selection {
  background: var(--lavender-on-dark);
  color: var(--ink);
}

.wf-board :focus-visible { outline-color: var(--lavender-on-dark); }

/* Ties the board to the cherry bracket over steps 02 and 03 */
.wf-board-kicker {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0 0 0.45rem;
  font: 650 0.92rem/1.3 var(--font-display);
  font-variant-numeric: tabular-nums;
  color: var(--c-aimi-dark);
  overflow-wrap: break-word;
}

.wf-board-kicker::before {
  content: "";
  flex: 0 0 1.6rem;
  height: 2px;
  background: currentColor;
}

/* A sub-section of the chapter: clearly below the chapter heading */
.wf-board-title {
  margin: 0 0 clamp(1rem, 2.6vw, 1.75rem);
  font-size: clamp(1.5rem, 2.7vw, 2.1rem);
  line-height: 1.05;
  letter-spacing: -0.035em;
  color: var(--wf-cream);
  text-wrap: balance;
  overflow-wrap: break-word;
}

.wf-board-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "film"
    "notes"
    "compare";
  gap: clamp(1.25rem, 3vw, 2.25rem);
}

.wf-film {
  grid-area: film;
  margin: 0;
  min-width: 0;
}

/* The walkthrough is cream slides, so it sits on a sand mount: at rest the poster
   reads as a mounted print, and in play the slides read as paper on that mount. */
.wf-board .demo-video {
  display: block;
  box-sizing: content-box;
  width: calc(100% - 2 * var(--wf-mat));
  height: auto;
  aspect-ratio: 8 / 5;
  object-fit: contain;
  border: var(--wf-mat) solid var(--wf-mount);
  border-radius: var(--r-control);
  background: var(--wf-poster-ground);
  box-shadow: 0 18px 36px -22px rgba(0, 0, 0, 0.7);
}

.wf-film figcaption {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.15rem 0.75rem;
  padding-block-start: 0.65rem;
  font-size: 0.86rem;
  line-height: 1.4;
  color: var(--wf-cream-muted);
}

.wf-film figcaption span {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Shot notes: a timeline that follows the video */
.wf-notes {
  grid-area: notes;
  container: wf-notes / inline-size;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.wf-notes h4 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  line-height: 1.25;
  color: var(--wf-cream);
}

/* Each note owns its stretch of the rail, so the played part can turn cherry */
.wf-board .demo-steps {
  list-style: none;
  counter-reset: none;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
}

.wf-board .demo-steps li {
  counter-increment: none;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 0.15rem;
  margin: 0;
  padding: 0.6rem 0.5rem 0.7rem 1rem;
  border: 0;
  border-inline-start: var(--wf-rail) solid var(--wf-line-strong);
  border-radius: 0 0.6rem 0.6rem 0;
  background: transparent;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.4;
  transition: background-color 200ms var(--ease-out), border-color 200ms var(--ease-out);
}

.wf-board .demo-steps li::before {
  content: "";
  position: absolute;
  inset-block-start: 0.95rem;
  inset-inline-start: calc(-0.5 * var(--wf-rail) - 0.35rem);
  box-sizing: border-box;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: var(--wf-forest);
  border: 1.5px solid var(--wf-cream-muted);
  font: inherit;
  transition: background-color 200ms var(--ease-out), border-color 200ms var(--ease-out), box-shadow 200ms var(--ease-out);
}

.wf-note-time {
  font: 600 0.8rem/1.3 var(--font-display);
  font-variant-numeric: tabular-nums;
  color: var(--wf-cream-muted);
}

.wf-note-title {
  font-family: var(--font-display);
  font-weight: 650;
  font-size: 1rem;
  color: var(--wf-cream);
  overflow-wrap: break-word;
}

.wf-board .demo-steps small {
  grid-column: auto;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--wf-cream-muted);
  overflow-wrap: break-word;
}

/* With room, a shot list: the timecode in its own column beside the note */
@container wf-notes (min-width: 16rem) {
  .wf-board .demo-steps li {
    grid-template-columns: 2.4rem minmax(0, 1fr);
    grid-template-areas:
      "time title"
      ". text";
    align-items: baseline;
    column-gap: 0.55rem;
    padding-block: 0.45rem 0.55rem;
  }

  .wf-notes h4 { margin-block-end: 0.6rem; }

  .wf-note-time { grid-area: time; }
  .wf-note-title { grid-area: title; }
  .wf-board .demo-steps small { grid-area: text; }

  .wf-board .demo-steps li::before { inset-block-start: 0.85rem; }
}

.wf-board .demo-steps li:has(~ li[aria-current]),
.wf-board .demo-steps li[aria-current] {
  border-color: var(--c-aimi-dark);
}

.wf-board .demo-steps li:has(~ li[aria-current])::before {
  background: var(--c-aimi-dark);
  border-color: var(--c-aimi-dark);
}

.wf-board .demo-steps li[aria-current] {
  background: var(--wf-forest-raised);
}

.wf-board .demo-steps li[aria-current]::before {
  background: var(--c-aimi-dark);
  border-color: var(--c-aimi-dark);
  box-shadow: 0 0 0 0.25rem rgba(230, 124, 135, 0.28);
}

.wf-board .demo-steps li[aria-current] .wf-note-time {
  color: var(--c-aimi-dark);
}

@media (prefers-reduced-motion: reduce) {
  .wf-board .demo-steps li,
  .wf-board .demo-steps li::before { transition: none; }
}

/* 3D reference beside the generated still */
.wf-compare {
  --wf-pair-gap: 0.6rem;
  --wf-arrow: 1.5rem;
  grid-area: compare;
  display: grid;
  gap: 1rem;
  margin: 0;
  padding-block-start: clamp(1.25rem, 3vw, 2.25rem);
  border-block-start: 1px solid var(--wf-line);
  min-width: 0;
}

.wf-compare-caption {
  margin: 0;
  max-width: 30ch;
  font: 600 clamp(1.12rem, 2.2vw, 1.45rem)/1.3 var(--font-display);
  letter-spacing: -0.015em;
  color: var(--wf-cream);
  text-wrap: pretty;
  overflow-wrap: break-word;
}

/* Key to the dashed eye line and paw line drawn across the stills */
.wf-compare-caption::before {
  content: "";
  display: block;
  width: 2.6rem;
  margin-block-end: 0.75rem;
  border-block-start: 2px dashed var(--c-aimi-dark);
}

.wf-compare-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--wf-arrow) minmax(0, 1fr);
  /* Frames share one row and labels the next, so the frames stay on the shared
     guides and both labels start on one line whatever their length */
  grid-template-rows: auto auto;
  align-items: start;
  column-gap: var(--wf-pair-gap);
  min-width: 0;
}

.wf-still {
  display: grid;
  grid-row: span 2;
  grid-template-rows: subgrid;
  row-gap: 0;
  margin: 0;
  min-width: 0;
}

/* Shared eye line and paw line: Basil sits at the same height in both frames */
.wf-still-frame {
  position: relative;
  display: block;
}

.wf-still-frame::before,
.wf-still-frame::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  border-block-start: 2px dashed var(--c-aimi-dark);
  opacity: 0.9;
  pointer-events: none;
}

.wf-still-frame::before { inset-block-start: 42%; }
.wf-still-frame::after { inset-block-start: 65.5%; }

.wf-still:first-child .wf-still-frame::before,
.wf-still:first-child .wf-still-frame::after {
  inset-inline-end: calc(-1 * var(--wf-arrow) - 2 * var(--wf-pair-gap));
}

.wf-still img {
  display: block;
  box-sizing: content-box;
  width: calc(100% - 2 * var(--wf-mat-still));
  height: auto;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  border: var(--wf-mat-still) solid var(--wf-mount);
  border-radius: var(--r-control);
  background: #3b4a41;
  box-shadow: 0 16px 30px -20px rgba(0, 0, 0, 0.7);
}

.wf-still figcaption {
  padding-block-start: 0.6rem;
  font-size: 0.86rem;
  font-weight: 650;
  line-height: 1.3;
  color: var(--wf-cream);
  overflow-wrap: break-word;
}

/* The overview step each frame comes from, in that step's numeral style */
.wf-still-step {
  margin-inline-end: 0.3em;
  font-family: var(--font-display);
  font-weight: 670;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--c-aimi-dark);
}

.wf-compare-arrow {
  grid-row: 1;
  grid-column: 2;
  align-self: center;
  width: var(--wf-arrow);
  height: var(--wf-arrow);
  fill: none;
  stroke: var(--c-basil-dark);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Very narrow: stack the two stills */
@container wf-board (max-width: 15rem) {
  .wf-compare-pair {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
  }

  .wf-still { display: block; width: 100%; grid-row: auto; }
  .wf-compare-arrow { grid-row: auto; grid-column: auto; transform: rotate(90deg); }

  .wf-still:first-child .wf-still-frame::before,
  .wf-still:first-child .wf-still-frame::after { inset-inline-end: 0; }
}

@container wf-board (min-width: 34rem) and (max-width: 39.99rem) {
  .wf-compare-pair {
    max-width: 34rem;
  }
}

/* Tablet: the notes run left to right under the film, like its scrub bar */
@container wf-board (min-width: 40rem) and (max-width: 51.99rem) {
  .wf-board .demo-steps {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .wf-board .demo-steps li {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "time" "title" "text";
    align-items: start;
    padding: 1rem 0.75rem 0.75rem 0;
    border-inline-start: 0;
    border-block-start: var(--wf-rail) solid var(--wf-line-strong);
    border-radius: 0 0 0.6rem 0.6rem;
  }

  .wf-board .demo-steps li[aria-current] { padding-inline-start: 0.5rem; }

  .wf-board .demo-steps li::before {
    inset-block-start: calc(-0.5 * var(--wf-rail) - 0.35rem);
    inset-inline-start: 0;
  }

  .wf-board .demo-steps li[aria-current]::before { inset-inline-start: 0.5rem; }
}

/* From tablet up the board reads as a Z on two mirrored columns: the film leads
   and the notes follow; below, the caption takes the notes' width and the stills
   take the film's. The caption's dashed key sits level with the eye line it names,
   while the guide lines stay inside the pair, where they compare the two frames. */
@container wf-board (min-width: 40rem) {
  .wf-board-grid {
    --wf-board-gap: clamp(1.5rem, 3vw, 2.5rem);
    /* Width of the media column, from the board's content width */
    --wf-media-col: calc((100cqw - var(--wf-board-gap)) * 1.75 / 2.75);
    --wf-board-cols: minmax(0, 1.75fr) minmax(0, 1fr);
  }

  .wf-compare {
    /* One still frame: half the pair less the arrow and its gaps, as a 9:16 mat */
    --wf-frame-w: calc((var(--wf-media-col) - var(--wf-arrow) - 2 * var(--wf-pair-gap)) / 2);
    --wf-frame-h: calc((var(--wf-frame-w) - 2 * var(--wf-mat-still)) * 16 / 9 + 2 * var(--wf-mat-still));
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.75fr);
    grid-template-areas: "caption pair";
    align-items: start;
    column-gap: var(--wf-board-gap);
  }

  .wf-compare-pair {
    grid-area: pair;
    width: var(--wf-media-col);
    max-width: none;
  }

  .wf-compare-caption {
    grid-area: caption;
    max-width: 19ch;
    /* The key rule lands on the eye line, 42% down the frames */
    margin-block-start: calc(var(--wf-frame-h) * 0.42);
  }
}

/* Wide: film and notes side by side, the caption and stills mirrored below */
@container wf-board (min-width: 52rem) {
  .wf-board-grid {
    grid-template-columns: var(--wf-board-cols);
    grid-template-areas:
      "film notes"
      "compare compare";
    column-gap: var(--wf-board-gap);
  }

  .wf-compare-caption {
    max-width: 18ch;
    font-size: clamp(1.3rem, 2.6cqw, 1.75rem);
  }

  /* Notes keep a steady rhythm rather than spreading to the film's height */
  .wf-board .demo-steps li { padding-block: 0.6rem 0.75rem; }
  .wf-board .demo-steps li::before { inset-block-start: 1rem; }
  .wf-note-title { font-size: 1.05rem; }
}
