body {
    font-family: Arial, sans-serif;
    background: #f5f5f5;
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
}

.app {
    max-width: 560px;
    width: 100%;
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
}

h1 {
    margin-top: 0;
    margin-bottom: 16px;
    text-align: center;
}

/* --------------------------------------------------------------------------
   Structure générale en zones
   -------------------------------------------------------------------------- */

.game-section {
    margin-top: 16px;
}

.game-section:first-of-type {
    margin-top: 0;
}

.section-title {
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 800;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

button,
input,
select {
    font-family: inherit;
}

button {
    transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}

button:active {
    transform: translateY(1px);
}

/* --------------------------------------------------------------------------
   Zone 1 : Partie / génération
   -------------------------------------------------------------------------- */

.setup-section {
    padding: 14px;
    border: 1px solid #e5e5e5;
    border-radius: 12px;
    background: #fafafa;
}

.setup-grid {
    display: grid;
    gap: 10px;
}

.seed-group,
.new-game-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.setup-grid input,
.setup-grid select,
.setup-grid button {
    min-width: 0;
    padding: 10px;
    font-size: 16px;
    border-radius: 8px;
}

.setup-grid input,
.setup-grid select {
    border: 1px solid #cccccc;
    background: #ffffff;
}

.setup-grid button {
    border: none;
    cursor: pointer;
}

.primary-button {
    background: #2e7d32;
    color: white;
    font-weight: 800;
    box-shadow: 0 2px 8px rgba(46, 125, 50, 0.25);
}

.primary-button:hover {
    background: #256628;
}

.secondary-button,
.share-button {
    background: #eeeeee;
    color: #222222;
}

.secondary-button:hover,
.share-button:hover {
    background: #dddddd;
}

.share-button {
    width: 100%;
}

.info {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 12px;
    font-weight: bold;
    font-size: 14px;
    color: #333333;
}

/* --------------------------------------------------------------------------
   Zone 2 : Grille et saisie
   -------------------------------------------------------------------------- */

.board-section {
    margin-top: 18px;
}

.grid {
    display: grid;
    width: min(90vw, 520px);
    height: min(90vw, 520px);
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    border: 3px solid #222;
    background: #222;
    gap: 1px;
    margin: 0 auto;
}

.cell {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: none;
    text-align: center;
    font-size: clamp(18px, 6vw, 32px);
    font-weight: 600;
    cursor: pointer;
    outline: none;
    transition: background 0.15s ease;
    padding: 0;
    overflow: hidden;
}

.cell.given {
    background: #e9eef8;
    color: #111;
    cursor: default;
}

.cell.selected {
    background: #fff7cf;
}

.cell.hint-target {
    background: #b9f6ca;
    box-shadow: inset 0 0 0 2px #4caf50;
}

.cell.hint-related {
    background: #e8f5e9;
}

.cell.correct {
    color: #1d6b38;
    font-weight: bold;
}

.cell.wrong {
    background: #ffd6d6;
    color: #b00020;
    font-weight: bold;
}

.thick-right {
    border-right: 3px solid #222;
}

.thick-bottom {
    border-bottom: 3px solid #222;
}

.number-pad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-top: 15px;
}

.number-pad button {
    padding: 14px;
    font-size: 20px;
    border: none;
    border-radius: 8px;
    background: #eeeeee;
    cursor: pointer;
}

.number-pad button:hover {
    background: #dddddd;
}


.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.96);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    text-align: center;
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 64px;
    height: 64px;
    border: 7px solid #dbeeff;
    border-top-color: #1f5f99;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
    margin-bottom: 24px;
}


@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-title {
    font-size: 28px;
    font-weight: 700;
    color: #1f5f99;
    margin-bottom: 14px;
}

.loading-text {
    color: #555;
    font-size: 18px;
    line-height: 1.6;
    max-width: 520px;
}

/* --------------------------------------------------------------------------
   Zone 3 : Aides immédiates
   -------------------------------------------------------------------------- */

.assist-section {
    padding: 14px;
    border-radius: 12px;
    background: #f7f7f7;
}

.assist-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.assist-actions button,
.live-check-option {
    min-height: 42px;
    padding: 10px;
    font-size: 15px;
    border: none;
    border-radius: 8px;
    background: #eeeeee;
    cursor: pointer;
    box-sizing: border-box;
}

.assist-actions button:hover,
.live-check-option:hover {
    background: #dddddd;
}

.live-check-option {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #222222;
    user-select: none;
}

.live-check-option input {
    margin: 0;
}

#candidatesBtn.candidates-active {
    background: #d9f2dd;
    color: #1d6b38;
    font-weight: bold;
    box-shadow: inset 0 0 0 2px #4caf50;
}

/* Compatibilité : le bouton effacer reste dans le DOM pour le JS, mais invisible. */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}


.feedback-section {
    margin-top: 12px;
}

.message {
    min-height: 24px;
    text-align: center;
    font-weight: bold;
}

.hint-box {
    margin-top: 10px;
    min-height: 48px;
    padding: 12px;
    border-radius: 10px;
    background: #ffffff;
    border: 1px solid #dbe5f1;
    color: #333;
    text-align: center;
    line-height: 1.5;
}

.hint-technique {
    font-weight: bold;
    color: #2e7d32;
    margin-bottom: 6px;
}

.hint-explanation {
    color: #333;
}

/* --------------------------------------------------------------------------
   Grille des candidats
   -------------------------------------------------------------------------- */

.cell.candidate-preview:not(.candidate-preview-filled) {
    color: #607d8b !important;
    font-size: clamp(10px, 2.5vw, 14px) !important;
    font-weight: 500 !important;
    line-height: 1 !important;
    padding: 0 !important;
    overflow: hidden !important;
}

.cell.candidate-preview-filled {
    background: #e0e0e0 !important;
    color: #111 !important;
    font-size: clamp(18px, 6vw, 32px) !important;
    font-weight: 600 !important;
}

.cell.candidate-preview-filled .candidate-list {
    display: none;
}

.candidate-list {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    align-items: center;
    justify-items: center;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    pointer-events: none;
}

.candidate-list span {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(10px, 2.5vw, 14px) !important;
    color: #607d8b !important;
    font-weight: 500 !important;
    line-height: 1 !important;
}



/* Indique qu'une case contient d'autres candidats masqués.
   Utilisé dans les explications pédagogiques quand seuls les candidats pertinents sont affichés. */
.candidate-list span.candidate-more {
    color: #777 !important;
    font-weight: 800 !important;
    font-size: clamp(9px, 2.2vw, 13px) !important;
    background: transparent !important;
    text-decoration: none !important;
}

/* --------------------------------------------------------------------------
   Visualisation pédagogique des techniques
   -------------------------------------------------------------------------- */

.cell.technique-source-cell {
    background: #e3f2fd !important;
    box-shadow: inset 0 0 0 2px #42a5f5;
}

.cell.technique-target-cell {
    background: #d9f7df !important;
    box-shadow: inset 0 0 0 2px #43a047;
}

.cell.technique-elimination-cell {
    background: #ffebee !important;
    box-shadow: inset 0 0 0 2px #ef5350;
}

.candidate-list span.candidate-value-source {
    color: #1565c0 !important;
    font-weight: 800 !important;
    background: #bbdefb;
    border-radius: 4px;
    padding: 0;
}

.candidate-list span.candidate-value-target {
    color: #1b5e20 !important;
    font-weight: 900 !important;
    background: #c8e6c9;
    border-radius: 4px;
    padding: 0;
}

.candidate-list span.candidate-value-eliminated {
    color: #b71c1c !important;
    font-weight: 900 !important;
    background: #ffcdd2;
    border-radius: 4px;
    padding: 0;
    text-decoration: line-through;
    text-decoration-thickness: 2px;
}

/* --------------------------------------------------------------------------
   Zone 4 : Résolution guidée
   -------------------------------------------------------------------------- */

.learning-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
}

.learning-actions button {
    flex: 1;
    padding: 12px;
    font-size: 16px;
    border: none;
    border-radius: 10px;
    background: #e3f2fd;
    color: #1f5f99;
    font-weight: 700;
    cursor: pointer;
}

.learning-actions button:hover {
    background: #cfe8ff;
}

.solution-panel {
    margin-top: 14px;
    padding: 16px;
    border: 2px solid #4a90e2;
    border-radius: 14px;
    background: #eef6ff;
    box-shadow: 0 3px 12px rgba(31, 95, 153, 0.12);
}

.solution-panel.hidden,
.hidden {
    display: none !important;
}

.solution-panel h3 {
    margin: 0 0 12px 0;
    color: #1f5f99;
    text-align: center;
}

.solution-section-title {
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 800;
    color: #1f5f99;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.solution-summary {
    margin-bottom: 12px;
    padding: 12px;
    border-radius: 10px;
    background: #ffffff;
    color: #333;
    font-size: 14px;
    line-height: 1.45;
}

.solution-summary ul {
    margin: 8px 0 0 0;
    padding-left: 20px;
}

.solution-step-info {
    margin-bottom: 12px;
    padding: 12px;
    border-radius: 10px;
    background: #ffffff;
    color: #333;
    line-height: 1.45;
}

.solution-step-counter {
    font-size: 13px;
    color: #666;
    margin-bottom: 8px;
    text-align: center;
}

.solution-step-technique {
    font-weight: 800;
    color: #1f5f99;
    margin-bottom: 8px;
    text-align: center;
}

.solution-step-explanation {
    color: #333;
}

.solution-navigation {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.solution-navigation button,
.solution-panel button {
    flex: 1;
    padding: 10px;
    font-size: 15px;
    border: none;
    border-radius: 8px;
    background: #dbeeff;
    color: #174f7c;
    cursor: pointer;
}

.solution-navigation button:hover,
.solution-panel button:hover {
    background: #c7e3ff;
}

.solution-navigation button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.solution-close-button {
    width: 100%;
    margin-top: 10px;
}

.solution-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 12px;
    padding: 10px;
    border-radius: 10px;
    background: #ffffff;
    font-size: 13px;
    color: #333;
    line-height: 1.4;
}

.solution-legend-title {
    width: 100%;
    text-align: center;
    font-weight: bold;
    margin-bottom: 4px;
    color: #1f5f99;
}

.solution-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.legend-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.legend-dot.source {
    background: #bbdefb;
    border: 1px solid #42a5f5;
}

.legend-dot.target {
    background: #c8e6c9;
    border: 1px solid #43a047;
}

.legend-dot.eliminated {
    background: #ffcdd2;
    border: 1px solid #ef5350;
}

#solutionToggleBtn.solution-active {
    background: #cfe8ff;
    box-shadow: inset 0 0 0 2px #4a90e2;
}

/* --------------------------------------------------------------------------
   Mobile
   -------------------------------------------------------------------------- */

@media (max-width: 520px) {
    body {
        padding: 12px;
    }

    .app {
        padding: 14px;
    }

    .seed-group,
    .new-game-group,
    .assist-actions {
        grid-template-columns: 1fr;
    }

    .learning-actions,
    .solution-navigation {
        flex-direction: column;
    }

    .solution-panel {
        padding: 12px;
    }

    .cell {
        font-size: 24px;
    }
}

/* --------------------------------------------------------------------------
   Historique pédagogique des candidats éliminés
   -------------------------------------------------------------------------- */

.candidate-list span.candidate-value-eliminated-past {
    color: #607d8b !important;
    font-weight: 500 !important;
    background: transparent !important;
    border-radius: 0 !important;
    padding: 0 !important;
    text-decoration: line-through;
    text-decoration-thickness: 1px;
    opacity: 0.8;
}


/* --------------------------------------------------------------------------
   Candidats saisis par le joueur
   -------------------------------------------------------------------------- */

.player-candidates-toggle {
    width: 100%;
    margin-top: 14px;
    padding: 12px 16px;
    border: 2px solid #8e6bbf;
    border-radius: 10px;
    background: #f3edfb;
    color: #5f3d8a;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
}

.player-candidates-toggle:hover {
    background: #e9def8;
}

.player-candidates-toggle.player-candidates-active {
    background: #6f4aa0;
    color: #ffffff;
    border-color: #5b378b;
    box-shadow: 0 2px 9px rgba(95, 61, 138, 0.28);
}

.grid.player-candidate-mode {
    border-color: #5f3d8a;
    background: #5f3d8a;
}

.grid.player-candidate-mode .cell {
    background: #fbf8ff;
}

.grid.player-candidate-mode .cell.given {
    /* La valeur initiale conserve sa police, sa taille et sa couleur habituelles. */
    background: #e9eef8;
    color: #111;
}

.grid.player-candidate-mode .cell.selected {
    background: #eadcf8;
    box-shadow: inset 0 0 0 2px #8e6bbf;
}

.player-candidate-cell {
    padding: 0 !important;
    overflow: hidden;
}

.player-candidate-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    pointer-events: none;
}

.player-candidate-list span {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6f4aa0;
    font-size: clamp(10px, 2.5vw, 14px);
    font-weight: 700;
    line-height: 1;
}

.number-pad.player-candidate-mode button {
    background: #eee4f8;
    color: #5f3d8a;
    box-shadow: inset 0 0 0 1px #c8afe3;
}

.number-pad.player-candidate-mode button:hover {
    background: #dfcff0;
}

@media (max-width: 520px) {
    .player-candidates-toggle {
        font-size: 15px;
    }
}
