/* Step panels ------------------------------------------------------------- */

.wl-step-panels__head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--wl-space-md) var(--wl-space-lg);
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: clamp(1.5rem, 3.5vw, 2.5rem);
}

.wl-step-panels__head .wl-stack {
  flex: 1 1 24rem;
  min-width: 0;
  max-width: var(--wl-measure);
}

.wl-step-panels__heading {
  font-family: var(--wl-font-display);
  font-size: var(--wl-text-2xl);
  line-height: var(--wl-leading-tight);
  letter-spacing: var(--wl-tracking-tight);
}

/*
 * The arrows exist to move along a row. On a phone the panels are a stack of
 * full-width bands, each one already a tap target, so a pair of left-right
 * arrows there is furniture. `:not([hidden])` because the script is what
 * reveals them, and the attribute has to keep winning until it does.
 */
.wl-step-panels__arrows { display: none; }

@media (min-width: 52em) {
  .wl-step-panels__arrows:not([hidden]) {
    display: flex;
    gap: var(--wl-space-xs);
  }
}

.wl-step-panels__arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  padding: 0;
  border: 1px solid var(--wl-rule);
  border-radius: var(--wl-radius);
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background var(--wl-duration) var(--wl-ease),
              border-color var(--wl-duration) var(--wl-ease),
              color var(--wl-duration) var(--wl-ease);
}

.wl-step-panels__arrow.is-next {
  border-color: var(--wl-ink);
  background: var(--wl-ink);
  color: var(--wl-ground);
}

.wl-step-panels__arrow:hover {
  border-color: var(--wl-accent);
  background: var(--wl-accent);
  color: var(--wl-on-accent);
}

.wl-step-panels__arrow:focus-visible {
  outline: 2px solid var(--wl-accent);
  outline-offset: 3px;
}

/* The row ---------------------------------------------------------------- */

/*
 * A stack on a phone, where a row of six narrow columns is unreadable, and a
 * row from the width at which a closed panel is still wide enough to carry a
 * step name on two lines.
 */
.wl-step-panels__row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.wl-step-panels__panel {
  position: relative;
  min-width: 0;
  background: var(--wl-sand);
}

.wl-step-panels__panel[open] {
  background: var(--wl-ink);
  color: var(--wl-on-ink);
}

/* The summary ------------------------------------------------------------ */

.wl-step-panels__summary {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: var(--wl-space-2xs);
  padding: var(--wl-space-md);
  cursor: pointer;
  list-style: none;
}

/* Safari still draws its own triangle without this. */
.wl-step-panels__summary::-webkit-details-marker { display: none; }

.wl-step-panels__summary:focus-visible {
  outline: 2px solid var(--wl-accent);
  outline-offset: -2px;
}

/*
 * The duration is sized by how long the stage actually takes — the weight
 * comes from the days field, in the template — so a row of shut panels still
 * says which part is the long one.
 */
.wl-step-panels__when {
  display: block;
  font-family: var(--wl-font-display);
  font-size: calc(var(--wl-text-xl) * var(--wl-step-weight, 1));
  line-height: 1;
  letter-spacing: var(--wl-tracking-tight);
}

.wl-step-panels__title {
  font-family: var(--wl-font-text);
  font-size: var(--wl-text-base);
  font-weight: 600;
  line-height: var(--wl-leading-snug);
}

/* The open panel --------------------------------------------------------- */

.wl-step-panels__body {
  display: grid;
  gap: var(--wl-space-sm);
  padding: 0 var(--wl-space-md) var(--wl-space-md);
}

.wl-step-panels__media {
  position: relative;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.wl-step-panels__img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
}

/*
 * A stage whose photograph does not exist yet names the shot that belongs
 * there, rather than showing a grey rectangle nobody can act on.
 */
.wl-step-panels__shot {
  display: flex;
  align-items: center;
  justify-content: center;
  /* Only as tall as the line needs: an empty box the size of the missing
     photograph is a wall, and it is not standing in for one yet. */
  min-height: 9rem;
  padding: var(--wl-space-md);
  text-align: center;
  text-wrap: balance;
  font-size: var(--wl-text-xs);
  line-height: var(--wl-leading-snug);
  color: var(--wl-on-ink-soft);
}

.wl-step-panels__text {
  max-width: 46ch;
  font-size: var(--wl-text-sm);
  line-height: var(--wl-leading-body);
  color: var(--wl-on-ink-soft);
}

/* The footer ------------------------------------------------------------- */

.wl-step-panels__foot {
  display: flex;
  flex-wrap: wrap;
  gap: var(--wl-space-md) var(--wl-space-lg);
  align-items: center;
  justify-content: space-between;
  margin-top: clamp(1.5rem, 3vw, 2.25rem);
}

.wl-step-panels__note {
  flex: 1 1 22rem;
  max-width: 54ch;
  font-size: var(--wl-text-sm);
  color: var(--wl-ink-soft);
}

/* The row proper --------------------------------------------------------- */

@media (min-width: 52em) {
  .wl-step-panels__row {
    flex-direction: row;
    align-items: stretch;
  }

  /*
   * Closed panels take one share of the row and the open one takes three.
   * flex-grow is the only thing that moves, which is why the panels slide
   * open instead of jumping. The row has no fixed height: it is as tall as
   * the open panel, and the shut ones stretch to match.
   */
  .wl-step-panels__panel {
    flex: 1 1 0;
    transition: flex-grow 320ms var(--wl-ease);
  }

  .wl-step-panels__panel[open] { flex-grow: 3; }

  .wl-step-panels__summary {
    padding: var(--wl-space-lg) var(--wl-space-md) var(--wl-space-sm);
  }

  /*
   * A shut panel holds nothing but its summary, so the summary can be taken
   * out of flow and sat on the bottom edge: the row then reads as a line of
   * durations along the floor of it. An open panel keeps everything in
   * normal flow — duration, step, photograph, what happens — which is both
   * the reading order and the source order.
   *
   * The photograph is not behind the words. Overlaying it would need a scrim
   * for contrast, and would mean positioning the media against a box that
   * <details> does not reliably give us: browsers wrap a details' contents
   * in a box of their own, so the open content is not a child of the panel
   * in the way a stylesheet can count on.
   */
  .wl-step-panels__panel:not([open]) .wl-step-panels__summary {
    position: absolute;
    inset: auto 0 0 0;
  }

  .wl-step-panels__body {
    gap: var(--wl-space-md);
    padding: 0 var(--wl-space-md) var(--wl-space-lg);
  }

  .wl-step-panels__img,
  .wl-step-panels__shot {
    height: clamp(11rem, 19vw, 16rem);
    min-height: 0;
    aspect-ratio: auto;
  }
}

/* Tone ------------------------------------------------------------------- */

.wl-step-panels.is-ink .wl-step-panels__panel { background: rgba(255, 255, 255, 0.07); }
.wl-step-panels.is-ink .wl-step-panels__arrow { border-color: rgba(255, 255, 255, 0.28); }
.wl-step-panels.is-ink .wl-step-panels__arrow.is-next {
  border-color: var(--wl-on-ink);
  background: var(--wl-on-ink);
  color: var(--wl-ink);
}
.wl-step-panels.is-ink .wl-step-panels__note { color: var(--wl-on-ink-soft); }

@media (prefers-reduced-motion: reduce) {
  .wl-step-panels__panel { transition: none; }
}
