* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Comic Sans MS', 'Arial', sans-serif;
    background: linear-gradient(135deg, #87CEEB 0%, #98D8C8 50%, #90EE90 100%);
    min-height: 100vh;
    overflow: hidden;
    position: relative;
}

/* Кнопка закриття */
.close-button {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 1000;
    text-decoration: none;
}

.close-button:hover {
    transform: scale(1.15) rotate(90deg);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    background: #ff6b6b;
}

.close-button svg {
    width: 30px;
    height: 30px;
    stroke: #333;
    transition: stroke 0.3s ease;
}

.close-button:hover svg {
    stroke: white;
}

.close-button:active {
    transform: scale(1.05) rotate(90deg);
}

.container {
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.animals-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 20px;
    max-width: 1200px;
    width: 100%;
    max-height: 700px;
    height: 100%;
}

.animal {
    background: white;
    border-radius: 25px;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.animal::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.6), transparent);
    transform: translate(-50%, -50%);
    transition: width 0.4s, height 0.4s;
    pointer-events: none;
    opacity: 0;
}

.animal:hover {
    transform: translateY(-10px) scale(1.05);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
}

.animal:hover::before {
    width: 300px;
    height: 300px;
    opacity: 1;
}

.animal svg {
    width: 100%;
    height: 100%;
    max-width: 150px;
    max-height: 150px;
    filter: drop-shadow(3px 3px 5px rgba(0, 0, 0, 0.2));
    transition: all 0.3s ease;
}

/* Анімація при кліку */
.animal.clicked {
    animation: bounce 0.6s ease;
}

@keyframes bounce {
    0%, 100% {
        transform: scale(1);
    }
    25% {
        transform: scale(1.2) rotate(-5deg);
    }
    50% {
        transform: scale(1.1) rotate(5deg);
    }
    75% {
        transform: scale(1.15) rotate(-3deg);
    }
}

.animal.clicked svg {
    animation: shake 0.6s ease;
}

@keyframes shake {
    0%, 100% {
        transform: rotate(0deg);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: rotate(-10deg);
    }
    20%, 40%, 60%, 80% {
        transform: rotate(10deg);
    }
}

/* Унікальні кольори для кожної тварини */
.animal[data-animal="cat"] {
    background: linear-gradient(135deg, #fff 0%, #ffe5cc 100%);
}

.animal[data-animal="dog"] {
    background: linear-gradient(135deg, #fff 0%, #f5deb3 100%);
}

.animal[data-animal="cow"] {
    background: linear-gradient(135deg, #fff 0%, #e6f2ff 100%);
}

.animal[data-animal="sheep"] {
    background: linear-gradient(135deg, #fff 0%, #f0f0f0 100%);
}

.animal[data-animal="duck"] {
    background: linear-gradient(135deg, #fff 0%, #ffffcc 100%);
}

.animal[data-animal="pig"] {
    background: linear-gradient(135deg, #fff 0%, #ffe6f0 100%);
}

.animal[data-animal="rooster"] {
    background: linear-gradient(135deg, #fff 0%, #ffe6e6 100%);
}

.animal[data-animal="horse"] {
    background: linear-gradient(135deg, #fff 0%, #e6d5cc 100%);
}

/* Адаптивність */
@media (max-width: 1024px) {
    .animals-grid {
        grid-template-columns: repeat(3, 1fr);
        grid-template-rows: repeat(3, 1fr);
        gap: 15px;
    }
}

@media (max-width: 768px) {
    .animals-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: repeat(4, 1fr);
        gap: 12px;
    }

    .animal {
        padding: 15px;
    }

    .animal svg {
        max-width: 100px;
        max-height: 100px;
    }
}

@media (max-width: 480px) {
    .animals-grid {
        gap: 10px;
    }

    .animal {
        padding: 10px;
        border-radius: 15px;
    }

    .animal svg {
        max-width: 70px;
        max-height: 70px;
    }

    /* Збільшуємо кнопку закриття для маленьких пальчиків */
    .close-button {
        width: 70px;
        height: 70px;
        top: 10px;
        right: 10px;
    }

    .close-button svg {
        width: 35px;
        height: 35px;
    }
}

/* Дуже маленькі телефони */
@media (max-width: 400px) {
    .close-button {
        width: 65px;
        height: 65px;
        top: 5px;
        right: 5px;
    }

    .close-button svg {
        width: 32px;
        height: 32px;
    }

    .container {
        padding: 10px;
    }

    .animals-grid {
        gap: 8px;
    }
}

/* Landscape orientation для телефонів */
@media (max-width: 896px) and (orientation: landscape) {
    .animals-grid {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(2, 1fr);
        gap: 8px;
        max-height: 90vh;
    }

    .animal {
        padding: 8px;
    }

    .animal svg {
        max-width: 60px;
        max-height: 60px;
    }

    .close-button {
        width: 50px;
        height: 50px;
        top: 5px;
        right: 5px;
    }

    .close-button svg {
        width: 25px;
        height: 25px;
    }

    .container {
        padding: 10px;
    }
}

/* Touch-specific improvements */
@media (hover: none) and (pointer: coarse) {
    /* Видаляємо hover ефекти на touch пристроях */
    .animal:hover {
        transform: none;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    }

    .animal:hover::before {
        width: 0;
        height: 0;
        opacity: 0;
    }

    .close-button:hover {
        transform: none;
        background: white;
        box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    }

    .close-button:hover svg {
        stroke: #333;
    }

    /* Додаємо active стани для тактильного відгуку */
    .animal:active {
        transform: scale(0.95);
    }

    .close-button:active {
        transform: scale(0.9) rotate(90deg);
        background: #ff6b6b;
    }

    .close-button:active svg {
        stroke: white;
    }

    /* Мінімальна область для натискання */
    .close-button {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Пульсація при завантаженні */
@keyframes pulse-gentle {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
}

.animal {
    animation: pulse-gentle 3s ease-in-out infinite;
}

.animal:nth-child(1) { animation-delay: 0s; }
.animal:nth-child(2) { animation-delay: 0.2s; }
.animal:nth-child(3) { animation-delay: 0.4s; }
.animal:nth-child(4) { animation-delay: 0.6s; }
.animal:nth-child(5) { animation-delay: 0.8s; }
.animal:nth-child(6) { animation-delay: 1s; }
.animal:nth-child(7) { animation-delay: 1.2s; }
.animal:nth-child(8) { animation-delay: 1.4s; }
