@layer components {
  .steps {
    --card-color: var(--color-ink-medium);
  }

  .step--answer {
    --mark: var(--color-success-button);
  }

  .step--added {
    animation: tint-fade var(--duration-slow) ease-out;
  }

  .step__content.step__content--heading {
    font-weight: 600;
  }

  /* Fizzy's 1em column is narrower than the 1.25em control. The control and the actions sit on the first line, which may wrap. */
  .step:has(> :is(.checkbox, .button_to)) {
    grid-template-columns: max-content auto auto;
  }

  .step > :is(.checkbox, .button_to) {
    margin-block-start: calc((1lh - 1.25em) / 2);
  }

  .step > .step__actions {
    align-self: start;
    block-size: 1lh;
  }

  .step__actions {
    --btn-size: 2em;

    align-items: center;
    display: flex;
    flex-wrap: nowrap;
    gap: var(--block-space-half);
    justify-self: end;

    .btn {
      --btn-background: transparent;
      --btn-border-color: transparent;

      @media (any-hover: hover) {
        &:hover {
          --btn-background: var(--tint-ink-10);
        }
      }
    }
  }

  /* A row's actions show on hover. On touch they are left to its editor, which a tap on the row opens and which
     carries the same actions. */
  :is(.step__card, .row) > .step__actions {
    display: none;
    margin-inline-start: auto;

    @media (any-hover: hover) {
      display: flex;
      opacity: 0;
      transition: opacity var(--duration-medium) ease-out;
    }
  }

  @media (any-hover: hover) {
    :is(.step__card, .row):is(:hover, :focus-within) > .step__actions {
      opacity: 1;
    }
  }

  .step__card {
    align-items: center;
    border: 1px solid transparent;
    border-radius: var(--radius-lg);
    display: grid;
    gap: var(--inline-space);
    grid-template-columns: 1fr auto;
    min-inline-size: 0;
    padding: calc(var(--block-space-half) / 2) var(--block-space);
    position: relative;

    @media (any-hover: hover) {
      &:has(.step__link:hover) {
        background-color: var(--color-ink-lightest);
      }
    }

    > :first-child {
      min-inline-size: 0;
    }

    > .step__actions {
      position: relative;
      z-index: 1;
    }
  }

  .step__body {
    align-items: baseline;
    column-gap: var(--inline-space);
    display: flex;
    flex-wrap: wrap;
  }

  .step__title {
    font-weight: bold;
    overflow-wrap: anywhere;
  }

  .step__meta {
    color: var(--color-ink-medium);
    font-size: var(--text-small);
  }

  .step__link {
    color: inherit;
    text-decoration: none;

    &::after {
      content: "";
      inset: 0;
      position: absolute;
    }
  }

  .step__editor {
    align-items: start;
    background-color: var(--color-canvas);
    border: 1px solid var(--tint-ink-15);
    border-radius: var(--radius-lg);
    display: grid;
    gap: var(--block-space-half) var(--inline-space);
    grid-template-columns: 1fr auto;
    padding: var(--block-space-half) var(--block-space);

    > *,
    > form > * {
      grid-column: 1 / -1;
      min-inline-size: 0;
    }

    > form > .step__editor-head {
      grid-column: 1;
      grid-row: 1;
    }

    > .step__actions {
      grid-column: 2;
      grid-row: 1;
    }

    &:has(> form[aria-busy]) {
      cursor: progress;

      .step__title-field {
        color: var(--color-ink-medium);
      }
    }
  }

  /* The box bleeds past the column so its text keeps the section heading's left edge. */
  .step__card,
  .step__editor {
    @media screen {
      margin-inline: calc(-1 * (var(--inline-space) + 1px));
      padding-inline: var(--inline-space);
    }

    @media print {
      background: none;
      border: none;
    }
  }

  .step__title-field {
    background: none;
    border: 0;
    color: inherit;
    font-size: var(--text-normal);
    font-weight: bold;
    inline-size: 100%;
    margin: 0;
    outline: none;
    padding: 0;
    resize: none;
  }

  .step__title-field--heading {
    font-size: var(--text-medium);
  }

  .step__editor-head {
    display: grid;
    gap: var(--block-space-half);
    justify-items: start;

    > .autoresize__wrapper {
      justify-self: stretch;
    }
  }

  .step__editor-foot {
    align-items: center;
    border-block-start: var(--border);
    display: flex;
    gap: var(--inline-space);
    justify-content: space-between;
    padding-block-start: var(--block-space);
  }

  .step__editor-settings,
  .step__editor-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: var(--inline-space);
  }

  .step__editor-actions {
    flex: none;
    margin-inline-start: auto;
  }

  .steps__add {
    --btn-font-weight: normal;

    margin-block-start: var(--block-space-half);
  }
}
