@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&family=Nunito:wght@400;600;700;800&display=swap');

:root {
    --card-flip-duration: 0.4s;
}

* {
    box-sizing: border-box;
    max-width: 100%;
}

html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    font-family: 'Nunito', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

.game-board-wrapper {
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
    padding: 0.25rem;
}

.game-board {
    display: grid;
    gap: 0.5rem;
    width: 100%;
    max-width: min(600px, 90vw);
}

.difficulty-1 .game-board {
    grid-template-columns: repeat(4, 1fr);
    gap: clamp(0.25rem, 1vw, 0.5rem);
    max-width: min(600px, 90vw);
}

.difficulty-1 .card-face {
    border-width: 3px;
    border-radius: 0.75rem;
    aspect-ratio: 1;
    min-width: 0;
}

.difficulty-1 .card-front::before {
    font-size: clamp(1.25rem, 4vw, 2rem);
}

.difficulty-2 .game-board {
    grid-template-columns: repeat(5, 1fr);
    gap: clamp(0.2rem, 0.8vw, 0.4rem);
    max-width: min(830px, 90vw);
}

.difficulty-2 .card-face {
    font-size: clamp(0.75rem, 2vw, 1rem);
    border-width: 2px;
    aspect-ratio: 1;
    min-width: 0;
}

.difficulty-2 .card-front {
    box-shadow:
        0 3px 0 #c026d3,
        0 4px 8px rgba(0, 0, 0, 0.15),
        inset 0 -2px 0 rgba(0, 0, 0, 0.1);
}

.difficulty-2 .card-front::before {
    font-size: clamp(1rem, 3vw, 1.5rem);
}

.difficulty-2 .card-back {
    box-shadow:
        0 3px 0 #cbd5e1,
        0 4px 8px rgba(0, 0, 0, 0.15);
}

.difficulty-3 .game-board {
    grid-template-columns: repeat(6, 1fr);
    gap: clamp(0.15rem, 0.6vw, 0.35rem);
    max-width: min(800px, 90vw);
}

.difficulty-3 .card-face {
    font-size: clamp(0.65rem, 1.8vw, 0.9rem);
    border-width: 2px;
    aspect-ratio: 1;
    min-width: 0;
}

.difficulty-3 .card-front {
    box-shadow:
        0 3px 0 #c026d3,
        0 4px 8px rgba(0, 0, 0, 0.15),
        inset 0 -2px 0 rgba(0, 0, 0, 0.1);
}

.difficulty-3 .card-front::before {
    font-size: clamp(0.8rem, 2.5vw, 1.3rem);
}

.difficulty-3 .card-back {
    box-shadow:
        0 3px 0 #cbd5e1,
        0 4px 8px rgba(0, 0, 0, 0.15);
}

@media (max-width: 640px) {
    .difficulty-3 .game-board {
        grid-template-columns: repeat(4, 1fr);
        gap: clamp(0.15rem, 0.8vw, 0.3rem);
    }

    .difficulty-2 .game-board {
        grid-template-columns: repeat(4, 1fr);
    }

    .game-board {
        gap: 0.25rem;
    }

    .card-face {
        border-radius: 0.5rem;
        border-width: 2px;
    }

    .card-front::before {
        font-size: 1.5rem;
    }
}

.player-btn.selected {
    transform: scale(1.1);
    box-shadow: 0 0 0 4px rgba(168, 85, 247, 0.4);
}

.player-btn[data-count="2"].selected {
    background: #c084fc;
    border-color: #9333ea;
    color: white;
}

.player-btn[data-count="3"].selected {
    background: #f472b6;
    border-color: #db2777;
    color: white;
}

.player-btn[data-count="4"].selected {
    background: #67e8f9;
    border-color: #0891b2;
    color: #0e7490;
}

.diff-btn.selected {
    transform: scale(1.05);
    box-shadow: 0 0 0 4px rgba(168, 85, 247, 0.3);
}

.diff-btn[data-level="1"].selected {
    background: #86efac;
    border-color: #22c55e;
    color: #166534;
}

.diff-btn[data-level="2"].selected {
    background: #fde047;
    border-color: #eab308;
    color: #854d0e;
}

.diff-btn[data-level="3"].selected {
    background: #fca5a5;
    border-color: #ef4444;
    color: #991b1b;
}

.player-card {
    background: white;
    border: 2px solid;
    transition: all 0.3s ease;
}

.player-card.active {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

.player-card .turn-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    opacity: 0.3;
    transition: all 0.3s ease;
}

.player-card.active .turn-indicator {
    opacity: 1;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

.card {
    perspective: 1000px;
    cursor: pointer;
    aspect-ratio: 1;
    z-index: 1;
    min-width: 0;
    min-height: 0;
}

.card.flipped,
.card.matched,
.card.wrong {
    z-index: 2;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform var(--card-flip-duration) cubic-bezier(0.4, 0, 0.2, 1);
}

.card.flipped .card-inner,
.card.matched .card-inner,
.card.wrong .card-inner {
    transform: rotateY(180deg);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 1rem;
    border: 4px solid white;
    z-index: 1;
    min-width: 0;
    overflow: hidden;
}

.card-back {
    z-index: 2;
}

.card-front {
    background: linear-gradient(135deg, #f0abfc 0%, #e879f9 50%, #d946ef 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 6px 0 #c026d3,
        0 8px 15px rgba(0, 0, 0, 0.15),
        inset 0 -3px 0 rgba(0, 0, 0, 0.1);
}

.card-front::before {
    content: '?';
    font-size: 2rem;
    font-weight: 900;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.card-front::after {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    bottom: 8px;
    border: 3px dashed rgba(255, 255, 255, 0.4);
    border-radius: 0.75rem;
    pointer-events: none;
}

.card-back {
    transform: rotateY(180deg);
    background: #fff;
    overflow: hidden;
    box-shadow:
        0 6px 0 #cbd5e1,
        0 8px 15px rgba(0, 0, 0, 0.15);
}

.card-back img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0.75rem;
}

.card:hover:not(.flipped):not(.matched) .card-front {
    transform: translateY(-4px);
    box-shadow:
        0 10px 0 #c026d3,
        0 15px 25px rgba(0, 0, 0, 0.2),
        inset 0 -3px 0 rgba(0, 0, 0, 0.1);
}

.card.flipped {
    cursor: default;
}

.card.matched .card-front {
    background: linear-gradient(135deg, #86efac 0%, #4ade80 50%, #22c55e 100%);
    border-color: #166534;
    box-shadow:
        0 6px 0 #15803d,
        0 8px 20px rgba(34, 197, 94, 0.4);
}

.card.wrong .card-front {
    background: linear-gradient(135deg, #fca5a5 0%, #f87171 50%, #ef4444 100%);
    border-color: #dc2626;
    box-shadow:
        0 6px 0 #b91c1c,
        0 8px 20px rgba(239, 68, 68, 0.4);
}

.card.match-anim {
    animation: matchPop 0.4s ease-out;
}

@keyframes matchPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.card.wrong .card-inner {
    animation: wrongShake 0.4s ease-out;
}

@keyframes wrongShake {
    0%, 100% { transform: rotateY(180deg); }
    25% { transform: rotateY(180deg) translateX(-8px); }
    75% { transform: rotateY(180deg) translateX(8px); }
}

.modal-overlay.show {
    display: flex;
}

.modal-overlay.show .modal-content {
    transform: scale(1);
    opacity: 1;
}

@keyframes popIn {
    from {
        transform: scale(0.5);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-content {
    animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

#trophy {
    animation: float 2s ease-in-out infinite;
}

.name-input {
    background: #f8fafc;
    border: 3px solid #e2e8f0;
    border-radius: 1rem;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.2s;
}

.name-input:focus {
    outline: none;
    border-color: #a855f7;
    box-shadow: 0 0 0 4px rgba(168, 85, 247, 0.2);
}

.score-display {
    font-family: 'Fredoka', sans-serif;
    font-size: 1rem;
    font-weight: 700;
}
