/* Shared card-table layout and playing-card styling */

.game-root {
  min-height: 26rem; /* reserved before the script draws the table */
}

.board {
  --cols: 7;
  --gap: clamp(0.25rem, 1.4cqw, 0.9rem);
  --card-min: 2.2rem;
  --card-max: 5.8rem;
  --card-w: clamp(var(--card-min), calc((100cqw - var(--gap) * (var(--cols) - 1)) / var(--cols)), var(--card-max));
  --card-h: calc(var(--card-w) * 1.4);
  --radius: calc(var(--card-w) * 0.07);
  display: flex;
  flex-direction: column;
  gap: calc(var(--card-h) * 0.2);
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.4rem 0 0.6rem;
}

.board--8 { --cols: 8; }
.board--10 { --cols: 10; --card-min: 1.85rem; --gap: clamp(0.12rem, 0.7cqw, 0.9rem); }

.row {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--card-w));
  column-gap: var(--gap);
  justify-content: center;
  align-items: start;
  min-width: min-content;
}

/* Tableau: constant height (set per game), columns stretch to full height
   so the whole column is a generous drop target. */
.row--tableau {
  align-items: stretch;
  min-height: calc(var(--card-h) * (1 + var(--max-stack, 2.6)));
}

/* ---------- cards ---------- */

.playing-card {
  position: relative;
  width: var(--card-w, 5rem);
  height: var(--card-h, 7rem);
  border-radius: var(--radius, 0.4rem);
  background: #fffdf7;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.3), 0 2px 7px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  flex-shrink: 0;
}

.playing-card svg {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.playing-card:focus-visible {
  outline: 3px solid #f0cf6a;
  outline-offset: 2px;
}

@media (hover: hover) {
  .playing-card:not(.playing-card--back):hover {
    transform: translateY(-2px);
  }
}

.playing-card.is-selected {
  transform: translateY(-5px);
  box-shadow: 0 0 0 3px #f0cf6a, 0 8px 16px rgba(0, 0, 0, 0.45);
  z-index: 5;
}

.playing-card.is-hint {
  animation: hint-pulse 1s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%, 100% { box-shadow: 0 0 0 3px #8fe0bc, 0 2px 7px rgba(0, 0, 0, 0.3); }
  50% { box-shadow: 0 0 0 6px rgba(143, 224, 188, 0.55), 0 2px 7px rgba(0, 0, 0, 0.3); }
}

/* Card back: navy with a fine lattice, cream margin and a centre lozenge */
.playing-card--back,
.playing-card.is-dealing {
  background-color: #20406b;
  background-image:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.13) 0 1px, transparent 1px calc(var(--card-w) * 0.1)),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.13) 0 1px, transparent 1px calc(var(--card-w) * 0.1));
  border: calc(var(--card-w) * 0.05) solid #fffdf7;
  box-sizing: border-box;
  cursor: default;
}

.playing-card--back::before,
.playing-card.is-dealing::before {
  content: "";
  position: absolute;
  inset: 5%;
  border: 1px solid rgba(240, 222, 168, 0.75);
  border-radius: calc(var(--radius) * 0.6);
}

.playing-card--back::after,
.playing-card.is-dealing::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%) rotate(45deg);
  border: 1px solid rgba(240, 222, 168, 0.85);
  background: rgba(240, 222, 168, 0.14);
}

.playing-card.is-dealing svg { visibility: hidden; }

/* ---------- piles & slots ---------- */

.pile {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
}

.pile > .playing-card {
  position: absolute;
  left: 0;
  top: 0;
}

.pile--slot,
.pile--empty {
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.13);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.16);
}

.pile--slot::after,
.pile--empty::after {
  content: attr(data-ghost);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: Georgia, serif;
  font-size: calc(var(--card-w) * 0.5);
  color: rgba(255, 255, 255, 0.2);
  pointer-events: none;
}

.pile--slot.ghost-red::after { color: rgba(255, 160, 150, 0.28); }

/* ::after paints above children, so hide the ghost as soon as a card is here */
.pile--slot:has(> .playing-card)::after,
.pile--empty:has(> .playing-card)::after {
  content: none;
}

.pile--slot:has(> .playing-card),
.pile--empty:has(> .playing-card) {
  background: transparent;
  box-shadow: none;
}

.pile-column {
  height: auto;
  min-height: var(--card-h);
}

.row--tableau > .pile-column.pile--empty {
  /* the column stays full height (drop area); only the top slot is drawn */
  background: none;
  box-shadow: none;
}

.row--tableau > .pile-column.pile--empty::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: var(--card-h);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.13);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.16);
}

.row--tableau > .pile-column.pile--empty::after {
  inset: auto;
  left: 0;
  top: 0;
  width: 100%;
  height: var(--card-h);
}

.pile--hint {
  animation: hint-pulse 1s ease-in-out infinite;
  border-radius: var(--radius);
}

.pile-count {
  position: absolute;
  right: 4%;
  bottom: 4%;
  min-width: 1.6em;
  padding: 0 0.4em;
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.92);
  color: #20406b;
  font: 700 0.8rem/1.6 system-ui, sans-serif;
  text-align: center;
  z-index: 4;
  pointer-events: none;
}

/* Waste fan for draw-3 */
.pile--waste .playing-card:nth-child(2) { left: calc(var(--card-w) * 0.22); }
.pile--waste .playing-card:nth-child(3) { left: calc(var(--card-w) * 0.44); }

/* ---------- drag & drop ---------- */

.playing-card.is-draggable {
  touch-action: none;
  cursor: grab;
}

.playing-card.is-lifted {
  opacity: 0;
}

.drag-layer {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 200;
  pointer-events: none;
  will-change: transform;
}

.drag-layer .playing-card {
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: none;
  transform: none;
}

body.is-dragging-cards,
body.is-dragging-cards * {
  cursor: grabbing !important;
  user-select: none;
  -webkit-user-select: none;
}

.pile.drop-hover {
  border-radius: var(--radius);
  box-shadow: inset 0 0 0 3px #f0cf6a, 0 0 18px rgba(240, 207, 106, 0.35);
  background-color: rgba(240, 207, 106, 0.1);
}

@media (hover: hover) {
  .playing-card.is-draggable:hover { cursor: grab; }
}
