:root {
    --bg-color: #fce4ec;
    /* Soft pink background */
    --primary-color: #ff80ab;
    /* Deeper pink for accents */
    --secondary-color: #40c4ff;
    /* Light blue for UI elements */
    --text-color: #3e2723;
    /* Dark brown for friendly readable text */
    --card-bg-front: #ffffff;
    /* White for picture background */
    --card-bg-back: #b39ddb;
    /* Soft purple for card back */
    --card-bg-back-hover: #9575cd;
    --success-color: #69f0ae;
    /* Soft green for matching */
    --board-bg: #fff8e1;
    /* Soft yellow board */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Nunito', sans-serif;
    user-select: none;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
    padding: 20px;
}

/* --- Start Menu Styles --- */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    transition: opacity 0.5s ease;
}

.menu-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.menu-content {
    background-color: var(--board-bg);
    padding: 40px;
    border-radius: 30px;
    text-align: center;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
    border: 8px solid var(--secondary-color);
    max-width: 600px;
    width: 90%;
}

.menu-content h1 {
    font-size: 3.5rem;
    margin-bottom: 10px;
}

.menu-content h2 {
    font-size: 1.8rem;
    color: var(--text-color);
    margin-bottom: 30px;
}

.timer-selection {
    margin-bottom: 30px;
    background: rgba(255, 255, 255, 0.6);
    padding: 20px;
    border-radius: 16px;
}

.timer-selection h3 {
    margin-bottom: 15px;
    font-size: 1.3rem;
    color: var(--text-color);
}

.timer-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.timer-btn,
.diff-btn {
    background-color: #fff;
    color: var(--text-color);
    border: 3px solid #ccc;
    border-radius: 20px;
    padding: 10px 20px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.timer-btn:hover,
.diff-btn:hover {
    border-color: var(--secondary-color);
}

.timer-btn.selected,
.diff-btn.selected {
    background-color: var(--secondary-color);
    color: white;
    border-color: var(--secondary-color);
    box-shadow: 0 4px 0 #0091ea;
    transform: translateY(-2px);
}

.btn-start {
    font-size: 1.8rem;
    padding: 15px 50px;
    background-color: #00e676;
    /* Bright kid-friendly green for START */
    box-shadow: 0 6px 0 #00b0ff;
}

.btn-start:active {
    box-shadow: 0 0 0 #00b0ff;
}

.hidden {
    display: none !important;
}

/* --- Game Container --- */
.game-container {
    background-color: var(--board-bg);
    border-radius: 24px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    padding: 4vw;
    width: 100%;
    max-width: 1000px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    flex-wrap: wrap;
    gap: 15px;
}

h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.05);
    margin: 0;
}

.stats {
    display: flex;
    gap: 20px;
}

.stat-box {
    background-color: white;
    padding: 8px 20px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    border: 3px solid var(--secondary-color);
}

.stat-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--secondary-color);
}

.btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 12px 24px;
    font-size: 1.2rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 6px 0 #c51162;
    transition: all 0.1s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 #c51162;
}

.btn-large {
    font-size: 1.5rem;
    padding: 15px 40px;
    margin-top: 20px;
}

.game-board {
    display: grid;
    gap: 12px;
    width: 100%;
    max-height: 70vh;
}

/* Responsive adjustments handled dynamically */

.card {
    aspect-ratio: 1;
    perspective: 1000px;
    cursor: pointer;
    border-radius: 16px;
    width: 100%;
    height: 100%;
}

.card-inner {
    width: 100%;
    height: 100%;
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-style: preserve-3d;
    position: relative;
    border-radius: 16px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.card.flipped .card-inner,
.card.matched .card-inner {
    transform: rotateY(180deg);
}

.card-front,
.card-back {
    width: 100%;
    height: 100%;
    position: absolute;
    backface-visibility: hidden;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.card-back {
    background-color: var(--card-bg-back);
    background-image: radial-gradient(circle at center, rgba(255, 255, 255, 0.4) 0%, transparent 70%);
    border: 3px solid rgba(255, 255, 255, 0.5);
    font-size: 3rem;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s;
}

.card:hover .card-back {
    background-color: var(--card-bg-back-hover);
}

.card-back::after {
    content: '?';
    color: white;
    font-size: 3rem;
    font-weight: 900;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.card-front {
    background-color: var(--card-bg-front);
    transform: rotateY(180deg);
    border: 3px solid var(--secondary-color);
}

.card.matched .card-front {
    background-color: var(--success-color);
    border-color: #00c853;
}

.card-front .animal-emoji {
    font-size: 3.5rem;
    margin-top: 5px;
}

.card-front .animal-name {
    font-size: 0.8rem;
    font-weight: 800;
    text-transform: capitalize;
    margin-top: 2px;
    color: var(--text-color);
    text-align: center;
    line-height: 1;
}

.timer-alert {
    color: #f44336;
    animation: flashAlert 1s infinite alternate;
}

@keyframes flashAlert {
    from {
        color: #f44336;
    }

    to {
        color: #d32f2f;
        transform: scale(1.05);
    }
}

/* Modal Styling */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background-color: white;
    padding: 50px 40px;
    border-radius: 30px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    max-width: 90%;
    width: 500px;
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 8px solid var(--secondary-color);
}

.modal.hidden .modal-content {
    transform: scale(0.8);
}

.modal-content h2 {
    font-size: 3.5rem;
    color: var(--primary-color);
    margin-bottom: 20px;
}

.modal-content p {
    font-size: 1.5rem;
    margin-bottom: 20px;
}

.highlight {
    color: var(--primary-color);
    font-weight: 900;
    font-size: 2rem;
}

.bounce {
    animation: bounce 2s infinite ease-in-out;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-15px);
    }
}

@keyframes matchPulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

.card.matched {
    animation: matchPulse 0.5s ease-out;
}

/* Confetti */
.confetti {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Back to Hub Button */
.btn-back-hub {
    position: absolute;
    top: 20px;
    left: 20px;
    background-color: #ff6b6b;
    color: white;
    text-decoration: none;
    padding: 10px 20px;
    border-radius: 50px;
    font-weight: bold;
    font-size: 1.1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    z-index: 9999;
}

.btn-back-hub:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

/* --- Responsive Adjustments --- */
@media (max-width: 600px) {
    .menu-overlay {
        align-items: flex-start;
        padding-top: 80px;
        /* Space for the back button */
        padding-bottom: 20px;
        overflow-y: auto;
    }

    .menu-content {
        padding: 20px;
        margin: auto;
        /* Centers effectively, allows scrolling if larger */
        width: 95%;
    }

    .menu-content h1 {
        font-size: 2.2rem;
    }

    .menu-content h2 {
        font-size: 1.3rem;
        margin-bottom: 15px;
    }

    .timer-selection {
        padding: 15px;
        margin-bottom: 15px;
    }

    .timer-btn,
    .diff-btn {
        padding: 8px 12px;
        font-size: 0.95rem;
    }

    .btn-start {
        font-size: 1.4rem;
        padding: 12px 30px;
    }

    .btn-back-hub {
        top: 10px;
        left: 10px;
        font-size: 0.9rem;
        padding: 8px 15px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    .stats {
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
        width: 100%;
    }

    .stat-box {
        padding: 8px 10px;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    .game-board {
        gap: 8px;
    }

    .modal-content {
        padding: 30px 20px;
        width: 95%;
    }

    .modal-content h2 {
        font-size: 2.2rem;
    }
}

/* Handle short screens (landscape mobile) */
@media (max-height: 700px) {
    .menu-overlay {
        align-items: flex-start;
        padding-top: 70px;
        padding-bottom: 20px;
        overflow-y: auto;
    }

    .menu-content {
        margin: auto;
    }
}