/*
 * THE LAYOUT ENGINE, and it still MEASURES: every tile needs the resulting side as
 * a NUMBER — a badge is fitted to the slot and the compact threshold decides which
 * face a file takes — so the width is read with a `ResizeObserver` and arrives as
 * `--lotics-thumbnail-grid-item`. The gap is a prop, so it is data too.
 */
@layer theme, base, lotics, components, utilities;
@layer lotics.tokens, lotics.reset, lotics.components;

@layer lotics.components {
  .lotics-thumbnail-grid {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
    justify-content: flex-start;
    gap: var(--lotics-thumbnail-grid-gap);
    user-select: none;
  }

  .lotics-thumbnail-grid[data-align="end"] {
    justify-content: flex-end;
  }

  /* ONE non-wrapping row that fits what it can and counts the rest. */
  .lotics-thumbnail-grid[data-mode="single"] {
    flex-wrap: nowrap;
    align-items: center;
  }

  /* Something ABOVE the grid owns the press — a table cell, a pressable row —
     so no tile inside may take one. */
  .lotics-thumbnail-grid[data-inert] {
    pointer-events: none;
  }

  .lotics-thumbnail-grid__item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex-shrink: 0;
    width: var(--lotics-thumbnail-grid-item);
  }

  /* AN OWED SLOT, drawn as the tile it will become, so a pile of three with two
     still owed reads as five slots of one size.

     DASHED and in the shortfall's ink. The wash is that same amber so the dash has
     a ground to be read against at a 40px tile, and the dash says the slot is
     empty to a reader who cannot tell amber from grey. */
  .lotics-thumbnail-grid__ghost {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    width: 100%;
    aspect-ratio: 1;
    padding: 0;
    border: 1.5px dashed var(--lotics-ink-warning);
    border-radius: var(--lotics-radius-control);
    background-color: var(--lotics-tone-amber);
    appearance: none;
    cursor: default;
    --lotics-icon-color: var(--lotics-ink-warning);
    transition: background-color var(--lotics-duration-fast) var(--lotics-ease-standard);
  }

  .lotics-thumbnail-grid__ghost[data-compact] {
    border-radius: calc(var(--lotics-radius-control) - var(--lotics-space-2));
  }

  /* Only the slot that can BE filled answers a pointer. */
  .lotics-thumbnail-grid__ghost[data-pressable]:hover {
    background-color: var(--lotics-tone-amber-strong);
  }

  .lotics-thumbnail-grid__ghost:focus-visible {
    outline: var(--lotics-ring-width) solid var(--ring);
    outline-offset: 0;
  }

  /* The "+N" cell: a same-size tile in a single row, and loose type in a wrap,
     where there is no slot left to fill. */
  .lotics-thumbnail-grid__overflow {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: var(--lotics-thumbnail-grid-item);
    height: var(--lotics-thumbnail-grid-item);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--lotics-radius-control);
    background-color: var(--muted);
    appearance: none;
    cursor: default;
    transition: background-color var(--lotics-duration-fast) var(--lotics-ease-standard);
  }

  .lotics-thumbnail-grid__overflow[data-compact] {
    border-radius: calc(var(--lotics-radius-control) - var(--lotics-space-2));
  }

  .lotics-thumbnail-grid__overflow:hover {
    background-color: var(--lotics-wash-press);
  }

  .lotics-thumbnail-grid__overflow:active {
    background-color: var(--lotics-wash-control-press);
  }

  .lotics-thumbnail-grid__overflow:focus-visible {
    outline: var(--lotics-ring-width) solid var(--ring);
    outline-offset: 0;
  }
}
