/* =============================================================================
   Quasar Duel — Interface de table (duel)
   Design system + layout multi-joueurs (2–6), responsive natif.
   Scoped sous body.duel-mode pour remplacer l’ancien plateau.
   ============================================================================= */

body.duel-mode {
  min-height: 100dvh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;

  /* —— Breakpoints (référence) —— */
  --duel-bp-sm: 360px;
  --duel-bp-md: 768px;
  --duel-bp-lg: 1024px;
  --duel-bp-xl: 1440px;

  /* —— Spacing —— */
  --duel-space-2xs: clamp(2px, 0.35vw, 4px);
  --duel-space-xs: clamp(4px, 0.5vw, 6px);
  --duel-space-sm: clamp(6px, 0.75vw, 10px);
  --duel-space-md: clamp(10px, 1.1vw, 16px);
  --duel-space-lg: clamp(14px, 1.5vw, 22px);

  /* —— Radius —— */
  --duel-radius-sm: 8px;
  --duel-radius-md: 12px;
  --duel-radius-lg: 16px;
  --duel-radius-pill: 999px;

  /* —— Borders —— */
  --duel-border-subtle: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
  --duel-border-glow: 1px solid color-mix(in srgb, var(--accent-2, #19b6a2) 28%, transparent);

  /* —— Shadows —— */
  --duel-shadow-card: 0 8px 28px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --duel-shadow-elevated: 0 16px 40px rgba(0, 0, 0, 0.42);
  --duel-shadow-inset: inset 0 0 24px rgba(0, 0, 0, 0.28);

  /* —— Surfaces —— */
  --duel-surface-glass: color-mix(in srgb, var(--surface) 82%, transparent);
  --duel-surface-card: linear-gradient(
    165deg,
    color-mix(in srgb, var(--surface-2) 92%, #0d1528 8%),
    color-mix(in srgb, var(--surface) 88%, #060a12 12%)
  );
  --duel-surface-lp: radial-gradient(
      circle at 50% 38%,
      color-mix(in srgb, var(--accent-2, #19b6a2) 14%, transparent),
      transparent 55%
    ),
    linear-gradient(180deg, rgba(4, 14, 32, 0.55), rgba(8, 18, 40, 0.82));

  /* —— Accent palette —— */
  --duel-cyan: #39d8ff;
  --duel-violet: #8b6cf6;
  --duel-gold-ui: var(--gold, #f0c04d);
  --duel-positive: var(--accent-2, #19b6a2);
  --duel-danger: var(--danger, #ef5c50);
  --duel-warning: var(--gold, #f0c04d);

  /* —— Typography —— */
  --duel-font-display: var(--font-display, "Syne", sans-serif);
  --duel-font-body: var(--font-body, "DM Sans", sans-serif);
  --duel-font-numeric: var(--font-numeric, "DM Sans", monospace);
  --duel-text-xs: clamp(0.58rem, 1.4dvh, 0.72rem);
  --duel-text-sm: clamp(0.66rem, 1.6dvh, 0.82rem);
  --duel-text-md: clamp(0.78rem, 1.9dvh, 0.95rem);
  --duel-text-lg: clamp(0.92rem, 2.2dvh, 1.12rem);

  /* —— Layout shell —— */
  --duel-header-h: clamp(34px, 7.5dvh, 48px);
  --duel-timer-h: clamp(44px, 8dvh, 56px);
  --duel-tools-h: clamp(40px, 7dvh, 52px);
  --duel-gap: var(--duel-space-xs);
  --duel-touch-min: 40px;

  /* —— LP scale (overridden per player count / density) —— */
  --duel-lp-font: clamp(2rem, min(12dvh, 10vw, 18cqi), 5rem);
  --duel-name-font: clamp(0.78rem, 1.2vw, 1rem);
  --duel-status-font: var(--duel-text-xs);
  --duel-button-font: clamp(0.62rem, 1.1vw, 0.82rem);
  --duel-card-pad: var(--duel-space-sm);

  width: 100%;
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  background-image: var(--bg-pattern),
    radial-gradient(ellipse 120% 80% at 50% -20%, rgba(57, 216, 255, 0.06), transparent 50%),
    radial-gradient(ellipse 80% 60% at 100% 100%, rgba(139, 108, 246, 0.05), transparent 45%);
}

/* —— Density tokens —— */
body.duel-mode.density-comfortable {
  --duel-card-pad: clamp(8px, 1.2dvh, 14px);
  --duel-gap: clamp(6px, 0.9dvh, 10px);
  --duel-touch-min: 44px;
}

body.duel-mode.density-compact {
  --duel-card-pad: clamp(5px, 0.85dvh, 9px);
  --duel-gap: clamp(4px, 0.65dvh, 7px);
  --duel-touch-min: 40px;
}

body.duel-mode.density-dense {
  --duel-card-pad: clamp(4px, 0.6dvh, 7px);
  --duel-gap: clamp(3px, 0.5dvh, 5px);
  --duel-touch-min: 36px;
}

/* —— LP scale per player count —— */
body.duel-mode.player-count-2 {
  --duel-lp-font: clamp(2.4rem, min(14dvh, 11vw, 20cqi), 5.4rem);
}

body.duel-mode.player-count-3 {
  --duel-lp-font: clamp(1.85rem, min(11dvh, 8.5vw, 17cqi), 4.2rem);
}

body.duel-mode.player-count-4 {
  --duel-lp-font: clamp(1.5rem, min(8.5dvh, 7vw, 14cqi), 3.2rem);
}

body.duel-mode.player-count-5,
body.duel-mode.player-count-6 {
  --duel-lp-font: clamp(1.15rem, min(6.5dvh, 5.5vw, 11cqi), 2.5rem);
  --duel-name-font: clamp(0.66rem, 1vw, 0.86rem);
  --duel-button-font: clamp(0.54rem, 0.9vw, 0.7rem);
}

body.duel-mode.player-count-5.density-dense,
body.duel-mode.player-count-6.density-dense {
  --duel-lp-font: clamp(1rem, min(5.8dvh, 4.8vw, 10cqi), 2.15rem);
}

/* —— Portrait : défilement naturel —— */
@media (orientation: portrait) {
  body.duel-mode {
    max-height: none;
    min-height: 100dvh;
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body.duel-mode .app-shell {
    overflow: visible;
    max-height: none;
  }
}

/* —— App shell en mode duel —— */
body.duel-mode .app-shell {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  min-height: 0;
  margin: 0;
  padding: var(--duel-gap) max(6px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom))
    max(6px, env(safe-area-inset-left));
  overflow: hidden;
}

body.duel-mode .app-header {
  flex: 0 0 var(--duel-header-h);
  min-height: 0;
  max-height: var(--duel-header-h);
  padding: 2px max(8px, env(safe-area-inset-right)) 2px max(8px, env(safe-area-inset-left));
  border-bottom: var(--duel-border-subtle);
  background: var(--duel-surface-glass);
  backdrop-filter: blur(12px);
}

/* =============================================================================
   DuelAppShell
   ============================================================================= */

body.duel-mode #duelView.duel-app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--duel-gap);
  flex: 1 1 0;
  width: 100%;
  min-height: 0;
  max-height: none;
  overflow: hidden;
}

body.duel-mode .duel-app-shell__viewport {
  display: contents;
}

/* =============================================================================
   TimerPanel + GlobalControls (command bar)
   ============================================================================= */

body.duel-mode .duel-command-bar {
  grid-row: 1;
  min-height: 0;
  z-index: 2;
}

body.duel-mode .timer-panel {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: var(--duel-space-sm);
  min-height: var(--duel-timer-h);
  padding: var(--duel-space-xs) var(--duel-space-md);
  border-radius: var(--duel-radius-md);
  border: var(--duel-border-subtle);
  background: var(--duel-surface-glass);
  backdrop-filter: blur(14px);
  box-shadow: var(--duel-shadow-card);
}

body.duel-mode .timer-panel__label {
  font-family: var(--duel-font-body);
  font-size: var(--duel-text-xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

body.duel-mode .timer-panel__readout,
body.duel-mode #timerDisplay {
  font-family: var(--duel-font-numeric);
  font-size: clamp(1.1rem, 4.2dvh, 1.75rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--duel-cyan);
  text-shadow: 0 0 20px color-mix(in srgb, var(--duel-cyan) 35%, transparent);
}

body.duel-mode .timer-panel {
  flex-shrink: 0;
}

body.duel-mode .timer-panel__readout,
body.duel-mode #timerDisplay {
  min-height: 1em;
}

body.duel-mode .timer-panel__actions {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--duel-space-2xs);
}

/* =============================================================================
   Duel main area
   ============================================================================= */

body.duel-mode .duel-main {
  grid-row: 2;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--duel-gap);
  min-height: 0;
  height: 100%;
  padding: var(--duel-space-xs);
  border-radius: var(--duel-radius-lg);
  border: var(--duel-border-subtle);
  background: color-mix(in srgb, var(--surface) 40%, transparent);
  overflow: hidden;
}

/* =============================================================================
   MatchStatusBar
   ============================================================================= */

body.duel-mode .match-status-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: var(--duel-space-xs) var(--duel-space-sm);
  padding: var(--duel-space-xs) var(--duel-space-sm);
  border-radius: var(--duel-radius-sm);
  border: var(--duel-border-subtle);
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
  overflow: hidden;
}

body.duel-mode .match-status-bar__main {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: var(--duel-space-sm);
  min-width: 0;
  overflow: hidden;
}

body.duel-mode .match-status-bar__kicker {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: var(--duel-radius-pill);
  font-size: var(--duel-text-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--duel-gold-ui);
  background: color-mix(in srgb, var(--duel-gold-ui) 12%, transparent);
}

body.duel-mode .match-status-bar__headline {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--duel-text-md);
  line-height: 1.15;
}

body.duel-mode .match-status-bar__score {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--duel-text-xs);
  color: var(--muted);
}

body.duel-mode .match-status-bar__actions {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-wrap: nowrap;
  gap: var(--duel-space-2xs);
}

body.duel-mode .recent-action-panel {
  grid-column: 1 / -1;
  grid-row: 2;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: nowrap;
  gap: var(--duel-space-sm);
  overflow: hidden;
  color: var(--muted);
  font-size: var(--duel-text-xs);
  line-height: 1.2;
}

body.duel-mode .recent-action-panel li {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.duel-mode.density-dense .recent-action-panel li:not(:first-child),
body.duel-mode.player-count-5 .recent-action-panel li:not(:first-child),
body.duel-mode.player-count-6 .recent-action-panel li:not(:first-child) {
  display: none;
}

/* =============================================================================
   PlayersGrid — CSS Grid déterministe par nombre de joueurs
   ============================================================================= */

body.duel-mode .players-grid {
  container-type: size;
  container-name: players-grid;
  min-height: clamp(220px, 42dvh, 640px);
  height: 100%;
  display: grid;
  gap: var(--duel-gap);
  overflow: hidden;
  align-items: stretch;
  align-content: stretch;
}

/* 2 joueurs : 2 colonnes symétriques */
body.duel-mode.player-count-2 .players-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: minmax(0, 1fr);
}

/* 3 joueurs : 3 colonnes desktop */
body.duel-mode.player-count-3 .players-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: minmax(0, 1fr);
}

/* 4 joueurs : 2×2 */
body.duel-mode.player-count-4 .players-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
}

/* 5 joueurs : 3 + 2 aligné */
body.duel-mode.player-count-5 .players-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
}

body.duel-mode.player-count-5 .players-grid .player-card:nth-child(4) {
  grid-column: 1 / 2;
}

body.duel-mode.player-count-5 .players-grid .player-card:nth-child(5) {
  grid-column: 3 / 4;
}

/* 6 joueurs : 3×2 */
body.duel-mode.player-count-6 .players-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
}

/* =============================================================================
   PlayerCard
   ============================================================================= */

body.duel-mode .player-card {
  container-type: inline-size;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--duel-space-2xs);
  padding: var(--duel-card-pad);
  border-radius: var(--duel-radius-md);
  border: var(--duel-border-subtle);
  background: var(--duel-surface-card);
  box-shadow: var(--duel-shadow-card);
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

body.duel-mode .player-card::before,
body.duel-mode .player-card::after {
  display: none;
}

body.duel-mode .player-card.is-winner {
  border-color: color-mix(in srgb, var(--duel-gold-ui) 55%, transparent);
  box-shadow: var(--duel-shadow-card), 0 0 24px color-mix(in srgb, var(--duel-gold-ui) 18%, transparent);
}

body.duel-mode .player-card.is-eliminated {
  opacity: 0.62;
  filter: saturate(0.75);
}

/* PlayerHeader */
body.duel-mode .player-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--duel-space-xs);
  min-height: 0;
}

body.duel-mode .player-header__avatar {
  width: clamp(24px, 5dvh, 36px);
  height: clamp(24px, 5dvh, 36px);
  min-width: clamp(24px, 5dvh, 36px);
  display: grid;
  place-items: center;
  border-radius: var(--duel-radius-pill);
  font-size: var(--duel-text-sm);
  font-weight: 800;
  background: linear-gradient(135deg, color-mix(in srgb, var(--duel-cyan) 35%, var(--surface-2)), var(--surface));
  border: 1px solid color-mix(in srgb, var(--duel-cyan) 25%, transparent);
}

body.duel-mode .player-header__ident {
  min-width: 0;
  display: grid;
  gap: 1px;
  text-align: left;
}

body.duel-mode .player-header__name {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--duel-font-display);
  font-size: var(--duel-name-font);
  line-height: 1.1;
}

body.duel-mode .player-header__deck {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--duel-text-xs);
  color: var(--muted);
  line-height: 1.1;
}

body.duel-mode .player-header__team {
  flex-shrink: 0;
  padding: 2px 6px;
  border-radius: var(--duel-radius-pill);
  font-size: var(--duel-text-xs);
  font-weight: 700;
  background: color-mix(in srgb, var(--duel-violet) 18%, transparent);
  color: color-mix(in srgb, var(--duel-violet) 80%, var(--text));
}

body.duel-mode .player-round-controls {
  display: flex;
  flex-wrap: nowrap;
  gap: 3px;
  flex-shrink: 0;
}

body.duel-mode .player-round-controls span {
  width: 7px;
  height: 7px;
  border-radius: var(--duel-radius-pill);
  background: color-mix(in srgb, var(--line) 80%, transparent);
}

body.duel-mode .player-round-controls span.is-won {
  background: var(--duel-gold-ui);
  box-shadow: 0 0 8px color-mix(in srgb, var(--duel-gold-ui) 50%, transparent);
}

body.duel-mode.density-dense .player-header__deck,
body.duel-mode.player-count-5 .player-header__deck,
body.duel-mode.player-count-6 .player-header__deck {
  display: none;
}

/* LifePointDisplay */
body.duel-mode .life-point-display {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: clamp(4px, 0.8dvh, 10px);
  border-radius: var(--duel-radius-md);
  border: var(--duel-border-glow);
  background: var(--duel-surface-lp);
  box-shadow: var(--duel-shadow-inset);
  overflow: hidden;
}

body.duel-mode .life-point-display__toggle {
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
}

body.duel-mode .life-point-display__score {
  display: grid;
  place-items: center;
  gap: 2px;
}

body.duel-mode .life-point-display__value,
body.duel-mode .player-lp-value {
  font-family: var(--duel-font-numeric);
  font-size: var(--duel-lp-font) !important;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 0.92;
  letter-spacing: -0.035em;
  color: var(--text);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

body.duel-mode .life-point-display__unit {
  font-size: var(--duel-text-xs);
  font-weight: 800;
  letter-spacing: 0.16em;
  color: color-mix(in srgb, var(--duel-cyan) 70%, var(--muted));
}

/* Status row */
body.duel-mode .player-card__status {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--duel-space-xs);
  font-size: var(--duel-status-font);
  line-height: 1;
}

body.duel-mode .player-card__status span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

body.duel-mode .player-card__status strong {
  padding: 2px 8px;
  border-radius: var(--duel-radius-pill);
  background: color-mix(in srgb, var(--text) 8%, transparent);
  font-variant-numeric: tabular-nums;
}

body.duel-mode.density-dense .player-card__status span {
  display: none;
}

/* LifePointActionGrid */
body.duel-mode .life-point-action-grid {
  display: grid;
  gap: var(--duel-space-2xs);
  min-height: 0;
}

body.duel-mode.player-count-2 .life-point-action-grid,
body.duel-mode.player-count-3 .life-point-action-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

body.duel-mode.player-count-4 .life-point-action-grid,
body.duel-mode.player-count-5 .life-point-action-grid,
body.duel-mode.player-count-6 .life-point-action-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* Player actions row */
body.duel-mode .player-card__actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--duel-space-2xs);
}

body.duel-mode.player-count-5 .player-card__actions,
body.duel-mode.player-count-6 .player-card__actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

body.duel-mode.player-count-5 .player-card__actions [data-player-undo],
body.duel-mode.player-count-6 .player-card__actions [data-player-undo] {
  display: none;
}

/* =============================================================================
   Boutons duel (design system)
   ============================================================================= */

body.duel-mode .btn,
body.duel-mode .life-point-action-grid button,
body.duel-mode .player-card__actions button,
body.duel-mode .timer-panel__actions button,
body.duel-mode .match-status-bar__actions button {
  min-width: 0;
  min-height: var(--duel-touch-min);
  max-height: var(--duel-touch-min);
  padding: 0 clamp(4px, 0.8vw, 10px);
  border-radius: var(--duel-radius-sm);
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  background: color-mix(in srgb, var(--surface-2) 85%, transparent);
  color: var(--text);
  font-family: var(--duel-font-body);
  font-size: var(--duel-button-font);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}

body.duel-mode .btn:hover:not(:disabled),
body.duel-mode .life-point-action-grid button:hover:not(:disabled),
body.duel-mode .player-card__actions button:hover:not(:disabled),
body.duel-mode .timer-panel__actions button:hover:not(:disabled) {
  background: color-mix(in srgb, var(--surface-2) 95%, var(--text) 5%);
  border-color: color-mix(in srgb, var(--line) 90%, var(--text) 10%);
}

body.duel-mode .btn:active:not(:disabled),
body.duel-mode .life-point-action-grid button:active:not(:disabled) {
  transform: scale(0.97);
}

body.duel-mode .btn:disabled,
body.duel-mode .life-point-action-grid button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

body.duel-mode .btn--primary {
  border-color: color-mix(in srgb, var(--duel-cyan) 45%, transparent);
  background: color-mix(in srgb, var(--duel-cyan) 18%, var(--surface-2));
  color: color-mix(in srgb, var(--duel-cyan) 90%, var(--text));
}

body.duel-mode .btn--positive,
body.duel-mode .lp-plus {
  border-color: color-mix(in srgb, var(--duel-positive) 40%, transparent);
  background: color-mix(in srgb, var(--duel-positive) 14%, var(--surface-2));
  color: color-mix(in srgb, var(--duel-positive) 85%, var(--text));
}

body.duel-mode .btn--danger,
body.duel-mode .lp-minus {
  border-color: color-mix(in srgb, var(--duel-danger) 40%, transparent);
  background: color-mix(in srgb, var(--duel-danger) 12%, var(--surface-2));
  color: color-mix(in srgb, var(--duel-danger) 88%, var(--text));
}

body.duel-mode .btn--warning {
  border-color: color-mix(in srgb, var(--duel-warning) 45%, transparent);
  background: color-mix(in srgb, var(--duel-warning) 12%, var(--surface-2));
  color: color-mix(in srgb, var(--duel-warning) 90%, var(--text));
}

body.duel-mode #timerDisplay.time-up {
  color: var(--duel-danger);
  text-shadow: 0 0 18px color-mix(in srgb, var(--duel-danger) 40%, transparent);
}

body.duel-mode.density-comfortable .life-point-action-grid button,
body.duel-mode.density-comfortable .player-card__actions button,
body.duel-mode.density-comfortable .timer-panel__actions button {
  min-height: 44px;
  max-height: 44px;
}

body.duel-mode.density-dense .life-point-action-grid button,
body.duel-mode.density-dense .player-card__actions button {
  min-height: 34px;
  max-height: 34px;
}

/* =============================================================================
   Players rail (mobile)
   ============================================================================= */

body.duel-mode .players-rail {
  display: none;
}

/* =============================================================================
   Tools dock
   ============================================================================= */

body.duel-mode .duel-tools-dock {
  grid-row: 3;
  min-height: 0;
  height: var(--duel-tools-h);
  overflow: hidden;
}

body.duel-mode .duel-tools-dock .panel-block {
  height: 100%;
  min-height: 0;
  padding: 2px max(6px, env(safe-area-inset-right)) max(2px, env(safe-area-inset-bottom))
    max(6px, env(safe-area-inset-left));
  border-radius: var(--duel-radius-md);
  border: var(--duel-border-subtle);
  background: var(--duel-surface-glass);
  backdrop-filter: blur(12px);
  overflow: hidden;
}

body.duel-mode .duel-tool-tabstrip {
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--duel-space-xs);
}

body.duel-mode .duel-tool-tab {
  min-width: 0;
  min-height: var(--duel-touch-min);
  padding: 0 var(--duel-space-sm);
  border-radius: var(--duel-radius-sm);
  border: var(--duel-border-subtle);
  background: color-mix(in srgb, var(--surface-2) 80%, transparent);
  font-size: var(--duel-text-sm);
  font-weight: 700;
  cursor: pointer;
}

body.duel-mode .duel-tool-tab[aria-selected="true"] {
  border-color: color-mix(in srgb, var(--duel-cyan) 45%, transparent);
  background: color-mix(in srgb, var(--duel-cyan) 14%, var(--surface-2));
  color: color-mix(in srgb, var(--duel-cyan) 90%, var(--text));
}

/* =============================================================================
   Responsive — Tablette (768–1023)
   ============================================================================= */

@media (max-width: 1023px) {
  body.duel-mode.player-count-3 .players-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

@media (max-width: 900px) {
  body.duel-mode.player-count-3 .players-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: auto auto;
  }

  body.duel-mode.player-count-3 .players-grid .player-card:nth-child(3) {
    grid-column: 1 / -1;
    max-width: min(100%, 420px);
    justify-self: center;
    width: 100%;
  }
}

/* =============================================================================
   Responsive — Mobile (< 768)
   ============================================================================= */

@media (max-width: 767px) {
  body.duel-mode {
    height: auto;
    min-height: 100dvh;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    --duel-header-h: clamp(40px, 10vw, 48px);
    --duel-timer-h: auto;
    --duel-touch-min: 44px;
  }

  body.duel-mode .app-shell {
    flex: none;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
    padding: 4px 8px max(8px, env(safe-area-inset-bottom));
  }

  body.duel-mode #duelView.duel-app-shell {
    display: flex;
    flex-direction: column;
    flex: none;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
    gap: var(--duel-gap);
  }

  body.duel-mode .app-header {
    flex: 0 0 auto;
    max-height: none;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px 6px;
  }

  body.duel-mode .brand-lockup h1 {
    font-size: 1rem;
    line-height: 1.1;
  }

  body.duel-mode .app-build-stamp {
    display: none;
  }

  body.duel-mode #deckBuilderButton,
  body.duel-mode #headerCollectionButton,
  body.duel-mode #newMatchButton {
    display: none !important;
  }

  body.duel-mode .header-actions {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 4px;
  }

  body.duel-mode .account-button {
    min-width: auto;
    padding: 4px 8px;
  }

  body.duel-mode .account-badge {
    max-width: 72px;
    font-size: 0.62rem;
  }

  body.duel-mode .timer-panel {
    flex-wrap: wrap;
    justify-content: space-between;
    min-height: auto;
    padding: 6px 8px;
    gap: 6px;
  }

  body.duel-mode .timer-panel__label {
    display: none;
  }

  body.duel-mode .timer-panel__readout,
  body.duel-mode #timerDisplay {
    font-size: clamp(1.25rem, 6vw, 1.6rem);
  }

  body.duel-mode .timer-panel__actions {
    flex: 1 1 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  body.duel-mode .timer-panel__actions button {
    min-height: 44px;
    max-height: none;
  }

  body.duel-mode .player-header__deck,
  body.duel-mode.density-dense .player-header__deck,
  body.duel-mode.player-count-5 .player-header__deck,
  body.duel-mode.player-count-6 .player-header__deck {
    display: block;
  }

  body.duel-mode.density-dense .player-card__status span {
    display: inline;
  }

  body.duel-mode.player-count-5 .player-card__actions [data-player-undo],
  body.duel-mode.player-count-6 .player-card__actions [data-player-undo] {
    display: inline-flex;
  }

  body.duel-mode.player-count-2 .life-point-action-grid,
  body.duel-mode.player-count-3 .life-point-action-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body.duel-mode .life-point-action-grid button,
  body.duel-mode .player-card__actions button {
    min-height: 44px;
    max-height: none;
    font-size: clamp(0.7rem, 3.2vw, 0.85rem);
  }

  body.duel-mode.player-count-2 {
    --duel-lp-font: clamp(2rem, 14vw, 3.2rem);
  }

  body.duel-mode.player-count-3 {
    --duel-lp-font: clamp(1.65rem, 11vw, 2.6rem);
  }

  body.duel-mode.player-count-4 {
    --duel-lp-font: clamp(1.4rem, 9vw, 2.2rem);
  }

  body.duel-mode.player-count-5,
  body.duel-mode.player-count-6 {
    --duel-lp-font: clamp(1.2rem, 8vw, 1.85rem);
  }

  body.duel-mode .recent-action-panel {
    display: none;
  }

  body.duel-mode .duel-tools-dock {
    position: sticky;
    bottom: 0;
    z-index: 25;
    height: auto;
    min-height: var(--duel-tools-h);
    margin-top: auto;
    background: color-mix(in srgb, var(--bg) 94%, transparent);
    backdrop-filter: blur(12px);
    padding-bottom: env(safe-area-inset-bottom);
  }

  body.duel-mode .duel-tool-tab {
    min-height: 44px;
  }

  body.duel-mode .duel-command-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(10px);
    padding-bottom: var(--duel-space-2xs);
  }

  body.duel-mode .duel-main {
    flex: none;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  body.duel-mode .players-grid {
    container-type: normal;
    min-height: 0;
    height: auto;
    overflow: visible;
    align-content: start;
  }

  body.duel-mode .player-card {
    min-height: min(50vw, 220px);
    max-height: none;
    overflow: visible;
  }

  body.duel-mode .players-rail {
    display: flex;
    flex-wrap: nowrap;
    gap: var(--duel-space-xs);
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: var(--duel-space-2xs);
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  body.duel-mode .players-rail::-webkit-scrollbar {
    display: none;
  }

  body.duel-mode .players-rail__chip {
    flex: 0 0 auto;
    display: grid;
    gap: 2px;
    min-width: 88px;
    padding: var(--duel-space-xs) var(--duel-space-sm);
    text-align: left;
  }

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

  body.duel-mode.player-count-3 .players-grid,
  body.duel-mode.player-count-4 .players-grid,
  body.duel-mode.player-count-5 .players-grid,
  body.duel-mode.player-count-6 .players-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-auto-rows: auto;
  }

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

  body.duel-mode .match-status-bar {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    gap: 6px;
  }

  body.duel-mode .match-status-bar__actions {
    grid-column: 1;
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    flex-wrap: wrap;
  }

  body.duel-mode .match-status-bar__actions button {
    min-height: 40px;
    max-height: none;
  }

  body.duel-mode .recent-action-panel {
    grid-row: 3;
    flex-direction: column;
  }

  body.duel-mode .match-status-bar__main {
    flex-wrap: wrap;
  }
}

/* 2 colonnes mobile large / petit paysage */
@media (min-width: 520px) and (max-width: 767px) and (orientation: landscape) {
  body.duel-mode.player-count-4 .players-grid,
  body.duel-mode.player-count-5 .players-grid,
  body.duel-mode.player-count-6 .players-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: minmax(0, 1fr);
  }

  body.duel-mode.player-count-5 .players-grid .player-card:nth-child(5) {
    grid-column: 1 / -1;
    max-width: 50%;
    justify-self: center;
  }
}

/* =============================================================================
   Desktop large (≥1440)
   ============================================================================= */

@media (min-width: 1440px) {
  body.duel-mode .app-shell {
    padding-inline: max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-left));
  }

  body.duel-mode .duel-main {
    padding: var(--duel-space-sm);
  }
}

/* =============================================================================
   Hauteur limitée — compacter secondaires
   ============================================================================= */

@media (max-height: 520px) and (orientation: landscape) {
  body.duel-mode {
    --duel-timer-h: 38px;
    --duel-tools-h: 36px;
    --duel-touch-min: 34px;
  }

  body.duel-mode .player-header__deck,
  body.duel-mode .recent-action-panel {
    display: none;
  }

  body.duel-mode .match-status-bar {
    grid-template-columns: minmax(0, 1fr) auto;
  }
}

body.duel-mode {
  overflow-x: clip;
}

body.duel-mode html {
  overflow-x: clip;
}

body.duel-mode .mobile-player-rail {
  display: none;
}

@media (max-width: 767px) {
  body.duel-mode:not(.duel-layout-table) .players-rail#mobilePlayerRail {
    display: flex !important;
  }
}

body.duel-mode .panel-block {
  border: none;
  box-shadow: none;
  background: transparent;
}

body.duel-mode .duel-band {
  border: none;
  background: transparent;
  box-shadow: none;
}

/* =============================================================================
   En-tête application (mode duel)
   ============================================================================= */

body.duel-mode .header-duel-actions {
  display: inline-flex;
}

body.duel-mode .header-duel-actions button {
  min-height: 32px;
  padding: 0 8px;
  font-size: max(11px, 0.68rem);
  font-weight: 700;
  white-space: nowrap;
}

body.duel-mode .header-duel-actions .primary-action {
  border-color: color-mix(in srgb, var(--duel-cyan) 45%, var(--line));
}

@media (max-width: 760px) and (orientation: landscape) {
  body.duel-mode .header-duel-actions #editSetupButton {
    max-width: 34px;
    overflow: hidden;
    color: transparent;
    position: relative;
  }

  body.duel-mode .header-duel-actions #editSetupButton::after {
    content: "Prep";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--text);
  }

  body.duel-mode #tableNewMatchButton {
    max-width: 42px;
    overflow: hidden;
    color: transparent;
    position: relative;
  }

  body.duel-mode #tableNewMatchButton::after {
    content: "Reset";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--text);
  }

  body.duel-mode #newMatchButton {
    max-width: 38px;
    overflow: hidden;
    color: transparent;
    position: relative;
  }

  body.duel-mode #newMatchButton::after {
    content: "Duel";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--text);
  }

  body.duel-mode .account-button {
    max-width: 48px;
  }
}

/* =============================================================================
   Modales outils (Hasard / Dégâts / Carte) — hors #duelView
   ============================================================================= */

body.duel-mode .duel-tool-sheet-heading {
  margin: 0;
  min-width: 0;
}

body.duel-mode .duel-tool-sheet-heading--card {
  display: flex;
  align-items: center;
  gap: 8px;
}

body.duel-mode .duel-tool-sheet-toolbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
}

body.duel-mode .duel-tool-sheet-toolbar .duel-tool-sheet-heading {
  flex: 1;
  align-self: center;
}

body.duel-mode .duel-tool-sheet-toolbar .duel-panel-close {
  flex-shrink: 0;
  align-self: center;
}

body.duel-mode #duelToolModalRoot:not(.is-hidden) .duel-tool-modal-sheets .duel-tool-sheet:not(.is-hidden) {
  position: relative;
  width: 100%;
  max-width: min(calc(100vw - 24px), 540px);
  max-height: min(68dvh, 520px);
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  margin: 0;
  padding: 10px 14px 14px;
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow), 0 20px 50px rgba(0, 0, 0, 0.42);
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

body.duel-mode #duelToolModalRoot:not(.is-hidden) .duel-tool-modal-sheets .card-lookup-block.duel-tool-sheet:not(.is-hidden) {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: 8px;
  max-width: min(calc(100vw - 24px), 560px);
  max-height: min(68dvh, 500px);
}

body.duel-mode #duelToolModalRoot:not(.is-hidden) .card-lookup-block.duel-tool-sheet:not(.is-hidden) #tableCardSearchInput {
  width: 100%;
  box-sizing: border-box;
}

body.duel-mode #duelToolModalRoot:not(.is-hidden) .card-lookup-block.duel-tool-sheet:not(.is-hidden) .table-card-preview {
  min-height: 5.5rem;
  padding: 12px 14px;
  margin-top: 2px;
  margin-bottom: 0;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--line) 65%, transparent);
  background: color-mix(in srgb, var(--surface-2) 88%, transparent);
  box-sizing: border-box;
  align-self: stretch;
}

body.duel-mode #duelToolModalRoot .damage-block #damageTarget {
  width: 100%;
  min-height: 46px;
  margin-top: 10px;
  padding: 10px 12px;
  font-size: 0.92rem;
  font-weight: 700;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  box-sizing: border-box;
}

body.duel-mode .duel-card-tab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  color: var(--gold);
}

body.duel-mode .duel-card-tab-icon .pictogram-svg {
  width: 100%;
  height: 100%;
}

@media (hover: none) and (pointer: coarse) and (min-width: 768px) {
  body.duel-mode {
    height: 100dvh;
    max-height: 100dvh;
  }

  body.duel-mode .app-shell {
    flex: 1 1 0%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding-bottom: 0;
  }

  body.duel-mode #duelView.duel-app-shell {
    flex: 1 1 0%;
    min-height: 0;
  }

  body.duel-mode .duel-tool-tab {
    min-height: 40px;
  }
}

@media (max-width: 767px) and (hover: none) and (pointer: coarse) {
  body.duel-mode {
    height: auto;
    min-height: 100dvh;
    max-height: none;
    overflow-y: auto;
  }

  body.duel-mode .app-shell,
  body.duel-mode #duelView.duel-app-shell {
    flex: none;
    min-height: 0;
    height: auto;
  }
}

@media (min-width: 981px) {
  body.duel-mode .duel-tool-tabstrip {
    position: relative;
    z-index: 150;
    padding-bottom: 4px;
    background: var(--surface);
    border-radius: 0 0 10px 10px;
  }
}

