:root {
    --bg-dark: #0f172a;
    --bg-panel: #1e293b;
    --primary: #10b981; /* Verde EDCELL-TECH */
    --primary-hover: #059669;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --piece-bg: #ffffff;
    --piece-dot: #0f172a;
    --danger: #ef4444;
    --warning: #f59e0b;
}

* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif; 
    -webkit-tap-highlight-color: transparent;
}

body { 
    background-color: var(--bg-dark); 
    color: var(--text-main); 
    display: flex; 
    justify-content: center; 
    min-height: 100vh; 
    overflow: hidden; 
}

#app { 
    width: 100%; 
    max-width: 1200px; 
    position: relative; 
    display: flex; 
    flex-direction: column; 
    height: 100vh;
}

.screen { 
    display: none; 
    width: 100%; 
    height: 100vh; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
    padding: 20px; 
}

.screen.active { 
    display: flex; 
}

/* Menu e Header */
header { text-align: center; margin-bottom: 20px; }
header h1 { font-size: 3rem; color: var(--primary); margin-bottom: 5px; text-shadow: 0 2px 10px rgba(16,185,129,0.3); }
header h2 { font-size: 1.2rem; letter-spacing: 2px; margin-bottom: 10px; font-weight: 400; color: var(--text-muted); }
header p { font-size: 0.95rem; color: var(--text-main); }

.menu-options { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 340px; margin-top: 15px; }
footer { margin-top: 25px; font-size: 0.8rem; color: var(--text-muted); text-align: center; }

button { 
    padding: 14px 20px; 
    background: var(--bg-panel); 
    color: var(--text-main); 
    border: 1px solid var(--primary); 
    border-radius: 8px; 
    font-size: 1rem; 
    cursor: pointer; 
    transition: all 0.2s ease; 
    font-weight: bold; 
    min-height: 48px;
}

button:hover:not(:disabled) { 
    background: var(--primary); 
    color: #fff; 
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16,185,129,0.3);
}

button:active:not(:disabled) {
    transform: translateY(0);
}

button.btn-primary { background: var(--primary); color: #fff; }
button.btn-danger { border-color: var(--danger); color: var(--danger); }
button.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

button:disabled { 
    opacity: 0.4; 
    cursor: not-allowed; 
    border-color: var(--text-muted); 
    transform: none !important;
}

.config-group { margin-bottom: 15px; width: 100%; max-width: 340px; text-align: left; }
.config-group label { display: block; margin-bottom: 6px; color: var(--primary); font-weight: 600; }
.config-group input, .config-group select { 
    width: 100%; 
    padding: 12px; 
    background: var(--bg-panel); 
    color: white; 
    border: 1px solid var(--text-muted); 
    border-radius: 8px; 
    font-size: 1rem;
    outline: none;
}
.config-group input:focus, .config-group select:focus { border-color: var(--primary); }

/* Interface do Jogo */
#screen-game { justify-content: space-between; padding: 0; }
.game-header { 
    width: 100%; 
    display: flex; 
    justify-content: space-between; 
    align-items: center;
    padding: 12px 20px; 
    background: var(--bg-panel); 
    border-bottom: 2px solid var(--primary); 
}
.player-info { display: flex; flex-direction: column; font-weight: bold; }
.match-info { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.piece-count { font-size: 0.85rem; color: var(--primary); }

.turn-indicator { 
    padding: 10px; 
    text-align: center; 
    font-weight: bold; 
    background: rgba(16, 185, 129, 0.15); 
    width: 100%; 
    letter-spacing: 1px; 
    transition: 0.3s; 
    border-bottom: 1px solid rgba(16, 185, 129, 0.3);
}
.turn-ai { color: var(--warning); background: rgba(245, 158, 11, 0.15); border-bottom-color: rgba(245, 158, 11, 0.3); }

/* Controles de Navegação da Mesa */
.board-controls {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 15px;
    background: rgba(15, 23, 42, 0.8);
}
.btn-scroll {
    padding: 6px 12px;
    font-size: 0.8rem;
    min-height: auto;
    border-radius: 20px;
    background: var(--bg-panel);
    border: 1px solid var(--text-muted);
}
.scroll-hint { font-size: 0.75rem; color: var(--text-muted); user-select: none; }

/* Contêiner da Mesa com Suporte a Drag & Touch */
.board-container { 
    flex: 1; 
    width: 100%; 
    display: flex; 
    align-items: center; 
    justify-content: flex-start; 
    overflow-x: auto; 
    overflow-y: hidden; 
    padding: 20px; 
    scroll-behavior: smooth; 
    cursor: grab;
    user-select: none;
    -webkit-overflow-scrolling: touch;
}
.board-container:active { cursor: grabbing; }

.mesa { 
    display: flex; 
    align-items: center; 
    gap: 6px; 
    padding: 20px; 
    min-width: max-content; 
    margin: 0 auto;
}

.controls-area { display: flex; justify-content: center; gap: 15px; padding: 10px; }
.player-hand-container { width: 100%; background: var(--bg-panel); padding: 15px; border-top: 2px solid var(--primary); }
.player-info-bottom { display: flex; justify-content: space-between; margin-bottom: 10px; font-weight: bold; }
.mao { display: flex; gap: 10px; overflow-x: auto; padding: 10px 5px; align-items: center; justify-content: center; min-height: 100px; }

/* Renderização dos Dominós */
.domino { 
    width: 44px; 
    height: 88px; 
    background: var(--piece-bg); 
    border-radius: 6px; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.5); 
    display: flex; 
    flex-direction: column; 
    padding: 3px; 
    cursor: pointer; 
    transition: transform 0.2s, opacity 0.3s; 
    user-select: none; 
    flex-shrink: 0; 
}
.domino:hover:not(.disabled) { transform: translateY(-8px); }
.domino.disabled { opacity: 0.35; cursor: not-allowed; filter: grayscale(0.8); }
.domino.horizontal { width: 88px; height: 44px; flex-direction: row; }

.half { 
    flex: 1; 
    display: grid; 
    grid-template-columns: repeat(3, 1fr); 
    grid-template-rows: repeat(3, 1fr); 
    align-items: center; 
    justify-items: center; 
    padding: 2px;
}
.domino:not(.horizontal) .half:first-child { border-bottom: 2px solid #cbd5e1; }
.domino.horizontal .half:first-child { border-right: 2px solid #cbd5e1; }

.dot { width: 8px; height: 8px; background: var(--piece-dot); border-radius: 50%; visibility: hidden; }

/* Mapeamento dos Pontos */
.val-1 .d5 { visibility: visible; }
.val-2 .d3, .val-2 .d7 { visibility: visible; }
.val-3 .d3, .val-3 .d5, .val-3 .d7 { visibility: visible; }
.val-4 .d1, .val-4 .d3, .val-4 .d7, .val-4 .d9 { visibility: visible; }
.val-5 .d1, .val-5 .d3, .val-5 .d5, .val-5 .d7, .val-5 .d9 { visibility: visible; }
.val-6 .d1, .val-6 .d3, .val-6 .d4, .val-6 .d6, .val-6 .d7, .val-6 .d9 { visibility: visible; }

/* Modais e Popups */
#modal-overlay { 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background: rgba(0,0,0,0.85); 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    z-index: 1000; 
    backdrop-filter: blur(4px);
}
.hidden { display: none !important; }
.modal-box { 
    background: var(--bg-panel); 
    padding: 25px; 
    border-radius: 14px; 
    border: 2px solid var(--primary); 
    text-align: center; 
    max-width: 450px; 
    width: 92%; 
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}
.modal-box h2 { color: var(--primary); margin-bottom: 15px; }
.modal-box p { margin-bottom: 10px; line-height: 1.4; color: var(--text-main); }
.modal-buttons { margin-top: 20px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Tabelas e Cards de Estatísticas/Ranking */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 15px 0; }
.stat-card { background: rgba(15,23,42,0.6); padding: 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.1); }
.stat-value { font-size: 1.4rem; font-weight: bold; color: var(--primary); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); }

.ranking-table { width: 100%; border-collapse: collapse; margin: 15px 0; text-align: left; }
.ranking-table th, .ranking-table td { padding: 10px; border-bottom: 1px solid rgba(255,255,255,0.1); font-size: 0.9rem; }
.ranking-table th { color: var(--primary); }

/* Responsividade Mobile */
@media (max-width: 768px) {
    .domino { width: 36px; height: 72px; }
    .domino.horizontal { width: 72px; height: 36px; }
    .dot { width: 6px; height: 6px; }
    header h1 { font-size: 2.2rem; }
    header h2 { font-size: 1rem; }
    .mao { justify-content: flex-start; }
    .scroll-hint { display: none; }
}