:root {
    --bg-dark: #1a1a2e;
    --bg-table: #2d5016;
    --bg-card: #f5f5dc;
    --gold: #d4af37;
    --red: #c41e3a;
    --black: #1a1a1a;
    --accent: #e94560;
    --green-felt: #35654d;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Cairo', sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, #16213e 100%);
    min-height: 100vh;
    color: white;
    overflow-x: hidden;
}

/* Écran d'accueil */
.screen {
    display: none;
    min-height: 100vh;
    padding: 20px;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.title {
    font-family: 'Playfair Display', serif;
    font-size: 4rem;
    color: var(--gold);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    margin-bottom: 10px;
    text-align: center;
}

.subtitle {
    font-size: 1.5rem;
    color: #ccc;
    margin-bottom: 40px;
}

.btn {
    background: linear-gradient(135deg, var(--gold), #b8941f);
    color: var(--bg-dark);
    border: none;
    padding: 15px 40px;
    font-size: 1.3rem;
    font-weight: 700;
    border-radius: 50px;
    cursor: pointer;
    margin: 10px;
    transition: all 0.3s;
    font-family: 'Cairo', sans-serif;
    box-shadow: 0 4px 15px rgba(212, 175, 55, 0.3);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(212, 175, 55, 0.5);
}

.btn-secondary {
    background: transparent;
    border: 2px solid var(--gold);
    color: var(--gold);
}

.btn-secondary:hover {
    background: var(--gold);
    color: var(--bg-dark);
}

/* Table de jeu */
.game-container {
    display: none;
    width: 100%;
    min-height: 100vh;
    flex-direction: column;
}

.game-container.active {
    display: flex;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(10px);
}

.score-board {
    display: flex;
    gap: 20px;
    font-size: 1.1rem;
}

.score-item {
    background: rgba(255,255,255,0.1);
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid var(--gold);
}

.score-item.highlight {
    background: var(--gold);
    color: var(--bg-dark);
    font-weight: 700;
}

/* Zone de jeu principale */
.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    position: relative;
}

/* Main adverse (IA) */
.opponent-hand {
    display: flex;
    margin-bottom: 20px;
    perspective: 1000px;
}

.opponent-hand .card {
    cursor: default;
}

/* Tapis (cartes au centre) */
.table-area {
    width: 100%;
    max-width: 800px;
    min-height: 200px;
    background: radial-gradient(ellipse at center, var(--green-felt) 0%, var(--bg-table) 100%);
    border-radius: 20px;
    border: 3px solid var(--gold);
    padding: 30px;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    align-items: center;
    box-shadow: inset 0 0 50px rgba(0,0,0,0.5), 0 10px 30px rgba(0,0,0,0.3);
    position: relative;
}

.table-label {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.5);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* Main du joueur */
.player-hand {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    perspective: 1000px;
}

/* Cartes */
.card {
    width: 100px;
    height: 140px;
    background: var(--bg-card);
    border-radius: 10px;
    border: 2px solid #333;
    position: relative;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 8px;
    user-select: none;
}

.card:hover {
    transform: translateY(-20px) rotate(0deg) !important;
    z-index: 100;
    box-shadow: 0 10px 25px rgba(0,0,0,0.4);
}

.card.selected {
    transform: translateY(-30px) !important;
    box-shadow: 0 0 20px var(--gold);
    border-color: var(--gold);
}

.card.playable {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 5px var(--gold); }
    50% { box-shadow: 0 0 20px var(--gold); }
}

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    font-size: 1.2rem;
    font-weight: 700;
}

.card-center {
    font-size: 2.5rem;
    text-align: center;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-bottom {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    font-size: 1.2rem;
    font-weight: 700;
    transform: rotate(180deg);
}

.red { color: var(--red); }
.black { color: var(--black); }

.suit {
    font-size: 1.5rem;
}

/* Animations */
@keyframes deal {
    from {
        opacity: 0;
        transform: translateY(-100px) rotateY(180deg);
    }
    to {
        opacity: 1;
        transform: translateY(0) rotateY(0);
    }
}

@keyframes capture {
    to {
        transform: scale(0) rotate(720deg);
        opacity: 0;
    }
}

@keyframes chkobba {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); box-shadow: 0 0 50px var(--gold); }
    100% { transform: scale(1); }
}

.animate-deal {
    animation: deal 0.5s ease-out;
}

.animate-capture {
    animation: capture 0.6s ease-in forwards;
}

.animate-chkobba {
    animation: chkobba 0.5s ease-out;
}

/* Messages et notifications */
.message-area {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.9);
    padding: 30px 50px;
    border-radius: 20px;
    border: 2px solid var(--gold);
    text-align: center;
    z-index: 1000;
    display: none;
}

.message-area.show {
    display: block;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.chkobba-text {
    font-size: 3rem;
    color: var(--gold);
    font-weight: 900;
    text-shadow: 0 0 20px var(--gold);
}

/* Modal règles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: linear-gradient(135deg, #1a1a2e, #0f3460);
    border: 2px solid var(--gold);
    border-radius: 20px;
    padding: 30px;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
    width: 100%;
}

.modal h2 {
    color: var(--gold);
    margin-bottom: 20px;
    text-align: center;
}

.modal h3 {
    color: var(--accent);
    margin: 15px 0 10px;
}

.modal p, .modal li {
    line-height: 1.6;
    margin-bottom: 8px;
}

.modal ul {
    padding-left: 20px;
}

.close-modal {
    float: right;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gold);
}

/* Images des cartes */
.card-img {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

.card-back {
    background: linear-gradient(135deg, #8b0000, #5c0000);
    border: 2px solid var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-back-icon {
    font-size: 2.5rem;
}

/* ============================================================
   TABLEAU DE RÉSULTAT
   ============================================================ */

.result-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    font-size: 1rem;
}

.result-table th,
.result-table td {
    padding: 10px 12px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.result-table th {
    background: rgba(212, 175, 55, 0.15);
    color: var(--gold);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 1px;
}

.result-table td:first-child {
    text-align: left;
}

.tbl-crit {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.tbl-icon {
    font-size: 1.2rem;
}

.tbl-val {
    font-weight: 700;
    color: #fff;
}

.result-table .winner-row td {
    background: rgba(212, 175, 55, 0.08);
}

.result-table .winner-row-opponent td {
    background: rgba(212, 175, 55, 0.08);
}

.result-table .winner-row .tbl-val.gold,
.result-table .winner-row-opponent .tbl-val.gold {
    color: var(--gold);
}

.result-table tfoot tr {
    border-top: 2px solid var(--gold);
    font-weight: 700;
}

.tbl-total td {
    padding-top: 12px;
    color: #ddd;
}

.tbl-grand-total td {
    font-size: 1.2rem;
    color: var(--gold);
}

/* ============================================================
   CHOIX DE CAPTURE (mode manuel)
   ============================================================ */

.capture-options-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gold);
    margin-bottom: 10px;
    text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

.capture-option-btn {
    display: block;
    width: 100%;
    max-width: 320px;
    margin: 8px auto;
    padding: 12px 20px;
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'Cairo', sans-serif;
    color: #fff;
    background: linear-gradient(135deg, var(--green-felt), var(--bg-table));
    border: 2px solid var(--gold);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.capture-option-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(212, 175, 55, 0.3);
    background: linear-gradient(135deg, #3d7a5c, #3a6018);
}

.capture-option-btn.cancel {
    background: transparent;
    border-color: #e94560;
    color: #e94560;
    font-size: 0.95rem;
    padding: 10px 20px;
}

.capture-option-btn.cancel:hover {
    background: rgba(233, 69, 96, 0.15);
}

/* Responsive */
@media (max-width: 768px) {
    .title { font-size: 2.5rem; }
    .card { width: 85px; height: 119px; }
    .table-area { padding: 15px; min-height: 150px; }
    .score-board { flex-wrap: wrap; justify-content: center; }
    .result-table th, .result-table td { padding: 8px; font-size: 0.9rem; }

    /* Historique déplacé en haut à droite pour ne pas masquer la main du joueur */
    .game-log {
        top: 10px;
        right: 10px;
        bottom: auto;
        left: auto;
        max-width: 150px;
        max-height: 110px;
        font-size: 0.75rem;
        padding: 8px;
        border-radius: 8px;
    }

    /* Bouton Annuler plus discret en mobile */
    .capture-option-btn { padding: 8px 14px; font-size: 0.9rem; }
    .capture-option-btn.cancel { padding: 6px 10px; font-size: 0.85rem; }
}

/* Historique des actions */
.game-log {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0,0,0,0.7);
    padding: 15px;
    border-radius: 10px;
    max-width: 300px;
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.85rem;
    border: 1px solid rgba(255,255,255,0.2);
}

.game-log div {
    margin-bottom: 5px;
    padding: 3px 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.log-capture { color: #4ade80; }
.log-chkobba { color: var(--gold); font-weight: 700; }
.log-system { color: #60a5fa; }

/* Indicateur de tour */
.turn-indicator {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: white;
    padding: 10px 30px;
    border-radius: 30px;
    font-weight: 700;
    display: none;
    z-index: 100;
}

.turn-indicator.show {
    display: block;
    animation: bounce 1s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-10px); }
}

/* Écran de fin de manche */
.round-summary {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    z-index: 1500;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.round-summary.active {
    display: flex;
}

.summary-box {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border: 3px solid var(--gold);
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    max-width: 500px;
    width: 90%;
}

.summary-box h2 {
    color: var(--gold);
    font-size: 2rem;
    margin-bottom: 20px;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    font-size: 1.1rem;
}

.summary-item.winner {
    color: var(--gold);
    font-weight: 700;
    font-size: 1.3rem;
}

.arabic-name {
    font-family: 'Cairo', sans-serif;
    color: #888;
    font-size: 0.9rem;
}

/* ============================================================
   ÉCRAN DE RÉSULTAT — FIN DE MANCHE & FIN DE PARTIE
   ============================================================ */

.summary-box {
    background: linear-gradient(145deg, #1a1a2e 0%, #0f1629 50%, #1a1a2e 100%);
    border: 3px solid var(--gold);
    border-radius: 24px;
    padding: 40px;
    text-align: center;
    max-width: 520px;
    width: 90%;
    box-shadow: 0 0 40px rgba(212, 175, 55, 0.15), inset 0 0 60px rgba(0,0,0,0.4);
    animation: slideUp 0.5s ease-out;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(40px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0)     scale(1); }
}

.summary-box h2 {
    color: var(--gold);
    font-size: 2.2rem;
    margin-bottom: 8px;
    text-shadow: 0 2px 8px rgba(212, 175, 55, 0.3);
}

.summary-subtitle {
    color: #aaa;
    font-size: 1rem;
    margin-bottom: 24px;
}

/* --- Lignes de score --- */
.summary-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    margin-bottom: 8px;
    border-radius: 12px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.05);
    transition: background 0.2s;
}

.summary-row:hover {
    background: rgba(255,255,255,0.06);
}

.summary-row.winner-row {
    background: rgba(212, 175, 55, 0.1);
    border-color: rgba(212, 175, 55, 0.25);
}

.summary-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.05rem;
    color: #ddd;
}

.summary-icon {
    font-size: 1.3rem;
    width: 28px;
    text-align: center;
}

.summary-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
}

.summary-value.gold {
    color: var(--gold);
}

/* --- Barres comparatives --- */
.summary-bars {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 6px;
}

.summary-bar-track {
    flex: 1;
    height: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
    overflow: hidden;
}

.summary-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.6s ease-out;
}

.summary-bar-fill.player { background: var(--accent); }
.summary-bar-fill.opponent { background: #666; }

/* --- Totaux --- */
.summary-total-box {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid var(--gold);
}

.summary-total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    font-size: 1.3rem;
    font-weight: 700;
}

.summary-total-row.gold {
    color: var(--gold);
    font-size: 1.5rem;
    text-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
}

/* --- Badge gagnant manche --- */
.manche-winner-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--gold), #b8941f);
    color: #1a1a2e;
    padding: 8px 20px;
    border-radius: 30px;
    font-weight: 900;
    font-size: 1.1rem;
    margin: 16px 0 8px;
    box-shadow: 0 4px 15px rgba(212, 175, 55, 0.3);
    animation: popIn 0.4s ease-out;
}

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

/* ============================================================
   ÉCRAN DE FIN DE PARTIE
   ============================================================ */

.game-over-title {
    font-family: 'Playfair Display', serif;
    font-size: 3.2rem;
    color: var(--gold);
    text-shadow: 0 0 30px rgba(212, 175, 55, 0.4);
    margin-bottom: 10px;
    animation: fadeInScale 0.6s ease-out;
}

.game-over-title.lose {
    color: #e94560;
    text-shadow: 0 0 30px rgba(233, 69, 96, 0.3);
}

@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.8); }
    to   { opacity: 1; transform: scale(1); }
}

.game-over-trophy {
    font-size: 5rem;
    margin: 10px 0 20px;
    display: block;
    animation: trophyPulse 1.5s ease-in-out infinite;
}

@keyframes trophyPulse {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 10px rgba(212,175,55,0.5)); }
    50%      { transform: scale(1.15); filter: drop-shadow(0 0 25px rgba(212,175,55,0.8)); }
}

.game-over-message {
    font-size: 1.4rem;
    color: #fff;
    margin-bottom: 8px;
    font-weight: 700;
}

.game-over-sub {
    font-size: 1rem;
    color: #aaa;
    margin-bottom: 24px;
}

.game-over-scoreboard {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    margin: 20px 0;
    padding: 20px;
    background: rgba(0,0,0,0.25);
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.08);
}

.score-block {
    text-align: center;
}

.score-block .score-name {
    font-size: 0.95rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 6px;
}

.score-block .score-num {
    font-size: 3rem;
    font-weight: 900;
    color: #fff;
    line-height: 1;
}

.score-block.winner .score-num {
    color: var(--gold);
    text-shadow: 0 0 15px rgba(212, 175, 55, 0.4);
}

.score-block.loser .score-num {
    color: #888;
}

.score-divider {
    font-size: 2rem;
    color: var(--gold);
    font-weight: 700;
}

/* Confettis CSS */
.confetti-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: -1;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--gold);
    animation: confettiFall linear forwards;
}

@keyframes confettiFall {
    0%   { transform: translateY(-10vh) rotate(0deg); opacity: 1; }
    100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* ============================================================
   PARAMÈTRES DE JEU (écran d'accueil)
   ============================================================ */

.settings-box {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(212, 175, 55, 0.25);
    border-radius: 16px;
    padding: 20px 24px;
    margin-bottom: 20px;
    max-width: 420px;
    width: 90%;
    text-align: left;
}

.setting {
    margin-bottom: 16px;
}

.setting:last-child {
    margin-bottom: 0;
}

.setting label {
    display: block;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--gold);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.radio-btn {
    background: rgba(0,0,0,0.3);
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: 30px;
    padding: 8px 16px;
    font-size: 0.9rem;
    color: #ccc;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.radio-btn:hover {
    border-color: var(--gold);
    color: #fff;
}

.radio-btn input[type="radio"] {
    accent-color: var(--gold);
    cursor: pointer;
}

.radio-btn:has(input:checked) {
    background: rgba(212, 175, 55, 0.15);
    border-color: var(--gold);
    color: #fff;
    font-weight: 700;
}

/* ============================================================
   ÉCRANS MULTIJOUEUR
   ============================================================ */

.lobby-player {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 10px;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.lobby-player span:first-child {
    font-weight: 700;
}

/* ============================================================
   BOUTON ACTION MODE MANUEL
   ============================================================ */

#playActionBtn {
    animation: fadeIn 0.3s ease-out;
}

/* Responsive */
@media (max-width: 768px) {
    .summary-box { padding: 24px; border-radius: 18px; }
    .summary-box h2 { font-size: 1.6rem; }
    .game-over-title { font-size: 2.2rem; }
    .game-over-trophy { font-size: 3.5rem; }
    .score-block .score-num { font-size: 2.2rem; }
    .game-over-scoreboard { gap: 16px; padding: 14px; }
    .settings-box { padding: 16px; }
    .radio-btn { padding: 6px 12px; font-size: 0.85rem; }
}
