/* Variables de couleur */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #ec4899;
    --accent: #f59e0b;
    --success: #10b981;
    --error: #ef4444;
    --bg: #f8fafc;
    --bg-secondary: #f1f5f9;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

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

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    color: var(--text);
    background-color: var(--bg);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 60px 20px;
    text-align: center;
    margin-bottom: 40px;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 0.95em;
    background: rgba(255, 255, 255, 0.15);
    padding: 10px 15px;
    border-radius: 8px;
    min-height: 40px;
}

.logo {
    font-size: 3em;
    font-weight: 800;
    margin-bottom: 10px;
    letter-spacing: -1px;
}

.tagline {
    font-size: 1.2em;
    opacity: 0.9;
    font-weight: 300;
}

.header-secondary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 20px;
    margin-bottom: 30px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

.header-secondary h1 {
    font-size: 1.8em;
    margin-top: 10px;
}

/* Pages */
.page {
    display: none;
}

.page.active {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

#chapter-detail main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Accueil */
.welcome {
    text-align: center;
    margin-bottom: 50px;
}

.welcome h2 {
    font-size: 2.5em;
    margin-bottom: 15px;
    color: var(--primary);
}

.welcome p {
    font-size: 1.1em;
    color: var(--text-light);
}

/* Grille des niveaux */
.levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
    margin-top: 40px;
}

.level-card {
    background: white;
    border-radius: 12px;
    padding: 30px;
    text-align: center;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    cursor: pointer;
}

.level-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
    border: 2px solid var(--primary);
}

.level-card h3 {
    font-size: 1.5em;
    margin-bottom: 10px;
    color: var(--primary);
}

.level-card p {
    color: var(--text-light);
    margin-bottom: 20px;
}

/* Styles pour drag & drop des niveaux */
.level-card[draggable="true"] {
    user-select: none;
}

.level-card[draggable="true"]:hover {
    cursor: grab;
}

.level-card[draggable="true"]:active {
    cursor: grabbing;
}

/* Grille des chapitres */
.chapters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 30px;
}

.chapter-card {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    cursor: pointer;
}

.chapter-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.chapter-card h3 {
    color: var(--primary);
    margin-bottom: 10px;
}

.chapter-card p {
    color: var(--text-light);
    font-size: 0.9em;
    margin-bottom: 15px;
}

.chapter-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85em;
    color: var(--text-light);
    padding-top: 15px;
    border-top: 1px solid var(--border);
}

.chapter-meta span {
    display: flex;
    align-items: center;
    gap: 5px;
}

.progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 10px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), var(--primary));
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* Boutons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-success {
    background: #27ae60;
    color: white;
}

.btn-success:hover {
    background: #229954;
    transform: translateY(-2px);
}

.btn-warning {
    background: #f39c12;
    color: white;
}

.btn-warning:hover {
    background: #e67e22;
    transform: translateY(-2px);
}

.btn-info {
    background: #3498db;
    color: white;
}

.btn-info:hover {
    background: #2980b9;
    transform: translateY(-2px);
}

.btn-danger {
    background: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background: #c0392b;
    transform: translateY(-2px);
}

.btn-back {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s ease;
}

.btn-back:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Markdown Lists */
.markdown-list {
    margin: 15px 0;
    padding-left: 30px;
    list-style-type: disc;
}

.markdown-list li {
    margin: 5px 0;
    line-height: 1.6;
}

/* Onglets */
.chapter-nav {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--border);
    flex-wrap: wrap;
}

.tab-btn {
    padding: 12px 20px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 1em;
    color: var(--text-light);
    transition: all 0.3s ease;
    font-weight: 600;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn:hover {
    color: var(--primary);
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
    flex: 1;
}

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

/* Fiches */
.fiches-list {
    display: grid;
    gap: 15px;
}

.fiche {
    background: white;
    border-left: 4px solid var(--primary);
    padding: 20px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.3s ease;
}

.fiche:hover {
    box-shadow: var(--shadow-lg);
    transform: translateX(5px);
}

.fiche h4 {
    color: var(--primary);
    margin-bottom: 10px;
}

.fiche p {
    color: var(--text-light);
    margin-bottom: 10px;
}

.fiche-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
}

/* Quizz */
.quizz-container {
    background: white;
    border-radius: 10px;
    padding: 30px;
    box-shadow: var(--shadow);
}

.question {
    margin-bottom: 25px;
}

.question-number {
    color: var(--primary);
    font-weight: 700;
}

.question-text {
    font-size: 1.1em;
    font-weight: 600;
    margin: 15px 0;
    color: var(--text);
}

.answers {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.answer-btn {
    padding: 15px;
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    transition: all 0.3s ease;
    font-weight: 500;
}

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

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

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

.answer-btn.incorrect {
    border-color: var(--error);
    background: var(--error);
    color: white;
}

.quizz-progress {
    background: var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 30px;
    text-align: center;
}

.quizz-progress p {
    margin-bottom: 10px;
    color: var(--text-light);
}

.quizz-score {
    font-size: 2em;
    color: var(--primary);
    font-weight: 700;
}

/* Flashcards */
.flashcards-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    padding: 20px;
    box-sizing: border-box;
    justify-content: space-between;
}

.flashcard {
    background: white;
    border-radius: 10px;
    padding: 30px;
    box-shadow: var(--shadow);
    cursor: pointer;
    height: 100%;
    min-height: 300px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    transition: transform 0.6s ease;
    transform-style: preserve-3d;
    position: relative;
    transform: rotateY(0deg);
    width: 100%;
}

.flashcard.flipped {
    transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 30px;
    box-sizing: border-box;
    border-radius: 10px;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.flashcard-front {
    background: white;
    color: var(--primary);
    font-size: 1.3em;
    font-weight: 600;
    transform: rotateY(0deg);
    z-index: 2;
    word-wrap: break-word;
    white-space: normal;
}

.flashcard-back {
    background: var(--primary);
    color: white;
    font-size: 1.1em;
    line-height: 1.8;
    transform: rotateY(180deg);
    z-index: 1;
    word-wrap: break-word;
    white-space: normal;
}

.flashcard-hint {
    font-size: 0.85em;
    color: var(--text-light);
    margin-top: 10px;
    opacity: 0.7;
}

.flashcard.flipped .flashcard-hint {
    color: rgba(255, 255, 255, 0.6);
}

.flashcard-controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
}

.flashcard-btn {
    padding: 10px 20px;
    background: var(--bg-secondary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.flashcard-btn:hover {
    background: var(--border);
}

.flashcard-counter {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 20px;
    font-weight: 600;
}

/* Statistiques */
.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.stat-card {
    background: white;
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-value {
    font-size: 2.5em;
    font-weight: 700;
    color: var(--primary);
    margin: 10px 0;
}

.stat-label {
    color: var(--text-light);
    font-weight: 600;
}

.stat-card.success .stat-value {
    color: var(--success);
}

.stat-card.warning .stat-value {
    color: var(--accent);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 30px;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: var(--text-light);
}

.modal-body {
    color: var(--text);
}

.modal h2 {
    font-size: 1.5em;
    color: var(--primary);
    margin: 0;
}

/* Authentification */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 300px);
    padding: 40px 20px;
}

.auth-box {
    background: white;
    border-radius: 12px;
    padding: 40px;
    max-width: 450px;
    width: 100%;
    box-shadow: var(--shadow-lg);
}

.auth-box h2 {
    color: var(--primary);
    margin-bottom: 10px;
    font-size: 1.8em;
}

.auth-box p {
    color: var(--text-light);
    margin-bottom: 30px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text);
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1em;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.password-input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.password-input-group input {
    width: 100%;
    padding-right: 45px;
}

.toggle-password {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2em;
    padding: 5px 8px;
    color: var(--text-light);
    transition: color 0.2s ease;
}

.toggle-password:hover {
    color: var(--primary);
}

/* Responsive */
@media (max-width: 768px) {
    .logo {
        font-size: 2em;
    }

    .tagline {
        font-size: 1em;
    }

    .levels-grid {
        grid-template-columns: 1fr;
    }

    .chapters-grid {
        grid-template-columns: 1fr;
    }

    .chapter-nav {
        overflow-x: auto;
        gap: 5px;
    }

    .tab-btn {
        padding: 10px 15px;
        font-size: 0.9em;
    }

    .stats-container {
        grid-template-columns: 1fr;
    }

    .welcome h2 {
        font-size: 1.8em;
    }
}
