
:root {
    --bg-body: #fafaf9;
    --bg-surface: #ffffff;
    --bg-elevated: #f5f5f4;
    --bg-code: #0c0a09;
    --text-primary: #0c0a09;
    --text-secondary: #78716c;
    --text-muted: #a8a29e;
    --border-color: rgba(0,0,0,0.05);
    --glass-bg: rgba(255,255,255,0.65);
    --glass-border: rgba(255,255,255,0.25);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -2px rgba(0,0,0,0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.06), 0 4px 6px -4px rgba(0,0,0,0.04);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.05);
    --shadow-glow: 0 0 40px rgba(91,54,214,0.08);
    --gradient-primary: linear-gradient(135deg, #5b36d6, #7451eb);
    --gradient-hero: linear-gradient(135deg, #f6f7fb 0%, #f0ecfd 35%, #fafaf9 100%);
    --gradient-card-1: linear-gradient(135deg, rgba(91,54,214,0.05), rgba(245,158,11,0.04));
    --gradient-card-2: linear-gradient(135deg, rgba(244,63,94,0.05), rgba(91,54,214,0.04));
    --gradient-card-3: linear-gradient(135deg, rgba(16,185,129,0.05), rgba(6,182,212,0.04));
    --gradient-card-4: linear-gradient(135deg, rgba(245,158,11,0.05), rgba(244,63,94,0.04));
}
.dark {
    --bg-body: #0c0a09;
    --bg-surface: #1c1917;
    --bg-elevated: #292524;
    --bg-code: #0a0807;
    --text-primary: #fafaf9;
    --text-secondary: #a8a29e;
    --text-muted: #78716c;
    --border-color: rgba(255,255,255,0.05);
    --glass-bg: rgba(28,25,23,0.65);
    --glass-border: rgba(255,255,255,0.06);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.35), 0 2px 4px -2px rgba(0,0,0,0.25);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4), 0 4px 6px -4px rgba(0,0,0,0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.45), 0 8px 10px -6px rgba(0,0,0,0.35);
    --shadow-glow: 0 0 40px rgba(116,81,235,0.18);
    --gradient-hero: linear-gradient(135deg, #100e1a 0%, #1a1630 40%, #0c0a09 100%);
    --gradient-card-1: linear-gradient(135deg, rgba(116,81,235,0.15), rgba(245,158,11,0.1));
    --gradient-card-2: linear-gradient(135deg, rgba(244,63,94,0.12), rgba(116,81,235,0.1));
    --gradient-card-3: linear-gradient(135deg, rgba(16,185,129,0.12), rgba(6,182,212,0.1));
    --gradient-card-4: linear-gradient(135deg, rgba(245,158,11,0.12), rgba(244,63,94,0.1));
}

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    transition: background 0.4s ease, color 0.4s ease;
    overflow-x: hidden;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }

.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(16px) saturate(160%);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    border: 1px solid var(--glass-border);
}

.gradient-text {
    background: linear-gradient(135deg, #7451eb, #ff4081, #00c853);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.25rem;
    margin: 0.25rem 0.75rem;
    border-radius: 0.75rem;
    color: var(--text-secondary);
    transition: all 0.25s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.nav-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%) scaleY(0);
    width: 3px;
    height: 55%;
    background: var(--gradient-primary);
    border-radius: 0 3px 3px 0;
    transition: transform 0.25s ease;
}
.nav-item:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    transform: translateX(3px);
}
.nav-item.active {
    background: var(--gradient-card-1);
    color: #5b36d6;
    font-weight: 600;
}
.dark .nav-item.active { color: #9b7efb; }
.nav-item.active::before { transform: translateY(-50%) scaleY(1); }

.module-section { display: none; }
.module-section.active { display: block; }

.sub-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 0.375rem;
    background: var(--bg-elevated);
    border-radius: 0.875rem;
    border: 1px solid var(--border-color);
}
.sub-nav-btn {
    padding: 0.5rem 1rem;
    color: var(--text-secondary);
    border-radius: 0.625rem;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    white-space: nowrap;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
}
.sub-nav-btn:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}
.sub-nav-btn.active {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 4px 12px rgba(116,81,235,0.3);
}
.sub-content { display: none; }
.sub-content.active { display: block; }

.concept-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 0.875rem;
    padding: 1.25rem;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}
.concept-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2.5px;
    background: var(--gradient-primary);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}
.concept-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}
.concept-card:hover::before { transform: scaleX(1); }

.r-code {
    font-family: 'IBM Plex Mono', monospace;
    background: var(--bg-code);
    color: #e7e5e4;
    padding: 1.25rem;
    border-radius: 0.875rem;
    font-size: 0.8rem;
    line-height: 1.7;
    overflow-x: auto;
    border: 1px solid rgba(255,255,255,0.05);
    position: relative;
}
.r-code::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, #7451eb, #f43f5e, #f59e0b);
    border-radius: 0.875rem 0.875rem 0 0;
}
.r-comment { color: #78716c; font-style: italic; }
.r-func { color: #b9a0ff; font-weight: 500; }
.r-string { color: #34d399; }
.r-step-title {
    color: #fbbf24;
    font-weight: 700;
    margin: 1rem 0 0.375rem;
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
.r-step-title:first-child { margin-top: 0; }

.r-code-controls {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    gap: 0.375rem;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 10;
}
.r-code:hover .r-code-controls { opacity: 1; }
.r-code-btn {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.1);
    color: #a8a29e;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.65rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: 'Outfit', sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.r-code-btn:hover {
    background: rgba(116,81,235,0.2);
    color: #e7e5e4;
    border-color: rgba(116,81,235,0.3);
}
.r-code-btn.copied { color: #34d399; border-color: rgba(52,211,153,0.3); }

.math-box {
    background: var(--gradient-card-1);
    border: 1px solid var(--border-color);
    border-left: 3px solid #7451eb;
    padding: 1.25rem;
    border-radius: 0.875rem;
    margin: 1.25rem 0;
    overflow-x: auto;
}
.interpret-card {
    background: var(--gradient-card-3);
    border: 1px solid var(--border-color);
    border-left: 3px solid #10b981;
    padding: 1.25rem;
    border-radius: 0.875rem;
    margin: 1.25rem 0;
}
.exam-tip {
    background: var(--gradient-card-2);
    border: 1px solid var(--border-color);
    border-left: 3px solid #f59e0b;
    padding: 1.125rem 1.25rem;
    border-radius: 0.875rem;
    margin: 1rem 0;
}
.warning-box {
    background: linear-gradient(135deg, rgba(244,63,94,0.06), rgba(116,81,235,0.04));
    border: 1px solid var(--border-color);
    border-left: 3px solid #f43f5e;
    padding: 1.125rem 1.25rem;
    border-radius: 0.875rem;
    margin: 1rem 0;
}
.info-box {
    background: var(--gradient-card-1);
    border: 1px solid var(--border-color);
    border-left: 3px solid #7451eb;
    padding: 1.125rem 1.25rem;
    border-radius: 0.875rem;
    margin: 1rem 0;
}

.table-container {
    width: 100%;
    overflow-x: auto;
    margin-bottom: 1rem;
    border-radius: 0.625rem;
    border: 1px solid var(--border-color);
}
table.data-table {
    width: 100%;
    min-width: 400px;
    border-collapse: collapse;
    font-size: 0.82rem;
    background: var(--bg-surface);
}
table.data-table th, table.data-table td {
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    text-align: right;
}
table.data-table th {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-weight: 600;
    text-align: center;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
table.data-table td:first-child {
    text-align: left;
    font-weight: 600;
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.svg-responsive { width: 100%; height: auto; max-width: 280px; }

.hero-gradient { background: var(--gradient-hero); }

.floating-shape {
    position: absolute;
    border-radius: 50%;
    filter: blur(50px);
    opacity: 0.3;
    animation: float 10s ease-in-out infinite;
    will-change: transform;
}
@keyframes float {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(15px, -20px); }
}

.progress-bar {
    height: 5px;
    background: var(--bg-elevated);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #7451eb, #ff4081);
    border-radius: 3px;
    transition: width 0.4s ease;
}

.theme-toggle {
    position: relative;
    width: 48px;
    height: 26px;
    border-radius: 13px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    padding: 2px;
}
.theme-toggle:hover { box-shadow: 0 0 10px rgba(116,81,235,0.15); }
.theme-toggle-knob {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--gradient-primary);
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    color: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.dark .theme-toggle-knob { transform: translateX(22px); }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.badge-primary {
    background: rgba(91,54,214,0.08);
    color: #5b36d6;
    border: 1px solid rgba(91,54,214,0.18);
}
.dark .badge-primary { color: #9b7efb; background: rgba(155,126,251,0.12); border-color: rgba(155,126,251,0.2); }

.mobile-menu-btn {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    transition: all 0.2s ease;
}
.mobile-menu-btn:hover {
    background: var(--bg-surface);
    box-shadow: var(--shadow-md);
}

.section-title-decoration {
    display: inline-block;
    width: 32px;
    height: 3px;
    background: var(--gradient-primary);
    border-radius: 2px;
    margin-bottom: 0.75rem;
}

.step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--gradient-primary);
    color: white;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
}

/* R Editor */
.r-editor-container {
    border: 1px solid var(--border-color);
    border-radius: 0.875rem;
    overflow: hidden;
    background: var(--bg-surface);
}
.r-editor-header {
    background: var(--bg-elevated);
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.r-editor-textarea {
    flex: 1;
    min-height: 180px;
    max-height: 400px;
    background: var(--bg-code);
    color: #e7e5e4;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.82rem;
    line-height: 1.7;
    padding: 1rem;
    border: none;
    resize: vertical;
    outline: none;
    overflow: auto;
}
.r-editor-textarea::placeholder { color: #57534e; }
.r-editor-wrapper {
    display: flex;
    position: relative;
    background: var(--bg-code);
}
.r-line-numbers {
    background: rgba(0,0,0,0.25);
    color: #57534e;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.82rem;
    line-height: 1.7;
    padding: 1rem 0.5rem 1rem 0.75rem;
    text-align: right;
    user-select: none;
    overflow: hidden;
    white-space: pre;
    min-width: 2rem;
    border-right: 1px solid rgba(255,255,255,0.05);
}
.r-output {
    background: var(--bg-code);
    color: #d6d3d1;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    line-height: 1.6;
    padding: 1rem;
    min-height: 80px;
    max-height: 300px;
    overflow-y: auto;
    border-top: 1px solid rgba(255,255,255,0.05);
    white-space: pre-wrap;
}
.r-output:empty::before {
    content: '# La sortie apparaîtra ici...';
    color: #57534e;
    font-style: italic;
}
.r-plot-img {
    display: block;
    max-width: 100%;
    height: auto;
    margin-top: 0.75rem;
    border-radius: 0.5rem;
    background: #ffffff;
    cursor: zoom-in;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.r-plot-img:hover {
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
}

/* Lightbox / Fullscreen modal */
.plot-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0,0,0,0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
.plot-lightbox.active {
    opacity: 1;
    pointer-events: auto;
}
.plot-lightbox-viewport {
    width: 90vw;
    height: 80vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    border-radius: 0.5rem;
}
.plot-lightbox-viewport:active {
    cursor: grabbing;
}
.plot-lightbox-viewport img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 0.5rem;
    background: #fff;
    transition: transform 0.15s ease-out;
    transform-origin: center center;
    user-select: none;
    -webkit-user-drag: none;
}
.plot-lightbox-toolbar {
    position: absolute;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.5rem;
    align-items: center;
    background: rgba(28,25,23,0.8);
    backdrop-filter: blur(8px);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.1);
}
.plot-lightbox-btn {
    background: transparent;
    border: none;
    color: #e7e5e4;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0.35rem 0.75rem;
    border-radius: 0.375rem;
    transition: background 0.15s ease;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
}
.plot-lightbox-btn:hover {
    background: rgba(255,255,255,0.1);
}
.plot-lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(28,25,23,0.8);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,0.1);
    color: #e7e5e4;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}
.plot-lightbox-close:hover {
    background: rgba(255,255,255,0.15);
}

.r-run-btn {
    background: var(--gradient-primary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
}
.r-run-btn:hover {
    box-shadow: 0 4px 12px rgba(116,81,235,0.3);
    transform: translateY(-1px);
}
.r-run-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}
.r-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Animation performance */
.will-animate { will-change: transform, opacity; }

/* Particle canvas */
#particles-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.25;
}

