/* Reset and base styles for consistent rendering across browsers */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow: hidden;
    user-select: none;
}

/* Main container with responsive height based on environment */
.game-container {
    width: 100%;
    height: 450px; /* Default iframe height */
    display: flex;
    flex-direction: column;
    position: relative;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

/* Responsive height for full browser tab */
@media (min-height: 500px) {
    .game-container {
        height: 90vh;
    }
}

/* Header section with game information */
.game-header {
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.2);
    border-bottom: 2px solid rgba(255, 255, 255, 0.3);
}

.info-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 100%;
}

.level-display, .score-display, .timer-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    min-width: 70px;
    cursor: help;
}

.label {
    font-size: 10px;
    font-weight: bold;
    color: #666;
    text-transform: uppercase;
}

#level-number, #score, #timer {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    margin-top: 2px;
}

/* Timer color changes based on urgency */
.timer-warning {
    color: #ff6b35 !important;
    animation: pulse 1s infinite;
}

.timer-critical {
    color: #e74c3c !important;
    animation: pulse 0.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Main game area containing the card grid */
.game-area {
    flex: 1;
    padding: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
}

/* Dynamic grid layout that adapts to different levels */
.game-grid {
    display: grid;
    gap: 8px;
    max-width: 100%;
    max-height: 100%;
    justify-content: center;
    align-content: center;
}

/* Grid configurations for different levels */
.grid-2x2 { grid-template-columns: repeat(2, 1fr); }
.grid-4x2 { grid-template-columns: repeat(4, 1fr); }
.grid-4x4 { grid-template-columns: repeat(4, 1fr); }
.grid-8x4 { grid-template-columns: repeat(8, 1fr); }
.grid-8x8 { grid-template-columns: repeat(8, 1fr); }

/* Individual card styling with interactive states */
.card {
    aspect-ratio: 1;
    background: linear-gradient(145deg, #ffffff, #f0f0f0);
    border: 2px solid #ddd;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    min-width: 60px;
    min-height: 60px;
    position: relative;
    overflow: hidden;
}

/* Responsive card sizing */
@media (max-width: 768px) {
    .card {
        min-width: 45px;
        min-height: 45px;
    }
}

/* Card hover and interaction states */
.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
    border-color: #4CAF50;
}

.card:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Card states for game logic */
.card.flipped {
    background: linear-gradient(145deg, #4CAF50, #45a049);
    border-color: #4CAF50;
    color: white;
    transform: rotateY(180deg);
}

.card.matched {
    background: linear-gradient(145deg, #2196F3, #1976D2);
    border-color: #2196F3;
    color: white;
    animation: matchSuccess 0.6s ease;
}

.card.wrong {
    background: linear-gradient(145deg, #f44336, #d32f2f);
    border-color: #f44336;
    color: white;
    animation: shake 0.5s ease;
}

/* Fraction display within cards */
.fraction {
    font-size: clamp(14px, 3vw, 24px);
    font-weight: bold;
    text-align: center;
    line-height: 1;
}

/* Animation keyframes for visual feedback */
@keyframes matchSuccess {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@keyframes fadeOut {
    0% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.8); }
}

/* Control buttons styling */
.controls {
    padding: 15px;
    display: flex;
    justify-content: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.1);
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    min-height: 44px; /* Touch-friendly minimum size */
}

.btn-primary {
    background: linear-gradient(145deg, #4CAF50, #45a049);
    color: white;
    box-shadow: 0 4px 8px rgba(76, 175, 80, 0.3);
}

.btn-secondary {
    background: linear-gradient(145deg, #2196F3, #1976D2);
    color: white;
    box-shadow: 0 4px 8px rgba(33, 150, 243, 0.3);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.btn:active {
    transform: translateY(0);
}

/* Modal styling for game messages */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    max-width: 90%;
    max-height: 80%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: modalAppear 0.3s ease;
}

@keyframes modalAppear {
    0% { opacity: 0; transform: scale(0.8); }
    100% { opacity: 1; transform: scale(1); }
}

#modal-title {
    color: #333;
    margin-bottom: 15px;
    font-size: 24px;
}

#modal-message {
    color: #666;
    margin-bottom: 20px;
    line-height: 1.5;
}

/* Tooltip for additional information */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    pointer-events: none;
    z-index: 1001;
    opacity: 0;
    transition: opacity 0.3s ease;
    max-width: 200px;
    text-align: center;
}

.tooltip.show {
    opacity: 1;
}

/* Responsive design for mobile devices */
@media (max-width: 480px) {
    .game-header {
        padding: 8px 10px;
    }
    
    .info-panel {
        gap: 5px;
    }
    
    .level-display, .score-display, .timer-display {
        padding: 6px 8px;
        min-width: 60px;
    }
    
    .game-area {
        padding: 10px;
    }
    
    .game-grid {
        gap: 4px;
    }
    
    .controls {
        padding: 10px;
        gap: 8px;
    }
    
    .btn {
        padding: 10px 16px;
        font-size: 12px;
    }
}