/* Card game layout — tableau + stock/waste/foundations + fanned stacks.
   TV-first sizes with the measure-and-fit fallback the screen uses.
   All sizing uses theme tokens; the screen measures to fit.

   Wave 1B: wide-layout classes for 8-column (FreeCell) and 10-column
   (Spider) tableaus, plus a cells row class.

   Wave 2: GRID layout for Pyramid / TriPeaks. Cards are placed grid-cell
   by grid-cell; the pileLayoutGrid on the spec maps pile cards to
   specific rows/cols so peak geometry and pyramid rows render as data,
   not renderer code. Row gap is placed on the grid container so rows
   overlap vertically by ~half a card. */

.card-board {
  --card-w: 78px;
  --card-h: 108px;
  --card-gap: 10px;
  --fan-step: 26px;
  position: relative;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: var(--card-gap);
  user-select: none;
  touch-action: manipulation;
}

.card-board.card-board--cols8 {
  --card-w: 92px;
  --card-h: 128px;
  --card-gap: 6px;
  --fan-step: 20px;
  max-width: 960px;
}
.card-board.card-board--cols10 {
  --card-w: 76px;
  --card-h: 106px;
  --card-gap: 4px;
  --fan-step: 16px;
  max-width: 960px;
}

.card-board__top {
  display: flex;
  gap: var(--card-gap);
  margin-bottom: var(--card-gap);
  align-items: flex-start;
}
.card-board__spacer { flex: 1; }
.card-board__cells {
  display: flex;
  gap: var(--card-gap);
  align-items: flex-start;
}

.card-board__tableau {
  display: flex;
  gap: var(--card-gap);
  align-items: flex-start;
}
.card-board__column {
  position: relative;
  flex: 1 1 0;
  min-width: var(--card-w);
  min-height: var(--card-h);
}

.card-pile {
  position: relative;
  width: var(--card-w);
  min-height: var(--card-h);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px dashed rgba(255, 255, 255, 0.18);
  touch-action: none;
  -webkit-touch-callout: none;
  z-index: 2;
}
.card-pile--foundation,
.card-pile--stock,
.card-pile--waste,
.card-pile--cell {
  flex: 0 0 auto;
}
.card-pile--cell { background: rgba(255, 255, 255, 0.08); }
.card-pile--runs { border-color: rgba(245, 197, 66, 0.45); }
.card-pile--column {
  width: 100%;
  min-height: var(--card-h);
  border-style: none;
  background: none;
  z-index: auto;
}
.card-pile__label {
  position: absolute;
  top: 4px; left: 6px;
  font-size: 0.72em;
  color: var(--fg-dim);
  pointer-events: none;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  z-index: 3;
}
.card-pile.is-focused {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.card-pile.is-dest-hint {
  box-shadow: 0 0 0 3px var(--focus), 0 0 18px rgba(245, 197, 66, 0.35);
}

.card-el {
  position: absolute;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 10px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(0, 0, 0, 0.35);
  transition: transform 0.16s ease-out, box-shadow 0.16s ease-out, outline-color 0.12s ease-out;
  will-change: transform;
  background: var(--card-bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  color: var(--card-fg);
  font-family: var(--font);
  cursor: pointer;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  z-index: 1;
}
.card-el:focus,
.card-el:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.drag-ghost {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.5));
}
.drag-ghost .card-el { transition: none; }
.card-el.is-down {
  background: var(--card-back, var(--card-bg));
  background-size: cover;
  background-position: center;
  box-shadow: inset 0 0 0 2px rgba(245, 197, 66, 0.4), 0 3px 8px rgba(0, 0, 0, 0.45);
}
.card-el.is-selected {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  transform: translateY(-6px);
  z-index: 4;
}
.card-el.is-hint-source,
.card-el.is-hint-dest {
  box-shadow: 0 0 0 3px rgba(78, 194, 122, 0.9), 0 0 12px rgba(78, 194, 122, 0.5);
}

.card-el__corner {
  position: absolute;
  top: 3px;
  left: 5px;
  font-weight: 800;
  font-size: 1.3em;
  line-height: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.card-el__corner--top-right {
  left: auto;
  right: 4px;
  top: auto;
  bottom: 2px;
  transform: rotate(180deg);
}
.card-el__rank { font-size: 1em; }
.card-el__suit { width: 1.14em; height: 1.14em; display: block; }
.card-el__suit--red { color: #b81f27; }
.card-el__suit--black { color: var(--card-fg); }
.card-el__pip {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.card-el__pip svg { width: 54%; height: 54%; }

.card-pile--column .card-el {
  top: calc(var(--fan-step) * var(--stack-index, 0));
  left: 0;
}
.card-pile--column .card-el.is-down {
  top: calc(6px * var(--stack-index, 0));
}
.card-board--cols10 .card-pile--column .card-el { top: calc(14px * var(--stack-index, 0)); }
.card-board--cols10 .card-pile--column .card-el.is-down { top: calc(6px * var(--stack-index, 0)); }

/* GRID GAMES: card-board--grid.

   The board is a CSS grid whose column count and row count are set via
   --grid-cols / --grid-rows by the screen at render time. The vertical
   row gap is set via --grid-row-gap so rows overlap by roughly half a
   card height (the screen sets it from cardH * 0.5).

   Reserve piles render their cards individually: each card carries
   data-pile + data-card-index and its OWN gridRow / gridColumn, so a
   pyramid or tripeaks row becomes a staggered fan without a pile
   wrapper. Non-reserve piles (stock/waste/removed) render as one
   .card-board__gridcell per pile. */

.card-board--grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 7), minmax(0, 1fr));
  grid-template-rows: repeat(var(--grid-rows, 7), auto);
  column-gap: var(--card-gap);
  row-gap: var(--grid-row-gap, calc(var(--card-h) * 0.5));
  align-items: start;
  justify-items: center;
  padding: var(--card-gap);
}

.card-board--grid .card-el--grid {
  position: relative;
  top: auto;
  left: auto;
  width: var(--card-w);
  height: var(--card-h);
  z-index: 2;
}

.card-board--grid .card-board__gridcell {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-width: var(--card-w);
  min-height: var(--card-h);
}

.card-board--grid .card-board__gridcell .card-pile {
  position: relative;
}

/* Pyramid: cards that are stacked directly under another pyramid card
   (its children) sit visually behind, so card z is bound to the row. */
.card-board--grid .card-el--grid[style*="grid-row: 1"] { z-index: 7; }
.card-board--grid .card-el--grid[style*="grid-row: 2"] { z-index: 6; }
.card-board--grid .card-el--grid[style*="grid-row: 3"] { z-index: 5; }
.card-board--grid .card-el--grid[style*="grid-row: 4"] { z-index: 4; }
.card-board--grid .card-el--grid[style*="grid-row: 5"] { z-index: 3; }
.card-board--grid .card-el--grid[style*="grid-row: 6"] { z-index: 2; }
.card-board--grid .card-el--grid[style*="grid-row: 7"] { z-index: 1; }

html.reduce-motion .card-el { transition-duration: 0.01ms !important; }

@media (min-width: 1200px) {
  .card-board {
    --card-w: 104px;
    --card-h: 144px;
    --card-gap: 14px;
    --fan-step: 34px;
    max-width: 1200px;
  }
  .card-board.card-board--cols8 {
    --card-w: 120px;
    --card-h: 168px;
    --card-gap: 8px;
    --fan-step: 24px;
    max-width: 1200px;
  }
  .card-board.card-board--cols10 {
    --card-w: 98px;
    --card-h: 138px;
    --card-gap: 6px;
    --fan-step: 20px;
    max-width: 1200px;
  }
}

@media (max-width: 700px) {
  .card-board { padding: 4px; }
  .card-pile__label { display: none; }
  .card-el__pip svg { width: 34%; height: 34%; }
  .card-board--grid { --grid-row-gap: calc(var(--card-h) * 0.4); padding: 4px; }
}
@media (max-height: 500px) {
  .card-pile__label { display: none; }
  .card-board--cols10 .card-pile--column .card-el { top: calc(10px * var(--stack-index, 0)); }
  .card-el__pip svg { width: 34%; height: 34%; }
  .card-board--grid { --grid-row-gap: calc(var(--card-h) * 0.35); }
}

@keyframes card-deal-in {
  from { opacity: 0; transform: translateY(-14px) scale(0.94); }
  to { opacity: 1; transform: none; }
}
.card-board.is-dealing .card-el { animation: card-deal-in 0.32s ease-out both; }

.card-pile.is-dest-hint::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 12px;
  pointer-events: none;
}

/* FLUX-ART-2026-11-17: felt lives on .game-board-wrap in game.css — the board box is shorter than the fanned columns, so painting it here left the fans hanging over the void. */
