/* Styles généraux */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
    background-size: 400% 400%;
    animation: gradient 15s ease infinite;
    color: #fff;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

@keyframes gradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.container {
    width: 100%;
    max-width: 1200px;
    padding: 20px;
    position: relative;
    min-height: 100vh;
}

/* Styles des écrans */
.screen {
    display: none;
    opacity: 0;
    transition: opacity 0.5s ease;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.screen.active {
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
}

.content {
    background-color: rgba(0, 0, 0, 0.7);
    border-radius: 15px;
    padding: 30px;
    text-align: center;
    max-width: 90%;
    width: 100%;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

h1, h2 {
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

p {
    margin-bottom: 25px;
    line-height: 1.6;
}

.btn {
    background: linear-gradient(45deg, #ff4e50, #f9d423);
    border: none;
    color: white;
    padding: 12px 30px;
    border-radius: 30px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    margin-top: 20px;
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 7px 20px rgba(0, 0, 0, 0.3);
}

.btn:active {
    transform: translateY(1px);
}

/* Styles de l'enveloppe */
.envelope {
    width: 200px;
    height: 150px;
    margin: 20px auto;
    position: relative;
    transition: transform 0.5s ease;
}

.envelope img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.envelope.open {
    transform: scale(1.2);
}

.prediction-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #fff;
    color: #000;
    padding: 10px;
    border-radius: 5px;
    font-weight: bold;
    font-size: 18px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

:root {
    --primary-color: #1a2a6c;
    --secondary-color: #b21f1f;
    --accent-color: #fdbb2d;
    --card-width: 140px;
    --card-height: 210px;
    --card-border-radius: 10px;
}

/* Styles des cartes */

.cards-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    margin: 20px 0;
    padding: 20px;
    max-height: 70vh;
    overflow-y: auto;
}

.card {
    flex: 0 0 auto;
    width: 140px !important;
    height: 210px !important;
    max-width: 140px !important;
    min-width: 140px !important;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease, margin 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
    background-color: white;
    position: relative;
    overflow: hidden;
    margin: 5px;
    border: 1px solid #ccc;
}

.card img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background-color: white;
    border-radius: 9px; /* Légèrement plus petit que la carte pour éviter les débordements */
}

.card:hover {
    transform: translateY(-15px) scale(1.1);
    z-index: 10;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
}

/* Styles des piles */
.piles-container {
    display: flex;
    justify-content: space-around;
    margin: 30px 0;
    flex-wrap: wrap;
    gap: 20px;
    perspective: 1000px;
}

.pile {
    width: 20%;
    min-width: 120px;
    min-height: 200px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.5s ease, box-shadow 0.5s ease;
    transform-style: preserve-3d;
    position: relative;
    overflow: visible;
    margin: 0 auto;
}

.pile:hover {
    transform: translateY(-10px) rotateY(5deg);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5);
}

.pile .card {
    width: 70px !important;
    height: 105px !important;
    max-width: 70px !important;
    min-width: 70px !important;
    margin-top: -80%;
    position: relative;
    transition: all 0.3s ease-out;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    animation: cardEntrance 0.5s ease-out forwards;
    animation-delay: calc(var(--card-index) * 0.05s);
    opacity: 0;
    z-index: 1;
    transform-origin: center center;
}

@keyframes cardEntrance {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes pileFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes cardAppear {
    from {
        opacity: 0;
        transform: scale(0) rotate(-10deg);
    }
    to {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

.pile .card:first-child {
    margin-top: 0;
}

.pile:hover .card {
    margin-top: calc(-60% + 5px);
    transform: translateZ(10px);
    transition-delay: calc(var(--card-index) * 0.05s);
}

/* Styles pour l'écran de coupe */
.cut-deck-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 20px 0;
    position: relative;
    min-height: 300px;
}

.cut-line {
    position: absolute;
    width: 100%;
    height: 4px;
    background-color: rgba(255, 215, 0, 0.7);
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.9), 0 0 20px rgba(255, 215, 0, 0.5);
    z-index: 100;
    display: none;
    pointer-events: none;
    left: 0;
    opacity: 0.9;
    transform-origin: center;
}

@keyframes pulseLine {
    from {
        transform: scaleY(1);
        box-shadow: 0 0 15px #f9d423, 0 0 5px rgba(255, 255, 255, 0.8);
    }
    to {
        transform: scaleY(1.5);
        box-shadow: 0 0 25px #f9d423, 0 0 10px rgba(255, 255, 255, 1);
    }
}

/* Styles pour l'écran de révélation finale */
.counting-cards {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    margin: 20px 0;
    gap: 10px;
    perspective: 1000px;
}

.card-back {
    transition: all 0.3s ease;
    transform-style: preserve-3d;
    width: var(--card-width);
    height: var(--card-height);
    max-width: var(--card-width);
    min-width: var(--card-width);
    border-radius: var(--card-border-radius);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    background-color: white;
    position: relative;
    overflow: hidden;
    margin: 5px;
    border: 1px solid #ccc;
}

.card-back:hover {
    transform: translateY(-5px) rotateY(10deg) !important;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3) !important;
}

.card-back::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: 40% 40%;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.2;
}

.card-back.revealed {
    transform: rotateY(180deg);
    background-color: white !important;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0;
    color: transparent !important;
}

.card-back.revealed::after {
    content: '';
    background-image: url('https://deckofcardsapi.com/static/img/back.svg');
    background-size: cover;
    opacity: 1;
    transform: rotateY(180deg);
}

.final-card {
    width: calc(var(--card-width) * 1.2);
    height: calc(var(--card-height) * 1.2);
    margin: 20px auto;
    transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform: scale(0);
    position: relative;
    perspective: 1000px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: transparent;
}

.final-card .card {
    width: 100%;
    height: 100%;
    margin: 0;
    transform: scale(0) rotateY(180deg);
    transition: transform 1.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.final-card.revealed .card {
    transform: scale(1) rotateY(0deg);
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.8), 0 0 60px rgba(255, 215, 0, 0.6);
    animation: pulse 1.5s infinite alternate;
}

.final-card.revealed {
    transform: scale(1);
}

@keyframes pulse {
    from {
        box-shadow: 0 0 30px rgba(255, 255, 255, 0.8), 0 0 60px rgba(255, 215, 0, 0.6);
    }
    to {
        box-shadow: 0 0 20px rgba(255, 255, 255, 0.5), 0 0 40px rgba(255, 215, 0, 0.3);
    }
}

.hidden {
    display: none;
}

/* Responsive */
@media (max-width: 768px) {
    .content {
        padding: 20px;
    }

    .cards-grid {
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    }

    .pile {
        min-width: 120px;
    }

    .final-card {
        width: 150px;
        height: 225px;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 24px;
    }

    h2 {
        font-size: 20px;
    }

    .btn {
        padding: 10px 20px;
        font-size: 16px;
    }

    .cards-grid {
        grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    }
}
