/* =========================================
   1. GLOBAL & LAYOUT
   ========================================= */
body {
    background-color: #1a1a1a;
    color: white;
    font-family: 'Segoe UI', Arial, sans-serif;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

h1 { color: #CC0000; text-shadow: 2px 2px 4px rgba(0,0,0,0.5); }

/* =========================================
   2. OVERLAYS (Menu, Rules, Game Over)
   ========================================= */
.menu-overlay, #rules-overlay, #game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 5000;
}

.menu-content, .rules-content, .game-over-content {
    background: #2c3e50;
    padding: 30px;
    border-radius: 20px;
    border: 4px solid #CC0000;
    text-align: center;
    width: 350px;
    box-shadow: 0 0 50px rgba(0,0,0,0.8);
}

.hidden { display: none !important; }

/* =========================================
   3. THE CARD AREA (The Game Table)
   ========================================= */
.card-area {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-top: 20px;
    perspective: 1000px; /* Crucial for 3D flip effect */
}

.deck-display-wrapper {
    text-align: center;
}

.deck-count-box {
    background: #444;
    padding: 5px 10px;
    border-radius: 5px;
    margin-bottom: 10px;
    font-weight: bold;
}

/* =========================================
   4. INDIVIDUAL CARDS (3D Logic)
   ========================================= */
   /* 1. Ensure the container defines the space */
.card-container {
    width: 280px;
    height: 480px;
    position: relative; /* This is the anchor */
    margin-bottom: 20px;
}

/* 2. Ensure the inner flipper fills that space */
.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
    transform: rotateY(180deg); /* Start showing the BACK */
}

/* 3. Force the faces to stack EXACTLY on top of each other */
.card-front, .card-back {
    position: absolute;
    top: 0;   /* Force them to the top of the container */
    left: 0;  /* Force them to the left of the container */
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 15px;
    border: 6px solid white;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    box-sizing: border-box;
    margin: 0; /* Remove any stray margins */
}
/* 1. The Front should be at 0 degrees (Facing you) */
.card-front {
    background: #fdfdfd;
    color: #333;
    /* Remove any rotateY from here so it starts visible */
    transform: rotateY(0deg); 
    display: flex;
    flex-direction: column;
    padding: 10px;
    z-index: 2; /* Sits on top */
}

/* 2. The Back should be at 180 degrees (Hidden) */
.card-back {
    background-color: #CC0000 !important;
    /* This flips the back so it's behind the front */
    transform: rotateY(180deg); 
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 40px 10px;
    z-index: 1;
}

/* 4. Fix the Logo Centering conflict */
/* We change the centering method so it doesn't break the face layout */
.card-back::after {
    content: "";
    display: block;
    width: 150px;
    height: 150px;
    background-color: white !important;
    background-image: url('./img/card_back_icon.JPG'); 
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 50%;
    border: 5px solid white;
    
    /* Centering without breaking the parent layout */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1; 
}
/* =========================================
   REFINED CARD BACK (Clean & Integrated)
   ========================================= */
.card-back {
    background-color: #CC0000 !important;
    background-image: radial-gradient(circle, #b30000 15%, transparent 16%);
    background-size: 30px 30px;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 40px 10px !important;
    box-sizing: border-box !important;
    height: 100% !important;
    position: relative;
}

/* 1. Top Title (Targeting your <h2>) */
.card-back h2 {
    color: white !important;
    margin: 0 !important;
    font-size: 1.5rem !important;
    border-bottom: 2px solid white;
    padding-bottom: 5px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* 2. The Center Logo Circle (Using a Pseudo-element for the white base) */
/* We attach this to the card-back itself to avoid overlapping h2 */
.card-back::after {
    content: "" !important;
    display: block;
    width: 150px;
    height: 150px;
    background-color: white !important;
    
    /* YOUR CORRECTED IMAGE PATH */
    background-image: url('./img/card_back_icon.JPG') !important; 
    
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 50%;
    border: 5px solid white;
    box-shadow: 0 5px 15px rgba(0,0,0,0.4);
    
    /* Perfect Centering */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* 3. Bottom Subtitle (Targeting your <p>) */
.card-back p {
    color: white !important;
    margin: 0 !important;
    font-weight: bold !important;
    font-size: 1.1rem !important;
    letter-spacing: 1px;
    text-transform: uppercase;
}
/* =========================================
   5. CARD CONTENT ELEMENTS
   ========================================= */
.card-image {
    width: 100%;
    height: 120px; /* Reduced from 140px/160px */
    object-fit: cover;
    border-radius: 5px;
    margin-bottom: 5px;
}

.stats-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex-grow: 1; /* Pushes stats to fill available space */
}

.stat-item {
    display: flex;
    justify-content: space-between;
    background: #f4f4f4;
    margin: 2px 0;      /* Reduced margin from 4px to 2px */
    padding: 6px 8px;   /* Reduced padding from 8px to 6px */
    border-radius: 4px;
    font-size: 0.85em;  /* Slightly smaller font */
    border: 1px solid #ddd;
}
.is-flipped {
    transform: rotateY(0deg) !important;
}
.stat-item:hover { background: #ddd; }

/* Stat outcome colors */
.stat-winner { background: #27ae60 !important; color: white; }
.stat-loser { background: #c0392b !important; color: white; }

/* =========================================
   6. INTERACTIVE UI
   ========================================= */
button {
    background: #ecf0f1;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    margin: 5px;
}

button:hover { background: #bdc3c7; }

.settings-box {
    margin-top: 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    padding-top: 15px;
}