/* ==========================================================================
   recall-poker.css — recall poker's arena
   (src/assets/js/games/recall-poker/view.mjs), inside the table games.css
   draws: one line saying what to do and the seconds left, the three shared
   cards, the board, and under it the lock-in button or both hands. A card is
   a hairline tile, rank over suit; face down it is hatched. Every class here
   is .rp-*.
   ========================================================================== */

/* A round is played against the clock, so all of it — the seconds, the shared cards, the board and
   the button under it — is to stand in one window (view.mjs moves the page there as a board is
   dealt). One measure sets the cards: --card, a card's width, as large as three limits let it be:
     --full: 64 design pixels, where there is room;
     --wide: the arena's width holds a row of --cols of them (the arena is the container: cqi);
     --tall: the window's height holds everything. --fixed is what is there besides cards, with 12px
       clear above and below: the arena's padding, the two lines on top, the label, the line and
       the button under the board, and the spaces between. What is left is --rows of the board and
       the shared row (--shared of a card high), each card 1.3 times as tall as wide. It is the
       small viewport that is measured (svh), so a phone's toolbars sliding away never resize the
       board.
   A window too short to give a card 40px gets 40px all the same, and scrolls: a card still has to
   be a finger's target. The first --wide and --tall are for a browser without the newer units. */
.rp {
  --cols: 4; /* the board's columns and rows; view.mjs sets them */
  --rows: 4;
  --gap: calc(8 * var(--s, 1px));
  --step: calc(14 * var(--s, 1px)); /* between the arena's parts */
  --full: calc(64 * var(--s, 1px));
  --shared: 1; /* a shared card's size beside a card of the board */
  --fixed: calc(276 * var(--s, 1px));
  --wide: calc((100vw - 40px - (var(--cols) - 1) * var(--gap)) / var(--cols));
  --tall: calc((100vh - var(--fixed) - (var(--rows) - 1) * var(--gap)) / (var(--rows) + var(--shared)) / 1.3);
  --card: max(40px, min(var(--full), var(--wide), var(--tall)));
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--step);
  font-family: var(--font-mono);
  -webkit-user-select: none;
  user-select: none;
}
@supports (width: 1cqi) {
  .rp { --wide: calc((100cqi - (var(--cols) - 1) * var(--gap)) / var(--cols)); }
}
@supports (height: 1svh) {
  .rp { --tall: calc((100svh - var(--fixed) - (var(--rows) - 1) * var(--gap)) / (var(--rows) + var(--shared)) / 1.3); }
}

/* ---- On top: what to do, and under it the seconds left ------------------------
   Two lines of fixed height, each centred on the board's own middle: the words change length from
   one moment to the next ("turn two cards", "one more"), and neither the number nor the board
   under it moves when they do. */
.rp-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(4 * var(--s, 1px));
}
.rp-what {
  min-block-size: calc(24 * var(--s, 1px));
  font-size: calc(17 * var(--s, 1px));
  line-height: calc(24 * var(--s, 1px));
  font-weight: 500;
  text-wrap: balance;
}
.rp-what--ok { color: var(--green); }
/* The seconds: the biggest thing on the screen while they run, red for the last five. */
.rp-clock {
  display: flex;
  align-items: center;
  justify-content: center;
  block-size: calc(34 * var(--s, 1px));
  font-size: calc(32 * var(--s, 1px));
  font-weight: 500;
  line-height: 1;
}
.rp-clock--low { color: var(--red); }
/* "next in 5": words, so the size of words. */
.rp-clock--words {
  font-size: calc(13 * var(--s, 1px));
  font-weight: 400;
  color: var(--ink-muted);
}

/* ---- Cards ------------------------------------------------------------------ */
.rp-shared-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(6 * var(--s, 1px));
}
.rp-shared {
  display: flex;
  gap: var(--gap);
}
.rp-board {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--card));
  gap: var(--gap);
}
.rp-card {
  --w: var(--card); /* this card's own width: its face is sized by it */
  -webkit-appearance: none;
  appearance: none;
  position: relative; /* the key hint in its corner */
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  inline-size: var(--w);
  block-size: calc(var(--w) * 1.3);
  margin: 0;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: calc(4 * var(--s, 1px));
  background: var(--bg);
  font: inherit;
  color: var(--ink);
  cursor: default;
  -webkit-tap-highlight-color: transparent;
}
/* A disabled button greys its text in some browsers; a card's face is never greyed by that. */
.rp-card:disabled { color: var(--ink); opacity: 1; }
/* Face down: hatched, so a turned card is plainly not an empty place. */
.rp-card--down {
  border-color: var(--ink-muted);
  background:
    repeating-linear-gradient(135deg, transparent 0 calc(5 * var(--s, 1px)), var(--hairline) calc(5 * var(--s, 1px)) calc(6 * var(--s, 1px))),
    var(--bg);
}
.rp-card--shared { --w: calc(var(--card) * var(--shared)); }
/* A shared card not dealt yet: a place for one, not a card. */
.rp-card--shared.rp-card--down {
  border-style: dashed;
  border-color: var(--hairline);
  background: none;
}
/* A card that can be tapped now. */
.rp-card--live { cursor: pointer; }
@media (hover: hover) and (pointer: fine) {
  .rp-card--live:hover { border-color: var(--pink); }
}
/* Picked: yours now — green, and a heavier edge, drawn inside so nothing moves. */
.rp-card--picked,
.rp-card--picked:hover {
  border-color: var(--green);
  box-shadow: inset 0 0 0 calc(2 * var(--s, 1px)) var(--green);
  background:
    repeating-linear-gradient(135deg, transparent 0 calc(5 * var(--s, 1px)), color-mix(in oklch, var(--green) 35%, transparent) calc(5 * var(--s, 1px)) calc(6 * var(--s, 1px))),
    var(--bg);
}
/* Turned over at the end of a round. Yours: a solid green outline. The other player's: a dashed
   ink edge. Two shapes, so a card you both turned wears both. The rest step back. */
.rp-card--mine {
  outline: calc(2 * var(--s, 1px)) solid var(--green);
  outline-offset: calc(2 * var(--s, 1px));
}
.rp-card--theirs {
  border: calc(2 * var(--s, 1px)) dashed var(--ink);
}
.rp-card--dim {
  border-color: var(--hairline-soft);
}
.rp-card--dim .rp-face { opacity: 0.38; }

/* A face: the rank over its suit. */
.rp-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--w, var(--card)) * 0.06);
  line-height: 1;
  color: var(--ink);
}
.rp-face--red { color: var(--red); }
.rp-rank {
  font-size: calc(var(--w, var(--card)) * 0.36);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.rp-suit {
  inline-size: calc(var(--w, var(--card)) * 0.3);
  block-size: calc(var(--w, var(--card)) * 0.3);
  fill: currentColor;
}
/* In a line of text: rank and suit side by side, in a small tile. */
.rp-face--small {
  flex-direction: row;
  gap: 0.2ch;
  padding: calc(3 * var(--s, 1px)) calc(6 * var(--s, 1px));
  border: 1px solid var(--hairline);
  border-radius: calc(3 * var(--s, 1px));
}
.rp-face--small .rp-rank { font-size: calc(15 * var(--s, 1px)); }
.rp-face--small .rp-suit {
  inline-size: calc(12 * var(--s, 1px));
  block-size: calc(12 * var(--s, 1px));
}

/* The key that picks a card, in its corner, where a keyboard is likely (as on 24's tiles). */
.rp-card[data-key]::before {
  content: attr(data-key) / "";
  position: absolute;
  inset-block-start: calc(4 * var(--s, 1px));
  inset-inline-start: calc(6 * var(--s, 1px));
  font-size: calc(11 * var(--s, 1px));
  line-height: 1;
  color: var(--ink-muted);
  display: none;
}
@media (hover: hover) and (pointer: fine) {
  .rp-card--live[data-key]::before { display: block; }
}

/* ---- Under the board ---------------------------------------------------------- */
/* What the other player is doing; a reserved line, so the button never moves. */
.rp-note { min-block-size: calc(20 * var(--s, 1px)); }
.rp-keys {
  display: flex;
  justify-content: center;
}
/* Before the pick the button has nothing to do: its place is kept, the button is not shown. */
.rp-keys--off { visibility: hidden; }
.rp-lock {
  position: relative;
  min-inline-size: calc(132 * var(--s, 1px));
  min-block-size: calc(48 * var(--s, 1px));
  font-size: calc(15 * var(--s, 1px));
}
.rp-lock--done,
.rp-lock--done:disabled {
  color: var(--green);
  border-color: var(--green);
  opacity: 1;
}
.rp-lock::before {
  content: attr(data-key) / "";
  position: absolute;
  inset-block-start: calc(5 * var(--s, 1px));
  inset-inline-start: calc(7 * var(--s, 1px));
  font-size: calc(11 * var(--s, 1px));
  font-weight: 400;
  line-height: 1;
  color: var(--ink-muted);
  display: none;
}
@media (hover: hover) and (pointer: fine) {
  .rp-lock:not(:disabled)::before { display: block; }
}

/* Whose outline is whose: a sample of each beside its name. */
.rp-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem 2.4ch;
}
.rp-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 1ch;
}
.rp-swatch {
  box-sizing: border-box;
  inline-size: calc(12 * var(--s, 1px));
  block-size: calc(15 * var(--s, 1px));
  border-radius: calc(2 * var(--s, 1px));
}
.rp-swatch--mine { border: calc(2 * var(--s, 1px)) solid var(--green); }
.rp-swatch--theirs { border: calc(2 * var(--s, 1px)) dashed var(--ink); }

/* Both hands, one under the other in three columns: the name, the two cards turned, what they made
   with the shared three. (A row is only a row to the markup: its cells are the grid's own, so the
   two rows line up whatever the names are.) */
.rp-hands {
  display: grid;
  grid-template-columns: fit-content(14ch) max-content fit-content(26ch);
  justify-content: center;
  align-items: center;
  gap: calc(10 * var(--s, 1px)) 1.6ch;
  max-inline-size: 100%;
  font-size: calc(14 * var(--s, 1px));
  text-align: start;
}
.rp-hand {
  display: contents;
  color: var(--ink-muted);
}
.rp-hand-name {
  min-inline-size: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: end;
}
.rp-hand--you .rp-hand-name { font-weight: 600; }
.rp-hand-cards {
  display: inline-flex;
  gap: calc(4 * var(--s, 1px));
}
.rp-hand-what {
  min-inline-size: 0;
  text-wrap: pretty;
}
/* The hand that took the round: in ink and weight, and says so in green. */
.rp-hand--won { color: var(--ink); }
.rp-hand--won .rp-hand-made { font-weight: 500; }
.rp-hand-tag {
  display: block;
  color: var(--green);
  font-weight: 500;
}
.rp-hand-late { display: block; }

/* ---- The kinds of hand, for reference: shut until asked for --------------------- */
.rp-kinds {
  inline-size: min(100%, 30rem);
  margin-block-start: calc(6 * var(--s, 1px));
}
.rp-kinds-sum {
  display: inline-block;
  list-style: none;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--underline);
  text-underline-offset: calc(4 * var(--s, 1px));
  -webkit-tap-highlight-color: transparent;
}
.rp-kinds-sum::-webkit-details-marker { display: none; }
@media (hover: hover) and (pointer: fine) {
  .rp-kinds-sum:hover { color: var(--pink-text); text-decoration-color: var(--pink); }
}
/* One row a kind: the five cards, then its name over what it is. */
.rp-kinds-list {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  gap: calc(8 * var(--s, 1px)) 1.6ch;
  margin-block-start: calc(14 * var(--s, 1px));
  text-align: start;
}
.rp-kind { display: contents; }
.rp-kind-cards {
  display: inline-flex;
  gap: calc(3 * var(--s, 1px));
}
.rp-kind-text {
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
  font-size: calc(14 * var(--s, 1px));
  line-height: 1.35;
}
.rp-kind-name { font-weight: 500; }
.rp-kinds-notes {
  margin-block-start: calc(14 * var(--s, 1px));
  text-align: start;
  line-height: 1.6;
  text-wrap: pretty;
}

/* ---- Phones ------------------------------------------------------------------
   The same picture, drawn closer: a phone's window is about 660px tall, and the round has to stand
   in it. The shared cards are a size smaller than the board's, the two lines on top a little lower,
   the spaces tighter. With that a board of four rows keeps its full 64px cards on a 390 by 664
   window, and 45px ones on the shortest phone there is (375 by 553). */
@media (max-width: 600px) {
  .rp {
    --step: 10px;
    --shared: 0.8;
    --fixed: 238px;
  }
  .rp-what {
    min-block-size: 22px;
    line-height: 22px;
  }
  .rp-clock {
    block-size: 28px;
    font-size: 28px;
  }
  .rp-clock--words { font-size: 13px; }
  /* The five cards a size smaller, so a kind's name still has its column beside them. */
  .rp-kind-cards .rp-face--small { padding: 2px 3px; }
  .rp-kind-cards .rp-face--small .rp-rank { font-size: 13px; }
  .rp-kind-cards .rp-face--small .rp-suit { inline-size: 10px; block-size: 10px; }
  .rp-kinds-list { column-gap: 1ch; }
}

@media (forced-colors: active) {
  .rp-card--down { border-style: double; border-width: 3px; }
}
