/* Memory match: a grid of cards. */

/* The cards are square and as big as the room the stage has (see shell.css) allows: the side
   of a card is worked out from the stage's width and height and the number of columns and rows,
   and the board is exactly the cards plus the gaps. A stage that is taller than wide gets tall
   layouts (3 by 4, or 4 by 6 with more cards); a wider one gets them the other way round. */
.board {
  --cols: 3;
  --rows: 4;
  --space: 8px;
  --card: min((100cqw - (var(--cols) - 1) * var(--space)) / var(--cols), (100cqh - (var(--rows) - 1) * var(--space)) / var(--rows), 150px);
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--card));
  grid-template-rows: repeat(var(--rows), var(--card));
  gap: var(--space);
  width: calc(var(--cols) * var(--card) + (var(--cols) - 1) * var(--space));
  height: calc(var(--rows) * var(--card) + (var(--rows) - 1) * var(--space));
}
.board.is-more { --cols: 4; --rows: 6; }
@container (min-aspect-ratio: 1/1) {
  .board { --cols: 4; --rows: 3; }
  .board.is-more { --cols: 6; --rows: 4; }
}

.card {
  appearance: none;
  display: block;
  position: relative;
  width: var(--card);
  height: var(--card);
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: inherit;
  margin: 0;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
/* the back of a card: a plain diamond */
.card:not(.is-up)::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  background: var(--line);
  transform: rotate(45deg);
}
@media (hover: hover) { .card:not(.is-up):hover { border-color: var(--dim); } }
.card[aria-disabled="true"] { cursor: default; }

/* face up */
.card.is-up { background: #262d4a; border-color: #4a5278; }
.pic { position: absolute; left: calc(var(--card) * .14 - 2px); top: calc(var(--card) * .14 - 2px); width: calc(var(--card) * .72); height: calc(var(--card) * .72); display: block; }
.pic-fill { fill: var(--ink); }
.pic-line { fill: none; stroke: var(--ink); stroke-width: 9; stroke-linecap: round; }
.pic-cut { fill: #262d4a; }
.pic-cut-line { fill: none; stroke: #262d4a; stroke-width: 6; stroke-linecap: round; }

/* A matched pair takes the color of whoever found it, and carries their piece in the corner:
   solid for player 1, ringed for player 2. */
.card.own-1 { background: #1b2a2c; border-color: var(--p1); }
.card.own-2 { background: #2c2224; border-color: var(--p2); }
.own-1 .pic-fill { fill: var(--p1); }
.own-1 .pic-line { stroke: var(--p1); }
.own-2 .pic-fill { fill: var(--p2); }
.own-2 .pic-line { stroke: var(--p2); }
.own-1 .pic-cut { fill: #1b2a2c; }
.own-1 .pic-cut-line { stroke: #1b2a2c; }
.own-2 .pic-cut { fill: #2c2224; }
.own-2 .pic-cut-line { stroke: #2c2224; }
.badge { position: absolute; left: 5px; top: 5px; width: 14px; height: 14px; display: block; }
.badge.chip-1, .badge.chip-2 { position: absolute; }

/* a card turns over quickly */
@media (prefers-reduced-motion: no-preference) {
  .card.just-flipped { animation: turn .16s ease-out; }
  @keyframes turn { from { transform: scaleX(.1); } }
}
