/* ===== RESET E BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', 'Comic Sans MS', 'Chalkboard SE', cursive, sans-serif;
    min-height: 100vh;
    background: #3A86FF;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
}

body::before {
    content: '½ ⅓ ¼ ⅕ ⅙ ⅛ ⅔ ¾ ⅖';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    font-size: 5rem;
    color: rgba(255, 255, 255, 0.08);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    align-items: center;
    pointer-events: none;
    z-index: 0;
    transform: rotate(-5deg) scale(1.1);
}

#app {
    position: relative;
    z-index: 1;
    background: #B8F2E6;
    padding: 30px;
    border-radius: 40px;
    width: 95%;
    max-width: 1200px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    flex-direction: column;
    min-height: 85vh;
}

h1 {
    color: #C1121F;
    font-size: 2.8rem;
    text-align: center;
    margin-bottom: 20px;
    font-weight: 700;
    letter-spacing: 1px;
    text-shadow: 0 2px 10px rgba(193, 18, 31, 0.1);
}

#menu {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.5);
    padding: 20px;
    border-radius: 30px;
    margin-bottom: 20px;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.6);
}

.config-group {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #1e293b;
    font-weight: 600;
}

.config-group label {
    font-size: 0.95rem;
    color: #1e293b;
}

.config-group select,
.config-group input {
    padding: 10px 16px;
    border-radius: 12px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    background: white;
    color: #1e293b;
    font-size: 1rem;
}

.config-group input[type="number"] { width: 70px; }
#input-sala { width: 160px; }

button {
    padding: 12px 24px;
    border: none;
    border-radius: 50px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    letter-spacing: 0.5px;
}

button:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

button:active { transform: translateY(0); }

.btn-primary {
    background: linear-gradient(145deg, #f97316, #ea580c);
    color: white;
}

.btn-secondary {
    background: linear-gradient(145deg, #8b5cf6, #7c3aed);
    color: white;
}

.btn-success {
    background: linear-gradient(145deg, #22c55e, #16a34a);
    color: white;
}

.btn-danger {
    background: linear-gradient(145deg, #ef4444, #dc2626);
    color: white;
}

.btn-warning {
    background: linear-gradient(145deg, #f59e0b, #d97706);
    color: white;
}

#status {
    color: #C1121F;
    font-weight: 600;
    min-height: 2rem;
    text-align: center;
}

#jogo {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-top: 10px;
    flex: 1;
}

#info {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    background: rgba(255, 255, 255, 0.5);
    padding: 12px 20px;
    border-radius: 20px;
    margin-bottom: 10px;
    font-weight: 600;
    color: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.6);
}

#info span {
    background: rgba(255, 255, 255, 0.6);
    padding: 4px 16px;
    border-radius: 20px;
}

#lateral {
    flex: 0 0 180px;
    background: rgba(255, 255, 255, 0.4);
    padding: 15px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    max-height: 500px;
    overflow-y: auto;
}

#lateral h4 {
    color: #1e293b;
    margin-bottom: 12px;
    text-align: center;
}

#lista-jogadores {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.jogador-item {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #1e293b;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 12px;
    border-left: 3px solid transparent;
    transition: 0.2s;
}

.jogador-item.ativo {
    border-left-color: #f1c40f;
    background: rgba(241, 196, 15, 0.15);
}

#principal {
    flex: 1;
    min-width: 280px;
}

#tabuleiro {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.monte {
    text-align: center;
    min-width: 140px;
}

.monte h4 {
    color: #1e293b;
    margin-bottom: 6px;
    font-size: 1rem;
}

.monte div {
    color: #1e293b;
    font-size: 1.2rem;
    font-weight: 600;
}

#descarte-visual {
    margin: 8px 0;
    min-height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#descarte-visual .carta {
    cursor: pointer;
    transition: 0.2s;
}

#descarte-visual .carta:hover {
    transform: scale(1.05);
}

#descarte-acao {
    margin-top: 6px;
}

#area-montagem,
#area-mao {
    background: rgba(255, 255, 255, 0.3);
    padding: 15px;
    border-radius: 20px;
    margin-bottom: 15px;
    border: 2px dashed rgba(0, 0, 0, 0.06);
}

#area-montagem h4,
#area-mao h4 {
    color: #1e293b;
    margin-bottom: 10px;
    font-size: 1.1rem;
    text-align: center;
}

#progresso-montagem {
    color: #475569;
    font-weight: normal;
}

.slots {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    min-height: 100px;
    justify-content: center;
    align-items: center;
}

.slot-vazio {
    width: 100px;
    min-height: 130px;
    border: 2px dashed #cbd5e1;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 0.9rem;
    text-align: center;
}

.carta {
    width: 100px;
    min-height: 130px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    padding: 8px;
    transition: all 0.2s;
    cursor: pointer;
    position: relative;
    border: 2px solid transparent;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
}

.carta svg {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

.carta .valor {
    font-size: 1.2rem;
    font-weight: 700;
}

.carta .tipo {
    font-size: 0.7rem;
    color: #64748b;
    margin-top: 4px;
}

.carta.tipo-fração {
    background: #e0f2fe;
    border-color: #3b82f6;
}
.carta.tipo-decimal {
    background: #dcfce7;
    border-color: #22c55e;
}
.carta.tipo-porcentagem {
    background: #fef9c3;
    border-color: #eab308;
}
.carta.tipo-figura {
    background: #fce7f3;
    border-color: #ec4899;
}

.carta.virada {
    background: #e2e8f0;
    color: transparent;
    border-color: #94a3b8;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
}

.carta.virada .valor,
.carta.virada .tipo {
    display: none;
}

.carta.virada::after {
    content: '🂠';
    font-size: 2.8rem;
    color: #64748b;
    position: absolute;
}

.carta.minha-carta {
    cursor: pointer;
}

.carta.minha-carta:hover {
    transform: scale(1.04);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

.carta.selecionada {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 3px #ef4444;
}

#controles {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
    margin: 15px 0;
}

#controles button {
    min-width: 160px;
}

#mensagem {
    margin-top: 12px;
    font-weight: 600;
    color: #1e293b;
    font-size: 1.2rem;
    text-align: center;
    min-height: 2.5rem;
}

/* ===== MODAIS ===== */
#modal-nome,
#modal-vitoria {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#modal-nome.hidden,
#modal-vitoria.hidden {
    display: none;
}

#modal-content,
#vitoria-content {
    background: white;
    padding: 35px 40px;
    border-radius: 30px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.08);
}

#modal-content h2,
#vitoria-content h2 {
    color: #1e293b;
    margin-bottom: 20px;
}

#modal-content input {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    border: 2px solid #cbd5e1;
    background: #f8fafc;
    color: #1e293b;
    font-size: 1.1rem;
    margin-bottom: 15px;
}

#modal-content button {
    width: 100%;
    padding: 14px;
    font-size: 1.1rem;
}

.confetes {
    font-size: 3rem;
    margin: 20px 0;
    animation: confetes 1.5s infinite alternate;
}

@keyframes confetes {
    0% {
        transform: rotate(-3deg) scale(1);
    }
    100% {
        transform: rotate(3deg) scale(1.1);
    }
}

/* ===== RODAPÉ ===== */
footer {
    width: 100%;
    text-align: center;
    padding: 15px 0 5px 0;
    margin-top: 20px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
}

footer .assinatura {
    font-weight: 700;
    color: #C1121F;
    font-size: 1.1rem;
    margin-bottom: 2px;
    letter-spacing: 0.5px;
}

footer small {
    color: #1e293b;
    font-size: 0.8rem;
    opacity: 0.7;
}

/* ===== RESPONSIVO ===== */
@media (max-width: 800px) {
    #app { padding: 20px; min-height: 90vh; }
    h1 { font-size: 2.2rem; }
    #jogo { flex-direction: column; }
    #lateral { flex: 1; max-height: 200px; }
    #tabuleiro { flex-direction: column; align-items: center; gap: 15px; }
    .carta { width: 80px; min-height: 105px; }
    .carta .valor { font-size: 1rem; }
    footer .assinatura { font-size: 0.9rem; }
    footer small { font-size: 0.7rem; }
}

/* ===== MODAL DE REGRAS (corrigido) ===== */
#modal-regras {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    /* FORÇA OCULTAÇÃO INICIAL */
    display: none; /* <-- essa linha garante que o modal não apareça antes do clique */
}

#modal-regras.hidden {
    display: none; /* mantém oculto quando a classe está presente */
}

#modal-regras:not(.hidden) {
    display: flex; /* exibe quando a classe .hidden é removida */
}

#modal-regras-content {
    background: #1e293b;
    padding: 30px 35px;
    border-radius: 30px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
}

#modal-regras-content h2 {
    color: #f1c40f;
    text-align: center;
    margin-bottom: 15px;
    font-size: 1.8rem;
}

.regras-texto {
    color: #e2e8f0;
    font-size: 0.95rem;
    line-height: 1.6;
}

.regras-texto p {
    margin-bottom: 12px;
}

.regras-texto strong {
    color: #f1c40f;
}

#btn-fechar-regras {
    width: 100%;
    padding: 12px;
    margin-top: 15px;
    font-size: 1.1rem;
    border-radius: 30px;
}

@media (max-width: 600px) {
    #modal-regras-content {
        padding: 20px;
        max-height: 90vh;
    }
    #modal-regras-content h2 {
        font-size: 1.4rem;
    }
    .regras-texto {
        font-size: 0.85rem;
    }
}

/* ===== CHAT ===== */
#chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 300px;
    max-height: 400px;
    background: #1e293b;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.05);
    display: flex;
    flex-direction: column;
    z-index: 500;
    overflow: hidden;
    transition: all 0.3s ease;
}

#chat-container.minimizado {
    max-height: 40px;
}

#chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: #0f172a;
    color: #f1c40f;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}

#chat-messages {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    max-height: 280px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: #0f172a;
}

#chat-messages .msg {
    padding: 6px 10px;
    border-radius: 12px;
    background: #2d3748;
    color: #e2e8f0;
    font-size: 0.85rem;
    word-wrap: break-word;
    max-width: 90%;
    align-self: flex-start;
}

#chat-messages .msg .nome {
    font-weight: 700;
    color: #f1c40f;
    margin-right: 6px;
}

#chat-messages .msg .hora {
    font-size: 0.65rem;
    color: #94a3b8;
    margin-left: 6px;
}

#chat-messages .msg.sistema {
    background: #334155;
    color: #94a3b8;
    font-style: italic;
    text-align: center;
    align-self: center;
    max-width: 80%;
}

#chat-input-area {
    display: flex;
    gap: 6px;
    padding: 8px;
    background: #0f172a;
    border-top: 1px solid rgba(255,255,255,0.05);
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    padding: 6px 12px;
    border-radius: 30px;
    border: 1px solid #334155;
    background: #2d3748;
    color: #f1f5f9;
    font-size: 0.9rem;
    outline: none;
}

#chat-input:focus {
    border-color: #f1c40f;
}

#btn-enviar-chat {
    background: #f1c40f;
    color: #0f172a;
    border: none;
    border-radius: 30px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
}

#btn-enviar-chat:hover {
    background: #f39c12;
}

@media (max-width: 600px) {
    #chat-container {
        width: 250px;
        right: 10px;
        bottom: 10px;
    }
}