/*
 * Carte à collectionner (app/components/trading-card.js), partagée par l'app
 * et le concepteur de l'admin. Toutes les tailles sont en cqw : la carte
 * s'adapte à la largeur de son conteneur.
 */

.tcard {
    --frame1: #f5d76e;
    --frame2: #e0a82e;
    --rarity: #9e9e9e;
    --type: var(--frame2);
    --rx: 0deg;
    --ry: 0deg;
    --mx: 50%;
    --my: 50%;

    container-type: inline-size;
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 63 / 88;
    color: #1b1b1b;
    font-family: inherit;
    text-align: left;
    user-select: none;
    -webkit-user-select: none;
    /* Pas de transformation 3D au repos : Safari iOS fait passer les éléments 3D
       par-dessus le reste (barre du bas) et une collection en compte beaucoup */
    transform: none;
    transition: transform 0.4s ease;
    /* Les z-index internes (anneau arc-en-ciel) restent dans la carte : les pastilles posées
       autour (x2, cadenas, « Nouvelle ») passent devant */
    isolation: isolate;
}

.tcard.tilting {
    transform: perspective(600px) rotateX(var(--rx)) rotateY(var(--ry)) scale(1.04);
    transition: transform 0.08s linear;
}

/* Les cqw se calculent sur .tcard (conteneur) : le cadre est porté par .tcard-face */
.tcard-face {
    position: absolute;
    inset: 0;
    padding: 3.2cqw;
    box-sizing: border-box;
    border-radius: 4.5cqw;
    background: linear-gradient(145deg, var(--frame1), var(--frame2));
    box-shadow: 0 0.6rem 1.6rem rgba(0, 0, 0, 0.35), inset 0 0 0 0.6cqw rgba(255, 255, 255, 0.35);
    overflow: hidden;
}

/* Neutralise les styles globaux (span en width: 100%...) sans gagner sur les classes ci-dessous */
:where(.tcard) :is(span, p, small, b) {
    width: auto;
    font-size: inherit;
    line-height: 1.2;
    margin: 0;
    padding: 0;
    color: inherit;
}

.tcard-body {
    display: flex;
    flex-direction: column;
    gap: 1.6cqw;
    height: 100%;
    padding: 2.4cqw;
    box-sizing: border-box;
    border-radius: 2.5cqw;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(255, 255, 255, 0.62));
}

/* En-tête : nom, stat, icône du type */

.tcard-head {
    display: flex;
    align-items: center;
    gap: 1.8cqw;
}

.tcard-name {
    flex: 1;
    min-width: 0;
    font-family: var(--FontFocus);
    /* --name-scale : réduction posée par fitCardNames (trading-card.js) quand le nom déborde */
    font-size: calc(6.4cqw * var(--name-scale, 1));
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tcard-stat {
    display: flex;
    align-items: baseline;
    gap: 0.8cqw;
    font-size: 6.4cqw;
    font-weight: 800;
    color: #c62828;
}

.tcard-stat small {
    font-size: 3cqw;
    font-weight: 700;
    text-transform: uppercase;
}

.tcard-type-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 7.5cqw;
    height: 7.5cqw;
    border-radius: 50%;
    background: var(--type);
    color: #fff;
    font-size: 3.8cqw;
    box-shadow: 0 0 0 0.5cqw rgba(255, 255, 255, 0.8);
}

/* Illustration recadrée */

.tcard-art {
    position: relative;
    flex-shrink: 0;
    aspect-ratio: 4 / 3;
    border-radius: 1.5cqw;
    overflow: hidden;
    background: linear-gradient(135deg, var(--type), var(--frame1));
    box-shadow: inset 0 0 0 0.8cqw var(--frame2), 0 0.4cqw 1cqw rgba(0, 0, 0, 0.25);
}

.tcard-art img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform-origin: center;
    pointer-events: none;
}

.tcard-art-empty {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12cqw;
    color: rgba(255, 255, 255, 0.7);
}

.tcard-strip {
    display: flex;
    justify-content: space-between;
    gap: 2cqw;
    min-height: 4.6cqw;
    padding: 0.6cqw 2.4cqw;
    border-radius: 99px;
    background: linear-gradient(90deg, var(--frame2), var(--frame1));
    font-size: 3.2cqw;
    font-weight: 700;
    font-style: italic;
}

/* Chaque texte en noir ou blanc selon la teinte du dégradé sous lui (textColorOn) */
.tcard-strip > :first-child {
    color: var(--strip-start, inherit);
}

.tcard-strip > :last-child {
    color: var(--strip-end, inherit);
}

/* Capacités */

.tcard-abilities {
    display: flex;
    flex-direction: column;
    gap: 1.8cqw;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.tcard-ability-head {
    display: flex;
    justify-content: space-between;
    gap: 2cqw;
    font-size: 4.6cqw;
    font-weight: 800;
}

.tcard-ability-head b {
    font-size: 5.6cqw;
}

.tcard-ability-text {
    font-size: 3.4cqw;
}

.tcard-flavor {
    padding-top: 1.2cqw;
    border-top: 0.3cqw solid rgba(0, 0, 0, 0.2);
    font-size: 3.1cqw;
    font-style: italic;
    opacity: 0.85;
}

/* Carte sans attaque : la description prend la place et le style des attaques (.tcard-ability-head) */
.tcard-flavor-main {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding-top: 0;
    border-top: none;
    font-size: 4.6cqw;
    font-weight: 800;
    font-style: normal;
    opacity: 1;
}

.tcard-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2cqw;
    font-size: 2.8cqw;
    font-weight: 700;
    opacity: 0.85;
}

.tcard-rarity {
    display: inline-flex;
    gap: 0.6cqw;
    color: var(--rarity);
    font-size: 2.8cqw;
    filter: drop-shadow(0 0 0.3cqw rgba(0, 0, 0, 0.4));
}

/* Full art : l'illustration couvre toute la carte, le cadre devient un liseré
   et les textes passent par-dessus, en blanc sur un dégradé sombre */

.tcard-fullart .tcard-face {
    padding: 0;
}

.tcard-fullart .tcard-face::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 2;
    padding: 1.6cqw;
    border-radius: inherit;
    background: linear-gradient(145deg, var(--frame1), var(--frame2));
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
}

.tcard-fullart .tcard-body {
    position: relative;
    padding: 4.6cqw;
    border-radius: 0;
    background: none;
    color: #fff;
}

.tcard-fullart .tcard-body > * {
    position: relative;
    z-index: 1;
}

.tcard-fullart .tcard-body > .tcard-art {
    position: absolute;
    inset: 0;
    z-index: 0;
    aspect-ratio: auto;
    border-radius: 0;
    box-shadow: none;
}

.tcard-fullart .tcard-art::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.55) 0%, transparent 20%, transparent 42%, rgba(0, 0, 0, 0.55) 62%, rgba(0, 0, 0, 0.85) 100%);
    pointer-events: none;
}

.tcard-fullart .tcard-ability-head,
.tcard-fullart .tcard-ability-text,
.tcard-fullart .tcard-flavor,
.tcard-fullart .tcard-foot {
    text-shadow: 0 0.3cqw 1cqw rgba(0, 0, 0, 0.7);
}

/* Le nom coupe ce qui dépasse (points de suspension) : un text-shadow serait rogné,
   drop-shadow se dessine après la découpe et déborde du cadre */
.tcard-fullart .tcard-name {
    filter: drop-shadow(0 0.3cqw 0.5cqw rgba(0, 0, 0, 0.7));
}

.tcard-fullart .tcard-stat {
    color: #ffd65a;
    text-shadow: 0 0.3cqw 1cqw rgba(0, 0, 0, 0.7);
}

.tcard-fullart .tcard-strip {
    margin-top: auto;
}

.tcard-fullart .tcard-abilities,
.tcard-fullart .tcard-flavor-main {
    flex: 0 0 auto;
}

.tcard-fullart .tcard-flavor {
    border-top-color: rgba(255, 255, 255, 0.35);
}

.tcard-fullart .tcard-foot {
    opacity: 0.95;
}

/* Effets de rareté : reflet qui suit le pointeur (--mx, --my) */

.tcard-shine {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    mix-blend-mode: soft-light;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.tcard.effect-shine .tcard-shine {
    opacity: 0.7;
    background: radial-gradient(circle at var(--mx) var(--my), rgba(255, 255, 255, 0.9), transparent 55%);
}

.tcard.effect-holo .tcard-shine {
    opacity: 0.8;
    mix-blend-mode: color-dodge;
    background:
        radial-gradient(circle at var(--mx) var(--my), rgba(255, 255, 255, 0.55), transparent 45%),
        linear-gradient(115deg, transparent 20%, rgba(255, 0, 132, 0.35) 36%, rgba(0, 210, 255, 0.35) 50%, rgba(140, 255, 0, 0.35) 64%, transparent 80%);
    background-size: 100% 100%, 250% 250%;
    background-position: center, var(--mx) var(--my);
    animation: tcard-holo 12s ease-in-out infinite;
}

.tcard.effect-gold .tcard-face {
    box-shadow: 0 0.6rem 1.6rem rgba(0, 0, 0, 0.35), 0 0 1.2rem rgba(255, 196, 0, 0.55), inset 0 0 0 0.6cqw rgba(255, 236, 160, 0.8);
}

.tcard.effect-gold .tcard-shine {
    opacity: 0.9;
    mix-blend-mode: overlay;
    background:
        radial-gradient(circle at var(--mx) var(--my), rgba(255, 250, 220, 0.95), transparent 50%),
        linear-gradient(125deg, transparent 25%, rgba(255, 215, 0, 0.6) 45%, rgba(255, 255, 255, 0.7) 50%, rgba(255, 215, 0, 0.6) 55%, transparent 75%);
    background-size: 100% 100%, 300% 300%;
    animation: tcard-holo 8s ease-in-out infinite;
}

/* Aller-retour : le reflet revient à son point de départ, la boucle ne saute pas */
@keyframes tcard-holo {
    0%,
    100% {
        background-position: center, 0% 0%;
    }

    50% {
        background-position: center, 100% 100%;
    }
}

/* Arc-en-ciel : anneau posé sur le cadre dont la teinte tourne en boucle
   (le hue-rotate ne touche que l'anneau, pas l'illustration) */
.tcard.effect-rainbow .tcard-face::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 3;
    padding: 3.2cqw;
    border-radius: inherit;
    background: linear-gradient(135deg, #ff004c, #ff9a00, #ffe600, #34e05a, #00b7ff, #8a3dff, #ff004c);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    animation: tcard-rainbow 4s linear infinite;
}

.tcard-fullart.effect-rainbow .tcard-face::before {
    padding: 1.6cqw;
}

@keyframes tcard-rainbow {
    to {
        filter: hue-rotate(360deg);
    }
}

/* Carte en grand (showCardViewer), par-dessus une modal */

/* display seulement ouvert : sinon le <dialog> fermé resterait affiché */
.tcard-viewer[open] {
    display: flex;
}

.tcard-viewer {
    position: fixed;
    inset: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    padding: 1.5rem;
    border: none;
    box-sizing: border-box;
    background: rgba(5, 5, 10, 0.88);
    color: #fff;
    outline: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.tcard-viewer::backdrop {
    background: transparent;
}

.tcard-viewer.open {
    opacity: 1;
}

/* Plus grande carte qui tient à l'écran, avec une marge pour l'inclinaison */
.tcard-viewer-card {
    width: min(86vw, 62dvh * 63 / 88, 26rem);
    transform: scale(0.9);
    transition: transform 0.25s ease;
}

.tcard-viewer.open .tcard-viewer-card {
    transform: none;
}

/* Nombre d'exemplaires : même pastille que dans la Collection (css/boosters.css .collection-card
   .card-count, police des titres héritée de son bouton), en plus grand, en bas à droite de la carte */
.tcard-viewer-card {
    position: relative;
}

.tcard-viewer-card > .card-count {
    position: absolute;
    right: -0.75rem;
    bottom: -0.75rem;
    z-index: 2;
    width: auto;
    padding: 0.25rem 0.875rem;
    border-radius: 99px;
    background: var(--ColorPrimary);
    color: var(--ColorPrimaryText);
    font-family: var(--FontFocus);
    font-size: 1.25rem;
    font-weight: 700;
}

/* Sous les losanges de rareté, ligne discrète : exemplaires engagés dans un échange en attente, ou
   pour une carte à trouver (dos de la carte) « Carte à trouver · #N / total · booster »
   (le viewer espace ses éléments de 1rem) */
.tcard-viewer-reserved,
.tcard-viewer-locked {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    width: auto;
    margin: 0;
    font-size: 0.875rem;
    opacity: 0.65;
}

/* Juste sous les losanges de rareté */
.rarity-gems + .tcard-viewer-reserved,
.rarity-gems + .tcard-viewer-locked {
    margin-top: -0.5rem;
}

.tcard-viewer-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 2.75rem;
    height: 2.75rem;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
}

/* Dos de carte */

.tcard-back .tcard-face {
    display: flex;
    align-items: center;
    justify-content: center;
    /* Rayons gris sombre depuis le centre (comme le soleil du logo Turbo Bringue), assombris vers les bords */
    background:
        radial-gradient(circle at 50% 50%, transparent 0 20%, rgba(0, 0, 0, 0.55) 78%),
        repeating-conic-gradient(from 0deg at 50% 50%, #2e2e2e 0 7.5deg, #1f1f1f 7.5deg 15deg);
    box-shadow: 0 0.6rem 1.6rem rgba(0, 0, 0, 0.35), inset 0 0 0 1.8cqw #e0a82e;
}

.tcard-back .tcard-face img {
    width: 55%;
    filter: drop-shadow(0 0 2cqw rgba(224, 168, 46, 0.6));
}

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

    .tcard-shine,
    .tcard-face::before {
        animation: none !important;
    }
}

/* Losanges de rareté sous une carte (rarityGems, app/components/trading-card.js) : mêmes losanges que
   sur la carte (.tcard-rarity), à la couleur de la rareté (--rarity, posée en JS), en 24 px partout
   (ouverture des boosters, carte en grand). animated : arrivée un par un (ouverture des boosters) */
.rarity-gems {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    width: auto;
    color: var(--rarity, #9e9e9e);
    font-size: 1.5rem;
    filter: drop-shadow(0 0.125rem 0.25rem rgba(0, 0, 0, 0.4));
}

.rarity-gem {
    display: inline-block;
}

.rarity-gems.animated .rarity-gem {
    animation: rarity-gem-in 0.45s cubic-bezier(0.3, 1.6, 0.5, 1) both;
    animation-delay: 0.35s;
}

.rarity-gems.animated .rarity-gem:nth-child(2) { animation-delay: 0.47s; }
.rarity-gems.animated .rarity-gem:nth-child(3) { animation-delay: 0.59s; }
.rarity-gems.animated .rarity-gem:nth-child(4) { animation-delay: 0.71s; }
.rarity-gems.animated .rarity-gem:nth-child(5) { animation-delay: 0.83s; }

@keyframes rarity-gem-in {
    from {
        opacity: 0;
        transform: translateY(0.75rem) scale(0.3);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .rarity-gems.animated .rarity-gem {
        animation: none;
    }
}
