/*
 * Memory Match — mini-jeu intégré (page Partnership)
 *
 * Tous les styles sont isolés sous #memory-game et préfixés "mg-" afin de
 * n'avoir AUCUN impact sur le reste de la page (Bulma définit déjà .card,
 * .subtitle, etc.). Les couleurs principales (--main-blue-*, --main-yellow,
 * --main-white) proviennent de custom.css.
 *
 * @author LGI Sustainable Innovation
 */

/* ── Variables propres au jeu ── */
#memory-game {
    --main-blue-pale: #e8f0fb;
    --text-main: #205aa9;
    --text-muted: #5b7ba8;
    --shadow-card: 0 10px 20px 0 rgb(0 0 0 / 12%);
    --shadow-card-hover: 0 14px 28px rgba(32, 90, 169, 0.25);

    /* Mises à jour par le JS selon la taille des cartes */
    --card-emoji-size: 2rem;
    --card-text-size: 0.9rem;
}

/* Reset local (limité au widget pour ne pas toucher au reste de la page) */
#memory-game *,
#memory-game *::before,
#memory-game *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ── Écran de démarrage (bouton START) ──
 * Le jeu n'est chargé/affiché qu'après un clic sur START : .mg-wrap reste
 * masqué tant que #memory-game ne porte pas la classe .mg-started.
 */
#memory-game .mg-start {
    display: flex;
    justify-content: center;
    padding: clamp(24px, 7vh, 72px) 0;
}

#memory-game.mg-started .mg-start {
    display: none;
}

#memory-game .mg-btn-start {
    font-family: "Montserrat", sans-serif;
    font-weight: 700;
    font-size: clamp(1rem, 2.4vw, 1rem);
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 16px 48px;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    color: var(--main-white);
    background: linear-gradient(
        135deg,
        var(--main-blue-dark),
        var(--main-blue-medium)
    );
    box-shadow: 0 10px 24px rgba(32, 90, 169, 0.3);
    display: inline-flex;
    align-items: center;
    gap: 12px;
    transition:
        transform 0.18s ease,
        box-shadow 0.18s ease;
}

#memory-game .mg-btn-start:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 14px 30px rgba(32, 90, 169, 0.38);
}

#memory-game .mg-btn-start:active {
    transform: scale(0.97);
}

#memory-game .mg-btn-start .mg-start-icon {
    width: 1.1em;
    height: 1.1em;
    flex-shrink: 0;
    color: var(--main-yellow);
}

/* ── Conteneur du jeu (remplace les styles plein écran du <body> d'origine) ── */
#memory-game .mg-wrap {
    display: none; /* révélé une fois START cliqué (#memory-game.mg-started) */
    flex-direction: column;
    align-items: center;
    gap: clamp(18px, 3vh, 32px);
    font-family:
        "Roboto", "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS",
        sans-serif;
    color: var(--text-main);
}

#memory-game.mg-started .mg-wrap {
    display: flex;
}

/* ── Header ── */
#memory-game .mg-header {
    text-align: center;
}

#memory-game .mg-header h1 {
    font-family: "Montserrat", "Gill Sans", Calibri, sans-serif;
    font-weight: 700;
    font-size: clamp(1.6rem, 4vh, 2.4rem);
    letter-spacing: -1px;
    margin-bottom: 6px;
    color: var(--main-blue-dark);
    line-height: 1;
}

#memory-game .mg-header h1 span {
    color: var(--main-blue-medium);
    position: relative;
    display: inline-block;
}

/* Accent jaune discret — fine ligne */
#memory-game .mg-header h1 span::after {
    content: "";
    position: absolute;
    left: 0;
    width: 24px;
    bottom: -4px;
    height: 2px;
    background-color: var(--main-yellow);
    border-radius: 2px;
}

#memory-game .mg-subtitle {
    font-family: "Montserrat", sans-serif;
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-top: 12px;
    opacity: 0.7;
}

/* ── Barre de stats ── */
#memory-game .mg-stats-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(28px, 5vw, 56px);
}

#memory-game .mg-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 56px;
}

#memory-game .mg-stat-label {
    font-family: "Montserrat", sans-serif;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 2.5px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 4px;
}

#memory-game .mg-stat-value {
    font-family: "Montserrat", sans-serif;
    font-size: clamp(1.15rem, 2.6vh, 1.6rem);
    font-weight: 700;
    color: var(--main-blue-dark);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.5px;
}

#memory-game .mg-stat-sep {
    width: 1px;
    height: 28px;
    background: rgba(32, 90, 169, 0.12);
}

/* ── Grille ── */
#memory-game #mg-grid {
    display: grid;
    perspective: 1000px;
    margin: 0 auto;
}

/* ── Cartes ── */
#memory-game .mg-card {
    perspective: 1000px;
    cursor: pointer;
}

#memory-game .mg-card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition:
        transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1),
        box-shadow 0.3s ease;
    border-radius: 14px;
    box-shadow: var(--shadow-card);
}

#memory-game .mg-card:not(.flipped):not(.matched):hover .mg-card-inner {
    transform: rotateY(5deg) scale(1.04) translateY(-4px);
    box-shadow: var(--shadow-card-hover);
}

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

#memory-game .mg-card-face {
    position: absolute;
    inset: 0;
    border-radius: 14px;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--card-emoji-size, 2rem);
    user-select: none;
    overflow: hidden;
}

/* Dos de carte : dégradé bleu LGI avec "?" jaune */
#memory-game .mg-card-back {
    background: linear-gradient(
        135deg,
        var(--main-blue-dark),
        var(--main-blue-medium)
    );
    border: 1px solid rgba(255, 255, 255, 0.2);
}

#memory-game .mg-card-back::before {
    content: "";
    position: absolute;
    inset: -50%;
    background: repeating-linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.06) 0px,
        rgba(255, 255, 255, 0.06) 2px,
        transparent 2px,
        transparent 14px
    );
}

#memory-game .mg-card-back::after {
    content: "?";
    font-family: "Montserrat", sans-serif;
    font-weight: 800;
    font-size: var(--card-emoji-size, 2rem);
    color: var(--main-yellow);
    position: relative;
    z-index: 2;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

#memory-game .mg-card-front {
    background: var(--main-white);
    transform: rotateY(180deg);
    border: 2px solid var(--main-blue-light);
    font-family: "Montserrat", sans-serif;
    font-weight: 700;
    font-size: var(--card-text-size, 0.9rem);
    color: var(--main-blue-dark);
    padding: 6px;
    text-align: center;
    line-height: 1.15;
    word-break: break-word;
    hyphens: auto;
}

#memory-game .mg-card[data-type="ua"] .mg-card-front {
    border: 3px solid var(--main-yellow);
}

#memory-game .mg-card[data-type="eu"] .mg-card-front {
    border: 3px solid var(--main-blue-medium);
}

/* Trouvée : tout passe au vert — fond ET bordure — quel que soit le type (ua/eu).
 * La sélection [data-type] porte la même spécificité que les règles ci-dessus :
 * on la place donc APRÈS pour que le vert l'emporte. */
#memory-game .mg-card.matched .mg-card-front {
    background: #e8f5e9;
    box-shadow: 0 4px 12px rgba(46, 125, 50, 0.15);
}

#memory-game .mg-card.matched[data-type] .mg-card-front {
    border-color: #2e7d32;
}

#memory-game .mg-flag-container {
    position: absolute;
    top: 6px;
    right: 8px;
    z-index: 3;
    pointer-events: none;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

#memory-game .mg-flag-icon {
    display: block;
    border-radius: 1px;
    border: 0.5px solid rgba(255, 255, 255, 0.3);
}

#memory-game .mg-card.matched {
    cursor: default;
    pointer-events: none;
    animation: mgMatchPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

#memory-game .mg-card.shake .mg-card-inner {
    animation: mgShake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

/* ── Contrôles — boutons "pill" ── */
#memory-game .mg-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

#memory-game #mg-difficulty,
#memory-game #mg-btn-restart,
#memory-game #mg-btn-help {
    font-family: "Montserrat", sans-serif;
    font-weight: 600;
    font-size: 0.82rem;
    letter-spacing: 0.3px;
    padding: 9px 18px;
    border-radius: 999px;
    cursor: pointer;
    transition:
        background-color 0.18s ease,
        color 0.18s ease,
        border-color 0.18s ease,
        transform 0.18s ease;
    line-height: 1;
}

#memory-game #mg-difficulty {
    background-color: transparent;
    color: var(--text-main);
    border: 1px solid rgba(32, 90, 169, 0.2);
    appearance: none;
    -webkit-appearance: none;
    padding-right: 34px;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23205aa9%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 14px top 50%;
    background-size: 8px auto;
}

#memory-game #mg-difficulty:hover,
#memory-game #mg-difficulty:focus {
    border-color: var(--main-blue-medium);
    outline: none;
}

#memory-game #mg-difficulty option {
    background: var(--main-white);
    color: var(--main-blue-dark);
}

/* Action principale — bleu plein */
#memory-game #mg-btn-restart {
    background: var(--main-blue-dark);
    color: var(--main-white);
    border: 1px solid var(--main-blue-dark);
}

#memory-game #mg-btn-restart:hover {
    background: var(--main-blue-medium);
    border-color: var(--main-blue-medium);
}

#memory-game #mg-btn-restart:active {
    transform: scale(0.97);
}

/* Action secondaire — fantôme avec accent jaune sur l'icône */
#memory-game #mg-btn-help {
    background: transparent;
    color: var(--text-main);
    border: 1px solid rgba(32, 90, 169, 0.2);
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

#memory-game #mg-btn-help .mg-btn-icon {
    width: 1em;
    height: 1em;
    flex-shrink: 0;
    color: var(--main-yellow);
    filter: drop-shadow(0 0 0.5px rgba(254, 221, 0, 0.4));
}

#memory-game #mg-btn-help:hover:not(:disabled) {
    border-color: var(--main-yellow);
    background: rgba(254, 221, 0, 0.08);
}

#memory-game #mg-btn-help:active:not(:disabled) {
    transform: scale(0.97);
}

#memory-game #mg-btn-help:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#memory-game .mg-help-count-sep {
    margin: 0 6px;
    opacity: 0.35;
}

#memory-game #mg-help-count {
    font-variant-numeric: tabular-nums;
    opacity: 0.6;
    font-weight: 500;
}

/* ── Overlay de victoire ── */
#mg-win-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(32, 90, 169, 0.35);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

#mg-win-overlay.show {
    display: flex;
    animation: mgFadeIn 0.4s ease forwards;
}

#mg-win-overlay .mg-win-box {
    position: relative;
    background: var(--main-white);
    border-radius: 20px;
    padding: 48px 44px 36px;
    box-shadow: 0 20px 60px rgba(32, 90, 169, 0.18);
    max-width: 380px;
    width: 90%;
    text-align: center;
    transform: scale(0.9);
    opacity: 0;
    animation: mgPopIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s forwards;
    overflow: hidden;
}

/* Fine ligne jaune en haut */
#mg-win-overlay .mg-win-box::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--main-yellow);
}

#mg-win-overlay .mg-win-title {
    font-family: "Montserrat", sans-serif;
    font-size: clamp(1.6rem, 3.5vw, 2.1rem);
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 14px;
    color: var(--main-blue-dark);
    line-height: 1.1;
}

#mg-win-overlay .mg-win-stats {
    color: var(--text-muted);
    font-family: "Roboto", sans-serif;
    font-size: 0.95rem;
    margin-bottom: 28px;
    line-height: 1.6;
}

#mg-win-overlay .mg-win-stats strong {
    color: var(--main-blue-dark);
    font-weight: 700;
    font-size: inherit;
    font-variant-numeric: tabular-nums;
}

#mg-win-overlay #mg-btn-play-again {
    font-family: "Montserrat", sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
    letter-spacing: 0.3px;
    padding: 12px 32px;
    width: 100%;
    background: var(--main-blue-dark);
    color: var(--main-white);
    border: 1px solid var(--main-blue-dark);
    border-radius: 999px;
    cursor: pointer;
    transition:
        background-color 0.2s ease,
        border-color 0.2s ease,
        transform 0.2s ease;
}

#mg-win-overlay #mg-btn-play-again:hover {
    background: var(--main-blue-medium);
    border-color: var(--main-blue-medium);
}

#mg-win-overlay #mg-btn-play-again:active {
    transform: scale(0.98);
}

/* ── Animations ── */
@keyframes mgMatchPop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.08);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes mgShake {
    10%,
    90% {
        transform: rotateY(180deg) translateX(-2px);
    }

    20%,
    80% {
        transform: rotateY(180deg) translateX(4px);
    }

    30%,
    50%,
    70% {
        transform: rotateY(180deg) translateX(-8px);
    }

    40%,
    60% {
        transform: rotateY(180deg) translateX(8px);
    }
}

@keyframes mgFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes mgPopIn {
    0% {
        transform: scale(0.8) translateY(20px);
        opacity: 0;
    }

    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}
