/* ==========================================================
   Composants communs (écran MJ et vue joueur)
   Toutes les couleurs viennent des jetons de tokens.css.
   ========================================================== */

html { scroll-padding-top: 120px; }
a { color: var(--gold); }
p { margin: 0 0 var(--sp-3); }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.hidden { display: none !important; }
.stack { display: grid; gap: var(--sp-3); }
.row-flex { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.spacer { flex: 1; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* ---------------------------------------------------------- boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--target); min-width: var(--target); padding: 0 var(--sp-4);
  border-radius: var(--radius); border: 2px solid var(--border); background: transparent; color: var(--text);
  font: 600 var(--fs-md) var(--font-body); text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--gold); color: var(--on-gold); border-color: var(--gold); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { min-height: 56px; padding: 0 var(--sp-5); font-size: var(--fs-lg); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.heal { border-color: var(--heal); color: var(--heal); }
.btn.ghost { border-color: transparent; }
.btn.compact { min-height: 36px; min-width: 36px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }
.btn[aria-pressed="true"] { background: var(--surface-2); border-color: var(--gold); }
kbd { font: inherit; font-size: var(--fs-xs); border: 1px solid currentColor; border-radius: 4px; padding: 0 5px; opacity: .85; }

/* ---------------------------------------------------------- cartes et panneaux */
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--frame); padding: var(--sp-4); min-width: 0; }
.panel > h2, .panel-title {
  font-size: var(--fs-lg); margin-bottom: var(--sp-3); display: flex; align-items: center; gap: var(--sp-3);
}
.panel > h2::after, .panel-title::after { content: ""; flex: 1; height: 2px; background: linear-gradient(90deg, var(--border), transparent); }
.empty { padding: var(--sp-5); text-align: center; color: var(--muted); border: 2px dashed var(--hairline); border-radius: var(--radius); }

/* ---------------------------------------------------------- formulaires */
.field { display: grid; gap: var(--sp-1); }
.field > label, .label { font-weight: 600; }
.field small, .help { color: var(--muted); font-size: var(--fs-sm); }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input:not([type]), select, textarea {
  width: 100%; min-height: var(--target); background: var(--bg); color: var(--text);
  border: 2px solid var(--border); border-radius: var(--radius); padding: 0 var(--sp-3);
  font: var(--fs-md) var(--font-body);
}
textarea { padding: var(--sp-2) var(--sp-3); min-height: 120px; resize: vertical; line-height: var(--lh); }
input[aria-invalid="true"] { border-color: var(--danger); }
.check { display: flex; align-items: center; gap: var(--sp-2); min-height: var(--target); cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--gold); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--sp-3); }
.form-error { color: var(--danger); font-weight: 600; }

/* ---------------------------------------------------------- pastilles d'état */
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; min-height: 28px; padding: 0 10px;
  font: 700 var(--fs-xs) var(--font-body); color: var(--text);
  border: 2px solid currentColor; background: var(--surface); border-radius: 999px; cursor: pointer;
}
button.chip { font-family: var(--font-body); }
.chip.rect { border-radius: 4px; }
.chip.crit { border-width: 3px; border-radius: 4px; background: color-mix(in srgb, currentColor 20%, var(--surface)); }
.chip .rounds { font-variant-numeric: tabular-nums; border-left: 1px solid currentColor; padding-left: 5px; }
.t-danger { color: var(--danger); } .t-warn { color: var(--warn); } .t-arcane { color: var(--arcane); }
.t-heal { color: var(--heal); } .t-gold { color: var(--gold); } .t-muted { color: var(--muted); }
.chip.more { color: var(--muted); border-style: dashed; }

/* Rappel d'un état (s'ouvre au clic, jamais au survol seul) */
.popover {
  position: absolute; z-index: 30; max-width: 300px; padding: var(--sp-3); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text); box-shadow: var(--frame), var(--shadow); font-size: var(--fs-sm);
}
.popover strong { display: block; font-family: var(--font-title); margin-bottom: 4px; }

/* ---------------------------------------------------------- PV */
.hp-text { font-weight: 700; font-variant-numeric: tabular-nums; }
.hp-bar { position: relative; height: 12px; border-radius: 3px; background: var(--hairline); overflow: hidden; margin-top: 4px; }
.hp-bar > i { position: absolute; inset: 0 auto 0 0; background: var(--heal); transition: width .2s; }
.hp-bar > b { position: absolute; inset: 0 0 0 auto; background: repeating-linear-gradient(45deg, var(--arcane) 0 4px, transparent 4px 7px); }
.hp-bar.low > i { background: var(--warn); }
.hp-bar.crit > i { background: var(--danger); }
.hp-tag { font-size: var(--fs-xs); font-weight: 700; margin-left: 6px; white-space: nowrap; }

/* ---------------------------------------------------------- onglets */
.tabs { display: flex; flex-wrap: wrap; gap: var(--sp-1); border-bottom: 2px solid var(--border); margin-bottom: var(--sp-4); }
.tabs [role="tab"] {
  min-height: var(--target); padding: 0 var(--sp-4); border: 0; border-bottom: 4px solid transparent; background: none;
  color: var(--muted); font: 600 var(--fs-md) var(--font-body); cursor: pointer;
}
.tabs [role="tab"][aria-selected="true"] { color: var(--text); border-bottom-color: var(--gold); }

/* ---------------------------------------------------------- fenêtres (dialog) */
dialog {
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: var(--frame), var(--shadow);
}
dialog::backdrop { background: var(--overlay); }
dialog .dlg-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4); border-bottom: 2px solid var(--hairline); position: sticky; top: 0; background: var(--surface); z-index: 1; }
dialog .dlg-head h2 { font-size: var(--fs-lg); flex: 1; }
dialog .dlg-body { padding: var(--sp-4); display: grid; gap: var(--sp-4); }
dialog .dlg-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-4); border-top: 2px solid var(--hairline); }

/* ---------------------------------------------------------- notifications */
.toasts { position: fixed; z-index: 50; right: var(--sp-4); bottom: var(--sp-4); display: grid; gap: var(--sp-2); width: min(440px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--radius);
  background: var(--surface-2); box-shadow: var(--frame), var(--shadow); border-left: 6px solid var(--heal);
}
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast > span { flex: 1; }
.banner { padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); background: var(--surface-2); border-left: 6px solid var(--warn); font-weight: 600; }
.banner.error { border-left-color: var(--danger); }

/* ---------------------------------------------------------- en-tête d'application */
.app-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border-bottom: 2px solid var(--border); background: var(--bg);
}
.brand { font-family: var(--font-title); font-weight: 700; font-size: var(--fs-lg); color: var(--gold); text-decoration: none; letter-spacing: .06em; }
.brand::before { content: "⚔ "; }
.breadcrumb { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; color: var(--muted); }
.breadcrumb a { color: var(--text); }
.wrap { max-width: 1280px; margin: 0 auto; padding: var(--sp-4); }

/* Menu déroulant simple (bouton + liste) */
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 240px; padding: var(--sp-2);
  display: grid; gap: var(--sp-1); background: var(--surface-2); border-radius: var(--radius); box-shadow: var(--frame), var(--shadow);
}
.menu-list .btn { justify-content: flex-start; border-color: transparent; width: 100%; }

@media (max-width: 640px) {
  .wrap { padding: var(--sp-3); }
  body { font-size: max(16px, var(--fs-md)); }
}

/* ---------------------------------------------------------- tableau vu par les joueurs (page joueur + aperçu MJ) */
.board { display: grid; gap: var(--sp-4); }
.board-head { display: grid; gap: var(--sp-1); }
.board-round { font: 700 var(--fs-xl) var(--font-title); color: var(--gold); }
.board-turn { font-size: var(--fs-lg); }
.board-turn strong { font-family: var(--font-title); }
.board-title { font: 700 var(--fs-lg) var(--font-title); color: var(--text); }
.pv-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-2); }
.pv-row {
  display: grid; grid-template-columns: 20px minmax(0, 1fr) minmax(0, 1.4fr); gap: var(--sp-3); align-items: center;
  min-height: 64px; padding: var(--sp-2) var(--sp-3); background: var(--bg); border-radius: var(--radius); border-left: 6px solid transparent;
}
.pv-row .pointer { visibility: hidden; color: var(--gold); }
.pv-row[aria-current="true"] { background: var(--surface-2); border-left-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.pv-row[aria-current="true"] .pointer { visibility: visible; }
.pv-row.is-me { box-shadow: inset 0 0 0 2px var(--arcane); }
.pv-row.is-me[aria-current="true"] { box-shadow: 0 0 0 2px var(--gold), inset 0 0 0 2px var(--arcane); }
.pv-id { display: grid; min-width: 0; }
.pv-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-name .you { color: var(--arcane); font-weight: 600; }
.pv-side { font-size: var(--fs-xs); color: var(--muted); }
.pv-row .chips { justify-content: flex-end; }
.side-enemy .pv-side::before { content: "⚔ "; }
.side-ally .pv-side::before { content: "◈ "; }
@media (max-width: 640px) {
  .pv-row { grid-template-columns: 16px minmax(0, 1fr); }
  .pv-row .chips { grid-column: 2; justify-content: flex-start; }
}
