.team-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 40px;
    margin-top: 40px;
    padding-bottom: 80px;
}

.team-card {
    background-color: transparent;
    width: 100%;
    aspect-ratio: 1 / 1;
    /* Square ratio */
    perspective: 1200px;
    cursor: pointer;
    position: relative;
    z-index: 1;
}

.team-card.is-flipped {
    z-index: 100;
}

.team-card.is-unflipping {
    z-index: 99;
}

.team-card-inner {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1),
        width 0.6s cubic-bezier(0.4, 0.0, 0.2, 1),
        height 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
    transform-style: preserve-3d;
    transform: translate(-50%, -50%) rotateY(0deg);
    border-radius: 16px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
}

/* Expand horizontally (Landscape ratio e.g. 4:3) and scale 1.5x */
.team-card.is-flipped .team-card-inner {
    width: 180%;
    height: 110%;
    transform: translate(-50%, -50%) rotateY(540deg);
    transition: transform 1.2s cubic-bezier(0.4, 0.0, 0.2, 1),
        width 1.2s cubic-bezier(0.4, 0.0, 0.2, 1),
        height 1.2s cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Specific scale for the first card (CEO) - Square expansion */
.team-grid .team-card:first-child.is-flipped .team-card-inner {
    width: 150%;
    height: 150%;
}

/* Back to 1:1 square */
.team-card.is-unflipping .team-card-inner {
    width: 100%;
    height: 100%;
    transform: translate(-50%, -50%) rotateY(360deg);
    transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1),
        width 0.6s cubic-bezier(0.4, 0.0, 0.2, 1),
        height 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.team-card-front,
.team-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border-radius: 16px;
    overflow: hidden;
    background: transparent;
    display: flex;
    flex-direction: column;
    transform: translateZ(0);
    /* Forces GPU render and pre-paint to avoid white flash */
}

.team-card-back {
    transform: rotateY(180deg) translateZ(0);
}

.team-card-front img,
.team-card-back img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
}

.team-card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.4) 60%, transparent 100%);
    color: white;
    padding: 40px 20px 20px;
    text-align: left;
    box-sizing: border-box;
}

.team-card-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.3;
    font-family: 'Inter', sans-serif;
}

.name-highlight {
    color: #ffeb3b;
    /* Yellow color for the name */
}

/* Адаптация для мобильных устройств (чтобы не уходило за края экрана) */
@media (max-width: 768px) {
    .team-card.is-flipped .team-card-inner {
        /* На мобильных мы не можем увеличивать ширину (иначе вылезет за экран), 
           поэтому мы оставляем ширину 100%, но уменьшаем высоту до 70%, 
           чтобы получить ту же альбомную пропорцию (4:3) и показать фото целиком! */
        width: 100%;
        height: 65%;
    }

    /* Адаптация для первой карточки на мобильных - сохраняем квадрат */
    .team-grid .team-card:first-child.is-flipped .team-card-inner {
        width: 100%;
        height: 100%;
    }
}