/* Cours avec Coddy */
.td-app {
    --td-grad: linear-gradient(135deg, var(--accent) 0%, var(--accent5) 100%);
    display: flex;
    flex-direction: column;
    height: clamp(560px, calc(100vh - 140px), 860px);
    margin: 4px 0 30px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------- conversation ---------- */
.td-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: 0 14px 40px rgba(15, 20, 25, .07);
}

.td-tete {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    background: var(--td-grad);
    color: #fff;
}

.td-avatar {
    position: relative;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
}

.td-avatar img {
    width: 30px;
    height: 30px;
}

.td-statut {
    position: absolute;
    right: 0;
    bottom: 1px;
    width: 11px;
    height: 11px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #22c55e;
}

.is-ecrit .td-statut {
    animation: td-pulse 1s ease-in-out infinite;
}

@keyframes td-pulse {
    50% { transform: scale(1.25); }
}

.td-tete-txt {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.td-tete-txt strong {
    font: 700 14px 'Unbounded', var(--font-text);
}

.td-tete-txt span {
    font-size: 10.5px;
    color: rgba(255, 255, 255, .88);
}

.td-btn {
    flex-shrink: 0;
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 9px;
    background: rgba(255, 255, 255, .16);
    color: #fff;
    font-size: 17px;
    cursor: pointer;
    transition: background .15s;
}

.td-btn:hover {
    background: rgba(255, 255, 255, .3);
}

.td-btn[hidden] {
    display: none;
}

.td-btn-cours {
    display: inline-flex;
    gap: 6px;
    width: auto;
    padding: 0 12px;
    font: 700 11.5px var(--font-mono);
}

.td-btn-cours .mdi {
    font-size: 16px;
}

/* « Partager le cours » : bouton et menu */
.td-partage {
    position: relative;
    flex-shrink: 0;
}

.td-partage > summary {
    list-style: none;
    user-select: none;
}

.td-partage > summary::-webkit-details-marker {
    display: none;
}

.td-partage[open] > summary {
    background: rgba(255, 255, 255, .3);
}

.td-partage-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 230px;
    padding: 6px;
    border: 1px solid var(--border2);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 14px 34px rgba(15, 20, 25, .18);
    color: var(--text);
}

/* ouvert depuis le bouton « Partager ce cours » de fin de cours : placé au-dessus de ce bouton */
.td-partage-menu.is-flottant {
    position: fixed;
    right: auto;
    bottom: auto;
}

.td-partage-menu.is-flottant .td-partage-titre {
    display: none;
}

.td-partage-titre {
    margin: 0;
    padding: 6px 10px 4px;
    overflow: hidden;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .6px;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
    color: var(--text-dimmer);
}

.td-partage-menu a,
.td-partage-copier {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font: 12.5px var(--font-text);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.td-partage-menu a:hover,
.td-partage-copier:hover {
    background: var(--surface2);
    color: var(--text);
}

.td-partage-menu .mdi {
    font-size: 18px;
    color: var(--text-dim);
}

.td-partage-menu .is-facebook .mdi { color: #1877f2; }
.td-partage-menu .is-whatsapp .mdi { color: #25d366; }
.td-partage-menu .is-linkedin .mdi { color: #0a66c2; }

.td-partage-copier {
    margin-bottom: 4px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    border-radius: 8px 8px 0 0;
}

.td-partage-copier.is-copie,
.td-partage-copier.is-copie .mdi {
    color: #00a36c;
}

/* progression du cours, en bas de l'en-tête */
.td-barre {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 4px;
    background: rgba(255, 255, 255, .22);
}

.td-barre[hidden] {
    display: none;
}

.td-barre span {
    display: block;
    width: 0;
    height: 100%;
    background: #fff;
    border-radius: 0 4px 4px 0;
    transition: width .4s ease;
}

.td-vitesse {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 32px;
    padding: 0 4px 0 9px;
    border-radius: 9px;
    background: rgba(255, 255, 255, .16);
    font-size: 15px;
}

.td-vitesse select {
    -webkit-appearance: none;
    appearance: none;
    height: 100%;
    padding: 0 22px 0 2px;
    border: 0;
    border-radius: 0;
    outline: none;
    background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='14' height='14'%3E%3Cpath fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round' d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 4px center;
    box-shadow: none;
    color: #fff;
    font: 600 11px var(--font-mono);
    cursor: pointer;
}

.td-vitesse select::-ms-expand {
    display: none;
}

.td-vitesse select option {
    background: #fff;
    color: #0f1419;
}

.td-btn:focus-visible,
.td-partage > summary:focus-visible,
.td-vitesse:focus-within {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.td-fil {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 18px 16px 12px;
    background:
        radial-gradient(circle at 1px 1px, var(--border) 1px, transparent 0) 0 0 / 18px 18px,
        var(--surface);
    scrollbar-width: thin;
    overscroll-behavior: contain;
}

.td-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 100%;
    animation: td-arrivee .22s ease-out;
}

@keyframes td-arrivee {
    from { opacity: 0; transform: translateY(6px); }
}

.td-moi {
    justify-content: flex-end;
}

.td-msg-avatar {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 6px rgba(15, 20, 25, .08);
}

.td-msg-avatar img {
    width: 19px;
    height: 19px;
}

.td-bulle {
    max-width: min(640px, 88%);
    min-width: 0;
    padding: 11px 14px;
    border-radius: 18px;
    font-size: 13px;
    line-height: 1.65;
    color: var(--text);
    overflow-wrap: anywhere;
}

.td-coddy .td-bulle {
    border: 1px solid var(--border);
    border-bottom-left-radius: 6px;
    background: var(--surface2);
}

.td-moi .td-bulle {
    border-bottom-right-radius: 6px;
    background: var(--td-grad);
    color: #fff;
    box-shadow: 0 6px 16px rgba(76, 108, 255, .22);
}

.td-bulle p {
    margin: 0 0 8px;
}

.td-bulle p:last-child,
.td-bulle ul:last-child,
.td-bulle ol:last-child {
    margin-bottom: 0;
}

.td-bulle ul,
.td-bulle ol {
    margin: 0 0 8px;
    padding-left: 20px;
}

.td-bulle li {
    margin: 3px 0;
}

.td-bulle li::marker {
    color: var(--accent);
    font-weight: 700;
}

.td-bulle code {
    padding: 1px 5px;
    border: 1px solid var(--border2);
    border-radius: 5px;
    background: var(--surface);
    color: var(--accent5);
    font-family: var(--font-mono);
    font-size: .92em;
}

.td-etiquette {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 6px;
    padding: 2px 9px;
    border-radius: 99px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .5px;
    text-transform: uppercase;
}

.td-msg-astuce .td-bulle {
    border-color: color-mix(in srgb, var(--accent2) 35%, var(--border));
    background: color-mix(in srgb, var(--accent2) 8%, var(--surface));
}

.td-msg-astuce .td-etiquette {
    background: color-mix(in srgb, var(--accent2) 16%, transparent);
    color: var(--accent2);
}

.td-msg-attention .td-bulle {
    border-color: color-mix(in srgb, var(--accent4) 40%, var(--border));
    background: color-mix(in srgb, var(--accent4) 8%, var(--surface));
}

.td-msg-attention .td-etiquette {
    background: color-mix(in srgb, var(--accent4) 16%, transparent);
    color: var(--accent4);
}

.td-msg-bravo .td-bulle {
    border-color: color-mix(in srgb, var(--accent2) 40%, var(--border));
    background: color-mix(in srgb, var(--accent2) 10%, var(--surface));
}

.td-bravo-titre {
    font: 700 15px/1.4 'Unbounded', var(--font-text);
}

.td-msg-pause .td-bulle {
    border-style: dashed;
}

/* points « Coddy écrit » */
.td-points {
    display: inline-flex;
    gap: 4px;
    padding: 14px 16px;
}

.td-points i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-dimmer);
    animation: td-points 1s ease-in-out infinite;
}

.td-points i:nth-child(2) { animation-delay: .15s; }
.td-points i:nth-child(3) { animation-delay: .3s; }

@keyframes td-points {
    0%, 60%, 100% { opacity: .35; transform: none; }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* exemples de code */
.td-msg-code .td-bulle {
    width: min(640px, 88%);
    padding: 0;
    overflow: hidden;
    background: var(--surface);
}

.td-code-tete {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 5px 6px 5px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .4px;
    text-transform: uppercase;
    color: var(--text-dim);
}

.td-code-tete .mdi {
    color: var(--accent);
}

.td-copier {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 24px;
    padding: 0 9px;
    border: 1px solid var(--border2);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text-dim);
    font: 600 10.5px var(--font-mono);
    letter-spacing: 0;
    text-transform: none;
    cursor: pointer;
    transition: color .15s, border-color .15s;
}

.td-copier .mdi {
    color: inherit;
    font-size: 13px;
}

.td-copier:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.td-copier.is-ok {
    border-color: var(--accent2);
    color: var(--accent2);
}

.td-msg-code pre.code-block {
    margin: 0;
    padding: 12px 16px;
    border: 0;
    border-radius: 0;
    background: var(--code-bg);
    font-size: 12px;
    line-height: 1.75;
    white-space: pre;
    overflow-x: auto;
}

/* séparateurs : parties du cours */
.td-sep {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 8px 0 2px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-dim);
}

.td-sep::before,
.td-sep::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border2);
}

.td-sep span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border: 1px solid var(--border2);
    border-radius: 99px;
    background: var(--surface);
}

.td-sep.is-partie span {
    border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
    background: color-mix(in srgb, var(--accent) 8%, var(--surface));
    color: var(--accent);
    font: 700 11.5px 'Unbounded', var(--font-text);
}

.td-sep.is-reprise span,
.td-sep.is-fin span {
    border-color: color-mix(in srgb, var(--accent2) 40%, var(--border));
    color: var(--accent2);
}

/* questions */
.td-msg-quiz .td-bulle {
    border-color: color-mix(in srgb, var(--accent5) 35%, var(--border));
    background: color-mix(in srgb, var(--accent5) 6%, var(--surface));
}

.td-msg-quiz .td-etiquette {
    background: color-mix(in srgb, var(--accent5) 16%, transparent);
    color: var(--accent5);
}

.td-quiz-choix {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
}

.td-quiz-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid var(--border2);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font: 13px/1.45 var(--font-text);
    text-align: left;
    cursor: pointer;
    transition: border-color .15s, transform .15s;
}

.td-quiz-btn:hover:not(:disabled) {
    border-color: var(--accent5);
    transform: translateX(2px);
}

.td-quiz-btn:disabled {
    cursor: default;
    opacity: .6;
}

.td-quiz-lettre {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--accent5) 14%, transparent);
    color: var(--accent5);
    font-size: 11px;
    font-weight: 700;
}

.td-quiz-btn.is-bonne {
    opacity: 1;
    border-color: var(--accent2);
    background: color-mix(in srgb, var(--accent2) 12%, var(--surface));
}

.td-quiz-btn.is-bonne .td-quiz-lettre {
    background: var(--accent2);
    color: #fff;
}

.td-quiz-btn.is-fausse {
    opacity: 1;
    border-color: var(--err);
    background: color-mix(in srgb, var(--err) 10%, var(--surface));
}

.td-quiz-btn.is-fausse .td-quiz-lettre {
    background: var(--err);
    color: #fff;
}

.td-quiz-reponse {
    color: var(--accent2);
    font-weight: 700;
}

/* grille de choix des cours, dans la conversation */
.td-msg-grille .td-bulle {
    width: min(960px, 92%);
    max-width: none;
    background: var(--surface);
}

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

.td-grille-titre {
    margin-bottom: 6px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.1px;
    text-transform: uppercase;
    color: var(--text-dimmer);
}

.td-grille-boutons {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 6px;
}

.td-choix {
    position: relative;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 10px;
    border: 1px solid var(--border2);
    border-radius: 12px;
    background: var(--surface2);
    color: var(--text);
    font: 600 12px/1.35 var(--font-text);
    text-align: left;
    cursor: pointer;
    transition: border-color .15s, transform .15s, box-shadow .15s;
}

.td-choix:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(15, 20, 25, .08);
}

.td-choix > .mdi:first-child {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: var(--td-grad);
    color: #fff;
    font-size: 16px;
}

.td-choix span {
    flex: 1;
    min-width: 0;
}

.td-choix small {
    display: block;
    margin-top: 1px;
    font-size: 10px;
    font-weight: 400;
    color: var(--text-dimmer);
}

.td-choix .td-fait {
    color: var(--accent2);
    font-size: 16px;
}

.td-choix .td-commence {
    color: var(--accent4);
    font-size: 16px;
}

.td-choix.is-actuel {
    border-color: var(--accent);
    box-shadow: inset 3px 0 0 var(--accent);
}

/* mini-projets : réservés aux membres */
.td-grille-note {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 6px;
    padding: 1px 8px;
    border-radius: 99px;
    background: color-mix(in srgb, var(--accent5) 12%, transparent);
    color: var(--accent5);
    letter-spacing: .3px;
    text-transform: none;
}

.td-choix .td-verrou {
    color: var(--accent5);
    font-size: 16px;
}

.td-choix.is-verrou > .mdi:first-child {
    opacity: .55;
}

.td-msg-porte .td-bulle {
    border-color: color-mix(in srgb, var(--accent5) 35%, var(--border));
    background: color-mix(in srgb, var(--accent5) 6%, var(--surface));
}

.td-msg-porte .td-etiquette {
    background: color-mix(in srgb, var(--accent5) 16%, transparent);
    color: var(--accent5);
}

/* ---------- pied : boutons d'action ---------- */
.td-pied {
    padding: 10px 14px 10px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.td-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    min-height: 0;
}

.td-actions:not(:empty) {
    margin-bottom: 8px;
}

.td-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border: 1px solid var(--border2);
    border-radius: 99px;
    background: var(--surface);
    color: var(--text);
    font: 700 12px var(--font-mono);
    text-decoration: none;
    cursor: pointer;
    animation: td-arrivee .25s ease-out;
    transition: border-color .15s, transform .15s;
}

.td-action:hover {
    border-color: var(--accent);
    color: var(--text);
    transform: translateY(-1px);
}

.td-action.is-principal {
    border-color: transparent;
    background: var(--td-grad);
    color: #fff;
    box-shadow: 0 6px 16px rgba(76, 108, 255, .25);
}

.td-action.is-principal:hover {
    color: #fff;
}

.td-mention {
    margin: 0;
    font-size: 10.5px;
    text-align: center;
    color: var(--text-dimmer);
}

.td-mention a {
    color: var(--accent);
}

/* ---------- plein écran : la conversation occupe tout l'écran ---------- */
html.td-plein,
html.td-plein body {
    overflow: hidden;
}

.td-app.is-plein {
    position: fixed;
    inset: 0;
    z-index: 10000;
    width: 100%;
    height: 100%;
    height: 100dvh;
    margin: 0;
    background: var(--surface);
}

.td-app.is-plein .td-chat {
    flex: 1;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

/* sur un grand écran, la conversation reste dans une colonne lisible */
.td-app.is-plein .td-fil,
.td-app.is-plein .td-pied {
    padding-left: max(16px, calc((100% - 1180px) / 2));
    padding-right: max(16px, calc((100% - 1180px) / 2));
}

/* version sans JavaScript */
.td-statique h3 {
    margin: 22px 0 8px;
}

/* ---------- petits écrans : la liste des cours devient un tiroir ---------- */
@media (max-width: 900px) {
    .td-app {
        height: calc(100vh - 90px);
        min-height: 520px;
    }

    .td-bulle {
        max-width: 92%;
    }

    .td-msg-code .td-bulle,
    .td-msg-grille .td-bulle {
        width: 100%;
    }

    .td-msg-code,
    .td-msg-grille {
        flex-direction: column;
        align-items: flex-start;
    }

    .td-msg-code .td-msg-avatar,
    .td-msg-grille .td-msg-avatar {
        display: none;
    }
}

/* en-tête étroit : les boutons « Les cours » et « Partager le cours » n'affichent plus que leur icône */
@media (max-width: 820px) {
    .td-btn-cours span {
        display: none;
    }

    .td-btn-cours {
        width: 32px;
        padding: 0;
        justify-content: center;
    }
}

@media (max-width: 520px) {
    .td-tete {
        gap: 6px;
        padding: 9px 10px;
    }

    .td-tete-txt {
        display: none;
    }

    .td-avatar {
        width: 34px;
        height: 34px;
        margin-right: auto;
    }

    .td-avatar img {
        width: 25px;
        height: 25px;
    }

    .td-btn {
        width: 30px;
        height: 30px;
    }

    .td-vitesse {
        height: 30px;
        padding-left: 7px;
    }

    .td-vitesse select {
        width: 92px;
    }

    .td-vitesse > .mdi {
        display: none;
    }

    .td-btn-cours {
        width: 30px;
    }

    .td-partage-menu {
        position: fixed;
        left: 10px;
        right: 10px;
        top: auto;
        bottom: 12px;
        width: auto;
    }

    .td-fil {
        padding: 14px 10px 10px;
    }

    .td-grille-boutons {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    .td-msg,
    .td-action,
    .td-points i,
    .is-ecrit .td-statut {
        animation: none;
    }
}

/* très petits téléphones : l'avatar de l'en-tête laisse la place aux boutons */
@media (max-width: 400px) {
    .td-tete {
        gap: 4px;
        justify-content: flex-end;
    }

    .td-avatar {
        display: none;
    }

    .td-vitesse select {
        width: 84px;
        font-size: 10px;
    }
}

@media (max-width: 350px) {
    #tdSauter {
        display: none;
    }
}
