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

body {
    font-family: 'Comic Sans MS', 'Chewy', 'Patrick Hand', cursive, sans-serif;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    position: relative;
}

/* ==================== Кнопка повернення ==================== */
.close-button {
    position: fixed;
    top: 20px;
    left: 20px;
    width: 70px;
    height: 70px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 1000;
    text-decoration: none;
}

.close-button:hover {
    transform: scale(1.2) rotate(-15deg);
    background: #FFD93D;
    box-shadow: 0 10px 40px rgba(255, 217, 61, 0.6);
}

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

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

/* ==================== Панель досягнень ==================== */
.achievements-panel {
    position: fixed;
    top: 20px;
    right: 20px;
    background: linear-gradient(135deg, #ffffff 0%, #f0f0f0 100%);
    border-radius: 25px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 900;
    max-width: 350px;
}

.stats {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
    justify-content: center;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: white;
    padding: 10px 20px;
    border-radius: 50px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.stat-icon {
    font-size: 28px;
}

.stat-value {
    font-size: 28px;
    font-weight: bold;
    color: #FF6B9D;
}

.stat-label {
    font-size: 18px;
    color: #999;
}

.achievements-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.achievement {
    background: white;
    border-radius: 15px;
    padding: 15px 10px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.achievement.locked {
    opacity: 0.4;
    filter: grayscale(1);
}

.achievement.unlocked {
    animation: unlock 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    box-shadow: 0 8px 30px rgba(255, 215, 0, 0.5);
}

.ach-icon {
    font-size: 36px;
    display: block;
    margin-bottom: 5px;
}

.ach-name {
    font-size: 12px;
    font-weight: bold;
    color: #333;
}

@keyframes unlock {
    0% {
        transform: scale(0.5) rotate(-180deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.2) rotate(10deg);
    }
    100% {
        transform: scale(1) rotate(0);
        opacity: 1;
    }
}

/* ==================== Панель інструментів ==================== */
.tools-panel {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    z-index: 800;
}

.tool-btn {
    width: 140px;
    height: 140px;
    background: linear-gradient(135deg, #ffffff 0%, #f5f5f5 100%);
    border: none;
    border-radius: 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    padding: 15px;
}

.tool-btn:hover {
    transform: scale(1.15) translateY(-10px);
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.3);
}

.tool-btn:active {
    transform: scale(1.05) translateY(-5px);
}

#waterAll:hover {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
}

#fertilizeAll:hover {
    background: linear-gradient(135deg, #ffe0b2 0%, #ffcc80 100%);
}

.tool-icon {
    width: 70px;
    height: 70px;
}

.tool-label {
    font-size: 18px;
    font-weight: bold;
    color: #333;
}

/* ==================== Фон ==================== */
.game-container {
    width: 100%;
    height: 100%;
    position: relative;
}

.background {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
}

.sky {
    width: 100%;
    height: 60%;
    background: linear-gradient(to bottom, #87CEEB 0%, #B0E0E6 100%);
    position: relative;
    overflow: hidden;
}

.sun {
    width: 100px;
    height: 100px;
    background: radial-gradient(circle, #FFD700 60%, #FFA500 100%);
    border-radius: 50%;
    position: absolute;
    top: 50px;
    right: 100px;
    box-shadow: 0 0 60px rgba(255, 215, 0, 0.6);
    animation: sunshine 3s ease-in-out infinite;
}

@keyframes sunshine {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 60px rgba(255, 215, 0, 0.6);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 0 80px rgba(255, 215, 0, 0.8);
    }
}

.cloud {
    background: white;
    border-radius: 100px;
    position: absolute;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
}

.cloud-1 {
    width: 150px;
    height: 60px;
    top: 100px;
    left: 10%;
    animation: float-cloud 30s linear infinite;
}

.cloud-2 {
    width: 120px;
    height: 50px;
    top: 180px;
    left: 40%;
    animation: float-cloud 40s linear infinite reverse;
}

.cloud-3 {
    width: 180px;
    height: 70px;
    top: 130px;
    left: 70%;
    animation: float-cloud 35s linear infinite;
}

@keyframes float-cloud {
    0% {
        transform: translateX(0);
    }
    100% {
        transform: translateX(100vw);
    }
}

.grass {
    width: 100%;
    height: 40%;
    background: linear-gradient(to bottom, #90EE90 0%, #7CB342 100%);
    position: relative;
}

/* ==================== Грядки ==================== */
.garden-grid {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: grid;
    grid-template-columns: repeat(3, 160px);
    grid-template-rows: repeat(3, 160px);
    gap: 20px;
    z-index: 10;
}

.garden-bed {
    width: 160px;
    height: 160px;
    background: linear-gradient(135deg, #8D6E63 0%, #6D4C41 100%);
    border: 4px solid #5D4037;
    border-radius: 20px;
    position: relative;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.garden-bed:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
    border-color: #FFD93D;
}

.garden-bed.empty::before {
    content: '+';
    font-size: 60px;
    color: rgba(255, 255, 255, 0.3);
    font-weight: bold;
}

/* ==================== Рослини ==================== */
.plant {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.plant-emoji {
    font-size: 80px;
    filter: drop-shadow(0 5px 15px rgba(0, 0, 0, 0.3));
    transition: all 0.3s ease;
}

.plant.seed .plant-emoji {
    font-size: 35px;
    opacity: 0.8;
}

.plant.watered .plant-emoji {
    font-size: 45px;
    animation: watered-shake 0.5s ease;
}

.plant.growing .plant-emoji {
    animation: growing 3s ease-out forwards;
}

.plant.grown .plant-emoji {
    font-size: 95px;
    animation: bloom 1s ease, pulse 2s ease-in-out infinite;
    cursor: pointer;
}

.plant.grown:hover .plant-emoji {
    transform: scale(1.2) rotate(10deg);
}

@keyframes watered-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@keyframes growing {
    0% {
        font-size: 45px;
        opacity: 0.8;
    }
    100% {
        font-size: 95px;
        opacity: 1;
    }
}

@keyframes bloom {
    0% {
        transform: scale(0.5) rotate(-180deg);
        opacity: 0;
    }
    60% {
        transform: scale(1.2) rotate(10deg);
    }
    100% {
        transform: scale(1) rotate(0);
        opacity: 1;
    }
}

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

/* Індикатори стану */
.plant.watered::after {
    content: '💧';
    position: absolute;
    top: -20px;
    right: -20px;
    font-size: 30px;
    animation: drop 0.5s ease;
}

.plant.fertilized::after {
    content: '🌿';
    position: absolute;
    top: -20px;
    left: -20px;
    font-size: 30px;
    animation: fertilizer-appear 0.5s ease;
}

@keyframes drop {
    0% {
        transform: translateY(-30px);
        opacity: 0;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes fertilizer-appear {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Зірочки для готових рослин */
.plant.grown::before {
    content: '✨';
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 35px;
    animation: sparkle 1.5s ease-in-out infinite;
}

@keyframes sparkle {
    0%, 100% {
        opacity: 0;
        transform: translateX(-50%) translateY(0);
    }
    50% {
        opacity: 1;
        transform: translateX(-50%) translateY(-10px);
    }
}

/* ==================== Панель насіння ==================== */
.seeds-panel {
    position: fixed;
    right: 30px;
    bottom: 30px;
    background: linear-gradient(135deg, #ffffff 0%, #f5f5f5 100%);
    border-radius: 25px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 700;
}

.seeds-title {
    font-size: 22px;
    color: #333;
    text-align: center;
    margin-bottom: 15px;
}

.seeds-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.seed-btn {
    width: 120px;
    height: 90px;
    background: white;
    border: 3px solid #ddd;
    border-radius: 18px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.seed-btn:hover {
    transform: scale(1.15);
    border-color: #FFD93D;
    box-shadow: 0 8px 25px rgba(255, 217, 61, 0.5);
}

.seed-btn:active {
    transform: scale(1.05);
}

.seed-btn.selected {
    border-color: #4CAF50;
    background: #E8F5E9;
    box-shadow: 0 0 30px rgba(76, 175, 80, 0.6);
    animation: pulse-border 1s infinite;
}

.seed-btn.empty {
    opacity: 0.3;
    cursor: not-allowed;
}

.seed-btn.empty:hover {
    transform: none;
}

@keyframes pulse-border {
    0%, 100% {
        border-color: #4CAF50;
    }
    50% {
        border-color: #81C784;
    }
}

.seed-preview {
    font-size: 50px;
}

.seed-count {
    position: absolute;
    bottom: -8px;
    right: -8px;
    background: #FF6B9D;
    color: white;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
    box-shadow: 0 4px 15px rgba(255, 107, 157, 0.5);
}

/* ==================== Попап досягнення ==================== */
.achievement-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    background: linear-gradient(135deg, #FFD93D 0%, #FFA500 100%);
    border-radius: 30px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    z-index: 2000;
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.achievement-popup.show {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

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

.popup-icon {
    font-size: 80px;
    margin-bottom: 15px;
    animation: bounce 0.6s ease;
}

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

.popup-title {
    font-size: 42px;
    color: white;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.3);
    margin-bottom: 10px;
}

.popup-text {
    font-size: 24px;
    color: #333;
    font-weight: bold;
}

.confetti {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* ==================== Підказка ==================== */
.tutorial {
    position: fixed;
    bottom: 250px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border-radius: 20px;
    padding: 20px 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    z-index: 1500;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.5s ease;
}

.tutorial.show {
    opacity: 1;
    animation: float-tutorial 2s ease-in-out infinite;
}

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

.tutorial-arrow {
    font-size: 50px;
    animation: point 1s ease-in-out infinite;
}

@keyframes point {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(10px);
    }
}

.tutorial-text {
    font-size: 24px;
    color: #333;
    font-weight: bold;
    text-align: center;
}

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

    .garden-bed {
        width: 130px;
        height: 130px;
    }

    .achievements-panel {
        max-width: 280px;
        padding: 15px;
    }

    .tool-btn {
        width: 110px;
        height: 110px;
    }

    .tool-icon {
        width: 55px;
        height: 55px;
    }
}

@media (max-width: 768px) {
    .garden-grid {
        grid-template-columns: repeat(3, 100px);
        grid-template-rows: repeat(3, 100px);
        gap: 12px;
    }

    .garden-bed {
        width: 100px;
        height: 100px;
    }

    .plant-emoji {
        font-size: 60px !important;
    }

    .seeds-panel {
        right: 15px;
        bottom: 15px;
        padding: 12px;
    }

    .seed-btn {
        width: 80px;
        height: 65px;
    }

    .seed-preview {
        font-size: 35px;
    }

    .tool-btn {
        width: 90px;
        height: 90px;
    }

    .achievements-panel {
        top: 10px;
        right: 10px;
        max-width: 220px;
        padding: 10px;
    }

    .stat-item {
        padding: 6px 12px;
    }

    .stat-icon {
        font-size: 20px;
    }

    .stat-value {
        font-size: 20px;
    }
}

/* Mobile phones (<480px) */
@media (max-width: 480px) {
    .game-container {
        padding: 5px;
    }

    .garden-grid {
        grid-template-columns: repeat(3, 85px);
        grid-template-rows: repeat(3, 85px);
        gap: 8px;
    }

    .garden-bed {
        width: 85px;
        height: 85px;
    }

    .plant-emoji {
        font-size: 50px !important;
    }

    .plant.grown .plant-emoji {
        font-size: 75px !important;
    }

    /* Achievements panel - make collapsible */
    .achievements-panel {
        top: 5px;
        right: 5px;
        max-width: 180px;
        padding: 8px;
        font-size: 12px;
    }

    .achievements-title {
        font-size: 14px;
        margin-bottom: 6px;
    }

    .achievement-item {
        padding: 4px;
        font-size: 11px;
    }

    .achievement-icon {
        font-size: 16px;
    }

    .stat-item {
        padding: 4px 8px;
    }

    .stat-icon {
        font-size: 16px;
    }

    .stat-value {
        font-size: 16px;
    }

    /* Tools panel - smaller */
    .tools-panel {
        bottom: 5px;
        left: 5px;
        gap: 8px;
        padding: 8px;
    }

    .tool-btn {
        width: 70px;
        height: 70px;
    }

    .tool-icon {
        width: 35px;
        height: 35px;
    }

    .tool-label {
        font-size: 11px;
    }

    /* Seeds panel - stack vertically on very small screens */
    .seeds-panel {
        right: 5px;
        bottom: 5px;
        padding: 8px;
        max-height: 45vh;
        overflow-y: auto;
    }

    .seed-btn {
        width: 70px;
        height: 60px;
        font-size: 11px;
    }

    .seed-preview {
        font-size: 30px;
    }

    .title {
        font-size: 24px;
        margin-bottom: 8px;
    }

    /* Reduce cloud animations for performance */
    .cloud {
        animation-duration: 60s !important;
    }
}

/* Landscape orientation optimization */
@media (max-width: 896px) and (orientation: landscape) {
    .game-container {
        padding: 5px 10px;
    }

    .garden-grid {
        grid-template-columns: repeat(3, 90px);
        grid-template-rows: repeat(3, 90px);
        gap: 10px;
    }

    .garden-bed {
        width: 90px;
        height: 90px;
    }

    /* Stack panels horizontally in landscape */
    .achievements-panel {
        top: 5px;
        right: auto;
        left: 5px;
        max-width: 200px;
        max-height: calc(100vh - 10px);
        overflow-y: auto;
    }

    .tools-panel {
        bottom: 5px;
        left: auto;
        right: 5px;
        flex-direction: row;
        padding: 8px;
    }

    .tool-btn {
        width: 70px;
        height: 70px;
    }

    .seeds-panel {
        bottom: 5px;
        right: 5px;
        top: auto;
        max-height: 60vh;
    }

    .seed-btn {
        width: 65px;
        height: 55px;
    }

    .title {
        font-size: 20px;
        margin-bottom: 5px;
    }

    /* Disable clouds in landscape for better performance */
    .cloud {
        display: none;
    }
}

/* Very small phones (<400px) */
@media (max-width: 400px) {
    .garden-grid {
        grid-template-columns: repeat(3, 75px);
        grid-template-rows: repeat(3, 75px);
        gap: 6px;
    }

    .garden-bed {
        width: 75px;
        height: 75px;
    }

    .plant-emoji {
        font-size: 45px !important;
    }

    .plant.grown .plant-emoji {
        font-size: 65px !important;
    }

    .tool-btn,
    .seed-btn {
        width: 60px;
        height: 60px;
    }

    .tool-icon {
        width: 30px;
        height: 30px;
    }

    .seed-preview {
        font-size: 25px;
    }

    .achievements-panel {
        max-width: 150px;
        font-size: 10px;
    }

    .achievement-icon,
    .stat-icon {
        font-size: 14px;
    }
}

/* Touch improvements for all mobile devices */
@media (hover: none) and (pointer: coarse) {
    /* Increase tap targets */
    .tool-btn,
    .seed-btn,
    .garden-bed {
        min-width: 60px;
        min-height: 60px;
    }

    /* Remove hover effects on touch devices */
    .tool-btn:hover,
    .seed-btn:hover,
    .garden-bed:hover {
        transform: none;
    }

    /* Add active state instead */
    .tool-btn:active,
    .seed-btn:active {
        transform: scale(0.95);
        opacity: 0.8;
    }

    .garden-bed:active {
        transform: scale(0.98);
    }

    /* Prevent text selection on touch */
    .tool-btn,
    .seed-btn,
    .garden-bed,
    .achievement-item {
        -webkit-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
}
