/* --- Global Reset & Background --- */
body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
     background-image: url('images/bgbody.png'); /* Ваш файл фона */
    background-size: cover;
    background-position: center center;
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'Segoe UI', sans-serif;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #1b5e20;
    
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-touch-callout: none; 
}

/* --- Scaler Container --- */
#game-scaler {
    width: 360px; 
    height: 640px;
    position: relative;
    overflow: hidden;
    touch-action: none; 
}

/* --- Internal Layout --- */
header {
    position: absolute;
    top: 10px;
    left: 0;
    width: 100%;
    text-align: center;
    padding: 0 15px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.game-logo {
    height: 35px; 
    width: auto;  
    display: block;
    margin-left: 10px;
    pointer-events: none;
}

.level-badge {
    font-size: 16px;
    color: #fff;
    background: #ff7043;
    padding: 5px 12px;
    border-radius: 20px;
    box-shadow: 0 4px 0 #d84315;
    border: 2px solid #fff;
    pointer-events: none;
}

.stats-panel {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    width: 320px;
    display: flex;
    justify-content: space-between;
    background: #fff;
    padding: 10px 15px;
    border-radius: 20px;
    border: 3px solid #a5d6a7;
    z-index: 10;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    pointer-events: none;
}

.stat-box { text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.icon-value-row { display: flex; align-items: center; justify-content: center; gap: 5px; margin-bottom: 2px; }
.stat-icon { font-size: 22px; line-height: 1; }
.stat-label { font-size: 10px; color: #888; text-transform: uppercase; font-weight: bold; }
.stat-value { font-size: 20px; font-weight: 900; color: #2e7d32; line-height: 1; }

#game-container {
    position: absolute;
    top: 110px;
    left: 50%;
    transform: translateX(-50%);
    width: 320px;
    height: 320px;
    background-color: #c5e1a5; 
    border-radius: 20px;
    padding: 10px;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.1);
    border: 5px solid #9ccc65;
    z-index: 1;
}

.grid {
    display: grid;
    grid-gap: 6px;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-content: center;
}

.cell {
    cursor: pointer;
    position: relative;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    box-shadow: inset 0 -3px 6px rgba(0,0,0,0.1);
    transition: transform 0.2s, background 0.2s;
    z-index: 1;
    -webkit-user-drag: none;
    user-drag: none;
}

.cell:hover { background: rgba(255, 255, 255, 0.6); }
.cell.selected {
    box-shadow: 0 0 0 4px #fff, 0 0 20px #ffeb3b;
    z-index: 2;
    transform: scale(1.1);
    background: #fff;
}

/* --- Hint Animation --- */
@keyframes hint-shake {
    0% { transform: rotate(0deg) scale(1); }
    25% { transform: rotate(-8deg) scale(1.1); }
    50% { transform: rotate(8deg) scale(1.1); }
    75% { transform: rotate(-8deg) scale(1.1); }
    100% { transform: rotate(0deg) scale(1); }
}

.hint-active { z-index: 5; background: rgba(255,255,255,0.6); }
.hint-active .gem {
    animation: hint-shake 0.8s infinite ease-in-out;
    filter: brightness(1.2);
}

/* --- Gems (Sprite) --- */
.gem {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background-image: var(--sprite-url);
    background-repeat: no-repeat;
    background-size: 600% 100%; 
    pointer-events: none;
}
.type-0 { background-position: 0% 0%; }
.type-1 { background-position: 20% 0%; }
.type-2 { background-position: 40% 0%; }
.type-3 { background-position: 60% 0%; }
.type-4 { background-position: 80% 0%; }
.type-5 { background-position: 100% 0%; }

@keyframes pop { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(0); opacity: 0; } }
@keyframes fall { 0% { transform: translateY(-50px); opacity: 0; } 100% { transform: translateY(0); opacity: 1; } }
.pop-anim { animation: pop 0.3s forwards; }
.fall-anim { animation: fall 0.4s ease-out; }

.particle { position: absolute; pointer-events: none; background: white; border-radius: 50%; z-index: 10; }

/* --- Bottom Controls --- */
.bottom-controls {
    position: absolute;
    bottom: 20px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 20px;
    box-sizing: border-box;
    z-index: 5;
}

.floating-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: linear-gradient(135deg, #ff8a65, #ff5722);
    box-shadow: 0 6px 15px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    cursor: pointer;
    transition: transform 0.1s, filter 0.2s;
    user-select: none;
}
.floating-btn:active { transform: scale(0.9); box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
.floating-btn:hover { filter: brightness(1.1); }
.btn-sound { background: linear-gradient(135deg, #42a5f5, #0077b6); }

/* --- Victory / Collection UI --- */
#overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
   background: rgba(232, 245, 233, 0.95); /* #e8f5e9 */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    text-align: center;
    padding: 20px;
    box-sizing: border-box;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    color: #1b5e20;
}

#overlay.active { opacity: 1; pointer-events: all; }

#overlay h2 { font-size: 28px; margin: 0 0 10px 0; color: #2e7d32; text-shadow: 1px 1px 0 #fff; z-index: 2; position: relative; user-select: none; }

.overlay-score-box {
    background: #fff;
    padding: 15px;
    border-radius: 15px;
    margin-bottom: 20px;
    width: 100%;
    box-sizing: border-box;
    border: 3px solid #a5d6a7;
    z-index: 2; position: relative;
    user-select: none;
}
.score-row { display: flex; justify-content: space-between; margin: 5px 0; font-size: 16px; color: #333; }
.score-total { color: #ef6c00; font-weight: bold; border-top: 1px solid #ddd; padding-top: 8px; margin-top: 8px; }

.reward-box {
    width: 80px;
    height: 80px;
    margin: 0 auto 15px auto;
    position: relative;
    display: none;
    z-index: 2;
}
.reward-box.active { display: block; animation: rewardPop 0.8s ease-out; }

@keyframes rewardPop {
    0% { transform: scale(0) rotate(-180deg); opacity: 0; }
    60% { transform: scale(1.2) rotate(10deg); opacity: 1; }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.reward-icon {
    width: 100%;
    height: 100%;
    background-size: 600% 100%;
    background-repeat: no-repeat;
    pointer-events: none;
}

.btn {
    background: #43a047;
    border: none;
    padding: 12px 30px;
    color: white;
    font-size: 18px;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 5px 0 #2e7d32;
    transition: transform 0.1s;
    margin-top: 10px;
    font-weight: bold;
    position: relative;
    z-index: 2;
    user-select: none;
}
.btn:active { transform: translateY(4px); box-shadow: 0 0 0 #2e7d32; }
.btn-secondary { background: #ff9800; box-shadow: 0 5px 0 #f57c00; }
.btn-secondary:active { box-shadow: 0 0 0 #f57c00; }

/* --- Collection Shelf Window --- */
#collection-window {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #f1f8e9;
    z-index: 200;
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 20px 10px;
    box-sizing: border-box;
    overflow-y: auto;
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
    user-select: none;
}

#collection-window.active { display: flex; }

.section-title {
    font-size: 20px;
    color: #5d4037;
    margin-top: 10px;
    margin-bottom: 10px;
    text-shadow: 1px 1px 0 #fff;
}

.shelf-wrapper {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 10px;
}

.shelf-container {
    width: 300px;
    height: 200px; 
    background: #d7ccc8;
    border-radius: 15px;
    padding: 10px 20px 25px 20px;
    position: relative;
    box-shadow: inset 0 5px 15px rgba(0,0,0,0.2), 0 10px 20px rgba(0,0,0,0.15);
    border: 4px solid #8d6e63;
    background-image: repeating-linear-gradient(90deg, rgba(0,0,0,0.02) 0px, rgba(0,0,0,0.02) 1px, transparent 1px, transparent 10px);
}

.shelf-planks {
    position: absolute;
    width: 85%;
    left: 7.5%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}
.shelf-plank {
    position: absolute;
    width: 100%;
    height: 8px;
    background: #a1887f;
    box-shadow: 0 3px 3px rgba(0,0,0,0.3);
    border-radius: 2px;
}
.shelf-plank:nth-child(1) { top: 80px; }
.shelf-plank:nth-child(2) { top: 155px; }

.shelf-grid {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr); 
    grid-template-rows: repeat(2, 1fr);    
    align-items: end; 
}

.shelf-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
    padding-bottom: 15px;
}

.shelf-item-icon {
    width: 50px;
    height: 50px;
    background-image: var(--sprite-url);
    background-size: 600% 100%;
    background-repeat: no-repeat;
    position: relative;
    filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.3));
    transition: transform 0.2s;
}
.shelf-item-icon:hover { transform: scale(1.1) rotate(5deg); }

.shelf-item-icon.is-bouquet {
    background-image: var(--bouquet-url) !important;
}

.shelf-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4081;
    color: white;
    font-size: 14px;
    font-weight: bold;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    z-index: 5;
}
.shelf-badge.hidden { display: none; }

.slot-0 .shelf-item-icon { background-position: 0% 0%; }
.slot-1 .shelf-item-icon { background-position: 20% 0%; }
.slot-2 .shelf-item-icon { background-position: 40% 0%; }
.slot-3 .shelf-item-icon { background-position: 60% 0%; }
.slot-4 .shelf-item-icon { background-position: 80% 0%; }
.slot-5 .shelf-item-icon { background-position: 100% 0%; }

.shelf-wrapper:has(#shelf-grid-flowers) .shelf-container {
    height: 120px;
    padding-bottom: 10px;
}

.shelf-wrapper:has(#shelf-grid-flowers) .shelf-plank:nth-child(2) {
    display: none;
}
.shelf-wrapper:has(#shelf-grid-flowers) .shelf-plank:nth-child(1) {
    top: 90px;
}

#shelf-grid-flowers {
    grid-template-rows: 1fr;
    grid-template-columns: repeat(6, 1fr);
}

#achievements-container {
    position: absolute;
    bottom: 100px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    z-index: 300;
    width: 300px;
}
.achievement-toast {
    background: #fff;
    border-left: 5px solid #43a047;
    padding: 10px;
    border-radius: 10px;
    color: #333;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    animation: slideIn 0.5s ease-out, fadeOut 0.5s ease-in 3.5s forwards;
    display: flex;
    align-items: center;
    gap: 10px;
    user-select: none;
}
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(-10px); } }
