/* =========================================
   1. RESET E IDENTIDADE VISUAL (PREMIUM DARK)
   ========================================= */
* {
    box-sizing: border-box;
    touch-action: manipulation;
    user-select: none;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* Identidade original mantida */
    background: radial-gradient(circle at center, #1a2a3a 0%, #000000 100%);
    font-family: 'Segoe UI', sans-serif;
    color: white;
}

/* =========================================
   2. ESTRUTURA DA MESA (FLUXO VERTICAL)
   ========================================= */
#mesa {
    display: none;
    flex-direction: column;
    width: 100%;
    height: 100vh; /* Altura fixa da tela para permitir rolagem interna */
    position: relative;
    overflow-y: auto; /* A rolagem acontece aqui */
    overflow-x: hidden;
    padding-bottom: 20px;
}

/* A MÁGICA CONTRA A SOBREPOSIÇÃO: 
   O flex-shrink: 0 impede que as áreas sejam esmagadas. 
   Se não couber na tela, ele empurra para baixo e cria a rolagem! */
#jogos-adversarios, 
.faixa-central, 
#meus-jogos, 
#hud-jogador {
    flex-shrink: 0; 
}

/* =========================================
   3. CABEÇALHO
   ========================================= */
#game-header {
    position: relative;
    z-index: 100;
    background: rgba(0, 0, 0, 0.5);
    border-bottom: 1px solid rgba(255, 215, 0, 0.2);
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
}

.logo {
    color: #f1c40f;
    font-weight: 900;
    font-size: 22px;
    text-shadow: 0 2px 5px black;
    letter-spacing: 1px;
}

#placar-integrado {
    display: flex;
    align-items: center;
    background: rgba(0,0,0,0.6);
    padding: 5px 20px;
    border-radius: 20px;
    border: 1px solid #444;
    gap: 20px;
}

/* --- 3 VERMELHOS NO CABEÇALHO --- */
.tres-vermelhos-header {
    display: flex;
    align-items: center;
    min-width: 45px; /* Mantém o espaço reservado mesmo vazio */
    min-height: 45px;
}

.carta-mini-header {
    width: 32px;
    height: 45px;
    margin-right: -20px; /* Sobreposição horizontal acentuada */
    border-radius: 3px;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.8);
    border: 1px solid rgba(255,255,255,0.2);
    background: white;
    transition: margin 0.2s;
    position: relative;
}

.carta-mini-header:last-child { 
    margin-right: 0; 
}



.carta-mini-header img { 
    width: 100%; 
    height: 100%; 
    display: block; 
    border-radius: 3px; 
}

.time-score { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.time-score .label { font-size: 9px; color: #bbb; font-weight: bold; }
.time-score .score { font-size: 20px; font-weight: bold; }
.azul { color: #3498db; }
.vermelha { color: #e74c3c; }
.vs-divider { color: #666; font-size: 10px; }

#info-jogo {
    margin-top: 5px;
    font-size: 11px;
    color: #f1c40f;
    text-transform: uppercase;
    font-weight: bold;
}

/* =========================================
   4. ÁREAS DOS JOGADORES
   ========================================= */
/* Topo (Parceiro) - Fixo visualmente no topo */
#mao-topo {
    position: absolute;
    top: 80px;
    width: 100%;
    display: flex;
    justify-content: center;
    z-index: 10;
    height: 80px;
    pointer-events: none;
}

/* Jogos dos Adversários (Abaixo do Topo) */
#jogos-adversarios {
    position: relative;
    margin-top: 100px; /* Distância do topo */
    width: 100%;
    min-height: 120px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 25px;
    z-index: 10;
    padding: 0 50px;
}

/* Laterais (Ficam flutuando no meio vertical da tela) */
#mao-esquerda, #mao-direita {
    position: absolute;
    top: 50%; transform: translateY(-50%);
    z-index: 50; /* Z-index alto para ficar acima de cartas da mesa */
    display: flex;
    flex-direction: column;
    align-items: center;
}
#mao-esquerda { left: 10px; }
#mao-direita { right: 10px; }

.info-player {
    background: #111;
    color: #f1c40f;
    border: 1px solid #f1c40f;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
    margin-bottom: 5px;
    box-shadow: 0 2px 5px black;
}

.carta-miniatura {
    width: 40px; height: 56px;
    background: url('https://deckofcardsapi.com/static/img/back.png');
    background-size: cover;
    border-radius: 3px;
    margin-bottom: -40px;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.8);
    border: 1px solid #333;
}

/* =========================================
   5. MESA CENTRAL (MONTE/LIXO) - ÁREA CRÍTICA
   ========================================= */
.faixa-central {
    margin-top: 50px; /* Distância dos adversários */
    margin-bottom: 50px; /* Distância dos seus jogos */
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 60px;
    position: relative;
    z-index: 50; /* Z-index alto para o Lixo e Monte sempre serem clicáveis */
    min-height: 140px;
    pointer-events: auto;
}

/* Reabilita cliques nos elementos interativos */
.slot-mesa { pointer-events: auto; }

.label-mesa {
    font-size: 10px; color: #888; font-weight: bold; letter-spacing: 1px; margin-bottom: 5px;
    text-align: center;
}

#monte, #lixo {
    width: 80px; height: 112px;
    border-radius: 6px;
    position: relative;
    transition: transform 0.1s;
    box-shadow: 0 10px 20px rgba(0,0,0,0.6);
}

#monte {
    background: url('https://deckofcardsapi.com/static/img/back.png');
    background-size: cover;
    cursor: pointer;
    border: 1px solid #444;
}

#lixo {
    border: 2px dashed #555;
    background: rgba(255,255,255,0.05);
    display: flex; justify-content: center; align-items: center;
}

/* Garante tamanho padrão para a carta dentro do lixo */
#carta-lixo .carta {
    width: 80px; height: 112px; 
    border-radius: 6px;
    position: relative; 
    box-shadow: none; /* Remove sombra extra pois já está no container */
}
#carta-lixo img { width: 100%; height: 100%; border-radius: 6px; }

.ativo-brilhando {
    box-shadow: 0 0 20px #f1c40f !important;
    border-color: #f1c40f !important;
    transform: scale(1.05);
    z-index: 50;
    cursor: pointer;
}

.contador-badge {
    position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%);
    background: #3498db; color: white; padding: 2px 6px;
    border-radius: 10px; font-size: 12px; font-weight: bold;
    border: 2px solid #111;
}

#area-mortos {
    position: relative; width: 100px; height: 100px;
}

/* =========================================
   6. SEUS JOGOS NA MESA
   ========================================= */
#meus-jogos {
    width: 100%;
    min-height: 120px;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 30px;
    padding: 10px 50px;
    margin-bottom: 40px; /* Dá um respiro antes da sua mão começar */
    position: relative;
    z-index: 10;
}

.grupo-baixado {
    display: flex;
    flex-direction: row; 
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 5px 10px;
    border-radius: 8px;
    position: relative;
    border: 1px solid rgba(255,255,255,0.1);
}

/* Efeito Leque Horizontal */
/* AS CARTAS NOS JOGOS - SOBREPOSIÇÃO OTIMIZADA */
.grupo-baixado .carta {
    width: 80px; 
    height: 112px; 
    /* A MÁGICA DO ESPAÇO: Aumentamos o valor negativo para esconder mais a carta.
       Como a carta tem 80px, -60px deixa exatamente 20px visíveis (só o número e naipe) */
    margin-right: -68px; 
    
    box-shadow: -2px 0 5px rgba(0,0,0,0.5); /* Sombra para a esquerda ajuda a destacar o corte */
    transition: margin 0.2s ease-in-out;
    background: white;
    border-radius: 6px;
    position: relative;
}

.grupo-baixado .carta img { 
    width: 100%; 
    height: 100%; 
    border-radius: 6px; 
}

.grupo-baixado .carta:last-child { 
    margin-right: 0; /* A última carta do jogo fica 100% visível */
}


/* =========================================
   7. HUD JOGADOR (SUA MÃO)
   ========================================= */
#hud-jogador {
    position: relative;
    width: 100%;
    margin-top: auto; 
    padding: 20px 0;
    background: linear-gradient(to top, #000 60%, transparent);
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    
    /* Permite que o mouse atravesse as áreas vazias do gradiente e clique no Lixo/Monte */
    pointer-events: none; 
}

#minha-mao {
    pointer-events: auto; /* Reativa o clique apenas nos botões e nas cartas */
}

button {
    padding: 10px 20px; border-radius: 5px; border: none;
    font-weight: bold; cursor: pointer; text-transform: uppercase; font-size: 12px;
    box-shadow: 0 4px 0 rgba(0,0,0,0.4);
}
button:active { transform: translateY(2px); box-shadow: none; }

#minha-mao {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
    width: 100%;
    max-width: 1200px;
    padding: 0 10px;
}

#minha-mao .carta {
    width: 80px; height: 112px;
    margin-right: -74px; /* Ajuste este valor (ex: -55px, -65px) conforme a largura real da sua carta para mostrar só o naipe */    
    //box-shadow: -2px 0 6px rgba(0,0,0,0.5);
    transition: transform 0.2s, margin 0.2s;
    cursor: pointer;
    border-radius: 6px;
    background: white;
    position: relative;
}
#minha-mao .carta img { width: 100%; height: 100%; border-radius: 6px; display: block; }
#minha-mao .carta:last-child { margin-right: 0; }

#minha-mao .carta.selecionada {
   /*transform: translateY(-25px);*/
    box-shadow: 0 0 0 3px #2ecc71, 0 10px 20px black;
    //z-index: 90;
}

/* =========================================
   8. FERRAMENTAS E MODAIS
   ========================================= */
#barra-ferramentas {
    position: fixed; /* Mantém os botões sempre visíveis na tela */
    bottom: 220px;   /* A MÁGICA: Empurra os botões para cima (ajuste esse valor se precisar de mais espaço) */
    right: 20px;     /* Cola na margem direita */
    display: flex;
    flex-direction: column; /* Empilha os botões verticalmente (um em cima do outro) */
    gap: 15px;       /* Espaço entre um botão e outro */
    z-index: 90;     /* Garante que fiquem por cima da mesa, mas abaixo de modais */
}

#barra-ferramentas button:hover {
    background: rgba(241, 196, 15, 0.9); /* Dourado ao passar o mouse */
    color: #000;
    transform: scale(1.1);
}

.btn-icone {
    width: 50px; height: 50px; background: #222; border: 2px solid #444;
    border-radius: 50%; display: flex; justify-content: center; align-items: center;
    font-size: 20px; cursor: pointer; color: #f1c40f;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}

.watermark {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    font-size: 30px; font-weight: 900; color: rgba(255,255,255,0.03);
    pointer-events: none; white-space: nowrap;
}

/* Modal Fim de Jogo */
#modal-fim {
    display: none; /* A CORREÇÃO ESTÁ AQUI: Deve iniciar oculto */
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.95); z-index: 5000;
    flex-direction: column; align-items: center;
    overflow-y: auto; padding: 40px 20px;
}
.tabela-extrato {
    background: #111; border: 1px solid #444; border-radius: 10px;
    width: 100%; max-width: 600px; margin-bottom: 20px;
    display: grid; grid-template-columns: 1.5fr 1fr 1fr;
}
.item-label, .item-valor {
    padding: 10px; border-bottom: 1px solid #333; font-size: 13px; color: #ccc;
    display: flex; align-items: center;
}
.item-label.header { color: #f1c40f; font-weight: bold; background: #222; }
.item-valor.header { color: #f1c40f; font-weight: bold; background: #222; justify-content: center; }
.item-valor { justify-content: center; }

@media (max-width: 768px) {
    /* No mobile, aumenta o espaço para garantir que não haja sobreposição */
   #jogos-adversarios { margin-top: 100px; padding: 0 10px; gap: 15px; }    
   .faixa-central { margin-top: 60px; gap: 20px; transform: scale(0.9); }
    
    /* Cartas menores para caber na tela do celular */
    .grupo-baixado .carta, #minha-mao .carta, #monte, #lixo, #carta-lixo .carta {
        width: 60px; height: 84px;
        margin-right: -35px;
    }
}

/* =========================================
   RESPONSIVIDADE: BARRA SUPERIOR (MOBILE)
   ========================================= */

@media (max-width: 768px) {
    /* 1. O ID correto: Trava a largura da barra superior */
    #game-header { 
        width: 100vw !important;
        max-width: 100vw !important;
        box-sizing: border-box;
        padding: 5px;
        display: flex;
        flex-wrap: nowrap; /* Força tudo a ficar na mesma linha */
        justify-content: space-between;
        align-items: center;
        gap: 2px;
        overflow: hidden; /* Corta qualquer coisa que tentar vazar */
    }

    /* 2. Oculta botões de texto no cabeçalho (Sair/Reiniciar) para liberar espaço */
    #game-header button {
        display: none !important;
    }

    /* 3. Reduz a logo e o placar para não esmagarem as cartas */
    #game-header .logo {
        font-size: 14px !important;
        letter-spacing: 0;
    }
    
    #placar-integrado {
        padding: 2px 8px !important;
        gap: 10px !important;
        transform: scale(0.85); /* Encolhe o placar todo proporcionalmente */
        transform-origin: center;
    }

    /* 4. Encolhe agressivamente os 3 Vermelhos e sobrepõe as cartas */
    #tres-vermelhos-nos, #tres-vermelhos-eles {
        display: flex;
        flex-shrink: 1;
        min-width: 0;
    }
    .carta-mini-header {
        width: 16px !important; /* Tamanho bem reduzido para celular */
        height: 24px !important;
        margin-right: -8px !important; /* Sobrepõe os 3 vermelhos */
    }
    .carta-mini-header:last-child {
        margin-right: 0 !important;
    }

    /* 5. Reduz as fontes dos status */
    #info-jogo {
        font-size: 10px !important;
        white-space: nowrap; 
    }

    /* 6. Encolhe a área que mostra as cartas na mão do adversário */
    .mao-adversario {
        transform: scale(0.7); 
        transform-origin: center right;
    }
   /* A MÁGICA NO MOBILE: Sobreposição extrema para a sua mão e jogos baixados */
    .grupo-baixado .carta, #minha-mao .carta {
        width: 60px; 
        height: 84px;
        /* Como a carta tem 60px, -45px deixa apenas 15px visíveis (exatamente o naipe e valor) */
        margin-right: -45px !important; 
    }

    /* Garante que a última carta de cada jogo/mão fica 100% visível no mobile */
    .grupo-baixado .carta:last-child, #minha-mao .carta:last-child {
        margin-right: 0 !important;
    }
}

