/*
 * Responsible for: how steps 2 and 3 of the cleanup and its result lay out a column of words and controls beside a mail
 * app. On a laptop the column stands at the left, the mail app fills the whole right side down to the row of buttons,
 * and a column too tall for the window scrolls inside itself. On a phone the words and controls come first, then the mail
 * app (tall enough for five emails, and as wide as the page), then the buttons.
 *
 * Must never: let the mail app or the buttons scroll out of sight on a laptop, let a count that grows by a digit move
 * anything, or let anything scroll sideways on a phone.
 */

@layer screens {
  /* A question with its choices under it. */
  .ia-step__ask {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--s-2);
    min-width: 0;
  }

  .ia-step__ask[hidden] {
    display: none;
  }

  .ia-step__ask > .ia-step__words:first-child {
    color: var(--ink);
    font-weight: 600;
  }

  .ia-step__counts {
    font-weight: 600;
  }

  .ia-step__note {
    color: var(--muted);
    font-size: var(--t-sm);
  }

  /* The three sentences that say what the slider does. */
  .ia-step__bullets {
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
    margin: 0;
    padding-left: var(--s-5);
    color: var(--ink);
    list-style: disc;
  }

  .ia-step__bullets > li::marker {
    color: var(--accent);
  }

  .ia-step__slider {
    min-width: 0;
  }

  .ia-step__ways {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-2);
  }

  /* The words and controls: a column of their own, and the mail app after them. */
  .ia-step--mail > .ia-step__controls {
    display: flex;
    flex-direction: column;
    gap: var(--s-4);
    min-width: 0;
    padding: var(--s-1);
  }

  /* A column too short for its parts scrolls; it never squeezes a sentence into the one under it. */
  .ia-step--mail > .ia-step__controls > * {
    flex-shrink: 0;
  }

  .ia-step__mail {
    min-height: 0;
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-1);
  }

  /* Step 3's count keeps room for three lines, so a number that grows by a digit moves nothing under it. */
  .ia-step--clean .ia-step__counts {
    min-height: 4.5em;
  }

  /* A phone: the words and controls, then the mail app, then the buttons. */
  @media (max-width: 899px) {
    /* The column has no box of its own here, so it must not claim to clip anything: a box that clips and has no size would
       hide everything in it from the guide, which only points at what a person can see. */
    .ia-step--mail > .ia-step__controls {
      display: contents;
      overflow: visible;
    }

    .ia-step--mail {
      gap: var(--s-4);
    }

    .ia-step--mail > .ia-cleanup__foot {
      order: 20;
    }

    /* The buttons that end the sorting or the plan, or let a day go by, stand as wide as each other, and as the main button under them. */
    .ia-step--mail > .ia-cleanup__foot > [data-action='stop'],
    .ia-step--mail > .ia-cleanup__foot > [data-action='cancel-plan'],
    .ia-step--mail > .ia-cleanup__foot > [data-action='pass-day'] {
      flex: 1 1 100%;
    }

    /* As wide as the page, so a row has room for the sender, the subject and the Keep button; the Keep button gets a column
       wide enough to read as two short lines. */
    .ia-step__mail {
      order: 10;
      height: 28rem;
      margin-inline: calc(-1 * (var(--s-4) + 1px + var(--ia-gutter)));
      border-radius: 0;
      box-shadow: none;
    }

    .ia-step--clean .ia-mail__frame {
      --ia-keep-col: calc(var(--s-7) + var(--s-5));
    }

    /* Step 2: the choices, the counts they make and the mail app right under them, so a press is seen in the counts and in the
       list without scrolling the page. */
    .ia-step--old [data-part='words'] { order: 1; }
    .ia-step--old [data-part='age'] { order: 2; }
    .ia-step--old [data-part='counts'] { order: 3; }
    .ia-step--old [data-part='starred'] { order: 12; }

    /* Step 3: the sentences that explain the slider, then the slider, its count and the mail app one under the other, so that
       the thumb and the emails leaving are in the window together. The line about keeping comes after the list it is about. */
    .ia-step--clean [data-part='words'] { order: 1; }
    .ia-step--clean [data-part='bullets'] { order: 2; }
    .ia-step--clean [data-part='ceiling'] { order: 3; }
    .ia-step--clean [data-part='slider'] { order: 4; }
    .ia-step--clean [data-part='counts'] { order: 5; }
    .ia-step--clean [data-part='keep'] { order: 11; }

    .ia-step--done > .ia-step__controls > * { order: 1; }
  }

  @media (min-width: 900px) {
    .ia-step--mail {
      display: grid;
      grid-template-columns: 24.5rem minmax(0, 1fr);
      grid-template-rows: minmax(0, 1fr);
      column-gap: var(--s-5);
      row-gap: var(--s-3);
    }

    /* Its own padding keeps a focus ring whole; the margin gives it back, so the words stand where the heading does.
       A column taller than the window scrolls inside itself and fades at its foot to say so. */
    .ia-step--mail > .ia-step__controls {
      gap: var(--s-3);
      grid-column: 1;
      grid-row: 1;
      min-height: 0;
      margin: calc(-1 * var(--s-1));
      padding-bottom: var(--s-4);
      -webkit-mask-image: linear-gradient(to bottom, var(--ink) calc(100% - var(--s-4)), transparent);
      mask-image: linear-gradient(to bottom, var(--ink) calc(100% - var(--s-4)), transparent);
    }

    /* Two lines of count are all a laptop's column needs, which leaves room for the whole of step 3 in a 900 px window. */
    .ia-step--clean .ia-step__counts {
      min-height: 3.1em;
    }

    /* Step 3 has the most to say, so its lines stand a little closer. */
    .ia-step--clean.ia-step--mail > .ia-step__controls {
      gap: var(--s-2);
    }

    .ia-step--mail > .ia-step__mail {
      grid-column: 2;
      grid-row: 1;
    }

    /* Inbox upkeep: its words change with the plan (a line more when the plan is paid), so the row is never shorter than the
       column's own words and the mail app, which brings no height of its own, grows or shrinks with it. */
    .ia-step--upkeep {
      grid-template-rows: minmax(min-content, 1fr);
    }

    .ia-step--upkeep > .ia-step__mail {
      contain: size;
    }

    .ia-step--mail > .ia-cleanup__foot {
      grid-column: 1 / -1;
      grid-row: 2;
    }
  }

  /*
   * A short window (a laptop's 1440 x 760 once the browser's own bars are taken off): the whole left column of every step stays in
   * sight, whole sentences with nothing under a fade, so the type is a size smaller, the lines and the gaps closer, and the column
   * a little wider (the mail app keeps about 890 px).
   */
  @media (min-width: 900px) and (max-height: 820px) {
    .ia-step--mail {
      grid-template-columns: 27rem minmax(0, 1fr);
    }

    .ia-cleanup {
      padding-block: var(--s-3);
    }

    .ia-cleanup__title {
      font-size: var(--t-xl);
    }

    .ia-step--mail > .ia-step__controls {
      gap: var(--s-2);
      font-size: var(--t-md);
      line-height: 1.32;
    }

    .ia-step--clean .ia-step__counts {
      min-height: 2.75em;
    }

    .ia-step--mail .ia-step__bullets {
      gap: var(--s-1);
      font-size: var(--t-sm);
      line-height: 1.3;
    }

    .ia-step--mail [data-part='keep'],
    .ia-step--mail [data-part='counts'] {
      font-size: var(--t-sm);
    }

    .ia-step--mail .ia-step__note {
      font-size: var(--t-xs);
    }
  }
}
