@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;
  }

  /* A section's name is its heading on a rule, at the heading's own weight. */
  .step__content.step__content--heading {
    margin: 0;
    font-weight: inherit;
  }

  .step__body:has(> .rows__heading) {
    display: block;
  }

  /* 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;
      --btn-hover-amount: 8%;
    }
  }

  /* 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, .step__row) > .step__actions {
    display: none;
    margin-inline-start: auto;

    @media (any-hover: hover) {
      display: flex;
    }
  }

  /* A question or an item reads at a row's size across the whole column. Its actions lie over the end of its first
     line, on a fade into the row's ground, so no word moves when they come into sight. */
  .step__card {
    --step-ground: var(--color-canvas);

    border: 1px solid transparent;
    border-radius: var(--radius-lg);
    display: grid;
    font-size: var(--text-row);
    min-inline-size: 0;
    padding: calc(var(--block-space-half) / 2) var(--block-space);
    position: relative;

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

        background-color: var(--step-ground);
      }
    }

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

    > .step__actions {
      --btn-size: var(--control-size);

      background: linear-gradient(to right, transparent, var(--step-ground) 2em);
      block-size: calc(var(--text-row) * 1.5 + var(--block-space-half));   /* the first line and the row's padding */
      border-start-end-radius: inherit;
      inset-block-start: 0;
      inset-inline-end: 0;
      padding-inline: 2.5em var(--inline-space);
      position: absolute;
      z-index: 1;
    }
  }

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

    > .row__pill {
      align-self: center;
    }
  }

  .step__title {
    overflow-wrap: anywhere;
  }

  .step__meta {
    color: var(--color-meta);
    font-size: var(--text-pill);
  }

  /* A question's place among those asked, in the column a box would take. */
  .step__number {
    color: var(--color-meta);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    min-inline-size: 1.25em;
    text-align: end;
  }

  .step__body > .row__pill {
    align-self: center;
  }

  /* On a phone the question wraps beside its number, and its pill goes under it. */
  @media (width < 640px) {
    .step__body:has(> .step__number) {
      display: grid;
      grid-template-columns: auto minmax(0, 1fr);
      row-gap: 0.25em;

      > .row__pill {
        grid-column: 2;
        justify-self: start;
      }
    }
  }

  /* A course's sections are titles over their questions, under the one rule of Preguntas. */
  .questions .rows__heading {
    font-size: var(--text-section);

    &::after {
      content: none;
    }
  }

  .questions .steps__add {
    margin-inline-start: calc(var(--text-row) * 1.25 + var(--inline-space));
  }

  .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);
      }
    }
  }

  /* A question opened where it stands: its number and words stay on their line over a rule, and its settings,
     options and buttons line up with its words below. */
  .step__editor--in-place {
    --step-indent: calc(var(--text-row) * 1.25 + var(--inline-space));

    background: none;
    border: 0;
    border-radius: 0;
    padding-block: calc(var(--block-space-half) / 2) var(--block-space-half);

    > form > .step__editor-head {
      align-items: start;
      border-block-end: var(--border);
      column-gap: var(--inline-space);
      display: flex;
      font-size: var(--text-row);
      grid-column: 1 / -1;
      line-height: 1.5;
      padding-block-end: var(--block-space-half);

      > .step__number {
        flex: none;
      }
    }

    .step__title-field:not(.step__title-field--heading) {
      font-size: inherit;
      font-weight: inherit;
    }

    > form > .step__fields,
    > .step__fields,
    > .step__editor-foot {
      margin-inline-start: var(--step-indent);
    }

    > form > .step__fields {
      border-block-start: 0;
      padding-block-start: 0;
    }

    /* A name level with the first option's words, in the row the option's mark sets. */
    .step__field-label {
      line-height: 2;
    }

    > .step__editor-foot {
      border-block-start: 0;
      justify-content: start;
      padding-block-start: var(--block-space-half);
    }

    .step__editor-settings > .separator {
      --border-color: var(--color-ink-lighter);

      block-size: 1.25em;
    }

    .step__editor-settings > .step__actions {
      gap: 0;
    }

    @media (width < 640px) {
      --step-indent: 0;
    }
  }

  /* A question's options: a round mark to tap for the right one, filled green once it is, and a × to take one out
     that shows on the row pointed at. */
  .step__field-options {
    display: grid;
    max-inline-size: 80ch;
    row-gap: calc(var(--block-space-half) / 2);

    > .steps {
      margin: 0;
      row-gap: calc(var(--block-space-half) / 2);
    }

    .step--answer {
      align-items: center;
      border-radius: var(--radius-md);
      grid-template-columns: max-content minmax(0, 1fr) auto;
      padding: 0.25em 0.4em;

      > :is(.checkbox, .button_to) {
        margin-block-start: 0;
      }

      .step__content {
        font-weight: 400;
        margin-block-end: 0;
      }

      > .step__actions {
        --btn-size: 1.75em;

        block-size: auto;
      }

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

    .checkbox-mark {
      border-color: var(--color-ink-medium);
    }

    .checkbox-mark--checked {
      background-color: var(--mark);
      border-color: var(--mark);
      color: var(--color-ink-inverted);
    }
  }

  .step__hint {
    color: var(--color-meta);
    font-size: var(--text-x-small);
    margin: 0;
    padding-inline: 0.4em;
  }

  /* 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);
  }

  /* An item's grip, in the column a box would take, over the link that opens it. Its add links line up with the
     items' names. */
  .step__grip {
    --icon-size: 1em;

    align-self: center;
    background: none;
    border: 0;
    border-radius: var(--radius-md);
    color: var(--color-meta);
    cursor: grab;
    display: grid;
    inline-size: 1.25em;
    padding: 0;
    place-items: center;
    position: relative;
    touch-action: none;
    z-index: 1;

    @media (any-hover: hover) {
      &:hover {
        color: var(--color-ink);
      }
    }
  }

  /* On a phone the item wraps beside its grip, and its pill goes under it. */
  @media (width < 640px) {
    .step__body:has(> .step__grip) {
      display: grid;
      grid-template-columns: auto minmax(0, 1fr);
      row-gap: 0.25em;

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

      > .row__pill {
        grid-column: 2;
        justify-self: start;
      }
    }
  }

  .checklist-items:has(.step__grip) .steps__add {
    margin-inline-start: calc(var(--text-row) * 1.25 + var(--inline-space));
  }

  .step--dragged {
    opacity: 0.4;
  }

  /* An item's settings under its name: each one's name on the left, in bold and set against what it sets. */
  .step__fields {
    align-items: center;
    border-block-start: var(--border);
    column-gap: var(--inline-space-double);
    display: grid;
    font-size: var(--text-control);
    grid-template-columns: 7em minmax(0, 1fr);
    padding-block-start: var(--block-space-half);
    row-gap: var(--block-space-half);

    /* The options go on under the settings, their name level with the first. */
    &:has(> :is(.steps, .step__field-options)) {
      border-block-start: 0;
      padding-block-start: 0;

      > .step__field-label {
        align-self: start;
      }
    }

    > .steps {
      margin: 0;
    }

    @media (width < 640px) {
      column-gap: var(--inline-space);
      grid-template-columns: 6.5em minmax(0, 1fr);
    }
  }

  .step__field-label {
    font-weight: 700;
    text-align: end;
  }

  .step__field-input {
    inline-size: auto;
    justify-self: start;
    max-inline-size: 100%;
  }

  /* A setting written in the line itself, on a dashed rule, so it reads as optional. */
  .step__field-input--quiet {
    --input-border-size: 0;
    --input-border-radius: 0;

    border-block-end: 1px dashed var(--color-ink-medium);
    inline-size: 100%;
    justify-self: stretch;
    padding-inline: 0.4em;
  }
}
