/* Donut Cards. Colours come from the shared :root variables in style.css. */

/* a card table wants the whole window, not the shell's narrow column */
main:has(.sw) {
  max-width: 1400px;
  padding-top: 10px;
  padding-bottom: 12px;
}

main:has(.sw) .game-actions {
  margin-top: 10px;
}

/* Sizes follow the window's width and height, so the table fills a phone, half a screen
   or a whole monitor. Text sizes are in em, so they follow the font size set here. */
.sw {
  --card-w: clamp(60px, min(12vw, 12vh), 120px); /* cards in your hand */
  --table-card: min(calc(var(--card-w) * 1.6), 24vw); /* the pile and the discards */
  --felt: #2a1a3d;
  --red-suit: #ff6b81;
  --turn: #ff9a3c; /* outlines whoever's turn it is, and faded, whoever goes after them */
  display: flex;
  flex-direction: column;
  gap: 0.7em;
  margin: 0 auto;
  font-size: clamp(16px, min(2.4vw, 2.2vh), 24px);
}

.sw .btn {
  font-size: 1em;
  padding: 0.55em 1.4em;
}

.sw img {
  display: block;
  user-select: none;
}

/* players */

.sw-players {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5em;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sw-player {
  display: flex;
  align-items: center;
  gap: 0.5em;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 0.25em 0.8em;
  font-weight: 600;
  transition: border-color 0.2s;
}

.sw-player.active {
  border-color: var(--turn);
  box-shadow: 0 0 0 1px var(--turn);
}

.sw-player.next {
  border-color: color-mix(in srgb, var(--turn) 40%, transparent);
}

.sw-player.gone {
  opacity: 0.5;
}

.sw-player.out {
  border-style: dashed;
}

.sw-place {
  color: var(--warn);
}

.sw-name {
  max-width: 10em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sw-count {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
}

.sw-count img {
  width: 0.8em;
}

/* table */

/* the pick-up pile and the played cards side by side in the middle, on felt just big enough
   for them. Older played cards fan out to the left, at most 3 x 0.16 of a card plus the
   corner of the last one turned 12 degrees, so the gap leaves room for that. */
.sw-table {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: calc(var(--table-card) * 0.7);
  width: fit-content;
  margin: 0 auto;
  box-sizing: border-box;
  background: var(--felt);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1em 1.5em;
}

@media (max-width: 560px) {
  .sw-table {
    padding: 0.75em;
  }
}

.sw-pile {
  position: relative;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: 6px;
}

.sw-pile:disabled {
  cursor: default;
}

.sw-pile:not(:disabled):hover img {
  transform: translateY(-3px);
}

.sw-pile img,
.sw-discard img {
  width: var(--table-card);
  border-radius: 6px;
  box-shadow: 2px 3px 0 rgb(0 0 0 / 0.35);
  transition: transform 0.15s;
}

/* how many cards are left, big in the middle of the deck */
.sw-pile span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  min-width: 1.7em;
  padding: 0.05em 0.3em;
  border-radius: 999px;
  background: rgb(20 11 28 / 0.85);
  border: 2px solid var(--line);
  color: var(--text);
  font-size: calc(var(--table-card) * 0.26);
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
}

.sw-discard {
  position: relative;
  width: var(--table-card);
  height: calc(var(--table-card) * 1.4);
}

/* the top card fills the box, so it sits in the middle; older ones peek out to its left */
.sw-discard img {
  position: absolute;
  top: 0;
  left: 0;
  transform: translateX(calc(var(--i) * var(--table-card) * 0.16)) rotate(calc(var(--i) * 4deg));
}

.sw-suit-btn img {
  width: 1.4em;
  height: 1.4em;
  image-rendering: pixelated;
  display: block;
}

.suit-H,
.suit-D {
  color: var(--red-suit);
}

/* status and log */

.sw-status {
  margin: 0;
  text-align: center;
  font-weight: 600;
  font-size: 1.2em;
}

.sw-log {
  margin: 0;
  padding: 0;
  list-style: none;
  text-align: center;
  font-size: 0.85em;
  max-height: 4.4em;
  overflow: hidden;
}

.sw-log li:first-child {
  color: var(--text);
}

/* a suit in the status or log, drawn as its donut, in the line of text (not a block like
   card images) */
.sw-status img.sw-pip,
.sw-log img.sw-pip {
  display: inline;
  width: 1.15em;
  height: 1.15em;
  margin-left: 0.05em;
  vertical-align: -0.25em;
  image-rendering: pixelated;
}

/* controls */

.sw-suits {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
}

.sw-suit-btn {
  width: 2.2em;
  height: 2.2em;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--surface);
  font-size: 1.3em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.sw-suit-btn.chosen {
  border-color: var(--pink);
  background: var(--surface-2);
}

.sw-controls {
  display: flex;
  justify-content: center;
  gap: 0.5em;
}

.sw .sw-call {
  background: #e0334f;
  border-color: #e0334f;
  color: #fff;
  font-weight: 700;
}

.sw .sw-call:hover:not(:disabled) {
  background: #c22640;
}

/* a player who has called cards and may go out on their next go */
.sw-called {
  background: #e0334f;
  color: #fff;
  font-size: 0.75em;
  font-weight: 700;
  padding: 0.1em 0.45em;
  border-radius: 999px;
  white-space: nowrap;
}

/* hand */

.sw-hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(6px, 0.8vw, 14px);
  padding-top: calc(var(--card-w) * 0.2); /* room for picked cards to lift */
}

.sw-card {
  position: relative;
  padding: 0;
  border: 0;
  background: none;
  border-radius: 5px;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.sw-card img {
  width: var(--card-w);
  border-radius: 6px;
  box-shadow: 1px 2px 0 rgb(0 0 0 / 0.35);
}

.sw-card:disabled {
  cursor: default;
}

.sw-card:not(:disabled, .dim):hover {
  transform: translateY(-4px);
}

.sw-card.selected {
  transform: translateY(calc(var(--card-w) * -0.18));
  outline: 3px solid var(--pink);
}

.sw-card.dim {
  opacity: 0.45;
  cursor: not-allowed;
}

.sw-order {
  position: absolute;
  top: -0.5em;
  right: -0.5em;
  width: 1.6em;
  height: 1.6em;
  border-radius: 50%;
  background: var(--pink);
  color: #fff;
  font-size: 0.8em;
  line-height: 1.6em;
  text-align: center;
}

.busy .sw-card,
.busy .sw-pile,
.busy .btn {
  pointer-events: none;
}

/* settings preview: the starting hand */

.sw-preview {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}

.sw-preview img {
  width: 40px;
  margin-left: -16px;
  border-radius: 3px;
  box-shadow: 1px 1px 0 rgb(0 0 0 / 0.35);
}

.sw-preview img:first-child {
  margin-left: 0;
}
