/**
 * Cartes FantasyLap — style Balatro, flip 3D, sélection.
 * Référence : docs/test-design.php
 * v2 — améliorations lisibilité & UI
 */

/* --- Conteneur cartes --- */
.play-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    perspective: 1200px;
}

@media (min-width: 480px) {
    .play-cards-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

@media (min-width: 768px) {
    .play-cards-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 0.5rem;
    }
}

/* --- Base carte --- */
.balatro-card {
    width: 100%;
    aspect-ratio: 2 / 3;
    max-width: 200px;
    margin: 0 auto;
    border-radius: 14px;
    border: 3px solid rgba(255, 255, 255, 0.14);
    box-sizing: border-box;
    position: relative;
    cursor: pointer;
    /* [amélioration] transition plus riche : on inclut box-shadow pour le hover */
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    transform-style: preserve-3d;
    perspective: 800px;
    overflow: hidden;
}

/* [amélioration] Tilt 3D léger au hover pour un effet Balatro plus marqué */
.balatro-card:hover:not(.balatro-card--locked) {
    transform: translateY(-8px) rotateX(4deg) rotateY(-3deg);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
}

/* [amélioration] Selected : pulsation douce au lieu d'un outline statique */
.balatro-card--selected {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
    animation: card-pulse 1.8s ease-in-out infinite;
}

@keyframes card-pulse {
    0%, 100% { box-shadow: 0 0 18px rgba(233, 69, 96, 0.4); }
    50%       { box-shadow: 0 0 34px rgba(233, 69, 96, 0.78); }
}

.balatro-card--locked {
    opacity: 0.6;
    cursor: not-allowed;
}

.balatro-card--over-budget {
    opacity: 0.55;
    filter: grayscale(0.75);
    cursor: not-allowed;
}

/* [amélioration] Badge "manque X" déplacé en bas pour éviter la collision avec .card-btn-effect */
.balatro-card--over-budget::after {
    content: attr(data-missing);
    position: absolute;
    /* Était top:8px / right:8px — maintenant en bas pour ne pas collisionner avec le bouton "i" */
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.82);
    color: #fff;
    font-size: 0.72rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(6px);
    pointer-events: none;
    /* S'assure de passer au-dessus du dégradé card-content */
    z-index: 8;
    white-space: nowrap;
}

/* Structure interne de la carte */
.balatro-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: 12px;
}

.balatro-card-face {
    position: absolute;
    inset: 0;
    border-radius: 12px;
    overflow: hidden;
}

/* --- Variantes rareté (badges) --- */
.balatro-card--common {
    background: var(--bg-card);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.balatro-card--common::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 0;
    background: var(--bg-mid);
}

/* [amélioration] Badge rareté : texte horizontal, taille lisible,
   remplace le writing-mode vertical qui était difficile à lire sur mobile */
.balatro-card--common .card-rarity {
    background: linear-gradient(135deg, #4a5568 0%, #2d3748 100%);
    border-color: #718096;
    color: #e2e8f0;
}

.balatro-card--rare {
    box-shadow: 0 4px 20px rgba(100, 100, 180, 0.3);
}

.balatro-card--rare .card-rarity {
    background: linear-gradient(135deg, #4c51bf 0%, #2d3748 100%);
    border-color: #6366f1;
    color: #c7d2fe;
}

.balatro-card--epic {
    box-shadow: 0 4px 24px rgba(168, 120, 255, 0.35);
}

.balatro-card--epic .card-rarity {
    background: linear-gradient(135deg, #7b4ba8 0%, #4a2d6b 100%);
    border-color: #b88ae0;
    color: #e8d5ff;
}

/* --- Structure interne --- */
.card-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 12px;
    z-index: 0;
}

/* Fond stylisé pilotes (couleur écurie + formes) */
.card-bg--driver {
    background-color: var(--team-color);
    background-image:
        radial-gradient(ellipse 70% 45% at 15% 15%, rgba(255, 255, 255, 0.22) 0%, transparent 55%),
        radial-gradient(ellipse 55% 70% at 90% 85%, rgba(0, 0, 0, 0.15) 0%, transparent 55%),
        linear-gradient(155deg, transparent 35%, rgba(255, 255, 255, 0.06) 48%, transparent 62%);
}

.card-bg--driver .card-bg-shape {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
}

.card-bg--driver .card-bg-shape--1 {
    width: 50%;
    height: 50%;
    top: -15%;
    right: -10%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.12) 0%, transparent 70%);
}

.card-bg--driver .card-bg-shape--2 {
    width: 35%;
    height: 35%;
    bottom: -5%;
    left: -8%;
    background: radial-gradient(circle, rgba(0, 0, 0, 0.1) 0%, transparent 70%);
}

.card-bg--driver .card-bg-shape--3 {
    width: 25%;
    height: 45%;
    top: 40%;
    right: -5%;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.08) 0%, transparent 50%);
    border-radius: 50% / 40%;
    transform: rotate(-25deg);
}

.card-bg--driver .card-bg-shape--4 {
    width: 100%;
    height: 100%;
    inset: 0;
    background: repeating-linear-gradient(
        135deg,
        transparent,
        transparent 12px,
        rgba(255, 255, 255, 0.03) 12px,
        rgba(255, 255, 255, 0.03) 14px
    );
    border-radius: 12px;
}

.card-image-wrap {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.card-image-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-content {
    position: absolute;
    top: 55%;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.5rem 0.5rem 0.55rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    gap: 0;
    z-index: 5;
    background: linear-gradient(
        to top,
        rgba(8, 8, 22, 0.95) 0%,
        rgba(8, 8, 22, 0.88) 45%,
        rgba(8, 8, 22, 0.4) 75%,
        transparent 100%
    );
}

/* [amélioration] Badge rareté : horizontal, lisible, taille minimale respectée.
   On abandonne writing-mode vertical au profit d'un badge classique en haut à gauche. */
.card-rarity {
    position: absolute;
    left: 6px;
    top: 6px;
    font-size: 0.6rem;
    padding: 3px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    z-index: 6;
    border: 1px solid;
    /* Suppression de writing-mode, text-orientation, rotate et transform-origin */
    line-height: 1.2;
    font-weight: 600;
    /* Fond semi-transparent pour lisibilité sur toutes les images */
    backdrop-filter: blur(4px);
}

/* [amélioration] Titre : fond flouté semi-transparent pour garantir
   la lisibilité sur les images claires comme sombres */
.card-title {
    font-family: var(--font-card);
    font-size: clamp(0.7rem, 2.5vw, 0.95rem);
    color: #fff;
    text-transform: uppercase;
    text-align: center;
    line-height: 1.1;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9), 0 0 14px rgba(0, 0, 0, 0.6);
    /* [amélioration] Fond flou pour maximiser la lisibilité sur fond variable */
    background: rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(3px);
    padding: 2px 7px;
    border-radius: 4px;
}

.card-title-single {
    display: block;
    font-size: 0.85em;
    font-family: var(--font-card);
    line-height: 1.2;
}

/* Driver / Manager : prénom au-dessus du nom */
.card-type-driver .card-title,
.card-type-manager .card-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1em;
}

.card-type-driver .card-title-first,
.card-type-manager .card-title-first {
    display: block;
    font-size: 0.55em;
    font-family: var(--font-card);
    opacity: 0.9;
}

.card-type-driver .card-title-last,
.card-type-manager .card-title-last {
    display: block;
    font-family: var(--font-card);
    font-size: 0.95em;
}

.card-type-driver .card-content,
.card-type-manager .card-content {
    padding: 0.5rem 0.5rem 0.55rem;
}

.card-type-driver .card-value,
.card-type-manager .card-value {
    margin-top: 3px;
}

.card-value {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    margin-top: 3px;
}

.card-value-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.card-value-icon svg {
    width: 14px;
    height: 14px;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.card-value-amount {
    font-family: var(--font-title);
    font-size: 1rem;
    color: var(--color-gold);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
    line-height: 1;
}

@media (max-width: 768px) {
    .card-title-single {
        display: block;
        font-size: 0.75em;
        font-family: var(--font-card);
        line-height: 1.2;
    }

    .card-type-driver .card-title-first,
.card-type-manager .card-title-first {
    display: block;
    font-size: 0.45em;
    font-family: var(--font-card);
    opacity: 0.9;
}

.card-type-driver .card-title-last,
.card-type-manager .card-title-last {
    display: block;
    font-family: var(--font-card);
    font-size: 0.85em;
}
}

/* Bouton "i" (flip) */
.card-btn-effect {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.5);
    color: var(--text);
    font-size: 0.8rem;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}

.card-btn-effect:hover {
    background: var(--accent);
}

/* Pas de badge "i" sur les cartes pilotes */
.card-type-driver .card-btn-effect {
    display: none;
}

/* [amélioration] Feedback tap mobile plus perceptible (scale 0.96 vs 0.985) */
.balatro-card:active {
    transform: translateY(-1px) scale(0.96);
}

/* ─── Card Info Panel : Bottom Sheet (mobile) / Popover (desktop) ────────── */

.card-info-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.card-info-backdrop.is-visible {
    opacity: 1;
    visibility: visible;
}

.card-info-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 82vh;
    background: var(--bg-card);
    border-radius: 1.25rem 1.25rem 0 0;
    border: 1px solid var(--border);
    border-bottom: none;
    z-index: 9999;
    transform: translateY(100%);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), visibility 0.32s;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    will-change: transform;
    pointer-events: none;
    visibility: hidden;
}

.card-info-panel.is-open {
    transform: translateY(0);
    pointer-events: auto;
    visibility: visible;
}

.card-info-panel__handle {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin: 0.75rem auto 0;
    flex-shrink: 0;
    cursor: grab;
}

.card-info-panel__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem 0.65rem;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
}

.card-info-panel__title-group {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.card-info-panel__name {
    font-family: var(--font-card);
    font-size: 1.05rem;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-info-panel__cost {
    font-family: var(--font-title);
    font-size: 0.85rem;
    color: var(--color-gold);
}

.card-info-panel__close {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.35);
    color: var(--text);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.card-info-panel__close:hover {
    background: var(--accent);
}

.card-info-panel__body {
    overflow-y: auto;
    padding: 1rem;
    flex: 1;
    -webkit-overflow-scrolling: touch;
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.card-info-panel__image {
    width: 90px;
    flex-shrink: 0;
    border-radius: var(--radius);
    overflow: hidden;
    aspect-ratio: 2 / 3;
    border: 1px solid var(--border);
}

.card-info-panel__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card-info-panel__text {
    flex: 1;
    min-width: 0;
}

.card-info-panel__desc {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text);
    margin: 0 0 0.75rem;
}

/* Popover ancré (tablette / desktop) */
@media (min-width: 768px) {
    .card-info-backdrop {
        background: rgba(0, 0, 0, 0.35);
    }

    .card-info-panel {
        bottom: auto;
        left: 0;
        right: auto;
        width: 300px;
        max-height: calc(100vh - 2rem);
        border-radius: var(--radius);
        border: 1px solid var(--border);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.25);
        transform: scale(0.94) translateY(-6px);
        opacity: 0;
        transition: transform 0.18s ease, opacity 0.18s ease, visibility 0.18s;
        will-change: transform, opacity;
    }

    .card-info-panel.is-open {
        transform: scale(1) translateY(0);
        opacity: 1;
        pointer-events: auto;
        visibility: visible;
    }

    .card-info-panel__handle {
        display: none;
    }

    .card-info-panel__body {
        flex-direction: column;
    }

    .card-info-panel__image {
        width: 100%;
        max-width: 110px;
        align-self: center;
    }
}

/* ─── Tooltip description carte ─────────────────────────────────────────── */
.card-description-tooltip {
    position: fixed;
    z-index: 999999;
    max-width: min(320px, calc(100vw - 2rem));
    padding: 0.75rem 1rem;
    background: var(--bg-card, #1a1a1f);
    color: var(--text, #f0f0f0);
    font-size: 0.7rem;
    line-height: 1.45;
    border-radius: var(--radius, 8px);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.card-description-tooltip--visible {
    opacity: 1;
    visibility: visible;
}

.card-description-tooltip__text {
    display: block;
}