/* QuizLab : design tokens Basik Studio (lime #BFF47B, dark #262E36) */
:root {
    --lime: #BFF47B;
    --lime-dark: #9ED95A;
    --dark: #262E36;
    --dark-2: #313B46;
    --dark-3: #3D4956;
    --text: #F2F5F7;
    --text-dim: #9AA7B2;
    --red: #FF7B7B;
    --font-head: 'Space Grotesk', sans-serif;
    --font-body: 'Open Sans', sans-serif;
    --radius: 14px;
}

* { box-sizing: border-box; }

/* L'attribut hidden doit toujours gagner, meme sur les blocs flex/grid */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--dark);
    color: var(--text);
    font-family: var(--font-body);
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-family: var(--font-head); }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; margin-top: 2rem; }
a { color: var(--lime); text-decoration: none; }
code, pre { background: var(--dark-3); border-radius: 6px; padding: 2px 6px; }
pre { padding: .8rem; overflow-x: auto; }

.container {
    max-width: 760px;
    margin: 0 auto;
    padding: 1rem 1rem 5.5rem;
}
.container-full { padding: 0; max-width: none; }

/* --- Topbar --- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .7rem 1rem;
    background: var(--dark-2);
    position: sticky;
    top: 0;
    z-index: 20;
}
.logo {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text);
}
.logo span { color: var(--lime); }
.topnav { display: flex; align-items: center; gap: .8rem; }
.topnav-user { color: var(--text); font-weight: 600; }
.topnav-link { font-size: 1.2rem; }

.xpbar { display: flex; align-items: center; gap: .5rem; }
.xpbar-level { font-size: .8rem; font-weight: 700; color: var(--lime); white-space: nowrap; }
.xpbar-track {
    display: inline-block;
    width: 70px; height: 8px;
    background: var(--dark-3);
    border-radius: 4px;
    overflow: hidden;
}
.xpbar-fill { display: block; height: 100%; background: var(--lime); border-radius: 4px; transition: width .4s; }
.xpbar-wide .xpbar-track { width: 100%; display: block; height: 10px; }
.xpbar-wide { display: block; margin-top: .5rem; }
.xpbar-wide small { color: var(--text-dim); }

/* --- Bottom nav (mobile) --- */
.bottomnav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    display: flex;
    background: var(--dark-2);
    border-top: 1px solid var(--dark-3);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 20;
}
.bn-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: .5rem 0 .4rem;
    color: var(--text-dim);
    font-size: .7rem;
    gap: 2px;
}
.bn-icon { font-size: 1.3rem; }

/* --- Boutons --- */
.btn {
    display: inline-block;
    background: var(--lime);
    color: var(--dark);
    font-family: var(--font-head);
    font-weight: 700;
    border: none;
    border-radius: var(--radius);
    padding: .7rem 1.3rem;
    cursor: pointer;
    font-size: 1rem;
    text-align: center;
    transition: transform .1s, background .2s;
}
.btn:active { transform: scale(.97); }
.btn:hover { background: var(--lime-dark); }
.btn-sm { padding: .35rem .8rem; font-size: .85rem; border-radius: 9px; }
.btn-lg { padding: .9rem 1.8rem; font-size: 1.1rem; }
.btn-block { display: block; width: 100%; margin-top: 1.2rem; }
.btn-outline { background: transparent; color: var(--lime); border: 2px solid var(--lime); }
.btn-outline:hover { background: rgba(191, 244, 123, .1); }
.btn-danger { background: var(--red); color: var(--dark); }
.btn-danger:hover { background: #e66; }

/* --- Flashes --- */
.flashes { max-width: 760px; margin: .8rem auto 0; padding: 0 1rem; }
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: .5rem; font-weight: 600; }
.flash-success { background: rgba(191, 244, 123, .15); color: var(--lime); }
.flash-error { background: rgba(255, 123, 123, .15); color: var(--red); }

/* --- Auth --- */
.auth-card {
    max-width: 380px;
    margin: 8vh auto 0;
    background: var(--dark-2);
    padding: 2rem;
    border-radius: var(--radius);
}
.auth-alt { color: var(--text-dim); text-align: center; margin-top: 1.2rem; }

/* --- Formulaires --- */
label { display: block; margin-top: 1rem; margin-bottom: .3rem; font-weight: 600; font-size: .9rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
select, textarea {
    width: 100%;
    padding: .65rem .8rem;
    border-radius: 10px;
    border: 1px solid var(--dark-3);
    background: var(--dark);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 1rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--lime); border-color: transparent; }
input[type="file"] { color: var(--text-dim); margin-top: .3rem; }
.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.checkbox input { width: auto; }
.form-card { background: var(--dark-2); padding: 1.5rem; border-radius: var(--radius); margin-top: 1rem; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; }
.preview { max-width: 200px; border-radius: 10px; display: block; margin: .5rem 0; }

/* --- Hero (accueil non connecte) --- */
.hero { text-align: center; padding: 3rem 0 2rem; }
.hero h1 { font-size: 2rem; line-height: 1.2; }
.accent { color: var(--lime); }
.hero p { color: var(--text-dim); max-width: 460px; margin: 1rem auto; }
.hero-actions { display: flex; gap: .8rem; justify-content: center; flex-wrap: wrap; margin-top: 1.5rem; }

/* --- Dashboard --- */
.dash-stats { display: flex; gap: .5rem; flex-wrap: wrap; }
.chip {
    display: inline-block;
    background: var(--dark-2);
    border-radius: 999px;
    padding: .35rem .9rem;
    font-size: .85rem;
    font-weight: 600;
    color: var(--text);
}
.chip-active { background: var(--lime); color: var(--dark); }
.review-banner {
    display: block;
    margin-top: 1rem;
    background: linear-gradient(90deg, rgba(191,244,123,.2), rgba(191,244,123,.05));
    border: 1px solid var(--lime);
    color: var(--text);
    padding: .9rem 1.2rem;
    border-radius: var(--radius);
}

/* --- Categories --- */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: .8rem;
}
.category-card {
    background: var(--dark-2);
    border-radius: var(--radius);
    padding: 1.1rem .9rem;
    display: flex;
    flex-direction: column;
    gap: .3rem;
    color: var(--text);
    transition: transform .15s, background .2s;
}
.category-card:hover { transform: translateY(-3px); background: var(--dark-3); }
.cat-icon { font-size: 1.8rem; }
.cat-name { font-family: var(--font-head); font-weight: 700; }
.cat-meta { font-size: .78rem; color: var(--text-dim); }
.cat-head p { color: var(--text-dim); }
.backlink { display: inline-block; margin-bottom: .5rem; color: var(--text-dim); }

/* --- Setup quiz --- */
.option-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; }
.option-card { display: block; margin: 0; }
.option-card input { position: absolute; opacity: 0; }
.option-card span {
    display: block;
    background: var(--dark-2);
    border: 2px solid transparent;
    border-radius: var(--radius);
    padding: .8rem;
    cursor: pointer;
    font-weight: 600;
    text-align: center;
}
.option-card input:checked + span { border-color: var(--lime); background: rgba(191,244,123,.08); }
.option-card small { color: var(--text-dim); font-weight: 400; }

.notice {
    background: var(--dark-2);
    border-left: 4px solid var(--lime);
    padding: .9rem 1.2rem;
    border-radius: 0 var(--radius) var(--radius) 0;
    margin: 1rem 0;
}
.empty { color: var(--text-dim); text-align: center; padding: 2rem 0; }

/* --- Jeu --- */
#quiz-app, #study-app {
    max-width: 560px;
    margin: 0 auto;
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}
.quiz-topbar { display: flex; align-items: center; gap: 1rem; padding: .3rem 0 1rem; }
.quiz-quit { font-size: 1.3rem; color: var(--text-dim); }
.quiz-progress { flex: 1; height: 10px; background: var(--dark-2); border-radius: 5px; overflow: hidden; }
.quiz-progress-fill { height: 100%; width: 0; background: var(--lime); border-radius: 5px; transition: width .3s; }
.quiz-score { font-family: var(--font-head); font-weight: 700; color: var(--lime); min-width: 2.2rem; text-align: right; }

.quiz-center { text-align: center; padding-top: 18vh; }
.quiz-body { flex: 1; display: flex; flex-direction: column; }

.spinner {
    width: 40px; height: 40px;
    border: 4px solid var(--dark-3);
    border-top-color: var(--lime);
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Fond flou de la meme photo pour combler les bords : sujet toujours entier (object-fit: contain) */
.q-image-wrap {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 1rem;
    height: min(300px, 38dvh);
    background-color: var(--dark-2);
    background-size: cover;
    background-position: center;
}
.q-image-wrap::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: inherit;
    background-size: cover;
    background-position: center;
    filter: blur(20px) brightness(.55);
    transform: scale(1.2);
}
.q-image-wrap img {
    position: relative;
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.q-credit {
    position: absolute; bottom: 0; right: 0;
    font-size: .65rem;
    background: rgba(0,0,0,.55);
    color: #ccc;
    padding: 2px 8px;
    border-radius: 6px 0 0 0;
}
.q-prompt { font-size: 1.25rem; margin: .3rem 0 1.2rem; }

.q-choices { display: grid; gap: .7rem; }
.q-choices.images { grid-template-columns: 1fr 1fr; }
.choice-btn {
    background: var(--dark-2);
    border: 2px solid transparent;
    border-radius: var(--radius);
    padding: .9rem 1rem;
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    transition: background .15s;
}
.choice-btn:hover { background: var(--dark-3); }
.choice-btn.img-choice { padding: 0; overflow: hidden; position: relative; background-color: var(--dark-2); }
.choice-btn.img-choice::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: inherit;
    background-size: cover;
    background-position: center;
    filter: blur(14px) brightness(.55);
    transform: scale(1.2);
}
.choice-btn.img-choice img { position: relative; width: 100%; height: min(150px, 22dvh); object-fit: contain; display: block; }
.choice-btn.correct { border-color: var(--lime); background: rgba(191,244,123,.15); }
.choice-btn.wrong { border-color: var(--red); background: rgba(255,123,123,.12); }
.choice-btn:disabled { cursor: default; }

.q-keyboard { display: flex; gap: .6rem; }
.q-keyboard input { flex: 1; }

.q-proposed {
    font-family: var(--font-head);
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    background: var(--dark-2);
    padding: 1.2rem;
    border-radius: var(--radius);
}
.tf-buttons { display: flex; gap: .8rem; }
.tf-btn { flex: 1; padding: 1rem; font-size: 1.1rem; }
.tf-false { background: var(--red); }

/* Feedback colle en bas : le bouton Suivant reste visible sans scroller sur mobile */
.q-feedback {
    position: sticky;
    bottom: 0;
    margin-top: auto;
    padding: .8rem 0 calc(.8rem + env(safe-area-inset-bottom));
    text-align: center;
    background: linear-gradient(transparent, var(--dark) 22%);
}
.q-feedback p { font-size: 1.1rem; font-weight: 700; }
.q-feedback .fb-ok { color: var(--lime); }
.q-feedback .fb-ko { color: var(--red); }
.q-feedback .fb-latin { color: var(--text-dim); font-style: italic; font-weight: 400; font-size: .9rem; }

.r-emoji { font-size: 4rem; margin: 0; }
.r-xp { color: var(--lime); font-weight: 700; font-size: 1.2rem; }
.r-badges { display: flex; gap: .8rem; justify-content: center; flex-wrap: wrap; margin: 1rem 0; }
.r-badge {
    background: var(--dark-2);
    border: 1px solid var(--lime);
    border-radius: var(--radius);
    padding: .6rem 1rem;
    animation: pop .4s;
}
@keyframes pop { 0% { transform: scale(0); } 80% { transform: scale(1.1); } 100% { transform: scale(1); } }
.r-actions { display: flex; gap: .8rem; justify-content: center; margin-top: 1.5rem; }

/* --- Classement --- */
.tabs { display: flex; gap: .4rem; margin: 1rem 0; }
.tab {
    padding: .5rem 1rem;
    border-radius: 999px;
    background: var(--dark-2);
    color: var(--text);
    font-weight: 600;
    font-size: .9rem;
}
.tab.active { background: var(--lime); color: var(--dark); }
.cat-filter { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.myrank { color: var(--text-dim); }

.leaderboard { list-style: none; padding: 0; margin: 0; }
.lb-row {
    display: flex;
    align-items: center;
    gap: .8rem;
    background: var(--dark-2);
    border-radius: var(--radius);
    padding: .7rem 1rem;
    margin-bottom: .5rem;
}
.lb-me { border: 1px solid var(--lime); }
.lb-rank { font-family: var(--font-head); font-weight: 700; min-width: 2.4rem; }
.lb-avatar { font-size: 1.3rem; }
.lb-name { flex: 1; font-weight: 600; }
.lb-streak { font-size: .8rem; color: var(--text-dim); }
.lb-xp { font-family: var(--font-head); font-weight: 700; color: var(--lime); }

/* --- Profil --- */
.profile-head { display: flex; gap: 1.2rem; align-items: flex-start; margin-top: 1rem; }
.profile-head h1 { margin: 0; }
.profile-head > div { flex: 1; }
.profile-sub { color: var(--text-dim); margin: .3rem 0; }
.avatar-btn {
    font-size: 2.2rem;
    background: var(--dark-2);
    border: 2px solid var(--dark-3);
    border-radius: 50%;
    width: 72px; height: 72px;
    cursor: pointer;
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .7rem; }
.stat-card {
    background: var(--dark-2);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}
.stat-card strong { display: block; font-family: var(--font-head); font-size: 1.5rem; color: var(--lime); }
.stat-card span { font-size: .8rem; color: var(--text-dim); }

.progress-row { display: flex; align-items: center; gap: .8rem; margin-bottom: .6rem; }
.pr-name { min-width: 130px; font-size: .9rem; font-weight: 600; }
.pr-track {
    flex: 1; height: 12px;
    background: var(--dark-2);
    border-radius: 6px;
    overflow: hidden;
    display: flex;
}
.pr-mastered { background: var(--lime); height: 100%; }
.pr-seen { background: var(--dark-3); height: 100%; }
.pr-count { font-size: .75rem; color: var(--text-dim); min-width: 100px; text-align: right; }
.hint { color: var(--text-dim); font-size: .85rem; }

.boxes { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; }
.box-card { background: var(--dark-2); border-radius: 10px; padding: .7rem .3rem; text-align: center; }
.box-card strong { display: block; font-family: var(--font-head); color: var(--lime); }
.box-card span { font-size: .7rem; color: var(--text-dim); }

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: .7rem; }
.badge-card {
    background: var(--dark-2);
    border-radius: var(--radius);
    padding: .8rem .4rem;
    text-align: center;
}
.badge-card.locked { opacity: .3; filter: grayscale(1); }
.badge-icon { font-size: 1.6rem; display: block; }
.badge-name { font-size: .72rem; font-weight: 600; }

.session-list { list-style: none; padding: 0; margin: 0; }
.session-list li {
    display: flex;
    align-items: center;
    gap: .8rem;
    background: var(--dark-2);
    border-radius: 10px;
    padding: .55rem .9rem;
    margin-bottom: .4rem;
    font-size: .9rem;
}
.session-list li span:first-child { flex: 1; font-weight: 600; }
.session-mode { color: var(--text-dim); font-size: .8rem; }
.session-score { font-family: var(--font-head); font-weight: 700; }
.session-xp { color: var(--lime); font-size: .85rem; }

/* --- Admin --- */
.page-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .8rem; }
.admin-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .8rem; margin: 1.5rem 0; }
.admin-link {
    background: var(--dark-2);
    border-radius: var(--radius);
    padding: 1.2rem;
    font-family: var(--font-head);
    font-weight: 700;
    color: var(--text);
    text-align: center;
}
.admin-link:hover { background: var(--dark-3); }

.table { width: 100%; border-collapse: collapse; margin-top: 1rem; font-size: .9rem; }
.table th { text-align: left; color: var(--text-dim); font-weight: 600; padding: .5rem .6rem; border-bottom: 1px solid var(--dark-3); }
.table td { padding: .5rem .6rem; border-bottom: 1px solid var(--dark-2); }
.thumb { width: 52px; height: 40px; object-fit: cover; border-radius: 6px; }
.thumb-none { font-size: 1.3rem; }
.row-actions { display: flex; gap: .4rem; align-items: center; }
.row-actions form { display: inline; margin: 0; }

/* --- Cartes de revision (flashcards) --- */
.study-counter { font-family: var(--font-head); font-weight: 700; color: var(--lime); min-width: 3.2rem; text-align: right; }
.study-hint { text-align: center; color: var(--text-dim); font-size: .85rem; margin: .2rem 0 .8rem; }

.card-stage { perspective: 1200px; flex: 1; display: flex; min-height: 0; }
.flashcard {
    width: 100%;
    height: min(430px, 56dvh);
    margin: auto;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}
.flashcard-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform .45s cubic-bezier(.4, 1.4, .6, 1);
}
.flashcard-inner.is-flipped { transform: rotateY(180deg); }
.flashcard-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: var(--radius);
    /* PAS d'overflow: hidden ici : ca casse backface-visibility sous Chrome */
}
.flashcard-front { background: var(--dark-2); border-radius: var(--radius); }
.flashcard-front img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: var(--radius); }
.flashcard-front .q-credit { border-radius: 6px 0 var(--radius) 0; }
.flashcard-back {
    transform: rotateY(180deg);
    background: linear-gradient(160deg, var(--dark-2), var(--dark-3));
    border: 2px solid var(--lime);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    padding: 1.5rem;
    text-align: center;
}
.card-answer { font-family: var(--font-head); font-size: 1.7rem; font-weight: 700; color: var(--lime); }
.card-latin { color: var(--text-dim); font-style: italic; }

.study-actions { display: flex; gap: .8rem; margin-top: 1rem; }
.study-btn { flex: 1; padding: .9rem; font-size: 1.05rem; }
.study-btn-no { background: var(--red); }
.study-nav { display: flex; justify-content: space-between; margin-top: .8rem; }

/* --- Mobile --- */
@media (max-width: 640px) {
    .table { display: block; overflow-x: auto; }
    .profile-head { flex-direction: column; align-items: center; text-align: center; }
    .pr-name { min-width: 105px; }
    .pr-count { min-width: 80px; }

    h1 { font-size: 1.35rem; }
    .container { padding: .8rem .8rem 5.5rem; }
    .hero { padding: 2rem 0 1.2rem; }
    .hero h1 { font-size: 1.6rem; }

    /* Cibles tactiles genereuses en jeu */
    .choice-btn { padding: 1rem; font-size: 1.05rem; }
    .q-choices { gap: .6rem; }
    .q-prompt { font-size: 1.1rem; }
    .tf-btn { padding: 1.1rem; }
    .q-keyboard { flex-direction: column; }
    .q-keyboard .btn { width: 100%; }

    .topnav { gap: .5rem; }
    .topnav-user { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (max-width: 420px) {
    .xpbar { display: none; }
    .option-grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 900px) {
    .bottomnav { display: none; }
    .container { padding-bottom: 2rem; }
}

/* Etat actif de la barre du bas */
.bn-item.active { color: var(--lime); }
