/* === GLOBAL STYLES === */
body {
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: Roboto, sans-serif;
    min-height: 100%;
    background-color: #f0f0f0;
    height: 95vh;
}

/* === GAME CONTAINER === */
.game-container {
    width: 95%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    border: solid 5px #025ab900;
    /*For checking out the container area occupied. Reduce opacity to to view*/
}

/* === GAME BOARD === */
.game-board {
    width: 95vw;
    /* Adjusted to maintain card squareness */
    max-width: 720px;
    height: 71.25vw;
    /* 3/4 of the width for a 3x4 board */
    max-height: 550px;
    /* 3/4 of the max-width */
    min-height: 100px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1vw;
    /* Provides consistent spacing between the cards */
    border: #ff407c00 solid 2px;
    /*For checking out the borad area occupied. Reduce opacity to to view*/
}

/* === CARDS === */
.card {
    width: 100%;
    height: 100%;
    background-color: #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
    perspective: 1000px;
    cursor: pointer;
}

.card-back,
.card-front {
    height: 100%;
    width: 100%;
    position: absolute;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgb(255, 255, 255);
    border-radius: 10px;
    transition: transform 1s;
}

.card-back {
    background-color: #f5f5f5;
    background-image: url("images/globe.webp");
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.card-front {
    transform: rotateY(180deg);
    background-size: cover;
    background-position: center;
}

.card.flipped .card-front {
    transform: rotateY(0);
}

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

/* === GAME INFO === */
.game-info {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f7f7f7;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.363);
}

#timer {
    max-width: 720px;
    font-size: 25px;
    background-color: #ffffff;
    padding: 4px 8px;
    border-radius: 5px;
}

.hidden {
    display: none;
}

/* === MODALS === */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.404);
    z-index: 1000;
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 20px;
    text-align: center;
    background-color: #f9f9f9;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.253);
    border-radius: 8px;
    padding: 20px;
}

.modal-content h2 {
    color: #333;
    font-weight: 400;
    font-size: 24px;
    margin-bottom: 15px;
}

.modal-content p {
    color: #3a3a3a;
    font-weight: 200;
    font-size: 18px;
    font-stretch: 100%;
    line-height: 1.5;
    /* margin: 3px 0; */
}

/* ===Intro modal === */
#introModal {
    background-color: rgba(0, 0, 0, 0.7);
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#modalWelcome {
    width: 80vw;
    max-width: 500px;
    /* Added a max-width for better control */
    height: auto;
    max-height: 80vh;
    overflow: auto;
    background-color: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    padding: 5px 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

#modalWelcome p {
    color: #000000;
    font-weight: 500;
    padding: 0.8%;
    margin: 0;
    /* To remove any default margin */
}

button {
    font-weight: 500;
    padding: 15px 30px;
    margin: 5px;
    border: none;
    background-color: #ff407d;
    color: #fff;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}

#startGame {
    padding: 15px 40px;
    animation: pulsate 2s infinite;
    background-color: #ff407d;
}

button:hover {
    background-color: #b90b43;
}

#startGame {
    animation: pulsate 2s infinite;
    background-color: #ff407d;
}

.modal-buttons {
    display: flex;
    justify-content: center;
    margin-top: 20px;
    width: 100%;
}


/*  === Win - Modal === */
#winModal {
    background-color: rgba(0, 0, 0, 0.7);
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    /* Ensure it's above other content */
}

#winModalContent {
    width: 80vw;
    max-width: 600px;
    height: auto;
    max-height: 80vh;
    overflow: auto;
    background-color: #f9f9f9;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    padding: 2vw;
}

#winModalContent h2 {
    font-size: clamp(1.5rem, 4vw, 2rem);
    text-align: center;
}

#winModalContent p {
    font-size: clamp(0.8rem, 2.5vw, 1.2rem);
    text-align: center;
}

#winModal .green-text {
    /* for the rank message*/
    color: green;
}


#startGame {
    animation: pulsate 2s infinite;
    background-color: #ff407d;
}

.loading-spinner {
    border: 8px solid #3498db;
    border-top: 8px solid #ff407d;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 10px auto;
    z-index: 10;
    background-color: rgba(255, 255, 255, 0.11);
    position: absolute;
    align-self: center;
    top: 30%;
    left: 40%;
    transform: translate(-50%, -50%);
}

/* === KEYFRAMES === */
@keyframes pulsate {
    0% {
        transform: scale(1);
        opacity: 0.9;
    }

    50% {
        transform: scale(1.05);
        opacity: 1;
    }

    100% {
        transform: scale(1);
        opacity: 0.9;
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* === MEDIA QUERIES === */
@media (min-width: 801px) {
    .game-board {
        grid-template-columns: repeat(5, 1fr);
    }
}

@media (min-width: 601px) {
    .game-board {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 700px) {
    .modal-content h2 {
        font-size: 20px;
        margin-bottom: 10px;
    }

    .modal-content p {
        font-size: 16px;
    }

    .modal-content label {
        font-size: 12px;
    }

    button {
        padding: 8px 15px;
        font-size: 14px;
    }

    .modal-content,
    #winModalContent {
        width: 100%;
        height: 100%;
        max-height: 100vh;
    }

    #modalWelcome {
        width: 80%;
        height: 45%
    }
}

@media (max-width: 600px) {
    .game-board {
        width: 98vw;
        /* Adjusted to maintain card squareness */
        max-width: 720px;
        height: 73.5vw;
        /* 3/4 of the width for a 3x4 board */
        max-height: 550px;
        /* 3/4 of the max-width */
    }

    #modalWelcome,
    #winModalContent {
        padding: 2px 5px;
        /* Reduced padding */
        width: 95vw;
        /* Slightly increased width */
    }

    #modalWelcome p,
    #winModalContent h2,
    #winModalContent p {
        font-size: 13px;
        /* Reduced font size */
        padding: 0.8%;
        /* Reduced padding */
    }

    button {
        font-size: 14px;
        /* Reduced font size */
        padding: 8px 15px;
        /* Reduced padding */
    }

    #startGame {
        padding: 8px 20px;
        /* Reduced padding */
    }

    #winModalContent label {
        font-size: 12px;
        /* Reduced font size */
        margin-bottom: 5px;
        /* Reduced margin */
    }

    #winModalContent {
        /* width: 100%; */
        height: 100vh !important;
    }
}

@media (max-width: 550px) and (orientation: landscape) {
    .game-board {
        gap: 0px;
    }

    .game-info {
        display: flex;
        justify-content: center;
        margin-bottom: 5px;
    }

    #timer {
        font-size: 20px;
        background-color: #fff;
        padding: 5px 10px;
        border-radius: 5px;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }

    .modal-content,
    #winModalContent {
        width: 100%;
        height: 100%;
    }
}