body {
    font-family: sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    margin: 0;
    background-color: #23272a;
    color: #dcddde;
    padding: 10px; /* Réduit le padding pour les petits écrans */
    box-sizing: border-box;
}

.container {
    background-color: #2c2f33;
    padding: 20px; /* Réduit le padding pour les petits écrans */
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
    text-align: center;
    width: 100%;
    max-width: 600px; /* Limite la largeur sur les grands écrans */
    box-sizing: border-box;
}

h1 {
    color: #ffffff;
    font-size: 1.8em; /* Taille de titre adaptable */
    margin-bottom: 20px;
}

h2 {
    color: #ffffff;
    font-size: 1.4em; /* Taille de titre adaptable */
    margin-top: 20px;
    margin-bottom: 10px;
}

.controls {
    display: flex;
    flex-wrap: wrap; /* Permet le passage à la ligne si pas assez de place */
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
}

.controls label {
    margin-right: 8px;
    font-weight: bold;
    color: #b9bbbe;
    margin-bottom: 10px; /* Marge pour l'empilement */
}

.controls input[type="number"] {
    width: 70px; /* Légèrement plus grand pour le tactile */
    padding: 10px;
    margin-right: 8px;
    border: 1px solid #40444b;
    background-color: #36393f;
    color: #dcddde;
    border-radius: 4px;
    box-sizing: border-box;
    margin-bottom: 10px; /* Marge pour l'empilement */
}

.controls button {
    padding: 10px 15px;
    margin-bottom: 10px; /* Marge pour l'empilement */
}


button {
    padding: 12px 18px; /* Boutons plus grands pour le tactile */
    background-color: #5865f2;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em; /* Taille de police adaptable */
    margin-top: 10px;
    transition: background-color 0.2s;
    width: 100%; /* Bouton principal pleine largeur */
    max-width: 300px; /* Limite la largeur du bouton inverser */
    box-sizing: border-box;
}

button#generateMatrix {
    width: auto; /* Le bouton générer peut être plus petit */
    max-width: none;
}


button:hover {
    background-color: #4752c4;
}

button:disabled {
    background-color: #40444b;
    color: #72767d;
    cursor: not-allowed;
}

#matrixInputContainer, #resultContainer {
    margin-top: 20px;
}

.table-wrapper {
    overflow-x: auto; /* Permet le défilement horizontal pour les tableaux */
    margin-bottom:10px;
}

table {
    margin: 10px auto;
    border-collapse: collapse;
    min-width: max-content; /* S'assure que le tableau ne se compresse pas trop */
}

td {
    padding: 0;
}

table input[type="number"] {
    width: 45px; /* Légèrement plus petit pour tenir plus de colonnes */
    height: 40px; /* Hauteur pour le tactile */
    text-align: center;
    border: 1px solid #40444b;
    background-color: #32353b;
    color: #dcddde;
    margin: 2px;
    border-radius: 3px;
    font-size: 0.9em; /* Taille de police adaptable */
    -moz-appearance: textfield; /* Enlève les flèches sur Firefox */
}

table input[type="number"]::-webkit-outer-spin-button,
table input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none; /* Enlève les flèches sur Chrome/Safari/Edge */
    margin: 0;
}


#matrixResult td {
    padding: 8px;
    border: 1px solid #40444b;
    min-width: 45px; /* Cohérent avec la taille des inputs */
    height: 38px;
    text-align: center;
    font-size: 0.9em;
    color: #dcddde;
    background-color: #2c2f33;
    box-sizing: border-box;
}

#errorMessage {
    color: #f04747;
    margin-top: 15px;
    font-weight: bold;
    word-wrap: break-word; /* S'assure que les messages longs ne débordent pas */
}

/* Media query pour les petits écrans */
@media (max-width: 480px) {
    .container {
        padding: 15px;
    }

    h1 {
        font-size: 1.5em;
    }
    h2 {
        font-size: 1.2em;
    }

    .controls {
        flex-direction: column; /* Empile les contrôles */
        align-items: stretch; /* Étire les éléments pour prendre toute la largeur */
    }

    .controls label {
        margin-right: 0;
        margin-bottom: 5px; /* Espace réduit */
        text-align: left;
    }

    .controls input[type="number"],
    .controls button {
        width: 100%; /* Pleine largeur pour les contrôles empilés */
        margin-right: 0;
        margin-bottom: 10px;
    }

    button {
        font-size: 0.95em;
    }

    table input[type="number"] {
        width: 40px; /* Encore plus petit si nécessaire */
        height: 35px;
    }

    #matrixResult td {
        min-width: 40px;
        height: 33px;
        padding: 6px;
    }
}