* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #ec4899;
    --success: #10b981;
    --error: #ef4444;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--background);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Animation de fond */
.background-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, #0f172a, #1e293b, #0f172a);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    z-index: -1;
}

.background-animation::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 20% 50%, rgba(99, 102, 241, 0.1) 0%, transparent 50%),
                radial-gradient(circle at 80% 80%, rgba(236, 72, 153, 0.1) 0%, transparent 50%);
    animation: pulse 8s ease infinite;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Écrans */
.screen {
    display: none;
    min-height: 100vh;
    padding: 2rem;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Écran de profil */
.profile-container {
    text-align: center;
    max-width: 1200px;
    width: 100%;
}

.app-title {
    font-size: 3.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 1rem;
    animation: titleFloat 3s ease-in-out infinite;
}

@keyframes titleFloat {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

.emoji {
    display: inline-block;
    animation: rotate 2s ease-in-out infinite;
}

@keyframes rotate {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-10deg); }
    75% { transform: rotate(10deg); }
}

.subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: 3rem;
}

.profiles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.profile-card {
    background: var(--surface);
    border-radius: 20px;
    padding: 2.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.profile-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    opacity: 0;
    transition: opacity 0.3s ease;
}

.profile-card:hover::before {
    opacity: 0.1;
}

.profile-card:hover {
    transform: translateY(-10px) scale(1.02);
    border-color: var(--primary);
    box-shadow: 0 20px 60px rgba(99, 102, 241, 0.3);
}

.profile-icon {
    font-size: 5rem;
    margin-bottom: 1rem;
    position: relative;
    z-index: 1;
}

.profile-card h3 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
    position: relative;
    z-index: 1;
}

.profile-stats {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
    z-index: 1;
}

.stat {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 1200px;
    margin-bottom: 2rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--surface);
    padding: 1rem 1.5rem;
    border-radius: 50px;
    font-size: 1.2rem;
}

.user-icon {
    font-size: 2rem;
}

/* Écran de sélection de deck */
.deck-container {
    width: 100%;
    max-width: 1200px;
}

.section-title {
    font-size: 2rem;
    margin-bottom: 2rem;
    text-align: center;
}

.decks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
    margin-bottom: 3rem;
}

.deck-card {
    background: var(--surface);
    border-radius: 20px;
    padding: 2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.deck-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 5px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
}

.deck-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: 0 10px 40px rgba(99, 102, 241, 0.2);
}

.deck-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.deck-card h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.deck-info {
    color: var(--text-secondary);
    margin-top: 1rem;
}

.add-deck-section {
    text-align: center;
}

/* Boutons */
.btn-primary, .btn-secondary, .btn-logout, .btn-back {
    padding: 1rem 2rem;
    border: none;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--surface-light);
}

.btn-secondary:hover {
    background: var(--surface);
    transform: translateY(-2px);
}

.btn-logout, .btn-back {
    background: var(--surface);
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

.btn-logout:hover, .btn-back:hover {
    background: var(--surface-light);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: linear-gradient(135deg, var(--surface) 0%, #1a2332 100%);
    padding: 0;
    border-radius: 24px;
    max-width: 900px;
    width: 95%;
    max-height: 90vh;
    position: relative;
    animation: modalSlideIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1px solid rgba(99, 102, 241, 0.2);
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px) scale(0.9);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.modal-header {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    padding: 2rem 2.5rem;
    position: relative;
}

.modal-content h2 {
    margin: 0;
    font-size: 2rem;
    color: white;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.modal-body {
    padding: 2.5rem;
    max-height: calc(90vh - 200px);
    overflow-y: auto;
}

.close {
    position: absolute;
    right: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 2.5rem;
    cursor: pointer;
    color: white;
    transition: all 0.3s ease;
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
}

.close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-50%) rotate(90deg);
}

/* Tabs pour basculer entre visuel et JSON */
.modal-tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    background: var(--background);
    padding: 0.5rem;
    border-radius: 12px;
}

.tab-btn {
    flex: 1;
    padding: 1rem 1.5rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.tab-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.tab-btn:hover:not(.active) {
    background: var(--surface-light);
    color: var(--text);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Formulaire visuel */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text);
    font-weight: 600;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    background: var(--background);
    border: 2px solid var(--surface-light);
    border-radius: 12px;
    padding: 1rem;
    color: var(--text);
    font-size: 1rem;
    transition: all 0.3s ease;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.input-with-icon {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.input-with-icon input {
    flex: 1;
}

.icon-preview {
    font-size: 3rem;
    width: 70px;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 16px;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

/* Liste de cartes améliorée */
.cards-section {
    margin-top: 2rem;
}

.cards-section h3 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.cards-count {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
}

.cards-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.cards-list::-webkit-scrollbar {
    width: 8px;
}

.cards-list::-webkit-scrollbar-track {
    background: var(--background);
    border-radius: 10px;
}

.cards-list::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 10px;
}

.card-row {
    display: flex;
    align-items: stretch;
    gap: 1rem;
    padding: 1.25rem;
    background: var(--background);
    border-radius: 16px;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.card-row:hover {
    border-color: var(--primary);
    transform: translateX(5px);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.15);
}

.card-order {
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.card-preview {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.card-preview .q {
    font-weight: 600;
    color: var(--text);
    font-size: 1.05rem;
}

.card-preview .a {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-style: italic;
}

.card-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.card-actions button {
    background: var(--surface-light);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-actions button:hover {
    transform: scale(1.1);
}

.card-actions button:first-child:hover {
    background: var(--primary);
}

.card-actions button:last-child:hover {
    background: var(--error);
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Zone JSON */
#jsonInput,
#editJsonInput {
    width: 100%;
    min-height: 400px;
    background: var(--background);
    border: 2px solid var(--surface-light);
    border-radius: 12px;
    padding: 1.5rem;
    color: var(--text);
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.9rem;
    resize: vertical;
    transition: all 0.3s ease;
}

#jsonInput:focus,
#editJsonInput:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.error-message {
    color: var(--error);
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 10px;
    border-left: 4px solid var(--error);
}

/* Actions de modal */
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid var(--background);
}

.btn-add-card {
    width: 100%;
    margin-top: 1rem;
    padding: 1.25rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-add-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}

/* Bouton éditer sur les decks */
.deck-actions {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--surface-light);
}

.btn-edit {
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: var(--surface-light);
    color: var(--text);
    border: 2px solid transparent;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-edit:hover {
    background: transparent;
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
}

/* Écran de révision */
.revision-header {
    width: 100%;
    max-width: 800px;
    margin-bottom: 2rem;
}

.progress-info {
    text-align: center;
    margin-top: 1rem;
}

.progress-info h3 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
}

.progress-bar {
    width: 100%;
    height: 10px;
    background: var(--surface);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    transition: width 0.5s ease;
    border-radius: 10px;
}

.progress-text {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Flashcard */
.flashcard-container {
    perspective: 1000px;
    width: 100%;
    max-width: 700px;
    height: 500px;
}


.flashcard {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.6s;
    -webkit-transform-style: preserve-3d;
        transform-style: preserve-3d;
}

.flashcard.flipped {
    -webkit-transform: rotateY(180deg);
            transform: rotateY(180deg);
}


.flashcard-inner {
    width: 100%;
    height: 100%;
    position: relative;
    -webkit-transform-style: preserve-3d;
            transform-style: preserve-3d;
}

.flashcard-front, .flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
            backface-visibility: hidden;
    background: var(--surface);
    border-radius: 20px;
    padding: 3rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border: 2px solid var(--surface-light);
    -webkit-transform: translateZ(0);
            transform: translateZ(0);
    overflow: hidden;
    pointer-events: auto;
}

.flashcard-front::-webkit-scrollbar,
.flashcard-back::-webkit-scrollbar {
    width: 6px;
}

.flashcard-front::-webkit-scrollbar-track,
.flashcard-back::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

.flashcard-front::-webkit-scrollbar-thumb,
.flashcard-back::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 10px;
}

.flashcard-front {
    z-index: 2;
}

.flashcard-back {
    -webkit-transform: rotateY(180deg);
            transform: rotateY(180deg);
    z-index: 1;
}

.card-label {
    position: absolute;
    top: 2rem;
    left: 2rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.card-content {
    font-size: 2rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.5;
    width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    padding: 1rem;
    flex: 1;
    overflow-y: scroll;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    max-height: 100%;
    touch-action: pan-y;
    overscroll-behavior: contain;
}

.card-text {
    width: 100%;
    min-height: 100%;
}

.card-content::-webkit-scrollbar {
    width: 0px;
    background: transparent;
}

.card-content {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.btn-reveal {
    margin-top: 2rem;
    padding: 1rem 2.5rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-reveal:hover {
    transform: scale(1.05);
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.4);
}

.answer-buttons {
    display: flex;
    gap: 1.5rem;
    margin-top: 2rem;
}

.btn-wrong, .btn-correct {
    padding: 1rem 2rem;
    border: none;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 150px;
}

.btn-wrong {
    background: var(--error);
    color: white;
}

.btn-wrong:hover {
    transform: scale(1.05);
    box-shadow: 0 10px 30px rgba(239, 68, 68, 0.4);
}

.btn-correct {
    background: var(--success);
    color: white;
}

.btn-correct:hover {
    transform: scale(1.05);
    box-shadow: 0 10px 30px rgba(16, 185, 129, 0.4);
}

/* Écran de résultats */
.results-container {
    text-align: center;
    max-width: 800px;
    width: 100%;
}

.results-container h2 {
    font-size: 3rem;
    margin-bottom: 2rem;
}

.results-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2rem;
    margin-bottom: 3rem;
}

.stat-card {
    background: var(--surface);
    border-radius: 20px;
    padding: 2.5rem;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.stat-card.correct {
    border-color: var(--success);
}

.stat-card.wrong {
    border-color: var(--error);
}

.stat-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.stat-number {
    font-size: 4rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
}

.stat-card.correct .stat-number {
    color: var(--success);
}

.stat-card.wrong .stat-number {
    color: var(--error);
}

.stat-label {
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.retry-section {
    background: var(--surface);
    border-radius: 20px;
    padding: 2rem;
    margin-bottom: 2rem;
}

.retry-section h3 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
}

.retry-section p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* Responsive */
@media (max-width: 768px) {
    .app-title {
        font-size: 2.5rem;
    }
    
    .profiles-grid, .decks-grid {
        grid-template-columns: 1fr;
    }
    
    .results-stats {
        grid-template-columns: 1fr;
    }
    
    .flashcard-container {
        height: 400px;
    }
    
    .flashcard-front, .flashcard-back {
        padding: 1.5rem 1rem;
    }
    
    .card-label {
        position: static;
        margin-bottom: 0.5rem;
    }
    
    .card-content {
        font-size: 1.2rem;
        padding: 1rem;
        max-height: 250px;
        width: 100%;
        overflow-y: scroll;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }
    
    .card-content::-webkit-scrollbar {
        width: 0px;
        display: none;
    }
    
    .card-text {
        width: 100%;
        min-height: 260px;
    }
    
    .btn-reveal {
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
        margin-top: 0.5rem;
    }
    
    .answer-buttons {
        flex-direction: column;
        width: 100%;
        gap: 0.75rem;
        margin-top: 0.5rem;
        padding: 0;
    }
    
    .btn-wrong, .btn-correct {
        width: 100%;
    }
    
    .btn-reveal {
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
    }
    
    .modal-content {
        width: 98%;
        max-height: 95vh;
    }
    
    .modal-body {
        padding: 1.5rem;
    }
    
    .modal-header {
        padding: 1.5rem;
    }
    
    .modal-content h2 {
        font-size: 1.5rem;
    }
    
    .modal-tabs {
        flex-direction: column;
    }
    
    .tab-btn {
        width: 100%;
    }
    
    .input-with-icon {
        flex-direction: column;
        align-items: stretch;
    }
    
    .icon-preview {
        width: 100%;
        height: 80px;
    }
    
    .card-row {
        flex-wrap: wrap;
        padding: 1rem;
    }
    
    .card-preview {
        width: 100%;
    }
    
    .card-preview .q,
    .card-preview .a {
        overflow-wrap: break-word;
        word-break: break-word;
    }
}
