/**
 * Memory Game Styles
 * Designed for the Exercise Framework
 */

:root {
    --memory-card-size: 120px;
    --memory-card-gap: 1rem;
    --memory-card-bg: #ffffff;
    --memory-card-front: var(--primary-color, #0f6da7);
    --memory-card-border: #e0e0e0;
    --memory-card-matched: #4caf50;
    --memory-card-shadow: rgba(0, 0, 0, 0.1);
}

/* Exercise Container */
.exercise-container {
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 80px 1rem 1rem 1rem; /* Account for nav bar */
}

/* Memory Grid */
.memory-grid {
    display: grid;
    gap: var(--memory-card-gap);
    max-width: 90vw;
    max-height: 80vh;
    padding: 1rem;
}

/* Responsive grid sizing */
@media (max-width: 768px) {
    :root {
        --memory-card-size: 80px;
        --memory-card-gap: 0.5rem;
    }

    .memory-grid {
        padding: 0.5rem;
    }
}

@media (min-width: 769px) and (max-width: 1200px) {
    :root {
        --memory-card-size: 100px;
        --memory-card-gap: 0.75rem;
    }
}

/* Memory Card */
.memory-card {
    width: var(--memory-card-size);
    height: var(--memory-card-size);
    perspective: 1000px;
    cursor: pointer;
    position: relative;
}

.memory-card.matched {
    cursor: default;
}

/* Card Inner Container */
.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

.memory-card.flipped .card-inner {
    transform: rotateY(180deg);
}

/* Card Faces */
.card-front,
.card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 2px solid var(--memory-card-border);
    box-shadow: 0 4px 8px var(--memory-card-shadow);
    font-size: 2rem;
    font-weight: bold;
    user-select: none;
}

/* Card Front (hidden initially) */
.card-front {
    background-color: var(--memory-card-front);
    color: white;
    font-size: 3rem;
}

/* Card Back (visible when flipped) */
.card-back {
    background-color: var(--memory-card-bg);
    color: #333;
    transform: rotateY(180deg);
}

/* Matched Cards */
.memory-card.matched .card-back {
    background-color: var(--memory-card-matched);
    color: white;
    border-color: var(--memory-card-matched);
}

.memory-card.matched .card-front {
    background-color: var(--memory-card-matched);
}

/* Hover Effect */
.memory-card:not(.matched):not(.flipped):hover .card-inner {
    transform: scale(1.05);
    transition: transform 0.2s;
}

/* Game Stats in Nav */
.game-stats {
    font-size: 0.9rem;
    font-weight: normal;
    margin-left: 1rem;
    opacity: 0.9;
}

/* Start Screen */
.exercise-container .container {
    max-width: 500px;
    text-align: center;
}

.start-btn {
    width: 100%;
    max-width: 300px;
    padding: 1rem 2rem;
    font-size: 1.2rem;
    background-color: var(--primary-color, #0f6da7);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.start-btn:hover {
    background-color: var(--primary-hover, #106193);
}

/* Grundschrift font support */
.card-back.grundschrift {
    font-family: 'GrundschriftRegular', 'Arial', sans-serif;
}

/* Animation for matched cards */
@keyframes matchPulse {
    0%, 100% { transform: scale(1) rotateY(180deg); }
    50% { transform: scale(1.1) rotateY(180deg); }
}

.memory-card.matched .card-inner {
    animation: matchPulse 0.5s ease-in-out;
}

/* Responsive font sizing for card content */
@media (max-width: 768px) {
    .card-front {
        font-size: 2rem;
    }

    .card-back {
        font-size: 1.2rem;
    }
}

/* Loading/Preview State */
.memory-card.preview .card-inner {
    transform: rotateY(180deg);
}

/* Accessibility */
.memory-card:focus {
    outline: 3px solid var(--primary-color, #0f6da7);
    outline-offset: 2px;
}

.memory-card:focus:not(:focus-visible) {
    outline: none;
}

/* Win State - Optional confetti effect placeholder */
.game-won .memory-grid {
    animation: celebration 1s ease-in-out;
}

@keyframes celebration {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(1.02) rotate(1deg); }
    75% { transform: scale(1.02) rotate(-1deg); }
}
