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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', 'Roboto', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #f5576c 75%, #feca57 100%);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

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

.container {
    background: rgba(255, 255, 255, 0.98);
    border-radius: 28px;
    padding: 40px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.2);
    max-width: 800px;
    width: 100%;
    border: 2px solid rgba(255, 255, 255, 0.8);
}

h1 {
    text-align: center;
    background: linear-gradient(135deg, #667eea, #764ba2, #f5576c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 30px;
    font-size: 3em;
    font-weight: 700;
    letter-spacing: -2px;
}

.game-info {
    display: flex;
    justify-content: space-around;
    margin-bottom: 30px;
    padding: 20px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(245, 87, 108, 0.1));
    border-radius: 18px;
    border: 2px solid rgba(102, 126, 234, 0.3);
}

.info-item {
    text-align: center;
}

.label {
    font-weight: 600;
    color: #667eea;
    margin-right: 8px;
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 2px;
    display: block;
    margin-bottom: 6px;
}

#level, #moves, #best {
    font-size: 2.2em;
    background: linear-gradient(135deg, #f5576c, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 700;
}

#gameCanvas {
    display: block;
    margin: 0 auto;
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.2);
    border: 2px solid rgba(102, 126, 234, 0.2);
}

.controls {
    margin-top: 30px;
}

.instructions {
    background: linear-gradient(135deg, rgba(254, 202, 87, 0.15), rgba(245, 87, 108, 0.15));
    padding: 20px;
    border-radius: 18px;
    margin-bottom: 25px;
    border: 2px solid rgba(245, 87, 108, 0.3);
    border-left: 5px solid #f5576c;
}

.instructions h3 {
    background: linear-gradient(135deg, #f5576c, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 12px;
    font-weight: 600;
    font-size: 1.1em;
}

.instructions p {
    margin: 8px 0;
    color: #555;
    line-height: 1.8;
    font-size: 0.95em;
}

.buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn {
    padding: 15px 30px;
    font-size: 0.95em;
    font-weight: 600;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn:hover {
    background: linear-gradient(135deg, #f5576c, #feca57);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(245, 87, 108, 0.4);
}

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

.btn:disabled {
    background: #ddd;
    color: #999;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(102, 126, 234, 0.3);
    animation: fadeIn 0.3s;
    backdrop-filter: blur(10px);
}

.modal-content {
    background: rgba(255, 255, 255, 0.98);
    margin: 15% auto;
    padding: 50px;
    border-radius: 28px;
    width: 90%;
    max-width: 500px;
    text-align: center;
    animation: slideIn 0.3s;
    box-shadow: 0 25px 50px rgba(102, 126, 234, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.8);
}

.modal-content h2 {
    background: linear-gradient(135deg, #667eea, #f5576c, #feca57);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 24px;
    font-size: 2.5em;
    font-weight: 700;
    letter-spacing: -1px;
}

.modal-content p {
    font-size: 1.15em;
    margin-bottom: 35px;
    color: #555;
    line-height: 1.8;
}

.modal-content .btn {
    margin: 8px;
}

/* Étoiles */
.stars-display {
    font-size: 1.5em;
}

#stars {
    background: linear-gradient(135deg, #feca57, #f5576c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 1.2em;
    letter-spacing: 2px;
}

/* Bouton hint */
.btn-hint {
    background: linear-gradient(135deg, #feca57, #f5576c);
}

.btn-hint:hover {
    background: linear-gradient(135deg, #f5576c, #feca57);
}

.btn-hint:disabled {
    background: #ddd;
    color: #999;
}

/* Animations */
@keyframes bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes particle {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(var(--x), var(--y)) scale(0);
    }
}

.bounce {
    animation: bounce 0.3s ease;
}

/* Particules de victoire */
.particle {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    pointer-events: none;
    animation: particle 1s ease-out forwards;
}

/* Hint highlight */
@keyframes pulse {
    0%, 100% { 
        box-shadow: 0 0 0 0 rgba(254, 202, 87, 0.7);
    }
    50% { 
        box-shadow: 0 0 0 15px rgba(254, 202, 87, 0);
    }
}

.hint-highlight {
    animation: pulse 1.5s ease-in-out 3;
}

/* Page d'accueil */
.home-page {
    text-align: center;
    max-width: 750px;
    padding: 60px 40px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0.95));
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.12);
}

.home-header {
    margin-bottom: 50px;
    position: relative;
}

.game-icon {
    font-size: 6em;
    margin-bottom: 20px;
    animation: float 3s ease-in-out infinite;
    filter: drop-shadow(0 10px 20px rgba(102, 126, 234, 0.3));
}

@keyframes float {
    0%, 100% { transform: translateY(0px) rotate(0deg); }
    50% { transform: translateY(-15px) rotate(5deg); }
}

.home-page h1 {
    font-size: 4em;
    margin-bottom: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f5576c 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 900;
    letter-spacing: -3px;
    text-shadow: 0 4px 10px rgba(102, 126, 234, 0.2);
}

.subtitle {
    font-size: 1.3em;
    color: #888;
    font-weight: 500;
    margin-bottom: 10px;
}

/* Statistiques */
.home-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 45px;
}

.stat-card {
    background: linear-gradient(135deg, #ffffff, #fafafa);
    padding: 25px 20px;
    border-radius: 20px;
    border: 2px solid rgba(102, 126, 234, 0.15);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, #667eea, #f5576c);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 30px rgba(102, 126, 234, 0.2);
    border-color: rgba(102, 126, 234, 0.3);
}

.stat-number {
    font-size: 3em;
    font-weight: 900;
    background: linear-gradient(135deg, #667eea, #f5576c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
    line-height: 1;
}

.stat-label {
    font-size: 0.85em;
    color: #888;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

/* Boutons */
.home-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 45px;
}

.btn-large {
    padding: 22px 40px;
    font-size: 1.15em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

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

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

.btn-icon {
    font-size: 1.5em;
    position: relative;
    z-index: 1;
}

.btn-text {
    font-weight: 800;
    position: relative;
    z-index: 1;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    box-shadow: 0 6px 25px rgba(102, 126, 234, 0.4);
    border: none;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #764ba2, #f5576c);
    transform: translateY(-4px);
    box-shadow: 0 10px 35px rgba(102, 126, 234, 0.5);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.8);
    color: #667eea;
    border: 2px solid rgba(102, 126, 234, 0.3);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.15);
}

.btn-secondary:hover {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(245, 87, 108, 0.1));
    border-color: rgba(102, 126, 234, 0.5);
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.25);
}

/* Features */
.home-features {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
}

.feature {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(250, 250, 250, 0.9));
    padding: 25px 20px;
    border-radius: 18px;
    border: 2px solid rgba(102, 126, 234, 0.15);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.08);
}

.feature:hover {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.08), rgba(245, 87, 108, 0.08));
    border-color: rgba(102, 126, 234, 0.35);
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.15);
}

.feature-icon {
    font-size: 2.5em;
    filter: drop-shadow(0 4px 8px rgba(102, 126, 234, 0.2));
}

.feature-text {
    font-size: 0.95em;
    color: #666;
    font-weight: 600;
    text-align: center;
    line-height: 1.5;
}

/* Page de sélection de niveaux */
.level-select-page {
    max-width: 900px;
}

.btn-back {
    margin-bottom: 20px;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
    margin-top: 20px;
}

.level-card {
    aspect-ratio: 1;
    border: 2px solid rgba(102, 126, 234, 0.3);
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(245, 87, 108, 0.1));
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    position: relative;
}

.level-card:hover:not(.locked) {
    background: linear-gradient(135deg, #667eea, #764ba2);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.level-card:hover:not(.locked) .level-number {
    color: white;
}

.level-card.locked {
    opacity: 0.4;
    cursor: not-allowed;
    background: #ddd;
}

.level-card.completed {
    border-color: rgba(245, 87, 108, 0.5);
    background: linear-gradient(135deg, rgba(245, 87, 108, 0.2), rgba(254, 202, 87, 0.2));
}

.level-number {
    font-size: 1.8em;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea, #f5576c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.level-card.locked .level-number {
    background: #999;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.level-status {
    font-size: 0.8em;
    color: #666;
    margin-top: 4px;
}

.level-card.completed .level-status {
    color: #f5576c;
}

.lock-icon {
    font-size: 2em;
    color: #999;
}

@media (max-width: 600px) {
    .container {
        padding: 20px;
    }
    
    h1 {
        font-size: 2em;
        letter-spacing: -1px;
    }
    
    .home-page {
        padding: 40px 25px;
    }
    
    .home-page h1 {
        font-size: 2.8em;
        letter-spacing: -2px;
    }
    
    .game-icon {
        font-size: 4em;
    }
    
    .subtitle {
        font-size: 1.1em;
    }
    
    .home-stats {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .stat-card {
        padding: 20px;
    }
    
    .stat-number {
        font-size: 2.5em;
    }
    
    .home-features {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .feature {
        padding: 20px;
    }
    
    .game-info {
        flex-direction: column;
        gap: 10px;
    }
    
    .buttons {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
    
    .level-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 8px;
    }
    
    .btn-large {
        padding: 18px 30px;
        font-size: 1.05em;
    }
    
    #gameCanvas {
        max-width: 100%;
        height: auto;
    }
}

/* Manette virtuelle pour mobile */
.virtual-dpad {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 20px auto;
    padding: 20px;
    max-width: 200px;
    touch-action: none;
}

.dpad-row {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

.dpad-btn {
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    font-size: 1.8em;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    transition: all 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dpad-btn:active {
    transform: scale(0.9);
    background: linear-gradient(135deg, #f5576c, #feca57);
    box-shadow: 0 2px 8px rgba(245, 87, 108, 0.4);
}

.dpad-center {
    width: 60px;
    height: 60px;
}

/* Afficher la manette seulement sur mobile */
@media (max-width: 768px) {
    .virtual-dpad {
        display: flex;
    }
    
    .instructions p:last-of-type {
        margin-bottom: 0;
    }
}

/* Empêcher le zoom sur double-tap */
canvas, button, .dpad-btn {
    touch-action: manipulation;
}

/* Améliorer le canvas sur mobile */
@media (max-width: 600px) {
    #gameCanvas {
        width: 100%;
        max-width: 100%;
        height: auto;
        touch-action: none;
    }
    
    .game-info {
        padding: 15px;
    }
    
    .info-item {
        font-size: 0.9em;
    }
    
    #level, #moves, #best {
        font-size: 1.8em;
    }
}

/* Afficher/masquer les instructions selon la plateforme */
.desktop-only {
    display: inline;
}

.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none;
    }
    
    .mobile-only {
        display: inline;
    }
}

