/* === Styles généraux === */
* { 
    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: 20px;
    animation: gradientShift 10s ease infinite;
    background-size: 200% 200%;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.container { 
    max-width: 1400px; 
    margin: 0 auto; 
    background: rgba(255, 255, 255, 0.98); 
    border-radius: 20px; 
    overflow: hidden; 
    box-shadow: 0 25px 80px rgba(0,0,0,0.3);
    backdrop-filter: blur(10px);
}

/* === Header === */
.header { 
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); 
    color: white; 
    padding: 32px; 
    text-align: center;
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    animation: headerPulse 8s ease-in-out infinite;
}

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

.header h1 { 
    font-size: 2.2rem; 
    margin-bottom: 8px;
    position: relative;
    z-index: 1;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.header p {
    position: relative;
    z-index: 1;
    font-size: 1.05rem;
    opacity: 0.95;
}

/* === Onglets === */
.tabs { 
    display: flex; 
    background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
    border-bottom: 3px solid #667eea; 
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.tab { 
    flex: 1; 
    padding: 18px; 
    text-align: center; 
    cursor: pointer; 
    font-weight: 700; 
    color: #6c757d; 
    border: none; 
    background: transparent; 
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    font-size: 1.05rem;
}

.tab::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0;
    height: 4px;
    background: linear-gradient(90deg, #667eea, #764ba2);
    transform: translateX(-50%);
    transition: width 0.3s ease;
}

.tab:hover {
    background: rgba(102, 126, 234, 0.08);
    color: #667eea;
}

.tab:hover::after {
    width: 80%;
}

.tab.active { 
    background: white; 
    color: #667eea; 
    border-bottom: none;
    box-shadow: 0 -2px 8px rgba(102, 126, 234, 0.2);
}

.tab.active::after {
    width: 100%;
}

.tab-content { 
    display: none; 
    padding: 24px; 
}

.tab-content.active { 
    display: block; 
}

/* === Sélecteur de mode === */
.mode-selector { 
    display: flex; 
    gap: 12px; 
    justify-content: center; 
    margin-bottom: 16px; 
}

.mode-btn { 
    padding: 12px 24px; 
    border-radius: 12px; 
    border: 3px solid #667eea; 
    cursor: pointer; 
    background: white; 
    color: #667eea; 
    font-weight: 700; 
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 1rem;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.mode-btn:hover {
    background: #f0f3ff;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.3);
}

.mode-btn.active { 
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; 
    border-color: #764ba2;
    transform: scale(1.05);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

/* === Sections d'entrée === */
.input-section { 
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 24px; 
    border-radius: 16px; 
    margin-bottom: 20px;
    border: 2px solid rgba(102, 126, 234, 0.1);
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
}

.input-section h3 {
    color: #667eea;
    margin-bottom: 16px;
    font-size: 1.3rem;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}

.input-group { 
    margin-bottom: 16px; 
}

.input-group label { 
    display: block; 
    font-weight: 700; 
    margin-bottom: 8px; 
    color: #495057;
    font-size: 1rem;
}

.input-group input, 
.input-group textarea { 
    width: 100%; 
    padding: 12px 16px; 
    border-radius: 10px; 
    border: 2px solid #dee2e6; 
    font-size: 1rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: white;
}

.input-group input:focus,
.input-group textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.15);
    transform: translateY(-2px);
}

.input-group textarea { 
    min-height: 100px; 
    resize: vertical; 
    font-family: 'Courier New', monospace;
}

.auto-gen-note { 
    background: linear-gradient(135deg, #e7f3ff 0%, #d0ebff 100%);
    border-left: 5px solid #0066cc; 
    padding: 14px 16px; 
    border-radius: 10px; 
    font-size: 0.95rem; 
    margin-bottom: 12px;
    box-shadow: 0 2px 8px rgba(0, 102, 204, 0.1);
}

.auto-gen-note strong {
    color: #0066cc;
}

/* === Zone de visualisation === */
.visualization-area { 
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    padding: 24px; 
    border-radius: 16px; 
    min-height: 400px;
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.05);
}

/* === Matrice === */
.matrix-container { 
    display: grid; 
    grid-template-columns: repeat(4, 1fr); 
    gap: 12px; 
    max-width: 720px; 
    margin: 16px auto; 
    padding: 10px;
}

.matrix-cell { 
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    padding: 14px; 
    border-radius: 12px; 
    text-align: center; 
    font-family: 'Courier New', monospace; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    font-size: 0.95rem;
    border: 2px solid transparent;
}

.matrix-cell:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

.matrix-cell.highlight { 
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; 
    transform: scale(1.08); 
    box-shadow: 0 8px 25px rgba(102,126,234,0.45);
    border-color: #764ba2;
    animation: pulse 1.5s ease-in-out infinite;
}

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

.matrix-cell.active { 
    background: linear-gradient(135deg, #ffc107 0%, #ff9800 100%);
    color: #000; 
    transform: scale(1.1); 
    box-shadow: 0 10px 30px rgba(255,193,7,0.5);
    border-color: #ff9800;
    animation: activeGlow 1s ease-in-out infinite;
}

@keyframes activeGlow {
    0%, 100% { 
        box-shadow: 0 10px 30px rgba(255,193,7,0.5);
    }
    50% { 
        box-shadow: 0 15px 40px rgba(255,193,7,0.7);
    }
}

.matrix-cell.result { 
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    border-color: #20c997;
    animation: resultPop 0.6s ease;
}

@keyframes resultPop {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

/* Affichage matriciel pour l'addition finale */
.matrix-addition-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin: 20px auto;
    flex-wrap: wrap;
}

.matrix-addition-label {
    font-size: 2rem;
    font-weight: bold;
    color: #667eea;
}

.matrix-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    max-width: 300px;
}

.matrix-grid-cell {
    background: white;
    padding: 10px;
    border-radius: 6px;
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.matrix-grid-cell.highlight {
    background: #667eea;
    color: white;
}

.matrix-grid-cell.result {
    background: #28a745;
    color: white;
}

/* === Contrôles === */
.controls { 
    display: flex; 
    gap: 12px; 
    justify-content: center; 
    margin-top: 20px; 
    flex-wrap: wrap; 
}

.btn { 
    padding: 12px 24px; 
    border-radius: 12px; 
    border: none; 
    cursor: pointer; 
    font-weight: 700; 
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 1rem;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

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

.btn:active {
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn:disabled:hover {
    transform: none;
    box-shadow: none;
}

.btn:disabled::before {
    display: none;
}

.btn-primary { 
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; 
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover {
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6);
}

.btn-secondary { 
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(108, 117, 125, 0.4);
}

.btn-secondary:hover {
    box-shadow: 0 8px 25px rgba(108, 117, 125, 0.6);
}

.btn-start { 
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white; 
    padding: 14px 32px;
    font-size: 1.1rem;
    box-shadow: 0 6px 20px rgba(40, 167, 69, 0.4);
}

.btn-start:hover {
    box-shadow: 0 10px 30px rgba(40, 167, 69, 0.6);
}

/* === Affichages === */
.operation-display, 
.poly-computation { 
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    padding: 16px; 
    border-radius: 12px; 
    border-left: 5px solid #667eea; 
    margin: 14px auto; 
    max-width: 900px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.operation-display h4,
.poly-computation h4 {
    color: #667eea;
    margin-bottom: 12px;
}

.poly-block {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 16px;
    border-radius: 10px;
    margin: 12px 0;
    border: 2px solid rgba(102, 126, 234, 0.1);
}

.poly-block h5 {
    color: #667eea;
    margin-bottom: 10px;
    font-size: 1.05rem;
}

.info-box { 
    background: linear-gradient(135deg, #fff3cd 0%, #ffe69c 100%);
    padding: 16px; 
    border-radius: 12px; 
    border: 3px solid #ffc107; 
    margin-top: 14px;
    box-shadow: 0 4px 12px rgba(255, 193, 7, 0.2);
}

.info-box strong {
    color: #856404;
}

.byte-display { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 8px; 
    justify-content: center;
    padding: 10px;
}

.byte { 
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    padding: 8px 10px; 
    border-radius: 8px; 
    font-family: 'Courier New', monospace; 
    box-shadow: 0 3px 8px rgba(0,0,0,0.1); 
    min-width: 45px; 
    text-align: center; 
    font-size: 0.95rem;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.byte:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 12px rgba(0,0,0,0.15);
}

.byte.highlight { 
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; 
    transform: scale(1.05);
    border-color: #764ba2;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.byte.active { 
    background: linear-gradient(135deg, #ffc107 0%, #ff9800 100%);
    color: #000; 
    transform: scale(1.08);
    border-color: #ff9800;
    box-shadow: 0 5px 15px rgba(255, 193, 7, 0.5);
    animation: byteActive 0.6s ease;
}

@keyframes byteActive {
    0%, 100% { transform: scale(1.08); }
    50% { transform: scale(1.15); }
}

.step-title { 
    text-align: center; 
    color: #667eea;
    font-weight: 700; 
    margin-bottom: 16px; 
    font-size: 1.4rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
    padding: 12px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-radius: 10px;
    border-left: 5px solid #667eea;
}

/* === Barre de progression === */
.progress-bar { 
    height: 28px; 
    background: linear-gradient(to right, #e9ecef, #dee2e6);
    border-radius: 14px; 
    overflow: hidden; 
    margin-bottom: 16px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
}

.progress-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

.progress-fill { 
    height: 100%; 
    background: linear-gradient(90deg, #667eea, #764ba2, #667eea);
    background-size: 200% 100%;
    display: flex; 
    align-items: center; 
    justify-content: center; 
    color: white; 
    font-weight: 700; 
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    animation: progressGradient 3s ease infinite;
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.5);
    position: relative;
}

@keyframes progressGradient {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 20px;
    height: 100%;
    background: linear-gradient(to right, transparent, rgba(255,255,255,0.3));
}

/* === Pre et Code === */
pre { 
    background: #f8f9fa; 
    padding: 10px; 
    border-radius: 6px; 
    overflow: auto; 
    font-family: 'Courier New', monospace; 
    font-size: 0.9rem;
    border: 1px solid #e0e0e0;
}

/* === Utilitaires === */
.hidden { 
    display: none !important; 
}

/* === Animations === */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.visualization-area.active {
    animation: fadeIn 0.3s ease;
}

/* === Responsive === */
@media (max-width: 800px) { 
    .matrix-container { 
        grid-template-columns: repeat(2, 1fr); 
    }
    
    .matrix-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .matrix-addition-container {
        flex-direction: column;
    }
    
    .header h1 {
        font-size: 1.5rem;
    }
    
    .tabs {
        flex-direction: column;
    }
    
    .tab {
        border-bottom: 1px solid #e0e0e0;
    }
    
    .tab.active {
        border-bottom: 4px solid #2e4eb8;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    .container {
        border-radius: 8px;
    }
    
    .tab-content {
        padding: 12px;
    }
    
    .input-section {
        padding: 12px;
    }
}
