/* =========================================================================
   AlgoMaze — Design System
   Vanilla CSS avec variables thème clair / sombre.
   ========================================================================= */

/* ---------- Reset moderne ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    min-height: 100vh;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.2s ease, color 0.2s ease;
}
img { max-width: 100%; height: auto; display: block; }
button { font-family: inherit; font-size: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
h1, h2, h3, h4, h5, h6 { margin: 0 0 0.5em; line-height: 1.3; font-weight: 600; }
p, ul, ol { margin: 0 0 0.75em; }
ul, ol { padding-left: 1.25em; }
li { margin: 0.2em 0; }

/* ---------- Variables : thème clair (défaut) ---------- */
:root {
    --bg: #F9FAFB;
    --bg-elevated: #FFFFFF;
    --surface: #FFFFFF;
    --surface-hover: #F3F4F6;
    --surface-muted: #F9FAFB;
    --border: #E5E7EB;
    --border-strong: #D1D5DB;
    --text: #111827;
    --text-muted: #6B7280;
    --text-subtle: #9CA3AF;

    --primary: #6366F1;
    --primary-hover: #4F46E5;
    --primary-active: #4338CA;
    --primary-soft: #EEF2FF;
    --primary-fg: #FFFFFF;

    --success: #10B981;
    --success-soft: #D1FAE5;
    --danger: #EF4444;
    --danger-soft: #FEE2E2;
    --warning: #F59E0B;
    --warning-soft: #FEF3C7;
    --accent: #06B6D4;

    --canvas-bg: #1F2937;

    --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.05);
    --shadow: 0 4px 12px rgba(17, 24, 39, 0.07);
    --shadow-lg: 0 12px 32px rgba(17, 24, 39, 0.12);
    --shadow-glow: 0 0 0 4px rgba(99, 102, 241, 0.15);

    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 16px;
    --r-full: 9999px;

    --header-h: 60px;
    --container-max: 1280px;
}

/* ---------- Variables : thème sombre ---------- */
[data-theme="dark"] {
    --bg: #0F172A;
    --bg-elevated: #1E293B;
    --surface: #1E293B;
    --surface-hover: #334155;
    --surface-muted: #172033;
    --border: #334155;
    --border-strong: #475569;
    --text: #F1F5F9;
    --text-muted: #94A3B8;
    --text-subtle: #64748B;

    --primary: #818CF8;
    --primary-hover: #A5B4FC;
    --primary-active: #C7D2FE;
    --primary-soft: rgba(129, 140, 248, 0.15);
    --primary-fg: #0F172A;

    --success: #34D399;
    --success-soft: rgba(52, 211, 153, 0.15);
    --danger: #F87171;
    --danger-soft: rgba(248, 113, 113, 0.15);
    --warning: #FBBF24;
    --warning-soft: rgba(251, 191, 36, 0.15);
    --accent: #22D3EE;

    --canvas-bg: #0B1120;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
    --shadow-glow: 0 0 0 4px rgba(129, 140, 248, 0.25);
}

/* ---------- Liens ---------- */
a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.15s ease;
}
a:hover { color: var(--primary-hover); text-decoration: underline; }

/* ---------- App shell : en-tête commun ---------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--header-h);
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    backdrop-filter: saturate(180%) blur(10px);
}
.app-header-inner {
    max-width: var(--container-max);
    margin: 0 auto;
    height: 100%;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 24px;
}
.app-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text);
    letter-spacing: -0.01em;
    flex-shrink: 0;
}
.app-brand:hover { color: var(--text); text-decoration: none; }
.app-brand-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--r-md);
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.1rem;
    box-shadow: var(--shadow-sm);
}
.app-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
}
.app-nav-link {
    padding: 7px 14px;
    border-radius: var(--r-md);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.92rem;
    transition: background 0.15s ease, color 0.15s ease;
}
.app-nav-link:hover {
    background: var(--surface-hover);
    color: var(--text);
    text-decoration: none;
}
.app-nav-link.active {
    background: var(--primary-soft);
    color: var(--primary);
}
.app-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
    flex-shrink: 0;
}

/* Toggle thème */
.theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: background 0.15s ease, transform 0.15s ease;
}
.theme-toggle:hover {
    background: var(--surface-hover);
    transform: rotate(15deg);
}

/* Hamburger mobile */
.app-nav-toggle {
    display: none;
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

/* ---------- Layout principal ---------- */
.app-main {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 24px;
}
.page-title {
    font-size: 1.6rem;
    font-weight: 700;
    margin: 0 0 6px;
    letter-spacing: -0.02em;
}
.page-subtitle {
    color: var(--text-muted);
    margin: 0 0 24px;
}

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    padding: 20px;
}
.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 12px;
}

/* ---------- Boutons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    font-weight: 500;
    font-size: 0.95rem;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
    text-decoration: none;
    line-height: 1.2;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--shadow-glow); }
.btn:disabled, .btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

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

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

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn-success {
    background: var(--success);
    color: #fff;
}
.btn-success:hover { background: var(--success); filter: brightness(0.92); color: #fff; }

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover { background: var(--danger); filter: brightness(0.92); color: #fff; }

.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-block { width: 100%; }

/* ---------- Inputs ---------- */
.input,
input[type="text"]:not(.cm-input):not(.ql-editor input),
input[type="password"],
input[type="email"],
input[type="number"],
textarea:not(.ql-editor textarea),
select {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--text);
    font-size: 0.95rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus,
input[type="text"]:not(.cm-input):not(.ql-editor input):focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
textarea:not(.ql-editor textarea):focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
}
.input-group {
    margin-bottom: 14px;
}
.input-group label, .label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.input-help {
    font-size: 0.82rem;
    color: var(--text-subtle);
    margin-top: 4px;
}

/* ---------- Auth pages (login / register) ---------- */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(ellipse at top left, var(--primary-soft) 0%, transparent 50%),
        radial-gradient(ellipse at bottom right, rgba(6, 182, 212, 0.15) 0%, transparent 50%),
        var(--bg);
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    padding: 36px 32px;
    max-width: 400px;
    width: 100%;
}
.auth-card .app-brand-icon { width: 48px; height: 48px; margin: 0 auto 16px; font-size: 1.5rem; }
.auth-card h1 {
    font-size: 1.4rem;
    text-align: center;
    margin: 0 0 4px;
}
.auth-card .auth-subtitle {
    text-align: center;
    color: var(--text-muted);
    margin: 0 0 24px;
    font-size: 0.92rem;
}
.auth-card .links {
    text-align: center;
    margin-top: 18px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ---------- Tableaux ---------- */
.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface);
}
table.data-table {
    width: 100%;
    border-collapse: collapse;
}
table.data-table th, table.data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
}
table.data-table th {
    background: var(--surface-muted);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover { background: var(--surface-hover); }

/* ---------- Game layout ---------- */
.game-layout {
    display: grid;
    grid-template-columns: 220px 1fr 1fr;
    gap: 20px;
    align-items: start;
}
.game-sidebar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px;
    position: sticky;
    top: calc(var(--header-h) + 16px);
}
.game-sidebar h2 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin: 0 0 12px;
}
.game-main-column {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}
.game-canvas-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 12px;
    box-shadow: var(--shadow-sm);
}
.game-side {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

canvas#maze {
    background: var(--canvas-bg);
    border-radius: var(--r-md);
    width: 100%;
    height: auto;
    display: block;
}

/* Liste des niveaux */
.level-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 65vh;
    overflow-y: auto;
}
.level-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    margin: 2px 0;
    border-radius: var(--r-sm);
    cursor: pointer;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.92rem;
    transition: background 0.15s ease, color 0.15s ease;
    border-bottom: none;
}
.level-list li .level-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
/* Variante compacte du badge dans la liste des niveaux : plus petit pour tenir dans la sidebar. */
.level-list li .badge {
    flex-shrink: 0;
    font-size: 0.68rem;
    padding: 1px 8px;
    letter-spacing: 0;
    border-width: 1px;
}
.level-list li:hover {
    background: var(--surface-hover);
    color: var(--text);
}
.level-list li.highlight {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
}

/* Consigne */
.consigne-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px;
    max-height: 280px;
    overflow-y: auto;
}
.consigne-container h2, .game-section-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin: 0 0 10px;
}
.consigne-container p, .consigne-container li {
    color: var(--text);
}

/* Code editor */
.code-editor-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px;
}
.CodeMirror {
    height: 380px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    font-family: 'JetBrains Mono', 'Fira Code', Consolas, Monaco, monospace !important;
    font-size: 0.9rem;
}
[data-theme="dark"] .CodeMirror {
    background: #0B1120;
    color: #E2E8F0;
}
[data-theme="dark"] .CodeMirror-gutters {
    background: #0B1120;
    border-right: 1px solid var(--border);
}
[data-theme="dark"] .CodeMirror-linenumber { color: var(--text-subtle); }
[data-theme="dark"] .CodeMirror-cursor { border-left-color: #fff; }

/* Boutons d'action sous l'éditeur */
.editor-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}
.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
.icon-btn:hover {
    background: var(--surface-hover);
    border-color: var(--border-strong);
}
.icon-btn:active { transform: translateY(1px); }
.icon-btn.disabled, .icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}
/* Boutons de contrôle d'exécution (pause / step / stop) — SVG inline, themeable */
.icon-btn.exec-ctrl {
    color: var(--text);
    padding: 0;
}
.icon-btn.exec-ctrl svg { display: block; }
.icon-btn.exec-ctrl:disabled,
.icon-btn.exec-ctrl.disabled {
    opacity: 0.35;
    color: var(--text-muted);
    cursor: not-allowed;
}
/* Override l'opacité globale de icon-btn pour qu'on voie quand même les boutons inactifs. */
.icon-btn.exec-ctrl.disabled,
.icon-btn.exec-ctrl:disabled { pointer-events: none; }

/* Slider de vitesse */
.speed-control {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: 4px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
    font-size: 0.82rem;
    color: var(--text-muted);
}
.speed-control input[type="range"] {
    width: 100px;
    accent-color: var(--primary);
    margin: 0;
}
.speed-control .speed-label { user-select: none; }
.speed-control #speed-value {
    font-weight: 600;
    color: var(--text);
    min-width: 30px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Barre de progression du scrub d'exécution */
.exec-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
}
.exec-progress.disabled { opacity: 0.5; }
.exec-progress input[type="range"] {
    flex: 1;
    accent-color: var(--primary);
    margin: 0;
}
.exec-step-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    min-width: 70px;
}

/* Ligne en cours d'exécution dans CodeMirror */
.CodeMirror .cm-exec-line {
    background-color: rgba(99, 102, 241, 0.18) !important;
}
.CodeMirror .cm-exec-gutter {
    background-color: rgba(99, 102, 241, 0.35) !important;
}
[data-theme="dark"] .CodeMirror .cm-exec-line {
    background-color: rgba(129, 140, 248, 0.22) !important;
}
[data-theme="dark"] .CodeMirror .cm-exec-gutter {
    background-color: rgba(129, 140, 248, 0.45) !important;
}
.icon-btn img {
    width: 22px;
    height: 22px;
}
[data-theme="dark"] .icon-btn img {
    filter: invert(1) brightness(1.4);
}

/* Quick command pills */
.command-buttons {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}
.command-buttons h2 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin: 0 0 8px;
}
.command-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.command-pills button {
    background: var(--primary-soft);
    color: var(--primary);
    border: 1px solid transparent;
    padding: 5px 12px;
    border-radius: var(--r-full);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.15s ease;
}
.command-pills button:hover { background: var(--primary); color: var(--primary-fg); }

/* Bouton next-level */
#next-level-button {
    display: none;
    margin-left: auto;
    padding: 10px 18px;
    background: var(--success);
    color: #fff;
    border: none;
    border-radius: var(--r-md);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: filter 0.15s ease, transform 0.05s ease;
}
#next-level-button:hover { filter: brightness(0.92); }
#next-level-button:active { transform: translateY(1px); }
#next-level-button.visible { display: inline-flex; align-items: center; gap: 6px; }

/* Vieille classe gardée pour compat — alias vers icon-btn */
.command-buttons-img {
    width: 40px;
    height: 40px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--surface);
    padding: 8px;
    cursor: pointer;
    margin-right: 6px;
    transition: background 0.15s ease;
}
.command-buttons-img:hover { background: var(--surface-hover); }
.command-buttons-img.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}
[data-theme="dark"] .command-buttons-img { filter: invert(1) brightness(1.2); }

/* ---------- Feedback IA ---------- */
#feedback-container {
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}
#feedback-container.visible { display: block; }
#feedback-container h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin: 0 0 12px;
}
.feedback-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.feedback-score {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}
.feedback-badge {
    padding: 4px 12px;
    border-radius: var(--r-full);
    font-size: 0.8rem;
    font-weight: 500;
    color: #fff;
}
.feedback-badge.ok { background: var(--success); }
.feedback-badge.ko { background: var(--danger); }
.feedback-badge.pending {
    background: var(--surface-hover);
    color: var(--text-muted);
}
.feedback-text {
    margin: 10px 0;
    color: var(--text);
    line-height: 1.6;
}
.feedback-criteria { margin-top: 12px; }
.feedback-criteria summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.88rem;
    padding: 6px 0;
    user-select: none;
}
.feedback-criteria summary:hover { color: var(--text); }
.feedback-criterion {
    padding: 10px 14px;
    margin: 6px 0;
    border-left: 3px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface-muted);
}
.feedback-criterion.met { border-left-color: var(--success); }
.feedback-criterion.unmet { border-left-color: var(--danger); }
.feedback-criterion-name { font-weight: 600; margin-bottom: 4px; }
.feedback-error { color: var(--danger); }

/* ---------- Badges (gaming) ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 12px;
    border-radius: var(--r-full);
    font-weight: 600;
    font-size: 0.82rem;
    color: #fff;
    text-shadow: 0 1px 1px rgba(0,0,0,0.25);
    border: 2px solid rgba(255,255,255,0.15);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    letter-spacing: 0.02em;
}
.badge.Fer      { background: linear-gradient(135deg, #6b6b6b, #4a4a4a); }
.badge.Bronze   { background: linear-gradient(135deg, #cd7f32, #a0612a); }
.badge.Argent   { background: linear-gradient(135deg, #d8d8d8, #a8a8a8); color: #222; text-shadow: none; }
.badge.Or       { background: linear-gradient(135deg, #f4d35e, #d4af37); color: #3a2a00; text-shadow: none; }
.badge.Platine  { background: linear-gradient(135deg, #5dd9c8, #2bbbad); }

/* Pill d'avancement (Niv X/42) — visuellement neutre pour ne pas voler la vedette à la maîtrise */
.player-progress {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-hover);
    color: var(--text);
    padding: 5px 12px;
    border-radius: var(--r-full);
    font-size: 0.82rem;
    font-weight: 500;
    border: 1px solid var(--border);
    white-space: nowrap;
}
.player-progress b { font-weight: 700; }

/* Barre de progression linéaire — utilisée dans la vue admin */
.progress-bar {
    width: 120px;
    height: 6px;
    background: var(--surface-hover);
    border-radius: var(--r-full);
    overflow: hidden;
    display: inline-block;
    vertical-align: middle;
    margin-left: 8px;
}
.progress-bar-fill {
    display: block;
    height: 100%;
    background: var(--primary);
    border-radius: var(--r-full);
    transition: width 0.3s ease;
}

/* Pastille de maîtrise (compétence globale) */
.mastery-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 4px 12px;
    border-radius: var(--r-full);
    font-size: 0.82rem;
    font-weight: 600;
    border: 1px solid transparent;
    line-height: 1.2;
    white-space: nowrap;
}
.mastery-badge::before {
    content: '';
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);
}
[data-theme="dark"] .mastery-badge::before {
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.4);
}
.mastery-badge.red {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: rgba(239, 68, 68, 0.25);
}
.mastery-badge.amber {
    color: var(--warning);
    background: var(--warning-soft);
    border-color: rgba(245, 158, 11, 0.25);
}
.mastery-badge.blue {
    color: var(--primary);
    background: var(--primary-soft);
    border-color: rgba(99, 102, 241, 0.25);
}
.mastery-badge.green {
    color: var(--success);
    background: var(--success-soft);
    border-color: rgba(16, 185, 129, 0.25);
}

/* Rang global dans le header */
.player-rank {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--primary-soft);
    color: var(--primary);
    padding: 5px 12px;
    border-radius: var(--r-full);
    font-size: 0.82rem;
    font-weight: 500;
}
.player-rank b { font-weight: 700; }

/* ---------- Footer privacy (discret, en pied de page) ---------- */
.app-footer {
    max-width: var(--container-max);
    margin: 32px auto 16px;
    padding: 0 24px;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-subtle);
    line-height: 1.5;
}
.app-footer a {
    color: var(--text-muted);
    text-decoration: underline;
}

/* ---------- Page Documentation des fonctions ---------- */
.docs-section { margin-bottom: 32px; }
.docs-section-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0 0 14px;
    color: var(--text);
    letter-spacing: -0.01em;
}
.docs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}
.docs-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    transition: border-color 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
}
.docs-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow);
}
.docs-sig {
    font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
    font-size: 1.02rem;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: -0.01em;
}
.docs-sig .docs-paren { color: var(--text-muted); font-weight: 400; }
.docs-return {
    align-self: flex-start;
    padding: 2px 10px;
    border-radius: var(--r-full);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.docs-return.bool {
    background: var(--success-soft);
    color: var(--success);
}
.docs-return.void {
    background: var(--primary-soft);
    color: var(--primary);
}
.docs-desc {
    margin: 0;
    color: var(--text);
    font-size: 0.92rem;
    line-height: 1.55;
}
.docs-desc code {
    background: var(--surface-hover);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.86em;
    color: var(--text);
}
.docs-tip-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
}
.docs-section-intro {
    margin: -4px 0 16px;
    color: var(--text-muted);
    font-size: 0.93rem;
    line-height: 1.6;
    max-width: 72ch;
}
.docs-badges {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.docs-badge-card {
    gap: 10px;
}
.docs-badge-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.docs-badge-xp {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}
.rank-pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 12px;
    border-radius: var(--r-full);
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border: 1.5px solid transparent;
}
.rank-pill.rank-legende  { background: linear-gradient(135deg, #a78bfa, #7c3aed); color: #fff; }
.rank-pill.rank-maitre   { background: linear-gradient(135deg, #f472b6, #db2777); color: #fff; }
.rank-pill.rank-expert   { background: linear-gradient(135deg, #5dd9c8, #2bbbad); color: #fff; }
.rank-pill.rank-initie   { background: var(--primary-soft); color: var(--primary); border-color: rgba(99,102,241,0.3); }
.rank-pill.rank-apprenti { background: var(--surface-hover); color: var(--text-muted); border-color: var(--border); }
.docs-mastery-formula {
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 10px 16px;
    margin: 0 0 16px;
    display: inline-block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.88rem;
    color: var(--primary);
}

/* ---------- Live dashboard (vue temps réel enseignant) ---------- */
.live-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-bottom: 20px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
}
.live-stats {
    display: flex;
    gap: 16px;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.live-stats b { color: var(--text); }
.live-filter-pills {
    display: flex;
    gap: 4px;
    margin-left: auto;
    flex-wrap: wrap;
}
.live-filter-pills button {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    padding: 5px 12px;
    border-radius: var(--r-full);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.live-filter-pills button:hover { color: var(--text); }
.live-filter-pills button.active {
    background: var(--primary-soft);
    color: var(--primary);
    border-color: var(--primary);
}

.live-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.live-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    border-radius: var(--r-lg);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: border-left-color 0.2s ease, transform 0.08s ease, box-shadow 0.15s ease;
}
.live-card:hover {
    box-shadow: var(--shadow);
}
.live-card.status-active  { border-left-color: var(--success); }
.live-card.status-idle    { border-left-color: var(--warning); }
.live-card.status-stuck   { border-left-color: var(--danger); }
.live-card.status-offline { border-left-color: var(--border); opacity: 0.55; }

.live-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
}
.live-card-username {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.live-card-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px var(--surface);
}
.live-card-dot.active  { background: var(--success); animation: live-pulse 2s ease-in-out infinite; }
.live-card-dot.idle    { background: var(--warning); }
.live-card-dot.stuck   { background: var(--danger); }
.live-card-dot.offline { background: var(--text-subtle); }
@keyframes live-pulse {
    0%, 100% { box-shadow: 0 0 0 2px var(--surface), 0 0 0 0 rgba(16, 185, 129, 0.5); }
    50%      { box-shadow: 0 0 0 2px var(--surface), 0 0 0 6px rgba(16, 185, 129, 0); }
}

.live-card-level {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    line-height: 1;
}
.live-card-level .label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-right: 6px;
}
.live-card-meta {
    font-size: 0.82rem;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
}

.live-card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.live-flag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--r-full);
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--danger-soft);
    color: var(--danger);
}
.live-flag.warn { background: var(--warning-soft); color: var(--warning); }
.live-flag.info { background: var(--primary-soft); color: var(--primary); }

.live-card-actions {
    margin-top: 6px;
    display: flex;
    gap: 6px;
}
.live-card-actions a {
    font-size: 0.82rem;
    color: var(--text-muted);
    text-decoration: none;
    border: 1px solid var(--border);
    padding: 4px 10px;
    border-radius: var(--r-md);
    transition: background 0.15s ease, color 0.15s ease;
}
.live-card-actions a:hover {
    background: var(--surface-hover);
    color: var(--text);
    text-decoration: none;
}

.live-empty {
    grid-column: 1 / -1;
}

/* ---------- Tutoriel interactif (overlay + spotlight + popup) ---------- */
.tutorial-overlay {
    position: fixed;
    inset: 0;
    z-index: 1500;
    /* L'overlay lui-même est transparent : c'est le spotlight qui projette l'ombre. */
}
/* Spotlight : un rectangle transparent qui projette une énorme ombre alentour
   pour assombrir tout sauf la zone surlignée. */
.tutorial-spotlight {
    position: fixed;
    border-radius: 10px;
    box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.72);
    pointer-events: none;
    transition: top 0.25s ease, left 0.25s ease, width 0.25s ease, height 0.25s ease;
    outline: 2px solid rgba(99, 102, 241, 0.7);
    outline-offset: -2px;
}
.tutorial-popup {
    position: fixed;
    width: 420px;
    max-width: calc(100vw - 32px);
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    padding: 18px 20px;
    z-index: 1600;
    animation: tutorial-pop 0.22s ease-out;
}
@keyframes tutorial-pop {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.tutorial-popup-step {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
}
.tutorial-popup-title {
    margin: 0 0 8px;
    font-size: 1.1rem;
    line-height: 1.3;
}
.tutorial-popup-body {
    font-size: 0.92rem;
    line-height: 1.5;
    color: var(--text);
    margin-bottom: 14px;
}
.tutorial-popup-body code {
    background: var(--surface-hover);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
}
.tutorial-popup-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Bouton flottant "?" pour relancer le tutoriel */
.tutorial-help-btn {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    cursor: pointer;
    font-size: 1.3rem;
    font-weight: 600;
    z-index: 100;
    transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.tutorial-help-btn:hover {
    background: var(--primary-soft);
    color: var(--primary);
    transform: scale(1.08);
}

@media (max-width: 768px) {
    .tutorial-popup { width: calc(100vw - 24px); padding: 14px 16px; }
    .tutorial-help-btn { width: 38px; height: 38px; font-size: 1.1rem; bottom: 14px; left: 14px; }
}

/* ---------- Notifications ---------- */
#notification-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
    max-width: calc(100vw - 40px);
}
.notification {
    padding: 12px 18px;
    color: #fff;
    border-radius: var(--r-md);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateX(100%);
    animation: slideIn 0.4s forwards, fadeOut 0.4s 2.5s forwards;
    font-size: 0.92rem;
    font-weight: 500;
    max-width: 360px;
}
.notification.success { background: var(--success); }
.notification.error { background: var(--danger); }
.notification.info { background: var(--primary); color: var(--primary-fg); }
@keyframes slideIn { to { opacity: 1; transform: translateX(0); } }
@keyframes fadeOut { to { opacity: 0; transform: translateX(100%); } }

/* ---------- Solutions admin ---------- */
.solutions-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-bottom: 24px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
}
.solutions-controls .control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}
.solutions-controls .label { margin: 0; }
.solutions-controls input[type="radio"] { margin: 0; accent-color: var(--primary); }
.solutions-controls select {
    width: auto;
    min-width: 200px;
}
.solution-entry {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}
.solution-entry h3 {
    font-size: 1rem;
    margin: 0 0 12px;
    color: var(--text);
}
.solution-entry pre {
    background: #0F172A;
    color: #E2E8F0;
    padding: 14px;
    border-radius: var(--r-md);
    overflow-x: auto;
    font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    white-space: pre-wrap;
    margin: 0 0 10px;
}
.solution-entry details { margin-top: 10px; }
.solution-entry details summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.88rem;
    padding: 4px 0;
    user-select: none;
}
.solution-entry details summary:hover { color: var(--text); }

.history-entry {
    border-left: 3px solid var(--border);
    padding: 8px 14px;
    margin: 6px 0 6px 4px;
    background: var(--surface-muted);
    border-radius: var(--r-sm);
}
.history-entry.valid { border-left-color: var(--success); }
.history-entry.invalid { border-left-color: var(--danger); }
.history-meta {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.feedback-block {
    margin-top: 10px;
    padding: 12px 14px;
    background: var(--surface-muted);
    border-left: 4px solid var(--primary);
    border-radius: var(--r-md);
}
.feedback-block.error { border-left-color: var(--danger); }
.feedback-block.pending { border-left-color: var(--warning); }
.fb-header { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.fb-score { font-weight: 700; font-size: 1.2rem; }
.fb-badge {
    padding: 3px 10px;
    border-radius: var(--r-full);
    font-size: 0.78rem;
    color: #fff;
    font-weight: 500;
}
.fb-badge.ok { background: var(--success); }
.fb-badge.ko { background: var(--danger); }
.fb-badge.pending { background: var(--text-subtle); }
.fb-text { color: var(--text); margin: 6px 0; line-height: 1.5; }
.fb-criterion {
    padding: 6px 10px;
    margin: 4px 0;
    border-left: 3px solid var(--border);
    background: var(--surface);
    border-radius: var(--r-sm);
    font-size: 0.9rem;
}
.fb-criterion.met { border-left-color: var(--success); }
.fb-criterion.unmet { border-left-color: var(--danger); }

/* Bloc signaux (anti-triche, données brutes) */
.signals-block {
    margin-top: 10px;
    padding: 10px 14px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    font-size: 0.88rem;
}
.signals-block h4 {
    margin: 0 0 8px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
}
.signals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 4px 16px;
}
.signals-grid > div {
    color: var(--text);
}
.signals-grid b { font-weight: 600; color: var(--text); }
.signals-grid .label { color: var(--text-muted); font-size: 0.82rem; margin-right: 4px; }

/* Mise en évidence des signaux qui dépassent le seuil. */
.signals-grid .suspect {
    background: var(--danger-soft);
    color: var(--danger);
    padding: 2px 8px;
    border-radius: var(--r-sm);
    margin: -2px;
}
.signals-grid .suspect .label,
.signals-grid .suspect b { color: var(--danger); }

/* Récap "X signaux suspects" en tête de bloc. */
.signals-summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: var(--r-full);
    font-size: 0.78rem;
    font-weight: 600;
    margin-left: 8px;
}
.signals-summary.clean { background: var(--success-soft); color: var(--success); }
.signals-summary.warn  { background: var(--warning-soft); color: var(--warning); }
.signals-summary.alert { background: var(--danger-soft); color: var(--danger); }

/* Flag de saut de qualité dans le feedback */
.quality-jump-flag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: var(--r-full);
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--warning-soft);
    color: var(--warning);
    margin-left: 8px;
}

/* Section similarité (vue par niveau) */
.similarity-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px;
    margin-bottom: 20px;
}
.similarity-panel h3 {
    margin: 0 0 8px;
    font-size: 1rem;
}
.similarity-panel .baseline-info {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-bottom: 10px;
}
.similarity-pair {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    margin: 4px 0;
    background: var(--danger-soft);
    border-left: 3px solid var(--danger);
    border-radius: var(--r-sm);
    font-size: 0.92rem;
}
.similarity-pair {
    cursor: pointer;
    transition: filter 0.15s ease, transform 0.05s ease;
}
.similarity-pair:hover { filter: brightness(0.95); }
.similarity-pair:active { transform: translateY(1px); }
.similarity-pair .pair-users { font-weight: 600; }
.similarity-pair .pair-score { color: var(--danger); font-weight: 700; font-variant-numeric: tabular-nums; }
.similarity-pair .pair-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-left: auto;
    margin-right: 8px;
}

/* Constellation graph — disposition force-directed des paires suspectes */
.constellation {
    margin-top: 14px;
}
.constellation summary {
    cursor: pointer;
    color: var(--text-muted);
    font-weight: 600;
    user-select: none;
    padding: 4px 0;
}
.constellation summary:hover { color: var(--text); }
.constellation-svg {
    width: 100%;
    height: 420px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    margin-top: 8px;
}
.constellation-svg .node {
    fill: var(--primary-soft);
    stroke: var(--primary);
    stroke-width: 1.5;
    cursor: default;
}
.constellation-svg .node-label {
    font-size: 11px;
    font-weight: 600;
    fill: var(--text);
    text-anchor: middle;
    pointer-events: none;
    user-select: none;
}
.constellation-svg .edge {
    stroke: var(--danger);
    cursor: pointer;
    transition: stroke-width 0.1s ease;
}
.constellation-svg .edge:hover {
    stroke-width: 4;
}
.constellation-svg .edge-label {
    font-size: 10px;
    fill: var(--danger);
    font-weight: 600;
    pointer-events: none;
    user-select: none;
}

/* Modale de comparaison */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    animation: fadeBg 0.15s ease;
}
.modal-overlay.open { display: flex; }
@keyframes fadeBg { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    max-width: 1200px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}
.modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 {
    margin: 0;
    font-size: 1.05rem;
    flex: 1;
}
.modal-close {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 6px;
}
.modal-close:hover { color: var(--text); }
.modal-body {
    padding: 16px 20px;
    overflow: auto;
    flex: 1;
}

/* Diff side-by-side */
.diff-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.diff-side h4 {
    margin: 0 0 8px;
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.diff-pre {
    background: #0F172A;
    color: #E2E8F0;
    border-radius: var(--r-md);
    padding: 10px;
    font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    overflow: auto;
    margin: 0;
    max-height: 65vh;
}
.diff-line {
    display: block;
    padding: 0 8px;
    white-space: pre-wrap;
    word-break: break-word;
    border-radius: 2px;
    min-height: 1.6em;
}
.diff-line.equal { color: #94A3B8; }
.diff-line.add {
    background: rgba(16, 185, 129, 0.18);
    color: #6EE7B7;
}
.diff-line.remove {
    background: rgba(239, 68, 68, 0.18);
    color: #FCA5A5;
}
.diff-line.empty {
    background: rgba(255, 255, 255, 0.03);
    color: transparent;
}
.diff-line .gutter {
    display: inline-block;
    width: 1.2em;
    color: rgba(255, 255, 255, 0.35);
    user-select: none;
    margin-right: 4px;
}
.diff-line.add .gutter { color: rgba(16, 185, 129, 0.7); }
.diff-line.remove .gutter { color: rgba(239, 68, 68, 0.7); }

@media (max-width: 768px) {
    .diff-grid { grid-template-columns: 1fr; }
    .diff-pre { max-height: 40vh; }
}

.empty-state {
    color: var(--text-muted);
    font-style: italic;
    padding: 32px;
    text-align: center;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--r-lg);
}

/* ---------- Level editor ---------- */
.editor-layout {
    display: grid;
    grid-template-columns: 220px 1fr 320px;
    gap: 20px;
    align-items: start;
}
.editor-canvas-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px;
}
.editor-canvas-card canvas {
    background: var(--canvas-bg);
    border-radius: var(--r-md);
    width: 100%;
    height: auto;
    display: block;
}
.editor-side {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.editor-side h2 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin: 0 0 8px;
}
#editor-container {
    height: 200px;
    background: var(--surface);
    border: 1px solid var(--border) !important;
    border-radius: var(--r-md);
}
.ql-toolbar.ql-snow {
    border: 1px solid var(--border) !important;
    border-radius: var(--r-md) var(--r-md) 0 0;
    background: var(--surface);
}
.ql-container.ql-snow {
    border: 1px solid var(--border) !important;
    border-top: none !important;
    border-radius: 0 0 var(--r-md) var(--r-md);
}
[data-theme="dark"] .ql-snow .ql-stroke { stroke: var(--text-muted); }
[data-theme="dark"] .ql-snow .ql-fill { fill: var(--text-muted); }
[data-theme="dark"] .ql-snow .ql-picker-label { color: var(--text-muted); }
[data-theme="dark"] .ql-editor { color: var(--text); }
[data-theme="dark"] .ql-editor.ql-blank::before { color: var(--text-subtle); }

.selector-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
}
.selector-item {
    width: 56px;
    height: 56px;
    cursor: pointer;
    border-radius: var(--r-md);
    border: 2px solid var(--border);
    transition: border-color 0.15s ease, transform 0.05s ease;
}
.selector-item:hover { border-color: var(--primary); }
.selector-item.selected { border-color: var(--primary); box-shadow: var(--shadow-glow); }

/* ---------- Utilitaires ---------- */
.muted { color: var(--text-muted); }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-gap { gap: 12px; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.hidden { display: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .game-layout {
        grid-template-columns: 200px 1fr;
    }
    .game-side {
        grid-column: 1 / -1;
    }
    .editor-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .app-header-inner { padding: 0 16px; gap: 12px; }
    .app-nav-toggle { display: inline-flex; }
    .app-nav {
        display: none;
        position: absolute;
        top: var(--header-h);
        left: 0;
        right: 0;
        background: var(--bg-elevated);
        border-bottom: 1px solid var(--border);
        flex-direction: column;
        align-items: stretch;
        padding: 8px;
        gap: 2px;
        box-shadow: var(--shadow);
    }
    .app-nav.open { display: flex; }
    .app-nav-link { padding: 12px 14px; }
    .app-main { padding: 16px; }
    .game-layout { grid-template-columns: 1fr; }
    .game-sidebar { position: static; }
    .level-list { max-height: 200px; }
    .player-rank, .mastery-badge, .player-progress {
        font-size: 0.75rem;
        padding: 3px 8px;
    }
    table.data-table th, table.data-table td {
        padding: 8px 10px;
        font-size: 0.85rem;
    }
    .auth-card { padding: 24px 20px; }
    .solutions-controls { flex-direction: column; align-items: stretch; }
    .solutions-controls .control-group { flex-wrap: wrap; }
}

@media (max-width: 480px) {
    .page-title { font-size: 1.3rem; }
    .CodeMirror { height: 280px; }
    .feedback-score { font-size: 1.5rem; }
}
