:root {
    --color-units: #FF6B6B;        /* Rouge pour les unités */
    --color-tens: #4ECDC4;         /* Turquoise pour les dizaines */
    --color-hundreds: #FFE66D;     /* Jaune pour les centaines */
    --color-thousands: #A29BFE;    /* Violet pour les milliers */
    --color-primary: #4CAF50;
    --color-success: #28a745;
    --color-error: #dc3545;
    --color-warning: #ffc107;
    --color-bg: #f8f9fa;
    --color-text: #333;
    --shadow: 0 2px 10px rgba(0,0,0,0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 1rem;
    color: var(--color-text);
}

.container {
    max-width: 800px;
    margin: 0 auto;
}

header {
    background: white;
    padding: 1.5rem;
    border-radius: 15px;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

h1 {
    text-align: center;
    color: var(--color-primary);
    margin-bottom: 1rem;
    font-size: 2rem;
}

.operation-selector {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.operation-btn {
    padding: 1rem 2rem;
    border: 3px solid #ddd;
    background: white;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: bold;
    transition: all 0.3s;
    min-width: 150px;
}

.operation-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.2);
}

.operation-btn.active {
    background: linear-gradient(135deg, var(--color-primary) 0%, #45a049 100%);
    color: white;
    border-color: var(--color-primary);
    box-shadow: 0 4px 8px rgba(76, 175, 80, 0.3);
}

.tables-selector {
    text-align: center;
    margin-top: 1rem;
}

.tables-selector label {
    font-weight: bold;
    margin-right: 1rem;
    font-size: 1rem;
}

.table-select {
    padding: 0.5rem 1rem;
    border: 2px solid var(--color-primary);
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    background: white;
}

.level-selector {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.level-btn {
    padding: 0.8rem 1.5rem;
    border: 2px solid #ddd;
    background: white;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: bold;
    transition: all 0.3s;
}

.level-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.level-btn.active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.level-btn small {
    display: block;
    font-size: 0.75rem;
    font-weight: normal;
    margin-top: 0.25rem;
}

.stats {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.stat-item {
    background: white;
    padding: 1rem 1.5rem;
    border-radius: 10px;
    text-align: center;
    box-shadow: var(--shadow);
    min-width: 100px;
}

.stat-label {
    display: block;
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 0.5rem;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--color-primary);
}

main {
    background: white;
    padding: 2rem;
    border-radius: 15px;
    box-shadow: var(--shadow);
}

.exercise-container {
    margin-bottom: 2rem;
}

.operation-display {
    text-align: right;
    font-size: 2.5rem;
    font-weight: bold;
    margin-bottom: 2rem;
    font-family: 'Courier New', monospace;
    position: relative;
}

.number-row {
    margin-bottom: 0.5rem;
    position: relative;
}

.operator {
    margin-right: 1rem;
}

.number {
    display: inline-block;
    letter-spacing: 0.5rem;
}

.line {
    border-top: 3px solid #333;
    margin: 0.5rem 0;
}

.retenue-row {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    min-height: 50px;
    font-size: 1.2rem;
    align-items: center;
    padding-right: 0.25rem;
}

.retenue-row.subtraction-retenue {
    margin: 0.5rem 0;
}

.retenue-row.addition-retenue {
    margin-bottom: 0.5rem;
    margin-top: 0;
}

.retenue-row.hidden {
    display: none;
}

.retenue-input-wrapper {
    width: 60px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.retenue-input {
    width: 100%;
    height: 100%;
    text-align: center;
    font-weight: bold;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    font-size: 1.3rem;
    transition: all 0.3s;
    padding: 0;
}

.retenue-input:focus {
    outline: none;
    border-color: #4CAF50;
    background: white;
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

.retenue-input::placeholder {
    color: #ccc;
}

.division-label {
    font-size: 1.1rem;
    font-weight: bold;
    color: #333;
    margin-bottom: 0.5rem;
    text-align: left;
    width: 120px;
}

.division-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.division-quotient-container,
.division-remainder-container {
    display: flex;
    gap: 0.5rem;
}

.retenue {
    width: 60px;
    height: 45px;
    text-align: center;
    font-weight: bold;
    border: 2px dashed #ddd;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    background: rgba(255, 255, 255, 0.5);
    user-select: none;
    font-size: 1.3rem;
    position: relative;
}

/* Trait vers le bas pour les soustractions (emprunte au chiffre du bas) */
.subtraction-retenue .retenue::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 8px;
    background: #ccc;
}

/* Trait vers le bas pour les additions (retenue s'ajoute au chiffre du haut) */
.addition-retenue .retenue::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 8px;
    background: #ccc;
}

.retenue:hover {
    background: rgba(233, 236, 239, 0.8);
    border-color: #adb5bd;
    transform: translateY(-2px);
}

.retenue.active {
    background: rgba(220, 53, 69, 0.15);
    border-color: var(--color-error);
    color: var(--color-error);
    border-style: solid;
    font-size: 1.5rem;
}

.retenue.correct-hint {
    background: rgba(40, 167, 69, 0.15);
    border-color: var(--color-success);
    color: var(--color-success);
    border-style: solid;
}

.retenue-label {
    font-size: 0.7rem;
    color: #6c757d;
    margin-bottom: 0.25rem;
    text-align: center;
}

.digit-inputs {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.digit-input {
    width: 60px;
    height: 80px;
    font-size: 2rem;
    text-align: center;
    border: 3px solid #ddd;
    border-radius: 10px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    transition: all 0.3s;
}

.digit-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2);
}

.digit-input.units {
    background-color: rgba(255, 107, 107, 0.1);
    border-color: var(--color-units);
}

.digit-input.tens {
    background-color: rgba(78, 205, 196, 0.1);
    border-color: var(--color-tens);
}

.digit-input.hundreds {
    background-color: rgba(255, 230, 109, 0.1);
    border-color: var(--color-hundreds);
}

.digit-input.thousands {
    background-color: rgba(162, 155, 254, 0.1);
    border-color: var(--color-thousands);
}

.digit-input.correct {
    background-color: rgba(40, 167, 69, 0.2);
    border-color: var(--color-success);
    animation: pulse 0.5s;
}

.digit-input.incorrect {
    background-color: rgba(220, 53, 69, 0.2);
    border-color: var(--color-error);
    animation: shake 0.5s;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.help-section {
    min-height: 60px;
    margin-bottom: 1.5rem;
}

.help-text {
    background: #e3f2fd;
    padding: 1.5rem;
    border-radius: 10px;
    border-left: 4px solid #2196F3;
    font-size: 0.95rem;
    line-height: 2;
    font-family: 'Courier New', monospace;
    white-space: pre-line;
}

.help-text .step-line {
    display: block;
    padding: 0.5rem;
    margin: 0.25rem 0;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 5px;
}

.help-text .step-line.units {
    border-left: 4px solid var(--color-units);
}

.help-text .step-line.tens {
    border-left: 4px solid var(--color-tens);
}

.help-text .step-line.hundreds {
    border-left: 4px solid var(--color-hundreds);
}

.help-text .step-line.thousands {
    border-left: 4px solid var(--color-thousands);
}

.controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.btn {
    padding: 1rem 2rem;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-success {
    background: var(--color-success);
    color: white;
}

.feedback {
    padding: 1.5rem;
    border-radius: 10px;
    text-align: center;
    font-size: 1.2rem;
    font-weight: bold;
    animation: slideIn 0.5s;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.feedback.success {
    background: rgba(40, 167, 69, 0.2);
    color: var(--color-success);
    border: 2px solid var(--color-success);
}

.feedback.error {
    background: rgba(220, 53, 69, 0.2);
    color: var(--color-error);
    border: 2px solid var(--color-error);
}

.feedback-content {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

.visual-aid {
    background: #f8f9fa;
    padding: 1.5rem;
    border-radius: 10px;
    margin-top: 2rem;
}

.visual-aid h3 {
    margin-bottom: 1rem;
    color: var(--color-primary);
}

.blocks-container {
    display: flex;
    gap: 2rem;
    justify-content: center;
    flex-wrap: wrap;
}

.block-group {
    text-align: center;
}

.block-label {
    font-weight: bold;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.blocks {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    max-width: 200px;
    justify-content: center;
}

.block {
    width: 30px;
    height: 30px;
    border-radius: 5px;
    transition: all 0.3s;
}

.block.units {
    background: var(--color-units);
}

.block.tens {
    background: var(--color-tens);
    width: 100px;
}

.block.hundreds {
    background: var(--color-hundreds);
    width: 150px;
}

.block.thousands {
    background: var(--color-thousands);
    width: 180px;
}

.block.crossed {
    opacity: 0.3;
    position: relative;
}

.block.crossed::after {
    content: '✗';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 1.5rem;
}

footer {
    text-align: center;
    margin-top: 2rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 10px;
    color: var(--color-primary);
    font-weight: bold;
}

.hidden {
    display: none !important;
}

/* Responsive */
@media (max-width: 600px) {
    h1 {
        font-size: 1.5rem;
    }
    
    .operation-display {
        font-size: 2rem;
    }
    
    .digit-input {
        width: 50px;
        height: 70px;
        font-size: 1.5rem;
    }
    
    main {
        padding: 1rem;
    }
    
    .controls {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
}
