@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap');

#p4-wrapper {
    font-family: 'Fredoka', sans-serif;
    width: 100%; min-height: 650px; 
    background: linear-gradient(135deg, #e0c3fc 0%, #8ec5fc 100%);
    display: flex; justify-content: center; align-items: center;
    padding: 10px; box-sizing: border-box;
}
#p4-wrapper:fullscreen { width: 100vw; height: 100vh; border-radius: 0; padding: 0; }
#p4-wrapper * { box-sizing: border-box; touch-action: manipulation; }

#p4-container {
    width: 100%; max-width: 800px;
    background: #fff; border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
    display: flex; flex-direction: column; overflow: hidden; position: relative;
    min-height: 600px; height: 100%;
}

/* HEADER */
.p4-header {
    padding: 10px 20px; background: #f8f9fa; border-bottom: 2px solid #e9ecef;
    display: flex; justify-content: space-between; align-items: center; height: 60px;
    flex-shrink: 0;
}
.p4-header-left { display: flex; align-items: center; gap: 15px; }
.p4-main-title { font-size: 1.4rem; color: #5b4b8a; margin: 0; font-weight: 700; }

#p4-turn-box {
    display: flex; align-items: center; gap: 8px;
    background: #e9ecef; padding: 5px 15px; border-radius: 30px;
    font-size: 0.9rem; font-weight: 600; color: #495057;
}
#p4-turn-token { width: 16px; height: 16px; border-radius: 50%; background: #ccc; border: 1px solid rgba(0,0,0,0.1); }
#p4-turn-token.red { background: #ff4757; }
#p4-turn-token.yellow { background: #f1c40f; }

.p4-icon-btn {
    width: 36px; height: 36px; border-radius: 50%; border: 1px solid #ced4da;
    background: white; cursor: pointer; font-size: 1.1rem; 
    display: flex; align-items: center; justify-content: center; color: #555; transition:0.2s;
}
.p4-icon-btn:hover { background: #e9ecef; }

/* VUES & MODALES */
.p4-view { 
    flex-grow: 1; width: 100%; display: flex; justify-content: center; align-items: center; 
    flex-direction: column; position: absolute; top: 60px; left: 0; bottom: 0;
    background: #fff; transition: opacity 0.3s; z-index: 1;
}
.p4-hidden { display: none !important; opacity: 0; pointer-events: none; z-index: -1; }
.p4-active { display: flex !important; opacity: 1; pointer-events: auto; z-index: 10; }
.p4-overlay { background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(5px); z-index: 100; top: 0; height: 100%; }

/* CARTES */
.p4-card {
    background: white; padding: 30px; border-radius: 20px;
    width: 90%; max-width: 400px; text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1); border: 1px solid #eee;
    animation: popIn 0.3s ease-out;
}
@keyframes popIn { from { transform: scale(0.9); opacity:0; } to { transform: scale(1); opacity:1; } }

.p4-card.no-shadow { box-shadow: none; border: none; background: transparent; }
.p4-card-title { color: #5b4b8a; margin: 0 0 20px 0; font-size: 1.5rem; }
.p4-btn-stack { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.p4-row { display: flex; gap: 8px; justify-content: center; width: 100%; }

/* BOUTONS */
.p4-btn { padding: 12px; border-radius: 12px; font-weight: bold; cursor: pointer; border: none; font-size: 0.95rem; width: 100%; transition: 0.2s; font-family: inherit; }
.p4-start { background: #3b82f6; color: white; border-bottom: 4px solid #2563eb; }
.p4-online { background: #e0f2fe; color: #0284c7; border: 2px solid #bae6fd; }
.p4-online-small { background: #e0f2fe; color: #0284c7; border: 2px solid #bae6fd; font-size: 0.85rem; padding: 8px; }
.p4-secondary { background: #f1f5f9; color: #475569; border: 2px solid #e2e8f0; }
.p4-primary { background: #2ecc71; color: white; border-bottom: 4px solid #27ae60; }
.p4-btn:hover { transform: translateY(-2px); filter: brightness(0.95); }
.p4-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.big-btn { font-size: 1.1rem; padding: 15px; }

/* SELECTION DIFFICULTE */
.p4-diff-area { margin-top: 10px; margin-bottom: 10px; animation: slideDown 0.3s; background: #f8f9fa; padding: 15px; border-radius: 12px; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.p4-btn-diff { flex: 1; padding: 8px; border: 2px solid #e2e8f0; background: #fff; border-radius: 8px; cursor: pointer; font-size: 0.9rem; color: #666; font-weight: bold; transition:0.2s; }
.p4-btn-diff:hover { border-color: #3b82f6; }
.p4-btn-diff.p4-selected { background: #3b82f6; color: white; border-color: #3b82f6; }

.p4-separator { display: flex; align-items: center; color: #ccc; margin: 10px 0; font-size: 0.7rem; font-weight: bold; text-transform: uppercase; }
.p4-separator::before, .p4-separator::after { content: ''; flex: 1; border-bottom: 1px solid #eee; }
.p4-separator span { padding: 0 10px; }

.p4-input-small { width: 80px; padding: 0 10px; text-align: center; text-transform: uppercase; border: 2px solid #cbd5e1; border-radius: 8px; font-weight: bold; }
.p4-code-display { font-family: monospace; font-size: 2.5rem; font-weight: bold; background: #2d3436; color: #55efc4; padding: 15px; border-radius: 10px; margin: 15px 0; letter-spacing: 5px; }
.p4-loader { width: 40px; height: 40px; border: 4px solid #eee; border-top-color: #3b82f6; border-radius: 50%; animation: spin 1s infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* PLATEAU DE JEU */
.p4-players-names { 
    width: 100%; display: flex; justify-content: space-around; align-items: center; 
    margin-bottom: 10px; font-weight: bold; font-size: 1.1rem; flex-shrink: 0;
}
.vs-badge { background: #f1f5f9; padding: 2px 8px; border-radius: 10px; font-size: 0.8rem; color: #888; }
.p-name.p1 { color: #ff4444; }
.p-name.p2 { color: #e6c200; }

.p4-board-container {
    background: #34495e; padding: 15px; border-radius: 15px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
    width: 95%; max-width: 700px; max-height: 70vh; aspect-ratio: 7/6;
    display: flex; justify-content: center; align-items: center;
}
#p4-grid {
    display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(6, 1fr); 
    gap: 1.5%; width: 100%; height: 100%;
}
.p4-cell {
    background: #f0f2f5; border-radius: 50%; width: 100%; height: 100%;
    cursor: pointer; position: relative; box-shadow: inset 2px 2px 5px rgba(0,0,0,0.3);
}

/* PIONS */
.p4-token {
    width: 100%; height: 100%; border-radius: 50%;
    position: absolute; top: 0; left: 0;
    animation: p4-drop 0.4s cubic-bezier(0.5, 0.05, 0.1, 1) forwards;
    box-shadow: inset -2px -2px 5px rgba(0,0,0,0.3), 2px 2px 5px rgba(255,255,255,0.4);
}
@keyframes p4-drop { 0% { transform: translateY(-400px); opacity: 0; } 100% { transform: translateY(0); opacity: 1; } }

.p4-token.red { background: #ff4757; }
.p4-token.yellow { background: #f1c40f; }
.p4-cell.preview.red { background: rgba(255, 71, 87, 0.4); }
.p4-cell.preview.yellow { background: rgba(241, 196, 15, 0.4); }

/* ANIMATION VICTOIRE */
.p4-cell.win-cell {
    animation: p4WinPulse 0.6s ease-in-out infinite;
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.8) !important;
}

.p4-cell.win-cell .p4-token {
    animation: p4TokenWin 0.6s ease-in-out infinite;
}

@keyframes p4WinPulse {
    0%, 100% { 
        transform: scale(1); 
        box-shadow: 0 0 20px rgba(251, 191, 36, 0.8);
    }
    50% { 
        transform: scale(1.15); 
        box-shadow: 0 0 30px rgba(251, 191, 36, 1);
    }
}

@keyframes p4TokenWin {
    0%, 100% { 
        transform: scale(1);
        box-shadow: inset -2px -2px 5px rgba(0,0,0,0.3), 2px 2px 5px rgba(255,255,255,0.4);
    }
    50% { 
        transform: scale(1.1);
        box-shadow: inset -3px -3px 8px rgba(0,0,0,0.4), 3px 3px 8px rgba(255,255,255,0.6), 0 0 15px rgba(255, 215, 0, 0.6);
    }
}

/* ANIMATION PIECE */
.p4-coin { width: 80px; height: 80px; margin: 10px auto; position: relative; transform-style: preserve-3d; transition: transform 2s; }
.p4-side-a, .p4-side-b { position: absolute; width: 100%; height: 100%; border-radius: 50%; backface-visibility: hidden; border: 4px solid white; box-shadow: 0 5px 15px rgba(0,0,0,0.2); }
.p4-side-a { background: #ff4444; } 
.p4-side-b { background: #ffff44; transform: rotateY(180deg); } 

.p4-flip-p1 { animation: flipP1 2s forwards; }
.p4-flip-p2 { animation: flipP2 2s forwards; }
@keyframes flipP1 { 0% { transform: rotateY(0); } 100% { transform: rotateY(1800deg); } }
@keyframes flipP2 { 0% { transform: rotateY(0); } 100% { transform: rotateY(1980deg); } }
.toss-text { color:#5b4b8a; margin-top:20px; opacity:0; transition: opacity 0.5s; background:white; padding:10px; border-radius:10px; }

.p4-token-large { width: 60px; height: 60px; border-radius: 50%; margin: 0 auto 20px; border: 4px solid white; box-shadow: 0 5px 15px rgba(0,0,0,0.2); }
.p4-token-large.red { background: #ff4757; }
.p4-token-large.yellow { background: #f1c40f; }

@media(max-width: 600px) {
    #p4-container { border-radius: 0; min-height: 100vh; }
    .p4-board-container { padding: 5px; gap: 5px; }
}