/* ===== SCREEN 2 : PLACEMENT ===== */
#screen-placement {
  background: var(--beige);
}
.placement-layout {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  overflow: hidden;
}

.placement-header {
  background: var(--brown);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.player-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.card-counter {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--gold);
  flex-shrink: 0;
}

.btn-player-nav {
  background: rgba(255,255,255,0.12);
  border: none;
  color: var(--gold);
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  touch-action: manipulation;
  transition: background 0.15s, opacity 0.15s;
}
.btn-player-nav:active { background: rgba(255,255,255,0.22); }
.btn-player-nav:disabled { opacity: 0.2; pointer-events: none; }

.grid-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  overflow: hidden;
  min-height: 0;
  position: relative;
}

/* ===== GRILLE 5×4 ===== */
.grid-5x4 {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 4px;
  width: 100%;
  max-width: min(95vw, max(200px, calc((100vh - 300px) * 5 / 4)));
  aspect-ratio: 5/4;
}

.grid-cell {
  border-radius: 8px;
  background: rgba(255,255,255,0.5);
  border: 2px dashed #c8b89a;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  touch-action: manipulation;
  overflow: hidden;
  aspect-ratio: 1;
}
.grid-cell:active { transform: scale(0.94); }

.grid-cell.has-card {
  border: 2px solid #d4c4aa;
  cursor: default;
  background-size: cover;
  background-position: center 20%;
  background-repeat: no-repeat;
}
.grid-cell.face-down {
  border-color: var(--brown-light);
  filter: grayscale(1) brightness(0.35);
}

.cell-remove-btn {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--terracotta);
  color: #fff;
  border: none;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 2;
  padding: 0;
}
.grid-cell.has-card:hover .cell-remove-btn,
.grid-cell.has-card:focus-within .cell-remove-btn {
  display: flex;
}

/* Highlight pour sélection */
.grid-cell.selected-target {
  background: rgba(42,157,143,0.15);
  border: 2px dashed var(--teal);
}

/* ===== PALETTE ===== */
.palette-wrapper {
  background: var(--brown);
  padding: 6px 8px;
  overflow: hidden;
}

.placement-mode-hint {
  margin: 4px 0 6px;
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(255,255,255,0.6);
  line-height: 1.35;
  text-align: center;
}

.card-palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
  width: 100%;
}

.palette-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  touch-action: manipulation;
  padding: 6px 4px;
  border-radius: 10px;
  border: 2px solid transparent;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  user-select: none;
  width: 100%;
}
.palette-item:active { transform: scale(0.92); }
.palette-item.selected {
  background: rgba(233,196,106,0.25);
  border-color: var(--gold);
}

.palette-thumb {
  width: 100%;
  aspect-ratio: 3/4;
  background-size: cover;
  background-position: center 20%;
  background-repeat: no-repeat;
  border-radius: 6px;
  pointer-events: none;
}
.palette-item .palette-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--beige);
  text-align: center;
  line-height: 1.1;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette-item .palette-count {
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--gold);
}

/* Bouton reset dans le header */
.btn-player-nav.btn-reset {
  color: #e07060;
  margin-left: 2px;
}
.btn-player-nav.btn-reset:active { background: rgba(224,112,96,0.18); }

/* Bouton Valider intégré dans la palette */
.palette-item-validate {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 4px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  border-radius: 10px;
  border: 2px solid var(--teal);
  background: rgba(42,157,143,0.18);
  color: var(--teal);
  font-family: inherit;
  font-weight: 800;
  font-size: 0.7rem;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, transform 0.1s;
  width: 100%;
  text-align: center;
  line-height: 1.2;
}
.palette-item-validate:active { transform: scale(0.92); }
.palette-item-validate:disabled {
  opacity: 0.35;
  pointer-events: none;
  border-color: #888;
  color: #888;
  background: transparent;
}
.palette-item-validate .validate-icon {
  font-size: 1.4rem;
  line-height: 1;
}

/* ===== CURSEUR SÉQUENTIEL ===== */
.grid-cell.seq-cursor {
  border: 3px solid var(--gold);
  background: rgba(233,196,106,0.22);
  animation: pulse-cursor 0.85s ease-in-out infinite alternate;
}
@keyframes pulse-cursor {
  from {
    box-shadow: inset 0 0 6px rgba(233,196,106,0.25), 0 0 0 0 rgba(233,196,106,0);
  }
  to {
    box-shadow: inset 0 0 14px rgba(233,196,106,0.5), 0 0 0 6px rgba(233,196,106,0.3);
  }
}

/* ===== POSE DE CARTE ===== */
.grid-cell.cell-flying {
  opacity: 0;
}
.grid-cell.cell-just-placed {
  animation: cell-stamp 0.32s ease-out forwards;
  position: relative;
  z-index: 5;
}
@keyframes cell-stamp {
  0% {
    transform: scale(1.12);
    box-shadow: 0 0 0 4px rgba(255,255,255,0.7), 0 0 16px rgba(233,196,106,0.65);
    filter: brightness(1.3);
  }
  100% {
    transform: scale(1);
    box-shadow: none;
    filter: brightness(1);
  }
}

/* ===== RESPONSIVE AJUSTEMENTS ===== */

@media (min-width: 480px) {
  .grid-5x4 { gap: 6px; }
  .grid-cell { border-radius: 10px; }
}

@media (min-width: 540px) {
  /* Thumb plein format, label en overlay */
  .palette-item {
    position: relative;
    padding: 0;
    overflow: hidden;
    gap: 0;
    height: 72px;
  }

  .palette-item.selected {
    background: transparent;
  }

  /* Bordure de sélection via pseudo-élément (par-dessus le thumb) */
  .palette-item.selected::after {
    content: '';
    position: absolute;
    inset: 0;
    border: 3px solid var(--gold);
    border-radius: 10px;
    pointer-events: none;
    z-index: 3;
  }

  .palette-thumb {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    aspect-ratio: unset;
    border-radius: 0;
  }

  .palette-item .palette-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.72));
    padding: 14px 4px 5px;
    border-radius: 0;
    z-index: 1;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  }
}

/* ===== GRAND ÉCRAN : PALETTE LATÉRALE ===== */
@media (min-width: 820px) {

  /* 1. Layout 2D : header pleine largeur, grille + palette côte à côte */
  .placement-layout {
    grid-template-rows: auto 1fr;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "header  header"
      "grid    palette";
  }
  .placement-header { grid-area: header; }
  .grid-wrapper     { grid-area: grid; }
  .palette-wrapper  { grid-area: palette; }

  /* 2. Palette : colonne fixe 180px, flex column pour distribuer l'espace */
  .palette-wrapper {
    width: 180px;
    display: flex;
    flex-direction: column;
    padding: 8px;
    overflow: hidden;
  }

  /* 3. Mode toggle : ne se comprime pas */
  .mode-toggle-bar {
    flex-shrink: 0;
  }

  /* 4. Grille palette : 2 colonnes × 6 lignes, remplit toute la hauteur */
  .card-palette {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(6, 1fr);
    flex: 1;
    gap: 4px;
    min-height: 0;
  }

  /* 5. Items : annule le height: 72px fixe imposé par >=540px */
  .palette-item {
    height: auto;
    min-height: 0;
  }

  /* 6. Grille de jeu : contrainte par hauteur seule (palette n'est plus en bas) */
  .grid-5x4 {
    max-width: min(
      calc(100vw - 196px),
      max(200px, calc((100vh - 56px) * 5 / 4))
    );
  }
}
