/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    background-size: 300% 300%;
    animation: gentleGradient 12s ease infinite;
    min-height: 100vh;
    height: 100vh;
    color: #2d3748;
    overflow: hidden;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
}

@keyframes gentleGradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Subtle magical elements */
body::before {
    content: '✨';
    position: fixed;
    top: 15%;
    left: 8%;
    font-size: 1.5rem;
    animation: gentleFloat 6s ease-in-out infinite;
    z-index: 1;
    opacity: 0.6;
}

body::after {
    content: '⭐';
    position: fixed;
    top: 75%;
    right: 12%;
    font-size: 1.2rem;
    animation: gentleFloat 8s ease-in-out infinite reverse;
    z-index: 1;
    opacity: 0.6;
}

@keyframes gentleFloat {
    0%, 100% { transform: translateY(0px) rotate(0deg); opacity: 0.6; }
    50% { transform: translateY(-15px) rotate(90deg); opacity: 0.8; }
}

/* Screen management */
.screen {
    display: none;
    height: 100vh;
    width: 100vw;
    padding: 10px;
    overflow: hidden;
    position: relative;
    z-index: 2;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* Setup Screen */
#setup-screen {
    justify-content: flex-start;
    align-items: center;
    padding: 10px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.setup-container {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 24px;
    padding: 32px 24px;
    box-shadow: 
        0 20px 40px rgba(0, 0, 0, 0.1),
        0 8px 24px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.5);
    max-width: 90vw;
    width: 100%;
    max-width: 420px;
    text-align: center;
    animation: slideUp 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: visible;
    margin: auto;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

@keyframes slideUp {
    0% { 
        transform: translateY(30px); 
        opacity: 0; 
        filter: blur(4px);
    }
    100% { 
        transform: translateY(0); 
        opacity: 1; 
        filter: blur(0);
    }
}

.setup-container h1 {
    font-size: 2.4rem;
    font-weight: 700;
    margin-bottom: 32px;
    background: linear-gradient(135deg, #667eea, #764ba2, #f093fb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

/* Professional Card Selection */
.selection-section {
    margin-bottom: 28px;
}

.selection-section h3 {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: #4a5568;
    text-align: center;
    letter-spacing: -0.2px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.selection-card {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(102, 126, 234, 0.1);
    border-radius: 20px;
    padding: 20px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 110px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.selection-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, transparent, rgba(102, 126, 234, 0.05), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.selection-card:hover {
    transform: translateY(-4px);
    border-color: rgba(102, 126, 234, 0.3);
    box-shadow: 
        0 12px 32px rgba(102, 126, 234, 0.15),
        0 4px 16px rgba(102, 126, 234, 0.1);
}

.selection-card:hover::before {
    opacity: 1;
}

.selection-card.selected {
    border-color: #667eea;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(255, 255, 255, 0.9));
    transform: translateY(-2px);
    box-shadow: 
        0 16px 40px rgba(102, 126, 234, 0.2),
        0 6px 20px rgba(102, 126, 234, 0.15);
}

.selection-card.selected .card-title {
    color: #667eea;
    font-weight: 600;
}

.card-icon {
    font-size: 2.2rem;
    margin-bottom: 12px;
    display: block;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: #2d3748;
    letter-spacing: -0.2px;
}

.card-description {
    font-size: 0.85rem;
    color: #718096;
    font-weight: 500;
    line-height: 1.3;
}

/* Professional Buttons */
.btn-primary, .btn-secondary {
    padding: 16px 32px;
    border: none;
    border-radius: 16px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    display: inline-block;
    min-height: 48px;
    position: relative;
    overflow: hidden;
    letter-spacing: -0.2px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    box-shadow: 
        0 8px 24px rgba(102, 126, 234, 0.3),
        0 4px 12px rgba(102, 126, 234, 0.2);
    margin-top: 20px;
    width: 100%;
    max-width: 280px;
}

.btn-primary:disabled {
    background: linear-gradient(135deg, #cbd5e0, #a0aec0);
    cursor: not-allowed;
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.1),
        0 2px 6px rgba(0, 0, 0, 0.08);
    opacity: 1 !important;
    transform: none !important;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 
        0 12px 32px rgba(102, 126, 234, 0.4),
        0 6px 16px rgba(102, 126, 234, 0.3);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.9);
    color: #4a5568;
    border: 2px solid rgba(102, 126, 234, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    min-height: 44px;
    backdrop-filter: blur(10px);
}

/* Smaller buttons for animal sounds game */
.animal-game-container .btn-secondary {
    padding: 8px 16px;
    font-size: 13px;
    min-height: 36px;
}

/* Compact header for setup screens */
#setup-screen .game-header,
#animal-sounds-screen .game-header {
    padding: 8px 12px;
    height: 48px;
}

#setup-screen .header-content h1,
#animal-sounds-screen .header-content h1 {
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0;
    background: linear-gradient(135deg, #667eea, #764ba2, #f093fb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 1);
    border-color: rgba(102, 126, 234, 0.4);
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

/* Game Screen */
#game-screen {
    padding: 0;
    height: 100vh;
    overflow: hidden;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    padding: 8px 12px;
    height: 48px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(102, 126, 234, 0.1);
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.05);
}

.header-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.header-content h1 {
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0;
    background: linear-gradient(135deg, #667eea, #764ba2, #f093fb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1;
}

.game-info {
    color: #4a5568;
    font-weight: 600;
    font-size: 16px;
    letter-spacing: -0.2px;
}

/* Professional Game Tiles */
.game-tile {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    aspect-ratio: 1;
    perspective: 1000px;
    cursor: pointer;
    position: relative;
    touch-action: manipulation;
    user-select: none;
    box-sizing: border-box;
    animation: gentleTileFloat 4s ease-in-out infinite;
    animation-delay: calc(var(--tile-index) * 0.1s);
}

.game-tile:nth-child(1) { --tile-index: 1; }
.game-tile:nth-child(2) { --tile-index: 2; }
.game-tile:nth-child(3) { --tile-index: 3; }
.game-tile:nth-child(4) { --tile-index: 4; }
.game-tile:nth-child(5) { --tile-index: 5; }
.game-tile:nth-child(6) { --tile-index: 6; }
.game-tile:nth-child(7) { --tile-index: 7; }
.game-tile:nth-child(8) { --tile-index: 8; }

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

.tile-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.game-tile.flipped .tile-inner {
    transform: rotateY(180deg);
    animation: professionalFlip 0.6s ease-out;
}

@keyframes professionalFlip {
    0% { transform: rotateY(0deg) scale(1); }
    50% { transform: rotateY(90deg) scale(1.05); }
    100% { transform: rotateY(180deg) scale(1); }
}

.tile-front, .tile-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        0 8px 24px rgba(0, 0, 0, 0.12),
        0 4px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.tile-front {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    font-size: clamp(1.8rem, 5vw, 4rem);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-weight: 700;
    letter-spacing: -0.5px;
    position: relative;
    overflow: hidden;
}

.tile-front::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255,255,255,0.1), transparent);
    transform: rotate(45deg) translateX(-100%);
    transition: transform 0.6s ease;
}

.tile-back {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    transform: rotateY(180deg);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(102, 126, 234, 0.2);
    padding: 0;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.tile-back img {
    width: calc(100% - 8px);
    height: calc(100% - 8px);
    object-fit: cover;
    border-radius: 12px;
    transition: transform 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.tile-back:hover img {
    transform: scale(1.02);
}

/* Professional matched tiles */
.game-tile.matched .tile-inner {
    transform: rotateY(180deg);
    animation: professionalMatch 0.8s ease-out;
}

.game-tile.matched .tile-back {
    box-shadow: 
        0 0 0 3px #667eea,
        0 12px 32px rgba(102, 126, 234, 0.3),
        0 6px 16px rgba(102, 126, 234, 0.2);
    border-color: #667eea;
    animation: professionalGlow 2s ease-in-out infinite;
}

@keyframes professionalMatch {
    0% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(180deg) scale(1.08); }
    100% { transform: rotateY(180deg) scale(1); }
}

@keyframes professionalGlow {
    0%, 100% { 
        box-shadow: 
            0 0 0 3px #667eea,
            0 12px 32px rgba(102, 126, 234, 0.3),
            0 6px 16px rgba(102, 126, 234, 0.2);
    }
    50% { 
        box-shadow: 
            0 0 0 3px #764ba2,
            0 16px 40px rgba(118, 75, 162, 0.4),
            0 8px 20px rgba(118, 75, 162, 0.3);
    }
}

/* Professional tile hover effects */
.game-tile:hover:not(.flipped):not(.matched) {
    animation: none;
    transform: translateY(-6px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.game-tile:hover:not(.flipped):not(.matched) .tile-front {
    box-shadow: 
        0 16px 40px rgba(102, 126, 234, 0.25),
        0 8px 20px rgba(102, 126, 234, 0.15);
}

.game-tile:hover:not(.flipped):not(.matched) .tile-front::before {
    transform: rotate(45deg) translateX(100%);
}

/* Professional Win Overlay */
.win-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, 
        rgba(102, 126, 234, 0.95), 
        rgba(118, 75, 162, 0.95), 
        rgba(240, 147, 251, 0.95));
    background-size: 300% 300%;
    animation: gentleGradient 3s ease infinite;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(20px);
}

.win-content {
    text-align: center;
    color: white;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(20px);
    padding: 48px 32px;
    border-radius: 32px;
    box-shadow: 
        0 32px 64px rgba(0, 0, 0, 0.2),
        0 16px 32px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    max-width: 90vw;
    animation: professionalWinBounce 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
}

.win-content::before {
    content: '✨';
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 2rem;
    animation: gentleFloat 3s ease-in-out infinite;
    opacity: 0.8;
}

.win-content::after {
    content: '🎉';
    position: absolute;
    bottom: 20px;
    left: 20px;
    font-size: 2rem;
    animation: gentleFloat 3s ease-in-out infinite reverse;
    opacity: 0.8;
}

@keyframes professionalWinBounce {
    0% { 
        transform: scale(0.8); 
        opacity: 0; 
        filter: blur(8px);
    }
    100% { 
        transform: scale(1); 
        opacity: 1; 
        filter: blur(0);
    }
}

.win-content h2 {
    font-size: 2.8rem;
    font-weight: 800;
    margin: 0 0 20px 0;
    background: linear-gradient(135deg, #ffffff, #f0f8ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.win-content p {
    font-size: 1.2rem;
    margin: 16px 0 32px 0;
    color: rgba(255, 255, 255, 0.95);
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: -0.2px;
}

/* Game Grid - Fullscreen */
.game-grid {
    display: grid !important;
    gap: 8px;
    height: calc(100vh - 60px); /* Full height minus header */
    width: 100vw;
    max-width: 100vw; /* Ensure it doesn't exceed viewport */
    padding: 8px;
    margin: 0;
    box-sizing: border-box;
    overflow: hidden; /* Prevent scrolling */
}

/* Grid size classes - Mobile-optimized */
.grid-2x2 {
    grid-template-columns: repeat(2, 1fr) !important;
    grid-template-rows: repeat(2, 1fr) !important;
}

.grid-2x3 {
    grid-template-columns: repeat(2, 1fr) !important;
    grid-template-rows: repeat(3, 1fr) !important;
}

.grid-2x4 {
    grid-template-columns: repeat(2, 1fr) !important;
    grid-template-rows: repeat(4, 1fr) !important;
}

.grid-3x4 {
    grid-template-columns: repeat(3, 1fr) !important;
    grid-template-rows: repeat(4, 1fr) !important;
}

.grid-2x6 {
    grid-template-columns: repeat(2, 1fr) !important;
    grid-template-rows: repeat(6, 1fr) !important;
}

.grid-2x8 {
    grid-template-columns: repeat(2, 1fr) !important;
    grid-template-rows: repeat(8, 1fr) !important;
}

/* Sparkle overlay for the game grid */
.game-grid::before {
    content: '⭐';
    position: absolute;
    top: 5%;
    left: 5%;
    font-size: 1.5rem;
    animation: sparkleMove 6s linear infinite;
    z-index: 1;
    pointer-events: none;
}

.game-grid::after {
    content: '✨';
    position: absolute;
    bottom: 5%;
    right: 5%;
    font-size: 1.2rem;
    animation: sparkleMove 4s linear infinite reverse;
    z-index: 1;
    pointer-events: none;
}

@keyframes sparkleMove {
    0% { 
        transform: translate(0, 0) rotate(0deg);
        opacity: 1;
    }
    25% { 
        transform: translate(20px, -20px) rotate(90deg);
        opacity: 0.7;
    }
    50% { 
        transform: translate(-10px, -40px) rotate(180deg);
        opacity: 1;
    }
    75% { 
        transform: translate(-30px, -10px) rotate(270deg);
        opacity: 0.7;
    }
    100% { 
        transform: translate(0, 0) rotate(360deg);
        opacity: 1;
    }
}

/* Touch feedback for mobile */
.game-tile:active {
    transform: scale(0.95) !important;
    transition: transform 0.1s ease !important;
}

.btn-primary:active, .btn-secondary:active {
    transform: scale(0.95) !important;
    transition: transform 0.1s ease !important;
}

/* Grid configuration classes */
.grid-2x2 {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

.grid-2x3 {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(3, 1fr);
}

.grid-2x4 {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(4, 1fr);
}

.grid-3x4 {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(4, 1fr);
}

.grid-2x6 {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(6, 1fr);
}

.grid-2x8 {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(8, 1fr);
}

/* Responsive adjustments for extra small screens */
@media (max-width: 320px) or (max-height: 568px) {
    .game-header {
        height: 50px;
        padding: 8px 12px;
    }
    
    .game-info {
        font-size: 14px;
    }
    
    .game-grid {
        height: calc(100vh - 50px);
        gap: 8px;
        padding: 8px;
    }
    
    .tile-front {
        font-size: clamp(1.5rem, 5vw, 4rem);
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .tile-front {
        background: linear-gradient(135deg, #000080, #8B0000);
        border: 2px solid #FFFFFF;
    }
    
    .tile-back {
        border: 2px solid #000000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dynamic sparkle effect animation */
@keyframes sparkleDisappear {
    0% { 
        opacity: 0;
        transform: scale(0) rotate(0deg);
    }
    10% { 
        opacity: 1;
        transform: scale(1.2) rotate(180deg);
    }
    50% { 
        opacity: 1;
        transform: scale(1) rotate(360deg) translateY(-20px);
    }
    100% { 
        opacity: 0;
        transform: scale(0.5) rotate(720deg) translateY(-40px);
    }
}

/* Card-based Selection Interface */
.selection-section {
    margin-bottom: 20px;
}

.selection-section h3 {
    font-size: 1.2rem;
    margin-bottom: 12px;
    color: #5F27CD;
    text-align: center;
    font-weight: 600;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 15px;
}

.selection-card {
    background: linear-gradient(135deg, #fff, #f8f9ff);
    border: 3px solid #e1e5e9;
    border-radius: 15px;
    padding: 15px 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.selection-card:hover {
    transform: translateY(-5px) scale(1.05);
    border-color: #FF6B9D;
    box-shadow: 0 10px 25px rgba(255, 107, 157, 0.3);
}

.selection-card.selected {
    border-color: #FF6B9D;
    background: linear-gradient(135deg, #FF6B9D, #f8f9ff);
    color: white;
    transform: scale(1.1);
    box-shadow: 0 15px 30px rgba(255, 107, 157, 0.4);
}

.selection-card.selected .card-title,
.selection-card.selected .card-description {
    color: white;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

.card-icon {
    font-size: 2rem;
    margin-bottom: 8px;
    display: block;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 3px;
    color: #5F27CD;
}

.card-description {
    font-size: 0.8rem;
    color: #666;
    font-weight: 500;
}

/* Difficulty cards specific styling */
.difficulty-card[data-grid="2x2"] {
    border-color: #10b981;
}

.difficulty-card[data-grid="2x2"]:hover,
.difficulty-card[data-grid="2x2"].selected {
    border-color: #10b981;
    background: linear-gradient(135deg, #10b981, #f8f9ff);
}

.difficulty-card[data-grid="2x3"] {
    border-color: #f59e0b;
}

.difficulty-card[data-grid="2x3"]:hover,
.difficulty-card[data-grid="2x3"].selected {
    border-color: #f59e0b;
    background: linear-gradient(135deg, #f59e0b, #f8f9ff);
}

.difficulty-card[data-grid="2x4"] {
    border-color: #ef4444;
}

.difficulty-card[data-grid="2x4"]:hover,
.difficulty-card[data-grid="2x4"].selected {
    border-color: #ef4444;
    background: linear-gradient(135deg, #ef4444, #f8f9ff);
}

.difficulty-card[data-grid="3x4"] {
    border-color: #8b5cf6;
}

.difficulty-card[data-grid="3x4"]:hover,
.difficulty-card[data-grid="3x4"].selected {
    border-color: #8b5cf6;
    background: linear-gradient(135deg, #8b5cf6, #f8f9ff);
}

/* Responsive adjustments for mobile */
@media (max-height: 700px) {
    #setup-screen {
        padding: 5px;
    }
    
    .setup-container {
        padding: 20px 16px;
        margin: 5px auto;
    }
    
    .setup-container h1 {
        font-size: 2rem;
        margin-bottom: 20px;
    }
    
    .selection-section {
        margin-bottom: 20px;
    }
    
    .selection-section h3 {
        font-size: 1.1rem;
        margin-bottom: 12px;
    }
    
    .card-grid {
        gap: 12px;
        margin-bottom: 16px;
    }
    
    .selection-card {
        min-height: 95px;
        padding: 16px 12px;
    }
    
    .card-icon {
        font-size: 2rem;
        margin-bottom: 8px;
    }
    
    .card-title {
        font-size: 1rem;
    }
    
    .card-description {
        font-size: 0.8rem;
    }
    
    .btn-primary {
        margin-top: 16px;
        padding: 14px 28px;
        font-size: 16px;
    }
}

/* Mobile game screen adjustments */
@media (max-width: 768px) {
    .game-header {
        height: 56px;
        padding: 12px 16px;
    }
    
    .game-grid {
        height: calc(100vh - 56px);
        gap: 6px;
        padding: 6px;
    }
    
    .win-content {
        padding: 36px 24px;
        margin: 16px;
    }
    
    .win-content h2 {
        font-size: 2.2rem;
    }
    
    .win-content p {
        font-size: 1.1rem;
    }
}

@media (max-width: 480px) {
    .setup-container {
        padding: 16px 12px;
        border-radius: 20px;
    }
    
    .card-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .selection-card {
        min-height: 85px;
        padding: 12px 8px;
        border-radius: 16px;
    }
    
    .card-icon {
        font-size: 1.8rem;
    }
    
    .card-title {
        font-size: 0.95rem;
    }
    
    .card-description {
        font-size: 0.75rem;
    }
    
    .game-grid {
        gap: 4px;
        padding: 4px;
    }
    
    .tile-front, .tile-back {
        border-radius: 12px;
    }
    
    .win-content {
        padding: 28px 20px;
        border-radius: 24px;
    }
}

/* Touch feedback for mobile */
.game-tile:active {
    transform: scale(0.98) !important;
    transition: transform 0.1s ease !important;
}

.btn-primary:active, .btn-secondary:active {
    transform: scale(0.98) !important;
    transition: transform 0.1s ease !important;
}

.selection-card:active {
    transform: scale(0.98) !important;
    transition: transform 0.1s ease !important;
}

/* Dynamic sparkle effect animation */
@keyframes sparkleDisappear {
    0% { 
        opacity: 0;
        transform: scale(0) rotate(0deg);
    }
    10% { 
        opacity: 1;
        transform: scale(1.2) rotate(180deg);
    }
    50% { 
        opacity: 1;
        transform: scale(1) rotate(360deg) translateY(-20px);
    }
    100% { 
        opacity: 0;
        transform: scale(0.5) rotate(720deg) translateY(-40px);
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .tile-front {
        background: linear-gradient(135deg, #000080, #8B0000);
        border: 2px solid #FFFFFF;
    }
    
    .tile-back {
        border: 2px solid #000000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Animal Sounds Game Styles */
#animal-sounds-screen {
    justify-content: flex-start;
    align-items: stretch;
    padding: 5px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.animal-game-container {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 16px;
    padding: 8px;
    box-shadow: 
        0 20px 40px rgba(0, 0, 0, 0.1),
        0 8px 24px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.5);
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    text-align: center;
    animation: slideUp 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
    margin: 0;
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    flex-direction: column;
}

.score-display {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
    padding: 4px 8px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.8rem;
}

.game-status {
    margin: 8px 0;
    text-align: center;
    flex-shrink: 0;
}

.game-status p {
    font-size: 1rem;
    color: #4a5568;
    margin-bottom: 12px;
    font-weight: 500;
    line-height: 1.3;
}

.animal-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin: 12px 0;
    flex: 1;
    align-content: center;
    padding: 0 8px;
}

.animal-option {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(102, 126, 234, 0.1);
    border-radius: 20px;
    padding: 12px 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    height: auto;
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.animal-option::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, transparent, rgba(102, 126, 234, 0.05), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.animal-option:hover {
    transform: translateY(-4px);
    border-color: rgba(102, 126, 234, 0.3);
    box-shadow: 
        0 12px 32px rgba(102, 126, 234, 0.15),
        0 4px 16px rgba(102, 126, 234, 0.1);
}

.animal-option:hover::before {
    opacity: 1;
}

.animal-option.correct {
    border-color: #48bb78;
    background: linear-gradient(135deg, rgba(72, 187, 120, 0.1), rgba(255, 255, 255, 0.9));
    animation: correctPulse 0.6s ease-out;
}

.animal-option.incorrect {
    border-color: #f56565;
    background: linear-gradient(135deg, rgba(245, 101, 101, 0.1), rgba(255, 255, 255, 0.9));
    animation: incorrectShake 0.6s ease-out;
}

.animal-option.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

@keyframes correctPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); box-shadow: 0 0 20px rgba(72, 187, 120, 0.3); }
    100% { transform: scale(1); }
}

@keyframes incorrectShake {
    0%, 20%, 40%, 60%, 80% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
}

.animal-visual {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 8px;
    position: relative;
    flex: 1;
    width: 100%;
}

.animal-image {
    width: 85%;
    height: 80%;
    max-width: 160px;
    max-height: 160px;
    object-fit: cover;
    border-radius: 16px;
    margin-bottom: 6px;
    transition: all 0.3s ease;
    border: 2px solid rgba(102, 126, 234, 0.1);
}

.animal-image:hover {
    transform: scale(1.05);
    border-color: rgba(102, 126, 234, 0.3);
}

.animal-emoji {
    font-size: 5rem;
    display: none; /* Hidden by default when image loads */
    margin-bottom: 6px;
}

/* Only show emoji when image fails to load */
.animal-image[style*="display: none"] + .animal-emoji {
    display: block;
}

.animal-name {
    font-size: 1rem;
    font-weight: 600;
    color: #4a5568;
    text-transform: capitalize;
}

.countdown-display {
    margin: 20px 0;
    text-align: center;
    padding: 16px;
    background: rgba(72, 187, 120, 0.1);
    border-radius: 16px;
    border: 2px solid rgba(72, 187, 120, 0.2);
}

.countdown-display p {
    font-size: 1.1rem;
    color: #48bb78;
    font-weight: 600;
    margin: 0;
}

#countdown-number {
    font-size: 1.5rem;
    font-weight: 700;
    color: #38a169;
    animation: countdownPulse 1s ease-in-out infinite;
}

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

/* Animal Sounds Win Screen */
#animal-win-screen {
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.win-celebration {
    text-align: center;
    animation: magicalAppear 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.win-celebration h1 {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 24px;
    background: linear-gradient(135deg, #667eea, #764ba2, #f093fb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: rainbowShimmer 2s ease-in-out infinite;
}

.win-celebration p {
    font-size: 1.3rem;
    color: #4a5568;
    margin-bottom: 32px;
    font-weight: 500;
}

.celebration-stats {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 24px;
    margin: 24px 0;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.stat-number {
    font-size: 3rem;
    font-weight: 700;
    background: linear-gradient(135deg, #48bb78, #38a169);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-label {
    font-size: 1rem;
    color: #4a5568;
    font-weight: 600;
}

.win-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 32px;
}

@keyframes magicalAppear {
    0% { 
        transform: translateY(30px) scale(0.9); 
        opacity: 0; 
        filter: blur(8px);
    }
    100% { 
        transform: translateY(0) scale(1); 
        opacity: 1; 
        filter: blur(0);
    }
}

@keyframes rainbowShimmer {
    0%, 100% { 
        background: linear-gradient(135deg, #667eea, #764ba2, #f093fb);
        -webkit-background-clip: text;
        background-clip: text;
    }
    50% { 
        background: linear-gradient(135deg, #f093fb, #667eea, #764ba2);
        -webkit-background-clip: text;
        background-clip: text;
    }
}

/* Confetti Animation */
.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    background: #f0f;
    animation: confettiFall linear infinite;
    z-index: 9999;
    pointer-events: none;
}

.confetti:nth-child(1) { 
    background: #ff6b9d; 
    left: 10%; 
    animation-delay: 0s; 
    animation-duration: 3s; 
}
.confetti:nth-child(2) { 
    background: #c44569; 
    left: 20%; 
    animation-delay: 0.5s; 
    animation-duration: 2.5s; 
}
.confetti:nth-child(3) { 
    background: #667eea; 
    left: 30%; 
    animation-delay: 1s; 
    animation-duration: 3.5s; 
}
.confetti:nth-child(4) { 
    background: #764ba2; 
    left: 40%; 
    animation-delay: 0.2s; 
    animation-duration: 2.8s; 
}
.confetti:nth-child(5) { 
    background: #f093fb; 
    left: 50%; 
    animation-delay: 0.8s; 
    animation-duration: 3.2s; 
}
.confetti:nth-child(6) { 
    background: #feca57; 
    left: 60%; 
    animation-delay: 0.3s; 
    animation-duration: 2.7s; 
}
.confetti:nth-child(7) { 
    background: #48bb78; 
    left: 70%; 
    animation-delay: 1.2s; 
    animation-duration: 3.8s; 
}
.confetti:nth-child(8) { 
    background: #ff9ff3; 
    left: 80%; 
    animation-delay: 0.6s; 
    animation-duration: 2.9s; 
}
.confetti:nth-child(9) { 
    background: #54a0ff; 
    left: 90%; 
    animation-delay: 0.9s; 
    animation-duration: 3.3s; 
}
.confetti:nth-child(10) { 
    background: #5f27cd; 
    left: 95%; 
    animation-delay: 0.4s; 
    animation-duration: 3.1s; 
}

@keyframes confettiFall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* Confetti shapes */
.confetti.square {
    border-radius: 0;
}

.confetti.circle {
    border-radius: 50%;
}

.confetti.triangle {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 10px solid;
    background: transparent;
}

.confetti.star {
    background: transparent;
    position: relative;
}

.confetti.star:before {
    content: '⭐';
    position: absolute;
    font-size: 12px;
    top: -6px;
    left: -6px;
}

/* Game Selection Styles */
.game-card[data-game="memory"] {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05), rgba(255, 255, 255, 0.9));
}

.game-card[data-game="memory"]:hover,
.game-card[data-game="memory"].selected {
    border-color: #667eea;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(255, 255, 255, 0.9));
}

.game-card[data-game="animal-sounds"] {
    background: linear-gradient(135deg, rgba(72, 187, 120, 0.05), rgba(255, 255, 255, 0.9));
}

.game-card[data-game="animal-sounds"]:hover,
.game-card[data-game="animal-sounds"].selected {
    border-color: #48bb78;
    background: linear-gradient(135deg, rgba(72, 187, 120, 0.1), rgba(255, 255, 255, 0.9));
}

/* Responsive adjustments for animal sounds */
@media (max-width: 480px) {
    .animal-game-container {
        padding: 12px 8px;
        border-radius: 12px;
    }
    
    .animal-grid {
        gap: 8px;
        padding: 0 4px;
    }
    
    .animal-option {
        padding: 8px 6px;
        border-radius: 16px;
    }
    
    .animal-image {
        width: 90%;
        height: 85%;
        max-width: 140px;
        max-height: 140px;
    }
    
    .animal-emoji {
        font-size: 4rem;
    }
    
    .animal-name {
        font-size: 0.9rem;
    }
    
    .game-status p {
        font-size: 1rem;
    }
    
    .score-display {
        font-size: 0.8rem;
        padding: 4px 8px;
    }
    
    .countdown-display {
        margin: 16px 0;
        padding: 12px;
    }
    
    .countdown-display p {
        font-size: 1rem;
    }
    
    #countdown-number {
        font-size: 1.3rem;
    }
    
    .win-celebration h1 {
        font-size: 2.5rem;
    }
    
    .win-celebration p {
        font-size: 1.1rem;
    }
} 