:root {
  --battle-header-bg: url('../../assets/art/backgrounds/bkg-library.png');
}

body {
  background: var(--color-bg-primary);
  background-image: radial-gradient(
    circle at center,
    var(--color-bg-radial-light) 0%,
    var(--color-bg-radial-dark) 70%
  );
  color: var(--color-text-primary);
  font-family: var(--font-primary);
  font-size: clamp(14px, 1.5vw, 18px);
  line-height: 1.6;
  height: 100vh;
  padding: 2vh 2vw;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.battle-container {
  width: 90%;
  max-width: 1600px;
  margin: 0 auto;
  animation: fadeIn 1s ease;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2vh;
  overflow: hidden;
  height: 100vh;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(2vh);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.battle-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2vw;
  padding: 2vh 2vw;
  border: 2px solid var(--color-stone-dark);
  border-radius: var(--size-border-radius);
  backdrop-filter: blur(5px);
  flex: 0 0 auto;

  /* bkg image with a tint, we can control this with style.setProperty in js */
  background: var(--battle-header-bg) center/cover no-repeat;
  background-color: rgba(0, 0, 0, 0.4);
  background-blend-mode: multiply;
}

.combatant {
  flex: 1;
  text-align: center;
  animation: slideIn 0.8s ease;
  position: relative;
  overflow: hidden;
}

.combatant::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 15%;
  right: 15%;
  background-color: rgba(0, 0, 0, 0.3);
  z-index: 0;
  pointer-events: none;
  border-radius: var(--size-border-radius);
}

.combatant > * {
  position: relative;
  z-index: 1;
}

.combatant--player {
  animation-delay: 0.2s;
}

.combatant--enemy {
  animation-delay: 0.4s;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-2vw);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.combatant__name {
  font-family: var(--font-heading);
  font-size: clamp(1rem, 2vw, 1.5rem);
  font-weight: 600;
  color: var(--color-text-gold);
  text-shadow: 2px 2px 4px black;
  margin-bottom: 1vh;
  letter-spacing: 1px;
}

.combatant__name--enemy {
  color: var(--color-hp);
  text-shadow: 0 0 10px var(--color-hp-glow);
}

.combatant__avatar {
  width: 15vw;
  height: 15vw;
  max-width: 250px;
  max-height: 250px;
  margin: 0 auto 1.5vh;
  position: relative;
}

.combatant__sprite {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 10px rgba(0, 0, 0, 0.5));
  transition: transform var(--transition-medium);
}

.combatant__sprite:hover {
  transform: scale(1.05);
}

.combatant--enemy .combatant__sprite:hover {
  transform: scaleX(-1) scale(1.05);
}

/* status effects area */
.combatant__stats {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-icon-stack {
  width: 1.5rem;
  max-height: calc(5 * 1.5rem + 4 * 2px);
  display: flex;
  flex-direction: row;
  gap: 2px;
  z-index: 10;
  position: relative;
}

.combatant--player .combatant__stats {
  justify-content: flex-start;
}

.combatant--enemy .combatant__stats {
  justify-content: flex-end;
}

.status-icon {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 4px;
  object-fit: cover;
  background-color: var(--color-stone-dark);
  box-shadow: var(--shadow-primary);
  border: 1px solid var(--color-stone);
  cursor: help;
  transition: border-color var(--transition-fast);
}

.status-icon:hover {
  border-color: var(--color-text-accent);
}

.status-icon-tooltip {
  position: fixed;
  background-color: var(--color-bg-primary);
  color: var(--color-text-primary);
  padding: 0.5rem 1rem;
  border: 1px solid var(--color-text-accent);
  border-radius: var(--size-border-radius);
  font-family: var(--font-body);
  font-size: 0.9rem;
  max-width: 20vw;
  line-height: 1.4;
  text-align: left;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(0px);
  transition:
    opacity var(--transition-fast),
    transform var(--transition-fast);
  z-index: 999;
}

.status-icon-tooltip.is-visible {
  opacity: 1;
  visibility: visible;
}

.stat-bar__wrapper {
  position: relative;
  width: 100%;
}

.stat-bar__label-inside {
  white-space: nowrap;
  position: absolute;
  top: 50%;
  left: 16%;
  transform: translate(-50%, -50%);
  color: var(--color-text-primary);
  font-size: 0.8rem;
  pointer-events: none; /* so clicks go through */
  text-shadow: 1px 1px 2px black;
}

.combatant__stats {
  display: flex;
  flex-direction: column;
  gap: 1vh;
  align-items: center;
}

.stat-bar {
  width: 100%;
  max-width: 20vw;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stat-bar__progress {
  width: 100%;
  height: 2.5vh;
  border-radius: 0.5rem;
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  overflow: hidden;
  background: var(--color-stone-darker);
  border: 1px solid var(--color-stone-dark);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
  transition: all var(--transition-medium);
}

.stat-bar--hp .stat-bar__progress::-webkit-progress-bar {
  background: var(--color-stone-darker);
}

.stat-bar--hp .stat-bar__progress::-webkit-progress-value {
  background: linear-gradient(90deg, #8b2620, var(--color-hp));
  box-shadow: var(--shadow-glow-red);
}

.stat-bar--hp .stat-bar__progress::-moz-progress-bar {
  background: linear-gradient(90deg, #8b2620, var(--color-hp));
  box-shadow: var(--shadow-glow-red);
}

.battle-divider {
  width: 2px;
  min-height: 25vh;
  background: linear-gradient(
    to bottom,
    transparent,
    var(--color-stone-dark) 20%,
    var(--color-stone-dark) 80%,
    transparent
  );
  opacity: 0.5;
}

.combat-log {
  background: var(--color-bg-secondary);
  border: 2px solid var(--color-stone-dark);
  border-radius: var(--size-border-radius);
  padding: 2vh 2vw;
  overflow-y: auto;
  backdrop-filter: blur(3px);
  box-shadow: var(--shadow-box);
  flex: 1 1 auto;
  margin-bottom: 3vh;
}

.combat-log__content {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.combat-log__entry {
  padding: 0.5rem;
  border-left: 3px solid transparent;
  transition: all var(--transition-fast);
  animation: logEntry 0.5s ease;
}

@keyframes logEntry {
  from {
    opacity: 0;
    transform: translateY(-1vh);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.combat-log__entry--intro {
  font-style: italic;
  color: var(--color-text-secondary);
}

.combat-log__entry--player {
  border-left-color: var(--color-text-gold);
  background: rgba(226, 192, 122, 0.05);
}

.combat-log__entry--enemy {
  border-left-color: var(--color-hp);
  background: rgba(160, 24, 32, 0.05);
}

.combat-log__entry--victory {
  border-left-color: #4a7c59;
  background: rgba(74, 124, 89, 0.1);
  color: #7fb069;
  font-weight: bold;
}

.combat-log__entry--defeat {
  border-left-color: var(--color-hp);
  background: rgba(160, 24, 32, 0.1);
  color: #ff6b6b;
  font-weight: bold;
}

.combat-log::-webkit-scrollbar {
  width: 0.5rem;
}

.combat-log::-webkit-scrollbar-track {
  background: var(--color-stone-darker);
  border-radius: 4px;
}

.combat-log::-webkit-scrollbar-thumb {
  background: var(--color-stone-dark);
  border-radius: 4px;
}

.combat-log::-webkit-scrollbar-thumb:hover {
  background: var(--color-stone);
}

.action-panel {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
}

.action-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
  min-height: 0;
}

.action-buttons-container {
  display: grid;
  align-content: start;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  width: 100%;
}

.action-btn {
  background: linear-gradient(135deg, var(--color-btn-bg), var(--color-stone-darker));
  color: var(--color-text-primary);
  border: 2px solid var(--color-btn-border);
  padding: 7vh 0;
  font-family: var(--font-heading);
  font-size: clamp(0.9rem, 1.5vw, 1.2rem);
  font-weight: 600;
  letter-spacing: 1px;
  border-radius: var(--size-border-radius);
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  position: relative;
  overflow: hidden;
  width: 100%;
}

.action-btn--primary {
  font-size: clamp(1rem, 1.8vw, 1.4rem);
  padding: 7vh 0;
}

.action-btn--back {
  background: linear-gradient(135deg, var(--color-stone-dark), var(--color-stone-darker));
  font-size: 1rem;
  padding: 7vh 0;
  min-width: 8vw;
}

.action-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(226, 192, 122, 0.2), transparent);
  transition: left var(--transition-slow);
}

.action-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--color-btn-hover), var(--color-stone));
  border-color: var(--color-btn-border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow-gold);
}

.action-btn:hover:not(:disabled)::before {
  left: 100%;
}

.action-btn:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--color-stone-darker);
  border-color: var(--color-stone-dark);
}

.action-btn:disabled:hover {
  transform: none;
  box-shadow: none;
}

.hidden {
  display: none;
}

/* Inventory Styles */
.inventory-container {
  display: flex;
  flex-direction: column;
  gap: 1vh;
}

.inventory-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex: 0 0 auto;
}

.inventory-header .action-btn--back {
  width: auto;
  padding: 1vh 2vw;
  font-size: 0.95rem;
}

.inventory-header .action-btn--use {
  flex: 1;
  max-width: 20vw;
  padding: 1.5vh 2vw;
  font-size: 1.05rem;
  margin: 0 auto;
}

.inventory-list-container {
  background: var(--color-bg-secondary);
  border: 2px solid var(--color-stone-dark);
  border-radius: var(--size-border-radius);
  padding: 1.5vh 1.5vw;
  max-height: 45vh;
  overflow-y: auto;
  box-shadow: var(--shadow-box);
}

.inventory-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1vh;
}

.inventory-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1vh 1vw;
  background: var(--color-stone-darker);
  border: 2px solid var(--color-stone-dark);
  border-radius: var(--size-border-radius);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.inventory-item:hover {
  background: var(--color-stone-dark);
  border-color: var(--color-text-gold);
  transform: translateX(0.5vw);
}

.inventory-item__icon {
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-stone-dark);
  border-radius: 6px;
  flex-shrink: 0;
  object-fit: contain;
  image-rendering: pixelated;
}

.inventory-item__info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.inventory-item__name {
  font-family: var(--font-heading);
  font-size: 1rem;
  color: var(--color-text-gold);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.inventory-item__description {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  display: inline;
}

.inventory-list-container::-webkit-scrollbar {
  width: 0.5rem;
}

.inventory-list-container::-webkit-scrollbar-track {
  background: var(--color-stone-darker);
  border-radius: 4px;
}

.inventory-list-container::-webkit-scrollbar-thumb {
  background: var(--color-stone-dark);
  border-radius: 4px;
}

.inventory-list-container::-webkit-scrollbar-thumb:hover {
  background: var(--color-stone);
}

/* Target Selection Styles */
.target-selection-container {
  display: flex;
  flex-direction: column;
  gap: 1.5vh;
  align-items: center;
  padding: 2vh;
}

.target-selection-text {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  color: var(--color-text-gold);
  text-align: center;
  margin: 2vh 0;
}

.combatant__sprite.target-selectable {
  cursor: pointer;
  border: 3px solid var(--color-text-gold);
  border-radius: 10px;
  box-shadow: 0 0 20px rgba(226, 192, 122, 0.6);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 20px rgba(226, 192, 122, 0.6);
  }

  50% {
    box-shadow: 0 0 30px rgba(226, 192, 122, 0.9);
  }
}

/* Item Animation Styles */
.item-throw-animation {
  image-rendering: pixelated;
  filter: drop-shadow(0 0 10px rgba(226, 192, 122, 0.6));
  will-change: transform, opacity;
}

@media (max-width: 768px) {
  body {
    padding: 1vh 1vw;
  }

  .battle-header {
    flex-direction: column;
    align-items: center;
    gap: 2vh;
    padding: 1.5vh;
  }

  .battle-divider {
    display: none;
  }

  .action-buttons-container {
    grid-template-columns: 1fr;
  }

  .combatant__avatar {
    width: 25vw;
    height: 25vw;
  }

  .inventory-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .inventory-item__name {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }
}

#battle-header {
  background-image: var(--battle-header-bg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
