@layer components {
  /* ——— Avatars ———
     A circle of initials: the one place a name is allowed to become a mark.
     Neutral at rest; a person's face takes their own hue (below). */

  /* A meeting's guest has no person card to open (layouts/application), and
     a line that arrives over the cable was drawn for nobody in particular. */
  body.guest button.avatar {
    pointer-events: none;
  }

  .avatar {
    display: grid;
    place-items: center;
    inline-size: var(--avatar-size, 1.75rem);
    block-size: var(--avatar-size, 1.75rem);
    flex-shrink: 0;
    /* The initials are sized to their circle, the x-small step at the full
       face: at the inline size they fit with room, so a lap hides no letter. */
    font-size: min(var(--text-x-small), calc(var(--avatar-size, 1.75rem) * 0.42));
    font-weight: 600;
    color: var(--color-ink-subtle);
    /* The surface tint is 3% ink over whatever is behind — behind a face
       that is the next face in a stack, or the words a marker stands over,
       and the circle read as translucent (owner, 2026-10-13). The canvas
       under the tint makes it opaque without a second colour. */
    background-color: var(--color-canvas);
    background-image: linear-gradient(var(--color-surface), var(--color-surface));
    border-radius: 50%;

    /* Positioned only when it actually carries the dot, so the circle stays
       inert everywhere else. */
    &:has(.unread-dot) {
      position: relative;
    }

    /* The face that opens the person card is the button itself (avatar_tag),
       so it sheds a control's frame and keeps the circle. */
    &:is(button) {
      padding: 0;
      border: none;
      cursor: pointer;
    }

    /* A face fills the circle the initials were centred in. Cover, not
       contain: a portrait cropped square is a face, a portrait letterboxed
       into a circle is two grey wedges. Square, said outright: the settings
       preview shows the raw upload before any thumb exists, and a portrait
       there grew the grid row to its own height, an ellipse over the label
       beside it. */
    > img {
      aspect-ratio: 1;
      inline-size: 100%;
      block-size: 100%;
      object-fit: cover;
      border-radius: 50%;
    }
  }

  /* A person's own colour (owner, 2026-11-03, reversing "their caret, never
     their face"): their initials in their tint and its paired ink, the same
     hue (User#hue) their caret wears in a document (cursors.css). A
     photograph covers it. Only a person's face carries a hue — a company's
     mark and a meeting's glyph stay neutral — so avatar_tag sets both the
     class and the hue. */
  .avatar--person {
    color: oklch(var(--lch-person-ink) var(--person-hue));
    background-color: oklch(var(--lch-person-tint) var(--person-hue));
    background-image: none;
  }

  /* The face doubles as the file picker in settings' profile pane — fizzy's
     anatomy: the circle IS the control, wrapped in a <label> with the input
     clipped away inside it, so the browser's own "Choose File / No file
     chosen" never appears. The words beside the circle are part of the same
     label, which is why the pointer belongs to the label and not the circle.

     The circle holds two things at once — the initials you have now and the
     picture you just picked — stacked in the one grid cell so the preview
     COVERS rather than replaces. Cancel the picker and nothing was thrown
     away; and until Save nothing has been uploaded either. */
  .avatar-picker {
    cursor: pointer;

    .avatar > * {
      grid-area: 1 / 1;
    }
  }

  /* One of the faces Chalet ships, picked like a colour (color-picker.css):
     the radio inside is clipped, and the face draws its state — a ring of
     ink when it is the one. The ring is the label's, so it stands clear of
     the circle. */
  .avatar-choice {
    border-radius: 50%;
    cursor: pointer;

    &:has(:checked) {
      outline: var(--focus-ring-size) solid var(--color-ink);
      outline-offset: var(--focus-offset);
    }

    &:has(:focus-visible) {
      outline: var(--focus-ring);
      outline-offset: var(--focus-offset);
    }
  }

  /* Several people as one mark: subscribers under a message, a ping row, the
     assignees on a to-do. The paper ring is what keeps them countable where
     they touch.

     The lap is slight, a fifth of a face at any size: a pile hides the end of
     every circle but the last, and "LB" lapped by half read "LE" (user's image
     42, 2026-08-13). Where people gather in number, avatars/_stack draws the
     group: up to three apart, more as four lapped faces and "+N" that open in
     place (owner, 2026-11-04). */
  .avatars {
    display: flex;

    /* A group can be one link — a project's faces open its people page — and
       the initials are faces, not words to underline. */
    text-decoration: none;

    /* How far each face laps the one before — a fifth of it, so a smaller
       strip laps less by itself — read with its default so a strip can still
       retune it from where it stands. */
    > .avatar + .avatar {
      margin-inline-start: calc(-1 * var(--avatar-overlap, var(--avatar-size, 1.75rem) * 0.2));
      box-shadow: 0 0 0 2px var(--color-canvas);
    }

    /* The stack that opens sheds a control's frame (`unbuttoned`) and keeps
       the circle's edge for its focus ring. */
    &:is(button) {
      border-radius: 999px;
    }
  }

  /* Three or fewer stand apart, each whole — a lap would only hide them. */
  .avatars--apart {
    --avatar-overlap: calc(var(--inline-space-half) * -1);
  }

  /* The stack opened: a float over it, every face whole at the size faces are
     everywhere, ten to a row, under the count. It covers the stack — its first
     face where the stack's was, the margin taking back the padding — and by
     an edge it flips, margins and all (popups.css). Said at a popup's weight
     and one more, because popups.css loads after this file and declares the
     padding and the margin itself. */
  .avatars__float:is(.popup) {
    --popup-area: span-block-end span-inline-end;
    --avatar-size: 1.75rem;

    /* Its own width, never the room left beside the stack: squeezed, the
       faces wrapped two to a row by an edge instead of flipping. */
    inline-size: max-content;
    margin: calc(var(--block-space) * -1.5) 0 0 calc(var(--block-space) * -1.5);
    padding: calc(var(--block-space) * 1.5);

    /* A narrow sheet opens it under its line, the width of the column (the
       canvas's phone). */
    @container main (width < 35rem) {
      --popup-area: block-end span-all;

      inline-size: auto;
      justify-self: stretch;
      margin: var(--block-space-half) var(--inline-space-double) 0;
    }
  }

  /* Ten to a row, then it scrolls past about sixty (the row is utilities). */
  .avatars__grid {
    gap: var(--block-space);
    max-inline-size: calc(10 * var(--avatar-size) + 9 * var(--block-space));
    max-block-size: calc(6.5 * var(--avatar-size) + 6 * var(--block-space));
    overflow-y: auto;
  }

  /* A company's mark (crm-v2, the compact pass): the face's tile, squared,
     so a company and a person read apart at a glance. */
  .avatar--square {
    border-radius: var(--border-radius);

    /* A logo keeps its whole shape on the tile, where a face is cropped to
       fill its circle. */
    > img {
      object-fit: contain;
      border-radius: inherit;
    }
  }

  /* A thread of several mails, on its row in Mail (docs/planning/
     email-ux.md, ruling 10): the edge of a second circle behind the mark,
     up and back, the paper ring between them as in a pile of faces. */
  .avatar--stack {
    box-shadow: 0 0 0 2px var(--color-canvas), -4px -4px 0 0 var(--color-line);
  }

  /* In a line of words — a folder row's "Nina · Oct 13" — the face sits
     in the line, small, on the middle of the text. */
  .avatar--inline {
    --avatar-size: 1.25rem;

    display: inline-grid;
    vertical-align: middle;
  }

  /* Unread is a shu dot and nothing else — no count, no bold, no ring of
     colour. The paper border keeps it legible against any avatar. */
  .unread-dot {
    position: absolute;
    inset-block-start: 0;
    inset-inline-end: -2px;
    inline-size: 9px;
    block-size: 9px;
    background-color: var(--color-accent);
    border: 2px solid var(--color-canvas);
    border-radius: 50%;
  }
}
