/* ============================================================
   Portail fanabriques.fr : la table LEGO en 3D (voir js/portail.js)
   ============================================================ */

.table {
    position: relative;
    display: block;
    /* Plus large que la colonne de texte : jusqu'à 1500 px, centrée.
       Plafonnée par la hauteur d'écran (portables) pour que la table et les légendes tiennent sans défiler,
       sans descendre sous 820 px de large. */
    --table-largeur: min(1500px, 100vw - 32px, max(820px, (100vh - 340px) * 2.1));
    width: var(--table-largeur);
    margin: 0 0 6px calc(50% - var(--table-largeur) / 2);
    aspect-ratio: 2.1 / 1;
}

.table canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    outline: none;
}

/* Visuels de repli tant que la 3D n'est pas prête (ou sans WebGL) */
.table-repli {
    position: absolute;
    inset: 0;
    display: flex;
    gap: 2%;
    justify-content: center;
    align-items: center;
}

.table-repli img {
    width: 40%;
    height: auto;
}

.table-repli a {
    display: contents;
}

.table-prete .table-repli {
    display: none;
}

/* Chargement : voile + briques qui s'empilent, seulement si ça traîne (pas de flash sur une bonne connexion) */
.table-chargement {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background-color: rgba(255, 255, 255, .7);
    border-radius: 12px;
    color: #1C325A;
    font-family: 'Luckiest Guy', Tahoma, sans-serif;
    font-size: 18px;
    letter-spacing: .03em;
    pointer-events: none;
    animation: table-apparition .3s ease-out .4s both;
}

.table-prete .table-chargement,
.table-echec .table-chargement {
    display: none;
}

@keyframes table-apparition {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.table-briques {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    height: 66px;
}

/* Une brique 2x4 vue de face : corps + deux tenons */
.table-briques i {
    position: relative;
    display: block;
    width: 48px;
    height: 18px;
    margin-top: 4px;
    border-radius: 2px;
    background-color: var(--brique);
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .18);
    animation: table-brique 1.8s ease-in infinite;
}

.table-briques i::before {
    content: "";
    position: absolute;
    top: -5px;
    left: 8px;
    right: 8px;
    height: 5px;
    background: linear-gradient(to right, var(--brique) 0 10px, transparent 10px calc(100% - 10px), var(--brique) calc(100% - 10px));
    border-radius: 2px 2px 0 0;
}

.table-briques i:nth-child(1) { --brique: #d01012; animation-delay: 0s; }
.table-briques i:nth-child(2) { --brique: #f5cd2f; animation-delay: .25s; }
.table-briques i:nth-child(3) { --brique: #0055bf; animation-delay: .5s; }

/* Chaque brique tombe sur la précédente, la pile reste un moment, puis on recommence */
@keyframes table-brique {
    0%       { transform: translateY(-60px); opacity: 0; }
    15%      { transform: translateY(0); opacity: 1; }
    19%      { transform: translateY(-4px); }
    23%, 80% { transform: translateY(0); opacity: 1; }
    95%, 100% { transform: translateY(0); opacity: 0; }
}

/* Échec : les images restent, cliquables, et l'aide au toucher (Bricky) n'a plus lieu d'être */
.table-echec .table-repli img {
    cursor: pointer;
    transition: transform .25s;
}

.table-echec .table-repli a:hover img {
    transform: translateY(-4px) scale(1.02);
}

.table-echec + .table-aide {
    display: none;
}

/* Légendes cliquables sous la table */
.choix {
    align-items: flex-start;
}

.batiment {
    text-decoration: none;
    color: #1C325A;
    outline: none;
    padding: 10px 12px;
    border-radius: 8px;
    transition: background-color .25s, transform .25s;
}

.batiment:hover,
.batiment:focus-visible,
.batiment-survole {
    background-color: rgba(255, 255, 255, .55);
    transform: translateY(-2px);
}

.legende {
    display: block;
    font-size: 15px;
    line-height: 1.35;
}

.legende b {
    display: block;
    font-size: 1.35em;
    margin-bottom: 2px;
}

.batiment .choix-badge {
    top: -14px;
    right: 8px;
    z-index: 5;
}

/* Aide au toucher, uniquement sur mobile */
.table-aide {
    display: none;
    margin: 0 0 10px 0;
    font-size: 13px;
    color: #1C325A;
    opacity: .8;
}

@media screen and (max-width: 767px) {
    .table {
        aspect-ratio: 4 / 3;
        margin-left: -16px;
        margin-right: -16px;
        width: auto;
    }

    .table-aide {
        display: block;
    }

    .choix {
        gap: 10px;
    }

    .batiment {
        width: 100%;
        max-width: 420px;
        background-color: rgba(255, 255, 255, .55);
    }

    .batiment .choix-badge {
        top: -10px;
        right: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .batiment {
        transition: none;
    }

    .table-briques i {
        animation: none;
    }
}
