/* =============================================
   VARIABLES
============================================= */
:root {
    --bg:     #0b1020;
    --stroke: rgba(255, 255, 255, .14);
    --text:   rgba(255, 255, 255, .92);
    --muted:  rgba(255, 255, 255, .60);
    --good:   #2bff64;
    --bad:    #ff4d6d;
    --accent: #6d5cff;
    --shadow: 0 20px 60px rgba(0, 0, 0, .55);
    --r:      12px;
    --r2:     20px;
    --maxw:   min(80vw, 1200px);
    --pad:    14px;

    --card-bg:    rgba(255, 255, 255, .055);
    --hover-bg:   rgba(255, 255, 255, .12);
    --choice-bg:  rgba(255, 255, 255, .05);
    --btn-bg:     rgba(255, 255, 255, .08);
    --media-bg:   rgba(0, 0, 0, .40);
    --progress-bg: rgba(255, 255, 255, .10);
    --spinner-bg:  rgba(255, 255, 255, .10);
}

/* =============================================
   THÈME CLAIR
============================================= */
html[data-theme="light"] {
    --bg:     #f0f2f5;
    --text:   rgba(0, 0, 0, .88);
    --muted:  rgba(0, 0, 0, .55);
    --stroke: rgba(0, 0, 0, .12);
    --shadow: 0 20px 60px rgba(0, 0, 0, .12);

    --card-bg:    rgba(255, 255, 255, .75);
    --hover-bg:   rgba(0, 0, 0, .06);
    --choice-bg:  rgba(0, 0, 0, .04);
    --btn-bg:     rgba(0, 0, 0, .06);
    --media-bg:   rgba(0, 0, 0, .06);
    --progress-bg: rgba(0, 0, 0, .08);
    --spinner-bg:  rgba(0, 0, 0, .10);
}

/* =============================================
   RESET & BASE
============================================= */
*, *::before, *::after { box-sizing: border-box; }

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

body {
    height: 100dvh;
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
}

/* Fond dégradé fixe — pseudo-element : stable sur iOS Safari */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(900px 500px at 10%   5%,   rgba(109, 92, 255, .22), transparent 60%),
        radial-gradient(800px 500px at 85%   0%,   rgba(43, 212, 255, .16), transparent 55%),
        radial-gradient(900px 700px at 50%  110%,  rgba(255, 77, 109, .09), transparent 60%),
        var(--bg);
}

html[data-theme="light"] body::before {
    background:
        radial-gradient(900px 500px at 10%   5%,   rgba(109, 92, 255, .08), transparent 60%),
        radial-gradient(800px 500px at 85%   0%,   rgba(43, 212, 255, .06), transparent 55%),
        radial-gradient(900px 700px at 50%  110%,  rgba(255, 77, 109, .04), transparent 60%),
        var(--bg);
}

/* =============================================
   LAYOUT — toute la hauteur, aucun scroll de page
============================================= */
.app {
    height: 100dvh;
    max-width: var(--maxw);
    margin: 0 auto;
    padding: var(--pad) var(--pad) 6px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* =============================================
   TOPBAR
============================================= */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
}

.title h1 {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
}

.title p {
    margin: 0;
    font-size: 11px;
    color: var(--muted);
}

.stats {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* Toggle thème */
.theme-toggle {
    appearance: none;
    border: 1px solid var(--stroke);
    background: var(--choice-bg);
    color: var(--text);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .2s, border-color .2s;
    -webkit-tap-highlight-color: transparent;
}

.theme-toggle:hover { background: var(--hover-bg); }

.pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--stroke);
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.pill--good { color: var(--good); border-color: rgba(43, 255, 100, .3); }
.pill--bad  { color: var(--bad);  border-color: rgba(255, 77, 109, .3); }

/* =============================================
   PROGRESSION
============================================= */
.progress-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.progress-wrap {
    flex: 1;
    height: 5px;
    background: var(--progress-bg);
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), #2bd4ff);
    border-radius: 999px;
    transition: width .45s cubic-bezier(.4, 0, .2, 1);
}

.progress-label {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 42px;
    text-align: right;
}

/* =============================================
   CARD — prend tout l'espace restant,
   layout flex interne pour tout caser sans scroll
============================================= */
.card {
    flex: 1;
    min-height: 0;
    background: var(--card-bg);
    border: 1px solid var(--stroke);
    border-radius: var(--r2);
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#quizView {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

#quizView.is-hidden { display: none !important; }

/* =============================================
   IMAGE — prend sa part de l'espace flex,
   jamais trop grande, image toujours entière
============================================= */
.qmedia {
    margin: 0;
    background: var(--media-bg);
    overflow: hidden;
    border-radius: var(--r2) var(--r2) 0 0;
    flex: 1 1 auto;
    min-height: 120px;
    max-height: 45vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qmedia__img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
    transition: opacity .2s ease-out;
}

/* =============================================
   CORPS DE QUESTION
============================================= */
.qbody {
    padding: 16px 22px 8px;
    flex-shrink: 0;
}

.qnum {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--muted);
}

.question {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.5;
}

/* =============================================
   CHOIX QCM
============================================= */
.choices {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 8px 22px 12px;
    flex-shrink: 0;
}

/* Sur mobile on revient à une colonne */
@media (max-width: 600px) {
    .choices { grid-template-columns: 1fr; }
}

.choice {
    appearance: none;
    width: 100%;
    text-align: left;
    border: 1px solid var(--stroke);
    background: var(--choice-bg);
    color: var(--text);
    padding: 14px 16px;
    border-radius: var(--r);
    font-size: 15px;
    line-height: 1.4;
    min-height: 60px;        /* boutons plus hauts = moins vide */
    cursor: pointer;
    transition: background .2s ease, border-color .2s ease,
                color .2s ease, opacity .3s ease, transform .07s ease;
    display: flex;
    align-items: flex-start;
    gap: 11px;
    height: 100%;               /* hauteur uniforme dans la grille */
    -webkit-tap-highlight-color: transparent;
}

.choice-letter {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid var(--stroke);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 800;
    color: var(--muted);
    margin-top: 1px;
    transition: background .15s, border-color .15s, color .15s;
}

.choice-text { flex: 1; }

.choice:not(:disabled):hover {
    background: rgba(109, 92, 255, .14);
    border-color: rgba(109, 92, 255, .5);
}

.choice:not(:disabled):hover .choice-letter {
    border-color: rgba(109, 92, 255, .6);
    color: var(--text);
}

.choice:not(:disabled):active { transform: scale(.99); }
.choice:disabled { cursor: default; }

@keyframes pulse-correct {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.02); }
    100% { transform: scale(1); }
}

@keyframes shake-wrong {
    0%, 100% { transform: translateX(0); }
    20%      { transform: translateX(-4px); }
    40%      { transform: translateX(4px); }
    60%      { transform: translateX(-3px); }
    80%      { transform: translateX(2px); }
}

/* État : bonne réponse */
.choice.is-correct {
    background: rgba(43, 255, 100, .10);
    border-color: rgba(43, 255, 100, .45);
    color: var(--good);
    animation: pulse-correct .35s ease-out;
}
.choice.is-correct .choice-letter {
    background: rgba(43, 255, 100, .18);
    border-color: rgba(43, 255, 100, .55);
    color: var(--good);
}

/* État : mauvaise réponse sélectionnée */
.choice.is-selected-wrong {
    background: rgba(255, 77, 109, .13);
    border-color: rgba(255, 77, 109, .55);
    color: var(--bad);
    animation: shake-wrong .35s ease-out;
}
.choice.is-selected-wrong .choice-letter {
    background: rgba(255, 77, 109, .2);
    border-color: rgba(255, 77, 109, .55);
    color: var(--bad);
}

/* État : autres mauvaises options */
.choice.is-wrong { opacity: .40; }

/* =============================================
   FEEDBACK
============================================= */
.feedback {
    margin: 0 18px;
    border-radius: var(--r);
    border: 1px solid var(--stroke);
    background: var(--choice-bg);
    opacity: 0;
    transform: translateY(6px);
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
    transition: opacity .25s ease-out, transform .25s ease-out,
                max-height .3s ease-out, padding .25s ease-out;
    pointer-events: none;
    flex-shrink: 0;
}

.feedback.is-show {
  padding: 10px 13px;
    opacity: 1;
    transform: translateY(0);
    max-height: 120px;
    padding-top: 11px;
    padding-bottom: 11px;
    pointer-events: auto;
}
.feedback.is-ok .feedback__title { color: var(--good);  }
.feedback.is-ko .feedback__title { color: var(--bad); }

.feedback__title {
    margin: 0 0 3px;
    font-weight: 800;
    font-size: 14px;
}

.feedback__text {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

/* =============================================
   ACTIONS
============================================= */
.actions {
    padding: 8px 18px 14px;
    flex-shrink: 0;
    margin-top: auto;
}

.is-hidden { display: none !important; }

/* =============================================
   ÉCRAN DE CHARGEMENT
============================================= */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 16px;
}

.spinner {
    width: 38px;
    height: 38px;
    border: 3px solid var(--spinner-bg);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

/* =============================================
   TRANSITIONS ENTRE QUESTIONS
============================================= */
@keyframes q-in {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0);    }
}

@keyframes q-out {
    from { opacity: 1; transform: translateX(0);     }
    to   { opacity: 0; transform: translateX(-40px); }
}

.is-entering { animation: q-in  .22s ease-out forwards; }
.is-leaving  { animation: q-out .15s ease-in  forwards; pointer-events: none; }

.btn {
    appearance: none;
    display: block;
    width: 100%;
    border: 1px solid var(--stroke);
    background: var(--btn-bg);
    color: var(--text);
    padding: 12px 20px;
    border-radius: var(--r);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: transform .07s ease, background .15s ease, border-color .15s ease;
    user-select: none;
    text-align: center;
}

.btn:hover  { background: var(--hover-bg); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn--primary {
    background: linear-gradient(135deg, rgba(109, 92, 255, .9), rgba(43, 212, 255, .5));
    border-color: rgba(109, 92, 255, .5);
}
.btn--primary:hover {
    background: linear-gradient(135deg, rgba(109, 92, 255, 1), rgba(43, 212, 255, .65));
}

/* =============================================
   ÉCRAN DE FIN
============================================= */
.end-screen {
    padding: 40px 24px 32px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 8px;
}

.end-icon { font-size: 48px; line-height: 1; margin-bottom: 4px; }

.end-score {
    margin: 0;
    font-size: 52px;
    font-weight: 900;
    line-height: 1;
    background: linear-gradient(135deg, var(--accent), #2bd4ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.end-mention { margin: 0; font-size: 18px; font-weight: 700; }

.end-label { margin: 0 0 8px; color: var(--muted); font-size: 14px; }

.end-pills { display: flex; gap: 8px; margin-bottom: 16px; }

.end-screen .btn { max-width: 280px; }

/* =============================================
   RESPONSIVE — tablette / grand mobile
============================================= */
@media (max-width: 600px) {
    :root {
        --pad: 10px;
    }

    .qmedia   { max-height: 28vh; }
    .qmedia__img { object-fit: cover; }

    .title h1 { font-size: 16px; }

    .qbody    { padding: 10px 14px 6px; }
    .question { font-size: 15px; }

    .choices  { padding: 5px 12px 10px; gap: 6px; }
    .choice   { padding: 10px 12px; font-size: 13px; gap: 9px; min-height: 48px; }
    .choice-letter { width: 22px; height: 22px; font-size: 10px; }

    .feedback { margin: 0 12px; }
    .feedback.is-show { padding: 8px 12px; }
    .actions  { padding: 6px 12px 10px; }

    .pill { padding: 4px 10px; font-size: 12px; }
}

/* =============================================
   RESPONSIVE — petit mobile (≤ 400 px)
============================================= */
@media (max-width: 400px) {
    :root {
        --pad: 6px;
        --r:   10px;
        --r2:  16px;
    }

    .qmedia   { max-height: 24vh; }
    .qmedia__img { object-fit: cover; }

    .title h1 { font-size: 15px; }
    .title p  { display: none; }

    .qbody    { padding: 8px 10px 4px; }
    .question { font-size: 13px; }

    .choices  { padding: 4px 10px 8px; gap: 5px; }
    .choice   { padding: 8px 10px; font-size: 12px; gap: 8px; min-height: 38px; }
    .choice-letter { width: 20px; height: 20px; font-size: 9px; }

    .feedback { margin: 0 10px; font-size: 12px; }
    .feedback.is-show { padding: 7px 10px; }
    .actions  { padding: 6px 10px 8px; }

    .stats .pill--bad { display: none; }
}

/* =============================================
   RESPONSIVE — très haut écran (desktop)
   On plafonne la hauteur image pour ne pas
   gâcher de l'espace sur grands moniteurs
============================================= */
