/* style.css - Versão com todas as funcionalidades e layout responsivo */

/* Estilos Gerais */
body {
    font-family: Arial, sans-serif;
    margin: 0;
    background-color: #e0e0e0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    /* O tamanho de fonte base em vmin é ótimo, mantemos isso */
    font-size: 1.5vmin;
}

#main-container {
    display: flex;
    /* ALTERAÇÃO: Removidas as regras de tamanho e proporção fixas. */
    /* aspect-ratio: 1280 / 720; */
    /* width: 1260px; */
    /* height: 710px; */
    
    /* ALTERAÇÃO: Fazemos o contentor ocupar o ecrã, com limites */
    width: 100%;
    height: 100vh; /* Ocupa 100% da altura da viewport */
    max-width: 1600px; /* Limite máximo para ecrãs muito grandes */
    margin: auto;      /* Centra o contentor se max-width for atingido */

    background-image: url('images/fundo1.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 3px;
    box-shadow: 0 0.5vmin 1vmin rgba(0,0,0,0.2);
    position: relative; 
    overflow: hidden;
    border: 1px solid #bbb;
}

.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    /* ALTERAÇÃO: A largura será controlada pela Media Query mais abaixo */
    width: 70%; 
    height: 100%;
    padding: 2.5vmin;
    box-sizing: border-box;
    text-align: center;
    overflow-y: auto;
    background-color: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(1px);
}

.active-screen {
    display: flex;
}

.hidden {
    display: none !important;
}

h1, h2 {
    color: #003366;
    text-shadow: 0.1vmin 0.1vmin 0.2vmin rgba(255,255,255,0.7);
}
h1 { font-size: 4.2vmin; margin-bottom: 0.2vmin;}
h2 { font-size: 3.2vmin; margin-top: 0.2vmin; margin-bottom: 0.5vmin;}

p {
    font-size: 1.2vmin;
    text-shadow: 0.1vmin 0.1vmin 0.1vmin rgba(255,255,255,0.7);
    line-height: 1.1;
}
label {
    font-size: 2.1vmin;
    text-shadow: 0.1vmin 0.1vmin 0.1vmin rgba(255,255,255,0.7);
    font-weight: bold;
}

#welcome-screen {
    justify-content: center;
}
#welcome-screen p {
    font-size: 1.5vmin;
    margin-bottom: 1vmin;
}
#welcome-screen label {
    margin-top: 1vmin;
}
#welcome-screen input[type="text"] {
    margin-top: 0.8vmin;
    margin-bottom: 2.5vmin;
    padding: 1.2vmin;
    font-size: 2.2vmin;
    width: 35vmin;
    max-width: 80%;
    text-align: center;
    border: 1px solid #ccc;
    border-radius: 0.5vmin;
    box-shadow: inset 0 0.1vmin 0.3vmin rgba(0,0,0,0.1);
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(10vmin, 1fr));
    gap: 2vmin;
    margin-top: 1vmin;
    width: 90%;
    max-width: 80vmin;
}

body.game-is-fullscreen .level-grid {
    grid-template-columns: repeat(3, 1fr);
    max-width: 90%;
}

.level-button {
    padding: 0.8vmin;
    cursor: pointer;
    border: 1px solid #999;
    border-radius: 1vmin;
    background-color: rgba(240, 240, 240, 0.8);
    transition: all 0.2s ease-in-out;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 4vmin;
    box-shadow: 0.3vmin 0.2vmin 0.4vmin rgba(0,0,0,0.2);
    font-size: 2vmin;
}
.level-button:hover {
    background-color: rgba(224, 224, 224, 0.9);
    border-color: #555;
    transform: translateY(-0.3vmin);
    box-shadow: 0.4vmin 0.5vmin 0.8vmin rgba(0,0,0,0.3);
}
.level-button img {
    max-width: 95%;
    max-height: 10vmin;
    margin-bottom: 0.5vmin;
    border-radius: 0.5vmin;
    display: block;
}

.game-info {
    display: flex;
    justify-content: space-between;
    width: 90%;
    font-size: 2.8vmin;
	margin-top: 5vmin;
    margin-bottom: 2vmin;
    font-weight: bold;
    flex-shrink: 0;
    color: #1a1a1a;
    text-shadow: 1px 1px 1px rgba(255,255,255,0.9);
}

#question-text {
    font-size: 3.2vmin;
    margin-bottom: 1.5vmin;
    min-height: 10vmin;
    white-space: pre-line;
    flex-shrink: 0;
    font-weight: bold;
    color: #003366;
}

#abacus-area {
    margin-bottom: 2vmin;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    max-width: 100%;
    padding: 1vmin 0;
    box-sizing: border-box;
}
#abacus-canvas {
    border: 0px solid #ccc;
    max-width: 100%;
    width: 70vmin;
    height: calc(70vmin * (220 / 800));
}

.options-grid {
    display: grid;
    /* Esta regra já é perfeitamente responsiva, ótimo! */
    grid-template-columns: repeat(auto-fit, minmax(20vmin, 1fr));
    gap: 2vmin;
    width: 100%;
    max-width: 85vmin;
    margin-bottom: 2.5vmin;
    flex-shrink: 0;
}
.option-button {
    padding: 2vmin 2.5vmin;
    font-size: 2.8vmin;
    font-weight: bold;
    cursor: pointer;
    border: 1px solid #888;
    border-radius: 1vmin;
    background-color: rgba(231, 243, 255, 0.85);
    transition: all 0.2s ease;
    box-shadow: 0.3vmin 0.3vmin 0.6vmin rgba(0,0,0,0.2);
    color: #003366;
}
.option-button:hover:not(:disabled) {
    background-color: rgba(204, 228, 255, 0.95);
    border-color: #333;
    transform: translateY(-0.2vmin);
    box-shadow: 0.4vmin 0.4vmin 0.7vmin rgba(0,0,0,0.25);
}
.option-button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
    background-color: rgba(200, 200, 200, 0.7);
    box-shadow: none;
    transform: none;
}

.feedback-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    pointer-events: none;
}
.feedback-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}
#feedback-message {
    font-size: 6vmin;
    font-weight: bold;
    padding: 5vmin;
    border-radius: 2vmin;
    background-color: white;
    box-shadow: 0 0.8vmin 3vmin rgba(0,0,0,0.3);
    text-align: center;
    white-space: pre-line;
    max-width: 80%;
}
.feedback-correct { color: #28a745; }
.feedback-incorrect { color: #dc3545; }
.feedback-final { color: #004085; font-size: 3vmin; }
.feedback-continue { color: #17a2b8; font-size: 2.8vmin; }

.level-end-message, .final-message {
    margin-top: 3vmin;
    padding: 3.5vmin;
    border: 1px solid #ccc;
    background-color: rgba(249, 249, 249, 0.9);
    width: 90%;
    max-width: 85vmin;
    border-radius: 1vmin;
    flex-shrink: 0;
    box-shadow: 0 0.3vmin 0.7vmin rgba(0,0,0,0.1);
}
.level-end-message p, .final-message p {
    font-size: 2.8vmin;
    margin-bottom: 3vmin;
    white-space: pre-line;
    color: #333;
}
#level-decision-buttons {
    display: flex;
    justify-content: space-around;
    gap: 2vmin;
}
.accent-button {
    padding: 1.8vmin 3.5vmin;
    font-size: 2.5vmin;
    font-weight: bold;
    cursor: pointer;
    border: none;
    border-radius: 1vmin;
    background-color: #007bff;
    color: white;
    transition: all 0.2s ease;
    box-shadow: 0.2vmin 0.2vmin 0.4vmin rgba(0,0,0,0.3);
    text-shadow: 1px 1px 1px rgba(0,0,0,0.4);
}
.accent-button:hover {
    background-color: #0056b3;
    box-shadow: 0.3vmin 0.3vmin 0.7vmin rgba(0,0,0,0.4);
    transform: translateY(-0.2vmin);
}
#restart-button {
    margin-top: 2vmin;
}

#scoreboard-panel {
    /* ALTERAÇÃO: A largura e altura serão controladas pela Media Query */
    width: 30%; /* Ligeiro ajuste para preencher o espaço */
    height: calc(100% - 4vmin); 
    margin: 2vmin;
    box-sizing: border-box;
    border: 2px solid #ccc;
    border-radius: 1vmin;
    padding: 2vmin;
    background-color: rgba(248, 249, 250, 0.9);
    backdrop-filter: blur(2px);
    overflow: hidden;
    text-align: center;
    display: flex;
    flex-direction: column;
    box-shadow: inset 0 0 0.5vmin rgba(0,0,0,0.1);
}
#scoreboard-panel h2 {
    margin-top: 0;
    margin-bottom: 1.5vmin;
    font-size: 2.2vmin;
    flex-shrink: 0;
    color: #003366;
    text-shadow: 1px 1px 1px rgba(255,255,255,0.7);
}
#scoreboard-content {
    font-family: "Consolas", "Courier New", Courier, monospace;
    font-size: 1.3vmin;
    text-align: left;
    white-space: pre;
    line-height: 1.3;
    margin-top: 1vmin;
    padding: 1.3vmin;
    overflow: auto;
    flex-grow: 1;
    background-color: rgba(255, 255, 255, 0.6);
    border-radius: 0.7vmin;
    border: 1px solid #ddd;
}

#scoreboard-controls {
    display: flex;
    justify-content: flex-end;
    gap: 1vmin;
    margin-top: 1.5vmin;
    padding-top: 1vmin;
    border-top: 1px solid #ddd;
    flex-shrink: 0;
}
.control-button {
    padding: 0.8vmin 1.5vmin;
    font-size: 1.6vmin;
    font-weight: bold;
    cursor: pointer;
    border: 1px solid #bbb;
    border-radius: 0.7vmin;
    background-color: #f0f0f0;
    color: #333;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}
.control-button:hover {
    background-color: #e0e0e0;
    border-color: #888;
}

/* Estilos para o Modal de Ajuda (sem alterações) */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 2vmin;
    box-sizing: border-box;
}

.modal.hidden {
    display: none !important;
}

.modal-content {
    background-color: #fefefe;
    padding: 3vmin 4vmin;
    border: 1px solid #888;
    border-radius: 1vmin;
    width: 80%;
    max-width: 600px;
    box-shadow: 0 0.5vmin 1.5vmin rgba(0,0,0,0.3);
    text-align: left;
    max-height: 80vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

#help-modal-title {
    font-size: 3vmin;
    color: #003366;
    margin-top: 0;
    margin-bottom: 2vmin;
    text-align: center;
}

#help-modal-body {
    font-size: 1.8vmin;
    line-height: 1.6;
    margin-bottom: 3vmin;
    color: #333;
}

#help-modal-body h4 {
    font-size: 2.2vmin;
    color: #0056b3;
    margin-top: 1.5vmin;
    margin-bottom: 0.5vmin;
}

#help-modal-body ul {
    padding-left: 3vmin;
    margin-top: 0.5vmin;
}
#help-modal-body li {
    margin-bottom: 0.8vmin;
}

#close-help-modal-btn {
    font-size: 2vmin;
    padding: 1.2vmin 2.5vmin;
    align-self: center;
}

/* ==========================================================================
   NOVA SECÇÃO: MEDIA QUERY PARA RESPONSIVIDADE
   Estas regras aplicam-se apenas a ecrãs com largura igual ou inferior a 900px
   ==========================================================================
*/
@media (max-width: 900px) {
    #main-container {
        /* Altera a direção do flexbox para empilhar os elementos verticalmente */
        flex-direction: column;
        height: auto; /* A altura torna-se automática */
        min-height: 100vh; /* Garante que ocupa pelo menos toda a altura do ecrã */
    }

    .screen {
        /* O ecrã do jogo passa a ocupar 100% da largura */
        width: 100%;
        min-height: 65vh; /* Garante uma altura mínima para o jogo */
        overflow-y: auto;
        padding: 2vmin 4vmin; /* Ajusta o padding para ecrãs mais estreitos */
    }

    #scoreboard-panel {
        /* O painel de pontuação também ocupa 100% da largura */
        width: auto; /* Remove a largura fixa percentual */
        height: auto; /* Altura automática */
        min-height: 30vh; /* Altura mínima para o scoreboard */
        margin: 0; /* Remove as margens laterais */
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    /* Aumenta ligeiramente o tamanho da fonte em ecrãs pequenos para melhor legibilidade */
    #scoreboard-content {
        font-size: 1.8vmin;
    }

    .game-info {
        font-size: 3.5vmin;
    }

    #question-text {
        font-size: 4vmin;
    }
}