* {
    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;
    direction: rtl;
    overflow-x: hidden; /* 🔧 AJOUTÉ: Éviter le défilement horizontal */
}

.screen {
    display: none;
    min-height: 100vh;
    padding: 20px;
    justify-content: center;
    align-items: center;
    width: 100vw; /* 🔧 AJOUTÉ: Assurer la largeur complète */
}

.screen.active {
    display: flex;
}

/* Masquer l'écran de sélection de famille */
#levelInfoScreen {
    display: none !important;
}

.welcome-card, .avatar-card, .level-info-card {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    padding: 40px;
    text-align: center;
    max-width: 500px;
    width: 90%;
    margin: 0 auto; /* 🔧 AJOUTÉ: Centrage supplémentaire */
    animation: slideIn 0.8s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.app-title {
    font-size: 32px;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 20px;
    background: linear-gradient(45deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.input-group {
    margin: 30px 0;
}

.input-label {
    font-size: 18px;
    color: #2c3e50;
    margin-bottom: 10px;
    font-weight: bold;
}

.name-input {
    width: 100%;
    padding: 15px;
    font-size: 18px;
    border: 3px solid #e9ecef;
    border-radius: 15px;
    text-align: center;
    outline: none;
    transition: border-color 0.3s ease;
}

.name-input:focus {
    border-color: #667eea;
}

.avatar-selection {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin: 30px 0;
    flex-wrap: wrap; /* 🔧 AJOUTÉ: Permettre le wrap sur mobile */
}

.avatar-option {
    width: 120px;
    height: 120px;
    border: 4px solid #e9ecef;
    border-radius: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 60px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #f8f9fa;
}

.avatar-option:hover {
    border-color: #667eea;
    transform: scale(1.05);
}

.avatar-option.selected {
    border-color: #667eea;
    background: linear-gradient(45deg, #667eea, #764ba2);
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}

.btn {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 25px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 20px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Map Screen */
.map-container {
    width: 100%;
    min-height: 100vh;
    position: relative;
    background: 
        radial-gradient(circle at 20% 20%, rgba(255,255,255,0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(255,255,255,0.1) 0%, transparent 50%),
        linear-gradient(135deg, #667eea 0%, #764ba2 50%, #667eea 100%);
    padding: 20px;
    display: flex; /* 🔧 AJOUTÉ: Flexbox pour centrage */
    flex-direction: column;
    align-items: center;
}

.map-header {
    text-align: center;
    color: white;
    margin-bottom: 30px;
}

.player-info {
    font-size: 24px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.progress-path {
    position: relative;
    width: 100%;
    max-width: 800px; /* 🔧 MODIFIÉ: Taille max réduite */
    margin: 0 auto;
    height: 500px;
    /* 🔧 MODIFIÉ: Utiliser CSS Grid pour un meilleur responsive */
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    grid-gap: 20px;
    align-items: center;
    justify-items: center;
}

/* 🔧 MODIFIÉ: Niveaux en responsive au lieu de positions absolues */
.level {
    position: relative; /* 🔧 CHANGÉ: relative au lieu d'absolute */
    width: 120px;
    height: 120px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 3;
    border: 4px solid white;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.level.unlocked {
    background: linear-gradient(45deg, #4CAF50, #45a049);
    cursor: not-allowed;
    opacity: 0.8;
}

.level.current {
    background: linear-gradient(45deg, #ff6b6b, #ffa726);
    animation: currentLevelGlow 1.5s ease infinite alternate;
    cursor: pointer;
}

.level.current:hover {
    transform: scale(1.1);
}

.level.locked {
    background: linear-gradient(45deg, #9e9e9e, #757575);
    cursor: not-allowed;
    opacity: 0.6;
}

/* Ajouter un indicateur visuel pour le niveau actuel */
.level.current::after {
    content: "🎯";
    position: absolute;
    top: -15px;
    right: -15px;
    font-size: 20px;
    background: white;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.level-number {
    font-size: 24px;
    font-weight: bold;
    color: white;
    margin-bottom: 5px;
}

.level-name {
    font-size: 11px;
    color: white;
    text-align: center;
    font-weight: bold;
}

/* 🔧 SUPPRIMÉ: Positions absolues remplacées par CSS Grid */

.character {
    position: absolute;
    width: 50px;
    height: 50px;
    font-size: 40px;
    z-index: 5;
    animation: characterBounce 1s ease infinite alternate;
    transition: all 1s ease;
    /* 🔧 MODIFIÉ: Position responsive */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

@keyframes characterBounce {
    0% { transform: translate(-50%, -50%) translateY(0); }
    100% { transform: translate(-50%, -50%) translateY(-10px); }
}

@keyframes currentLevelGlow {
    0% { transform: scale(1); box-shadow: 0 10px 30px rgba(0,0,0,0.3); }
    100% { transform: scale(1.1); box-shadow: 0 20px 50px rgba(255, 107, 107, 0.6); }
}

/* Level Info Screen - Supprimé car non utilisé */
.level-info-container {
    display: none;
}

.families-grid {
    display: none;
}

.family-card {
    display: none;
}

/* Game Screen */
.game-container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    padding: 30px;
    max-width: 600px;
    width: 90%;
    margin: 0 auto; /* 🔧 AJOUTÉ: Centrage */
    text-align: center;
    animation: slideIn 0.8s ease;
}

/* Messages plus clairs dans l'interface */
.game-header {
    background: linear-gradient(45deg, #ff6b6b, #ffa726);
    color: white;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
    text-align: center;
}

.game-header .level-indicator {
    font-size: 14px;
    opacity: 0.9;
    margin-bottom: 5px;
}

.family-title {
    font-size: 20px;
    margin-bottom: 10px;
}

.progress-info {
    font-size: 14px;
    opacity: 0.9;
}

.question-container {
    background: #f8f9fa;
    padding: 30px;
    border-radius: 15px;
    margin: 20px 0;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.instruction {
    font-size: 16px;
    color: #6c757d;
    margin-bottom: 20px;
}

.question {
    font-size: 24px;
    font-weight: bold;
    color: #2c3e50;
}

.choices-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 20px 0;
}

.choice-btn {
    background: linear-gradient(45deg, #36d1dc, #5b86e5);
    color: white;
    border: none;
    padding: 15px;
    border-radius: 15px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

.choice-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}

.choice-btn.correct {
    background: linear-gradient(45deg, #4CAF50, #45a049);
    animation: correctPulse 0.6s ease;
}

.choice-btn.wrong {
    background: linear-gradient(45deg, #f44336, #d32f2f);
    animation: wrongShake 0.6s ease;
}

.feedback {
    font-size: 16px;
    font-weight: bold;
    margin: 15px 0;
    padding: 10px;
    border-radius: 10px;
    display: none;
}

.feedback.correct {
    background: #d4edda;
    color: #155724;
    border: 2px solid #c3e6cb;
}

.feedback.wrong {
    background: #f8d7da;
    color: #721c24;
    border: 2px solid #f5c2c7;
}

.next-btn {
    background: linear-gradient(45deg, #ff6b6b, #ffa726);
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 20px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: none;
}

@keyframes correctPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Special styles for different question types */
.elements-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin: 10px 0;
}

.element-item {
    font-size: 24px;
    animation: bounceIn 0.6s ease;
}

.big-number {
    font-size: 48px;
    font-weight: bold;
    color: #2c3e50;
    background: linear-gradient(45deg, #6a11cb, #2575fc);
    color: white;
    padding: 20px 30px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.equation-display {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.equation-display .number {
    background: linear-gradient(45deg, #ff6b6b, #ffa726);
    color: white;
    font-size: 32px;
    font-weight: bold;
    padding: 15px 20px;
    border-radius: 10px;
}

.equation-display .operator, .equation-display .equals {
    font-size: 32px;
    font-weight: bold;
    color: #2c3e50;
}

.equation-display .question-mark {
    background: linear-gradient(45deg, #4ecdc4, #44a08d);
    color: white;
    font-size: 32px;
    font-weight: bold;
    padding: 15px 20px;
    border-radius: 10px;
}

.number-composition {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.digit-info {
    background: linear-gradient(45deg, #ff6b6b, #ffa726);
    border-radius: 15px;
    padding: 15px;
    text-align: center;
    color: white;
}

.digit-label {
    font-size: 14px;
    margin-bottom: 5px;
}

.digit-value {
    font-size: 32px;
    font-weight: bold;
}

@keyframes bounceIn {
    0% { opacity: 0; transform: scale(0.3); }
    50% { opacity: 1; transform: scale(1.05); }
    100% { opacity: 1; transform: scale(1); }
}

.back-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px;
}

.domino {
    background: #ffffff;
    border: 3px solid #2c3e50;
    border-radius: 10px;
    width: 80px;
    height: 160px;
    display: flex;
    flex-direction: column;
    margin: 10px auto;
}

.domino-half {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    padding: 5px;
}

.domino-half:first-child {
    border-bottom: 2px solid #2c3e50;
}

.domino-dot {
    width: 8px;
    height: 8px;
    background: #2c3e50;
    border-radius: 50%;
    margin: 1px;
}

.numbers-to-sort {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.number-card {
    background: linear-gradient(45deg, #ff9800, #ff5722);
    color: white;
    font-size: 24px;
    font-weight: bold;
    width: 60px;
    height: 60px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.enigma-display {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 15px;
    padding: 20px;
    color: white;
    text-align: center;
}

.enigma-text {
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 15px;
}

.enigma-question {
    font-size: 18px;
    background: linear-gradient(45deg, #4ecdc4, #44a08d);
    padding: 10px 20px;
    border-radius: 20px;
    display: inline-block;
}

/* Toast notifications styles */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    pointer-events: none;
}

.toast {
    background: #333;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    margin-bottom: 10px;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
    pointer-events: auto;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast.toast-error {
    background: #f44336;
}

.toast.toast-success {
    background: #4CAF50;
}

.toast.toast-info {
    background: #2196F3;
}

/* Achievement popup styles */
.achievement-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.achievement-popup.show {
    opacity: 1;
}

.achievement-content {
    background: white;
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    max-width: 400px;
    transform: scale(0.7);
    transition: transform 0.3s ease;
}

.achievement-popup.show .achievement-content {
    transform: scale(1);
}

.achievement-icon {
    font-size: 60px;
    margin-bottom: 20px;
}

.achievement-title {
    font-size: 24px;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 10px;
}

.achievement-description {
    font-size: 16px;
    color: #6c757d;
    margin-bottom: 20px;
}

/* 🔧 RESPONSIVE DESIGN COMPLET */

/* 📱 Mobile Portrait (320px - 480px) */
@media (max-width: 480px) {
    .screen {
        padding: 10px;
    }
    
    .welcome-card, .avatar-card, .game-container {
        width: 95%;
        padding: 20px;
    }
    
    .app-title {
        font-size: 24px;
    }
    
    .avatar-selection {
        gap: 15px;
    }
    
    .avatar-option {
        width: 80px;
        height: 80px;
        font-size: 40px;
    }
    
    .level {
        width: 80px;
        height: 80px;
    }
    
    .level-number {
        font-size: 18px;
    }
    
    .level-name {
        font-size: 9px;
    }
    
    .progress-path {
        grid-template-columns: repeat(2, 1fr);
        height: auto;
        gap: 15px;
    }
    
    .game-header {
        padding: 15px;
    }
    
    .family-title {
        font-size: 16px;
    }
    
    .progress-info {
        font-size: 12px;
    }
    
    .question-container {
        padding: 20px;
        min-height: 120px;
    }
    
    .question {
        font-size: 20px;
    }
    
    .choice-btn {
        padding: 12px;
        font-size: 16px;
    }
    
    .equation-display .number,
    .equation-display .question-mark {
        font-size: 24px;
        padding: 10px 15px;
    }
    
    .equation-display .operator,
    .equation-display .equals {
        font-size: 24px;
    }
    
    .big-number {
        font-size: 32px;
        padding: 15px 20px;
    }
}

/* 📱 Mobile Landscape & Small Tablet (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    .welcome-card, .avatar-card, .game-container {
        width: 90%;
        padding: 30px;
    }
    
    .app-title {
        font-size: 28px;
    }
    
    .avatar-option {
        width: 100px;
        height: 100px;
        font-size: 50px;
    }
    
    .level {
        width: 100px;
        height: 100px;
    }
    
    .level-number {
        font-size: 20px;
    }
    
    .level-name {
        font-size: 10px;
    }
    
    .progress-path {
        grid-template-columns: repeat(3, 1fr);
        height: auto;
        gap: 20px;
    }
    
    .equation-display .number,
    .equation-display .question-mark {
        font-size: 28px;
        padding: 12px 18px;
    }
    
    .big-number {
        font-size: 40px;
        padding: 18px 25px;
    }
}

/* 💻 Tablet (769px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .welcome-card, .avatar-card, .game-container {
        max-width: 600px;
        padding: 35px;
    }
    
    .progress-path {
        grid-template-columns: repeat(4, 1fr);
        max-width: 700px;
    }
    
    .level {
        width: 110px;
        height: 110px;
    }
    
    .avatar-option {
        width: 110px;
        height: 110px;
        font-size: 55px;
    }
}

/* 🖥️ Desktop (1025px+) */
@media (min-width: 1025px) {
    .welcome-card, .avatar-card, .game-container {
        max-width: 700px;
    }
    
    .progress-path {
        grid-template-columns: repeat(5, 1fr);
        max-width: 900px;
    }
    
    .level:hover {
        transform: scale(1.05);
    }
    
    .choice-btn:hover {
        transform: translateY(-3px);
    }
}

/* 🖥️ Large Desktop (1440px+) */
@media (min-width: 1440px) {
    .welcome-card, .avatar-card, .game-container {
        max-width: 800px;
        padding: 50px;
    }
    
    .app-title {
        font-size: 36px;
    }
    
    .progress-path {
        max-width: 1000px;
    }
    
    .level {
        width: 140px;
        height: 140px;
    }
    
    .level-number {
        font-size: 28px;
    }
    
    .level-name {
        font-size: 12px;
    }
}

/* 🔧 CORRECTIONS SPÉCIALES pour le centrage */
@media (max-width: 768px) {
    .toast-container {
        left: 10px;
        right: 10px;
        top: 10px;
    }
    
    .toast {
        transform: translateY(-100%);
        margin-bottom: 5px;
    }
    
    .toast.show {
        transform: translateY(0);
    }
    
    .character {
        font-size: 30px;
        width: 40px;
        height: 40px;
    }
    
    .map-container {
        padding: 10px;
    }
    
    .back-btn {
        top: 10px;
        left: 10px;
        padding: 8px 12px;
        font-size: 14px;
    }
}