/* =========================================================
   ANT TACTIC - STYLE.CSS (clean)
   ========================================================= */

/* ---------- Variables ---------- */
:root {
  --bg: #0b1220;
  --panel: #162033;
  --panel-alt: #0f1827;
  --panel-border: #2b3a55;
  --text: #e5edf9;
  --muted: #a3b2cc;

  --offense: #ef4444;
  --defense: #3b82f6;
  --success: #22c55e;
  --warning: #f59e0b;
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);

  /* Layout global */
  display: flex;
  flex-direction: column;
  overflow: hidden; /* desktop: pas de scroll page */
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

/* ---------- Header ---------- */
.app-header {
  flex: 0 0 auto;
  padding: 12px 16px;
  border-bottom: 1px solid var(--panel-border);
  background: #111a2a;
}

.app-header h1 {
  margin: 0;
  font-size: 1.1rem;
}

/* ---------- Panels ---------- */
.panel {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  border-radius: 10px;
  color: var(--text);
}

/* ---------- Main Layout ---------- */
.layout {
  flex: 1 1 auto;
  min-height: 0;

  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

.left-stack {
  min-width: 0;
  min-height: 0;

  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  overflow: hidden;
}

/* ---------- Summary Panel ---------- */
.summary-panel {
  margin: 0;
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  position: sticky; /* reste visible pendant scroll du board-panel */
  top: 0;
  z-index: 2;
}

.summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.summary-header h2 {
  margin: 0;
}

.summary-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.summary-content {
  margin-top: 8px;
}

.summary-panel.is-collapsed .summary-content {
  display: none;
}

/* Boutons header summary */
.toggle-summary-btn {
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid #2a3a56;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.82rem;
}

.toggle-summary-btn:hover {
  background: #132036;
}

.end-turn-btn {
  background: #1d4ed8;
  color: #f8fafc;
  border: 1px solid #3b82f6;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
}

.end-turn-btn:hover {
  background: #2563eb;
}

.end-turn-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.2);
}

/* Cards + table summary */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 8px;
}

.summary-card {
  background: var(--panel-alt);
  border: 1px solid #2a3a56;
  border-radius: 8px;
  padding: 8px;
}

.summary-card .label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.summary-card .value {
  display: block;
  margin-top: 4px;
  font-size: 1.2rem;
  font-weight: 700;
}

.camp-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 0.85rem;
}

.camp-table th,
.camp-table td {
  border: 1px solid #2a3a56;
  padding: 6px 8px;
  text-align: left;
}

.camp-table th {
  background: var(--panel-alt);
  color: var(--muted);
  font-weight: 600;
}

/* ---------- Promotion Bar ---------- */
.promotion-bar {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: flex-start;

  margin: 8px 0 10px;
  padding: 6px 8px;
  border: 1px solid #334155;
  border-radius: 8px;
  background: #0b1220;
}

.promotion-bar--empty {
  opacity: 0.8;
}

.promotion-bar-title {
  font-weight: 700;
  color: #cbd5e1;
  margin-right: 6px;
}

.promotion-items {
  min-width: 0;
  max-height: 84px; /* hauteur fixe */
  overflow-y: auto; /* scroll interne */
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.promotion-bar.is-list .promotion-items {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}

.promotion-chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 4px 6px;
  border-radius: 999px;
  border: 1px solid #334155;
  background: #111827;
}

.promotion-chip.is-offense {
  border-color: #7f1d1d;
}

.promotion-chip.is-defense {
  border-color: #1e3a8a;
}

.promotion-focus-btn,
.promotion-activate-btn {
  border: 1px solid #475569;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
}

.promotion-focus-btn:hover,
.promotion-activate-btn:hover {
  filter: brightness(1.1);
}

.promotion-chip.is-offense .promotion-activate-btn {
  border-color: #b91c1c;
  color: #fecaca;
}

.promotion-chip.is-defense .promotion-activate-btn {
  border-color: #1d4ed8;
  color: #bfdbfe;
}

.promotion-overflow {
  color: #94a3b8;
  font-weight: 700;
}

/* ---------- Board ---------- */
.board-panel {
  min-height: 0;
  padding: 8px;
  overflow: auto; /* scroll plateau ici */
}

#board-svg {
  width: 100%;
  height: auto;
  min-height: 760px;
  display: block;
  background: var(--panel-alt);
  border-radius: 8px;
}

/* Hex tiles */
.hex {
  stroke: #334155;
  stroke-width: 1;
}

.hex--plain {
  fill: #243447;
}

.hex--edge {
  fill: #0d1422;
  stroke: #3d4f71;
  stroke-width: 1.2;
}

.hex--medical-camp-cell {
  fill: #ffffff;
  stroke: #94a3b8;
  stroke-width: 1.4;
}

/* Highlights */
.hex-highlight {
  pointer-events: none;
}

.hex-highlight--selected {
  fill: rgba(250, 204, 21, 0.25);
  stroke: #facc15;
  stroke-width: 2;
}

.hex-highlight--reachable {
  fill: rgba(34, 197, 94, 0.28);
  stroke: #22c55e;
  stroke-width: 1.4;
}

.hex-highlight--melee {
  fill: rgba(239, 68, 68, 0.28);
  stroke: #ef4444;
  stroke-width: 1.7;
}

.hex-highlight--structure {
  fill: rgba(56, 189, 248, 0.16);
  stroke: #38bdf8;
  stroke-width: 1.8;
}

/* Units */
.unit {
  cursor: pointer;
}

.unit-label {
  fill: #f8fafc;
  font-size: 10px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

.unit-ring {
  fill: none;
  stroke: #fde047;
  stroke-width: 2.5;
  pointer-events: none;
}

.unit-melee-target-ring {
  fill: none;
  stroke: #ef4444;
  stroke-width: 2;
  pointer-events: none;
}

.unit-acid-target-ring {
  fill: none;
  stroke: #a855f7;
  stroke-width: 2;
  pointer-events: none;
}

.unit--melee-target .unit-label {
  fill: #fff;
}

.unit--moved {
  opacity: 0.58;
  filter: saturate(0.65);
}

.unit--moved .unit-label {
  fill: #dbe3ef;
}

.unit--attacked {
  opacity: 0.42;
  filter: grayscale(0.9);
}

.unit--attacked .unit-label {
  fill: #e2e8f0;
}

.unit--in-medical-camp {
  animation: fadeIntoCamp 220ms ease-out forwards;
  opacity: 0.35;
  filter: saturate(0.72);
}

/* Unités actives (pulse) */
.unit-active-ready .unit-body {
  animation: activePulse 1.8s ease-in-out infinite;
}

@keyframes activePulse {
  0%,
  100% {
    opacity: 0.72;
    filter: drop-shadow(0 0 1px rgba(56, 189, 248, 0.28));
  }
  50% {
    opacity: 1;
    filter: drop-shadow(0 0 6px rgba(56, 189, 248, 0.7));
  }
}

@keyframes fadeIntoCamp {
  from { opacity: 1; }
  to   { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .unit-active-ready .unit-body {
    animation: none;
  }
}

/* Structures médicales */
.structure {
  cursor: pointer;
}

.medical-camp-selected-ring {
  fill: rgba(56, 189, 248, 0.2);
  stroke: #38bdf8;
  stroke-width: 2;
}

.medical-camp-base {
  fill: #ffffff;
  stroke: #dc2626;
  stroke-width: 1.5;
}

.medical-camp-cross {
  stroke: #dc2626;
  stroke-width: 2.8;
  stroke-linecap: round;
}

.medical-camp-smoke {
  fill: #cbd5e1;
  opacity: 0.45;
  pointer-events: none;
}

.medical-camp-hp-bg {
  fill: #111827;
  stroke: #475569;
  stroke-width: 0.6;
}

.medical-camp-hp-fill {
  fill: #22c55e;
}

/* ---------- Inspector ---------- */
.inspector-panel {
  min-height: 0;
  height: 100%;
  padding: 12px;
  overflow: hidden;

  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 10px;
}

.inspector-panel h2 {
  margin: 0;
}

.inspector-turn-status {
  margin: 0;
  padding: 0.6rem;
  border: 1px solid #334155;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.65);
}

#selected-entity {
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
  margin-bottom: 0;
}

#selected-entity small {
  color: var(--muted);
  font-size: 0.76rem;
}

.stat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.stat-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--panel-alt);
  border: 1px solid #293750;
}

.stat-list .label {
  color: var(--muted);
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
}

/* Legend (simple) */
.legend h3 {
  margin: 0 0 8px;
}

.legend ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

/* Legend collapsible (si tu utilises <details>) */
.legend-collapsible {
  border: 1px solid #2a3a56;
  border-radius: 8px;
  background: var(--panel-alt);
  padding: 6px 8px;
}

.legend-collapsible summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-weight: 600;
  user-select: none;
}

.legend-collapsible summary::-webkit-details-marker {
  display: none;
}

.legend-chevron {
  transition: transform 0.18s ease;
  font-size: 0.9rem;
  opacity: 0.9;
}

.legend-collapsible[open] .legend-chevron {
  transform: rotate(90deg);
}

.legend-collapsible ul {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

/* Dots */
.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
  margin-right: 8px;
  vertical-align: middle;
}

.dot-worker { background: #8b5a2b; }
.dot-warrior { background: #cf2a2a; }
.dot-flying { background: #5b5bd6; }
.dot-guard { background: #7a1f1f; border: 1px solid #d4af37; }
.dot-queen { background: #d4af37; }

/* ---------- Battle log (optionnel) ---------- */
.battle-log-panel {
  margin: 10px 12px 0;
  padding: 8px 10px;
  max-height: 140px;
  overflow: auto;
}

.battle-log-panel h2 {
  margin: 0 0 8px;
  font-size: 0.98rem;
}

.log-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.battle-log-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}

.battle-log-item {
  font-size: 0.82rem;
}

/* ---------- Vétérance ---------- */
.vet-stars {
  font-weight: 800;
  letter-spacing: 0.4px;
}

.vet-stars--offense {
  color: var(--offense);
  text-shadow: 0 0 6px rgba(239, 68, 68, 0.25);
}

.vet-stars--defense {
  color: var(--defense);
  text-shadow: 0 0 6px rgba(59, 130, 246, 0.25);
}

.vet-pending {
  color: var(--warning);
  font-weight: 700;
}

.vet-max {
  color: var(--success);
  font-weight: 700;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  body {
    overflow: auto; /* page scroll mobile */
  }

  .layout {
    display: block;
    overflow: visible;
    padding: 12px;
  }

  .left-stack {
    display: block;
    overflow: visible;
  }

  .summary-panel,
  .board-panel {
    margin-bottom: 12px;
    position: static;
  }

  .inspector-panel {
    display: block;
    overflow: visible;
    max-height: none;
    height: auto;
  }

  #selected-entity {
    max-height: none;
  }

  #board-svg {
    min-height: 680px;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

.surrender-btn {
  background: #7f1d1d;
  color: #fee2e2;
  border: 1px solid #ef4444;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
}

.surrender-btn:hover {
  background: #991b1b;
}

.surrender-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.game-over-banner {
  margin: 8px 0 10px;
  padding: 8px 10px;
  border: 1px solid #f59e0b;
  border-radius: 8px;
  background: rgba(245, 158, 11, 0.12);
  color: #fde68a;
  font-weight: 700;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(3px);
}

.modal-card {
  width: min(440px, calc(100vw - 32px));
  padding: 20px;
  border-radius: 14px;
  border: 1px solid #475569;
  background: #111827;
  color: #e5edf9;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
}

.modal-card h2 {
  margin: 0 0 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.modal-actions button {
  background: #1d4ed8;
  color: #f8fafc;
  border: 1px solid #3b82f6;
  border-radius: 6px;
  padding: 7px 10px;
  cursor: pointer;
}

.modal-actions button:first-child {
  background: #334155;
  border-color: #64748b;
}

.hex--black {
  fill: #000000;
  stroke: #94a3b8;
  stroke-width: 1.3;
}

.royal-warning-mark {
  fill: rgba(250, 204, 21, 0.28);
  stroke: rgba(15, 23, 42, 0.45);
  stroke-width: 0.45;
  font-size: 20px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
}

.draw-btn {
  background: #334155;
  color: #e2e8f0;
  border: 1px solid #94a3b8;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
}

.draw-btn:hover {
  background: #475569;
}

.draw-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.new-game-btn {
  background: #0f766e;
  color: #ccfbf1;
  border: 1px solid #14b8a6;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
}

.new-game-btn:hover {
  background: #0d9488;
}

.new-game-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.rules-btn {
  background: #78350f;
  color: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
}

.rules-btn:hover {
  background: #92400e;
}

.modal-card--rules {
  width: min(820px, calc(100vw - 32px));
  max-height: min(860px, calc(100vh - 32px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: visible;
  border-color: #d97706;
  background:
    radial-gradient(circle at top left, rgba(245, 158, 11, 0.16), transparent 36%),
    linear-gradient(135deg, #111827, #0f172a 58%, #1c1917);
}

.rules-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(245, 158, 11, 0.35);
}

.rules-kicker {
  color: #fbbf24;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.rules-header h2 {
  margin: 4px 0 0;
}

.rules-close-btn {
  background: transparent;
  border: 1px solid #92400e;
  color: #fef3c7;
  border-radius: 999px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 1.3rem;
}

.rules-scroll {
  overflow: auto;
  padding: 14px 4px 14px 0;
  display: grid;
  gap: 12px;
}

.rules-section {
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(15, 23, 42, 0.72);
  border-radius: 12px;
  padding: 12px 14px;
}

.rules-section--primary {
  border-color: rgba(245, 158, 11, 0.7);
  background: rgba(120, 53, 15, 0.26);
}

.rules-section h3 {
  margin: 0 0 8px;
  color: #fde68a;
}

.rules-section p,
.rules-section ul,
.rules-section ol {
  margin: 0;
}

.rules-section ul,
.rules-section ol {
  padding-left: 20px;
  display: grid;
  gap: 5px;
}

.rules-note {
  margin-top: 8px !important;
  color: #cbd5e1;
  font-size: 0.92rem;
}

.rule-tip {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-left: 5px;
  border-radius: 999px;
  background: #f59e0b;
  color: #111827;
  font-size: 12px;
  font-weight: 900;
  cursor: help;
  z-index: 10000;
}

.rule-tip::after {
  content: attr(data-tip);
  position: fixed;
  left: 50%;
  top: 28px;
  bottom: auto;
  transform: translateX(-50%);

  width: min(520px, calc(100vw - 48px));
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #f59e0b;
  background: #020617;
  color: #e5edf9;

  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.35;

  opacity: 0;
  pointer-events: none;
  z-index: 999999;

  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.55);
}

.rule-tip:hover::after,
.rule-tip:focus::after {
  opacity: 1;
}

.rules-footer {
  padding-top: 12px;
  border-top: 1px solid rgba(245, 158, 11, 0.35);
  display: flex;
  justify-content: flex-end;
}

.rules-footer button {
  background: #92400e;
  color: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 7px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 700;
}

.ai-status {
  margin-top: 8px;
  padding: 7px 9px;
  border: 1px solid #22d3ee;
  border-radius: 7px;
  background: rgba(8, 145, 178, 0.14);
  color: #a5f3fc;
  font-weight: 700;
  font-size: 0.84rem;
}

/* Promotions : remplissage horizontal puis retour ligne.
   On évite la liste verticale scrollable qui se remet en haut. */

.promotion-bar,
.promotion-bar.is-wrap,
.promotion-bar.is-list {
  overflow: visible;
}

.promotion-bar .promotion-items,
.promotion-bar.is-wrap .promotion-items,
.promotion-bar.is-list .promotion-items {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  align-content: flex-start;
  gap: 0.35rem 0.45rem;

  max-height: none;
  overflow: visible;

  padding: 0.25rem 0;
}

.promotion-chip {
  display: inline-flex;
  align-items: stretch;
  flex: 0 0 auto;
  max-width: 100%;
  white-space: nowrap;
}

.promotion-focus-btn {
  flex: 0 0 auto;
}

.promotion-activate-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.sound-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
  padding: 0.35rem 0.45rem;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 0.55rem;
  background: rgba(15, 23, 42, 0.22);
  font-size: 0.82rem;
}

.sound-controls-label {
  margin-right: auto;
  font-weight: 700;
  opacity: 0.78;
}

.sound-toggle-btn {
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 0.4rem;
  background: rgba(15, 23, 42, 0.35);
  color: inherit;
  cursor: pointer;
  padding: 0.18rem 0.35rem;
}

.sound-toggle-btn:hover {
  background: rgba(250, 204, 21, 0.15);
}

.sound-volume-range {
  width: 92px;
  accent-color: #facc15;
}

.sound-volume-value {
  min-width: 2.6rem;
  text-align: right;
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
}

/* Correction chevauchement inspecteur */
/* Ordre fixe des blocs dans l'inspecteur */
.inspector-panel {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  overflow-y: auto !important;
}

.inspector-panel > .sound-controls {
  order: 0 !important;
  flex: 0 0 auto !important;
}

.inspector-panel > h2 {
  order: 1 !important;
  flex: 0 0 auto !important;
}

.inspector-panel > #inspector-turn-status {
  order: 2 !important;
  flex: 0 0 auto !important;
  position: static !important;
  display: block !important;
  margin-bottom: 0.9rem !important;
  padding-bottom: 0.65rem !important;
  border-bottom: 1px solid rgba(148, 163, 184, 0.22);
}

.inspector-panel > #selected-entity {
  order: 3 !important;
  flex: 0 0 auto !important;
  position: static !important;
  display: block !important;
  margin-top: 0 !important;
}

.inspector-panel > .legend {
  order: 4 !important;
  flex: 0 0 auto !important;
}

#inspector-turn-status h3,
#selected-entity h3 {
  position: static !important;
  display: block !important;
  float: none !important;
  clear: both !important;
  margin: 0 0 0.55rem 0 !important;
  line-height: 1.25 !important;
}