/*
 * Responsible for: how the words under the Inbox overview's title sit: the count, the small note, the story told while a
 * mailbox is read, and the bar along the foot of the header that shows how far the reading has got.
 *
 * Must never: let one wording, one line of the story or one state change the height of this box. The overview's box is
 * sized for its longest count and note. Once a live reading's story was told in it (the lines mark it data-told) the box
 * is taller, sized for the longest count, the longest note and the story's room, and it stays that tall when the reading
 * ends, so the Map under it never moves. A page opened on the finished overview never had a story and keeps the short box.
 */

@layer screens {
  /* One height for every wording of the finished overview at a given width; a live reading's is taller (below). */
  .ia-overview__status {
    height: 7.9em;
    margin-top: var(--s-1);
    overflow: hidden;
    color: var(--muted);
    font-size: var(--t-sm);
    line-height: 1.45;

    /* The story's size and its room in rows: its longest line on two rows, and a row above where the one before fades. */
    --story-size: var(--t-md);
    --story-rows: 3;
    --words-rows: 4;
  }

  /*
   * Words that told a story keep its room, during the reading and after it: the count and the note (four rows between
   * them, five on a phone), and the story's room. At every width from 320 to 1920 px the newest line stands whole in it (measured).
   */
  .ia-overview__status[data-told='true'] {
    height: calc(var(--words-rows) * 1.45em + var(--s-1) + var(--s-4) + var(--story-rows) * 1.35 * var(--story-size));
  }

  /* On a phone the count and the note take five rows, and the longest line of the story three. */
  @media (max-width: 519px) {
    .ia-overview__status {
      --story-rows: 4;
      --words-rows: 5;
    }
  }

  /*
   * On the narrower phones the count of a whole mailbox and its note take one row more than the box holds below 390 px, and two
   * more at 320 px (measured with 5,145 emails: 121 px of words at 350 to 375, 141 px at 320).
   */
  @media (max-width: 389px) {
    .ia-overview__status {
      height: 9.4em;
    }
  }

  @media (max-width: 329px) {
    .ia-overview__status {
      height: 10.6em;
    }
  }

  .ia-overview__count,
  .ia-overview__note {
    display: block;
  }

  .ia-overview__count {
    margin-bottom: var(--s-1);
    color: var(--ink);
  }

  /*
   * The story, spoken to the person while a mailbox is read: heavier and larger than the count, so it reads as a voice
   * and not as a status line. Its lines stack from the foot of a room of fixed height (two lines of speech); a new one
   * comes in at the foot, the earlier ones move up, grow fainter and fade out at the top (half a line of the one before
   * shows above two lines of the newest), so nothing below it moves.
   */
  .ia-overview__story {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    height: calc(var(--story-rows) * 1.35em);
    margin-top: var(--s-4);
    overflow: hidden;
    color: var(--ink);
    font-size: var(--story-size);
    font-weight: 600;
    line-height: 1.35;
    mask-image: linear-gradient(to bottom, transparent, black 1.35em);
  }

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

  .ia-overview__story-line {
    flex: none;
    opacity: 0.35;
    transition: opacity var(--calm) var(--calm-ease), transform var(--calm) var(--calm-ease);
  }

  .ia-overview__story-line[data-on='true'] {
    opacity: 1;
    animation: ia-story-arrive var(--calm) var(--calm-ease) both;
  }

  @keyframes ia-story-arrive {
    from,
    40% {
      opacity: 0;
      transform: translateY(0.6em);
    }
  }

  /* The reading's bar is a line along the foot of the header: it can fill and fade without moving a word. */
  .ia-overview__bar {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: 3px;
    overflow: hidden;
    border-radius: var(--r-pill);
    background: var(--rule);
    opacity: 0;
    transition: opacity var(--slow) var(--ease);
  }

  .ia-overview[data-state='reading'] .ia-overview__bar {
    opacity: 1;
  }

  .ia-overview__bar-fill {
    display: block;
    width: 100%;
    height: 100%;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform var(--fast) linear;
  }

  /* On a laptop the words sit beside the title and the story is set a little larger. */
  @media (min-width: 900px) {
    .ia-overview__status {
      flex: 1 1 0;
      height: calc(var(--words-rows) * 1.45em + var(--s-1));
      margin-top: 0;

      --story-size: var(--t-lg);
    }
  }

  /* In a narrower window the words have too little room beside the title: they go under it, in the same box in every state. */
  @media (min-width: 900px) and (max-width: 1439px) {
    .ia-overview__status {
      height: 6.6em;
      margin-top: var(--s-1);
    }
  }
}
