/* Interface immersive — carte plein écran + overlays */

body.battle-immersive {
  overflow: hidden;
  background-color: #1a1208;
  background-image: url("/assets/ui/battle-command-table.jpg");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  /* Carte carrée pleine largeur ; bandes éventuelles en haut/bas seulement */
  --battle-map-size: 100vw;
}

body.battle-immersive .topbar,
body.battle-immersive #game-root > footer,
body.battle-immersive #game-status,
body.battle-immersive .battle-legacy-panel,
body.battle-immersive main > .panel:not(#map-panel),
body.battle-immersive .map-board-left,
body.battle-immersive .map-board-right,
body.battle-immersive .map-heading {
  display: none !important;
}

body.battle-immersive #game-root {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: #1a1208;
  background-image: url("/assets/ui/battle-command-table.jpg");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}

body.battle-immersive main {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body.battle-immersive #command-layout {
  height: 100%;
  margin: 0;
}

body.battle-immersive #map-panel.panel {
  position: fixed;
  inset: 0;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  z-index: 20;
}

body.battle-immersive .map-panel-stage {
  position: absolute;
  inset: 0;
  background: transparent;
}

body.battle-immersive .zone-map,
body.battle-immersive .map-board-shell {
  width: 100%;
  height: 100%;
  background: transparent;
}

body.battle-immersive .map-toolbar {
  display: none !important;
}

/* Table d'état-major derrière la carte ; visible dans les bandes haut/bas */
body.battle-immersive.in-game .map-viewport-wrap {
  padding: 0 !important;
}

body.battle-immersive .map-viewport-wrap {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  border: none;
  overflow: hidden;
  box-shadow: none;
  background-color: #1a1208;
  background-image: url("/assets/ui/battle-command-table.jpg");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}

body.battle-immersive .map-viewport-wrap::before,
body.battle-immersive .map-viewport-wrap::after {
  display: none;
}

body.battle-immersive .map-viewport {
  position: relative;
  z-index: 1;
  width: 100vw;
  height: 100vw;
  max-width: 100vw;
  min-width: 100vw;
  aspect-ratio: 1 / 1;
  margin: 0;
  flex-shrink: 0;
  overflow: hidden;
  border: 1px solid rgba(168, 144, 88, 0.35);
  background-color: #1a1208;
  background-image: url("/assets/ui/battle-command-table.jpg");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  box-shadow:
    inset 0 0 0 1px rgba(236, 226, 199, 0.12),
    0 10px 36px rgba(0, 0, 0, 0.42);
}

/* ——— Battle UI overlay ——— */

.battle-ui {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
}

body.battle-immersive .battle-ui:not([hidden]) {
  display: block;
  --battle-dock-max-h: calc(
    100dvh
    - max(0.55rem, env(safe-area-inset-top, 0px))
    - max(0.55rem, env(safe-area-inset-bottom, 0px))
    - 6.25rem
  );
}

.battle-fab {
  pointer-events: auto;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0.4rem 0.65rem;
  color: #f4e6c1;
  font-size: 0.88rem;
  font-weight: 700;
  background: rgba(14, 12, 10, 0.88);
  border: 1px solid rgba(195, 166, 90, 0.5);
  border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

.battle-fab:hover {
  background: rgba(28, 24, 18, 0.95);
  border-color: rgba(241, 202, 89, 0.7);
}

/* Menu haut gauche */

.battle-menu-wrap {
  position: absolute;
  top: max(0.55rem, env(safe-area-inset-top, 0px));
  left: max(0.55rem, env(safe-area-inset-left, 0px));
  z-index: 30;
  pointer-events: auto;
}

.battle-menu-btn {
  width: 2.75rem;
  padding: 0;
  font-size: 1.15rem;
  line-height: 1;
}

.battle-menu-popover {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  display: grid;
  gap: 0.2rem;
  min-width: 11.5rem;
  padding: 0.45rem;
  background: rgba(16, 14, 10, 0.96);
  border: 1px solid rgba(195, 166, 90, 0.45);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
}

.battle-menu-popover[hidden] {
  display: none !important;
}

.battle-menu-popover button {
  width: 100%;
  margin: 0;
  padding: 0.5rem 0.65rem;
  text-align: left;
  font-size: 0.86rem;
}

/* Bandeau haut droit */

.battle-command-bar {
  position: absolute;
  top: max(0.55rem, env(safe-area-inset-top, 0px));
  right: max(0.55rem, env(safe-area-inset-right, 0px));
  z-index: 28;
  overflow: hidden;
  isolation: isolate;
  max-width: min(36rem, calc(100vw - 5rem));
  border: 1px solid rgba(195, 166, 90, 0.42);
  border-radius: 12px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
  --battle-text-halo:
    0 0 1px #000,
    0 0 2px #000,
    0 1px 3px rgba(0, 0, 0, 0.95),
    0 -1px 3px rgba(0, 0, 0, 0.95),
    1px 0 3px rgba(0, 0, 0, 0.95),
    -1px 0 3px rgba(0, 0, 0, 0.95);
}

.battle-command-sky {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.battle-command-sky::before {
  display: none;
}

.battle-command-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.65rem;
  padding: 0.45rem 0.6rem;
  color: #fff;
  text-shadow: var(--battle-text-halo);
}

.battle-scenario-name {
  flex: 1 1 100%;
  min-width: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: var(--battle-text-halo);
}

.battle-command-bar .map-clock {
  flex-shrink: 0;
  gap: 0.35rem;
  margin: 0;
  color: #fff;
  font-size: 0.9rem;
  text-shadow: var(--battle-text-halo);
}

.battle-command-bar .map-clock-face {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.9)) drop-shadow(0 1px 3px rgba(0, 0, 0, 0.85));
}

.battle-command-bar .map-clock strong {
  color: #fff;
  font-weight: 700;
  text-shadow: var(--battle-text-halo);
}

.battle-turn,
.battle-weather {
  font-size: 0.76rem;
  color: #fff;
  font-weight: 600;
  text-shadow: var(--battle-text-halo);
}

.battle-command-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-left: auto;
}

.battle-cmd-btn {
  min-height: 2rem;
  padding: 0.28rem 0.6rem;
  font-size: 0.76rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.38);
  border: 1px solid rgba(255, 255, 255, 0.35);
  text-shadow: var(--battle-text-halo);
  cursor: pointer;
}

.battle-cmd-btn.primary {
  color: #17170f;
  background: linear-gradient(180deg, #f1ca59, #c9a860);
  border-color: #8a6a24;
  font-weight: 700;
  text-shadow: none;
}

/* Météo sur le bandeau (reprise map-heading) */

.battle-command-bar[data-weather="clear"] {
  background: linear-gradient(180deg, #5b91c7 0%, #87b5d8 58%, #d7b56a 100%);
}
.battle-command-bar[data-weather="cloudy"] {
  background: linear-gradient(180deg, #5f6f7d 0%, #8a98a4 55%, #b8a878 100%);
}
.battle-command-bar[data-weather="rain"] {
  background: linear-gradient(180deg, #3a4a58 0%, #5a6d7d 50%, #8a7a5a 100%);
}
.battle-command-bar[data-weather="fog"] {
  background: linear-gradient(180deg, #6a6e70 0%, #9a9c98 55%, #b8b0a0 100%);
}

.battle-command-bar .sky-sun,
.battle-command-bar .sky-cloud,
.battle-command-bar .sky-precip,
.battle-command-bar .sky-mist {
  display: none;
}

.battle-command-bar[data-weather="clear"] .sky-sun { display: block; }
.battle-command-bar[data-weather="clear"] .sky-cloud { display: block; opacity: 0.45; }

.battle-command-bar[data-weather="cloudy"] .sky-sun { display: block; opacity: 0.35; }
.battle-command-bar[data-weather="cloudy"] .sky-cloud { display: block; }

.battle-command-bar[data-weather="rain"] .sky-cloud { display: block; opacity: 0.7; }
.battle-command-bar[data-weather="rain"] .sky-precip { display: block; }

.battle-command-bar[data-weather="fog"] .sky-cloud { display: block; opacity: 0.35; }
.battle-command-bar[data-weather="fog"] .sky-mist { display: block; }

/* Mini-carte bas gauche */

.battle-minimap-wrap {
  position: absolute;
  left: max(0.55rem, env(safe-area-inset-left, 0px));
  bottom: max(0.55rem, env(safe-area-inset-bottom, 0px));
  z-index: 28;
  padding: 0.15rem;
  background: rgba(14, 12, 10, 0.88);
  border: 1px solid rgba(195, 166, 90, 0.45);
  border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
}

.battle-minimap {
  display: block;
  width: 132px;
  height: 132px;
  cursor: pointer;
  background: #2a3420;
}

/* Contrôles bas droite : zoom + état-major */

.battle-right-stack {
  position: absolute;
  right: max(0.55rem, env(safe-area-inset-right, 0px));
  bottom: max(0.55rem, env(safe-area-inset-bottom, 0px));
  z-index: 29;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
  pointer-events: none;
}

.battle-right-stack > * {
  pointer-events: auto;
}

.battle-zoom {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
}

.battle-zoom-btn {
  width: 2.5rem;
  padding: 0;
  text-align: center;
}

.battle-zoom-btn.is-active {
  color: #17170f;
  background: linear-gradient(180deg, #f1ca59, #c9a860);
  border-color: #8a6a24;
}

/* Dock état-major */

.battle-dock-wrap {
  position: relative;
  z-index: 1;
}

.battle-dock-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.battle-dock-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.2rem;
  height: 1.2rem;
  padding: 0 0.25rem;
  font-size: 0.68rem;
  color: #17170f;
  background: #f1ca59;
  border-radius: 999px;
}

.battle-dock-badge[hidden] {
  display: none !important;
}

.battle-dock-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.4rem);
  width: calc(
    100vw
    - max(0.55rem, env(safe-area-inset-left, 0px))
    - max(0.55rem, env(safe-area-inset-right, 0px))
  );
  height: auto;
  max-height: var(--battle-dock-max-h, calc(100dvh - 6.25rem));
  display: flex;
  flex-direction: column;
  background: rgba(14, 12, 10, 0.96);
  border: 1px solid rgba(195, 166, 90, 0.45);
  border-radius: 12px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.battle-dock-panel[hidden] {
  display: none !important;
}

.battle-dock-head {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.35rem 0.35rem 0.45rem;
  border-bottom: 1px solid rgba(195, 166, 90, 0.28);
}

.battle-dock-tabs {
  display: flex;
  flex: 1;
  gap: 0.2rem;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}
}

.battle-dock-tab {
  flex: 1 0 auto;
  margin: 0;
  padding: 0.4rem 0.35rem;
  font-size: 0.72rem;
  white-space: nowrap;
  color: #c8bc9c;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
}

.battle-dock-tab.is-active {
  color: #f1ca59;
  background: rgba(241, 202, 89, 0.12);
  border-color: rgba(241, 202, 89, 0.35);
}

.battle-dock-close {
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
  background: transparent;
  border: none;
  color: #c8bc9c;
  cursor: pointer;
}

.battle-dock-body {
  flex: 0 1 auto;
  min-height: 0;
  overflow-x: auto;
  overflow-y: auto;
  padding: 0.55rem;
}

.battle-dock-pane {
  display: none;
}

.battle-dock-pane.is-active {
  display: block;
}

.battle-dock-pane[hidden] {
  display: none !important;
}

.battle-dock-pane .map-legend {
  display: grid;
  gap: 0.4rem;
  font-size: 0.8rem;
}

.battle-dock-pane .map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.battle-table-wrap {
  overflow-x: auto;
}

.battle-table-wrap table {
  font-size: 0.8rem;
}

.battle-reports-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.45rem;
  font-size: 0.78rem;
}

.battle-reports-list {
  overflow: visible;
}

.battle-dock-pane .reports-list {
  max-height: none;
  overflow: visible;
}

.battle-dock-pane .reports-summary {
  margin-bottom: 0.45rem;
}

.battle-dock-pane .report,
.battle-dock-pane .turn-operations {
  max-width: none;
}

.battle-dock-hq-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 0.65rem;
}

.battle-dock-hq-head .eyebrow {
  margin: 0 0 0.15rem;
  font-size: 0.68rem;
}

.battle-dock-hq-title {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.2;
}

.battle-dock-hq-stats {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.battle-dock-hq-stats .stat {
  padding: 0.55rem 0.6rem;
}

.battle-dock-hq-stats .stat span {
  margin-bottom: 0.25rem;
  font-size: 0.64rem;
}

.battle-dock-hq-stats .stat strong {
  display: block;
  font-size: 0.82rem;
  line-height: 1.35;
  font-weight: 600;
}

@media (min-width: 520px) {
  .battle-dock-hq-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Fiche d'unité — milieu gauche, bouton puis déploiement */

.battle-selection-wrap {
  position: absolute;
  left: max(0.55rem, env(safe-area-inset-left, 0px));
  top: 50%;
  z-index: 28;
  transform: translateY(-50%);
  pointer-events: auto;
}

.battle-selection-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: min(11rem, calc(100vw - 12rem));
  padding: 0.35rem 0.55rem 0.35rem 0.35rem;
  text-align: left;
}

.battle-selection-toggle-thumb {
  width: 2.35rem;
  height: 1.85rem;
  flex: 0 0 auto;
  object-fit: cover;
  object-position: center top;
  border: 1px solid rgba(195, 166, 90, 0.45);
  border-radius: 4px;
  background: #2a3420;
}

.battle-selection-toggle-thumb[hidden] {
  display: none !important;
}

.battle-selection-toggle-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.78rem;
  font-weight: 700;
  color: #f4e6c1;
}

.battle-selection-panel {
  position: relative;
  width: min(15.5rem, calc(100vw - 11rem));
  max-height: min(62dvh, 24rem);
  overflow: auto;
  padding: 0.5rem 0.55rem 0.6rem;
  background: rgba(14, 12, 10, 0.94);
  border: 1px solid rgba(195, 166, 90, 0.45);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
}

.battle-selection-panel[hidden] {
  display: none !important;
}

.battle-selection-close {
  position: sticky;
  top: 0;
  z-index: 2;
  float: right;
  width: 1.85rem;
  height: 1.85rem;
  margin: -0.15rem -0.1rem 0.25rem 0.35rem;
  padding: 0;
  font-size: 1.15rem;
  line-height: 1;
  color: #c8bc9c;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(195, 166, 90, 0.35);
  border-radius: 8px;
  cursor: pointer;
}

.battle-selection-close:hover {
  color: #f1ca59;
  border-color: rgba(241, 202, 89, 0.55);
}

.battle-selection-body .board-selection-item {
  margin: 0;
}

.battle-selection-body .board-selection-chit {
  aspect-ratio: 4 / 3;
}

.battle-selection-body .board-selection-stats {
  font-size: 0.74rem;
}

/* Pied de carte : (zoom déplacé dans .battle-right-stack) */

body.battle-immersive .order-bubble.is-floating,
body.battle-immersive #deployment-bubble.order-bubble.is-floating {
  left: auto;
  transform: none;
}

body.battle-immersive .order-bubble.is-dragging,
body.battle-immersive #deployment-bubble.order-bubble.is-dragging {
  z-index: 40;
  box-shadow:
    0 22px 48px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(241, 202, 89, 0.2) inset;
}

/* Bulle d'ordre : centrée en bas */

body.battle-immersive .order-bubble,
body.battle-immersive #deployment-bubble.order-bubble {
  top: auto;
  right: auto;
  left: 50%;
  bottom: max(0.7rem, env(safe-area-inset-bottom, 0px));
  width: min(540px, calc(100vw - 9rem));
  max-height: min(58dvh, 760px);
  margin: 0;
  transform: translateX(-50%);
  border-radius: 18px;
  z-index: 35;
  pointer-events: none;
}

body.battle-immersive #deployment-bubble.order-bubble .order-bubble-heading,
body.battle-immersive #deployment-bubble.order-bubble .order-bubble-body,
body.battle-immersive #deployment-bubble.order-bubble .order-bubble-tools,
body.battle-immersive #deployment-bubble.order-bubble .order-bubble-drag-handle,
body.battle-immersive #order-bubble.order-bubble .order-bubble-heading,
body.battle-immersive #order-bubble.order-bubble .order-bubble-body,
body.battle-immersive #order-bubble.order-bubble .order-bubble-tools,
body.battle-immersive #order-bubble.order-bubble .order-bubble-drag-handle {
  pointer-events: auto;
}

body.battle-immersive .order-bubble::after {
  top: -10px;
  right: auto;
  left: 50%;
  transform: translateX(-50%) rotate(-45deg);
}

body.battle-immersive .order-bubble.is-collapsed {
  width: min(560px, calc(100vw - 6rem));
  max-width: calc(100vw - 6rem);
}

body.battle-immersive .order-bubble.is-collapsed .order-bubble-heading > div:first-child {
  flex: 1 1 100%;
  max-width: 100%;
}

body.battle-immersive .order-bubble.is-collapsed #submit-order-bar {
  min-width: 6.25rem;
  padding-inline: 0.75rem;
}

@media (max-width: 700px) {
  .battle-command-bar {
    left: max(0.55rem, env(safe-area-inset-left, 0px));
    max-width: calc(100vw - 1.1rem);
  }

  .battle-command-inner {
    padding: 0.4rem 0.5rem;
  }

  .battle-scenario-name {
    font-size: 0.72rem;
  }

  .battle-minimap {
    width: 112px;
    height: 112px;
  }

  .battle-right-stack {
    gap: 0.35rem;
  }

  .battle-selection-panel {
    width: min(14rem, calc(100vw - 8rem));
    max-height: min(56dvh, 20rem);
  }

  .battle-selection-toggle {
    max-width: min(9.5rem, calc(100vw - 8rem));
  }

  .battle-dock-panel {
    width: calc(
      100vw
      - max(0.55rem, env(safe-area-inset-left, 0px))
      - max(0.55rem, env(safe-area-inset-right, 0px))
    );
  }

  body.battle-immersive .order-bubble,
  body.battle-immersive #deployment-bubble.order-bubble {
    width: min(calc(100vw - 1.5rem), 540px);
    max-height: min(62dvh, 680px);
  }
}

@media (min-width: 901px) {
  .battle-minimap {
    width: 152px;
    height: 152px;
  }

  .battle-scenario-name {
    flex: 0 1 auto;
    max-width: 14rem;
  }
}

/* Priorité sur le mode mobile pleine largeur de style.css */
@media (max-width: 860px) {
  body.battle-immersive .order-bubble,
  body.battle-immersive #deployment-bubble.order-bubble {
    top: auto;
    left: 50%;
    right: auto;
    bottom: max(0.7rem, env(safe-area-inset-bottom, 0px));
    width: min(calc(100vw - 1.5rem), 540px);
    transform: translateX(-50%);
    border-radius: 18px;
    z-index: 35;
  }

  body.battle-immersive .order-bubble::after {
    display: block;
  }
}

/* Tutoriel au-dessus des overlays de bataille */
body.battle-immersive #scenario-tutorial-overlay {
  z-index: 50;
}

body.battle-immersive .tutorial-highlight {
  z-index: 49;
}

body.battle-immersive.scenario-tutorial-map-interact #scenario-tutorial-overlay {
  top: max(0.55rem, env(safe-area-inset-top, 0px));
  right: max(0.55rem, env(safe-area-inset-right, 0px));
  bottom: auto;
  left: max(0.55rem, env(safe-area-inset-left, 0px));
  height: auto;
  align-items: flex-start;
  justify-content: center;
  padding: 0;
  background: transparent;
}

body.battle-immersive.scenario-tutorial-map-interact #scenario-tutorial-overlay .scenario-tutorial-dialog {
  max-height: min(36dvh, 320px);
}

body.battle-immersive.scenario-tutorial-map-interact .order-bubble,
body.battle-immersive.scenario-tutorial-map-interact #deployment-bubble.order-bubble {
  z-index: 55;
}

/* Cases cliquables pendant le déploiement (zone française) */
.map-viewport.is-deployment .map-deploy-hit {
  pointer-events: auto;
  cursor: crosshair;
  z-index: 0;
}
