:root {
  --bg: #12101c;
  --card: rgba(255,255,255,0.05);
  --card-border: rgba(255,255,255,0.12);
  --text: #f2f0f7;
  --muted: #a5a0b8;
  --primary: #b8433a;
  --primary-2: #d97706;
  --success: #4ade80;
  --fail: #f87171;
  font-size: 16px;
}

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

.bg-blob { position: fixed; border-radius: 50%; filter: blur(90px); opacity: 0.35; pointer-events: none; z-index: 0; }
.blob-1 { width: 420px; height: 420px; background: var(--primary); top: -120px; left: -100px; }
.blob-2 { width: 380px; height: 380px; background: var(--primary-2); bottom: -140px; right: -100px; }
.blob-3 { width: 300px; height: 300px; background: #166534; top: 40vh; left: 60vw; opacity: 0.25; }

.hidden { display: none !important; }

.header {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px;
}
.brand { font-size: 1.3rem; font-weight: 700; cursor: pointer; background: none; border: none; color: inherit; padding: 0; font-family: inherit; }
.header-right { display: flex; align-items: center; gap: 10px; }
.room-badge {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--card-border); border-radius: 999px;
  padding: 6px 8px 6px 14px; font-weight: 700; letter-spacing: 2px;
}
.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0; border-radius: 50%;
  background: rgba(255,255,255,0.06); color: var(--text); border: 1px solid var(--card-border);
  font-size: 0.85rem; line-height: 1;
}
.icon-btn:hover { background: rgba(184,67,58,0.25); border-color: var(--primary); }

main { position: relative; z-index: 1; display: flex; justify-content: center; padding: 0 16px 40px; }
.view { width: 100%; max-width: 560px; }
.card {
  background: var(--card); border: 1px solid var(--card-border); backdrop-filter: blur(20px);
  border-radius: 20px; padding: 24px; box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}
h1 { font-size: 1.4rem; margin: 0 0 6px; }
h2 { font-size: 1rem; margin: 0 0 10px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 20px 0; }
.field input, .join-row input, .invite-link-row input {
  padding: 12px 14px; border-radius: 10px; border: 1px solid var(--card-border);
  background: rgba(255,255,255,0.04); color: var(--text); font-size: 1rem;
}

.home-actions { display: flex; flex-direction: column; gap: 14px; margin-top: 10px; }
.join-row { display: flex; gap: 8px; }
.join-row input { width: 100px; text-transform: uppercase; text-align: center; letter-spacing: 3px; }
.join-row button { flex: 1; }
.link { color: var(--primary); text-decoration: none; text-align: center; font-size: 0.9rem; }

button {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #10101a; border: none; border-radius: 10px; padding: 12px 18px;
  font-size: 1rem; font-weight: 600; cursor: pointer;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-ghost { background: rgba(255,255,255,0.06); color: var(--text); }
.btn-kick { background: rgba(248,113,113,0.15); color: var(--fail); padding: 4px 10px; font-size: 0.8rem; }

.error { color: var(--fail); margin-top: 12px; font-size: 0.9rem; }

.lobby-header { display: flex; align-items: center; justify-content: space-between; }
#lobbyCode { color: var(--primary); letter-spacing: 3px; }

.mode-picker { display: flex; gap: 8px; margin: 14px 0; }
.mode-btn {
  flex: 1; background: rgba(255,255,255,0.06); color: var(--muted);
  border: 1px solid var(--card-border);
}
.mode-btn-active { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #10101a; font-weight: 700; }

.lobby-body { display: flex; flex-direction: column; gap: 20px; margin: 14px 0; }
.players-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.player-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: rgba(255,255,255,0.04); border-radius: 10px; padding: 8px 12px;
}
.player-disconnected { opacity: 0.5; }
.player-character { color: var(--muted); font-size: 0.85rem; }

.characters-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.character-btn {
  background: rgba(255,255,255,0.06); color: var(--text); border: 1px solid var(--card-border);
  text-align: left; display: flex; flex-direction: column; gap: 2px; font-size: 0.9rem;
}
.character-btn small { color: var(--muted); font-weight: 400; }
.character-btn-mine { border-color: var(--primary); background: rgba(184,67,58,0.2); }
.character-btn-taken { opacity: 0.4; }

.host-controls { display: flex; flex-direction: column; gap: 12px; margin: 14px 0; padding-top: 14px; border-top: 1px solid var(--card-border); }
.switch-row { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
/* Bascule personnelle Adulte / Enfant (affichage seulement, jamais synchronisee au serveur). */
.child-mode-panel { margin: 14px 0; padding-top: 14px; border-top: 1px solid var(--card-border); }
.child-mode-panel-game { margin: 0 0 12px; padding-top: 0; border-top: none; }
.child-switch { display: flex; gap: 6px; }
.child-switch .child-opt {
  flex: 1; background: rgba(255,255,255,0.06); color: var(--muted);
  border: 1px solid var(--card-border); padding: 8px 10px; font-size: 0.85rem;
}
.child-switch .child-opt-active { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #10101a; font-weight: 700; }

.bot-controls { display: flex; gap: 8px; }
.bot-controls button { flex: 1; font-size: 0.9rem; }

.invite-panel { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--card-border); text-align: center; }
.invite-link-row { display: flex; gap: 8px; margin: 8px 0 14px; }
.invite-link-row input { flex: 1; font-size: 0.85rem; }
.qr-img { display: block; width: 160px; height: 160px; border-radius: 10px; background: #fff; padding: 8px; margin: 14px auto; }

/* ------------------------------------------------------------------------------------------ */
/* Vue de jeu */
.view-game-wrap { max-width: 1080px; }
.game-layout { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.game-main { flex: 1 1 560px; min-width: 320px; }
.game-side { flex: 0 0 300px; min-width: 260px; max-height: 80vh; display: flex; flex-direction: column; }

.turn-banner { font-weight: 700; margin-bottom: 12px; color: var(--primary); }

.board-scroll {
  overflow: auto; border-radius: 14px; padding: 14px;
  background: linear-gradient(145deg, #2b1710, #1a0f0a);
  border: 3px solid #4a2c1a; box-shadow: inset 0 0 24px rgba(0,0,0,0.6), 0 6px 20px rgba(0,0,0,0.4);
}
.board-grid {
  display: grid;
  grid-template-columns: repeat(var(--board-cols), 28px);
  grid-template-rows: repeat(var(--board-rows), 28px);
  gap: 2px;
  position: relative;
  width: max-content;
  background: #120a06;
  padding: 4px;
  border-radius: 6px;
}
/* Couloirs : petites cases, c'est le seul endroit ou l'on avance pas a pas. */
.tile { position: relative; border-radius: 2px; }
.tile-floor-a { background: #d8c9a8; }
.tile-floor-b { background: #c9b795; }
.tile-start { box-shadow: inset 0 0 0 2px rgba(184,67,58,0.85); }

/* Pieces : un seul bloc fusionne par piece (pas un paquet de cases). */
.room-block {
  position: relative; z-index: 1;
  border: 2px solid; border-radius: 8px;
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.4);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; padding: 4px; overflow: hidden;
}
.room-block-head { display: flex; align-items: center; gap: 4px; pointer-events: none; }
.room-block-icon { font-size: 15px; line-height: 1; }
.room-block-name {
  font-size: 10px; font-weight: 800; color: #fdf6e3; text-align: center; line-height: 1.1;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}
.room-tokens { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; }
.room-passage {
  font-size: 8px; font-weight: 700; color: #fdf6e3; opacity: 0.85; pointer-events: none;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* Portes : encoche claire sur le bord de la piece, seul passage couloir <-> piece. */
.door-mark {
  position: relative; z-index: 3; align-self: center; justify-self: center;
  width: 74%; height: 74%; border-radius: 3px; pointer-events: none;
  background: #f3e6c8;
  box-shadow: 0 0 0 2px #12100c, 0 0 8px rgba(243,230,200,0.6);
}

.tile-reachable { cursor: pointer; box-shadow: inset 0 0 0 3px #4ade80, 0 0 12px rgba(74,222,128,0.5); }
.tile.tile-reachable { background: rgba(74,222,128,0.6); }
.room-block.tile-reachable { filter: brightness(1.35); }
.tile-reachable:hover { box-shadow: inset 0 0 0 3px #86efac, 0 0 16px rgba(74,222,128,0.8); }

.token {
  position: absolute; inset: 2px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 9px; font-weight: 800; color: #10101a;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.85), 0 2px 4px rgba(0,0,0,0.6); z-index: 2;
}
/* Dans une piece, les pions se rangent cote a cote au lieu de remplir une case. */
.token-in-room { position: static; inset: auto; width: 18px; height: 18px; flex: 0 0 auto; }
.token-eliminated { opacity: 0.35; filter: grayscale(1); }

.dice-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.dice-face { font-size: 1.4rem; font-weight: 800; min-width: 54px; text-align: center; }
.dice-row button { padding: 10px 14px; font-size: 0.9rem; }

.side-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.side-tab {
  flex: 1; background: rgba(255,255,255,0.06); color: var(--muted); border: 1px solid var(--card-border);
  padding: 8px 10px; font-size: 0.85rem;
}
.side-tab-active { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #10101a; font-weight: 700; }
.side-panel { overflow-y: auto; max-height: 60vh; }

.game-log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; }
.game-log li { background: rgba(255,255,255,0.04); border-radius: 8px; padding: 6px 10px; }

.notebook-scroll { overflow: auto; max-height: 40vh; }
.notebook-freetext-field { margin: 12px 0 6px; }
.notebook-freetext-field textarea {
  resize: vertical; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--card-border);
  background: rgba(255,255,255,0.04); color: var(--text); font-size: 0.85rem; font-family: inherit;
}
.notebook { border-collapse: collapse; font-size: 0.75rem; width: 100%; }
.notebook th, .notebook td { border: 1px solid var(--card-border); padding: 4px 6px; text-align: center; white-space: nowrap; }
.notebook-item { text-align: left; color: var(--muted); }
.notebook-cat td { text-align: left; font-weight: 700; color: var(--primary); background: rgba(255,255,255,0.04); }
.notebook-cell { cursor: pointer; user-select: none; }
.notebook-cell:hover { background: rgba(255,255,255,0.08); }

/* Modales */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 10;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal { width: 100%; max-width: 420px; position: relative; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions button { flex: 1; }
.modal-close {
  position: absolute; top: 14px; right: 14px;
  width: 28px; height: 28px; padding: 0; border-radius: 50%;
  background: rgba(255,255,255,0.08); color: var(--text); font-size: 0.9rem; line-height: 1;
}
.modal-rules { max-width: 480px; max-height: 80vh; overflow-y: auto; text-align: left; }
.modal-rules ul { padding-left: 20px; margin: 14px 0; display: flex; flex-direction: column; gap: 10px; }
.modal-rules li { line-height: 1.4; }
.disprove-options { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.disprove-option { text-align: left; }

.rooms-list { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.room-card {
  display: flex; flex-direction: column; gap: 2px; text-decoration: none;
  background: rgba(255,255,255,0.05); border: 1px solid var(--card-border); border-radius: 12px;
  padding: 12px 14px; color: var(--text);
}
.room-card-code { font-weight: 700; letter-spacing: 2px; color: var(--primary); }
.room-card-info { font-size: 0.85rem; color: var(--muted); }
