/* Mots cachés : menu indépendant sur le modèle des motscaches.
   Styles isolés ; aucun changement des autres menus du site. */
#main1 > .motscaches-menu {
    grid-column: 1 / span 6;
    grid-row: 5;
    order: 7;
    min-width: 0;
    margin: 10px 0 0;
}

/* Le contenu utilise la place libérée par l'ancien menu latéral. */
.motscaches-page #contenu > .thirdRowCenterContenu {
    grid-column: 1 / span 6;
    min-width: 0;
}

.motscaches-menu,
.motscaches-menu * {
    box-sizing: border-box;
}

.motscaches-menu {
    position: relative;
    z-index: 10;
    width: 100%;
    border: 1px solid #52711f;
    border-top-color: #8bc135;
    border-radius: 6px;
    background: linear-gradient(to bottom, #658c26, #354914);
    color: #fff;
    font: 14px/1.5 Arial, Helvetica, sans-serif;
    text-align: left;
}

.motscaches-menu .motscaches-menu-categories,
.motscaches-menu .motscaches-menu-links {
    margin: 0;
    padding: 0;
    list-style: none;
}

.motscaches-menu .motscaches-menu-categories {
    display: flex;
}

.motscaches-menu .motscaches-menu-toggle[hidden],
.motscaches-menu .motscaches-menu-categories[hidden] {
    display: none;
}

.motscaches-menu .motscaches-menu-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 48px;
    margin: 0;
    padding: 12px 14px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: #fff;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.motscaches-menu .motscaches-menu-toggle-label {
    flex: 1;
    font: inherit;
    font-weight: bold;
}

.motscaches-menu .motscaches-menu-toggle-icon {
    font-size: 22px;
    line-height: 1;
}

.motscaches-menu .motscaches-menu-toggle::after {
    content: '';
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
}

.motscaches-menu .motscaches-menu-toggle[aria-expanded="true"]::after {
    transform: rotate(225deg) translate(-2px, -2px);
}

.motscaches-menu .motscaches-menu-toggle:not([hidden]) + .motscaches-menu-categories {
    border-top: 1px solid #ffffff40;
}

.motscaches-menu-categories > li {
    position: relative;
    flex: 0 1 auto;
    min-width: 0;
    margin: 0;
    padding: 0;
}

.motscaches-menu summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 46px;
    padding: 10px 14px;
    white-space: nowrap;
    cursor: pointer;
    list-style: none;
}

.motscaches-menu summary::-webkit-details-marker {
    display: none;
}

.motscaches-menu summary::after {
    content: '';
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
}

.motscaches-menu .motscaches-menu-current > summary {
    box-shadow: inset 0 -3px #ffffcc;
    font-weight: bold;
}

.motscaches-menu summary:hover,
.motscaches-menu details[open] > summary {
    background: #eee;
    color: #354914;
}

.motscaches-menu details[open] > summary::after {
    transform: rotate(225deg) translate(-2px, -2px);
}

.motscaches-menu summary:focus-visible,
.motscaches-menu a:focus-visible,
.motscaches-menu .motscaches-menu-toggle:focus-visible {
    outline: 3px solid #153e85;
    outline-offset: -3px;
    background: #fff;
    color: #1e3410;
}

.motscaches-menu .motscaches-menu-panel {
    position: absolute;
    top: 100%;
    right: auto;
    left: -1px;
    width: 300px;
    max-width: calc(100vw - 32px);
    padding: 14px;
    border: 1px solid #888;
    border-radius: 0 0 6px 6px;
    background: linear-gradient(to bottom, #eee, #ccc);
    color: #222;
    box-shadow: 0 5px 10px #0003;
}

.motscaches-menu .motscaches-menu-panel-wide {
    width: 520px;
}

/* Les trois dernières catégories se déploient vers la gauche. */
.motscaches-menu-categories > li:nth-last-child(-n+3) .motscaches-menu-panel {
    right: 0;
    left: auto;
}

.motscaches-menu .motscaches-menu-title {
    margin: 0 0 14px;
    padding: 0 0 10px;
    border-bottom: 1px solid #999;
    color: #a52a2a;
    font-size: 16px;
    font-weight: bold;
    text-align: left;
}

.motscaches-menu .motscaches-menu-links {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
}

.motscaches-menu .motscaches-menu-panel-wide .motscaches-menu-links {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.motscaches-menu-links li {
    margin: 0;
    padding: 0;
}

.motscaches-menu .motscaches-menu-links a {
    display: flex;
    align-items: center;
    height: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #aaa;
    border-radius: 3px;
    background: #f4f4f4;
    color: #354914;
    text-decoration: none;
    overflow-wrap: break-word;
}

.motscaches-menu .motscaches-menu-links a:hover {
    background: #fff;
    text-decoration: underline;
}

.motscaches-menu .motscaches-menu-links a[aria-current="page"] {
    border-color: #52711f;
    background: #eef4e1;
    font-weight: bold;
    text-decoration: underline;
}

@media (max-width: 1200px) {
    .motscaches-menu .motscaches-menu-categories {
        display: block;
    }

    .motscaches-menu-categories > li + li {
        border-top: 1px solid #ffffff40;
    }

    .motscaches-menu .motscaches-menu-panel {
        position: static;
        width: 100%;
        max-width: none;
        padding: 14px;
        border-right: 0;
        border-left: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .motscaches-menu .motscaches-menu-links {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 480px) {
    .motscaches-menu .motscaches-menu-links,
    .motscaches-menu .motscaches-menu-panel-wide .motscaches-menu-links {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media print {
    #main1 > .motscaches-menu {
        display: none;
    }
}

/* Raccordement limité à la page des mots cachés. */
.motscaches-page #contenu {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    min-width: 0;
}

.motscaches-page .motscaches-fil-ariane {
    box-sizing: border-box;
    padding: 0 20px;
    line-height: 1.8;
    overflow-wrap: break-word;
}

.motscaches-page .motscaches-niveaux {
    width: 100%;
    margin: 0 auto 10px;
}

.motscaches-page .niveau {
    gap: 4px;
}

.motscaches-page .niveau li a,
.motscaches-page .niveau li span,
.motscaches-page .niveau li p {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    margin: 0;
}

.motscaches-page #wordfind {
    max-width: 100%;
    aspect-ratio: 20 / 17;
}

/* Sur ordinateur, réserver de la hauteur au titre et aux niveaux.
   La largeur est limitée : le ratio hauteur/largeur 0,85 reste inchangé. */
@media (min-width: 641px) {
    .motscaches-page #wordfind {
        max-width: 760px;
        max-width: min(760px, calc((100vh - 180px) / 0.85));
    }
}

.motscaches-page #wordfindFrame {
    box-sizing: border-box;
    display: block;
}

/* Catalogue des 36 thèmes : cartes limitées à la page des mots cachés. */
.motscaches-page .motscaches-catalogue,
.motscaches-page .motscaches-catalogue * {
    box-sizing: border-box;
}

.motscaches-page .motscaches-catalogue {
    width: 90%;
    max-width: 1100px;
    min-width: 0;
    margin: 24px auto 32px;
}

.motscaches-page .motscaches-catalogue-titre {
    margin: 0 0 22px;
    padding: 0;
    color: #ffffcc;
    font-size: 18px;
    line-height: 1.4;
    text-align: center;
}

.motscaches-page .motscaches-cartes {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.motscaches-page .motscaches-cartes > li {
    min-width: 0;
    margin: 0;
    padding: 0;
}

.motscaches-page .motscaches-carte {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    height: 100%;
    min-width: 0;
    padding: 16px 12px;
    border: 1px solid #dedbc9;
    border-radius: 10px;
    background: #fffaf0;
    color: #293c37;
    box-shadow: 0 2px 5px rgba(63, 24, 24, 0.12);
    font: 600 15px/1.4 Arial, Helvetica, sans-serif;
    text-align: center;
    text-decoration: none;
}

.motscaches-page .motscaches-carte-image {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 118px;
    margin: 0;
    padding: 0;
}

.motscaches-page .motscaches-carte-image img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0;
}

.motscaches-page .motscaches-carte-libelle {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 2.8em;
    max-width: 100%;
    margin: 0;
    padding: 0;
    color: inherit;
    font: inherit;
    text-align: center;
    overflow-wrap: break-word;
}

/* Le contour de 3 px est visuel : il ne change pas la taille des cartes. */
.motscaches-page .motscaches-carte:hover,
.motscaches-page .motscaches-carte:focus-visible {
    border-color: #52711f;
    background: #eaf4d9;
    color: #293c37;
    box-shadow: 0 0 0 2px #52711f, 0 9px 18px rgba(63, 24, 24, 0.26);
}

@media (prefers-reduced-motion: no-preference) {
    .motscaches-page .motscaches-carte {
        transition: transform 160ms ease, background-color 160ms ease,
                    border-color 160ms ease, box-shadow 160ms ease;
    }
}

/* Soulèvement réservé au survol à la souris, sans déplacer les cartes voisines. */
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
    .motscaches-page .motscaches-carte:hover {
        transform: translateY(-4px);
    }
}

.motscaches-page .motscaches-carte:hover .motscaches-carte-libelle,
.motscaches-page .motscaches-carte:focus-visible .motscaches-carte-libelle {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.motscaches-page .motscaches-carte:focus-visible {
    outline: 3px solid #ffffcc;
    outline-offset: 3px;
}

@media (max-width: 900px) {
    .motscaches-page .motscaches-cartes {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .motscaches-page .motscaches-catalogue {
        width: calc(100% - 24px);
    }

    .motscaches-page .motscaches-cartes {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }

    .motscaches-page .motscaches-carte {
        padding: 12px 8px;
    }
}

@media (max-width: 300px) {
    .motscaches-page .motscaches-cartes {
        grid-template-columns: minmax(0, 1fr);
    }
}
