/* ===== Variables ===== */
:root {
  --bg:        #07071a;
  --bg-2:      #0d0d26;
  --bg-3:      #131332;
  --bg-4:      #1a1a42;
  --accent:    #6b5fff;
  --accent-h:  #7d72ff;
  --accent-dim:rgba(107,95,255,.13);
  --text:      #dcdcf0;
  --text-2:    #8080a8;
  --text-3:    #50506a;
  --border:    #20204a;
  --meute:     #c94040;
  --village:   #3a8fd4;
  --solitaire: #b89830;
  --danger:    #c94040;
  --success:   #3ab87a;
  --radius:    12px;
  --radius-sm: 8px;
}

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

html { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  min-height: 100%;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

img { display: block; max-width: 100%; }
button { font: inherit; cursor: pointer; border: none; background: none; }
input  { font: inherit; }

/* ===== Screens ===== */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100svh;
  animation: fadeUp .25s ease both;
}
.screen.active { display: flex; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== Layout helpers ===== */
.screen-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1rem 1.25rem .5rem;
  border-bottom: 1px solid var(--border);
}
.screen-header h2 { font-size: 1.1rem; font-weight: 600; }

.screen-body {
  flex: 1;
  padding: 1.25rem;
  overflow-y: auto;
}

.btn-back {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--text-2);
  font-size: 1.2rem;
  transition: background .15s;
}
.btn-back:hover { background: var(--bg-3); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: .95rem;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .4; pointer-events: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-h); }

.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent);
}
.btn-outline:hover { background: var(--accent-dim); }

.btn-ghost {
  background: var(--bg-3);
  color: var(--text);
}
.btn-ghost:hover { background: var(--bg-4); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-full { width: 100%; }
.btn-lg { padding: 1rem 2rem; font-size: 1.1rem; }

/* ===== Inputs ===== */
.input {
  width: 100%;
  background: var(--bg-3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: .75rem 1rem;
  font-size: 1rem;
  outline: none;
  transition: border-color .15s;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-3); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-4);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  z-index: 999;
  white-space: nowrap;
  animation: toastIn .2s ease;
  pointer-events: none;
}
.toast.error { border-color: var(--danger); color: #f09090; }
@keyframes toastIn {
  from { opacity:0; transform: translateX(-50%) translateY(8px); }
  to   { opacity:1; transform: translateX(-50%) translateY(0); }
}

/* ===== Modal overlay ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 200;
  align-items: flex-end;
}
.modal-overlay.active { display: flex; }

.modal-sheet {
  width: 100%;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 1.25rem;
  max-height: 85svh;
  overflow-y: auto;
  animation: sheetUp .25s ease;
}
@keyframes sheetUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 1rem;
}
.modal-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* ===== HOME ===== */
#screen-home {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 3rem;
  padding: 3rem 2rem;
  min-height: 100svh;
}

.home-logo h1 {
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--text);
  text-shadow: 0 0 40px rgba(107,95,255,.4);
}
.home-logo p {
  color: var(--text-2);
  margin-top: .5rem;
  font-size: .95rem;
  letter-spacing: .05em;
  text-transform: uppercase;
}

/* ===== CHOOSE ===== */
.choose-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem 1.25rem;
  flex: 1;
  justify-content: center;
}

.btn-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
  padding: .85rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  text-align: center;
  transition: filter .15s, transform .1s;
}
.btn-choice:hover  { filter: brightness(1.12); transform: translateY(-1px); }
.btn-choice:active { transform: translateY(0); }

.btn-choice-create { background: #2d9e70; }
.btn-choice-join   { background: #6b5fff; }

.choice-title { font-size: .95rem; font-weight: 700; color: #fff; }
.choice-sub   { font-size: .78rem; color: rgba(255,255,255,.65); }

/* ===== PSEUDO SCREEN ===== */
.pseudo-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1;
  justify-content: center;
  max-width: 400px;
  margin: 0 auto;
  width: 100%;
  padding: 1.5rem 1.25rem;
}
.pseudo-form label { font-size: .9rem; color: var(--text-2); }

/* ===== MJ CONFIG ===== */
.config-section { margin-bottom: 1.5rem; }
.config-section-title {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: .75rem;
}

.max-players-control {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .5rem 1rem;
  width: fit-content;
}
.max-players-control .val {
  font-size: 1.4rem;
  font-weight: 700;
  min-width: 2.5rem;
  text-align: center;
}
.stepper-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg-4);
  color: var(--text);
  font-size: 1.2rem;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.stepper-btn:hover { background: var(--accent); }

/* Role config grid */
.tribe-group { margin-bottom: 1.25rem; }
.tribe-label {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: .6rem;
  padding: .2rem .6rem;
  border-radius: 4px;
  display: inline-block;
}
.tribe-label.meute    { color: var(--meute);    background: rgba(201,64,64,.12); }
.tribe-label.village  { color: var(--village);  background: rgba(58,143,212,.12); }
.tribe-label.solitaire{ color: var(--solitaire);background: rgba(184,152,48,.12); }

.roles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: .75rem;
}

.role-config-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .4rem;
  background: var(--bg-3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .6rem .4rem;
  text-align: center;
}
.role-config-card img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
}
.role-config-name {
  font-size: .65rem;
  color: var(--text-2);
  line-height: 1.2;
  min-height: 2em;
}
.role-count-ctrl {
  display: flex;
  align-items: center;
  gap: .3rem;
}
.role-count-ctrl .count {
  font-size: .9rem;
  font-weight: 700;
  min-width: 1.2rem;
  text-align: center;
}
.role-count-btn {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--bg-4);
  color: var(--text);
  font-size: .9rem;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.role-count-btn:hover { background: var(--accent); }
.role-count-btn:disabled { opacity: .3; pointer-events: none; }

/* Card counter bar */
.card-counter {
  position: sticky;
  bottom: 0;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  padding: .75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.counter-label { font-size: .9rem; }
.counter-val { font-size: 1rem; font-weight: 700; }
.counter-val.ok  { color: var(--success); }
.counter-val.bad { color: var(--danger); }

/* ===== MJ LOBBY ===== */
.lobby-code-block {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  margin-bottom: 1rem;
}
.lobby-code-label { font-size: .75rem; color: var(--text-2); letter-spacing: .1em; text-transform: uppercase; }
.lobby-code {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: .3em;
  color: var(--accent-h);
  font-family: 'Courier New', monospace;
}

.lobby-status-badge {
  display: inline-block;
  font-size: .75rem;
  font-weight: 600;
  padding: .2rem .7rem;
  border-radius: 20px;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.lobby-status-badge.open   { background: rgba(58,184,122,.15); color: var(--success); }
.lobby-status-badge.locked { background: rgba(201,64,64,.15);  color: var(--danger); }

.section-title {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: .6rem;
}

.player-list {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  margin-bottom: 1rem;
}
.player-list-item {
  background: var(--bg-3);
  border-radius: var(--radius-sm);
  padding: .5rem .75rem;
  font-size: .9rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.player-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.event-log {
  background: var(--bg-3);
  border-radius: var(--radius-sm);
  padding: .75rem;
  max-height: 120px;
  overflow-y: auto;
  margin-bottom: 1rem;
}
.event-item {
  font-size: .8rem;
  color: var(--text-2);
  padding: .15rem 0;
}
.event-item.join  { color: var(--success); }
.event-item.leave { color: var(--danger); }

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* ===== PLAYER LOBBY ===== */
.player-lobby-code {
  text-align: center;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.player-lobby-code .code-val {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: .25em;
  color: var(--accent-h);
  font-family: 'Courier New', monospace;
}

/* ===== PLAYER GAME ===== */
#screen-player-game {
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 1.25rem;
}

.player-game-top {
  width: 100%;
  display: flex;
  justify-content: flex-end;
}

.card-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  flex: 1;
  justify-content: center;
}

.card-wrapper {
  perspective: 1000px;
  width: min(280px, 80vw);
  aspect-ratio: 1;
  cursor: pointer;
}
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .6s cubic-bezier(.4,0,.2,1);
}
.card-inner.flipped { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--border);
}
.card-face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.card-recto { transform: rotateY(180deg); }

.card-hint {
  font-size: .8rem;
  color: var(--text-3);
  letter-spacing: .05em;
}

.player-game-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

/* ===== MJ GAME ===== */
#screen-mj-game {
  overflow: hidden;
}

.mj-game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.mj-game-title { font-size: .9rem; font-weight: 600; color: var(--text-2); }

.mj-circle-container {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.mj-circle-ring {
  position: absolute;
  border-radius: 50%;
  border: 1px solid var(--border);
  pointer-events: none;
}

.mj-center-info {
  position: absolute;
  text-align: center;
  pointer-events: none;
}
.mj-center-code {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: .2em;
  color: var(--accent-dim);
  font-family: 'Courier New', monospace;
}
.mj-center-count { font-size: .75rem; color: var(--text-3); margin-top: .25rem; }

.mj-player-slot {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  cursor: pointer;
  transition: transform .15s, z-index 0s;
  z-index: 1;
}
.mj-player-slot:hover {
  transform: translate(-50%,-50%) scale(1.08) !important;
  z-index: 100;
}

.mj-card-img {
  object-fit: cover;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  display: block;
  aspect-ratio: 1;
}

/* Textes communs sous les cartes du cercle MJ */
.mj-player-name,
.mj-player-role-label,
.mj-player-herite-label,
.mj-player-infected-label {
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  line-height: 1;
}

.mj-player-name {
  font-size: .55rem;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 1px;
}

.mj-player-role-label {
  font-size: .44rem;
  color: var(--text-2);
}

.mj-player-herite-label {
  font-size: .44rem;
  color: #55aaff;
}

.mj-player-infected-label {
  font-size: .44rem;
  color: #72c442;
  font-style: italic;
}

.mj-status-badges {
  margin-top: 1px;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: center;
  max-width: 70px;
}
.status-badge {
  width: 14px; height: 14px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.status-badge svg { width: 9px; height: 9px; }

.mj-game-footer {
  display: flex;
  gap: .5rem;
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.mj-game-footer .btn { flex: 1; font-size: .85rem; padding: .6rem; }

/* ===== MJ toolbox modal ===== */
.toolbox-player {
  margin-bottom: 1.25rem;
}
.toolbox-player-name {
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: .5rem;
  color: var(--text-2);
}
.status-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}
.status-toggle-btn {
  display: flex;
  align-items: center;
  gap: .3rem;
  padding: .3rem .6rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  border: 1.5px solid transparent;
  background: var(--bg-3);
  color: var(--text-2);
  transition: all .15s;
}
.status-toggle-btn svg { width: 12px; height: 12px; }
.status-toggle-btn.active { color: #fff; }

/* ===== Role detail modal ===== */
.role-detail-img {
  width: 140px;
  height: 140px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  margin: 0 auto .75rem;
}
.role-detail-name { font-size: 1.1rem; font-weight: 700; text-align: center; margin-bottom: .15rem; }
.role-detail-sub  { font-size: .8rem; color: var(--text-2); text-align: center; margin-bottom: .75rem; }
.role-detail-tribe {
  display: inline-block;
  font-size: .75rem;
  font-weight: 700;
  padding: .2rem .6rem;
  border-radius: 4px;
  margin-bottom: .75rem;
}
.role-detail-desc { font-size: .9rem; line-height: 1.55; color: var(--text-2); }

/* ===== Roles panel (player) ===== */
.roles-panel-list { display: flex; flex-direction: column; gap: .5rem; }
.roles-panel-item {
  background: var(--bg-3);
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}
.roles-panel-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .75rem;
  cursor: pointer;
}
.roles-panel-header img { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.roles-panel-info { flex: 1; min-width: 0; }
.roles-panel-name { font-size: .85rem; font-weight: 600; }
.roles-panel-count { font-size: .75rem; color: var(--text-2); }
.roles-panel-body {
  display: none;
  padding: 0 .75rem .75rem;
  font-size: .82rem;
  color: var(--text-2);
  line-height: 1.5;
  border-top: 1px solid var(--border);
}
.roles-panel-body.open { display: block; }

/* ===== Confirmation modal ===== */
.confirm-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 300;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.confirm-modal.active { display: flex; }
.confirm-box {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 340px;
  width: 100%;
  text-align: center;
}
.confirm-title { font-size: 1rem; font-weight: 700; margin-bottom: .75rem; }
.confirm-msg { font-size: .85rem; color: var(--text-2); line-height: 1.5; margin-bottom: 1.25rem; }
.confirm-actions { display: flex; gap: .75rem; }
.confirm-actions .btn { flex: 1; }

/* ===== Status role picker ===== */
.roles-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
  gap: .5rem;
  max-height: 55svh;
  overflow-y: auto;
  padding: .25rem 0;
}

.role-picker-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .3rem;
  padding: .5rem .3rem;
  background: var(--bg-3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: border-color .15s;
}
.role-picker-btn img  { width: 50px; height: 70px; object-fit: cover; border-radius: 4px; }
.role-picker-btn span { font-size: .62rem; color: var(--text-2); line-height: 1.2; }
.role-picker-btn.selected { border-color: var(--accent); background: var(--accent-dim); }
.role-picker-btn:hover    { border-color: var(--accent); }

/* Toolbox extras */
.toolbox-player-role   { font-size: .72rem; color: var(--text-3); font-weight: 400; margin-left: .35rem; }
.status-role-hint      { font-size: .7em; opacity: .8; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
