@layer components {
  .project {
    display: flex;
    flex-direction: column;
    gap: var(--block-space-double);
  }

  /* It sits on the page's sheet, so it is no card of its own. */
  .project__sheet {
    background-color: var(--color-canvas);
  }

  .project__activity {
    --page-size: 40rem;
  }

  /* Nothing in its history or asked of it is one quiet line, starting where its heading does. */
  :is(.project__activity, .project__asked) .blank-slate {
    background: none;
    border: 0;
    color: var(--color-text-subtle);
    font-size: var(--text-small);
    font-weight: 400;
    margin-inline: 0;
    padding: 0;

    > strong {
      color: inherit;
      display: inline;
      font-weight: inherit;
    }
  }

  /* It reads from the start, right under the page's name as the rest of the title's lines do, and the tiles start a title's space below it. */
  .project__header {
    align-items: start;
    display: flex;
    flex-direction: column;
    gap: calc(var(--block-space-half) / 2);
    margin-block-start: calc(var(--block-space-half) - var(--page-header-space));
    padding-block-end: var(--page-header-space);
    text-align: start;

    &:not(:has(*)) {
      display: none;
    }
  }

  .project__text {
    margin: 0;
    max-inline-size: 40rem;
    overflow-wrap: anywhere;
    text-wrap: pretty;
  }

  .project__meta {
    color: var(--color-meta);
    font-size: var(--text-small);
    margin: 0;
    max-inline-size: 48rem;
    text-wrap: pretty;

    /* A link in a byline reads in the byline's colour, underlined, as on a record. */
    a:not(.project__prompt, .chip) {
      color: inherit;
      text-decoration-color: color-mix(in oklch, currentColor 40%, transparent);
      text-underline-offset: 0.15em;
    }
  }

  .project__prompt {
    color: var(--color-text-placeholder);
    text-decoration: none;

    @media (any-hover: hover) {
      &:hover {
        text-decoration: underline;
      }
    }
  }

  /* A public link: its section heading, the switch that opens and closes it, then the address and what to do
     with it, all from the left edge. */
  .publication {
    display: flex;
    flex-direction: column;
    gap: var(--block-space);
    inline-size: 100%;
    margin-block: var(--block-space);
  }

  .publication__switch .switch {
    flex-shrink: 0;
  }

  .publication__url {
    margin: 0;
  }

  .publication__actions {
    display: flex;
    flex-wrap: wrap;
    font-size: var(--text-small);
    gap: var(--inline-space);
  }

  /* Who is on it, in one quiet line: each group's name, then its faces. */
  .project__team {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    font-size: var(--text-small);
    gap: var(--inline-space-half) var(--inline-space-double);
    margin-block-start: var(--block-space-half);

    /* Alone under the name, it reads as the name's byline. */
    &:first-child {
      margin-block-start: 0;
    }

    &:not(:has(*)) {
      display: none;
    }
  }

  .project__people {
    --avatar-size: 1.75rem;

    align-items: center;
    color: inherit;
    display: flex;
    flex-wrap: wrap;
    row-gap: var(--inline-space-half);
    text-decoration: none;

    .project__team & {
      --avatar-size: 1.5rem;
    }

    @media (any-hover: hover) {
      &:is(a):hover .project__people-label {
        text-decoration: underline;
      }
    }

    .avatar {
      box-shadow: 0 0 0 2px var(--color-canvas);
      font-size: calc(var(--avatar-size) * 0.36);
      margin-inline-end: calc(var(--avatar-size) * -0.08);

      &:last-child {
        margin-inline-end: 0;
      }
    }
  }

  /* A site's strip starts with who is on it: a round people button, then their faces. */
  .header__title.project-bar {
    align-items: center;
    display: flex;
    font-weight: 400;
    gap: var(--inline-space);
    min-inline-size: 0;

    .project__people {
      --avatar-size: 1.5rem;

      flex-wrap: nowrap;
      gap: var(--inline-space-half);
      min-inline-size: var(--control-size);
      overflow: hidden;

      .avatar {
        flex: none;
        margin-inline-end: calc(var(--avatar-size) * -0.15 - var(--inline-space-half));

        &:last-child {
          margin-inline-end: 0;
        }
      }
    }

    /* The prompt gives up its room first, and on a phone the people button alone leads to it. */
    .project__prompt {
      flex-shrink: 100;
      min-inline-size: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;

      @media (width < 640px) {
        display: none;
      }
    }
  }

  .project__people-icon {
    --icon-size: 1.1em;

    align-items: center;
    border: 1px solid var(--color-ink-light);
    border-radius: 50%;
    display: inline-flex;
    flex: none;
    justify-content: center;
    block-size: var(--control-size);
    inline-size: var(--control-size);

    @media (any-hover: hover) {
      .project__people:hover & {
        background-color: var(--tint-ink-10);
      }
    }
  }

  /* Under a firm's name: the round people button, then the faces of who is on it. */
  .project__team .project__people-icon {
    margin-inline-end: var(--inline-space-half);
  }

  .project__people-label {
    color: var(--color-meta);
    margin-inline-end: var(--inline-space-half);
  }

  /* Each tool is its name over a card of its preview: two across on a phone and a tablet, three from there,
     the cards of a row as tall as the fullest of them and no taller. */
  .tools {
    display: grid;
    gap: calc(var(--block-space) * 1.5) var(--block-space);
    grid-template-columns: repeat(2, minmax(0, 1fr));

    @container card-grid (inline-size >= 800px) {
      gap: var(--block-space-double) var(--block-space);
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }

  .tool {
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: var(--block-space-half);
    min-block-size: 0;
    min-inline-size: 0;
    text-decoration: none;

    @media (any-hover: hover) {
      &:is(a):hover .tool__title {
        text-decoration: underline;
      }
    }

    &:focus-visible {
      border-radius: var(--radius-lg);
      outline: var(--focus-ring);
      outline-offset: var(--focus-ring-offset);
    }
  }

  /* A tool with a way to add to it: the tile, and a small pill in its name's row, at the right, never over the name. */
  .tool-slot {
    container: tool-slot / inline-size;
    display: grid;
    gap: var(--block-space-half) var(--inline-space);
    grid-template: auto 1fr / minmax(0, 1fr) auto;
    min-inline-size: 0;

    > .tool {
      display: grid;
      grid-area: 1 / 1 / -1 / -1;
      grid-template: subgrid / subgrid;
    }

    /* Stretched, a square preview keeps its column's width instead of taking it from the row's height. */
    .tool__panel {
      grid-column: 1 / -1;
      place-self: stretch;
    }

    > .tool__add,
    > form > .tool__add {
      grid-area: 1 / 2;
    }
  }

  .tool__add {
    --btn-border-radius: 2em;
    --btn-gap: 0.3em;
    --btn-padding: 0 0.7em;
    --icon-size: 1em;

    block-size: calc(var(--text-section) * 1.15);
    font-size: var(--text-control);
    white-space: nowrap;

    /* Out of sight until it has the focus or, with a pointer, the tile is under it or holds the focus. On a touch
       screen a tool adds from its own page. */
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration-medium) ease-out;

    &:focus-visible {
      opacity: 1;
      pointer-events: auto;
    }

    @media (any-hover: hover) {
      .tool-slot:is(:hover, :focus-within) & {
        opacity: 1;
        pointer-events: auto;
        transition-delay: 250ms;
      }
    }

    /* Where its label does not fit beside the tool's name, only its glyph, as on a phone. */
    @container tool-slot (inline-size < 264px) {
      --btn-padding: 0;

      aspect-ratio: 1;

      > span:not(.icon) {
        block-size: 1px;
        clip-path: inset(50%);
        inline-size: 1px;
        overflow: hidden;
        position: absolute;
        white-space: nowrap;
      }
    }

    /* Inspections, the longest name and label, need a wider tile for both. */
    @container tool-slot (inline-size < 316px) {
      .tool-slot--long & {
        --btn-padding: 0;

        aspect-ratio: 1;

        > span:not(.icon) {
          block-size: 1px;
          clip-path: inset(50%);
          inline-size: 1px;
          overflow: hidden;
          position: absolute;
          white-space: nowrap;
        }
      }
    }
  }

  .project__activity-link {
    color: var(--color-link);
  }

  /* The tool's name in the accent, over its preview, on one line. */
  .tool__title {
    color: var(--color-heading-accent);
    font-size: 1rem;                   /* 16px */
    font-weight: 600;
    line-height: 1.5rem;               /* 24px */
    margin: 0;
    white-space: nowrap;

    @media (min-width: 100ch) {
      font-size: 0.947rem;             /* 18px */
      line-height: 1.263rem;           /* 24px */
    }

    /* Cut by the link it holds, if any, so the link's focus ring is not. */
    &:not(:has(> a)),
    > a {
      overflow: hidden;
      text-overflow: ellipsis;
    }

    > a {
      color: inherit;
      display: block;
    }
  }

  .tool__panel {
    --rows-bg: transparent;
    --rows-border-size: 0;
    --rows-margin: 0;
    --tool-text: 0.75rem;              /* 12px: a row's details in a preview */
    --tool-title: 0.875rem;            /* 14px: a row's name in a preview */

    @media (min-width: 100ch) {
      --tool-text: 0.632rem;           /* 12px */
      --tool-title: 0.737rem;          /* 14px */
    }

    background-color: var(--color-canvas);
    border: 1px solid var(--color-ink-lighter);
    border-radius: var(--radius-lg);
    flex: 1 1 auto;
    line-height: 1.25;
    min-block-size: 0;
    overflow: hidden;
    padding: var(--block-space-half);

    /* Three across, a preview is square. */
    @container card-grid (inline-size >= 800px) {
      aspect-ratio: 1;
    }

    /* Two across, a tile is a preview at least 156px tall, and taller where its rows need it, so every row it
       shows is in sight above the count of the rest. */
    @container card-grid (inline-size < 800px) {
      min-block-size: calc(var(--text-section) * 7.8);
    }

    /* On a phone a row's state or count goes under its name, which keeps the tile's width. */
    @container card-grid (inline-size < 560px) {
      .row {
        flex-wrap: wrap;
        row-gap: 0;
      }

      .row__body {
        flex: 1 1 0;
        padding-block-end: 0;
      }

      .row__end {
        flex: 1 0 100%;
        padding-block-end: calc(var(--block-space-half) / 2);
      }
    }

    /* Nothing to preview is said in one quiet line, in the card every other tool has. */
    > .blank-slate {
      background: none;
      border: 0;
      color: var(--color-text-subtle);
      font-size: var(--text-small);
      font-weight: 400;
      margin: 0;
      padding: calc(var(--block-space-half) / 2) var(--inline-space-half);
      text-wrap: wrap;

      > strong {
        color: inherit;
        display: inline;
        font-weight: inherit;
      }
    }

    .row {
      padding-inline: var(--inline-space-half);
    }

    .row--nested {
      padding-inline-start: calc(var(--inline-space-half) + var(--depth, 0) * var(--inline-space));
    }

    .row__body {
      padding-block: calc(var(--block-space-half) / 2);
    }

    .row__title {
      font-size: var(--tool-title);
      font-weight: 700;
    }

    .row__meta {
      font-size: var(--tool-text);
      line-height: inherit;
    }

    /* A row's details say who, when and where in the same quiet line on every tile: words alone, a dot between
       them, without the pill, the faces or the glyphs a list gives them. */
    .row__pill {
      background: none;
      font-size: var(--tool-text);
      padding: 0;
    }

    .row__detail :is(.avatar, .icon) {
      display: none;
    }

    .row:not([hidden]) ~ .row {
      border-block-start: 0;
    }

    .row__end {
      font-size: var(--tool-text);
    }

    /* A state at a row's end is told by the word's colour alone, at the end's size. */
    .row__end .status {
      font-size: inherit;
      font-weight: normal;
    }
  }

  /* What a tool counts, large at the head of its card over a rule: the number, a pair as "N of M", and what it is
     a count of. A card headed by one stands as tall as a full one beside its neighbours, with the way to the rest
     at its foot. */
  .tool__figure {
    align-items: baseline;
    border-block-end: var(--border);
    color: var(--color-meta);
    display: flex;
    flex-wrap: wrap;
    font-size: var(--text-control);
    gap: 0 0.4em;
    line-height: calc(var(--text-section) * 1.6);
    margin: 0 var(--inline-space-half) calc(var(--block-space-half) / 2);
    padding-block-end: calc(var(--block-space-half) / 2);
  }

  .tool__figure-number {
    color: var(--color-ink);
    font-size: calc(var(--text-section) * 1.4);
    font-weight: 800;
    letter-spacing: -0.02em;
  }

  .tool__figure-of {
    color: var(--color-meta);
    font-size: calc(var(--text-section) * 0.8);
    font-weight: 700;
    letter-spacing: 0;
  }

  .tool__panel:has(> .tool__figure) {
    display: flex;
    flex-direction: column;

    &:has(> .rows) {
      @container card-grid (inline-size >= 800px) {
        min-block-size: calc(var(--text-section) * 15);
      }
    }

    .rows {
      flex: 1 1 auto;
    }
  }

  /* A day as a calendar leaf at the head of a row: its month on the link colour, its number under it. */
  .tool__date {
    border: 2px solid var(--color-link);
    border-radius: var(--radius-md);
    flex: none;
    font-size: var(--text-control);
    inline-size: 2.6em;
    line-height: 1.2;
    overflow: hidden;
    text-align: center;
  }

  .tool__date-month {
    background-color: var(--color-link);
    color: var(--color-canvas);
    display: block;
    font-size: 0.72em;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding-block: 0.15em;
    text-transform: uppercase;
  }

  .tool__date-day {
    color: var(--color-ink);
    display: block;
    font-size: 1.07em;
    font-weight: 800;
    padding-block: 0.1em;
  }

  /* A glyph at the head of a row says what kind of row it is, quietly. */
  .tool__panel .row > .icon {
    color: var(--color-meta);
  }

  /* A count at a row's end, in the figure's weight. */
  .tool__amount {
    color: var(--color-ink);
    font-size: var(--tool-text);
    font-weight: 800;
  }

  .tool__all {
    color: var(--color-link);
    font-size: var(--tool-text);
    margin: 0;
    padding: calc(var(--block-space-half) / 2) var(--inline-space-half);
  }

  .tool__more {
    color: var(--color-ink-dark);
    font-size: var(--tool-text);
    margin: 0;
    padding: calc(var(--block-space-half) / 2) var(--inline-space-half) 0;
  }

  .project__group {
    @media screen {
      margin-block: var(--block-space) 0;

      &:first-child {
        margin-block-start: 0;
      }
    }

    @media print {
      margin-block: var(--block-space-double);

      &:last-child {
        margin-block-end: 0;
      }
    }
  }
}
