/* Partie : tuiles de compteurs, dispositions, salon, tirage, fin. */

/* ---------- Couleur d'accent par joueur ---------- */
.tile[data-pid="p1"] { --accent: #d9b26a; }
.tile[data-pid="p2"] { --accent: #6fa3c9; }
.tile[data-pid="p3"] { --accent: #c96f7a; }
.tile[data-pid="p4"] { --accent: #79b48a; }

/* ---------- Tuile ---------- */

.tile {
  position: relative;
  container-type: size;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  background:
    radial-gradient(ellipse at 50% 40%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%),
    var(--surface);
  user-select: none;
  -webkit-user-select: none;
}

.tile-inner {
  position: absolute;
  inset: 0;
  container-type: size;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
}

/* Rotation vers le joueur (mode un seul téléphone) */
.tile[data-rot="180"] .tile-inner { transform: rotate(180deg); }
.tile[data-rot="90"] .tile-inner,
.tile[data-rot="270"] .tile-inner {
  inset: auto;
  top: 50%;
  left: 50%;
  width: 100cqh;
  height: 100cqw;
}
.tile[data-rot="90"] .tile-inner { transform: translate(-50%, -50%) rotate(90deg); }
.tile[data-rot="270"] .tile-inner { transform: translate(-50%, -50%) rotate(-90deg); }

.tile-head {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  pointer-events: none;
  font-family: var(--font-title);
  font-size: clamp(0.9rem, 7cqh, 1.4rem);
}
.tile-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { font-family: var(--font-body); font-size: 0.7rem; font-weight: 700; padding: 2px 6px; border-radius: 6px; }
.badge-first { background: var(--accent); color: #1a1410; }

.presence { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); opacity: 0.6; flex: 0 0 auto; }
.presence.on { background: var(--green); opacity: 1; box-shadow: 0 0 6px var(--green); }

.life {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-family: var(--font-num);
  font-weight: 700;
  font-variant-numeric: tabular-nums lining-nums;
  font-size: min(46cqh, 34cqw);
  line-height: 1;
  color: var(--text);
  text-shadow: 0 2px 16px color-mix(in srgb, var(--accent) 50%, transparent);
}

/* Zones tactiles : moitié gauche = −1, moitié droite = +1 */
.tap {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  border: 0;
  background: transparent;
  z-index: 1;
  display: flex;
  align-items: center;
  font-size: min(16cqh, 12cqw);
  color: color-mix(in srgb, var(--text) 35%, transparent);
  transition: background 0.12s;
}
.tap-minus { left: 0; justify-content: flex-start; padding-left: 6%; }
.tap-plus { right: 0; justify-content: flex-end; padding-right: 6%; }
.tap:active { background: color-mix(in srgb, var(--accent) 18%, transparent); }

.tile-foot {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tile-foot .btn-small { min-width: 54px; }

.chip-poison { min-height: 38px; min-width: 0; padding: 4px 12px; font-size: 0.95rem; color: var(--muted); }
.chip-poison.static { display: inline-flex; align-items: center; }
.tile.has-poison .chip-poison { color: var(--green); border-color: var(--green); }
.tile.poison-danger .chip-poison { color: var(--red); border-color: var(--red); }
.tile:not(.has-poison) .chip-poison.static { visibility: hidden; }

/* Mode poison : le grand nombre et les zones tactiles passent sur le poison */
.mode-label {
  position: absolute;
  top: 24%;
  z-index: 2;
  display: none;
  color: var(--green);
  font-weight: 700;
  font-size: min(7cqh, 5.5cqw);
  letter-spacing: 0.04em;
  pointer-events: none;
}
.tile.mode-poison { border-color: var(--green); }
.tile.mode-poison .mode-label { display: block; }
.tile.mode-poison .life { color: var(--green); text-shadow: 0 2px 16px color-mix(in srgb, var(--green) 50%, transparent); }
.tile.mode-poison .step5 { visibility: hidden; }
.tile.mode-poison .chip-poison { background: var(--green); color: #0f1a12; border-color: var(--green); }
.tile.mode-poison .bubble { display: none; }

/* Bulle de cumul : « −3 » */
.bubble {
  position: absolute;
  z-index: 2;
  top: 18%;
  left: 50%;
  transform: translate(-50%, 6px);
  opacity: 0;
  pointer-events: none;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: min(14cqh, 10cqw);
  transition: opacity 0.15s, transform 0.15s;
}
.bubble.show { opacity: 1; transform: translate(-50%, 0); }
.bubble.neg { color: var(--red); }
.bubble.pos { color: var(--green); }

.tile-status {
  position: absolute;
  bottom: 30%;
  font-weight: 700;
  color: var(--red);
  letter-spacing: 0.05em;
  pointer-events: none;
  z-index: 2;
}
.tile.eliminated { filter: grayscale(0.7); }
.tile.eliminated .life { opacity: 0.55; }

/* ---------- Petites tuiles (compteurs des autres) ---------- */

.tile-compact {
  flex: 1 1 0;
  min-width: 0;
  height: 104px;
}
.tile-compact .tile-inner { padding: 6px; }
.tile-compact .tile-head { font-size: 0.85rem; }
.tile-compact .life { font-size: min(44cqh, 30cqw); }
.tile-compact .tile-foot { transform: scale(0.8); transform-origin: bottom; }
.tile-compact .bubble { top: 6%; left: auto; right: 8px; transform: none; font-size: 1rem; }

/* ---------- Multi-téléphones ---------- */

.play-online .others { display: flex; gap: 8px; padding: 8px; }
.play-online .mine { flex: 1; display: flex; flex-direction: column; gap: 8px; padding: 0 8px 8px; min-height: 0; }
.play-online .mine .tile { flex: 1 1 0; min-height: 0; }
.play-online .mine.empty { padding: 24px; }

/* Sur grand écran / paysage : compteurs côte à côte */
@media (min-aspect-ratio: 1/1) {
  .play-online .mine { flex-direction: row; }
}

/* ---------- Un seul téléphone ---------- */

.play-solo { max-width: none; position: relative; }
.solo-grid { flex: 1; display: grid; gap: 6px; padding: 6px; min-height: 0; }
/* À 2 et 3 joueurs, un espace central accueille les boutons outils sans masquer les noms */
.players-2 .solo-grid { grid-template: "t" 1fr "b" 1fr / 1fr; row-gap: 62px; }
.players-3 .solo-grid { grid-template: "t t" 1fr "l r" 1.4fr / 1fr 1fr; row-gap: 62px; }
.players-4 .solo-grid { grid-template: "l2 r1" 1fr "l1 r2" 1fr / 1fr 1fr; }

/* Sur écran large (PC, tablette en paysage) : tuiles à plat, en ligne */
@media (min-aspect-ratio: 4/3) {
  .play-solo .solo-grid { grid-template: none !important; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; padding-bottom: 72px; }
  .play-solo .tile { grid-area: auto !important; }
  .play-solo .tile .tile-inner { inset: 0 !important; width: auto !important; height: auto !important; transform: none !important; }
}

/* Boutons outils au centre de la table */
.hub {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  display: flex;
  gap: 6px;
  padding: 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.hub .icon-btn { border-radius: 50%; width: 42px; height: 42px; }
/* Centre de l'espace entre les rangées 1fr / 1,4fr (marges de 6 px, espace de 62 px) */
.players-3 .hub { top: calc(6px + (100% - 12px - 62px) / 2.4 + 31px); }
@media (min-aspect-ratio: 4/3) {
  .players-3 .hub { top: auto; bottom: 12px; transform: translateX(-50%); }
  .play-solo .hub { top: auto; bottom: 12px; transform: translateX(-50%); }
}

/* ---------- Salon ---------- */

.invite { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.invite-text { flex: 1; text-align: center; }
.invite-text p { margin: 0; }
.invite .qr { width: 132px; flex: 0 0 132px; }
.qr { background: #fff; border-radius: 10px; padding: 6px; line-height: 0; }
.qr svg { width: 100%; height: auto; }

.seat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.seat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}
.seat-mine { border-color: var(--gold); }
.seat-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.seat-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.lobby-footer { padding: 12px 16px; border-top: 1px solid var(--border); }
.lobby-footer p { margin: 0 0 8px; }

@media (max-width: 380px) {
  .invite { flex-direction: column; }
}

/* ---------- Tirage ---------- */

.roll-round {
  margin: 12px 0;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  animation: fade-in 0.4s both;
}
.roll-round h3 { margin: 0 0 8px; font-size: 0.95rem; color: var(--muted); }
.roll-round ul { list-style: none; margin: 0; padding: 0; }
.roll-round li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; }
.roll-round li.top { color: var(--gold); font-weight: 700; }
.die {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 10px;
  border: 2px solid currentColor;
  font-family: var(--font-num);
  font-size: 1.3rem;
  font-weight: 700;
  animation: die-pop 0.45s both;
}
.roll-decision { margin-top: 18px; }

@keyframes fade-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes die-pop {
  0% { opacity: 0; transform: rotate(-90deg) scale(0.4); }
  70% { transform: rotate(8deg) scale(1.08); }
  100% { opacity: 1; transform: none; }
}

/* ---------- Fin de partie ---------- */

.winner { color: var(--gold); font-size: 1.8rem; }
.standings { list-style: none; margin: 18px 0; padding: 0; }
.standings li {
  display: flex;
  justify-content: space-between;
  padding: 12px 14px;
  margin-bottom: 6px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.standings li.win { border-color: var(--gold); color: var(--gold); font-weight: 700; }
.standing-life { font-variant-numeric: tabular-nums; }
