:root {
    --primary-color: #FF7F50; /* Naruto Orange */
    --secondary-color: #4682B4; /* Konoha Blue */
    --background-color: #FFF8DC; /* Light paper */
    --card-color: #ffffff;
    --font-color: #333;
    --border-radius: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: var(--background-color);
    color: var(--font-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
    -webkit-tap-highlight-color: transparent;
}

#game-container {
    width: 100%;
    max-width: 95vw;
    text-align: center;
    position: relative;
    padding: 0;
    transition: max-width 0.3s ease-in-out;
}

header {
    margin-bottom: 1rem;
    position: relative;
    display: flex;
    align-items: center;
}

h1 {
    color: var(--primary-color);
    font-size: clamp(1.5rem, 5vw, 2.2rem);
    text-shadow: 2px 2px var(--secondary-color);
    margin: 0;
}

#stats {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
    font-size: clamp(1rem, 4vw, 1.2rem);
    background: var(--secondary-color);
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: var(--border-radius);
    text-align: center;
}

#back-to-menu {
    position: relative;
    top: auto;
    left: auto;
    background: transparent;
    color: var(--secondary-color);
    border: none;
    padding: 0;
    border-radius: 50%;
    font-size: clamp(1.8rem, 5vw, 2.2rem);
    cursor: pointer;
    width: 44px;
    height: 44px;
    line-height: 44px;
    text-align: center;
    transition: background-color 0.2s, color 0.2s;
    z-index: 10;
    flex-shrink: 0;
    margin-right: 10px;
}

#back-to-menu:hover {
    background-color: var(--secondary-color);
    color: white;
}

#game-board {
    display: grid;
    gap: 10px;
    perspective: 1000px;
}

/* Mobile-first grid layouts */
#game-board.level-easy {
    grid-template-columns: repeat(2, 1fr);
}
#game-board.level-medium {
    grid-template-columns: repeat(3, 1fr);
}
#game-board.level-hard {
    grid-template-columns: repeat(3, 1fr);
}

.card {
    background-color: transparent;
    aspect-ratio: 1 / 1;
    cursor: pointer;
    position: relative;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

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

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    overflow: hidden;
}

.card-front {
    background: var(--card-color);
    transform: rotateY(180deg);
}

.card-front img {
    width: 90%;
    height: 90%;
    object-fit: contain;
}

.card-back {
    background-color: var(--secondary-color);
    border: 4px solid var(--primary-color);
    background-image: url('card-back.png');
    background-size: 75%;
    background-repeat: no-repeat;
    background-position: center;
}

.card-back img {
    display: none;
}

.main-screen-naruto {
    max-width: 250px;
    width: 60vw;
    height: auto;
    max-height: 30vh;
    object-fit: contain;
}

#level-selection {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    text-align: center;
}

#level-selection.hidden,
#game-container.hidden {
    display: none;
}

#level-selection h2 {
    font-size: clamp(1.2rem, 5vw, 2rem);
    color: var(--secondary-color);
}

.level-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 300px;
}

.level-btn {
    font-size: clamp(1.2rem, 5vw, 1.8rem);
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    background-color: var(--secondary-color);
    color: white;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s;
    font-weight: bold;
    text-shadow: 1px 1px #00000050;
}

.level-btn:hover {
    transform: scale(1.05);
    background-color: var(--primary-color);
}

#win-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

#win-screen.hidden {
    display: none;
}

#win-message {
    font-size: clamp(2rem, 8vw, 4rem);
    color: white;
    background-color: var(--primary-color);
    padding: 1rem 2rem;
    border-radius: var(--border-radius);
    margin-bottom: 2rem;
    text-shadow: 3px 3px var(--secondary-color);
}

#play-again-btn {
    font-size: clamp(1.2rem, 5vw, 2rem);
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    background-color: var(--secondary-color);
    color: white;
    cursor: pointer;
    transition: transform 0.2s;
}

#play-again-btn:hover {
    transform: scale(1.05);
}

#game-title-and-stats {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

@media (max-width: 320px) {
    #game-board.level-medium {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 600px) {
    #game-container {
        max-width: 500px;
    }

    #game-board {
        gap: 15px;
    }

    #game-board.level-easy {
        grid-template-columns: repeat(3, 1fr);
    }

    #game-board.level-medium {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 768px) {
    #game-container {
        max-width: 700px;
    }

    #game-board {
        gap: 15px;
    }

    #game-board.level-hard {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 1024px) {
    #game-container {
        max-width: 800px;
    }
}