/* styles.css */
body {
    font-family: Arial, sans-serif;
    text-align: center;
    background: #f0f0f0;
    margin: 0;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
}

.game-container {
    max-width: 1000px;
    padding: 15px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

/* --- BOARD & SPOTS --- */
#board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}
#board {
    width: 900px;
    height: 600px;
    position: relative;
    background: #ddd;
    border: 1px solid #999;
}

#active-plate-indicator {
    position: fixed;
    background: rgba(255, 215, 0, 0.95);
    border: 3px solid #fff;
    border-radius: 15px;
    padding: 12px 20px;
    font-weight: bold;
    font-size: 14px;
    color: #333;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.7);
    z-index: 200;
    display: none;
    animation: plateGlow 2s infinite;
    min-width: 120px;
    text-align: center;
    white-space: nowrap;
    /* Position will be set dynamically by JavaScript */
}
.spot {
    width: 72px;
    height: 72px;
    position: absolute;
    background: #fff;
    border: 2px solid #000;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}
    position: absolute;
    background: #fff;
    border: 2px solid #000;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}
.entry-p1 { background: #fff; border: 4px dashed #2196F3; }
.entry-p2 { background: #fff; border: 4px dashed #f44336; }
.goal-p1 { background: #fff; border: 4px solid #2196F3; box-shadow: 0 0 8px #2196F3; }
.goal-p2 { background: #fff; border: 4px solid #f44336; box-shadow: 0 0 8px #f44336; }
.segment { position: absolute; background: #999; z-index: 0; }

/* --- POKEMON TOKENS --- */
.pokemon {
    width: 54px;
    height: 54px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    cursor: pointer;
    z-index: 10;
    user-select: none;
    transition: transform 0.1s ease;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
}
.pokemon.selected { background-color: #90EE90; }
.p1 { border: 2px solid #2196F3; }
.p2 { border: 2px solid #f44336; }
.highlight { background: #b3e5fc; }

/* --- BENCHES --- */
#benches-p1, #benches-p2 {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: stretch;
    width: 900px;
    height: 64px; /* Adjusted to accommodate larger bench height */
    margin: 2px 0;
    gap: 8px;
    padding: 2px;
    border-radius: 5px;
    transition: box-shadow 0.3s ease;
}
#benches-p1.active, #benches-p2.active {
    box-shadow: 0 0 15px 5px rgba(255, 215, 0, 0.7);
    animation: breatheGlow 3s ease-in-out infinite;
}
.bench {
    width: 50%; /* Larger, central position */
    padding: 2px;
    border-radius: 5px;
    position: relative;
    height: 60px; /* Slightly increased to accommodate margin */
    background: #e0e0e0;
    display: flex;
    flex-direction: column;
}

.wait-room {
    width: 25%; /* Smaller, left side */
    padding: 2px;
    border-radius: 5px;
    position: relative;
    height: 56px; /* Keep same height for wait room */
    background: #d0d0d0;
    border: 2px dashed #888;
    display: flex;
    flex-direction: column;
}

.bench h3, .wait-room h3 {
    margin: 0 0 2px 0;
    font-size: 10px;
    flex-shrink: 0;
    height: 12px; /* Fixed height for header */
}

/* Create a Pokemon container area */
.bench, .wait-room {
    overflow: hidden;
}

/* Pokemon container for horizontal layout */
.pokemon-container {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: center; /* Center Pokemon horizontally */
    gap: 1px;
    min-height: 40px;
}

/* Add margin below bench Pokemon row */
.bench .pokemon-container {
    margin-bottom: 4px; /* Add space below Pokemon row */
}

/* Style the Pokemon elements to display horizontally */
.bench-pokemon, .wait-room-pokemon {
    display: inline-block; /* Display side by side */
    vertical-align: top;
    flex-shrink: 0;
    position: relative; /* Remove absolute positioning if any */
}
.bench-pokemon {
    width: 40px;
    height: 40px;
    display: inline-block;
    border-radius: 50%;
    cursor: pointer;
    margin: 1px;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    vertical-align: top;
}

.wait-room-pokemon {
    width: 30px;
    height: 30px;
    display: inline-block;
    border-radius: 50%;
    cursor: pointer;
    margin: 1px;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.8;
    vertical-align: top;
}

.bench-pokemon.selected, .wait-room-pokemon.selected { background-color: #90EE90; }
.waiting { filter: grayscale(100%); cursor: not-allowed; }
.flow-arrow {
    position: absolute;
    top: 50%;
    right: -15px; /* Adjusted for smaller containers */
    transform: translateY(-50%) rotate(0deg); /* Point right toward bench */
    width: 15px;
    height: 15px;
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%234B0000"><path d="M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z"/></svg>') no-repeat center;
    background-size: contain;
    z-index: 1;
}

/* --- PLATES UI (In-Game) --- */
.plates-container {
    width: 25%; /* Right side - increased for better grid */
    height: 56px; /* Fixed height to match other containers */
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 1px;
    padding: 2px;
    background: #eee;
    border-radius: 5px;
    align-items: stretch;
    justify-items: stretch;
}
.plate-card {
    width: 100%;
    height: 100%;
    padding: 1px;
    background: linear-gradient(to bottom, #444, #222);
    color: white;
    font-size: 9px;
    border: 1px solid gold;
    border-radius: 2px;
    cursor: pointer;
    text-align: center;
    user-select: none;
    box-shadow: 0 1px 1px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    flex-direction: column;
    line-height: 1;
}
.plate-card:hover {
    transform: scale(1.05);
    background: linear-gradient(to bottom, #555, #333);
}
.plate-card.used {
    opacity: 0.5;
    cursor: default;
    filter: grayscale(100%);
}

/* --- ANIMATIONS --- */
@keyframes strike {
    0% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.1); }
    100% { transform: translate(-50%, -50%) scale(1); }
}
@keyframes knockout {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
}
@keyframes toWaitRoom {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: scale(0.8); opacity: 0.7; }
}
@keyframes jumpAnimation {
    0% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.2) translateY(-20px); }
    100% { transform: translate(-50%, -50%) scale(1); }
}
@keyframes breathing {
    0% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.3); }
    100% { transform: translate(-50%, -50%) scale(1); }
}
@keyframes deployFromBench {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}
.strike-animation { animation: strike 0.3s ease-in-out; }
.knockout-animation { animation: knockout 0.5s ease-in-out forwards; }
.to-wait-room { animation: toWaitRoom 1.5s ease-out forwards; }
.jump-animation { animation: jumpAnimation 0.3s ease-in-out; }
.breathing-animation { 
    animation: breathing 1.5s ease-in-out infinite; 
    transition: none !important;
}
.deploy-from-bench { animation: deployFromBench 1s ease-in-out; }

/* --- INDICATORS & OVERLAYS --- */
.pass-indicator {
    position: absolute;
    width: 35px;
    height: 35px;
    background: white !important;
    color: #333 !important;
    border: 2px solid white !important;
    border-radius: 50%;
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    z-index: 100 !important;
    transition: all 0.3s ease;
    text-shadow: 1px 1px 2px rgba(255,255,255,0.8);
    box-shadow: 0 4px 12px rgba(0,0,0,0.5) !important;
    animation: shield-pulse 2s infinite;
}
.pass-indicator:hover { 
    transform: scale(1.2); 
    box-shadow: 0 6px 16px rgba(0,0,0,0.6);
}

.status-marker {
    position: absolute;
    bottom: -5px;
    right: -5px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    z-index: 12;
    box-shadow: 0 0 3px #000;
}
.status-burn { background-color: #FF4500; content: "B"; }
.status-paralysis { background-color: #FFD700; content: "P"; color: black; }
.status-poison { background-color: #800080; content: "Psn"; font-size: 10px; }
.status-sleep { background-color: #aaa; content: "Zzz"; font-size: 8px; }

.popover {
    position: fixed;
    background: #f9f9f9;
    border: 2px solid #333;
    border-radius: 8px;
    padding: 12px;
    z-index: 3000; /* Very high Z-index */
    display: none;
    width: 240px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    text-align: center;
}
.popover canvas { width: 200px; height: 200px; }
.popover .title { font-size: 14px; font-weight: bold; margin-bottom: 10px; }

#active-plate-indicator {
    position: absolute;
    /* Position will be set by JavaScript */
    background: rgba(255, 215, 0, 0.95);
    border: 3px solid #fff;
    border-radius: 15px;
    padding: 12px 20px;
    font-weight: bold;
    font-size: 14px;
    color: #333;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.7);
    z-index: 200;
    display: none;
    animation: plateGlow 2s infinite;
    min-width: 120px;
    text-align: center;
    border-left: 8px solid gold; /* Emphasize the bleeding edge */
}
@keyframes plateGlow {
    0% { 
        box-shadow: 0 4px 15px rgba(255, 215, 0, 0.7), 0 0 0 0 rgba(255, 215, 0, 0.4); 
        transform: translateY(-50%) scale(1);
    }
    50% { 
        box-shadow: 0 6px 20px rgba(255, 215, 0, 0.9), 0 0 0 8px rgba(255, 215, 0, 0.1); 
        transform: translateY(-50%) scale(1.05);
    }
    100% { 
        box-shadow: 0 4px 15px rgba(255, 215, 0, 0.7), 0 0 0 0 rgba(255, 215, 0, 0.4); 
        transform: translateY(-50%) scale(1);
    }
}

@keyframes breatheGlow {
    0%, 100% {
        box-shadow: 0 0 15px 5px rgba(255, 215, 0, 0.5);
    }
    50% {
        box-shadow: 0 0 25px 8px rgba(255, 215, 0, 0.9);
    }
}

@keyframes breatheGlow {
    0%, 100% {
        box-shadow: 0 0 15px 5px rgba(255, 215, 0, 0.5);
    }
    50% {
        box-shadow: 0 0 25px 8px rgba(255, 215, 0, 0.9);
    }
}

#turn-indicator {
    position: absolute;
    /* Position will be set by JavaScript */
    background: rgba(76, 175, 80, 0.95);
    border: 3px solid #fff;
    border-radius: 15px;
    padding: 12px 20px;
    font-weight: bold;
    font-size: 14px;
    color: #fff;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.7);
    z-index: 201;
    animation: turnPulse 1s ease-in-out;
    min-width: 120px;
    text-align: center;
    display: none;
}

@keyframes turnPulse {
    0% { 
        opacity: 0;
        transform: translateX(-50%) scale(0.8);
    }
    50% { 
        opacity: 1;
        transform: translateX(-50%) scale(1.1);
    }
    100% { 
        opacity: 1;
        transform: translateX(-50%) scale(1);
    }
}

#coin-flip-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    display: none;
}

#coin-container {
    text-align: center;
}

#coin {
    width: 80px;
    height: 80px;
    position: relative;
    margin: 0 auto 20px auto;
    transform-style: preserve-3d;
    transform: rotateY(0deg); /* Start showing front face (star) */
}

.coin-face {
    position: absolute;
    width: 80px;
    height: 80px;
    background: linear-gradient(45deg, #ffd700, #ffed4e);
    border: 3px solid #b8860b;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 30px;
    backface-visibility: hidden;
}

.coin-back {
    transform: rotateY(180deg);
}

@keyframes coinFlip {
    0% {
        transform: rotateY(0deg);
    }
    100% {
        transform: rotateY(1800deg); /* 5 full rotations */
    }
}

#coin-message {
    color: white;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    min-height: 25px;
}

#winner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 30;
    flex-direction: column;
}
#winner-text {
    font-size: 48px;
    font-weight: bold;
    color: gold;
    text-shadow: 0 0 10px gold;
    margin-bottom: 20px;
}
#play-again-btn {
    font-size: 24px;
    padding: 15px 30px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

/* --- WHEEL SPIN --- */
#wheel-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 650px;
    height: 400px;
    background: rgba(0, 0, 0, 0.85);
    border-radius: 15px;
    z-index: 20;
    display: none;
    padding: 20px;
    box-sizing: border-box;
}
#canvas-container {
    position: relative;
    width: 100%;
    height: 320px;
    display: flex;
    justify-content: space-between;
}
#marker1, #marker2 {
    position: absolute;
    top: 145px;
    left: 50%;
    width: 0;
    height: 0;
    border-bottom: 10px solid transparent;
    border-top: 10px solid transparent;
    z-index: 22;
}
#marker1 { margin-left: -25px; border-right: 20px solid #8B0000; }
#marker2 { margin-left: 5px; border-left: 20px solid #8B0000; }
.wheel-canvas { width: 300px; height: 300px; }
.center-circle {
    position: absolute;
    top: 50%;
    width: 100px;
    height: 100px;
    background-color: white;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid black;
    z-index: 21;
}
#wheel1-center { left: 25%; }
#wheel2-center { left: 75%; }
#wheel1-center.winner, #wheel2-center.winner { border: 5px solid #00FF00; box-shadow: 0 0 10px #00FF00; }
.center-circle.loser { border: 5px solid red; filter: grayscale(100%); opacity: 0.7; }
.center-circle.clash { border: 5px solid #FFD700; box-shadow: 0 0 10px #FFD700; }
.center-image {
    width: 80px;
    height: 80px;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
}
.wheel-label {
    position: absolute;
    bottom: -20px;
    font-size: 18px;
    font-weight: bold;
    color: #fff;
    z-index: 23;
}
#wheel1-label { left: 25%; transform: translateX(-50%); }
#wheel2-label { left: 75%; transform: translateX(-50%); }

/* --- TEAM SELECTION DIALOG STYLES (FIXED) --- */
#welcome-dialog, #team-selection-dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.dialog-content {
    background: white;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.7);
    width: 98%;
    max-width: 1400px;
    max-height: 98vh;
    display: flex;
    flex-direction: column;
}

.dialog-content h2 {
    margin: 0 0 15px 0;
    font-size: 20px;
}

/* Container for the two players - Forces Side-by-Side */
#team-selection-container.pvp-mode {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    width: 100%;
    margin: 20px 0;
}

/* Container for online mode - Single player, centered */
#team-selection-container.online-mode {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    margin: 20px 0;
}

#team-selection-container.online-mode .team-section {
    flex: none;
    width: 400px;
    background: #f9f9f9;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
}

/* Individual Player Section */
.team-section {
    flex: 1;
    background: #f9f9f9;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
    min-width: 400px;
}

.team-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.team-header h3 {
    margin: 0;
    font-size: 16px;
}

.team-header select {
    flex: 1;
    padding: 4px;
    font-size: 12px;
}

.team-description {
    font-size: 10px;
    color: #666;
    margin: 5px 0;
    font-style: italic;
}

.team-section select {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    font-size: 14px;
}

/* Container for the Pokemon Tables (3x2 grid) */
.team-tables {
    display: flex;
    flex-direction: row;
    gap: 8px;
    margin-bottom: 8px;
}

.team-table {
    border-collapse: collapse;
    width: 48%;
    background: white;
    font-size: 10px;
}
.team-table th, .team-table td {
    border: 1px solid #ccc;
    padding: 3px;
    text-align: center;
}
.team-table th { 
    background-color: #eee;
    font-size: 9px;
    padding: 2px;
}
.team-table td { vertical-align: middle; }
.team-table .pokemon-name {
    font-weight: bold;
    font-size: 9px;
}

.pokemon-gif { width: 45px; height: 45px; display: block; margin: 0 auto; }
.team-pie-chart { width: 90px; height: 90px; display: block; margin: 0 auto; }

/* Plates Selection Area in Dialog */
.plates-section {
    margin-top: 8px;
}

.plates-section h4 {
    margin: 0 0 4px 0;
    font-size: 12px;
}

.plates-selection {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 3px;
    background: #e8e8e8;
    padding: 5px;
    border-radius: 4px;
    min-height: 25px;
}

.plates-selection select {
    width: auto;
    font-size: 9px;
    padding: 1px;
    margin: 1px;
}

.plate-card {
    font-size: 9px;
    padding: 2px 6px;
    margin: 1px;
    border-radius: 3px;
}

/* Dialog Buttons */
.dialog-content button {
    padding: 10px 30px;
    font-size: 18px;
    background-color: #2196F3;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 10px;
}
.dialog-content button:hover { background-color: #1976D2; }
.dialog-content button:disabled { background-color: #ccc; cursor: not-allowed; }