/* --- Background and Core Layout --- */
#background-container {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: -1;
    background-image: url('images/background.jpg');
    background-size: cover;
    background-position: center;
    filter: brightness(0.7);
}

body {
    font-family: 'MS Sans Serif', sans-serif;
    margin: 0;
    background-color: transparent;
    font-size: 11px;
    overscroll-behavior: none;
    height: 100vh;
    display: flex;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

#game-container {
    margin: 0 auto;
    width: 100%;
    max-width: 1200px; /* Optional: constrain max width */
    display: flex;
    flex-direction: column;
}

#game-board {
    padding: 4px;
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 4px; /* Added gap between player areas */
}

/* --- Player Areas and Zones (Now using classes) --- */
.player-area {
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0) 70%);
    border: 1px solid rgba(0, 64, 64, 0.5);
    padding: 4px;
    display: flex;
    flex-direction: column;
    position: relative;
    flex: 1;
    transition: background-color 0.3s ease; /* Smooth transition for current player highlight */
}

.player-area.current-player {
    background-color: rgba(255, 255, 0, 0.1);
}

.player-controls {
    position: absolute; top: 5px; right: 8px;
    display: flex; gap: 5px; align-items: center;
    font-size: 10px; color: white;
    background-color: rgba(0, 0, 0, 0.4);
    padding: 3px 6px; border-radius: 3px;
    z-index: 20;
}

.player-section { display: flex; flex-direction: column; height: 100%; gap: 4px; }
.hand {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(40px, 108px);
    justify-items: center;
    min-height: 154px; /* Give hand some min-height */
    border: 1px dashed rgba(255, 255, 255, 0.2);
    padding: 4px 12px;
    background-color: rgba(0, 0, 0, 0.1);
    justify-content: center; align-items: center;
    position: relative; flex-wrap: nowrap;
}
.hand .card { transition: transform 0.2s ease-out; position: relative; flex-shrink: 0; }
.hand .card:hover { transform: scale(1.5) translateY(-25%); z-index: 10; }
.hand .card[draggable] { touch-action: none; }

/* --- Game Board Alignment (Simplified with a modifier class) --- */
.game-area { display: flex; flex-direction: column; gap: 5px; flex: 1; justify-content: flex-end; align-items: center; }
.bench-area { display: flex; flex-direction: column; gap: 5px; }
.bench { display: flex; gap: 4px; justify-content: center; align-items: center; }

/* For the user's area, reverse the order of Hand and Game Area */
.player-area--user .player-section {
    flex-direction: column-reverse;
}

/* ALSO, reverse the order of Active and Bench within the user's Game Area */
.player-area--user .game-area {
    flex-direction: column-reverse; 
}

/* --- Card Sizing and Styling --- */
:root { --card-width: 106px; --card-height: 148px; }

.card {
    position: relative;
    width: var(--card-width); height: var(--card-height);
    border: 1px solid #333; border-radius: 11px;
    overflow: hidden; cursor: pointer;
    filter: drop-shadow(2px 2px 3px rgba(0,0,0,0.6));
    flex-shrink: 0;
}
.card:hover { border-color: #0099ff; }
.card.disabled { cursor: not-allowed; opacity: 0.7; }
.card.active-buddy { border: 2px solid #ffcc00; }

.bench-slot, .active-slot {
    width: var(--card-width); height: var(--card-height);
    border: 1px dashed rgba(255, 255, 255, 0.2);
    background-color: rgba(0, 0, 0, 0.1);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden; flex-shrink: 0; border-radius: 11px;
    transition: transform 0.2s ease, background-color 0.2s ease;
}
.active-slot { border-style: solid; border-color: rgba(255, 220, 0, 0.5); background-color: rgba(255, 220, 0, 0.1); }
.card-image { width: 100%; height: 100%; object-fit: cover; pointer-events: none; } /* Disable pointer events on image */
.card-hp { position: absolute; top: 4px; right: 4px; background: white; padding: 1px 5px; border-radius: 50%; font-weight: bold; font-family: Arial, sans-serif; font-size: 0.7em; color: #333; pointer-events: none; }

.active-slot.slot-is-active {
    overflow: visible; /* Allows the glow to escape during attack. */
}

/* --- Drag and Drop Styles --- */
.card.dragging { opacity: 0.4; transform: scale(0.9); }
.drop-target-hover { border: 2px dashed #4caf50 !important; background-color: rgba(76, 175, 80, 0.2) !important; transform: scale(1.05); }

/* --- Other UI elements --- */
.turn-indicator {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(255, 255, 0, .9);
    padding: 8px 12px; border: 2px solid #333; border-radius: 5px;
    font-weight: 700; font-size: 12px; z-index: 100;
}
#win-message {
    position: fixed; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background-color: #fff; border: 3px outset #c0c0c0;
    padding: 20px; font-size: 16px; font-weight: 700; z-index: 1000;
}
.hidden { display: none !important; }

button { font-family: 'MS Sans Serif', sans-serif; font-size: 10px; padding: 3px 6px; border: 2px outset #c0c0c0; background-color: #c0c0c0; cursor: pointer; }
button:hover { background-color: #d0d0d0; }
button:active { border: 2px inset #c0c0c0; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* --- Full-size Card Modal --- */
#card-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    justify-content: center;
    align-items: center;
}

#card-modal:not(.hidden) {
    display: flex;
}

.card-modal-content {
    position: relative;
    width: 80%;
    max-width: 400px;
}

.card-modal-image {
    width: 100%;
    border-radius: 8px;
}

.card-modal-close {
    position: absolute;
    top: -10px;
    right: -10px;
    color: white;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    width: 24px;
    height: 24px;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1001;
}

@keyframes card-hit {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
  50% {
    box-shadow: 0 0 15px 5px rgba(255, 0, 0, 0.7);
    filter: brightness(0.7) sepia(0.4) saturate(1.5); /* <-- ADD THIS LINE */
  }
}

.card-is-hit {
  /* Apply the hit reaction animation */
  animation: card-hit 0.5s ease-in-out;
}

@keyframes attacker-glow {
  0%, 100% {
    /* Animate back to the card's default drop-shadow */
    filter: drop-shadow(2px 2px 3px rgba(0,0,0,0.6));
  }
  50% {
    /* Glow effect using drop-shadow, combined with a brightness boost */
    filter: brightness(1.15) drop-shadow(0 0 10px rgba(255, 223, 100, 0.95));
  }
}

/* Add this new class for the attacker */
.card-is-attacking {
  animation: attacker-glow 0.4s ease-out;
  /* Bring the card and its glow on top of other elements during the animation */
  z-index: 60; 
}