/* ============================================================
   VARIABLES
   ============================================================ */
:root {
    --primary: #4f46e5;
    --primary-dark: #3730a3;
    --accent: #f59e0b;
    --success: #10b981;
    --danger: #ef4444;
    --purple: #764ba2;
    --bg: #0f0f1a;
    --bg-2: #1a1040;
    --text: #1e293b;
    --text-muted: #64748b;
    --radius: 16px;
}

/* ============================================================
   BASE
   ============================================================ */
body {
    font-family: "Nunito", sans-serif;
    background: linear-gradient(135deg, var(--bg) 0%, var(--bg-2) 100%);
    min-height: 100vh;
    color: white;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: "Fredoka", sans-serif;
    font-weight: 600;
}

/* ===== TEXTE ===== */
.text-muted {
    color: rgba(255, 255, 255, 0.6) !important;
}

/* ============================================================
   FOND ANIMÉ — ÉTOILES
   ============================================================ */
#stars-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.star {
    position: absolute;
    background: white;
    border-radius: 50%;
    animation: twinkle 3s infinite alternate;
    opacity: 0.7;
}

@keyframes twinkle {
    from {
        opacity: 0.2;
        transform: scale(1);
    }
    to {
        opacity: 1;
        transform: scale(1.3);
    }
}

/* ============================================================
   MISE EN PAGE — SIDEBAR / TOPBAR / OFFCANVAS
   ============================================================ */
aside {
    background: rgba(79, 70, 229, 0.15) !important;
    backdrop-filter: blur(20px);
    border-right: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.sidebar {
    width: 240px;
    flex-shrink: 0;
}

.sidebar-tagline {
    color: rgba(255, 255, 255, 0.6);
}

.sidebar-hr {
    border-color: rgba(255, 255, 255, 0.2);
}

.sidebar-admin {
    color: rgba(255, 255, 255, 0.6);
}

.topbar {
    height: 60px;
    background: rgba(255, 255, 255, 0.05) !important;
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    color: white;
    position: relative;
    z-index: 10;
}

.topbar h5 {
    color: white;
}

.offcanvas-sidebar {
    background: rgba(79, 70, 229, 0.25) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border-right: 1px solid rgba(255, 255, 255, 0.1) !important;
    width: 260px !important;
}

.offcanvas-sidebar .offcanvas-header,
.offcanvas-sidebar .offcanvas-body {
    background: transparent !important;
}

.sidebar-toggler {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 1.2rem;
    line-height: 1;
    padding: 4px 10px;
    border-radius: 8px;
}

.sidebar-toggler:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.flex-grow-1 {
    position: relative;
    z-index: 1;
}

/* ============================================================
   BOUTONS
   ============================================================ */
.btn-primary {
    background-color: var(--primary);
    border-color: var(--primary-dark);
    border-bottom: 4px solid var(--primary-dark);
    border-radius: var(--radius);
    font-family: "Nunito", sans-serif;
    font-weight: 700;
}

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

.btn-action-green {
    background: #4caf50 !important;
    border-bottom: 4px solid #388e3c;
    font-size: 16px;
}

.btn-action-red {
    background: #f44336 !important;
    border-bottom: 4px solid #c62828;
    font-size: 16px;
}

.btn-action-blue {
    background: #2196f3 !important;
    border-bottom: 4px solid #1565c0;
    font-size: 16px;
}

.btn-action-orange {
    background: #ff9800 !important;
    border-bottom: 4px solid #e65100;
    font-size: 16px;
}

/* ============================================================
   CARTES
   ============================================================ */
.card {
    border-radius: var(--radius) !important;
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    color: white !important;
}

/* ============================================================
   TABLEAUX
   ============================================================ */
.table {
    --bs-table-color: white !important;
    --bs-table-bg: transparent !important;
    --bs-table-striped-bg: rgba(255, 255, 255, 0.03) !important;
    --bs-table-hover-bg: rgba(255, 255, 255, 0.05) !important;
    --bs-table-border-color: rgba(255, 255, 255, 0.05) !important;
    color: white !important;
}

.table-light {
    --bs-table-color: white !important;
    --bs-table-bg: rgba(255, 255, 255, 0.05) !important;
    color: white !important;
}

.table-hover tbody tr:hover {
    --bs-table-hover-bg: rgba(255, 255, 255, 0.05) !important;
    --bs-table-hover-color: white !important;
    color: white !important;
}

/* ============================================================
   FORMULAIRES
   ============================================================ */
.form-control,
.form-select {
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    color: white !important;
    width: 100% !important;
}

.form-control:focus,
.form-select:focus {
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: var(--primary) !important;
    color: white !important;
    box-shadow: 0 0 0 0.25rem rgba(79, 70, 229, 0.25) !important;
}

.form-control::placeholder {
    color: rgba(255, 255, 255, 0.4) !important;
}

label {
    color: rgba(255, 255, 255, 0.8) !important;
}

select option {
    background: #1a1040;
    color: white;
}

/* Layout des champs (espacement label / input) */
.form-group label,
.mb-3 > label,
.mb-3 > div > label {
    display: block;
    margin-bottom: 6px;
}

.mb-3 > div > input,
.mb-3 > div > textarea,
.mb-3 > div > select {
    margin-top: 4px;
}

/* Autofill navigateur (Chrome/Edge) en dark mode */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px rgba(15, 15, 26, 0.9) inset !important;
    -webkit-text-fill-color: white !important;
    caret-color: white !important;
}

/* Barre de recherche (input + bouton groupés) */
.input-group input[type="search"] {
    border-radius: 8px 0 0 8px !important;
    flex: 1;
}

.input-group .btn {
    border-radius: 0 8px 8px 0 !important;
}

/* ============================================================
   ALERTES
   ============================================================ */
.alert-info {
    background: rgba(79, 70, 229, 0.2) !important;
    border-color: rgba(79, 70, 229, 0.3) !important;
    color: white !important;
}

/* ============================================================
   BADGES / BANNIÈRES
   ============================================================ */
.badge-theme {
    background: var(--primary);
    color: white;
}

.banner-welcome {
    background: linear-gradient(135deg, var(--primary), var(--purple));
}

/* Bannière thème — texte toujours blanc peu importe le mode */
.banner-theme h2,
.banner-theme p {
    color: white !important;
}

/* ============================================================
   SUJETS
   ============================================================ */
.subject-image {
    width: 100px;
    height: 100px;
    object-fit: contain;
    margin: 0 auto;
    display: block;
}

.subject-emoji {
    font-size: 3rem;
}

.subject-image-lg {
    width: 180px;
    height: 180px;
    object-fit: contain;
    margin: 0 auto;
    display: block;
}

.subject-emoji-lg {
    font-size: 5rem;
}

.subject-content {
    line-height: 1.8;
}

/* ============================================================
   MEMORY GAME
   ============================================================ */
.memory-card {
    width: 130px;
    height: 130px;
    cursor: pointer;
    perspective: 1000px;
}

.card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.5s;
}

.memory-card.flipped .card-inner,
.memory-card.matched .card-inner {
    transform: rotateY(180deg);
}

.card-front,
.card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.card-front {
    background: var(--primary);
    color: white;
}

.card-back {
    background: white;
    transform: rotateY(180deg);
    border: 2px solid var(--primary);
}

.card-back img {
    width: 100px;
    height: 100px;
    object-fit: contain;
}

.card-back span {
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--primary);
    text-align: center;
    padding: 5px;
}

.memory-card.matched .card-back {
    background: rgba(16, 185, 129, 0.2);
    border-color: var(--success);
}

/* ============================================================
   MODE CLAIR (LIGHT MODE)
   ============================================================ */

/* --- Base --- */
body.light-mode {
    background: linear-gradient(135deg, #f0f4ff 0%, #e8eeff 100%);
    color: var(--text);
}

body.light-mode h1,
body.light-mode h2,
body.light-mode h3,
body.light-mode h4,
body.light-mode h5,
body.light-mode h6 {
    color: var(--text);
}

body.light-mode .text-muted {
    color: var(--text-muted) !important;
}

body.light-mode .text-white {
    color: var(--text) !important;
}

body.light-mode .text-white-50 {
    color: rgba(55, 48, 163, 0.6) !important;
}

/* --- Fond animé --- */
body.light-mode #stars-bg {
    opacity: 0.3;
}

/* --- Mise en page --- */
body.light-mode aside {
    background: rgba(79, 70, 229, 0.12) !important;
    border-right: 1px solid rgba(79, 70, 229, 0.2) !important;
}

body.light-mode .sidebar-link,
body.light-mode .sidebar-admin {
    color: #3730A3 !important;
}

body.light-mode .sidebar-tagline {
    color: rgba(55, 48, 163, 0.7);
}

body.light-mode .sidebar-hr {
    border-color: rgba(79, 70, 229, 0.2);
}

body.light-mode .topbar {
    background: rgba(255, 255, 255, 0.8) !important;
    border-bottom: 1px solid rgba(79, 70, 229, 0.15) !important;
    color: var(--text);
}

body.light-mode .topbar h5 {
    color: var(--text);
}

body.light-mode .offcanvas-sidebar {
    background: rgba(240, 244, 255, 0.97) !important;
}

/* --- Cartes --- */
body.light-mode .card {
    background: rgba(255, 255, 255, 0.9) !important;
    border: 1px solid rgba(79, 70, 229, 0.15) !important;
    color: var(--text) !important;
}

/* --- Tableaux --- */
body.light-mode .table {
    --bs-table-color: var(--text) !important;
    --bs-table-bg: transparent !important;
    --bs-table-border-color: rgba(79, 70, 229, 0.1) !important;
    color: var(--text) !important;
}

body.light-mode .table-light {
    --bs-table-color: var(--text) !important;
    --bs-table-bg: rgba(79, 70, 229, 0.05) !important;
    color: var(--text) !important;
}

body.light-mode .table-hover tbody tr:hover {
    --bs-table-hover-bg: rgba(79, 70, 229, 0.08) !important;
    --bs-table-hover-color: var(--text) !important;
    color: var(--text) !important;
}

body.light-mode .table-hover tbody tr:hover td {
    color: var(--text) !important;
}

/* --- Formulaires --- */
body.light-mode .form-control,
body.light-mode .form-select {
    background: white !important;
    border: 1px solid rgba(79, 70, 229, 0.3) !important;
    color: var(--text) !important;
}

body.light-mode .form-control:focus,
body.light-mode .form-select:focus {
    background: white !important;
    color: var(--text) !important;
}

body.light-mode .form-control::placeholder {
    color: #94a3b8 !important;
}

body.light-mode label {
    color: var(--text) !important;
}

body.light-mode select option {
    background: white;
    color: var(--text);
}

/* --- Alertes --- */
body.light-mode .alert-info {
    background: rgba(79, 70, 229, 0.1) !important;
    border-color: rgba(79, 70, 229, 0.2) !important;
    color: var(--text) !important;
}

/* ===== MEMORY GAME — RESPONSIVE MOBILE ===== */
@media (max-width: 576px) {
    #memory-grid {
        gap: 0.5rem !important;
    }

    .memory-card {
        width: 78px;
        height: 78px;
    }

    .card-front {
        font-size: 1.4rem;
    }

    .card-back img {
        width: 55px;
        height: 55px;
    }

    .card-back span {
        font-size: 0.65rem;
        padding: 2px;
    }
}

@media (min-width: 577px) and (max-width: 768px) {
    .memory-card {
        width: 100px;
        height: 100px;
    }

    .card-back img {
        width: 75px;
        height: 75px;
    }
}