/* ─── Reset & Base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --village-color: #2563eb;
  --loups-color:   #dc2626;
  --bg-dark:       #0f172a;
  --bg-card:       #1e293b;
  --bg-card2:      #263348;
  --border:        #334155;
  --text:          #e2e8f0;
  --text-muted:    #94a3b8;
  --accent:        #f59e0b;
  --success:       #22c55e;
  --danger:        #ef4444;
  --radius:        12px;
  --radius-sm:     8px;
}

html {
  /* Pas de zoom double-tap ni de délai de tap (comportement app native) */
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

/* Aucun débordement horizontal : rien ne doit dépasser de l'écran */
html, body { overflow-x: hidden; max-width: 100%; }

/* iOS zoome automatiquement sur les champs < 16px : on force 16px sur mobile */
@media (pointer: coarse) {
  input, select, textarea { font-size: 16px; }
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ─── Utilities ─────────────────────────────────────────────────── */
.hidden   { display: none !important; }
.flex     { display: flex; }
.col      { flex-direction: column; }
.gap-1    { gap: 0.5rem; }
.gap-2    { gap: 1rem; }
.gap-3    { gap: 1.5rem; }
.center   { align-items: center; justify-content: center; }
.text-center { text-align: center; }
.w-full   { width: 100%; }
.mt-1     { margin-top: 0.5rem; }
.mt-2     { margin-top: 1rem; }
.mt-3     { margin-top: 1.5rem; }

/* ─── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.6rem 1.2rem;
  border: none; border-radius: var(--radius-sm);
  font-size: 0.875rem; font-weight: 600; cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover  { opacity: 0.88; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary  { background: var(--accent);  color: #000; }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-success  { background: var(--success); color: #000; }
.btn-ghost    { background: var(--bg-card2); color: var(--text); border: 1px solid var(--border); }
.btn-wolf     { background: var(--loups-color); color: #fff; }
.btn-village  { background: var(--village-color); color: #fff; }
.btn-sm       { padding: 0.35rem 0.75rem; font-size: 0.78rem; }
.btn-lg       { padding: 0.85rem 2rem; font-size: 1rem; }

/* ─── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

/* ─── Form Elements ─────────────────────────────────────────────── */
input[type="text"], input[type="number"], select {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}
input:focus, select:focus { border-color: var(--accent); }

label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.25rem; display: block; }

/* ─── Toast notifications ───────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  z-index: 9999; max-width: 360px;
}
.toast {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  animation: slideIn 0.25s ease;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--accent); }
@keyframes slideIn { from { transform: translateX(120%); opacity:0; } to { transform: translateX(0); opacity:1; } }

/* ═══════════════════════════════════════════════════════════════════
   MASTER INTERFACE
═══════════════════════════════════════════════════════════════════ */
.master-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.master-header {
  grid-column: 1 / -1;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex; align-items: center; gap: 1rem;
}
.master-header h1 { font-size: 1.3rem; font-weight: 700; }
.master-header .badge {
  background: var(--accent);
  color: #000; font-size: 0.7rem; font-weight: 700;
  padding: 0.2rem 0.6rem; border-radius: 999px;
}
.session-code-display {
  margin-left: auto;
  font-size: 1.5rem; font-weight: 800; letter-spacing: 0.1em;
  color: var(--accent);
}

.master-sidebar {
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 1.25rem;
  display: flex; flex-direction: column; gap: 1.25rem;
  overflow-y: auto;
  min-width: 0; /* empêche la grille de déborder horizontalement */
}

.master-main {
  padding: 1.25rem;
  display: flex; flex-direction: column; gap: 1.25rem;
  overflow-y: auto;
  min-width: 0;
}

/* QR section */
.qr-section { text-align: center; }
.qr-section img { max-width: 200px; border-radius: var(--radius-sm); background: #fff; padding: 6px; }
.qr-url { font-size: 0.72rem; color: var(--text-muted); word-break: break-all; margin-top: 0.5rem; }

/* Role stats */
.role-stats { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.role-badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.3rem 0.6rem; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600;
  border: 1px solid rgba(255,255,255,0.15);
}
.role-badge.village { background: rgba(37,99,235,0.3); }
.role-badge.loups   { background: rgba(220,38,38,0.3); }

/* Phase indicator */
.phase-indicator {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.82rem; color: var(--text-muted);
}
.phase-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
}
.phase-dot.lobby { background: #94a3b8; }
.phase-dot.active { background: var(--success); animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.4; } }

/* Player list */
.player-list { display: flex; flex-direction: column; gap: 0.5rem; }

.player-item {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.9rem;
  display: flex; align-items: center; gap: 0.75rem;
}
.player-item .player-name { font-weight: 600; flex: 1; }
.player-item .player-role-info { font-size: 0.75rem; color: var(--text-muted); }
.player-item.village-camp { border-left: 3px solid var(--village-color); }
.player-item.loups-camp   { border-left: 3px solid var(--loups-color); }

.player-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }

/* Reveal panel */
.reveal-scenarios { display: flex; flex-direction: column; gap: 0.75rem; }
.reveal-scenarios h3 { font-size: 0.9rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.scenario-btn {
  width: 100%; text-align: left;
  background: var(--bg-card2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.65rem 1rem;
  cursor: pointer; font-size: 0.85rem; color: var(--text);
  display: flex; align-items: center; gap: 0.5rem;
  transition: background 0.15s, border-color 0.15s;
}
.scenario-btn:hover { background: var(--border); border-color: var(--accent); }
.scenario-btn.wolf-scenario { border-left: 3px solid var(--loups-color); }
.scenario-btn.village-scenario { border-left: 3px solid var(--village-color); }

/* Distribution modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem; max-width: 480px; width: 100%;
  max-height: 90vh; overflow-y: auto;
}
.modal h2 { font-size: 1.1rem; margin-bottom: 1rem; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.modal-row { display: flex; flex-direction: column; gap: 0.25rem; }
.modal-footer { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1.25rem; }

/* Eliminated players */
.player-item.eliminated { opacity: 0.45; }
.player-item.eliminated .player-name { text-decoration: line-through; }

/* Grayed-out scenario buttons & tools (role holders eliminated) */
.scenario-btn:disabled {
  opacity: 0.4;
  filter: grayscale(1);
  cursor: not-allowed;
}
.tool-disabled { opacity: 0.55; }
.tool-disabled select, .tool-disabled .btn { cursor: not-allowed; }

/* Game over */
.gameover-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85);
  z-index: 3000; display: flex; align-items: center; justify-content: center;
  padding: 1rem; animation: confirmFadeIn 0.3s ease-out;
}
.gameover-card {
  border-radius: var(--radius);
  padding: 2rem 1.5rem; max-width: 420px; width: 100%;
  max-height: 90vh; overflow-y: auto;
  text-align: center; color: #fff;
  border: 2px solid rgba(255,255,255,0.2);
  animation: confirmPopIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.gameover-card.wolves-win  { background: linear-gradient(160deg, #450a0a, #7f1d1d); border-color: #dc2626; }
.gameover-card.village-win { background: linear-gradient(160deg, #1e3a8a, #1d4ed8); border-color: #60a5fa; }
.gameover-icon { font-size: 4rem; margin-bottom: 0.5rem; }
.gameover-title { font-size: 1.4rem; font-weight: 800; margin-bottom: 0.5rem; }
.gameover-reason { font-size: 0.85rem; opacity: 0.85; margin-bottom: 1.25rem; }
.gameover-players {
  display: flex; flex-direction: column; gap: 0.4rem;
  background: rgba(0,0,0,0.25); border-radius: var(--radius-sm);
  padding: 0.75rem;
}
.gameover-player {
  display: flex; align-items: center; gap: 0.6rem;
  font-size: 0.85rem; padding: 0.3rem 0.5rem;
}
.gameover-player.eliminated { opacity: 0.55; }
.gameover-player-name { font-weight: 700; flex: 1; text-align: left; }
.gameover-player-role { opacity: 0.85; }

/* PWA install button */
.pwa-install-btn {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 500;
  background: var(--accent); color: #000;
  border: none; border-radius: 999px;
  padding: 0.7rem 1.1rem; font-weight: 700; font-size: 0.85rem;
  cursor: pointer; box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: confirmPopIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.pwa-install-btn:active { transform: scale(0.96); }

/* Custom role modal */
.icon-picker {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.4rem;
}
.icon-option {
  font-size: 1.3rem; padding: 0.4rem 0;
  background: var(--bg-card2);
  border: 2px solid transparent; border-radius: var(--radius-sm);
  cursor: pointer; line-height: 1;
}
.icon-option.selected { border-color: var(--accent); background: var(--bg-dark); }
.camp-picker { display: flex; gap: 0.5rem; }
.camp-option {
  flex: 1; padding: 0.55rem;
  background: var(--bg-card2); color: var(--text);
  border: 2px solid transparent; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 0.85rem; cursor: pointer;
}
.camp-option.village.selected { border-color: var(--village-color); background: rgba(37,99,235,0.15); }
.camp-option.loups.selected   { border-color: var(--loups-color);   background: rgba(220,38,38,0.15); }
textarea {
  background: var(--bg-card2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem; font-family: inherit; font-size: 0.9rem;
  resize: vertical; width: 100%;
}
.custom-role-divider { border-top: 1px solid var(--border); margin: 1rem 0; }
.saved-roles { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.saved-role-chip {
  display: flex; align-items: center;
  background: var(--bg-card2); border-radius: 999px;
  border: 1px solid var(--border); overflow: hidden;
}
.saved-role-chip.loups   { border-color: rgba(220,38,38,0.5); }
.saved-role-chip.village { border-color: rgba(37,99,235,0.5); }
.saved-role-use {
  background: none; border: none; color: var(--text);
  font-size: 0.8rem; font-weight: 600; padding: 0.35rem 0.3rem 0.35rem 0.7rem;
  cursor: pointer;
}
.saved-role-del {
  background: none; border: none; color: var(--text-muted);
  font-size: 0.7rem; padding: 0.35rem 0.6rem 0.35rem 0.3rem; cursor: pointer;
}
.saved-role-del:hover { color: var(--danger); }

/* Confirm modal (remplace confirm() natif) */
.confirm-overlay {
  animation: confirmFadeIn 0.15s ease-out;
}
.confirm-overlay.closing { opacity: 0; transition: opacity 0.15s; }
.confirm-modal {
  max-width: 380px;
  text-align: center;
  animation: confirmPopIn 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.confirm-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.confirm-modal h2 { margin-bottom: 0.5rem; }
.confirm-message {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.confirm-modal .modal-footer { justify-content: center; }
.confirm-modal .modal-footer .btn { min-width: 110px; }
@keyframes confirmFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes confirmPopIn {
  from { transform: scale(0.9); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* Reveal popup (on MC side) */
.reveal-popup {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--bg-card);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 2rem; z-index: 2000;
  text-align: center; min-width: 280px;
  box-shadow: 0 0 60px rgba(245,158,11,0.3);
  animation: popIn 0.25s ease;
}
@keyframes popIn { from { transform: translate(-50%,-50%) scale(0.85); opacity:0; } to { transform: translate(-50%,-50%) scale(1); opacity:1; } }
.reveal-popup .role-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.reveal-popup .role-name { font-size: 1.4rem; font-weight: 800; }
.reveal-popup .player-reveal-name { color: var(--text-muted); margin-bottom: 1rem; }
.reveal-popup-close { margin-top: 1rem; }

/* Landing (no session yet) */
.master-landing {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  flex-direction: column; gap: 1.5rem; padding: 2rem; text-align: center;
}
.master-landing h1 { font-size: 2.5rem; font-weight: 900; }
.master-landing p { color: var(--text-muted); max-width: 400px; }

/* Scrollable player list area */
.players-section-title {
  display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem;
}
.players-section-title h2 { font-size: 1rem; font-weight: 700; }
.player-count-badge {
  background: var(--bg-card2); border: 1px solid var(--border);
  border-radius: 999px; padding: 0.1rem 0.5rem; font-size: 0.75rem; color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════════
   PLAYER / JOIN INTERFACE
═══════════════════════════════════════════════════════════════════ */
.join-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  padding: 1.5rem;
  background: radial-gradient(ellipse at top, #1e293b 0%, #0f172a 70%);
}

/* Join form */
.join-form-container {
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 1rem; text-align: center;
}
.join-logo { font-size: 4rem; margin-bottom: 0.5rem; }
.join-title { font-size: 1.8rem; font-weight: 800; }
.join-subtitle { color: var(--text-muted); font-size: 0.9rem; }
.join-input-group { display: flex; flex-direction: column; gap: 0.5rem; text-align: left; }
.join-input { font-size: 1.1rem; padding: 0.85rem 1rem; border-radius: var(--radius); }
.join-btn { width: 100%; font-size: 1rem; padding: 0.9rem; border-radius: var(--radius); }

/* Waiting screen */
.waiting-screen {
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 1.25rem;
  padding: 2rem;
}
.waiting-spinner {
  width: 60px; height: 60px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.waiting-title { font-size: 1.4rem; font-weight: 700; }
.waiting-subtitle { color: var(--text-muted); }

/* Role card */
.role-card-screen {
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column;
  align-items: center;
  gap: 0;
}
.role-card {
  width: 100%;
  border-radius: 20px;
  padding: 2.5rem 2rem;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: cardReveal 0.5s cubic-bezier(0.22,1,0.36,1);
  position: relative; overflow: hidden;
}
@keyframes cardReveal {
  from { transform: scale(0.7) rotateY(90deg); opacity: 0; }
  to   { transform: scale(1) rotateY(0deg); opacity: 1; }
}
.role-card::before {
  content: '';
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.04);
  border-radius: 20px;
}
.role-card-camp-label {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.15em;
  text-transform: uppercase; opacity: 0.75; margin-bottom: 1rem;
}
.role-card-icon { font-size: 5rem; margin-bottom: 0.75rem; line-height: 1; }
.role-card-name { font-size: 2rem; font-weight: 900; margin-bottom: 0.5rem; }
.role-card-objective {
  font-size: 0.8rem; opacity: 0.75; font-style: italic;
  margin-bottom: 1.25rem;
}
.role-card-divider { height: 1px; background: rgba(255,255,255,0.2); margin: 0 -2rem 1.25rem; }
.role-card-description { font-size: 0.92rem; line-height: 1.65; opacity: 0.9; }

/* Notification overlay on player screen */
.player-notification {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 1rem;
  text-align: center; padding: 2rem;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
.player-notification.wolf-reveal { background: rgba(127,29,29,0.92); }
.player-notification.village-reveal { background: rgba(30,58,138,0.92); }
.player-notification.voyante-reveal { background: rgba(76,29,149,0.92); }
.player-notification.public-reveal  { background: rgba(15,23,42,0.92); }
.player-notification .notif-icon { font-size: 4rem; }
.player-notification .notif-title { font-size: 1.5rem; font-weight: 800; }
.player-notification .notif-body { font-size: 0.95rem; color: rgba(255,255,255,0.8); max-width: 320px; }
.player-notification .allies-list {
  display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; margin-top: 0.5rem;
}
.player-notification .ally-tag {
  background: rgba(255,255,255,0.15); border-radius: 999px;
  padding: 0.3rem 0.8rem; font-size: 0.85rem; font-weight: 600;
}
.notif-role-card {
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius); padding: 1rem 1.5rem;
  display: flex; align-items: center; gap: 0.75rem;
  font-weight: 700; font-size: 1rem;
}
.notif-role-card .notif-role-icon { font-size: 2rem; }

/* Public reveal banner */
.public-reveal-banner {
  position: fixed; top: 0; left: 0; right: 0;
  background: linear-gradient(135deg, #7f1d1d, #dc2626);
  padding: 1rem 1.5rem;
  text-align: center;
  z-index: 300;
  animation: slideDown 0.4s ease;
}
@keyframes slideDown { from { transform: translateY(-100%); } to { transform: translateY(0); } }
.public-reveal-banner .banner-title { font-weight: 800; font-size: 1rem; }
.public-reveal-banner .banner-body { font-size: 0.85rem; opacity: 0.85; }

/* Responsive */
@media (max-width: 768px) {
  .master-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
  }
  .master-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .modal-grid { grid-template-columns: 1fr; }
  /* Le header passe sur plusieurs lignes au lieu de déborder */
  .master-header {
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
    gap: 0.5rem 0.75rem;
  }
  .master-header h1 { font-size: 1.05rem; }
  .session-code-display { font-size: 1.2rem; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Section headers */
.section-header {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-muted);
  padding-bottom: 0.5rem; border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

/* Empty state */
.empty-state {
  text-align: center; color: var(--text-muted);
  padding: 2rem; font-size: 0.85rem;
}

/* No-session overlay */
#no-session-screen {
  grid-column: 1 / -1;
}
