:root {
  --bg: #16110d;
  --bg-raised: #1f1811;
  --bg-input: #2a2118;
  --border: #3b3128;
  --border-strong: #554634;
  --text: #ede3d4;
  --text-muted: #a5967f;
  --gold: #c9a24b;
  --gold-bright: #e6bf62;
  --blue: #8fb8de;
  --red: #d4614f;
  --green: #7fa86a;
  --amber: #d99a3f;
  --radius: 8px;
  --gap: 1rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

h1, h2, h3 { line-height: 1.25; }
h2 { color: var(--gold); font-size: 1.25rem; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; margin: 0 0 0.25rem; }
p { margin: 0 0 0.5rem; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: 0.87rem; }

/* ---------- Barre supérieure ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 0.6rem 1rem;
  background: rgba(22, 17, 13, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.5rem; }
.brand-mark { color: var(--gold); font-size: 1.3rem; }
.brand h1 { font-size: 1.1rem; margin: 0; letter-spacing: 0.04em; }
.topbar-right { display: flex; align-items: center; gap: 0.6rem; }

.badge {
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.8rem;
  color: var(--gold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}

/* ---------- Contrôles ---------- */

button {
  font: inherit;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
button:hover:not(:disabled) { background: #362b1f; border-color: var(--gold); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: var(--gold);
  border-color: var(--gold);
  color: #1a1410;
  font-weight: 600;
}
button.primary:hover:not(:disabled) { background: var(--gold-bright); border-color: var(--gold-bright); }
button.ghost { background: transparent; font-size: 0.85rem; }

input, textarea, select {
  font: inherit;
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--gold);
}
input:disabled { opacity: 0.55; }
textarea { resize: vertical; }

.field { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.75rem; }
.field > span { font-size: 0.82rem; color: var(--text-muted); }
.field.inline { flex-direction: row; align-items: center; gap: 0.5rem; margin: 0; }
.field.inline select { width: auto; }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin: 0 0 0.9rem;
}
legend { color: var(--gold); padding: 0 0.35rem; font-size: 0.85rem; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 0.75rem; }
.abilities { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 0.5rem; }
.abilities label { display: flex; align-items: center; gap: 0.35rem; font-size: 0.8rem; color: var(--text-muted); }
.skills-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.35rem; }
.skills-grid label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.87rem; }
.skills-grid input { width: auto; }
.spell-slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 0.5rem; }
.spell-slots label { display: flex; flex-direction: column; align-items: center; gap: 0.2rem; font-size: 0.8rem; color: var(--text-muted); }

.collapsible {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  margin-bottom: 1rem;
  background: var(--bg-raised);
}
.collapsible > summary { cursor: pointer; color: var(--gold); font-size: 0.9rem; }
.collapsible[open] > summary { margin-bottom: 0.9rem; }

/* ---------- Étapes de création ---------- */

.step { margin-bottom: 2rem; }
.step-num {
  display: inline-grid;
  place-items: center;
  width: 1.5rem; height: 1.5rem;
  border-radius: 50%;
  background: var(--gold);
  color: #1a1410;
  font-size: 0.85rem;
  margin-right: 0.4rem;
}
.scenario-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--gap); flex-wrap: wrap; margin-bottom: 0.75rem;
}
.hint { color: var(--text-muted); font-size: 0.87rem; margin: 0; }

/* ---------- Cartes ---------- */

.card-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.card-list.compact { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }

.card {
  display: flex; flex-direction: column; gap: 0.6rem;
  justify-content: space-between;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
}
.card h3 { color: var(--text); }
.card.selectable { cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.card.selectable:hover { border-color: var(--border-strong); background: #241c14; }
.card.selected { border-color: var(--gold); background: #2a2016; }
.card.selected h3::after { content: " ✓"; color: var(--gold); }

.tag {
  display: inline-block;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  font-size: 0.75rem;
  color: var(--gold);
  margin: 0 0.25rem 0.25rem 0;
}
.tag.warn { color: var(--amber); border-color: var(--amber); }
.scenario-meta { margin: 0.35rem 0; }

/* ---------- Partie ---------- */

.game-layout { display: grid; grid-template-columns: 290px 1fr; gap: var(--gap); align-items: start; }
@media (max-width: 860px) { .game-layout { grid-template-columns: 1fr; } }

.sheet {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  position: sticky;
  top: 4.2rem;
  max-height: calc(100vh - 5.5rem);
  overflow-y: auto;
}
@media (max-width: 860px) { .sheet { position: static; max-height: none; } }

.sheet-head h2 { margin-bottom: 0.1rem; color: var(--text); font-size: 1.15rem; }
.sheet-head p { font-size: 0.85rem; }
.sheet-block { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 0.75rem; }
.sheet-block h3, .sheet-block summary { color: var(--gold); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }
.sheet-block summary { cursor: pointer; }

.hp { margin-top: 0.9rem; }
.hp-label { display: flex; justify-content: space-between; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.hp-label strong { color: var(--text); }
.hp-bar { height: 8px; background: var(--bg-input); border-radius: 999px; overflow: hidden; }
.hp-fill { height: 100%; border-radius: 999px; transition: width 0.4s ease, background 0.4s ease; }
.hp-fill.sain { background: var(--green); }
.hp-fill.blesse { background: var(--amber); }
.hp-fill.critique { background: var(--red); }

.stat-row { display: flex; gap: 0.5rem; margin-top: 0.9rem; }
.stat {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  background: var(--bg-input); border-radius: var(--radius); padding: 0.4rem;
}
.stat-val { font-size: 1.2rem; font-weight: 700; color: var(--gold); }
.stat-key { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.abilities-mini { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.25rem; margin-top: 0.6rem; }
.ability { display: flex; flex-direction: column; align-items: center; background: var(--bg-input); border-radius: 6px; padding: 0.3rem 0.1rem; }
.ability-key { font-size: 0.6rem; color: var(--text-muted); }
.ability-val { font-size: 0.85rem; font-weight: 600; }
.ability-mod { font-size: 0.7rem; color: var(--gold); }

.chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.chip { background: var(--bg-input); border: 1px solid var(--border); border-radius: 999px; padding: 0.1rem 0.55rem; font-size: 0.78rem; }
.inventory { list-style: none; margin: 0; padding: 0; font-size: 0.85rem; }
.inventory li { padding: 0.15rem 0; border-bottom: 1px solid var(--border); }
.inventory li:last-child { border-bottom: none; }

.slots { margin-top: 0.4rem; }
.slot-row { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; font-size: 0.8rem; padding: 0.15rem 0; }
.pips { color: var(--gold); letter-spacing: 0.15em; flex: 1; text-align: center; }
.slot-count { color: var(--text-muted); font-size: 0.75rem; }

/* ---------- Chat ---------- */

#chat { display: flex; flex-direction: column; gap: 0.6rem; }

#messages {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  height: min(62vh, 620px);
  overflow-y: auto;
  scroll-behavior: smooth;
}

.msg { margin-bottom: 1.1rem; }
.msg:last-child { margin-bottom: 0; }
.msg-role {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.25rem;
  color: var(--text-muted);
}
.msg.mj .msg-role { color: var(--gold); }
.msg.joueur .msg-role { color: var(--blue); }
.msg.joueur .msg-body {
  color: var(--blue);
  border-left: 2px solid var(--blue);
  padding-left: 0.7rem;
}
.msg-body > :first-child { margin-top: 0; }
.msg-body > :last-child { margin-bottom: 0; }
.msg-body h2, .msg-body h3, .msg-body h4, .msg-body h5, .msg-body h6 {
  color: var(--gold); margin: 0.8rem 0 0.3rem; font-size: 1rem;
}
.msg-body blockquote {
  margin: 0.5rem 0;
  padding: 0.4rem 0.8rem;
  border-left: 3px solid var(--gold);
  background: rgba(201, 162, 75, 0.07);
  font-style: italic;
}
.msg-body ul, .msg-body ol { margin: 0.4rem 0; padding-left: 1.3rem; }
.msg-body code { background: var(--bg-input); padding: 0.05rem 0.3rem; border-radius: 4px; font-size: 0.9em; }
.msg-body pre { background: var(--bg-input); padding: 0.6rem; border-radius: var(--radius); overflow-x: auto; }
.msg-body pre code { background: none; padding: 0; }
.msg-body hr { border: none; border-top: 1px solid var(--border); margin: 0.8rem 0; }
.table-wrap { overflow-x: auto; margin: 0.5rem 0; }
.msg-body table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
.msg-body th, .msg-body td { border: 1px solid var(--border); padding: 0.3rem 0.5rem; text-align: left; }
.msg-body th { background: var(--bg-input); color: var(--gold); }

.thinking { display: flex; align-items: center; gap: 0.35rem; color: var(--text-muted); font-size: 0.85rem; padding-left: 0.2rem; }
.thinking .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--gold); animation: blink 1.4s infinite both; }
.thinking .dot:nth-child(2) { animation-delay: 0.2s; }
.thinking .dot:nth-child(3) { animation-delay: 0.4s; }
#thinking-label { margin-left: 0.35rem; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

#chat-form, #roll-form { display: flex; gap: 0.5rem; }
#chat-input, #roll-input { flex: 1; }

#roll-request {
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 0.8rem;
  background: rgba(201, 162, 75, 0.08);
}
#roll-request-text { margin-bottom: 0.6rem; font-size: 0.9rem; }
#roll-request-text strong { color: var(--gold); }

.mic-btn { flex: 0 0 auto; border-color: var(--gold); }
.mic-btn.recording { background: var(--red); border-color: var(--red); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* ---------- Réglages vocaux (popover) ---------- */

.popover { position: relative; }
.popover > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-input);
  font-size: 0.95rem;
}
.popover > summary::-webkit-details-marker { display: none; }
.popover-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  width: min(300px, 88vw);
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0.85rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.voice-toggle { display: flex; align-items: center; gap: 0.45rem; font-size: 0.87rem; margin-bottom: 0.75rem; }
.voice-toggle input { width: auto; }
.voice-status { font-size: 0.78rem; color: var(--text-muted); margin: 0.5rem 0 0; }
.voice-status.error { color: var(--red); }

/* ---------- Notifications ---------- */

.toasts {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(360px, 90vw);
}
.toast {
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  font-size: 0.87rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  animation: slide-in 0.2s ease;
}
.toast.error { border-left-color: var(--red); }
.toast.out { opacity: 0; transform: translateX(12px); transition: opacity 0.4s, transform 0.4s; }
@keyframes slide-in { from { opacity: 0; transform: translateX(16px); } }

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

/* ==========================================================================
   Multi-joueurs
   ========================================================================== */

/* ---------- Connexion ---------- */

.auth-card {
  max-width: 24rem;
  margin: 3rem auto;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.auth-card form { display: flex; flex-direction: column; gap: 0.75rem; }
.auth-card button.primary { margin-top: 0.25rem; }

.linklike {
  background: none;
  border: none;
  color: var(--gold);
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
  font-size: inherit;
}
.linklike:hover { background: none; color: var(--gold-bright); }

/* ---------- Salon ---------- */

.lobby-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--gap);
  margin-top: var(--gap);
}
.join-form { display: flex; align-items: flex-end; gap: 0.5rem; }
.join-form input { width: 8rem; letter-spacing: 0.15em; font-family: ui-monospace, monospace; }

/* ---------- Panneau du groupe ---------- */

.party {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem;
  margin-bottom: var(--gap);
}
.party-head { display: flex; align-items: center; justify-content: space-between; gap: var(--gap); }
.party-head h3 { color: var(--gold); font-size: 0.95rem; margin: 0; }

.join-code {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0.15rem 0.5rem;
  letter-spacing: 0.1em;
}

.party-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.party-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.65rem;
}
/* Mon personnage se distingue d'un coup d'œil dans le groupe. */
.party-card.moi { border-color: var(--gold); }
.party-card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; }
.party-card p { margin: 0.25rem 0 0; }
.hp-bar.small { height: 5px; margin: 0.35rem 0 0.15rem; }

.tag.ok { color: var(--green); border-color: var(--green); }
.tag.warn { color: var(--amber); border-color: var(--amber); }

/* ---------- Attente ---------- */

.waiting {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 0.7rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}

#lobby-bar {
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 0.8rem;
  background: rgba(201, 162, 75, 0.08);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
#lobby-bar p { margin: 0; flex: 1 1 14rem; }

#force-resolve-btn { align-self: flex-start; font-size: 0.85rem; }

/* ==========================================================================
   Création de personnage assistée
   ========================================================================== */

.mode-switch { display: flex; gap: 0.4rem; margin-bottom: var(--gap); }
.mode-btn { flex: 0 1 auto; font-size: 0.85rem; }
.mode-btn.active {
  background: var(--gold);
  border-color: var(--gold);
  color: #1a1409;
  font-weight: 600;
}
.mode-btn.active:hover:not(:disabled) { background: var(--gold-bright); }

/* Notes de règles : présentes sans happer l'attention. */
.rule-note {
  font-size: 0.83rem;
  color: var(--text-muted);
  margin: 0.2rem 0 0.6rem;
  line-height: 1.45;
}
.rule-note:empty { display: none; }

.warn-text { color: var(--amber); }
.tag.warn { color: var(--amber); border-color: var(--amber); }

.methode-carac {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.7rem;
}

.assist-abilities { display: grid; gap: 0.4rem; }
.assist-ability {
  display: grid;
  grid-template-columns: 2.6rem 5.5rem 1fr auto;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 0.5rem;
}
.assist-ability-key { color: var(--gold); font-weight: 600; font-size: 0.85rem; }
.assist-ability-bonus { font-size: 0.78rem; color: var(--green); }
.assist-ability-total { font-weight: 600; font-variant-numeric: tabular-nums; }
.assist-ability-total em { color: var(--text-muted); font-style: normal; font-weight: 400; }
.assist-ability select, .assist-ability input { padding: 0.3rem 0.4rem; }

.checkbox-field { flex-direction: row; align-items: center; gap: 0.5rem; }

/* Le récapitulatif est le cœur du mode assisté : il montre le résultat des
   règles que le joueur n'a pas eu à appliquer. */
.recap {
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  background: rgba(201, 162, 75, 0.08);
  padding: 0.8rem;
  margin: var(--gap) 0;
}
.recap h4 { margin: 0 0 0.6rem; color: var(--gold); font-size: 0.9rem; }
.recap-grid { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.recap-grid > div { display: flex; flex-direction: column; align-items: center; }
.recap-val { font-size: 1.6rem; font-weight: 700; color: var(--gold-bright); line-height: 1; }
.recap-key { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.recap p { margin: 0.6rem 0 0; }

/* ---------- Bulles d'aide ---------- */

.aide-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  min-height: 0;
  padding: 0;
  margin-left: 0.3rem;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 0.7rem;
  line-height: 1;
  cursor: help;
  flex: 0 0 auto;
}
.aide-btn:hover:not(:disabled) { color: var(--gold); border-color: var(--gold); background: var(--bg-input); }

.aide-bulle {
  position: absolute;
  z-index: 40;
  background: var(--bg-raised);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 0.8rem 2rem 0.8rem 0.9rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  font-size: 0.85rem;
  line-height: 1.5;
}
.aide-bulle h4 { color: var(--gold); margin: 0 0 0.4rem; font-size: 0.92rem; }
.aide-bulle p { margin: 0 0 0.45rem; }
.aide-bulle p:last-child { margin-bottom: 0; }
.aide-fermer {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  width: 1.5rem;
  height: 1.5rem;
  min-height: 0;
  padding: 0;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
}
.aide-fermer:hover { background: none; color: var(--gold); }

.conseil {
  border-left: 2px solid var(--gold);
  padding-left: 0.6rem;
  color: var(--text-muted);
  font-size: 0.83rem;
  margin: 0.5rem 0 0;
}

/* ---------- Équipement de départ ---------- */

.equipement {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.85rem;
  margin-bottom: var(--gap);
}
.equipement:empty { display: none; }
.equipement h4 { margin: 0 0 0.45rem; color: var(--gold); font-size: 0.88rem; }
.equipement-liste { margin: 0; padding-left: 1.1rem; font-size: 0.86rem; }
.equipement-liste li { margin-bottom: 0.2rem; }

/* ---------- Compétences avec aide ---------- */

.skill-row { display: flex; align-items: center; gap: 0.15rem; }
.skill-row label { flex: 1; margin: 0; }

/* ---------- Choix des sorts ---------- */

.sorts-groupe { margin-bottom: 0.9rem; }
.sorts-groupe h5 {
  margin: 0 0 0.45rem;
  font-size: 0.85rem;
  color: var(--gold);
  font-weight: 600;
}
.sort-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  margin-bottom: 0.35rem;
  font-size: 0.86rem;
  cursor: pointer;
}
.sort-item:hover { border-color: var(--border-strong); }
.sort-item input { margin-top: 0.15rem; flex: 0 0 auto; }
.sort-item:has(input:checked) { border-color: var(--gold); background: rgba(201, 162, 75, 0.08); }

/* ---------- Fiche consultable et modifiable ---------- */

.fiche-panneau {
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  background: var(--bg-raised);
  padding: 1rem;
  margin-bottom: var(--gap);
}
.fiche-entete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: 0.8rem;
}
.fiche-entete h3 { margin: 0; color: var(--gold); font-size: 1rem; }
#fiche-contenu { display: flex; flex-direction: column; gap: 0.8rem; }
#fiche-enregistrer { margin-top: 0.9rem; }

.card-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
button.danger { color: var(--red); border-color: var(--border-strong); }
button.danger:hover:not(:disabled) { border-color: var(--red); background: rgba(212, 97, 79, 0.12); }

.equip-fixe { color: var(--text-muted); }
.equipement-liste select { width: 100%; margin: 0.15rem 0; }

/* ---------- Aide-mémoire ---------- */

#aide-memoire-contenu h4 {
  color: var(--gold);
  font-size: 0.88rem;
  margin: 1rem 0 0.4rem;
}
.table-scroll { overflow-x: auto; }
.ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
  margin-bottom: 0.5rem;
}
.ref-table th, .ref-table td {
  text-align: left;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.ref-table th { color: var(--text-muted); font-weight: 600; }
/* Les colonnes descriptives doivent revenir à la ligne, sinon le tableau
   défile sur des dizaines de centimètres. */
.ref-table td.wrap { white-space: normal; min-width: 14rem; }

/* ==========================================================================
   Téléphone — les joueurs sont sur mobile, c'est le cas nominal et non une
   adaptation de secours.
   ========================================================================== */

@media (max-width: 640px) {
  main { padding: 0.6rem; }

  .topbar { flex-wrap: wrap; gap: 0.5rem; padding: 0.5rem 0.7rem; }
  .topbar h1 { font-size: 1rem; }
  .badge { font-size: 0.72rem; max-width: 100%; }

  /* Le fil de narration prend la hauteur utile, sans repousser la saisie
     hors de l'écran. */
  #messages { height: 52vh; padding: 0.7rem; }

  .party-list { grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); }

  /* Cibles tactiles : 44 px est le minimum confortable au pouce. */
  button, .mic-btn { min-height: 44px; }
  input, select, textarea {
    min-height: 44px;
    /* 16 px empêche iOS et Chrome Android de zoomer à la mise au point. */
    font-size: 16px;
  }

  #chat-form, #roll-form { flex-wrap: wrap; }
  #chat-input, #roll-input { flex: 1 1 100%; }
  #chat-form button, #roll-form button { flex: 1; }
  .mic-btn { flex: 0 0 3.2rem; }

  .lobby-actions { flex-direction: column; align-items: stretch; }
  .join-form { width: 100%; }
  .join-form input { width: 100%; }

  .grid-2 { grid-template-columns: 1fr; }
  .abilities, .spell-slots { grid-template-columns: repeat(3, 1fr); }
  .skills-grid { grid-template-columns: 1fr 1fr; }

  .auth-card { margin: 1rem auto; padding: 1.1rem; }

  /* La ligne de caractéristique passe sur deux rangs : quatre colonnes sur un
     écran de téléphone écraseraient le champ de saisie. */
  .assist-ability {
    grid-template-columns: 2.4rem 1fr auto;
    grid-template-areas: "cle champ total" ". bonus bonus";
    row-gap: 0.2rem;
  }
  .assist-ability-key { grid-area: cle; }
  .assist-ability select, .assist-ability input { grid-area: champ; }
  .assist-ability-total { grid-area: total; }
  .assist-ability-bonus { grid-area: bonus; }

  .mode-switch { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 0.3rem 0; }
  .mode-btn { flex: 1; }
  .recap-grid { justify-content: space-around; gap: 0.8rem; }
  .ref-table { font-size: 0.78rem; }
}

/* Détail des objets d'une option d'équipement : présent mais discret, il ne
   doit pas noyer la liste des choix. */
.equip-detail {
  list-style: none;
  margin: 0.3rem 0 0.6rem;
  padding: 0 0 0 0.6rem;
  border-left: 2px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}
.equip-detail li { margin-bottom: 0.2rem; }
.equip-detail strong { color: var(--text); font-weight: 600; }

/* Barre d'expérience — même gabarit que les points de vie. */
.xp { margin-top: 0.8rem; }
.xp-label { display: flex; justify-content: space-between; font-size: 0.82rem; margin-bottom: 0.25rem; }
.xp-fill { height: 100%; background: var(--blue); transition: width 0.4s; }
.xp-monte { margin: 0.4rem 0 0; font-size: 0.82rem; color: var(--gold-bright); }

/* Bouton de relecture d'une intervention du MJ. */
.msg-role { display: flex; align-items: center; gap: 0.4rem; }
.relire {
  min-height: 0;
  padding: 0 0.3rem;
  font-size: 0.8rem;
  line-height: 1.4;
  border: 1px solid transparent;
  background: none;
  opacity: 0.55;
}
.relire:hover:not(:disabled) { opacity: 1; background: none; border-color: var(--gold); }

/* Options d'équipement présentées côte à côte, pour pouvoir les comparer. */
.equip-groupe { margin-bottom: 0.7rem; }
.equip-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 0.5rem; }
.equip-option {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  cursor: pointer;
  font-size: 0.85rem;
}
.equip-option:hover { border-color: var(--border-strong); }
.equip-option.retenue { border-color: var(--gold); background: rgba(201, 162, 75, 0.08); }
.equip-option input { width: auto; margin-top: 0.2rem; flex: 0 0 auto; }
.equip-option .equip-detail { margin-top: 0.25rem; border-left-color: var(--border-strong); }

/* Ligne de sélection du chapitre suivant. */
.chapitre-ligne { display: flex; gap: 0.5rem; align-items: center; }
.chapitre-ligne select { flex: 1; }
@media (max-width: 640px) { .chapitre-ligne { flex-direction: column; align-items: stretch; } }
