/* --- VARIABLES DE TAILLE --- */
:root {
    /* Taille de base sur grand écran */
    --card-w: 70px;
    --card-h: 100px;
    --pile-scale: 1.2;
    --zone-scale: 1;
}

/* --- RESET & FOND --- */
body {
    background: radial-gradient(circle at center, #2c3e50 0%, #000000 100%);
    color: white;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
    margin: 0; padding: 0;
}

.screen {
    width: 100vw;
}
#screen-game{
    padding-top: 0;
    height: 100vh;
}

.game-board {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* --- BOUTONS & ANNONCES --- */

.btn-quit {
    pointer-events: auto;
    position: fixed; top: 15px; right: 15px;
    background: #c0392b; border: none; color: white;
    width: 45px; height: 45px; border-radius: 50%;
    cursor: pointer; z-index: 200; font-size: 1.2em;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

/* --- ZONE CENTRALE (Paquet) --- */
.center-table {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    display: flex; gap: 20px;
    z-index: 50;
    padding: 20px;
    transition: top 0.5s ease, transform 0.5s ease;
}

.center-table.layout-3p {
    top: 50%;
}
.pile-container { text-align: center; }
.pile-label { color: #7f8c8d; font-size: 0.7em; margin-top: 5px; text-transform: uppercase; letter-spacing: 1px; font-weight: bold;}
.pile {
    width: calc(var(--card-w) * var(--pile-scale)); 
    height: calc(var(--card-h) * var(--pile-scale));
    border-radius: 8px;
    border: 2px dashed rgba(255,255,255,0.2);
    display: flex; justify-content: center; align-items: center;
    cursor: pointer; transition: 0.2s; background: rgba(255,255,255,0.05);
}
.pile.glow { box-shadow: 0 0 25px #f1c40f; border-color: #f1c40f; transform: scale(1.05); background: rgba(241, 196, 15, 0.1); }

/* --- CARTES --- */
.card {
    width: var(--card-w); 
    height: var(--card-h);
    border-radius: 8px;
    position: relative;
    box-shadow: 2px 4px 8px rgba(0,0,0,0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Segoe UI', sans-serif;
    font-weight: 800;
    border: 2px solid rgba(255,255,255,0.3);
    overflow: hidden;
    transition: transform 0.2s;
    background-color: #ecf0f1; /* Fallback */
}

/* Dos de carte : Motif géométrique */
.card.back {
    background: #2c3e50;
    background-image: 
        linear-gradient(45deg, #34495e 25%, transparent 25%, transparent 75%, #34495e 75%, #34495e),
        linear-gradient(45deg, #34495e 25%, transparent 25%, transparent 75%, #34495e 75%, #34495e);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    border: 2px solid #bdc3c7;
}
/* On cache le texte sur le dos */
.card.back * { display: none; }

/* --- COULEURS DES CARTES --- */
.card-bonus { 
    background: linear-gradient(135deg, #9b59b6, #8e44ad); 
    color: white; 
    text-shadow: 0 2px 0 rgba(0,0,0,0.2);
} /* -2 */

.card-zero { 
    background: linear-gradient(135deg, #f1c40f, #f39c12); 
    color: #fff; 
    text-shadow: 0 2px 0 rgba(0,0,0,0.2);
    border-color: #f1c40f;
} /* Roi */

.card-low { 
    background: linear-gradient(135deg, #2ecc71, #27ae60); 
    color: white; 
} /* 1 à 5 */

.card-neutral { 
    background: linear-gradient(135deg, #3498db, #2980b9); 
    color: white; 
} /* 6 à 9 */

.card-high { 
    background: linear-gradient(135deg, #e74c3c, #c0392b); 
    color: white; 
} /* 10, V, D */

/* --- TYPOGRAPHIE --- */
.card-center-text {
    font-size: 2.2em;
    z-index: 2;
}

.corner {
    position: absolute;
    font-size: 0.9em;
    opacity: 0.8;
}

.tl { top: 2px; left: 4px; }
.br { bottom: 2px; right: 4px; transform: rotate(180deg); }
.card-center { font-size: 1.4em; }

/* Couleurs spéciales */
.card[data-val="-2"] { background: #9b59b6; color: white; } /* Joker */
.card[data-val="0"] { background: #f1c40f; color: black; } /* Roi */

/* --- POSITIONNEMENT JOUEURS --- */
.player-zone {
    position: absolute;
    width: auto; 
    min-width: 160px;
    display: flex; 
    flex-direction: column; 
    align-items: center;
    transition: all 0.5s ease;
    z-index: 60;
    transform-origin: center center;
    scale: var(--zone-scale);
}

/* 2 JOUEURS */
.pos-p2-left {top: 50%; left: 15vw; transform-origin: left center; transform: translate(0, -50%); }
.pos-p2-right { top: 50%; right: 15vw; transform-origin: right center; transform: translate(0, -50%); }

/* 3 JOUEURS */
.pos-top { top: 10vh; left: 49%; transform-origin: top center; transform: translate(-50%, 0); } /* Collé en haut */
.pos-bottom-left { bottom: 8vh; left: 15%; transform-origin: bottom left; transform: translate(0, 0); }
.pos-bottom-right { bottom: 8vh; right: 15%; transform-origin: bottom right; transform: translate(0, 0); }

/* 4 JOUEURS (Carré / Croix) */
/* Haut (Moi), Droite, Bas, Gauche */
.pos-4p-0 { bottom: 6%; left: 8%; transform: translate(0, 0); } /* Bas-gauche */
.pos-4p-1 { top: 6%; left: 8%; transform: translate(0, 0); }    /* Haut-gauche */
.pos-4p-2 { top: 6%; right: 8%; transform: translate(0, 0); }   /* Haut-droite */
.pos-4p-3 { bottom: 6%; right: 8%; transform: translate(0, 0); }/* Bas-droite */

/* 5 JOUEURS (Pentagone) */
.pos-5p-0 { bottom: 2%; left: 50%; transform: translateX(-50%); } /* Moi */
.pos-5p-1 { bottom: 25%; left: 2%; }
.pos-5p-2 { top: 5%; left: 20%; }
.pos-5p-3 { top: 5%; right: 20%; }
.pos-5p-4 { bottom: 25%; right: 2%; }

/* 6 JOUEURS (Hexagone) */
.pos-6p-0 { bottom: 2%; left: 50%; transform: translateX(-50%); } /* Moi */
.pos-6p-1 { bottom: 25%; left: 2%; }
.pos-6p-2 { top: 15%; left: 2%; }
.pos-6p-3 { top: 2%; left: 50%; transform: translateX(-50%); } /* Face */
.pos-6p-4 { top: 15%; right: 2%; }
.pos-6p-5 { bottom: 25%; right: 2%; }

/* 7 JOUEURS (Heptagone) */
.pos-7p-0 { bottom: 2%; left: 50%; transform: translateX(-50%); } /* Moi */
.pos-7p-1 { bottom: 20%; left: 2%; }
.pos-7p-2 { top: 30%; left: 2%; }
.pos-7p-3 { top: 2%; left: 30%; }
.pos-7p-4 { top: 2%; right: 30%; }
.pos-7p-5 { top: 30%; right: 2%; }
.pos-7p-6 { bottom: 20%; right: 2%; }

/* 8 JOUEURS (Octogone) */
.pos-8p-0 { bottom: 2%; left: 50%; transform: translateX(-50%); } /* Moi */
.pos-8p-1 { bottom: 20%; left: 2%; }
.pos-8p-2 { top: 40%; left: 2%; transform: translateY(-50%); }
.pos-8p-3 { top: 10%; left: 15%; }
.pos-8p-4 { top: 2%; left: 50%; transform: translateX(-50%); } /* Face */
.pos-8p-5 { top: 10%; right: 15%; }
.pos-8p-6 { top: 40%; right: 2%; transform: translateY(-50%); }
.pos-8p-7 { bottom: 20%; right: 2%; }


.player-label {
    /* On remonte un peu le label pour qu'il ne gêne pas la grille */
    position: relative;
    top: 0;
    margin-bottom: 5px;
}
/* Équipe C (Vert) */
.player-label.team-c .player-avatar {
    background: #d5f5e3;
    color: #27ae60;
    border-color: #2ecc71;
}
.player-label.team-c { border-left: 4px solid #2ecc71; }

/* Équipe D (Jaune) */
.player-label.team-d .player-avatar {
    background: #fcf3cf;
    color: #f39c12;
    border-color: #f1c40f;
}
.player-label.team-d { border-left: 4px solid #f1c40f; }

/* Équipe E (Violet) */
.player-label.team-e .player-avatar {
    background: #f5eef8;
    color: #8e44ad;
    border-color: #9b59b6;
}
.player-label.team-e { border-left: 4px solid #9b59b6; }

/* Équipe F (Orange) */
.player-label.team-f .player-avatar {
    background: #fdf2e9;
    color: #d35400;
    border-color: #e67e22;
}
.player-label.team-f { border-left: 4px solid #e67e22; }

/* Équipe G (Rose) */
.player-label.team-g .player-avatar {
    background: #fdeef8;
    color: #c71585;
    border-color: #ff69b4;
}
.player-label.team-g { border-left: 4px solid #ff69b4; }

/* Équipe H (Cyan) */
.player-label.team-h .player-avatar {
    background: #e8f8f5;
    color: #16a085;
    border-color: #1abc9c;
}
.player-label.team-h { border-left: 4px solid #1abc9c; }

/* GRILLES */
.grid-container {
    display: grid; gap: 4px;
    padding: 6px;
    background: rgba(255,255,255,0.1); border-radius: 12px;
    backdrop-filter: blur(2px);
    border: 1px solid rgba(255,255,255,0.05);
}
.grid-9 { grid-template-columns: repeat(3, 1fr); }
.grid-6 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(2, 1fr); }

/* INTERACTION */
.clickable:hover { transform: translateY(-8px) scale(1.05); cursor: pointer; border-color: #f1c40f; z-index: 10; }
.targetable { animation: pulse 1s infinite; border: 2px solid #e056fd !important; cursor: pointer; }
.peeked { border: 2px solid #2ecc71 !important; box-shadow: 0 0 10px #2ecc71; opacity: 0.6;}

/* OVERLAY ACTION */
.drawn-area {
    position: absolute; top: 68%; left: 50%;
    transform: translate(-50%, -50%);
    background: #2d3436; padding: 15px; border-radius: 15px;
    border: 1px solid rgba(255,255,255,0.2);
    z-index: 100; text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
}
.drawn-area.hidden { display: none; }

/* Animation de surbrillance pour les grilles cibles */
.grid-container.highlight-target {
    box-shadow: 0 0 15px #e056fd;
    border-color: #e056fd;
    animation: pulseGrid 1.5s infinite;
}

@keyframes pulseGrid { 
    0% { box-shadow: 0 0 5px #e056fd; border-color: rgba(224, 86, 253, 0.5); } 
    50% { box-shadow: 0 0 20px #e056fd; border-color: #e056fd; } 
    100% { box-shadow: 0 0 5px #e056fd; border-color: rgba(224, 86, 253, 0.5); } 
}

.btn-action { margin-top: 8px; padding: 8px 16px; border:none; border-radius:6px; color:white; font-weight:bold; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.btn-red { background: #c0392b; }
.btn-purple { background: #8e44ad; }
.btn-blue { background: #2980b9; }

/* MOBILE */
@media (max-width: 700px) {
    :root { --card-w: 42px; --card-h: 58px; }
    .card { width: 45px; height: 63px; font-size: 0.9em; }
    .pile { width: 60px; height: 84px; }
    .player-zone { width: auto; }
    
    /* Mobile: 2J Haut/Bas pour lisibilité, ou garder Gauche/Droite mais serré */
    .pos-p2-left { left: 2%; scale: 0.9; }
    .pos-p2-right { right: 2%; scale: 0.9; }
    
    .pos-bottom-left { bottom: 10%; left: 5%; scale: 0.85; }
    .pos-bottom-right { bottom: 10%; right: 5%; scale: 0.85; }
    
    .pos-bottom { bottom: 60px; } /* Place pour l'interface navigateur */
    
    /* Les joueurs sur les côtés sont réduits pour laisser place au centre */
    .pos-left, .pos-right, .pos-p2-left, .pos-p2-right {
        scale: 0.75; 
    }
}

@keyframes pulse { 0% { box-shadow: 0 0 0px #e056fd; } 100% { box-shadow: 0 0 20px #e056fd; } }

.selected-swap {
    border: 3px solid #e74c3c !important;
    transform: translateY(-10px);
    box-shadow: 0 0 15px #e74c3c;
}

.grid-finished {
    opacity: 0.6;
    filter: grayscale(100%);
    transition: all 0.5s ease;
    pointer-events: none; /* Empêche de cliquer dessus (optionnel) */
}

/* ADAPTATION RESPONSIVE (Largeur ET Hauteur) */
@media (max-width: 1400px), (max-height: 800px) {
    :root { --card-w: 60px; --card-h: 84px; }
}

@media (max-width: 1000px), (max-height: 650px) {
    :root { --card-w: 50px; --card-h: 70px; --zone-scale: 0.9; }
}

@media (max-width: 600px) {
    :root { --card-w: 40px; --card-h: 56px; --zone-scale: 0.85; }

    /* 2 JOUEURS */
    .pos-p2-left {top: 5vh; left: 50%; transform-origin: left center; transform: translate(-50%, 0); }
    .pos-p2-right { bottom: 5vh; right: 50%; transform-origin: right center; transform: translate(50%, 0); }

    .center-table {
        top: 45%;
    }
}

/* --- SCOREBOARD (Style Tarot) --- */
.scoreboard-container { width: 100%; text-align: center; color: #2c3e50; }
.scoreboard-container h2 { margin-top: 0; color: #2c3e50; }

/* Table des scores */
.score-table { 
    width: 100%; 
    border-collapse: collapse; 
    margin-bottom: 20px; 
    background: white; 
    border-radius: 8px; 
    overflow: hidden; 
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.score-table th { 
    background: #34495e; 
    color: white; 
    padding: 12px; 
    font-size: 0.9em; 
    text-transform: uppercase; 
}

.score-table td { 
    padding: 12px; 
    border-bottom: 1px solid #bdc3c7; 
    color: #2c3e50; 
}

.score-table tr:last-child td { border-bottom: none; }
.score-table tr.is-me { background: #fff9c4; font-weight: bold; }

/* Valeurs */
.total-score { font-size: 1.2em; font-weight: bold; }
.round-delta { font-size: 1em; font-weight: bold; }

/* Couleurs Golf : Positif = Mauvais (Rouge), Négatif/Zéro = Bon (Vert) */
.positive { color: #27ae60; } /* Vert */
.negative { color: #c0392b; } /* Rouge */
.neutral { color: #7f8c8d; }  /* Gris */

.scoreboard-actions { display: flex; justify-content: center; gap: 15px; margin-top: 10px; }
.waiting-msg { font-style: italic; color: #7f8c8d; }

/* Ajustement Modale pour fond clair */
#score-modal .modal-box, #game-over-modal .modal-box {
    background: #ecf0f1; /* Fond gris clair */
    color: #2c3e50;
    padding: 20px;
    border-radius: 15px;
    max-width: 600px;
    width: 90%;
}

/* --- ANIMATION SCORE --- */
@keyframes popScore {
    0% { transform: scale(1); }
    50% { transform: scale(1.5); }
    100% { transform: scale(1); }
}

.anim-score-up {
    color: #e74c3c !important; /* Rouge (Mauvais au Golf) */
    animation: popScore 0.6s ease;
    display: inline-block; /* Nécessaire pour le transform */
}

.anim-score-down {
    color: #2ecc71 !important; /* Vert (Bon au Golf) */
    animation: popScore 0.6s ease;
    display: inline-block;
}

/* 1. Retournement (Flip) */
@keyframes flipIn {
    0% { transform: rotateY(90deg); opacity: 0.5; }
    100% { transform: rotateY(0deg); opacity: 1; }
}

.anim-flip {
    animation: flipIn 0.5s ease-out forwards;
}

/* 2. Carte Volante (Déplacement vers défausse) */
.flying-card {
    position: fixed; /* Fixe par rapport à l'écran pour ignorer les conteneurs */
    z-index: 9999;
    pointer-events: none;
    transition: all 0.6s cubic-bezier(0.25, 0.8, 0.25, 1); /* Mouvement fluide */
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
}
/* Compteur de cartes sur la pioche */
.pile-count {
    position: absolute;
    background: #e74c3c;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    line-height: 24px;
    font-size: 0.8em;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    z-index: 101;
}

/* Bouton Finir la manche */
.btn-finish-round {
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.75em;
    font-weight: bold;
    cursor: pointer;
    margin-top: 4px;
    text-transform: uppercase;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: background 0.2s;
    animation: popIn 0.3s ease-out;
}

.btn-finish-round:hover {
    background: #c0392b;
}

@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}