@layer components {
  /* While Shift is held, a control that answers to a key shows it on a cap after its name and widens for it.
     A control that shows its key itself, as a field does, gets none. */
  @media (any-hover: hover) {
    [data-key-hints] [aria-keyshortcuts]:not(:has(kbd))::before {
      border: 1px solid;
      border-radius: 0.3em;
      box-shadow: 0 0.1em 0 currentColor;
      content: attr(aria-keyshortcuts);
      content: attr(aria-keyshortcuts) / "";
      flex: none;
      font: 600 calc(var(--text-control) * 0.8) / 1.25 var(--font-mono);
      margin-inline-end: 0.3em;
      order: 1;
      padding: 0 0.4em;
      text-transform: uppercase;
      white-space: nowrap;
    }

    /* A button that is only its icon keeps the icon's square and grows by the cap. */
    [data-key-hints] .btn[aria-keyshortcuts]:not(:has(kbd)) {
      aspect-ratio: auto;
      grid-auto-flow: column;
      grid-template-columns: var(--btn-size);
      inline-size: auto;
    }

    /* Below 800 Messages is an icon, and takes a little room around it. */
    @media (width < 800px) {
      [data-key-hints] .site-header__link[aria-keyshortcuts] {
        --btn-padding: 0 0.5em;
      }
    }

    [data-key-hints] [aria-keyshortcuts~="Escape"]:not(:has(kbd))::before {
      content: "esc";
      content: "esc" / "";
    }

    /* A crumb clips what it cannot fit, so its cap stands in room made after the name and a long name gives way to it. */
    [data-key-hints] .breadcrumbs > [aria-keyshortcuts] {
      padding-inline-end: 2.7em;
      position: relative;

      &::before {
        inset-block-start: 50%;
        inset-inline-end: 0;
        margin: 0;
        position: absolute;
        translate: 0 -50%;
      }
    }
  }
}
