/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Keyframe animations */
@keyframes fastMatchPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); box-shadow: 0 0 20px rgba(76, 175, 80, 0.8); }
    100% { transform: scale(1.15); }
}

@keyframes matchScrollOut {
    0% { 
        transform: translateY(0) scale(1); 
        opacity: 1; 
        background: linear-gradient(135deg, #4CAF50, #66BB6A);
        box-shadow: 0 0 15px rgba(76, 175, 80, 0.7);
    }
    25% { 
        transform: translateY(-10px) scale(1.1); 
        opacity: 0.9; 
        background: linear-gradient(135deg, #66BB6A, #81C784);
        box-shadow: 0 0 20px rgba(76, 175, 80, 0.8);
    }
    50% { 
        transform: translateY(-20px) scale(1.05); 
        opacity: 0.7; 
    }
    75% { 
        transform: translateY(-40px) scale(0.8); 
        opacity: 0.4; 
    }
    100% { 
        transform: translateY(-60px) scale(0.3); 
        opacity: 0; 
    }
}

@keyframes slideOut {
    0% { transform: translateX(0) scale(1); opacity: 1; }
    100% { transform: translateX(50px) scale(0); opacity: 0; }
}

@keyframes tileSelect {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes matchGlow {
    0% { 
        background: linear-gradient(135deg, #4CAF50, #66BB6A);
        box-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
        transform: scale(1);
    }
    100% { 
        background: linear-gradient(135deg, #66BB6A, #81C784);
        box-shadow: 0 0 25px rgba(76, 175, 80, 0.9);
        transform: scale(1.1);
    }
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: 10px;
    margin: 0;
    position: relative;
    overflow: hidden;
    gap: 10px;
}

/* Dynamic Level Background Images */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.6; /* Increased from 0.3 for better visibility */
    z-index: -2;
    transition: background-image 0.8s ease-in-out;
    filter: brightness(1.2) saturate(1.3) contrast(1.1); /* Enhanced colors */
    animation: backgroundFloat 20s ease-in-out infinite alternate; /* Floating animation */
}

/* Background floating animation */
@keyframes backgroundFloat {
    0% {
        transform: scale(1) rotate(0deg);
        filter: brightness(1.2) saturate(1.3) contrast(1.1) hue-rotate(0deg);
    }
    25% {
        transform: scale(1.05) rotate(0.5deg);
        filter: brightness(1.3) saturate(1.4) contrast(1.15) hue-rotate(5deg);
    }
    50% {
        transform: scale(1.02) rotate(-0.3deg);
        filter: brightness(1.25) saturate(1.35) contrast(1.12) hue-rotate(-3deg);
    }
    75% {
        transform: scale(1.08) rotate(0.8deg);
        filter: brightness(1.35) saturate(1.45) contrast(1.18) hue-rotate(8deg);
    }
    100% {
        transform: scale(1.1) rotate(-0.5deg);
        filter: brightness(1.4) saturate(1.5) contrast(1.2) hue-rotate(-5deg);
    }
}

/* Level-specific backgrounds */
body.level-1::before {
    background-image: url('./assets/backgrounds/bg1.jpg');
    animation: backgroundFloat 20s ease-in-out infinite alternate, backgroundBreathe 8s ease-in-out infinite;
}

body.level-2::before {
    background-image: url('./assets/backgrounds/bg2.jpg');
    animation: backgroundFloat 18s ease-in-out infinite alternate, backgroundBreathe 7s ease-in-out infinite;
}

body.level-3::before {
    background-image: url('./assets/backgrounds/bg3.jpg');
    animation: backgroundFloat 22s ease-in-out infinite alternate, backgroundBreathe 9s ease-in-out infinite;
}

body.level-4::before {
    background-image: url('./assets/backgrounds/bg4.jpg');
    animation: backgroundFloat 19s ease-in-out infinite alternate, backgroundBreathe 6s ease-in-out infinite;
}

body.level-5::before {
    background-image: url('./assets/backgrounds/bg5.jpg');
    animation: backgroundFloat 21s ease-in-out infinite alternate, backgroundBreathe 8.5s ease-in-out infinite;
}

body.level-6::before {
    background-image: url('./assets/backgrounds/bg6.jpg');
    animation: backgroundFloat 17s ease-in-out infinite alternate, backgroundBreathe 7.5s ease-in-out infinite;
}

body.level-7::before {
    background-image: url('./assets/backgrounds/bg7.jpg');
    animation: backgroundFloat 23s ease-in-out infinite alternate, backgroundBreathe 6.5s ease-in-out infinite;
}

body.level-8::before {
    background-image: url('./assets/backgrounds/bg1.jpg');
    animation: backgroundFloat 20s ease-in-out infinite alternate, backgroundBreathe 9.5s ease-in-out infinite;
}

/* Background breathing animation */
@keyframes backgroundBreathe {
    0%, 100% {
        opacity: 0.6;
        filter: brightness(1.2) saturate(1.3) contrast(1.1);
    }
    50% {
        opacity: 0.65;
        filter: brightness(1.25) saturate(1.35) contrast(1.15);
    }
}

body.level-9::before {
    background-image: url('./assets/backgrounds/bg2.jpg');
}

body.level-10::before {
    background-image: url('./assets/backgrounds/bg3.jpg');
}

body.level-11::before {
    background-image: url('./assets/backgrounds/bg1.jpg');
}

body.level-12::before {
    background-image: url('./assets/backgrounds/bg2.jpg');
}

body.level-13::before {
    background-image: url('./assets/backgrounds/bg3.jpg');
}

body.level-14::before {
    background-image: url('./assets/backgrounds/bg4.jpg');
}

body.level-15::before {
    background-image: url('./assets/backgrounds/bg5.jpg');
}

body.level-16::before {
    background-image: url('./assets/backgrounds/bg6.jpg');
}

body.level-17::before {
    background-image: url('./assets/backgrounds/bg7.jpg');
}

body.level-18::before {
    background-image: url('./assets/backgrounds/bg1.jpg');
}

body.level-19::before {
    background-image: url('./assets/backgrounds/bg2.jpg');
}

body.level-20::before {
    background-image: url('./assets/backgrounds/bg3.jpg');
}

/* Cycling pattern for higher levels */
body[class*="level-"]::before {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* Level ranges with different themes */
body.level-21::before, body.level-31::before, body.level-41::before, body.level-51::before {
    background-image: url('./assets/backgrounds/bg1.jpg');
}

body.level-22::before, body.level-32::before, body.level-42::before, body.level-52::before {
    background-image: url('./assets/backgrounds/bg2.jpg');
}

body.level-23::before, body.level-33::before, body.level-43::before, body.level-53::before {
    background-image: url('./assets/backgrounds/bg3.jpg');
}

body.level-24::before, body.level-34::before, body.level-44::before, body.level-54::before {
    background-image: url('./assets/backgrounds/bg4.jpg');
}

/* Milestone levels (every 5th level) */
body.level-milestone::before {
    background-image: url('./assets/backgrounds/bg1.jpg');
    opacity: 0.7; /* Increased opacity */
    animation: milestoneBackgroundGlow 2s ease-in-out infinite alternate;
    filter: brightness(1.3) saturate(1.5) contrast(1.2); /* Enhanced colors */
}

@keyframes milestoneBackgroundGlow {
    0% {
        opacity: 0.6;
        filter: brightness(1.3) saturate(1.5) contrast(1.2) hue-rotate(0deg);
        transform: scale(1) rotate(0deg);
    }
    25% {
        opacity: 0.7;
        filter: brightness(1.4) saturate(1.6) contrast(1.25) hue-rotate(15deg);
        transform: scale(1.03) rotate(0.3deg);
    }
    50% {
        opacity: 0.75;
        filter: brightness(1.45) saturate(1.65) contrast(1.28) hue-rotate(-10deg);
        transform: scale(1.05) rotate(-0.2deg);
    }
    75% {
        opacity: 0.8;
        filter: brightness(1.5) saturate(1.7) contrast(1.3) hue-rotate(20deg);
        transform: scale(1.02) rotate(0.5deg);
    }
    100% {
        opacity: 0.85;
        filter: brightness(1.55) saturate(1.75) contrast(1.35) hue-rotate(-15deg);
        transform: scale(1.08) rotate(-0.3deg);
    }
}

/* Boss levels (every 10th level) */
body.level-boss::before {
    background-image: url('./assets/backgrounds/bg3.jpg');
    opacity: 0.75; /* Increased opacity */
    animation: bossBackgroundPulse 3s ease-in-out infinite alternate;
    filter: brightness(1.3) saturate(1.4) contrast(1.2); /* Enhanced colors */
}

@keyframes bossBackgroundPulse {
    0% {
        opacity: 0.65;
        transform: scale(1) rotate(0deg);
        filter: brightness(1.3) saturate(1.4) contrast(1.2) hue-rotate(0deg);
    }
    20% {
        opacity: 0.7;
        transform: scale(1.01) rotate(0.5deg);
        filter: brightness(1.4) saturate(1.5) contrast(1.25) hue-rotate(10deg);
    }
    40% {
        opacity: 0.75;
        transform: scale(1.015) rotate(-0.3deg);
        filter: brightness(1.45) saturate(1.55) contrast(1.28) hue-rotate(-5deg);
    }
    60% {
        opacity: 0.8;
        transform: scale(1.008) rotate(0.8deg);
        filter: brightness(1.48) saturate(1.58) contrast(1.3) hue-rotate(25deg);
    }
    80% {
        opacity: 0.82;
        transform: scale(1.018) rotate(-0.2deg);
        filter: brightness(1.5) saturate(1.6) contrast(1.32) hue-rotate(-10deg);
    }
    100% {
        opacity: 0.85;
        transform: scale(1.02) rotate(0.4deg);
        filter: brightness(1.55) saturate(1.65) contrast(1.35) hue-rotate(30deg);
    }
}

/* Additional background overlay for better contrast */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%); /* Reduced opacity */
    z-index: -1;
    pointer-events: none;
    animation: overlayShift 15s ease-in-out infinite alternate; /* Subtle movement */
}

/* Background overlay shifting animation */
@keyframes overlayShift {
    0% {
        background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
        transform: translateX(0) translateY(0);
    }
    25% {
        background: linear-gradient(145deg, rgba(118, 75, 162, 0.06) 0%, rgba(102, 126, 234, 0.04) 100%);
        transform: translateX(2px) translateY(-1px);
    }
    50% {
        background: linear-gradient(125deg, rgba(102, 126, 234, 0.04) 0%, rgba(118, 75, 162, 0.06) 100%);
        transform: translateX(-1px) translateY(2px);
    }
    75% {
        background: linear-gradient(155deg, rgba(118, 75, 162, 0.05) 0%, rgba(102, 126, 234, 0.05) 100%);
        transform: translateX(1px) translateY(-2px);
    }
    100% {
        background: linear-gradient(135deg, rgba(102, 126, 234, 0.06) 0%, rgba(118, 75, 162, 0.04) 100%);
        transform: translateX(-2px) translateY(1px);
    }
}

/* Main Container - Direct body layout approach */
/* Direct body layout for game elements */
body > header,
body > main,
body > .game-info,
body > .game-grid,
body > .selection-container {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

body > main {
    /* flex-grow: 1; */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.title-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
    width: 100%;
    padding: 10px;
}

.title-container h1 {
    margin: 0;
    font-size: 2rem;
    color: #333;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    text-align: center;
}

/* Mobile devices (portrait) */
@media screen and (max-width: 480px) {
    body {
        height: 100vh;
        justify-content: space-between;
    }
    
    body > header,
    body > main,
    body > .game-info,
    body > .game-grid,
    body > .selection-container {
        max-width: 100%;
        width: 100%;
        margin: 0;
    }
    
    header h1 {
        display: none; /* Keep hidden on mobile */
    }
    
    .game-info {
        padding: 8px 15px;
        font-size: 14px;
        margin-bottom: 5px;
        flex-shrink: 0;
    }
}

/* Tablet optimization */
@media screen and (min-width: 481px) and (max-width: 768px) {
    body > header,
    body > main,
    body > .game-info,
    body > .game-grid,
    body > .selection-container {
        max-width: 500px;
        padding: 20px;
    }
    
    header h1 {
        display: none; /* Keep hidden on tablet */
    }
}

/* Desktop optimization */
@media screen and (min-width: 769px) {
    body {
        padding: 20px;
    }
    
    body > header,
    body > main,
    body > .game-info,
    body > .game-grid,
    body > .selection-container {
        max-width: 600px;
        padding: 30px;
    }
    
    header h1 {
        display: none; /* Keep hidden on desktop */
    }
}

/* Header */
header {
    text-align: center;
    margin-bottom: 0; /* Remove bottom margin */
    width: 100%;
    background: transparent;
    color: white;
    padding: 5px 0; /* Reduced padding */
}

header h1 {
    display: block; /* Show the game title */
    font-size: 2.2rem;
    margin: 0;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    background: linear-gradient(45deg, #8B5CF6, #A78BFA);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: #8B5CF6;
}

.instructions {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border-radius: 8px;
    padding: 12px 16px;
    margin: 10px auto;
    border: 1px solid rgba(255, 255, 255, 0.2);
    max-width: 600px;
    text-align: center;
}

.instructions p {
    margin: 0;
    font-size: 14px;
    line-height: 1.4;
    color: white;
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: transparent;
    color: white;
    padding: 10px 16px;
    border-radius: 8px;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 14px;
    box-shadow: none;
    width: 100%;
    min-height: 40px;
}

.level-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.level-number {
    font-size: 18px;
    font-weight: 700;
}

.level-type {
    display: none; /* Hide level type info */
}

.level-progress {
    display: none; /* Hide level progress info */
}

.score-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
}

.score-number {
    font-size: 18px;
    font-weight: 700;
}

.matches-info {
    display: none; /* Hide detailed matches info */
}

.score, .level {
    font-size: 1.2rem;
    font-weight: bold;
    color: white;
}

/* Special level indicators */
.milestone-indicator {
    display: none; /* Hide milestone indicator */
}

.boss-indicator {
    display: none; /* Hide boss indicator */
}

@keyframes milestoneShine {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes bossShine {
    0%, 100% { 
        transform: scale(1);
        text-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
    }
    50% { 
        transform: scale(1.15);
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
    }
}

/* Controls container for icons */
.controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

/* Sound icon */
.sound-icon {
    cursor: pointer;
    font-size: 1.5rem;
    transition: all 0.3s ease;
    opacity: 0.8;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.sound-icon:hover {
    opacity: 1;
    transform: scale(1.2);
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.4));
}

.sound-icon.muted {
    opacity: 0.5;
    filter: grayscale(50%) drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.sound-icon.muted:hover {
    opacity: 0.7;
    transform: scale(1.1);
}

/* Restart icon */
.restart-icon {
    cursor: pointer;
    font-size: 1.5rem;
    transition: all 0.3s ease;
    opacity: 0.8;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.restart-icon:hover {
    opacity: 1;
    transform: scale(1.2) rotate(180deg);
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.4));
}

/* 3D Layer Info Display */
.layer-info-display {
    display: none; /* Hide 3D layer information */
}

.layers-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.layer-count {
    font-weight: 600;
    font-size: 14px;
}

.depth-visualization {
    display: flex;
    gap: 8px;
    align-items: center;
}

.depth-level {
    padding: 4px 10px;
    background: linear-gradient(145deg, #3498db, #2980b9);
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* Game Grid - Base styles and mobile-first responsive layout with 3D effect */
.game-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    justify-items: center;
    align-items: center;
    width: 100%;
    max-width: 375px; /* 7 tiles * 45px + 6 gaps * 8px + 30px padding = 375px */
    /* min-height: 300px; */
    margin: 5px auto 10px auto; /* Reduced margins */
    padding: 0; /* Remove padding */
    background: transparent; /* Remove background */
    border-radius: 0; /* Remove border radius */
    box-shadow: none; /* Remove box shadow */
    overflow: visible;
    
    /* 3D perspective effects */
    perspective: 1000px;
    transform-style: preserve-3d;
    transform: rotateX(10deg) rotateY(-5deg);
    transition: transform 0.3s ease;
}

.game-grid:hover {
    transform: rotateX(5deg) rotateY(-2deg);
}

/* Game Grid - Enhanced for True 3D Dimensional Layout */
.game-grid-3d {
    position: relative;
    transform-style: preserve-3d;
    background: transparent;
    margin: 5px auto 10px auto; /* Reduced margins */
    overflow: visible;
    perspective: 1200px;
    perspective-origin: center center;
    transform: rotateX(15deg) rotateY(-10deg);
}

/* 3D Dimensional Tile Styling */
.tile-3d {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    transform-style: preserve-3d;
    position: absolute;
    backface-visibility: visible;
    /* Remove default background/border - handled in JavaScript for better 3D effect */
}

.tile-3d.selected {
    background: linear-gradient(145deg, #4CAF50, #45a049) !important;
    color: white !important;
    border-color: #4CAF50 !important;
    transform: translateZ(-5px) scale(0.8) !important;
    box-shadow: 
        0 2px 8px rgba(76, 175, 80, 0.4),
        inset 0 1px 0 rgba(255,255,255,0.2) !important;
}

/* Special level styling for 3D */
.game-grid-3d.milestone-level {
    filter: hue-rotate(30deg) brightness(1.1);
}

.game-grid-3d.boss-level {
    filter: hue-rotate(-15deg) brightness(1.05) saturate(1.2);
    animation: boss3DGlow 2s ease-in-out infinite alternate;
}

@keyframes boss3DGlow {
    from {
        box-shadow: 
            0 20px 40px rgba(220, 53, 69, 0.4),
            inset 0 1px 0 rgba(255,255,255,0.3);
    }
    to {
        box-shadow: 
            0 25px 50px rgba(220, 53, 69, 0.6),
            inset 0 1px 0 rgba(255,255,255,0.4);
    }
}

/* Special level styling */
.game-grid.milestone-level {
    background: linear-gradient(145deg, #fff3cd, #ffeaa7);
    box-shadow: 
        inset 0 2px 10px rgba(255, 193, 7, 0.2),
        0 0 20px rgba(255, 193, 7, 0.3);
}

.game-grid.boss-level {
    background: linear-gradient(145deg, #f8d7da, #f5c6cb);
    box-shadow: 
        inset 0 2px 10px rgba(220, 53, 69, 0.2),
        0 0 25px rgba(220, 53, 69, 0.4);
    animation: bossGlow 2s ease-in-out infinite alternate;
}

@keyframes bossGlow {
    from {
        box-shadow: 
            inset 0 2px 10px rgba(220, 53, 69, 0.2),
            0 0 25px rgba(220, 53, 69, 0.4);
    }
    to {
        box-shadow: 
            inset 0 2px 10px rgba(220, 53, 69, 0.3),
            0 0 35px rgba(220, 53, 69, 0.6);
    }
}

/* Fixed Tile Sizes - Enhanced 3D Appearance with depth */
.tile {
    width: 50px;
    height: 50px;
    background: linear-gradient(145deg, #f8f9fb, #e9ecef);
    border: 1px solid #c9d1d9;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.15),
        0 2px 4px rgba(0, 0, 0, 0.08),
        inset 0 2px 0 rgba(255, 255, 255, 0.9),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
    z-index: 1;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    padding: 4px;
    transform-style: preserve-3d;
    perspective: 300px;
    
    /* 3D depth effect */
    transform: translateZ(10px);
}

/* Add varying depth for different grid positions */
.tile:nth-child(7n+1), .tile:nth-child(7n+7) {
    transform: translateZ(15px); /* Corner tiles come out more */
}

.tile:nth-child(7n+2), .tile:nth-child(7n+6) {
    transform: translateZ(12px);
}

.tile:nth-child(7n+3), .tile:nth-child(7n+5) {
    transform: translateZ(8px);
}

.tile:nth-child(7n+4) {
    transform: translateZ(5px); /* Center tiles are deeper */
}

/* Ensure images scale properly within tiles */
.tile img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

/* Remove variable sizing - keep tiles consistent */

.tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transition: left 0.5s ease;
}

.tile:hover::before {
    left: 100%;
}

.tile:hover {
    transform: translateZ(25px) translateY(-6px) scale(1.08) rotateX(5deg);
    box-shadow: 
        0 15px 35px rgba(0, 0, 0, 0.3),
        0 8px 16px rgba(0, 0, 0, 0.15),
        inset 0 3px 0 rgba(255, 255, 255, 0.95),
        inset 0 -2px 0 rgba(0, 0, 0, 0.15);
    border-color: #4dabf7;
    background: linear-gradient(145deg, #ffffff, #e7f5ff);
    z-index: 10;
}

.tile:active {
    transform: translateZ(15px) translateY(-4px) scale(1.02);
    transition: all 0.1s ease;
}

.tile.selected {
    background: linear-gradient(145deg, #007bff, #0056b3);
    color: white;
    transform: translateZ(5px) scale(0.95);
    box-shadow: 
        inset 0 4px 8px rgba(0, 0, 0, 0.3),
        0 2px 8px rgba(0, 123, 255, 0.3);
    border-color: #0056b3;
    animation: selectedPulse 0.6s ease;
    z-index: 5;
}

@keyframes selectedPulse {
    0% { transform: translateZ(10px) scale(1); }
    50% { transform: translateZ(5px) scale(0.9); }
    100% { transform: translateZ(5px) scale(0.95); }
}

.tile.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
    filter: grayscale(50%);
}

/* Layered tile effects */
.tile[style*="position: absolute"] {
    border-width: 3px;
    background: linear-gradient(145deg, #f8f9fa, #e9ecef);
}

.tile[style*="position: absolute"]:hover {
    transform: translateY(-12px) scale(1.1);
    z-index: 15;
}

/* Selection Box - Mobile-first responsive container */
.selection-container {
    padding: 5px;
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
    min-height: 80px;
}

.selection-container h3 {
    display: block; /* Show the heading text */
    margin: 5px 0; /* Reduced margin */
    font-size: 1.1rem;
    color: white;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

.selection-box {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
    justify-items: center;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    overflow: visible; /* Allow scroll animations to be visible */
    padding-top: 5px;
}

.selection-slot {
    width: 50px;
    height: 50px;
    border: 2px dashed #ced4da;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    background: linear-gradient(145deg, #ffffff, #f8f9fa);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 
        inset 0 2px 6px rgba(0, 0, 0, 0.1),
        0 2px 8px rgba(0, 0, 0, 0.05);
    position: relative;
    overflow: visible; /* Allow animations to extend beyond slot */
    user-select: none;
    -webkit-user-select: none;
    padding: 3px; /* Add padding for image spacing */
}

/* Ensure images in selection slots scale properly */
.selection-slot img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

.selection-slot::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at center, rgba(40, 167, 69, 0.1), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.selection-slot.filled {
    border-style: solid;
    border-color: #28a745;
    background: linear-gradient(145deg, #d4edda, #c3e6cb);
    animation: fillSlot 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 
        0 4px 12px rgba(40, 167, 69, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.selection-slot.filled::before {
    opacity: 1;
}

.selection-slot.matching {
    background: linear-gradient(145deg, #fff3cd, #ffeaa7);
    border-color: #ffc107;
    animation: matchingPulse 0.8s ease infinite alternate;
    box-shadow: 
        0 4px 15px rgba(255, 193, 7, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

@keyframes fillSlot {
    0% {
        transform: scale(0.6) rotate(-10deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.1) rotate(5deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

@keyframes matchingPulse {
    0% {
        transform: scale(1);
        box-shadow: 
            0 4px 15px rgba(255, 193, 7, 0.4),
            inset 0 1px 0 rgba(255, 255, 255, 0.7);
    }
    100% {
        transform: scale(1.1);
        box-shadow: 
            0 6px 20px rgba(255, 193, 7, 0.6),
            inset 0 1px 0 rgba(255, 255, 255, 0.8);
    }
}

.selection-counter {
    display: none; /* Hide the selection counter text */
}

.selection-counter.warning {
    display: none; /* Hide warning state as well */
}

@keyframes warningPulse {
    from {
        opacity: 0.7;
    }
    to {
        opacity: 1;
    }
}

/* Game Messages */
.game-message {
    text-align: center;
    margin-top: 20px;
    padding: 15px;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: bold;
    transition: all 0.3s ease;
}

.game-message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.game-message.warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

.game-message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s ease;
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 90%;
    animation: slideIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 2rem;
}

.modal-content p {
    color: #666;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.play-again-btn, .next-level-btn {
    background: #28a745;
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.1rem;
    margin-top: 20px;
    transition: background 0.3s;
}

.play-again-btn:hover, .next-level-btn:hover {
    background: #218838;
}

/* Responsive Design - Mobile-first vertical layout */
@media (max-width: 480px) {
    body {
        padding: 0;
        height: 100vh;
        overflow: hidden;
        justify-content: space-between;
    }
    
    body > .game-info {
        flex-direction: row;
        gap: 8px;
        padding: 8px 15px;
        font-size: 14px;
        margin-bottom: 5px;
        flex-shrink: 0;
    }

    body > .game-grid {
        grid-template-columns: repeat(7, 1fr);
        gap: 3px;
        padding: 0; /* Remove padding */
        height: 82vh;
        max-width: none;
        width: 100%;
        margin: 0;
        flex-grow: 1;
        display: grid;
        align-content: center;
    }

    body > .selection-container {
        padding: 5px;
        width: 100%;
        flex-shrink: 0;
    }

    .selection-box {
        gap: 3px;
        max-width: 100%;
        width: 100%;
        padding-top: 5px;
    }

    .tile {
        width: calc((100vw - 40px) / 7);
        height: calc((100vw - 40px) / 7);
        font-size: 1.8rem;
        max-width: 70px;
        max-height: 70px;
    }

    .selection-slot {
        width: calc((100vw - 40px) / 7);
        height: calc((100vw - 40px) / 7);
        max-width: 70px;
        max-height: 70px;
    }
}

/* Tablet responsive design - vertical layout optimization */
@media (min-width: 481px) {
    body > header,
    body > main,
    body > .game-info,
    body > .game-grid,
    body > .selection-container {
        padding: 18px;
        margin: 8px auto;
        width: 96%;
        max-width: 450px;
    }

    body > .game-grid {
        grid-template-columns: repeat(7, 1fr);
        gap: 6px;
        min-height: 320px;
        max-width: 384px; /* 7 tiles * 48px + 6 gaps * 6px + 30px padding = 402px */
        padding: 0; /* Remove padding */
    }

    .tile {
        width: 48px;
        height: 48px;
        font-size: 1.5rem;
    }

    .selection-slot {
        width: 48px;
        height: 48px;
    }
}

/* Touch-friendly interactions - simplified */
@media (hover: none) and (pointer: coarse) {
    .tile:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
    
    .tile {
        border-width: 3px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    }
    
    .selection-slot {
        border-width: 3px;
    }
}

/* Desktop optimization - larger screens */
@media (min-width: 769px) {
    body > header,
    body > main,
    body > .game-info,
    body > .game-grid,
    body > .selection-container {
        /* max-width: 600px; */
        /* padding: 30px; */
        margin: 20px auto;
    }

    body > .game-grid {
        grid-template-columns: repeat(7, 1fr);
        gap: 8px;
        max-width: 430px; /* 7 tiles * 50px + 6 gaps * 8px + 40px padding = 438px */
        min-height: 400px;
        padding: 0; /* Remove padding */
    }

    .tile {
        width: 50px;
        height: 50px;
        font-size: 1.6rem;
    }

    .selection-slot {
        width: 50px;
        height: 50px;
    }
}

/* Title Container with Instructions Icon */
.title-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 15px;
    position: relative;
}

.title-container h1 {
    margin: 0;
    font-size: 1.8rem;
    color: #333;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

/* Game Board Styles */

.close-btn {
  position: absolute;
  top: 15px;
  right: 15px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 1.5rem;
  width: 35px;
  height: 35px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}.dialog-body {
    padding: 24px;
}

.instruction-section {
    margin-bottom: 20px;
}

.instruction-section h4 {
    margin: 0 0 8px 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #ff6b6b;
}

.instruction-section p {
    margin: 8px 0;
    line-height: 1.5;
    color: #444;
}

.instruction-section ul {
    margin: 8px 0;
    padding-left: 20px;
}

.instruction-section li {
    margin-bottom: 4px;
    line-height: 1.4;
    color: #555;
}

.example-tiles {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    margin: 8px 0;
    flex-wrap: wrap;
}

.example-tile {
    background: linear-gradient(135deg, #4CAF50, #66BB6A);
    color: white;
    padding: 8px;
    border-radius: 6px;
    font-size: 1.2rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.arrow {
    font-size: 1.2rem;
    color: #ff6b6b;
    font-weight: bold;
}

.example-selection {
    background: #e8f5e8;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #2e7d32;
    border: 1px solid #c8e6c9;
}

.tile-examples {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    margin: 8px 0;
}

.tile-example {
    background: linear-gradient(135deg, #4CAF50, #66BB6A);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    text-align: center;
    font-size: 0.9rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Mobile responsiveness for dialog */
@media (max-width: 768px) {
    .dialog-content {
        width: 95%;
        max-height: 85vh;
    }
    
    .dialog-header {
        padding: 16px;
    }
    
    .dialog-header h3 {
        font-size: 1.1rem;
    }
    
    .dialog-body {
        padding: 20px 16px;
    }
    
    .instruction-section h4 {
        font-size: 1rem;
    }
    
    .tile-examples {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    }
    
    .example-tiles {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 480px) {
    .dialog-content {
        width: 98%;
        max-height: 90vh;
    }
    
    .dialog-header {
        padding: 12px;
    }
    
    .dialog-header h3 {
        font-size: 1rem;
    }
    
    .dialog-body {
        padding: 16px 12px;
    }
    
    .close-instructions {
        width: 28px;
        height: 28px;
        font-size: 1.3rem;
        top: 10px;
        right: 10px;
    }
    
    .title-container h1 {
        font-size: 1.4rem;
    }
    
}

/* Responsive Design */
