/* ================================
   RESET & BASE STYLES
   ================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Comic Sans MS', 'Arial Rounded MT Bold', cursive, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

/* ================================
   SCREEN MANAGEMENT
   ================================ */
.screen {
    display: none;
    width: 100%;
    min-height: 100vh;
    padding: 20px;
}

.screen.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ================================
   LEVEL SELECTION SCREEN
   ================================ */
.level-container {
    background: white;
    border-radius: 30px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
    max-width: 600px;
    width: 100%;
    animation: slideIn 0.5s ease-out;
}

.game-title {
    font-size: 3rem;
    color: #667eea;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.subtitle {
    font-size: 1.5rem;
    color: #764ba2;
    margin-bottom: 30px;
}

.level-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 30px;
}

.level-btn {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border: none;
    border-radius: 20px;
    padding: 25px;
    font-size: 1.5rem;
    font-weight: bold;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.level-btn:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.level-btn:active {
    transform: translateY(-2px) scale(0.98);
}

.level-btn.easy {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    color: #333;
}

.level-btn.medium {
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    color: #333;
}

.level-btn.hard {
    background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
    color: #333;
}

.level-btn .emoji {
    font-size: 3rem;
}

.level-info {
    font-size: 1rem;
    opacity: 0.8;
}

.best-score {
    background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
    padding: 15px;
    border-radius: 15px;
    font-size: 1.2rem;
    font-weight: bold;
    color: #333;
}

/* ================================
   GAME SCREEN
   ================================ */
.game-container {
    background: white;
    border-radius: 30px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 900px;
    width: 100%;
    animation: slideIn 0.5s ease-out;
}

.game-header {
    text-align: center;
    margin-bottom: 30px;
}

.game-title-small {
    font-size: 2rem;
    color: #667eea;
    margin-bottom: 20px;
}

.stats {
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
    padding: 15px;
    border-radius: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 0.9rem;
    color: #333;
    font-weight: bold;
}

.stat-value {
    font-size: 2rem;
    color: #e17055;
    font-weight: bold;
}

.stars {
    display: flex;
    gap: 5px;
    font-size: 1.5rem;
}

.star {
    transition: all 0.3s ease;
}

.star.earned {
    animation: starPop 0.5s ease;
}

.star.lost {
    opacity: 0.3;
    filter: grayscale(100%);
}

/* ================================
   GAME BOARD & CARDS
   ================================ */
.game-board {
    display: grid;
    gap: 15px;
    margin: 30px 0;
    justify-content: center;
}

/* Grid layouts for different difficulty levels */
.game-board.easy {
    grid-template-columns: repeat(3, 120px);
}

.game-board.medium {
    grid-template-columns: repeat(4, 110px);
}

.game-board.hard {
    grid-template-columns: repeat(5, 100px);
}

/* Card Styling */
.card {
    width: 100%;
    aspect-ratio: 1;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3rem;
    cursor: pointer;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.card:hover {
    transform: scale(1.05);
}

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

.card.matched {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    animation: matchBounce 0.6s ease;
    pointer-events: none;
}

.card-front,
.card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 15px;
}

.card-back {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    font-size: 2rem;
}

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

/* ================================
   FEEDBACK MESSAGES
   ================================ */
.feedback {
    text-align: center;
    font-size: 2rem;
    font-weight: bold;
    min-height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 20px 0;
}

.feedback.show {
    animation: feedbackPop 0.6s ease;
}

.feedback.positive {
    color: #00b894;
}

.feedback.negative {
    color: #ff7675;
}

/* ================================
   GAME FOOTER / CONTROLS
   ================================ */
.game-footer {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-restart,
.btn-back {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border: none;
    border-radius: 15px;
    padding: 15px 30px;
    font-size: 1.2rem;
    font-weight: bold;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.btn-back {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    color: #333;
}

.btn-restart:hover,
.btn-back:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.btn-restart:active,
.btn-back:active {
    transform: translateY(-1px);
}

/* ================================
   WIN SCREEN
   ================================ */
.win-container {
    background: white;
    border-radius: 30px;
    padding: 50px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
    max-width: 600px;
    width: 100%;
    z-index: 10;
    position: relative;
    animation: slideIn 0.8s ease-out;
}

.win-title {
    font-size: 3.5rem;
    color: #00b894;
    margin-bottom: 20px;
    animation: winTitleBounce 1s ease infinite;
}

.win-message {
    font-size: 1.5rem;
    color: #667eea;
    margin-bottom: 30px;
}

.win-stats {
    display: flex;
    justify-content: space-around;
    margin: 30px 0;
    gap: 20px;
}

.win-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%);
    padding: 20px;
    border-radius: 20px;
    font-size: 2rem;
    font-weight: bold;
    color: #333;
    flex: 1;
}

.win-emoji {
    font-size: 3rem;
    margin-bottom: 10px;
}

.win-stat span:last-child {
    font-size: 1rem;
    opacity: 0.8;
}

.win-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.btn-play-again,
.btn-menu {
    background: linear-gradient(135deg, #00b894 0%, #00cec9 100%);
    border: none;
    border-radius: 20px;
    padding: 20px;
    font-size: 1.3rem;
    font-weight: bold;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.btn-menu {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    color: #333;
}

.btn-play-again:hover,
.btn-menu:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* ================================
   CONFETTI ANIMATION
   ================================ */
#confetti {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.confetti-piece {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #f093fb;
    top: -10px;
    opacity: 0;
    animation: confettiFall 3s ease-out forwards;
}

/* ================================
   ANIMATIONS
   ================================ */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes matchBounce {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15) rotate(5deg);
    }
}

@keyframes starPop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.5) rotate(20deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
    }
}

@keyframes feedbackPop {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

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

@keyframes confettiFall {
    to {
        top: 100vh;
        opacity: 1;
        transform: translateX(var(--x)) rotate(var(--rotate));
    }
}

/* ================================
   RESPONSIVE DESIGN
   ================================ */
@media (max-width: 768px) {
    .game-title {
        font-size: 2rem;
    }
    
    .level-btn {
        font-size: 1.2rem;
        padding: 20px;
    }
    
    .game-board.easy {
        grid-template-columns: repeat(3, 100px);
    }
    
    .game-board.medium {
        grid-template-columns: repeat(4, 80px);
    }
    
    .game-board.hard {
        grid-template-columns: repeat(5, 70px);
    }
    
    .card {
        font-size: 2rem;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    .win-title {
        font-size: 2.5rem;
    }
}

@media (max-width: 480px) {
    .game-board.easy {
        grid-template-columns: repeat(3, 90px);
    }
    
    .game-board.medium {
        grid-template-columns: repeat(4, 70px);
    }
    
    .game-board.hard {
        grid-template-columns: repeat(5, 55px);
    }
    
    .level-container,
    .game-container,
    .win-container {
        padding: 20px;
    }
}