* {
    box-sizing: border-box;
}

/* Mobile/tablette : évite le zoom au double-tap sur les éléments interactifs */
a,
button,
input[type="button"],
input[type="submit"],
select,
[role="button"] {
    touch-action: manipulation;
}

html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: #14141a;
    color: #e6edf3;
    display: flex;
    flex-direction: column;
}

/* La barre du haut est la barre de navigation commune du site (css/top-nav.css) : dans la colonne du <body>, elle garde sa hauteur. */
body > header {
    flex-shrink: 0;
}

/* Ligne de contexte sous la barre : retour à la fiche + type d'atelier. */
.atelier-context {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.6rem;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid #2a2a33;
    background: #0d0d12;
}

.atelier-back {
    margin-right: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.6rem 0.9rem;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(255,255,255,0.02);
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.9rem;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.atelier-back:hover {
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.32);
    transform: translateY(-1px);
    text-decoration: none;
}

.atelier-badge {
    font-size: 0.8rem;
    font-weight: 700;
    color: #8a8a92;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.atelier-workspace {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    gap: 0.65rem;
}

.ae-editor {
    flex: 1;
    min-height: 120px;
    width: 100%;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid #30363d;
    background: #161b22;
    color: #e6edf3;
    font-family: var(--font-mono, ui-monospace, Consolas, "Courier New", monospace);
    font-size: 0.85rem;
    line-height: 1.55;
    resize: none;
    font-variant-ligatures: none;
    font-feature-settings: "liga" 0, "calt" 0, "dlig" 0;
}

.ae-editor-shell {
    flex: 1;
    min-height: 120px;
    position: relative;
    border-radius: 8px;
    border: 1px solid #30363d;
    background: #161b22;
    overflow: hidden;
}

.ae-editor-shell:focus-within {
    border-color: #58a6ff;
    box-shadow: 0 0 0 1px #58a6ff;
}

.ae-editor-mirror,
.ae-editor {
    margin: 0;
    padding: 1rem;
    font-family: var(--font-mono, ui-monospace, Consolas, "Courier New", monospace);
    font-size: 0.85rem;
    line-height: 1.55;
    tab-size: 4;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-variant-ligatures: none;
    font-feature-settings: "liga" 0, "calt" 0, "dlig" 0;
}

.ae-editor-mirror {
    position: absolute;
    inset: 0;
    overflow: auto;
    pointer-events: none;
    border: none;
    background: transparent;
}

.ae-editor-mirror code {
    display: block;
    min-height: 100%;
}

.ae-editor {
    flex: 1;
    min-height: 120px;
    width: 100%;
    border-radius: 8px;
    border: 1px solid #30363d;
    background: #161b22;
    color: #e6edf3;
    resize: none;
}

.ae-editor-shell .ae-editor,
.ae-editor--overlay {
    position: absolute;
    inset: 0;
    flex: none;
    min-height: 0;
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 0;
    background: transparent;
    color: transparent;
    caret-color: #e6edf3;
    resize: none;
    overflow: auto;
}

.ae-editor-shell .ae-editor:focus,
.ae-editor--overlay:focus {
    outline: none;
    border-color: transparent;
    box-shadow: none;
}

/* Coloration syntaxique (palette IDE, alignée sur les fiches) */
.ae-editor-mirror .syn-kw {
    color: #c792ea;
    font-weight: 600;
}

.ae-editor-mirror .syn-builtin {
    color: #82aaff;
}

.ae-editor-mirror .syn-mod {
    color: #ffcb6b;
}

.ae-editor-mirror .syn-name {
    color: #e2e8f0;
}

.ae-editor-mirror .syn-str {
    color: #c3e88d;
}

.ae-editor-mirror .syn-num {
    color: #f78c6c;
}

.ae-editor-mirror .syn-cmt {
    color: #5c6370;
    font-style: italic;
}

.ae-editor-mirror .syn-punct {
    color: #89ddff;
}

.ae-editor:focus {
    outline: none;
    border-color: #58a6ff;
    box-shadow: 0 0 0 1px #58a6ff;
}

.ae-toolbar {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.ae-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem 1.15rem;
    border-radius: 6px;
    border: 1.5px solid rgba(255,255,255,0.14);
    font-family: "Manrope", -apple-system, "Segoe UI", sans-serif;
    font-weight: 700;
    font-size: 0.88rem;
    line-height: 1.2;
    cursor: pointer;
    background: rgba(255,255,255,0.02);
    color: #e6edf3;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.ae-btn:hover {
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.28);
    transform: translateY(-1px);
}

.ae-primary {
    background: #ef4a34;
    border-color: #ef4a34;
    color: #fff;
    box-shadow: 0 10px 24px -10px rgba(239,74,52,0.55);
}

.ae-primary:hover {
    background: #c93620;
    border-color: #c93620;
    transform: translateY(-1px);
}

.ae-preview {
    flex: 1;
    min-height: 140px;
    border-radius: 8px;
    border: 1px solid #30363d;
    background: #ffffff;
    color: #1f2937;
    padding: 1rem;
    overflow: auto;
    font-size: 0.95rem;
}

.ae-preview.ae-terminal {
    background: #0d1117;
    color: #c9d1d9;
    font-family: var(--font-mono, ui-monospace, Consolas, "Courier New", monospace);
    font-size: 0.82rem;
    white-space: pre-wrap;
    word-break: break-word;
    font-variant-ligatures: none;
    font-feature-settings: "liga" 0, "calt" 0, "dlig" 0;
}

.ae-preview.ae-error {
    border-color: #f85149;
    color: #f85149;
}

.ae-frame {
    flex: 1;
    min-height: 180px;
    width: 100%;
    border: 1px solid #30363d;
    border-radius: 8px;
    background: #fff;
}

.ae-hint {
    font-size: 0.75rem;
    color: #8b949e;
    margin: 0;
}

.ae-html-frame {
    min-height: 220px;
    background: #fff;
}

.ae-html-status.ae-ok {
    color: #3fb950;
}

.ae-html-status.ae-error {
    color: #f85149;
}

.ae-autocomplete {
    font-family: var(--font-mono, ui-monospace, Consolas, "Courier New", monospace) !important;
}

.ae-exercise {
    flex-shrink: 0;
    padding: 0.75rem 0.85rem;
    border-radius: 8px;
    border: 1px solid #30363d;
    background: #161b22;
}

.ae-exercise__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    font-size: 0.9rem;
    color: #e6edf3;
}

.ae-exercise__head .ex-stars {
  margin-left: auto;
}

.ae-btn-solution {
    border-color: #a371f7;
    color: #d2a8ff;
}

/* .ae-btn impose display: inline-flex, ce qui annulait l'attribut hidden : « Solution » ne doit apparaître qu'après deux essais ratés. */
.ae-btn[hidden] {
    display: none;
}

.ae-btn-solution:hover {
    background: rgba(163, 113, 247, 0.15);
}

.ae-exercise__more {
    font-size: 0.78rem;
    color: #58a6ff;
    text-decoration: none;
    font-weight: 600;
}

.ae-exercise__more:hover {
    text-decoration: underline;
}

.ae-exercise__hint {
    margin: 0.45rem 0 0.65rem;
    font-size: 0.82rem;
    color: #8b949e;
    line-height: 1.45;
}

.ae-exercise__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.ae-exercise__feedback {
    margin: 0.55rem 0 0;
    font-size: 0.82rem;
    line-height: 1.45;
}

.ae-exercise__feedback.ae-ok {
    color: #3fb950;
}

.ae-exercise__feedback.ae-error {
    color: #f85149;
}

/* Responsive pour mobile */
@media (max-width: 768px) {
    .atelier-context {
        padding: 0.5rem;
    }

    .atelier-back {
        font-size: 0.9rem;
    }
    
    .atelier-badge {
        font-size: 0.75rem;
    }
    
    .atelier-workspace {
        padding: 0.5rem;
        gap: 0.5rem;
    }
    
    .ae-editor-shell {
        min-height: 100px;
    }

    .ae-editor-mirror,
    .ae-editor {
        font-size: 0.82rem;
        padding: 0.75rem;
    }
    
    .ae-toolbar {
        flex-wrap: wrap;
        gap: 0.4rem;
    }
    
    .ae-btn {
        flex: 1;
        min-width: 80px;
        padding: 0.5rem 0.75rem;
        font-size: 0.82rem;
    }
    
    .ae-preview {
        min-height: 100px;
        font-size: 0.9rem;
        padding: 0.75rem;
    }
    
    .ae-frame {
        min-height: 150px;
    }
}

@media (max-width: 480px) {
    .atelier-context {
        padding: 0.4rem;
    }

    .atelier-back {
        font-size: 0.85rem;
    }
    
    .atelier-workspace {
        padding: 0.4rem;
        gap: 0.35rem;
    }
    
    .ae-editor-shell {
        min-height: 80px;
    }

    .ae-editor-mirror,
    .ae-editor {
        font-size: 0.78rem;
        padding: 0.5rem;
    }
    
    .ae-btn {
        min-width: 70px;
        padding: 0.4rem 0.5rem;
        font-size: 0.75rem;
    }
    
    .ae-preview {
        min-height: 80px;
        font-size: 0.85rem;
        padding: 0.5rem;
    }
}

/* Atelier CSS : deux éditeurs (le CSS, puis le HTML de la page qu'il met en forme) au-dessus de l'aperçu. */
.ae-pair {
    flex: 2 1 0;
    min-height: 160px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
}

.ae-pane {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.ae-pane__head {
    flex-shrink: 0;
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.ae-pane__title {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #a3acb8;
}

.ae-pane__note {
    font-size: 0.72rem;
    color: #8b949e;
}

.ae-check {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: #a3acb8;
    cursor: pointer;
}

@media (max-width: 760px) {
    .ae-pair {
        flex: none;
        grid-template-columns: 1fr;
    }

    .ae-pane .ae-editor-shell {
        min-height: 120px;
    }
}
