/* ===========================================
   FIND THE PAIR - Styles
   Mobile-first, Kids-friendly
   =========================================== */

/* Reset and Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Colors */
    --color-background: #E8F5E9;
    --color-card: #FFFFFF;
    --color-selected: #FFD700;
    --color-glow: rgba(255, 215, 0, 0.6);
    --color-success: #4CAF50;
    --color-success-glow: rgba(76, 175, 80, 0.6);
    --color-shadow: rgba(0, 0, 0, 0.15);
    --color-title: #2E7D32;

    /* Sizes */
    --object-size: 80px;
    --object-gap: 12px;
    --emoji-size: 48px;
    --border-radius: 16px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-medium: 0.3s ease;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-background);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

/* ===========================================
   GAME CONTAINER
   =========================================== */

.game-container {
    width: 100%;
    max-width: 400px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

/* ===========================================
   HEADER
   =========================================== */

.header {
    text-align: center;
}

.title {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
}

.title .emoji {
    font-size: 40px;
    animation: float 2s ease-in-out infinite;
}

.title .emoji:nth-child(2) {
    animation-delay: 0.3s;
}

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

/* ===========================================
   GAME GRID
   =========================================== */

.game-grid {
    display: grid;
    gap: var(--object-gap);
    justify-content: center;
    align-content: center;
}

/* Grid configurations based on data attribute */
.game-grid[data-size="4"] {
    grid-template-columns: repeat(2, var(--object-size));
}

.game-grid[data-size="6"] {
    grid-template-columns: repeat(3, var(--object-size));
}

.game-grid[data-size="9"] {
    grid-template-columns: repeat(3, var(--object-size));
}

/* ===========================================
   OBJECTS
   =========================================== */

.object {
    width: var(--object-size);
    height: var(--object-size);
    background: var(--color-card);
    border-radius: var(--border-radius);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: var(--emoji-size);
    cursor: pointer;
    border: 3px solid transparent;
    box-shadow: 0 4px 12px var(--color-shadow);
    transition: transform var(--transition-fast),
                border-color var(--transition-fast),
                box-shadow var(--transition-fast);
    touch-action: manipulation;
}

.object:active {
    transform: scale(0.95);
}

/* Selected state */
.object.selected {
    transform: scale(1.1);
    border-color: var(--color-selected);
    box-shadow: 0 0 20px var(--color-glow),
                0 8px 20px var(--color-shadow);
}

/* Matched state */
.object.matched {
    border-color: var(--color-success);
    box-shadow: 0 0 25px var(--color-success-glow),
                0 8px 20px var(--color-shadow);
    animation: celebrate-match 0.6s ease;
}

@keyframes celebrate-match {
    0% {
        transform: scale(1.1);
    }
    25% {
        transform: scale(1.3) rotate(-5deg);
    }
    50% {
        transform: scale(1.3) rotate(5deg);
    }
    75% {
        transform: scale(1.2) rotate(-3deg);
    }
    100% {
        transform: scale(1.1);
    }
}

/* No match - shake */
.object.no-match {
    animation: shake 0.4s ease;
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    20% {
        transform: translateX(-8px);
    }
    40% {
        transform: translateX(8px);
    }
    60% {
        transform: translateX(-6px);
    }
    80% {
        transform: translateX(6px);
    }
}

/* Entering animation */
.object.entering {
    animation: fade-in 0.3s ease backwards;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Staggered entrance */
.object:nth-child(1) { animation-delay: 0ms; }
.object:nth-child(2) { animation-delay: 50ms; }
.object:nth-child(3) { animation-delay: 100ms; }
.object:nth-child(4) { animation-delay: 150ms; }
.object:nth-child(5) { animation-delay: 200ms; }
.object:nth-child(6) { animation-delay: 250ms; }
.object:nth-child(7) { animation-delay: 300ms; }
.object:nth-child(8) { animation-delay: 350ms; }
.object:nth-child(9) { animation-delay: 400ms; }

/* ===========================================
   CELEBRATION OVERLAY
   =========================================== */

.celebration-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(232, 245, 233, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: overlay-in 0.3s ease;
}

.celebration-overlay[hidden] {
    display: none;
}

@keyframes overlay-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.celebration-content {
    text-align: center;
    position: relative;
}

.celebration-emojis {
    display: flex;
    gap: 16px;
    justify-content: center;
    font-size: 64px;
}

.celebration-emojis span {
    animation: bounce-celebrate 0.6s ease infinite;
}

.celebration-emojis span:nth-child(1) {
    animation-delay: 0s;
}

.celebration-emojis span:nth-child(2) {
    animation-delay: 0.1s;
}

.celebration-emojis span:nth-child(3) {
    animation-delay: 0.2s;
}

@keyframes bounce-celebrate {
    0%, 100% {
        transform: translateY(0) scale(1);
    }
    50% {
        transform: translateY(-20px) scale(1.1);
    }
}

/* ===========================================
   CONFETTI
   =========================================== */

.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.confetti-piece {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    animation: confetti-fall var(--duration, 2s) ease-out var(--delay, 0s) forwards;
}

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

/* ===========================================
   RESPONSIVE
   =========================================== */

/* Larger screens */
@media (min-width: 400px) {
    :root {
        --object-size: 90px;
        --object-gap: 16px;
        --emoji-size: 52px;
    }
}

/* Tablet and larger */
@media (min-width: 600px) {
    :root {
        --object-size: 100px;
        --object-gap: 20px;
        --emoji-size: 56px;
    }

    .title .emoji {
        font-size: 48px;
    }

    .celebration-emojis {
        font-size: 80px;
    }
}

/* Landscape on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    :root {
        --object-size: 70px;
        --emoji-size: 40px;
    }

    .game-container {
        gap: 12px;
    }

    .title .emoji {
        font-size: 32px;
    }
}
