/* =============================================================================
   Mode table immersif (mobile) — plein écran paysage, texte horizontal
   Activé via body.duel-mode.duel-layout-table
   ============================================================================= */

body.duel-mode:not(.duel-layout-table) .player-card__table-face,
body.duel-mode:not(.duel-layout-table) .player-card__table-ident,
body.duel-mode:not(.duel-layout-table) .player-card__table-rounds {
  display: none;
}

body.duel-mode.duel-layout-table .player-header,
body.duel-mode.duel-layout-table .player-card__status,
body.duel-mode.duel-layout-table .life-point-action-grid,
body.duel-mode.duel-layout-table .player-card__actions {
  display: none !important;
}

body.duel-mode.duel-layout-table {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  padding: 0;
}

body.duel-mode.duel-layout-table #networkStatusBanner,
body.duel-mode.duel-layout-table .skip-link {
  display: none !important;
}

body.duel-mode.duel-layout-table .players-rail#mobilePlayerRail,
body.duel-mode.duel-layout-table .mobile-player-rail {
  display: none !important;
}

body.duel-mode.duel-layout-table .duel-table-rotator {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  width: 100%;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

/* Portrait : même écran qu’en paysage (rotation du conteneur) */
@media (orientation: portrait) {
  body.duel-mode.duel-layout-table.duel-forced-landscape {
    overflow: hidden;
    background: #05080f;
  }

  body.duel-mode.duel-layout-table.duel-forced-landscape .app-shell {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  body.duel-mode.duel-layout-table.duel-forced-landscape #duelView.duel-app-shell {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body.duel-mode.duel-layout-table.duel-forced-landscape .duel-table-rotator {
    position: absolute;
    width: 100vh;
    height: 100vw;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) rotate(90deg);
    flex: none;
    background: #05080f;
  }
}

body.duel-mode.duel-layout-table .app-header {
  display: none;
}

body.duel-mode.duel-layout-table .app-shell {
  padding: 0 !important;
  min-height: 100dvh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.duel-mode.duel-layout-table #contenu-principal.app-shell {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

body.duel-mode.duel-layout-table #duelView.duel-app-shell {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  height: auto;
  min-height: 0;
  padding: 0;
  gap: 0;
  overflow: hidden;
}

body.duel-mode.duel-layout-table .duel-app-shell__viewport {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
}
body.duel-mode.duel-layout-table .duel-command-bar,
body.duel-mode.duel-layout-table .match-status-bar,
body.duel-mode.duel-layout-table .players-rail,
body.duel-mode.duel-layout-table .duel-tools-dock {
  display: none !important;
}

body.duel-mode.duel-layout-table .duel-main {
  flex: 1 1 0;
  min-height: 0;
  height: auto;
  display: flex;
  flex-direction: column;
  padding: 0;
  border: none;
  border-radius: 0;
  background: #05080f;
  overflow: hidden;
}

body.duel-mode.duel-layout-table .players-grid {
  flex: 1 1 0;
  width: 100%;
  height: auto;
  min-height: 0;
  padding: 3px;
  gap: 3px;
  box-sizing: border-box;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  container-type: normal;
  overflow: hidden;
  align-content: stretch;
}

body.duel-mode.duel-layout-table.player-count-2 .players-grid {
  grid-template-rows: minmax(0, 1fr);
}

body.duel-mode.duel-layout-table.player-count-3 .players-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  grid-template-rows: minmax(0, 1fr) !important;
  grid-auto-rows: unset !important;
}

body.duel-mode.duel-layout-table.player-count-3 .players-grid .player-card:nth-child(1) {
  grid-column: 1 !important;
  grid-row: 1 !important;
  max-width: none !important;
  justify-self: stretch !important;
}

body.duel-mode.duel-layout-table.player-count-3 .players-grid .player-card:nth-child(2) {
  grid-column: 2 !important;
  grid-row: 1 !important;
  max-width: none !important;
  justify-self: stretch !important;
}

body.duel-mode.duel-layout-table.player-count-3 .players-grid .player-card:nth-child(3) {
  grid-column: 3 !important;
  grid-row: 1 !important;
  max-width: none !important;
  justify-self: stretch !important;
}

body.duel-mode.duel-layout-table.player-count-4 .players-grid {
  grid-template-rows: repeat(2, minmax(0, 1fr));
}

/* 5 joueurs : 3 en haut, 2 centrés en bas (pyramide inversée) */
body.duel-mode.duel-layout-table.player-count-5 .players-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
  grid-template-rows: repeat(2, minmax(0, 1fr)) !important;
  grid-auto-rows: unset;
}

body.duel-mode.duel-layout-table.player-count-5 .players-grid .player-card:nth-child(1) {
  grid-column: 1 / 3 !important;
  grid-row: 1 !important;
}

body.duel-mode.duel-layout-table.player-count-5 .players-grid .player-card:nth-child(2) {
  grid-column: 3 / 5 !important;
  grid-row: 1 !important;
}

body.duel-mode.duel-layout-table.player-count-5 .players-grid .player-card:nth-child(3) {
  grid-column: 5 / 7 !important;
  grid-row: 1 !important;
}

body.duel-mode.duel-layout-table.player-count-5 .players-grid .player-card:nth-child(4) {
  grid-column: 2 / 4 !important;
  grid-row: 2 !important;
}

body.duel-mode.duel-layout-table.player-count-5 .players-grid .player-card:nth-child(5) {
  grid-column: 4 / 6 !important;
  grid-row: 2 !important;
  max-width: none !important;
  justify-self: stretch !important;
}

body.duel-mode.duel-layout-table.player-count-6 .players-grid {
  grid-template-rows: repeat(3, minmax(0, 1fr));
}

body.duel-mode.duel-layout-table .player-card {
  --seat-hue: calc(36 + (var(--seat-index, 0) * 43));
  container-type: size;
  position: relative;
  min-height: 0;
  height: 100%;
  border: none;
  border-radius: 10px;
  padding: 0;
  overflow: hidden;
  background: linear-gradient(
    165deg,
    hsl(var(--seat-hue) 46% 30%) 0%,
    hsl(var(--seat-hue) 40% 17%) 100%
  );
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 2px 10px rgba(0, 0, 0, 0.38);
}

body.duel-mode.duel-layout-table .player-card.is-winner {
  box-shadow:
    inset 0 0 0 2px var(--duel-gold-ui),
    0 0 22px color-mix(in srgb, var(--duel-gold-ui) 28%, transparent);
}

body.duel-mode.duel-layout-table .player-card.is-eliminated {
  opacity: 0.55;
  filter: saturate(0.65);
}

body.duel-mode.duel-layout-table .player-card__inner {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 2.5cqh, 12px);
  min-height: 0;
  transform: none;
}

body.duel-mode.duel-layout-table .player-card__table-ident {
  order: 1;
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 0 clamp(6px, 3cqw, 14px);
  box-sizing: border-box;
}

body.duel-mode.duel-layout-table .player-card__table-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(4px, 1.6vmin, 8px);
  max-width: 100%;
  text-align: center;
  line-height: 1.2;
}

body.duel-mode.duel-layout-table .player-card__table-name {
  font-family: var(--duel-font-display);
  font-size: clamp(0.78rem, 3.6vmin, 1.05rem);
  font-weight: 800;
  color: rgba(255, 255, 255, 0.95);
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: min(100%, 18ch);
}

body.duel-mode.duel-layout-table .life-point-display {
  order: 2;
  flex: 0 0 auto;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  display: flex;
  justify-content: center;
  width: 100%;
}

body.duel-mode.duel-layout-table .player-card__table-rounds {
  order: 3;
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: clamp(4px, 1.4vmin, 7px);
  width: 100%;
  margin: 0;
  padding: 0;
}

body.duel-mode.duel-layout-table .player-card__table-rounds span {
  width: clamp(9px, 2.6vmin, 14px);
  height: clamp(9px, 2.6vmin, 14px);
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.28);
  box-sizing: border-box;
}

body.duel-mode.duel-layout-table .player-card__table-rounds .is-won {
  border-color: var(--duel-gold-ui, #f4b942);
  background: var(--duel-gold-ui, #f4b942);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--duel-gold-ui, #f4b942) 22%, transparent);
}

body.duel-mode.duel-layout-table .player-card__seat {
  font-family: var(--duel-font-display);
  font-size: clamp(0.68rem, 2.8vmin, 0.88rem);
  font-weight: 800;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.72);
  flex: 0 0 auto;
}

.duel-table-round-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 45;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(92vw, 420px);
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: color-mix(in srgb, var(--surface, #12151d) 92%, transparent);
  backdrop-filter: blur(16px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
  text-align: center;
  pointer-events: auto;
}

.duel-table-round-banner.is-hidden {
  display: none;
}

.duel-table-round-banner__text {
  margin: 0;
  font-family: var(--duel-font-display);
  font-size: clamp(0.95rem, 3.8vmin, 1.15rem);
  font-weight: 800;
  color: var(--text, #f4f1ea);
  line-height: 1.35;
}

.duel-table-round-banner__btn {
  min-height: 48px;
  min-width: 200px;
  padding: 0 20px;
  border: none;
  border-radius: 999px;
  background: var(--duel-cyan, #19b6a2);
  color: #041018;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
}

body.duel-mode.duel-layout-table .player-card__vitality {
  font-size: clamp(0.68rem, 2.8vmin, 0.9rem);
  color: #ff7080;
  line-height: 1;
  flex: 0 0 auto;
}

body.duel-mode.duel-layout-table .player-card__vitality.is-out {
  color: rgba(255, 255, 255, 0.35);
}

body.duel-mode.duel-layout-table .life-point-display__toggle {
  width: auto;
  height: auto;
  min-height: 44px;
  padding: 4px 8px;
}

body.duel-mode.duel-layout-table .life-point-display__value,
body.duel-mode.duel-layout-table .player-lp-value {
  font-size: clamp(1.5rem, 24cqh, 4.2rem) !important;
  color: #fff;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
}

body.duel-mode.duel-layout-table .life-point-display__unit {
  display: none;
}

body.duel-mode.duel-layout-table .duel-table-chrome:not(.is-hidden) {
  display: flex;
  position: absolute;
  inset: auto 0 6px 0;
  z-index: 40;
  justify-content: space-between;
  align-items: flex-end;
  gap: 10px;
  padding: 0 8px;
  pointer-events: none;
}

body.duel-mode.duel-layout-table .duel-table-chrome__lp {
  pointer-events: auto;
  display: inline-flex;
  align-items: stretch;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(14px);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

body.duel-mode.duel-layout-table .duel-table-chrome__lp-btn,
body.duel-mode.duel-layout-table .duel-table-chrome__lp-value {
  min-width: 48px;
  min-height: 48px;
  padding: 0 10px;
  border: none;
  background: transparent;
  color: var(--text);
  font-weight: 800;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}

body.duel-mode.duel-layout-table .duel-table-chrome__lp-value {
  min-width: 56px;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  border-inline: 1px solid rgba(255, 255, 255, 0.12);
}

body.duel-mode.duel-layout-table .duel-table-chrome__lp-btn:first-child {
  color: color-mix(in srgb, var(--duel-danger) 90%, #fff);
}

body.duel-mode.duel-layout-table .duel-table-chrome__lp-btn:last-child {
  color: color-mix(in srgb, var(--duel-positive) 90%, #fff);
}

body.duel-mode.duel-layout-table .duel-table-chrome__menu {
  pointer-events: auto;
  display: grid;
  place-items: center;
  min-width: 52px;
  min-height: 52px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  backdrop-filter: blur(14px);
  color: var(--text);
  font-size: 1.2rem;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

body.duel-mode.duel-layout-table .duel-table-menu-backdrop {
  position: absolute;
  inset: 0;
  z-index: 80;
}

body.duel-mode.duel-layout-table .duel-table-menu {
  position: absolute;
  z-index: 90;
}

.duel-table-menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.58);
}

.duel-table-menu {
  position: fixed;
  left: 50%;
  top: 50%;
  bottom: auto;
  z-index: 90;
  width: min(94vw, 720px);
  max-height: min(88dvh, 400px);
  transform: translate(-50%, -50%);
  display: grid;
  gap: 10px 14px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.52);
  overflow-y: auto;
  box-sizing: border-box;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "head head"
    "timer tools"
    "match match"
    "foot foot";
}

body.duel-mode.duel-layout-table .duel-table-menu {
  width: min(92vw, 680px);
  max-height: min(86dvh, 360px);
}

.duel-table-menu__head {
  grid-area: head;
}

.duel-table-menu__timer {
  grid-area: timer;
}

.duel-table-menu__tools {
  grid-area: tools;
  flex-direction: column;
}

.duel-table-menu__match {
  grid-area: match;
}

.duel-table-menu__foot {
  grid-area: foot;
}

.duel-table-menu.is-hidden,
.duel-table-menu-backdrop.is-hidden {
  display: none;
}

.duel-table-menu__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.duel-table-menu__head strong {
  font-family: var(--duel-font-display);
  font-size: 1.05rem;
}

.duel-table-menu__close {
  min-width: 40px;
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.duel-table-menu__timer {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--line) 65%, transparent);
  background: color-mix(in srgb, var(--surface-2) 88%, transparent);
}

.duel-table-menu__timer-label {
  font-size: var(--duel-text-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.duel-table-menu__timer-readout {
  font-family: var(--duel-font-numeric);
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--duel-cyan);
}

.duel-table-menu__timer-readout.time-up {
  color: var(--duel-danger);
}

.duel-table-menu__timer-actions,
.duel-table-menu__tools,
.duel-table-menu__match,
.duel-table-menu__foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.duel-table-menu__timer-actions .btn,
.duel-table-menu__tools .btn,
.duel-table-menu__match .btn,
.duel-table-menu__foot .btn {
  flex: 1 1 auto;
  min-height: 44px;
}

/* ── Overrides duel-ui responsive — 3j / 5j en mode table uniquement ── */

@media (max-width: 1023px) {
  body.duel-mode.duel-layout-table.player-count-3 .players-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    grid-template-rows: minmax(0, 1fr) !important;
    grid-auto-rows: unset !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
    align-content: stretch !important;
  }

  body.duel-mode.duel-layout-table.player-count-5 .players-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
    grid-template-rows: repeat(2, minmax(0, 1fr)) !important;
    grid-auto-rows: unset !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
    align-content: stretch !important;
  }
}

@media (max-width: 767px) {
  body.duel-mode.duel-layout-table.player-count-3 .players-grid .player-card,
  body.duel-mode.duel-layout-table.player-count-5 .players-grid .player-card {
    min-height: 0 !important;
    max-height: none !important;
    overflow: hidden !important;
  }

  body.duel-mode.duel-layout-table.player-count-3 .players-grid .player-card:nth-child(3),
  body.duel-mode.duel-layout-table.player-count-5 .players-grid .player-card:nth-child(4),
  body.duel-mode.duel-layout-table.player-count-5 .players-grid .player-card:nth-child(5) {
    max-width: none !important;
    width: auto !important;
    justify-self: stretch !important;
  }
}

@media (min-width: 520px) and (max-width: 767px) and (orientation: landscape) {
  body.duel-mode.duel-layout-table.player-count-5 .players-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
    grid-template-rows: repeat(2, minmax(0, 1fr)) !important;
  }

  body.duel-mode.duel-layout-table.player-count-5 .players-grid .player-card:nth-child(5) {
    grid-column: 4 / 6 !important;
    grid-row: 2 !important;
    max-width: none !important;
    justify-self: stretch !important;
  }
}

/* ── Dialogue fin de duel (mode table / mobile) ─────────────────────── */

.duel-end-dialog {
  width: min(92vw, 520px);
  max-width: calc(100vw - 20px);
  max-height: min(92dvh, 640px);
  margin: auto;
  padding: 0;
  border: none;
  border-radius: 18px;
  background: transparent;
  color: var(--text, #f4f1ea);
  overflow: visible;
}

.duel-end-dialog::backdrop {
  background: rgba(4, 8, 15, 0.78);
  backdrop-filter: blur(6px);
}

.duel-end-dialog__panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 18px 16px;
  border-radius: 18px;
  border: 1px solid color-mix(in srgb, var(--duel-gold-ui, #f4b942) 28%, rgba(255, 255, 255, 0.14));
  background: linear-gradient(
    165deg,
    color-mix(in srgb, var(--surface, #161a24) 96%, #000) 0%,
    color-mix(in srgb, var(--surface-2, #12151d) 94%, #000) 100%
  );
  box-shadow:
    0 24px 64px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  box-sizing: border-box;
}

.duel-end-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.duel-end-dialog__title {
  margin: 0;
  font-family: var(--duel-font-display);
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.duel-end-dialog__close {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--text, #f4f1ea);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.duel-end-dialog__close:hover {
  border-color: color-mix(in srgb, var(--duel-gold-ui, #f4b942) 45%, rgba(255, 255, 255, 0.2));
  background: rgba(0, 0, 0, 0.4);
}

.duel-end-dialog__summary {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.4;
  text-align: center;
}

.duel-end-dialog__hint {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.45;
  text-align: center;
  color: var(--muted, #aeb6c2);
}

.duel-end-dialog__actions {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
  margin-top: 4px;
}

.duel-end-dialog__btn {
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text, #f4f1ea);
  font-weight: 800;
  font-size: 0.82rem;
  line-height: 1.25;
  text-align: center;
  cursor: pointer;
}

.duel-end-dialog__btn--primary {
  grid-column: span 1;
  border-color: color-mix(in srgb, var(--duel-danger, #e43d5f) 55%, rgba(255, 255, 255, 0.12));
  background: linear-gradient(
    165deg,
    color-mix(in srgb, var(--duel-danger, #e43d5f) 88%, #fff) 0%,
    color-mix(in srgb, var(--duel-danger, #e43d5f) 72%, #000) 100%
  );
  color: #fff;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--duel-danger, #e43d5f) 28%, transparent);
}

.duel-end-dialog__btn--ghost {
  grid-column: 1 / -1;
  background: transparent;
  color: var(--muted, #aeb6c2);
  font-weight: 700;
}

@media (max-width: 520px) {
  .duel-end-dialog__actions {
    grid-template-columns: 1fr;
  }

  .duel-end-dialog__btn--primary {
    grid-column: auto;
  }
}
