:root {
  --bg: #f7f5fa;
  --surface: #ffffff;
  --text: #2b2438;
  --muted: #6e6680;
  --border: #e4e0eb;
  --primary: #4e4164;        /* violet : boutons, cartes, texte fort */
  --primary-dark: #3b3050;
  --primary-soft: #ebe7f1;
  --accent: #84cac5;         /* turquoise : table, mises en avant (jamais en texte) */
  --accent-soft: #dcf0ee;
  --accent-text: #2e7570;    /* turquoise assez foncé pour être lisible en texte */
  --danger: #c0392b;
  --radius: 12px;
  --card-w: 46px;
  --card-h: 74px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

button, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }

/* ---------- Boutons & champs ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 22px;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-size: 1rem;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.5; }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-outline { background: var(--surface); color: var(--primary); border: 2px solid var(--primary); }
.btn-outline:hover { background: var(--primary-soft); }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; text-align: left; }
.field > label { font-weight: 600; font-size: 0.9rem; }
.field input[type="text"],
.field input[type="password"],
.select {
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.field input:focus, .select:focus { outline: none; border-color: var(--primary); }

.error { color: var(--danger); font-size: 0.9rem; margin-bottom: 12px; min-height: 1.2em; }
.hint { color: var(--muted); font-weight: 600; }

/* ---------- Accueil ---------- */

.home {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.panel {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(78, 65, 100, 0.1);
  padding: 36px 28px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.logo { font-size: 3rem; margin-bottom: 8px; }
.panel h1 { font-size: 1.6rem; margin-bottom: 6px; color: var(--primary); }
.panel .subtitle { color: var(--muted); margin-bottom: 24px; }
.panel .footer-link { margin-top: 18px; font-size: 0.85rem; }

/* ---------- Page table : structure ---------- */
/* Colonne : en-tête / plateau (s'étire) / paquet collé en bas, sans superposition */

.room-page {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 14px 24px;
  flex-wrap: wrap;
}
.topbar h1 {
  font-size: 1.25rem;
  color: var(--primary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.me-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 600;
  color: var(--text);
  max-width: 200px;
}
.me-chip:hover { border-color: var(--primary); }
.me-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  flex: none;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700;
}

.connection-banner {
  background: #fdf2d0;
  color: #7a5a00;
  text-align: center;
  padding: 8px;
  font-size: 0.9rem;
}

.board {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 8px 16px 24px;
}

.observers { color: var(--muted); font-size: 0.9rem; text-align: center; }
.lonely { text-align: center; }
.lonely .btn-ghost { font-weight: 700; padding: 4px 10px; }

/* ---------- Plateau : sièges autour de la table (écrans larges) ---------- */

.seats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px 24px;
  width: 100%;
  max-width: 1000px;
}
.seats:empty { display: none; }

.table-center {
  width: 100%;
  max-width: 360px;
  min-height: 140px;
  border-radius: 28px;
  background: var(--accent-soft);
  border: 2px solid var(--accent);
  box-shadow: 0 0 28px rgba(132, 202, 197, 0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
}

.seat { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 76px; }
.seat-name {
  font-weight: 700;
  font-size: 0.9rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.seat.offline { opacity: 0.45; }
.seat.is-me .seat-name { color: var(--accent-text); }

.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  perspective: 600px;
}
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s ease;
  transform-style: preserve-3d;
}
.card.face-up .card-inner { transform: rotateY(180deg); }
.card-front, .card-back {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-back {
  background-color: var(--primary);
  background-image:
    repeating-linear-gradient(45deg, rgba(132, 202, 197, 0.45) 0 5px, transparent 5px 11px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.12) 0 5px, transparent 5px 11px);
}
.card-front {
  transform: rotateY(180deg);
  background: var(--surface);
  border: 2px solid var(--primary);
  color: var(--primary);
  font-weight: 800;
  font-size: 1.2rem;
}
.card.empty .card-back { background: #e4e0eb; background-image: none; }
.card.empty.face-up .card-front { border-color: #d3cddd; color: #a39cb0; }

/* ---------- Plateau : liste simple (écrans étroits) ---------- */

.player-list {
  list-style: none;
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.player-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
}
.player-list li + li { border-top: 1px solid var(--border); }
.player-list .name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-list li.is-me .name { color: var(--accent-text); }
.player-list li.offline { opacity: 0.5; }
.status {
  flex: none;
  min-width: 40px;
  padding: 3px 10px;
  border-radius: 999px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--bg);
  color: var(--muted);
}
.status.voted { background: var(--accent-soft); color: var(--accent-text); }
.status.value { background: var(--primary); color: #fff; font-size: 1rem; }

/* ---------- Résultats ---------- */

.results { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; }

/* Min | Moyenne | Max : la moyenne est mise en avant, min et max sont indicatifs */
.stats { display: flex; gap: 12px; align-items: center; justify-content: center; }
.stat { text-align: center; color: var(--muted); min-width: 56px; }
.stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 1.2rem; font-weight: 700; }
.stat.main {
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 26px;
  color: var(--text);
}
.stat.main .stat-value { font-size: 2.4rem; font-weight: 800; color: var(--primary); line-height: 1.1; }

/* Répartition : combien de personnes par carte */
.distribution { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.dist-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.dist-card {
  width: 34px; height: 52px;
  border-radius: 6px;
  border: 2px solid var(--primary);
  color: var(--primary);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
}
.dist-item.top .dist-card { background: var(--primary); color: #fff; }
.dist-count { font-size: 0.8rem; color: var(--muted); font-weight: 600; }

.consensus-banner {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--accent-text);
  animation: pop 0.6s cubic-bezier(.2, 1.6, .4, 1);
}

/* ---------- Paquet de cartes : dans le flux, collé en bas ---------- */

.deck-area {
  position: sticky;
  bottom: 0;
  z-index: 10;
  background: var(--bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 20px rgba(78, 65, 100, 0.06);
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  text-align: center;
}
.deck-area p { margin-bottom: 10px; font-size: 0.95rem; }
.deck {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  max-width: 900px;
  margin: 0 auto;
}
.deck-card {
  width: 48px;
  height: 72px;
  border-radius: 8px;
  border: 2px solid var(--primary);
  background: var(--surface);
  color: var(--primary);
  font-weight: 800;
  font-size: 1.1rem;
  transition: transform 0.15s, background 0.15s, color 0.15s;
}
.deck-card:hover:not(:disabled) { transform: translateY(-4px); background: var(--primary-soft); }
.deck-card.selected,
.deck-card.selected:hover:not(:disabled) {
  background: var(--primary);
  color: #fff;
  transform: translateY(-6px);
  box-shadow: 0 4px 0 var(--accent);
}
.deck-card:disabled { opacity: 0.4; }

.deck-select { display: none; max-width: 320px; margin: 0 auto; }
.deck-area.collapsed p { margin-bottom: 0; color: var(--muted); }
.deck-area.collapsed .deck,
.deck-area.collapsed .deck-select { display: none; }

/* ---------- Modale & toast ---------- */

.modal {
  position: fixed; inset: 0;
  background: rgba(43, 36, 56, 0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 50;
  overflow-y: auto;
}
.modal .panel { max-width: 380px; margin: auto; }

.role-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.role-option { position: relative; }
.role-option input { position: absolute; opacity: 0; }
.role-option span {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px 8px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  height: 100%;
}
.role-option small { font-weight: 400; color: var(--muted); font-size: 0.8rem; }
.role-option input:checked + span { border-color: var(--primary); background: var(--primary-soft); }
.role-option input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

.toast {
  position: fixed;
  top: 20px; left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--primary);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 600;
  z-index: 60;
  animation: fade-in 0.2s;
}

/* ---------- Animation d'unanimité ---------- */

.confetti-layer { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 40; }
.confetti {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 14px;
  animation: confetti-fall linear forwards;
}
.seat.celebrate .card { animation: bounce 0.6s ease 0.5s 2; }

@keyframes confetti-fall { to { transform: translate(var(--drift), 105vh) rotate(var(--spin)); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }
@keyframes pop { 0% { transform: scale(0.3); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Responsive ---------- */

/* Tablette / petit portable : la table devient une liste, cartes de vote plus compactes */
@media (max-width: 700px) {
  .topbar { padding: 12px 16px; }
  .seats { display: none; }
  .table-center { min-height: 0; border-radius: 20px; padding: 16px; }
  .deck { gap: 6px; }
  .deck-card { width: 42px; height: 60px; font-size: 1rem; }
}
@media (min-width: 701px) {
  .player-list { display: none; }
}

/* Téléphone : les cartes de vote deviennent une liste déroulante */
@media (max-width: 480px) {
  .topbar { padding: 10px 12px; }
  .topbar h1 { font-size: 1.1rem; flex: 1; }
  .topbar .btn-outline { padding: 8px 12px; }
  .me-chip { padding: 6px 10px; max-width: 130px; }
  .deck { display: none; }
  .deck-select { display: block; }
  .stats { gap: 8px; }
  .stat.main { padding: 8px 18px; }
  .stat.main .stat-value { font-size: 2rem; }
}

/* Très petit téléphone : le nom de la table passe sur sa propre ligne */
@media (max-width: 360px) {
  .topbar h1 { flex-basis: 100%; }
  .topbar-actions { margin-left: 0; width: 100%; justify-content: space-between; }
}
