/* Memory Game Styles - Mobile Optimized */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

#app {
    width: 100vw;
    min-height: 100vh;
    position: relative;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 100vh;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 1rem;
    padding-top: 2rem;
}

.screen.active {
    display: flex;
}

/* Game Screen Layout - Vertical Stack */
.game-screen {
    gap: 1rem;
    justify-content: flex-start;
}

.container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    text-align: center;
    max-width: 400px;
    width: 100%;
    backdrop-filter: blur(10px);
}

/* Typography */
.title {
    font-size: 2.5rem;
    font-weight: 800;
    color: #333;
    margin-bottom: 0.5rem;
    background: linear-gradient(45deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: #666;
    margin-bottom: 2rem;
    font-size: 1rem;
}

/* Buttons */
.btn {
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    font-size: 1rem;
}

.btn:hover {
    transform: translateY(-2px);
}

/* Difficulty Buttons */
.difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

.difficulty-btn {
    background: white;
    border: 2px solid #e0e0e0;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.difficulty-btn:hover {
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.btn-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.difficulty-name {
    font-weight: 600;
    font-size: 1.1rem;
}

.difficulty-desc {
    font-size: 0.9rem;
    opacity: 0.8;
}

.easy {
    border-color: #4CAF50;
}

.easy:hover {
    background: #4CAF50;
    color: white;
}

.medium {
    border-color: #FF9800;
}

.medium:hover {
    background: #FF9800;
    color: white;
}

.hard {
    border-color: #F44336;
}

.hard:hover {
    background: #F44336;
    color: white;
}

/* High Scores */
.high-scores {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.high-scores h3 {
    margin-bottom: 1rem;
    color: #333;
    font-size: 1rem;
}

.scores-grid {
    display: grid;
    gap: 0.5rem;
}

.score-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}

/* Settings Button */
.settings-btn {
    background: #6c757d;
    color: white;
    padding: 0.75rem 1.5rem;
}

.settings-btn:hover {
    background: #5a6268;
}

/* Game UI - Compact for Mobile */
.game-ui {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    width: 100%;
    max-width: 90vw;
    margin: 0 auto;
}

.ui-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.back-btn, .sound-btn {
    background: #6c757d;
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.back-btn:hover, .sound-btn:hover {
    background: #5a6268;
}

.difficulty-badge {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: 600;
    text-transform: capitalize;
    font-size: 0.9rem;
}

.ui-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    text-align: center;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stat-label {
    font-size: 0.75rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
}

/* Game Board - Optimized for Vertical Layout */
.game-board {
    display: grid;
    gap: 0.5rem;
    justify-content: center;
    width: 100%;
    max-width: 90vw;
    margin: 0 auto;
}

.grid-easy {
    grid-template-columns: repeat(5, 1fr);
    max-width: 300px;
}

.grid-medium {
    grid-template-columns: repeat(4, 1fr);
    max-width: 260px;
}

.grid-hard {
    grid-template-columns: repeat(6, 1fr);
    max-width: 320px;
}

/* Game Cards - Smaller for Mobile */
.game-card {
    width: 55px;
    height: 55px;
    perspective: 1000px;
    cursor: pointer;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

.game-card.flipped .card-inner {
    transform: rotateY(180deg);
}

.game-card.matched .card-inner {
    animation: matchPulse 0.5s ease;
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 8px;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.card-front {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
}

.card-back {
    background: white;
    transform: rotateY(180deg);
    border: 2px solid #e0e0e0;
    padding: 4px;
}

.card-back img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 4px;
}

@keyframes matchPulse {
    0%, 100% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(180deg) scale(1.1); }
}

/* Win Screen */
.celebration {
    font-size: 3rem;
    margin-bottom: 1rem;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-20px); }
    60% { transform: translateY(-10px); }
}

.win-title {
    font-size: 1.8rem;
    font-weight: 800;
    color: #333;
    margin-bottom: 0.5rem;
}

.win-subtitle {
    color: #666;
    margin-bottom: 1rem;
}

.new-high-score {
    background: linear-gradient(45deg, #FFD700, #FFA500);
    color: white;
    padding: 0.75rem;
    border-radius: 12px;
    margin: 1rem 0;
    font-weight: 600;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.win-stats {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 1rem;
    margin: 1.5rem 0;
    display: grid;
    gap: 0.75rem;
}

.win-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.win-stat-label {
    font-weight: 500;
    color: #666;
}

.win-stat-value {
    font-weight: 600;
    color: #333;
    font-size: 1.1rem;
}

.win-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn.primary {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    padding: 0.75rem 1.5rem;
}

.btn.primary:hover {
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn.secondary {
    background: #6c757d;
    color: white;
    padding: 0.75rem 1.5rem;
}

.btn.secondary:hover {
    background: #5a6268;
}

/* Settings Screen */
.settings-title {
    font-size: 1.8rem;
    font-weight: 800;
    color: #333;
    margin-bottom: 2rem;
}

.settings-section {
    margin-bottom: 2rem;
    text-align: left;
}

.settings-section h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 1rem;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: #f8f9fa;
    border-radius: 8px;
}

.toggle-btn {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 20px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: background 0.3s ease;
    min-width: 60px;
    font-size: 0.9rem;
}

.toggle-btn.active {
    background: #28a745;
}

.current-scores {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.score-display {
    padding: 0.5rem 0;
    border-bottom: 1px solid #e0e0e0;
}

.score-display:last-child {
    border-bottom: none;
}

.reset-btn {
    background: #dc3545;
    color: white;
    padding: 0.75rem 1rem;
    width: 100%;
}

.reset-btn:hover {
    background: #c82333;
}

.instructions {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1rem;
    text-align: left;
}

.instructions p {
    margin: 0.5rem 0;
    color: #666;
    font-size: 0.9rem;
}

.back-btn-settings {
    background: #6c757d;
    color: white;
    padding: 0.75rem 1.5rem;
    width: 100%;
}

.back-btn-settings:hover {
    background: #5a6268;
}

/* Mobile-First Responsive Design */
@media (max-width: 768px) {
    body {
        overflow-y: auto;
    }
    
    .screen {
        padding: 1rem;
        padding-top: 1rem;
        justify-content: flex-start;
        overflow-y: auto;
    }
    
    /* Game UI - Compact and Full Width */
    .game-ui {
        width: 100%;
        max-width: none;
        margin-bottom: 1rem;
        padding: 0.8rem;
    }
    
    .ui-top {
        justify-content: space-between;
        margin-bottom: 0.8rem;
    }
    
    .back-btn, .sound-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
    }
    
    .difficulty-badge {
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
    }
    
    /* Stats in Grid Layout for Mobile */
    .ui-stats {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
        text-align: center;
    }
    
    .stat {
        flex-direction: column;
        gap: 0.2rem;
    }
    
    .stat-label {
        font-size: 0.7rem;
    }
    
    .stat-value {
        font-size: 1rem;
    }
    
    /* Game Board - Centered and Properly Sized */
    .game-board {
        gap: 0.4rem;
        width: 100%;
        max-width: 100vw;
        padding: 0 0.5rem;
    }
    
    .grid-easy {
        grid-template-columns: repeat(5, 1fr);
        max-width: 280px;
    }
    
    .grid-medium {
        grid-template-columns: repeat(4, 1fr);
        max-width: 230px;
    }
    
    .grid-hard {
        grid-template-columns: repeat(6, 1fr);
        max-width: 300px;
    }
    
    .game-card {
        width: 48px;
        height: 48px;
    }
    
    .card-front {
        font-size: 1.3rem;
    }
    
    /* Win screen adjustments */
    .win-buttons {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .celebration {
        font-size: 2.5rem;
    }
}

@media (max-width: 480px) {
    .screen {
        padding: 0.8rem;
        gap: 0.8rem;
    }
    
    .container {
        padding: 1.2rem;
        margin: 0;
        border-radius: 16px;
    }
    
    .title {
        font-size: 1.8rem;
    }
    
    .game-ui {
        padding: 0.7rem;
        border-radius: 10px;
    }
    
    /* Extra small game cards for very small screens */
    .game-card {
        width: 42px;
        height: 42px;
    }
    
    .card-front {
        font-size: 1.1rem;
    }
    
    .grid-easy {
        max-width: 240px;
    }
    
    .grid-medium {
        max-width: 190px;
    }
    
    .grid-hard {
        max-width: 270px;
    }
    
    /* Smaller UI elements */
    .back-btn, .sound-btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.8rem;
    }
    
    .difficulty-badge {
        padding: 0.3rem 0.6rem;
        font-size: 0.8rem;
    }
    
    .ui-stats {
        gap: 0.3rem;
    }
    
    .stat-label {
        font-size: 0.65rem;
    }
    
    .stat-value {
        font-size: 0.9rem;
    }
}

/* Landscape Phone Optimization */
@media (max-height: 500px) and (orientation: landscape) {
    .screen {
        padding: 0.5rem;
        justify-content: center;
    }
    
    .game-ui {
        padding: 0.5rem;
        margin-bottom: 0.5rem;
    }
    
    .ui-top {
        margin-bottom: 0.5rem;
    }
    
    .game-card {
        width: 40px;
        height: 40px;
    }
    
    .card-front {
        font-size: 1rem;
    }
    
    .grid-easy {
        max-width: 220px;
    }
    
    .grid-medium {
        max-width: 180px;
    }
    
    .grid-hard {
        max-width: 260px;
    }
}