@layer components {
  /* All Agents: the cards three across, on every width (stream J), as flat as the papers on a binder
     (stream K, Joey: "It isn't flat and simple like everything else"). */
  .card-binder { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(0.7rem, 2vw, 1.4rem); max-width: 40rem;
    margin-block-start: calc(var(--block-space) * 1.2); }
  .roster-link { display: block; text-decoration: none; color: inherit; }
  .roster-link:focus-visible { outline: none; }
  .roster-link:focus-visible .agent-card { box-shadow: 0 0 0 2px var(--accent); }

  /* A card: a paper on the page as a binder's papers are (the same paper, hairline, soft shadow and
     lift under the pointer), in a playing card's proportions with its rounder corners; its mark, its
     name and its title, sized to the card. Its colour is its mark's, nowhere else. */
  /* Its own padding and gap are in the card's width (percent), since container units inside a rule
     measure an ancestor, never the element itself. */
  .agent-card { container-type: inline-size; display: grid; align-content: center; justify-items: center; gap: 0.35rem; aspect-ratio: 63 / 88;
    padding: 10% 8%; border-radius: 5px; background: var(--raised); text-align: center;
    box-shadow: 0 0 0 1px var(--rule), 0 6px 16px -12px oklch(var(--lch-shade) / 0.35); transition: transform 180ms ease-out; }
  .roster-link:hover .agent-card { transform: translateY(-4px) rotate(-0.6deg); }
  @media (prefers-reduced-motion: reduce) { .agent-card { transition: none; } .roster-link:hover .agent-card { transform: none; } }
  .agent-card.is-unseen { opacity: 0.6; }
  .agent-card-mark { width: 46cqw !important; height: 46cqw !important; margin-block-end: 3cqw; }
  .agent-card .agent-card-name { margin: 0; max-width: 100%; font-size: max(10.5cqw, 0.8rem); font-weight: 700; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .agent-card .agent-card-type { margin: 0; max-width: 100%; font-size: max(7.4cqw, 0.68rem); color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .agent-card-none { font-style: italic; }

  /* An agent's page (stream K): a plain page; its mark large beside its name and what it is, as a
     person's page has theirs; its words and numbers; the page's own rows; the small print. */
  .agent-head { display: flex; align-items: center; gap: 1.1rem; min-width: 0; flex: 1 1 auto; }
  .agent-head-mark { width: 4.2rem !important; height: 4.2rem !important; flex: none; }
  .agent-page .binder-top { flex-wrap: wrap; row-gap: 0.4rem; }
  /* Connections sits under its title as Where It Works does, with no rule between. */
  .agent-connections .setting-row:first-child { border-block-start: 0; }
  .agent-page .binder-edit { white-space: nowrap; }
  @media (max-width: 60ch) { .agent-head { gap: 0.8rem; } .agent-head-mark { width: 3.2rem !important; height: 3.2rem !important; } }
  .agent-head-words { min-width: 0; }
  .agent-head .agent-card-name { margin: 0; overflow-wrap: break-word; }
  .agent-page .agent-card-type { margin: 0.2rem 0 0; font-size: 0.95rem; color: var(--ink-soft); }
  .agent-page .agent-card-about { margin-block-start: 1rem; }
  .agent-card-stats { display: flex; flex-wrap: wrap; gap: 0.3rem 1.3rem; margin: 0.6rem 0 0; font-size: 0.9rem; color: var(--ink-soft); }
  .agent-card-stat b { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }
  .agent-card-more { white-space: nowrap; }
  .agent-card-foot { display: flex; justify-content: space-between; gap: 1rem; margin: calc(var(--block-space) * 1.5) 0 0; font-size: 0.78rem; color: var(--ink-soft); }
  .agent-card-foot span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Where it works, its connections and its papers. */
  .agent-places { list-style: none; margin: 0; padding: 0; display: grid; }
  .agent-place { display: grid; gap: 0.15rem; padding-block: 0.6rem; border-block-end: 1px solid var(--rule); }
  .agent-place:last-child { border-block-end: 0; }
  .agent-place-where { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.2rem 0.6rem; }
  .agent-place-name { font-weight: 700; color: var(--ink); text-decoration: none; }
  .agent-place-name:hover { text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 0.2em; }
  .agent-place-shelf { font-size: 0.8rem; color: var(--ink-soft); }
  .agent-place-what { font-size: 0.82rem; line-height: 1.5; color: var(--ink-soft); }
  .agent-place-tag + .agent-place-tag::before { content: "·"; margin-inline: 0.45rem; }
  .agent-place-tag.is-assigned { color: var(--ink); }
  .writer-head { display: flex; align-items: center; gap: 0.8rem; }
  .writer-mark { width: 2.4rem !important; height: 2.4rem !important; font-size: 0.8rem !important; }
  .row.is-list.writer-holding { margin-block-start: 1.6rem; }

  /* Edit Profile's picture, as Basecamp's project sheet has it: the mark as it is now, clicked to
     choose another, shown in its own shape before it is saved; and Remove, when there is one. */
  .agent-picture-field { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 1rem; }
  .agent-picture-field .field-label { flex-basis: 100%; }
  .agent-picture-pick { display: inline-flex; align-items: center; gap: 0.8rem; cursor: pointer; }
  .agent-picture-pick:focus-within .button { box-shadow: 0 0 0 2px var(--accent); }
  .agent-picture-pick [data-agent-picture-target=tile] { display: grid; place-items: center; width: 3.4rem; height: 3.4rem; }
  .agent-picture-pick [data-agent-picture-target=tile].has-picture .who-picture { width: 100%; height: 100%; object-fit: contain; }
  .agent-picture-mark { width: 3.4rem !important; height: 3.4rem !important; }
  .agent-picture-remove { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--ink-soft); cursor: pointer; }
  .field .agent-picture-remove input { width: auto; padding: 0; }
}

@layer components {
  /* Agents, in the masthead: a round control beside the reader's mark, its agents' marks overlapping
     in it as a small hand of cards; a wave when there are none. Its menu is the New menu's card. */
  .masthead-agents { position: relative; align-self: center; }
  .agents-circle { display: inline-flex; align-items: center; justify-content: center; min-width: 1.85rem; height: 1.85rem; padding: 0 0.2rem;
    border-radius: 999px; border: 1px solid var(--rule); background: var(--paper); color: var(--ink-soft); }
  .agents-circle:hover, .agents-circle[aria-expanded=true] { border-color: var(--ink-soft); color: var(--ink); }
  .agents-circle.is-empty { width: 1.85rem; padding: 0; }
  .agents-circle-mark { width: 1.3rem !important; height: 1.3rem !important; font-size: 0.45rem !important; box-shadow: 0 0 0 1.5px var(--paper); }
  .agents-circle-mark + .agents-circle-mark { margin-inline-start: -0.45rem; }
  .agents-menu { min-width: 17rem; max-height: min(34rem, calc(100dvh - 5rem)); overflow-y: auto; }
  .new-menu-title.is-first { border-block-start: 0; margin-block-start: 0; }
  .agents-menu-row { display: grid !important; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 0.6rem; }
  .agents-menu-row .timeline-who { width: 1.5rem; height: 1.5rem; font-size: 0.5rem; }
  .agents-menu-name { display: grid; min-width: 0; font-weight: 600; }
  .agents-menu-what { font-weight: 400; font-size: 0.74rem; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .agents-menu-when { font-size: 0.7rem; color: var(--ink-soft); white-space: nowrap; }
  .agents-menu-none { margin: 0.2rem 0.7rem 0.4rem; font-size: 0.8rem; color: var(--ink-soft); }
  .agents-menu-all { position: sticky; bottom: -0.35rem; border-block-start: 1px solid var(--rule); border-radius: 0 0 5px 5px; margin-block-start: 0.25rem; font-weight: 700; background: var(--raised); }
  @media (max-width: 60ch) { .agents-menu { position: fixed; left: 16px; right: 16px; top: 3.6rem; min-width: 0; } }

  /* Who is assigned to a shelf, a binder or a paper: the masthead's round control in small, at the top
     right, its menu the same card; each assigned agent with Unassign, then Assign. */
  .assign-control .agents-circle { min-width: 1.75rem; height: 1.75rem; }
  .assign-control .agents-circle.is-empty { width: 1.75rem; }
  .assign-menu { min-width: 18rem; }
  .assign-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0.4rem; }
  .assign-off { padding: 0.3rem 0.5rem; font-size: 0.74rem; color: var(--ink-soft); border-radius: 5px; }
  .assign-off:hover { color: var(--ink); background: color-mix(in oklab, var(--ink) 6%, transparent); }
  .new-menu form.assign-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.4rem; padding: 0.15rem 0.45rem 0.4rem; }
  .assign-form .select, .assign-form input[type=text] { grid-column: 1 / -1; width: 100%; padding: 0.4rem 0.5rem; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); font: inherit; font-size: 0.85rem; color: var(--ink); }
  .assign-form .button { grid-column: 2; }
  .paper-head-actions { display: flex; align-items: flex-start; gap: 0.5rem; }
  .paper-head-actions .assign-control { margin-block-start: -0.2rem; }
}

@layer components {
  /* Connect: the platforms as a row of choices, the chosen one raised, and under them the chosen
     platform's own setup alone. */
  /* Wide enough for the six platforms in a row; its top stays where it opened while another
     platform's setup, taller or shorter, is chosen. On a phone it is the usual sheet. */
  @media (min-width: 60ch) { .binder-dialog.is-form.connect-dialog { width: min(38rem, calc(100vw - 2rem)); margin-block: 12dvh auto; } }
  .connect-platforms { display: flex; flex-wrap: wrap; gap: 0.35rem; border: 0; padding: 0; margin: 0 0 1rem; }
  .connect-platforms legend { margin-block-end: 0.4rem; }
  .connect-platform { position: relative; padding: 0.35rem 0.7rem; border: 1px solid var(--rule); border-radius: 999px; font-size: 0.85rem; cursor: pointer; }
  .connect-platform input { position: absolute; opacity: 0; pointer-events: none; }
  .connect-platform:has(input:checked) { background: var(--raised); border-color: var(--ink-soft); font-weight: 700; }
  .connect-platform:has(input:focus-visible) { box-shadow: 0 0 0 2px var(--accent); }
  .connect-setup { display: none; }
  .connect-step { display: grid; gap: 0.4rem; justify-items: start; }
  .connect-code { width: 100%; font-family: var(--mono); font-size: 0.8rem; padding: 0.5rem 0.6rem; border: 1px solid var(--rule); border-radius: 6px; background: var(--desk); color: var(--ink); resize: none; field-sizing: content; overflow-wrap: anywhere; }
  .connect-dialog:has(input[value=claude_code]:checked) .connect-setup[data-platform=claude_code],
  .connect-dialog:has(input[value=codex]:checked) .connect-setup[data-platform=codex],
  .connect-dialog:has(input[value=cursor]:checked) .connect-setup[data-platform=cursor],
  .connect-dialog:has(input[value=claude]:checked) .connect-setup[data-platform=claude],
  .connect-dialog:has(input[value=grok_bot]:checked) .connect-setup[data-platform=grok_bot],
  .connect-dialog:has(input[value=command_line]:checked) .connect-setup[data-platform=command_line] { display: block; }
}
