/**
 * БЁРЧИ | Farm & Tamagotchi Styles
 * Версия 5.3.0 | ФИКС: Умное позиционирование HUD и Криттера 🐌✨
 */

/* =========================================
   БАЗА И ЦЕНТРИРОВАНИЕ ДЛЯ ПК
========================================= */
body.farm-body {
    margin: 0;
    padding: 0;
    background: #0f111a; 
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Roboto', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow-x: hidden;
}

/* =========================================
   ГЛАВНЫЙ КОНТЕЙНЕР
========================================= */
.farm-app-container {
    position: relative;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    background: #12151E;
    color: #fff;
    display: flex;
    touch-action: pan-y;
}

@media (min-width: 500px) {
    .farm-app-container {
        width: 420px;
        height: 85vh;
        max-height: 900px;
        border-radius: 30px;
        box-shadow: 0 20px 60px rgba(0,0,0,0.8), 0 0 0 8px rgba(255,255,255,0.05);
        border: 1px solid #333;
    }
}

/* =========================================
   СВАЙП-ПАНЕЛИ
========================================= */
.farm-pane {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s ease;
    background: #12151E;
}

#pane-main { transform: translateX(0); z-index: 10; }
#pane-market { transform: translateX(100%); z-index: 20; }
.farm-app-container.show-market #pane-main { transform: translateX(-30%); opacity: 0.3; }
.farm-app-container.show-market #pane-market { transform: translateX(0); }

/* =========================================
   ЗОНА КРИТТЕРА (ВЕРХНЯЯ ЧАСТЬ)
========================================= */
.critter-ai-zone {
    flex: 0 0 55%; /* Увеличили высоту верхней зоны для массивного HUD */
    background: linear-gradient(180deg, #1e3c72 0%, #2a5298 50%, #12151E 100%);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: 15px;
    z-index: 2;
}

/* =========================================
   🔥 ИДЕАЛЬНЫЙ HUD (ПРИБОРНАЯ ПАНЕЛЬ) 🔥
========================================= */
.farm-header-hud {
    /* МАГИЯ ЗДЕСЬ: Убрали absolute, добавили margin-bottom: auto */
    position: relative;
    width: calc(100% - 30px);
    margin: 15px auto auto auto; /* Эта пружина выталкивает криттера вниз */
    display: flex;
    flex-direction: column; 
    background: rgba(22, 26, 37, 0.85); 
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 15px;
    border-radius: 20px; 
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), inset 0 2px 4px rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.05);
    gap: 12px;
    z-index: 100;
    box-sizing: border-box;
}

.player-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); 
    gap: 10px;
    width: 100%;
}

.stat-item, .btn-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 8px;
    border-radius: 12px; 
    font-size: 14px;
    font-weight: 800;
    color: #FFFFFF;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
    box-shadow: 0 4px 0 rgba(0,0,0,0.25); 
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    border: none;
    outline: none;
    white-space: nowrap;
    user-select: none;
}

.stat-item:active, .btn-nav:active, 
#hud-btn-storage:active, #hud-btn-cafe:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 rgba(0,0,0,0) !important;
}

/* 🪙 Монеты */
.stat-item.coins {
    background: #2D3240 !important;
    border: 1px solid #444A5A;
    color: #F8BC04 !important;
    box-shadow: 0 4px 0 #1A1D26 !important;
    text-shadow: none;
    cursor: default; 
}
.stat-item.coins:active { transform: none; box-shadow: 0 4px 0 #1A1D26 !important; } 

/* ⭐ Уровень */
.stat-item.xp {
    background: #1A73E8 !important;
    box-shadow: 0 4px 0 #1152A5 !important;
    cursor: default;
}
.stat-item.xp:active { transform: none; box-shadow: 0 4px 0 #1152A5 !important; }

/* 📦 Склад */
#hud-btn-storage {
    background: #34A853 !important;
    box-shadow: 0 4px 0 #1F6B32 !important;
}

/* 💰 Сбыт/Кафе */
#hud-btn-cafe {
    background: #EA4335 !important;
    box-shadow: 0 4px 0 #B32D22 !important;
}

/* 🛒 Рынок */
.btn-nav {
    width: 100%;
    background: #F8BC04 !important;
    color: #1A1D26 !important; 
    box-shadow: 0 4px 0 #C59600 !important;
    text-shadow: none;
    font-size: 15px;
    padding: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Диалоговое окно криттера */
.farm-dialog-bubble {
    background: rgba(255, 255, 255, 0.95);
    color: #111;
    padding: 10px 15px;
    border-radius: 20px 20px 20px 5px;
    margin-bottom: 10px;
    max-width: 85%;
    text-align: center;
    font-weight: 600;
    font-size: 13px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: translateY(0);
    z-index: 10;
}

.farm-dialog-bubble.hidden { opacity: 0; pointer-events: none; transform: translateY(10px); }

.farm-critter-wrapper {
    width: 130px;
    height: 130px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 10px;
    filter: drop-shadow(0 10px 15px var(--critter-glow, rgba(0,0,0,0.5)));
    transition: transform 0.3s;
    cursor: pointer;
    z-index: 10;
}

#critter-svg-wrapper { width: 100%; height: 100%; }
.critter-placeholder { font-size: 14px; color: rgba(255, 255, 255, 0.7); }

/* ЧАТ С КРИТТЕРОМ */
.farm-chat-interface {
    display: flex;
    width: 90%;
    gap: 8px;
    z-index: 10;
}

#farm-chat-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    padding: 10px 15px;
    color: #fff;
    font-size: 14px;
    outline: none;
    backdrop-filter: blur(5px);
    transition: border-color 0.2s, background 0.2s;
}

#farm-chat-input:focus { border-color: #4fc3f7; background: rgba(0, 0, 0, 0.6); }
#farm-chat-input::placeholder { color: rgba(255, 255, 255, 0.6); }

.chat-send-btn {
    background: linear-gradient(135deg, #4fc3f7, #0288d1);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: #fff;
    font-size: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    transition: transform 0.1s;
}

.chat-send-btn:active { transform: scale(0.9); }
.chat-send-btn:disabled { background: #555; color: #888; cursor: not-allowed; box-shadow: none; }

/* =========================================
   ЗОНА ФЕРМЫ И ГРЯДОК (НИЖНЯЯ ЧАСТЬ)
========================================= */
.farm-plots-zone {
    flex: 1;
    padding: 20px 15px 100px 15px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.zone-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    color: #fff;
    font-weight: 800;
}

.zone-title h3 {
    margin: 0;
    font-size: 22px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

#plots-counter {
    background: rgba(255,255,255,0.1);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 14px;
}

.farm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 12px;
    justify-items: center;
}

.farm-plot {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 40px;
    cursor: pointer;
    position: relative;
    user-select: none;
    transition: transform 0.2s, filter 0.2s;
    box-shadow: 0 8px 15px rgba(0,0,0,0.3);
}

.farm-plot:active { transform: scale(0.92); }
.farm-plot:hover { filter: brightness(1.1); }
.farm-plot.planted { filter: brightness(0.8); }
.farm-plot.ready { animation: pulse-ready 1.5s infinite; }

@keyframes pulse-ready {
    0% { box-shadow: 0 0 0 0 rgba(255, 235, 59, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(255, 235, 59, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 235, 59, 0); }
}

.plot-timer {
    position: absolute;
    bottom: 5px;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.7);
    color: #FFF;
    padding: 3px 8px;
    border-radius: 10px;
    font-weight: bold;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.1);
}

/* =========================================
   ЭКРАН РЫНКА И БИЗНЕСА
========================================= */
.market-header {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: #202124;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid #3c4043;
}

.market-header h2 { margin: 0; flex-grow: 1; font-size: 20px; color: #fff; }

.market-tabs { display: flex; padding: 15px; gap: 10px; background: #12151E; overflow-x: auto; }

.tab-btn {
    flex: 1;
    background: #202124;
    color: #9AA0A6;
    border: 2px solid transparent;
    padding: 12px;
    border-radius: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.tab-btn.active { background: rgba(66, 133, 244, 0.1); color: #4285F4; border-color: #4285F4; }

.market-content { flex: 1; padding: 15px; overflow-y: auto; }
.market-section { animation: fadeIn 0.3s; }
.market-section.hidden { display: none; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.shop-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
}

.shop-item {
    background: #202124;
    border-radius: 20px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    border: 1px solid #3c4043;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.shop-item .emoji { font-size: 40px; margin-bottom: 10px; filter: drop-shadow(0 4px 8px rgba(0,0,0,0.4)); }

.item-info h4 { margin: 0 0 5px 0; color: #fff; font-size: 16px; }

.buy-btn {
    background: #1A73E8;
    color: #fff;
    border: none;
    padding: 10px;
    border-radius: 12px;
    font-weight: bold;
    width: 100%;
    margin-top: 10px;
    cursor: pointer;
    box-shadow: 0 3px 0 #1152A5;
    transition: transform 0.1s;
    font-size: 13px;
}

.buy-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: none; }
.buy-btn:disabled { background: #5F6368; box-shadow: none; cursor: not-allowed; color: #9AA0A6; }

.business-locked-notice {
    grid-column: 1 / -1; background: rgba(255, 82, 82, 0.1);
    border: 1px dashed #ff5252; padding: 20px; border-radius: 10px;
    text-align: center; color: #ff8a80; font-size: 13px;
}

/* =========================================
   ОВЕРЛЕЙ ИГРЫ "ТРИ В РЯД"
========================================= */
.match3-overlay {
    position: absolute; 
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s;
}

.match3-overlay.hidden { opacity: 0; pointer-events: none; }

.match3-container {
    background: #202124; padding: 25px; border-radius: 20px;
    text-align: center; width: 90%; max-width: 350px;
    border: 1px solid #3c4043; box-shadow: 0 10px 30px rgba(0,0,0,0.8);
}

.match3-header h2 { margin: 0 0 10px; color: #ff5252; text-transform: uppercase; font-size: 18px; }
.match3-header p { margin: 0 0 15px; font-size: 13px; color: #bbb; }
.match3-stats { background: #12151E; padding: 10px; border-radius: 10px; font-weight: bold; color: #4fc3f7; font-size: 13px; border: 1px solid #333; }

.match3-board {
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px;
    margin-top: 20px; background: #12151E; padding: 10px; border-radius: 12px; border: 1px solid #333;
}

.match3-cell {
    aspect-ratio: 1; background: #3c4043; border-radius: 8px;
    display: flex; justify-content: center; align-items: center;
    font-size: 24px; cursor: pointer; user-select: none;
    transition: transform 0.2s, background 0.2s;
    box-shadow: inset 0 -3px 0 rgba(0,0,0,0.2);
}

.match3-cell:active { transform: scale(0.85); box-shadow: none; }
.match3-cell.selected {
    background: #4caf50; transform: scale(1.1);
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.5); z-index: 2;
}