/* Shape Cards hand: its own column between the board and the info panel. */
.shape-hand-panel {
  align-content: start;
  gap: var(--space-3);
  min-block-size: 0;
  overflow-y: auto;
}

.shape-hand-status {
  margin: 0;
}

.shape-hand-grid {
  display: grid;
  gap: var(--space-2);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* Cards that can't be picked right now (not your turn / card in progress) dim slightly,
   except the highlighted one, which overrides the global disabled-button fade. */
.shape-hand-grid button.shape-card:disabled {
  cursor: default;
  opacity: 1;
}

.shape-hand-grid button.shape-card:disabled:not(.is-selected) {
  opacity: 0.6;
}

.shape-hand-playing .shape-card {
  inline-size: 50%;
}

/* Same buttons as the Pass / Undo / Resign row, sized to however many there are. */
.shape-hand-actions,
.shape-card-color {
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  grid-template-columns: none;
}

.shape-card-slot {
  display: grid;
}

@media (min-width: 760px) {
  .shell.game-layout.desktop-fit .game-view.has-shape-hand {
    grid-template-columns:
      minmax(0, 1fr) var(--shape-hand-inline-size, 15rem) var(--sidebar-inline-size) 1px
      var(--metadata-inline-size);
  }
}

/* Every shape card is the same size; its board scales to fit a fixed square frame. */
.shape-card {
  cursor: default;
  grid-template-rows: auto 1fr auto;
  inline-size: 100%;
  box-sizing: border-box;
}

.shape-card__name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  line-height: 1.2;
  min-block-size: 2.4em;
}

.shape-card__frame {
  aspect-ratio: 1;
  container-type: size;
  display: grid;
  place-items: center;
  inline-size: 100%;
}

.shape-card .j-card__board {
  /* Fit the board's aspect ratio inside the square frame. */
  inline-size: min(
    100cqw,
    100cqh * var(--j-card-board-width, 1) / var(--j-card-board-height, 1)
  );
  max-block-size: none;
  /* Shape cards show only a few lines, so stones are sized from the line spacing. */
  container-type: inline-size;
}

.shape-card .j-card__stone {
  --j-card-stone-size: calc(
    min(
      (100cqi - 2 * var(--j-card-edge-pad, 0.38rem)) / (var(--j-card-board-width, 2) - 1),
      (100cqi * var(--j-card-board-height, 2) / var(--j-card-board-width, 2) -
          2 * var(--j-card-edge-pad, 0.38rem)) / (var(--j-card-board-height, 2) - 1)
    ) * 0.85
  );
}

.shape-card-piles {
  margin: 0;
  padding-left: 1rem;
}

/* Stacked (phone / narrow) layout: the hand sits under the board. */
.shell.game-layout:not(.desktop-fit) .shape-hand-panel {
  margin-top: 1rem;
  overflow: visible;
  padding-inline: var(--gutter-compact);
}

.shell.game-layout:not(.desktop-fit) .shape-hand-grid {
  grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
}
