/* Math Match Styles */
:root {
    --bg-color: #E0E0E0;
    --card-color: #F44336; /* Red as per user image */
    --card-back: #F44336;
    --card-face: #eee;
    --text-color: #333;
    --accent: #FFD54F;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Roboto', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
    user-select: none;
}

.home-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    font-size: 1.5rem;
    color: #555;
    background: #fff;
    width: 40px; height: 40px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    text-decoration: none;
    z-index: 100;
}

.header-bar {
    position: absolute;
    top: 0; left: 0; width: 100%;
    padding: 20px 60px; /* Space for home btn */
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none; /* Let clicks pass through */
}

.score-box, .timer-box {
    background: #fff;
    padding: 10px 20px;
    border-radius: 20px;
    font-family: 'Fredoka One', cursive;
    font-size: 1.5rem;
    box-shadow: 0 4px 0 rgba(0,0,0,0.1);
    color: #444;
}

.combo-box {
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    color: #FF9800;
    font-family: 'Fredoka One', cursive;
    font-size: 2rem;
    text-shadow: 2px 2px 0 #fff;
    transition: opacity 0.3s;
}

/* Screens */
.screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s;
    background: var(--bg-color);
    z-index: 10;
}
.screen:not(.active) {
    transform: translateY(100%);
    pointer-events: none;
}

/* Mode Selection */
.mode-grid {
    display: flex;
    gap: 20px;
    margin: 30px 0;
    flex-wrap: wrap;
    justify-content: center;
}

.mode-card {
    background: #fff;
    width: 120px;
    height: 120px;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 5px 0 #ccc;
    transition: transform 0.1s;
    border: 3px solid transparent;
}
.mode-card:hover { transform: translateY(-5px); }
.mode-card:active { transform: translateY(0); box-shadow: none; }
.mode-card.selected { border-color: #F44336; background: #FFF3E0; }

.mode-card i { font-size: 2.5rem; color: #555; margin-bottom: 10px; }

.difficulty-select {
    margin-bottom: 30px;
    text-align: center;
}
.diff-options { display: flex; gap: 10px; justify-content: center; margin-top: 10px; }
.diff-btn {
    padding: 10px 20px;
    border: 2px solid #aaa;
    background: transparent;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    color: #666;
}
.diff-btn.selected {
    border-color: #F44336;
    background: #F44336;
    color: #fff;
}

.start-btn {
    padding: 15px 50px;
    font-size: 1.5rem;
    background: #4CAF50;
    color: #fff;
    border: none;
    border-radius: 30px;
    font-family: 'Fredoka One', cursive;
    cursor: pointer;
    box-shadow: 0 5px 0 #2E7D32;
    transition: transform 0.1s;
}
.start-btn:active { transform: translateY(5px); box-shadow: none; }

/* Game Grid */
.grid-container {
    display: grid;
    gap: 15px;
    width: 90%;
    max-width: 600px;
    perspective: 1000px;
}
/* Difficulty adjustments */
.grid-easy { grid-template-columns: repeat(3, 1fr); }
.grid-hard { grid-template-columns: repeat(4, 1fr); }
.grid-master { grid-template-columns: repeat(5, 1fr); }

.card {
    background-color: transparent;
    aspect-ratio: 1; /* Square cards */
    perspective: 1000px;
    cursor: pointer;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    border-radius: 15px;
}

.card.flipped .card-inner {
    transform: rotateY(180deg);
}

.card.matched .card-inner {
    opacity: 0; /* Fade out or stay flipped? User requested "Memory Game" typically keeps them face up or removes them. Let's keep face up but dim. */
    opacity: 0.5;
    pointer-events: none;
    animation: popSuccess 0.3s;
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 15px;
    font-weight: bold;
    font-size: 2.2rem; /* Increased from 1.8rem */
    font-family: 'Fredoka One', cursive;
}

.card-front {
    background-color: var(--card-face);
    color: #333;
    transform: rotateY(180deg);
    border: 3px solid #ddd;
}

.card-back {
    background-color: var(--card-color);
    color: white;
}
/* Dots representation */
.dots-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px; /* Slightly larger gap */
    width: 80%; /* Larger container */
    height: 80%;
    align-content: center; /* Center content vertically */
    justify-content: center;
}
.dot {
    width: 100%;
    aspect-ratio: 1;
    background: #444;
    border-radius: 50%;
    /* Ensure they fit nicely */
    max-width: 25px; 
    max-height: 25px;
    margin: auto;
}

@keyframes popSuccess {
    0% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(180deg) scale(1.2); }
    100% { transform: rotateY(180deg) scale(1); }
}

/* Modals */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
}
.modal-content {
    background: #fff;
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    min-width: 300px;
}
.btn-control {
    padding: 10px 20px;
    margin: 10px;
    border: none;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
    color: #fff;
    font-size: 1rem;
}
.btn-control.yellow { background: #FFC107; }
.btn-control.green { background: #4CAF50; }

@media (max-width: 600px) {
    .grid-container { width: 95%; gap: 10px; }
    .card-front { font-size: 1.2rem; }
    .dot { width: 80%; }
}
