/* ===== COMBAT VIEWER - Fidele au systeme de combat en jeu ===== */

/* --- Section fullscreen (rentre entierement dans le viewport) --- */
.cv-section {
  --cv-overhead: 10rem; /* espace header + controles */
  height: 100vh;
  padding: 0 !important;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}

.cv-section-header {
  flex-shrink: 0;
  text-align: center;
  padding: 2rem 2rem 1rem;
  width: 100%;
  max-width: 900px;
}

/* --- Layout principal --- */
.combat-viewer {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  background: #212529;
  position: relative;
}

/* --- Scene de combat (reproduit .combat-screen) --- */
/* Largeur = min(100%, hauteur disponible * 16/9) pour toujours */
/* rentrer dans le viewport tout en gardant le ratio 16:9 */
.cv-scene {
  width: min(100%, calc((100vh - var(--cv-overhead)) * 16 / 9));
  aspect-ratio: 16 / 9;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  background-color: #212529;
  background-size: cover;
  background-position: bottom;
}

.cv-background {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.cv-background img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* --- Zone de feedback (comme #combat-feedback-area) --- */
.cv-feedback-area {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 200;
  overflow: hidden;
}

/* --- Slots ennemis (reproduit .enemies-area.custom-layout .enemy-slot) --- */
.cv-enemy-slot {
  position: absolute;
  transform: translate(-50%, -100%);
  transform-origin: bottom center;
  width: 16%;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
}

.cv-enemy-slot[data-slot="0"] {
  left: 50%;
  top: 60%;
  width: 24%;
}

.cv-enemy-slot[data-slot="1"] {
  left: 22%;
  top: 50%;
}

.cv-enemy-slot[data-slot="2"] {
  left: 78%;
  top: 50%;
}

/* --- Portrait ennemi (reproduit .enemy-portrait) --- */
.cv-enemy-portrait {
  position: relative;
  transform-origin: bottom center;
  width: 100%;
  overflow: visible;
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

.cv-enemy-portrait img {
  position: relative;
  transform-origin: bottom center;
  width: auto;
  height: auto;
  max-width: 100%;
  object-fit: contain;
  will-change: transform;
  backface-visibility: hidden;
}

/* Flip pour slot 1 (Apibeia) */
.cv-enemy-slot[data-slot="1"] .cv-enemy-portrait img {
  transform: scaleX(-1);
}

/* Animation de respiration ennemis (identique au jeu, pas pour les volants) */
.cv-enemy-slot:not(.cv-pause-breathing):not(.cv-flying) .cv-enemy-portrait > img {
  animation: cv-breathe-centered 3s ease-in-out infinite;
}

.cv-enemy-slot.cv-pause-breathing .cv-enemy-portrait > img {
  animation-play-state: paused !important;
}

.cv-enemy-name {
  font-size: clamp(0.6rem, 1.5vw, 0.85rem);
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  margin-top: 2px;
  white-space: nowrap;
}

/* --- Joueur (reproduit .player-area.custom-player-slot) --- */
/* bottom negatif pour que les 30% inferieurs soient caches par overflow:hidden */
.cv-player {
  position: absolute;
  left: 32%;
  bottom: -18%;
  width: 21%;
  transform: translateX(-50%) scale(1.25);
  transform-origin: bottom center;
  z-index: 35;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
}

.cv-player-visual {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

.cv-player-visual img {
  width: 100%;
  height: auto;
  transform-origin: bottom center;
  will-change: transform;
}

/* Ombre aux pieds du joueur (identique au jeu) */
.cv-player-visual::before {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 20px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0.15) 40%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
  z-index: -1;
}

/* --- Status bars (icones de statut au-dessus des sprites) --- */
.cv-status-bar {
  display: flex;
  gap: 4px;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
}

.cv-status-bar img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

/* --- Drop zones (reproduit .drag-highlight / .drag-over du jeu) --- */
.cv-enemy-slot.drop-valid .cv-enemy-portrait img {
  filter: drop-shadow(0 0 10px rgba(255, 255, 200, 0.4));
}

.cv-enemy-slot.drop-hover .cv-enemy-portrait img {
  filter: drop-shadow(0 0 15px rgba(255, 255, 200, 0.8));
}

.cv-player.drop-valid .cv-player-visual img {
  filter: drop-shadow(0 0 10px rgba(255, 255, 200, 0.4));
}

.cv-player.drop-hover .cv-player-visual img {
  filter: drop-shadow(0 0 15px rgba(255, 255, 200, 0.8));
}

/* --- Main de cartes (superposee a la scene, a droite du joueur) --- */
.cv-hand {
  position: absolute;
  bottom: 4%;
  right: 8%;
  display: flex;
  gap: clamp(4px, 0.8vw, 10px);
  z-index: 40;
  align-items: flex-end;
}

.cv-card {
  width: clamp(55px, 10vw, 100px);
  aspect-ratio: 2 / 3;
  cursor: grab;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.2);
  transition: transform 0.25s ease, border-color 0.25s ease, opacity 0.4s ease, box-shadow 0.25s ease;
  position: relative;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.cv-card-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  pointer-events: none;
  -webkit-user-drag: none;
  user-drag: none;
}

.cv-card-cost {
  position: absolute;
  top: 3px;
  right: 3px;
  min-width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-weight: bold;
  font-size: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,0.3);
  z-index: 1;
}

.cv-card-name {
  background: linear-gradient(transparent, rgba(0,0,0,0.85) 30%);
  padding: 8px 4px 4px;
  color: #efefef;
  font-size: clamp(0.45rem, 1vw, 0.6rem);
  font-weight: bold;
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.cv-card:hover {
  transform: translateY(-8px) scale(1.08);
  border-color: rgba(218, 165, 32, 0.8);
  box-shadow: 0 3px 15px rgba(218, 165, 32, 0.3);
}

.cv-card.selected {
  transform: translateY(-12px) scale(1.08);
  border-color: #daa520;
  box-shadow: 0 0 15px rgba(218, 165, 32, 0.5), 0 0 30px rgba(218, 165, 32, 0.2);
}

.cv-card.dragging {
  opacity: 0.3;
  cursor: grabbing;
}

.cv-card.used {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

/* --- Bouton Reset --- */
.cv-reset-btn {
  display: none;
  margin: 1rem auto;
  padding: 0.7rem 2rem;
  font-size: 1rem;
  cursor: pointer;
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  transition: background 0.2s, border-color 0.2s;
  text-align: center;
}

.cv-reset-btn:hover {
  background: rgba(255,255,255,0.2);
  border-color: rgba(255,255,255,0.5);
}

.cv-reset-btn.visible {
  display: block;
}

/* --- Mobile hint --- */
.cv-mobile-hint {
  display: none;
  text-align: center;
  padding: 0.5rem;
  color: #daa520;
  font-size: 0.85rem;
}

.cv-mobile-hint.visible {
  display: block;
}

/* --- Texte flottant (reproduit .floating-text du jeu) --- */
.cv-floating-text {
  position: absolute;
  font-size: 1.4rem;
  font-weight: bold;
  padding: 3px 8px;
  border-radius: 5px;
  text-shadow: 1px 1px 3px black;
  white-space: nowrap;
  opacity: 1;
  transition: opacity 1s ease-out, transform 1s ease-out;
  transform: translateX(-50%);
  z-index: 201;
  pointer-events: none;
}

.cv-floating-text.damage {
  color: #ff4d4d;
}

.cv-floating-text.block {
  color: #87ceeb;
}

.cv-floating-text.buff {
  color: #77dd77;
}

.cv-floating-text.debuff {
  color: #ff8c00;
}

/* ===== ANIMATIONS KEYFRAMES ===== */

/* Respiration ennemi (identique a breathe-centered du jeu) */
@keyframes cv-breathe-centered {
  0%, 100% {
    transform: var(--cv-base-transform, scale(1)) rotateX(0deg);
  }
  50% {
    transform: var(--cv-base-transform, scale(1)) scale(1.01) rotateX(-1deg);
  }
}

/* Animation de vol : geree par JS (startRandomFlying dans combat-viewer.js) */
/* Les keyframes CSS deterministes ont ete remplacees par des mouvements JS aleatoires */

/* Ennemi vaincu (apres animation de mort) */
.cv-enemy-slot.cv-defeated .cv-enemy-portrait > img {
  animation: none !important;
  opacity: 0.6;
  filter: grayscale(50%);
}

/* Ombre au sol pour ennemis volants */
.cv-enemy-slot.cv-flying:not(.cv-defeated) .cv-enemy-portrait::before {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 50%;
  height: 12px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.3) 0%, transparent 70%);
  border-radius: 50%;
  opacity: 0.5;
  pointer-events: none;
}

/* Status icon appear */
@keyframes cv-status-appear {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.cv-anim-status-appear {
  animation: cv-status-appear 0.4s ease-out forwards;
}

/* Buff glow (identique au jeu) */
@keyframes cv-buff-glow {
  0% { filter: drop-shadow(0 0 0 transparent); }
  30% { filter: drop-shadow(0 0 15px rgba(100, 220, 100, 0.8)); }
  70% { filter: drop-shadow(0 0 20px rgba(218, 165, 32, 0.6)); }
  100% { filter: drop-shadow(0 0 0 transparent); }
}

/* ===== RESPONSIVE ===== */

@media (max-width: 768px) {
  .cv-section-header {
    padding: 2rem 1.5rem 1rem;
  }

  .cv-card {
    width: clamp(45px, 12vw, 75px);
  }

  .cv-enemy-name {
    font-size: 0.6rem;
  }

  .cv-status-bar img {
    width: 18px;
    height: 18px;
  }
}

@media (max-width: 480px) {
  .cv-section-header {
    padding: 1.5rem 1rem 0.8rem;
  }

  .cv-card {
    width: clamp(38px, 14vw, 60px);
  }

  .cv-hand {
    gap: 3px;
    right: 4%;
  }

  .cv-floating-text {
    font-size: 1rem;
  }

  .cv-status-bar img {
    width: 16px;
    height: 16px;
  }
}
