@layer components {

  /* A manual popover (see the `toast` controller), stripped of the
     browser's popover chrome; `display` keeps it drawn whether or not it is
     open, so it stands where it always did until a toast lifts it into the
     top layer, above a modal dialog. */
  #inv-toast-container {
    align-items: center;
    background: none;
    border: 0;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    inset-block-end: 2rem;
    inset-block-start: auto;
    inset-inline-end: auto;
    inset-inline-start: 50%;
    margin: 0;
    overflow: visible;
    padding: 0;
    pointer-events: none;
    position: fixed;
    transform: translateX(-50%);
    z-index: var(--z-toast);
  }

  .inv-toast {
    align-items: center;
    background: var(--color-positive);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-popover);
    color: var(--color-ink-inverted);
    display: inline-flex;
    font-size: 0.9375rem;
    font-weight: 500;
    gap: 0.5rem;
    opacity: 0;
    padding: 0.75rem 1.5rem;
    pointer-events: auto;
    transform: translateY(0.75rem);
    transition: opacity 0.25s, transform 0.25s;
    white-space: nowrap;
  }

  .inv-toast--visible {
    opacity: 1;
    transform: translateY(0);
  }

  /* A refusal (e.g. too many re-processing attempts) — an amber toast that
     may wrap: the explanation runs longer than a confirmation. */
  .inv-toast--warning {
    background: var(--color-warning);
    max-inline-size: min(30rem, calc(100dvw - 2rem));
    text-align: start;
    white-space: normal;
  }

  .inv-toast--action {
    padding-inline-end: 0.5rem;
  }

  .inv-toast__action-form {
    display: inline-flex;
    margin: 0;
  }

  .inv-toast__action {
    background: oklch(from var(--color-ink-inverted) l c h / 22%);
    border: none;
    border-radius: var(--radius-pill);
    color: var(--color-ink-inverted);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.35rem 0.9rem;
    transition: background 0.15s;
  }

  .inv-toast__action:hover {
    background: oklch(from var(--color-ink-inverted) l c h / 34%);
  }

  @media (width < 480px) {
    #inv-toast-container {
      inset-block-end: 1rem;
      inset-inline-end: 1rem;
      inset-inline-start: 1rem;
      transform: none;
    }

    .inv-toast {
      inline-size: 100%;
      justify-content: center;
    }
  }

  /* The native apps' tab bar floats over the bottom of the page (see
     `--native-tab-bar-clearance` in layout.css): a toast stands centred just
     above it, as wide as its message, whatever the screen's width. */
  :is([data-platform~="android"], [data-platform~="ios"]) {
    #inv-toast-container {
      inset-block-end: calc(var(--native-tab-bar-clearance) + 0.5rem);
      /* Spans the screen (a popover is otherwise only as wide as its toast) so
         its `align-items` centres the toast. */
      inline-size: auto;
      inset-inline: 1rem;
      transform: none;
    }

    .inv-toast {
      inline-size: auto;
    }
  }
}
