:root {
  --bg: #170f1f;
  --card-bg: rgba(255,255,255,0.05);
  --card-border: rgba(255,255,255,0.12);
  --primary: #f5576c;
  --primary-2: #f9a826;
  --text: #f5f0f7;
  --muted: #a89fb5;
  --success: #4ade80;
  --fail: #f87171;
  --radius: 20px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

.bg-blob { position: fixed; border-radius: 50%; filter: blur(90px); opacity: 0.35; z-index: 0; pointer-events: none; }
.blob-1 { width: 420px; height: 420px; background: var(--primary); top: -120px; left: -100px; animation: float1 38s ease-in-out infinite; }
.blob-2 { width: 380px; height: 380px; background: var(--primary-2); bottom: -140px; right: -100px; animation: float2 44s ease-in-out infinite; }

@keyframes float1 {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(60vw, 20vh); }
  50%  { transform: translate(30vw, 60vh); }
  75%  { transform: translate(-20vw, 30vh); }
  100% { transform: translate(0, 0); }
}
@keyframes float2 {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(-50vw, -25vh); }
  50%  { transform: translate(-25vw, -55vh); }
  75%  { transform: translate(15vw, -20vh); }
  100% { transform: translate(0, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .bg-blob { animation: none !important; }
}

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; position: relative; z-index: 1; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.1rem; }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, var(--primary), var(--primary-2)); font-weight: 800; font-size: 0.9rem; }
.room-badge { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.08); border: 1px solid var(--card-border); padding: 6px 14px; border-radius: 999px; font-size: 0.85rem; }
.qr-icon-btn { background: none; border: none; color: var(--text); cursor: pointer; font-size: 1rem; }

#app { position: relative; z-index: 1; max-width: 820px; width: 100%; margin: 0 auto; padding: 10px 20px 60px; }
.hidden { display: none !important; }

.active-room-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(245, 87, 108, 0.15);
  border: 1px solid rgba(245, 87, 108, 0.4);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 18px;
  font-size: 0.9rem;
}
.active-room-banner .btn-small { padding: 8px 14px; font-size: 0.85rem; flex: 0 0 auto; }

.bot-controls { display: flex; gap: 10px; margin: 4px 0 16px; flex-wrap: wrap; }

.card { background: var(--card-bg); border: 1px solid var(--card-border); border-radius: var(--radius); padding: 28px; backdrop-filter: blur(20px); }

h1 { font-size: 1.8rem; margin: 0 0 10px; }
h2 { margin: 0 0 8px; }
h3.section-title { margin: 22px 0 10px; font-size: 1rem; }
.subtitle { color: var(--muted); margin: 0 0 24px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.field { margin-bottom: 18px; }
.field label { display: block; margin-bottom: 6px; font-size: 0.85rem; color: var(--muted); }
input { width: 100%; background: rgba(255,255,255,0.06); border: 1px solid var(--card-border); border-radius: 12px; padding: 12px 14px; color: var(--text); font-size: 1rem; }

.btn { border: none; border-radius: 12px; padding: 12px 18px; font-weight: 700; cursor: pointer; font-size: 0.95rem; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #1a0f10; }
.btn-secondary { background: rgba(255,255,255,0.1); color: var(--text); border: 1px solid var(--card-border); }

.home-actions { display: flex; flex-direction: column; gap: 12px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1 1 100px; text-transform: uppercase; letter-spacing: 2px; text-align: center; }
.error-text { color: var(--fail); min-height: 1.2em; margin-top: 14px; font-size: 0.9rem; }

.player-list { list-style: none; padding: 0; margin: 18px 0; display: flex; flex-direction: column; gap: 8px; }
.player-list li { display: flex; align-items: center; gap: 8px; justify-content: space-between; background: rgba(255,255,255,0.06); border: 1px solid var(--card-border); padding: 10px 14px; border-radius: 12px; }
.tag { font-size: 0.7rem; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color:#1a0f10; padding: 2px 8px; border-radius: 999px; }
.tag-offline { background: rgba(248,113,113,0.2) !important; color: var(--fail); border: 1px solid rgba(248,113,113,0.4); }
.kick-btn { background: none; border: 1px solid rgba(248,113,113,0.4); color: var(--fail); border-radius: 8px; padding: 4px 10px; font-size: 0.75rem; cursor: pointer; }

.turn-banner { text-align: center; font-weight: 700; padding: 10px; border-radius: 12px; background: rgba(245,87,108,0.15); border: 1px solid rgba(245,87,108,0.4); margin-bottom: 4px; }
.turn-banner.mine { background: rgba(74,222,128,0.18); border-color: rgba(74,222,128,0.5); }

.pending-action { margin-top: 14px; padding: 14px; border-radius: 14px; background: rgba(249,168,38,0.15); border: 1px solid rgba(249,168,38,0.5); }
.pending-action p { margin: 0 0 10px; font-weight: 600; }
.target-list { display: flex; gap: 8px; flex-wrap: wrap; }
.target-btn { background: rgba(255,255,255,0.1); border: 1px solid var(--card-border); color: var(--text); border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 600; }
.target-btn:hover { background: rgba(255,255,255,0.18); }

/* Une ligne compacte par joueur (nom + statut + cartes + score), pour rester lisible sans
   trop de defilement meme au maximum de 8 joueurs, plutot qu'une grande carte empilee. */
.players { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.player-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 6px 10px;
  min-height: 46px; /* = hauteur reelle d'une ligne avec carte (mini-card 32px + padding 12px
                        + 2px de bordure/gap constates a l'usage), pour que la ligne ne
                        s'agrandisse pas des la premiere carte posee en main */
  box-sizing: border-box;
}
.player-panel.current-turn { border-color: var(--primary-2); box-shadow: 0 0 0 1px var(--primary-2); }
.player-panel.status-busted { opacity: 0.55; }
.player-panel.status-stayed { border-color: rgba(74,222,128,0.4); }
.player-panel .pname { font-weight: 700; font-size: 0.85rem; flex: 0 0 auto; }
.status-pill { font-size: 0.65rem; padding: 2px 8px; border-radius: 999px; font-weight: 700; flex: 0 0 auto; }
.status-pill.active { background: rgba(34,193,195,0.2); color: #6fe3e5; }
.status-pill.stayed { background: rgba(74,222,128,0.2); color: var(--success); }
.status-pill.busted { background: rgba(248,113,113,0.2); color: var(--fail); }
.status-pill.frozen { background: rgba(147,197,253,0.2); color: #93c5fd; }
.player-cards { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; flex: 1 1 auto; }
.mini-card { min-width: 24px; height: 32px; padding: 0 3px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.72rem; background: linear-gradient(160deg, #fff, #e4e4e4); color: #16151f; }
.mini-card.mod { background: linear-gradient(160deg, var(--primary), var(--primary-2)); color: #1a0f10; font-size: 0.62rem; }
.mini-card.special { background: linear-gradient(160deg, #93c5fd, #60a5fa); color: #0e1b2e; font-size: 0.58rem; }
/* Carte en double a l'origine d'un bust : entouree en rouge pour la reperer d'un coup d'oeil. */
.mini-card.busted-culprit { outline: 2px solid var(--fail); outline-offset: 1px; }
.player-score-compact { flex: 0 0 auto; font-size: 0.85rem; white-space: nowrap; }
.player-score { font-weight: 800; }
.player-total { color: var(--muted); font-size: 0.75rem; }

.game-actions { display: flex; gap: 10px; margin-top: 16px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 20px; }
.modal-content { background: var(--bg); border: 1px solid var(--card-border); border-radius: var(--radius); padding: 24px; text-align: center; position: relative; max-width: 320px; width: 100%; }
.modal-close { position: absolute; top: 10px; right: 14px; background: none; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; }
#qrImage { width: 100%; border-radius: 12px; margin: 12px 0; background: #fff; }

/* ---------- Chat du salon ---------- */
.chat-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 40;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(245, 87, 108, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-fab:hover { box-shadow: 0 10px 30px rgba(245, 87, 108, 0.55); }

.chat-unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--fail);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
}

.chat-panel {
  position: fixed;
  right: 24px;
  bottom: 92px;
  z-index: 40;
  width: min(340px, calc(100vw - 48px));
  height: min(440px, calc(100vh - 140px));
  display: flex;
  flex-direction: column;
  background: #190f18;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  overflow: hidden;
}
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--card-border);
  font-weight: 700;
  flex: 0 0 auto;
}
.chat-header .modal-close { position: static; }

.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-msg { max-width: 88%; }
.chat-msg .chat-msg-name { font-size: 0.72rem; color: var(--muted); margin-bottom: 2px; }
.chat-msg .chat-msg-bubble {
  display: inline-block;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--card-border);
  font-size: 0.92rem;
  word-break: break-word;
}
.chat-msg.chat-msg-mine { align-self: flex-end; text-align: right; }
.chat-msg.chat-msg-mine .chat-msg-bubble {
  background: linear-gradient(135deg, rgba(245,87,108,0.4), rgba(249,168,38,0.35));
  border-color: rgba(245,87,108,0.5);
}
.chat-msg-system { align-self: center; color: var(--muted); font-size: 0.78rem; }

.chat-input-row {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--card-border);
}
.chat-input-row input { flex: 1; min-width: 0; }
.chat-send-btn { flex: 0 0 auto; padding: 10px 16px; }

@media (max-width: 420px) {
  .chat-panel { right: 12px; bottom: 84px; }
  .chat-fab { right: 16px; bottom: 16px; }
}

/* Les <option> ignorent souvent le style du <select> parent et retombent sur le blanc par
   defaut du systeme/navigateur pour le menu deroulant : on force explicitement le theme sombre. */
select option { background: var(--bg); color: var(--text); }

/* ---------- Historique ---------- */
.history-panel { display: none; }
.history-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column-reverse; gap: 8px; overflow-y: auto; }
.history-list li { font-size: 0.82rem; color: var(--muted); border-bottom: 1px solid var(--card-border); padding-bottom: 8px; }
.history-list li:last-child { color: var(--text); font-weight: 600; }

/* Panneau FIXE hors flux, comme le chat mais a gauche : ne reduit jamais la zone de jeu
   centrale. Visible seulement si la fenetre est assez large pour ne pas empieter sur le
   contenu centre (#app fait 820px de large max). */
@media (min-width: 1180px) {
  .history-panel {
    display: block;
    position: fixed;
    left: 24px;
    top: 90px;
    width: 260px;
    max-height: calc(100vh - 120px);
    z-index: 30;
  }
  .history-panel .history-list { max-height: calc(100vh - 200px); }
}

/* ---------- Salons publics (parite avec Just One) ---------- */
.brand-link {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 10px;
  transition: background 0.15s;
  font-family: inherit;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-link:hover { background: rgba(255,255,255,0.08); }

.btn-ghost { background: none; color: var(--muted); border: 1px solid var(--card-border); }

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 30px 20px 40px;
  position: relative;
  z-index: 1;
}

.public-rooms-link {
  display: block;
  text-align: center;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
}
.public-rooms-link:hover { color: var(--text); text-decoration: underline; }

.public-controls { margin: 18px 0; }
.public-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(139, 92, 246, 0.08);
  border: 1px solid rgba(139, 92, 246, 0.25);
}
.public-toggle-title { font-weight: 700; margin: 0 0 2px; }

.switch {
  flex: 0 0 auto;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: rgba(255,255,255,0.15);
  border: 1px solid var(--card-border);
  position: relative;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s;
}
.switch[aria-checked="true"] {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-color: transparent;
}
.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.switch[aria-checked="true"] .switch-knob { transform: translateX(20px); }

.rooms-list { display: flex; flex-direction: column; gap: 12px; margin: 20px 0; }
.room-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 16px 18px;
}
.room-card-title { font-weight: 700; margin-bottom: 4px; }
.room-card-code {
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 1px;
  margin-left: 6px;
}
