/**
 * Component: Flip Cards Slider
 * Architecture: Standalone (no external dependencies). Every rule is scoped to .tama-fc,
 * state lives on the instance (no IDs), so several instances on one page never clash.
 * Direction-aware: logical properties + native scroll (works in RTL and LTR).
 */

.tama-fc {
    --fc-gap: 40px;
    --fc-cols: 3;
    --fc-dark: var(--third-color, #1c2d00);
    --fc-green: var(--primary-color, #667f06);
    width: 100%;
    display: block;
    padding: 80px 0;
}

.tama-fc--many {
    --fc-cols: 3.2; /* peek of the next card on desktop when there are more than 3 cards */
}

.tama-fc__container {
    width: 100%;
    max-width: 1520px;
    margin: 0 auto;
    padding-inline: 15px;
}

/* Header */
.tama-fc__header {
    text-align: center;
    margin-block-end: 40px;
}

.tama-fc .tama-fc__subtitle {
    margin: 0 0 8px;
    font-size: 20px;
    text-transform: uppercase;
    color: var(--fc-green);
}

.tama-fc .tama-fc__title {
    margin: 0;
    font-size: clamp(36px, 3vw, 56px) !important;
    line-height: 1.1 !important;
    color: var(--fc-dark);
}

/* Viewport + track (native scroll-snap slider) */
.tama-fc__viewport {
    overflow: hidden;
}

.tama-fc__track {
    display: flex;
    gap: var(--fc-gap);
    overflow-x: auto;
    padding-block: 12px 28px; /* room for the card shadow */
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.tama-fc__track::-webkit-scrollbar {
    display: none;
}

/* Card */
.tama-fc__card {
    text-align: start; /* front title + back text start at the reading side (page body forces left) */
    flex: 0 0 calc((100% - (var(--fc-cols) - 1) * var(--fc-gap)) / var(--fc-cols));
    min-width: 0;
    aspect-ratio: 3 / 4;
    scroll-snap-align: start;
    perspective: 1400px;
}

.tama-fc__inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.6s ease;
}

.tama-fc__card.is-flipped .tama-fc__inner {
    transform: rotateY(180deg);
}

.tama-fc__face {
    position: absolute;
    inset: 0;
    border-radius: 24px;
    overflow: hidden;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    -webkit-transform: translateZ(0); /* iOS Safari: own layer per face */
    transform: translateZ(0);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

/* iOS Safari: children with their own layer (positioned / z-index / scrolling) ignore the parent's
   backface-visibility, so the front title and "+" showed mirrored on the flipped card. */
.tama-fc__face * {
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Front */
.tama-fc__front {
    background-color: var(--fc-dark);
}

.tama-fc__picture,
.tama-fc__img {
    display: block;
    width: 100%;
    height: 100%;
}

.tama-fc__img {
    object-fit: cover;
}

.tama-fc__front::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0) 45%);
    pointer-events: none;
}

.tama-fc__caption {
    position: absolute;
    inset-inline: 40px;
    inset-block-end: 40px;
    z-index: 1;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
}

.tama-fc .tama-fc__card-title {
    margin: 0;
    font-size: 32px;
    line-height: 1.25;
    color: #fff;
}

/* Back */
.tama-fc__back {
    -webkit-transform: rotateY(180deg) translateZ(0);
    transform: rotateY(180deg) translateZ(0);
    background-color: #ece5dc;
    color: var(--fc-dark);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 40px;
}

.tama-fc__back-text {
    font-size: 22px;
    line-height: 1.4;
    overflow-y: auto;
    scrollbar-width: none; /* no visible scrollbar - it looked like an option */
}

.tama-fc__back-text::-webkit-scrollbar {
    display: none;
}

.tama-fc__back-text p {
    margin: 0 0 12px;
}

.tama-fc__back-text p:last-child {
    margin-bottom: 0;
}

/* Plus / minus toggle */
.tama-fc__toggle {
    flex: 0 0 auto;
    display: block;
    width: 48px;
    height: 48px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--fc-dark);
    cursor: pointer;
}

.tama-fc__toggle img,
.tama-fc__toggle svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* No square after a mouse click; keyboard users still get a visible ring */
.tama-fc__toggle:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}

.tama-fc__toggle:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
    border-radius: 50%;
}

.tama-fc__front .tama-fc__toggle:focus-visible {
    outline-color: #fff;
}

/* Both faces are clickable when the card has back text */
.tama-fc__card.has-back .tama-fc__face {
    cursor: pointer;
}

.tama-fc__toggle--close {
    align-self: flex-start;
}

/* Front + icon: raised 8px; the title's last line is centered on the icon
   (icon center = 8 + 24 = 32px from the bottom, half a line = 0.625em) */
.tama-fc__front .tama-fc__toggle {
    margin-block-end: 8px;
}

.tama-fc__front .tama-fc__card-title {
    margin-block-end: calc(32px - 0.625em);
}

/* Arrows (centered under the slider) */
.tama-fc__controls {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-block-start: 8px;
}

.tama-fc__controls[hidden] {
    display: none;
}

.tama-fc__arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 2px solid var(--fc-green);
    border-radius: 4px;
    background: transparent;
    color: var(--fc-green);
    cursor: pointer;
    transition: all 0.2s ease;
}

.tama-fc__arrow:hover:not(:disabled) {
    background-color: var(--fc-green);
    color: #fff;
}

.tama-fc__arrow:disabled {
    border-color: #c9c9c9;
    color: #c9c9c9;
    cursor: default;
}

/* Arrow direction follows the reading direction */
.tama-fc__arrow--prev svg {
    transform: scaleX(-1);
}

[dir="rtl"] .tama-fc__arrow--prev svg {
    transform: none;
}

[dir="rtl"] .tama-fc__arrow--next svg {
    transform: scaleX(-1);
}

/* Tablet */
@media (max-width: 1199px) {
    .tama-fc {
        --fc-gap: 24px;
        --fc-cols: 2;
    }

    .tama-fc--over2 {
        --fc-cols: 2.2;
    }

    .tama-fc__caption {
        inset-inline: 28px;
        inset-block-end: 28px;
    }

    .tama-fc .tama-fc__card-title {
        font-size: 26px;
    }

    .tama-fc__back {
        padding: 28px;
    }

    .tama-fc__back-text {
        font-size: 19px;
    }
}

/* Mobile: one card plus a peek of the next one */
@media (max-width: 768px) {
    .tama-fc {
        --fc-gap: 16px;
        --fc-cols: 1.15;
        padding: 48px 0;
    }

    .tama-fc--over2,
    .tama-fc--many {
        --fc-cols: 1.15;
    }

    .tama-fc__header {
        margin-block-end: 24px;
    }

    .tama-fc .tama-fc__subtitle {
        font-size: 16px;
        margin-bottom:16px !important;
    }

    .tama-fc .tama-fc__title {
        font-size: 34px !important;
    }

    .tama-fc__caption {
        inset-inline: 20px;
        inset-block-end: 20px;
    }

    .tama-fc .tama-fc__card-title {
        font-size: 22px;
    }

    .tama-fc__back {
        padding: 20px;
    }

    .tama-fc__back-text {
        font-size: 24px;
    }
}

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