/* === ОСНОВНЫЕ ПЕРЕМЕННЫЕ === */
:root {
    --index: calc(1vw + 1.2vh);
    --transition: 1.5s cubic-bezier(.05, .5, 0, 1);
    --glass-bg: rgba(0, 0, 0, 0.55);
    --glass-border: rgba(255, 255, 255, 0.15);
    --text-color: #ffffff;
    --accent: #a5d8ff;
    --accent2: #4dabf7;
}

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

@font-face {
    font-family: 'kamerik-3d';
    src: url('../fonts/kamerik205-heavy.woff2') format('woff2');
    font-weight: 900;
}
@font-face {
    font-family: 'merriweather-italic';
    src: url('../fonts/merriweather-regular-italic.woff2') format('woff2');
}

body {
    background-color: #000;
    color: var(--text-color);
    font-family: 'merriweather-italic', serif;
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    -webkit-font-smoothing: antialiased;
}

/* === 3D СЦЕНА (ФОН) === */
.layers {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: -1;
    perspective: 1000px;
    overflow: hidden;
}
.layers__container {
    height: 100vh;
    transform-style: preserve-3d;
    transform: rotateX(var(--move-y, 0deg)) rotateY(var(--move-x, 0deg));
    will-change: transform;
    transition: transform var(--transition);
}
.layers__item {
    position: absolute;
    inset: -5vw;
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: center;
    justify-content: center;
}
.layer-1 { transform: translateZ(-55px) scale(1.06); }
.layer-2 { transform: translateZ(80px) scale(0.88); }
.layer-4 { transform: translateZ(190px) scale(0.9); }
.layer-5 { transform: translateZ(300px) scale(0.9); }
.layer-6 { transform: translateZ(380px); }

canvas.rain {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
}

/* === ИГРОВАЯ ОБОЛОЧКА === */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border-radius: calc(var(--index) * 1.8);
    border: 1px solid var(--glass-border);
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    transition: transform 0.3s ease;
}

.game-container {
    width: 100%;
    max-width: 800px;
    z-index: 1;
}
.game-panel {
    padding: calc(var(--index) * 1.8);
    display: flex;
    flex-direction: column;
    gap: calc(var(--index) * 1.2);
}

/* Верхняя панель */
.top-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.8rem;
    background: rgba(255,255,255,0.08);
    padding: 0.6rem 1rem;
    border-radius: 40px;
}
.currency-box, .xp-box {
    background: rgba(255,255,255,0.1);
    padding: 0.4rem 1.2rem;
    border-radius: 30px;
    font-weight: bold;
    font-size: calc(var(--index) * 0.7);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.btn-group {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}
.nav-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    padding: 0.4rem 0.9rem;
    border-radius: 30px;
    font-size: calc(var(--index) * 0.55);
    cursor: pointer;
    transition: 0.2s;
    font-family: 'kamerik-3d', sans-serif;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.nav-btn:hover {
    background: var(--accent);
    color: #000;
}
.music-btn {
    opacity: 0.8;
}

/* Грядки */
.fields-container {
    background: rgba(0,0,0,0.3);
    border-radius: 20px;
    padding: 0.8rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
}
.grid {
    display: grid;
    gap: 8px;
    justify-content: flex-start;
}
.cell {
    aspect-ratio: 1 / 1;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--index) * 1.2);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    text-align: center;
    padding: 4px;
    position: relative;
    min-width: 60px;
    max-width: 80px;
}
.cell.empty {
    background: rgba(255, 255, 255, 0.05);
}
.cell.ready {
    background: rgba(255, 215, 0, 0.25);
    border-color: gold;
    box-shadow: 0 0 15px gold;
    animation: harvestPulse 1.5s infinite;
}
@keyframes harvestPulse {
    0%, 100% { box-shadow: 0 0 10px gold; }
    50% { box-shadow: 0 0 20px gold, 0 0 30px orange; }
}
.water-icon {
    position: absolute;
    bottom: 2px; right: 4px;
    font-size: 0.8rem;
    opacity: 0.9;
}
.timer-text {
    font-size: 0.6rem;
    background: rgba(0,0,0,0.6);
    color: #ffffaa;
    font-weight: bold;
    padding: 1px 4px;
    border-radius: 12px;
    margin-top: 2px;
}
.plant-info {
    font-size: 0.6rem;
    background: rgba(0,0,0,0.5);
    color: #ffecb3;
    padding: 1px 4px;
    border-radius: 16px;
    margin-top: 2px;
}

/* Магазин */
.shop {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0.8rem;
    background: rgba(255,255,255,0.05);
    border-radius: 20px;
}
.plant-card {
    background: rgba(255,255,255,0.1);
    flex: 1;
    min-width: 80px;
    border-radius: 16px;
    padding: 6px;
    text-align: center;
    cursor: pointer;
    border: 2px solid transparent;
    transition: 0.1s;
}
.plant-card.selected {
    background: rgba(165,216,255,0.2);
    border-color: var(--accent);
    transform: scale(0.96);
}
.plant-emoji { font-size: 1.5rem; }
.plant-name { font-size: 0.7rem; font-weight: bold; }
.plant-price, .plant-time {
    font-size: 0.6rem;
    background: rgba(0,0,0,0.4);
    display: inline-block;
    padding: 1px 8px;
    border-radius: 20px;
    margin-top: 3px;
}

/* Сообщение */
.message-area {
    background: rgba(0,0,0,0.4);
    border-radius: 30px;
    padding: 0.5rem 1rem;
    text-align: center;
    font-size: calc(var(--index) * 0.65);
    color: #ffeaaf;
}

/* Кнопки внизу */
.buttons-row {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.back-btn, .reset-btn {
    padding: 0.6rem 1.8rem;
    border-radius: 30px;
    font-weight: bold;
    font-size: calc(var(--index) * 0.7);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    border: none;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: 0.3s;
}
.back-btn {
    background: rgba(59, 130, 246, 0.3);
    border: 1px solid var(--accent);
    color: white;
}
.back-btn:hover {
    background: var(--accent);
    color: #000;
}
.reset-btn {
    background: rgba(220, 38, 38, 0.3);
    border: 1px solid #fca5a5;
    color: white;
}
.reset-btn:hover {
    background: #dc2626;
    color: white;
}

/* Модальные окна */
.dynamic-modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}
.dynamic-modal-content {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border-radius: 20px;
    padding: 1.5rem;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid var(--glass-border);
}
.dynamic-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.2);
    padding-bottom: 0.5rem;
}
.dynamic-modal-header h3 {
    font-family: 'kamerik-3d', sans-serif;
    color: var(--accent);
}
.dynamic-close {
    font-size: 1.5rem;
    cursor: pointer;
    color: #aaa;
}
.items-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.item-card {
    background: rgba(255,255,255,0.1);
    border-radius: 16px;
    padding: 8px;
    width: 120px;
    text-align: center;
    font-size: 0.7rem;
}
.craft-btn, .sell-btn {
    background: #6f9e3f;
    border: none;
    padding: 4px 8px;
    border-radius: 30px;
    font-weight: bold;
    font-size: 0.7rem;
    margin-top: 6px;
    cursor: pointer;
    width: 100%;
}
.resource-badge {
    font-size: 0.65rem;
    background: rgba(0,0,0,0.5);
    display: inline-block;
    padding: 2px 6px;
    border-radius: 16px;
    margin: 4px 0;
}
.achievement-item {
    background: rgba(255,255,255,0.1);
    padding: 8px;
    border-radius: 16px;
    margin: 4px 0;
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
}
.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.7rem;
}
.leaderboard-table th, .leaderboard-table td {
    padding: 6px;
    text-align: left;
    border-bottom: 1px solid rgba(255,255,255,0.2);
}
.leaderboard-table th { color: var(--accent); }

/* Строка игрока (вы) */
.player-row {
    background: rgba(165,216,255,0.15) !important;
    font-weight: bold;
}
.player-row td {
    color: var(--accent);
}
.player-tag {
    color: var(--accent);
    font-weight: bold;
    margin-left: 4px;
}

/* ========== АДАПТИВНОСТЬ ========== */
@media (max-width: 768px) {
    :root {
        --index: calc(0.75vw + 0.75vh);
    }
    body {
        padding: 0.4rem;
        align-items: flex-start;
    }
    .game-panel {
        padding: calc(var(--index) * 1.2);
        gap: calc(var(--index) * 0.8);
    }

    .top-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.4rem;
        padding: 0.4rem 0.8rem;
    }
    .currency-box, .xp-box {
        font-size: clamp(12px, calc(var(--index) * 0.8), 18px);
        justify-content: center;
        padding: 0.3rem 1rem;
    }
    .btn-group {
        justify-content: space-evenly;
        gap: 0.3rem;
    }
    .nav-btn {
        font-size: clamp(11px, calc(var(--index) * 0.55), 14px);
        padding: 0.3rem 0.6rem;
        flex: 1 1 auto;
        justify-content: center;
        white-space: nowrap;
    }

    .fields-container {
        padding: 0.3rem;
    }

    /* Увеличены размеры ячеек, убрано скрытие переполнения */
    .cell {
        min-width: 60px;        /* было 55px */
        max-width: 75px;        /* было 70px */
        font-size: clamp(12px, calc(var(--index) * 0.9), 16px);
        overflow: visible;      /* больше не скрываем содержимое */
        padding: 4px 2px;       /* чуть меньше боковых отступов */
    }

    .plant-info {
        font-size: clamp(10px, 0.55rem, 14px);
    }

    /* Таймер: всегда в одну строку, не обрезается */
    .timer-text {
        font-size: clamp(9px, 0.48rem, 11px);
        white-space: nowrap;
        overflow: visible;      /* показываем полностью */
        text-overflow: unset;   /* убираем многоточие */
        max-width: none;        /* снимаем ограничение ширины */
        padding: 1px 0;
        line-height: 1;
    }

    .shop {
        gap: 3px;
        padding: 0.4rem;
        flex-wrap: nowrap;
        overflow-x: auto;
    }
    .plant-card {
        min-width: 65px;
        flex-shrink: 0;
        padding: 4px;
    }
    .plant-emoji { font-size: 1.3rem; }
    .plant-name { font-size: clamp(11px, 0.65rem, 14px); }
    .plant-price, .plant-time {
        font-size: clamp(10px, 0.55rem, 13px);
        padding: 1px 6px;
    }

    .message-area {
        font-size: clamp(12px, calc(var(--index) * 0.65), 16px);
        padding: 0.4rem 0.8rem;
    }

    .buttons-row {
        gap: 0.5rem;
    }
    .back-btn, .reset-btn {
        font-size: clamp(12px, calc(var(--index) * 0.65), 16px);
        padding: 0.5rem 1rem;
        flex: 1 1 auto;
        justify-content: center;
    }

    .dynamic-modal-content {
        width: 95%;
        max-width: 95vw;
        padding: 0.8rem;
        border-radius: 16px;
    }
    .dynamic-modal-header h3 {
        font-size: clamp(14px, 1.1rem, 20px);
    }
    .dynamic-close {
        font-size: clamp(16px, 1.4rem, 22px);
    }
    .items-list {
        gap: 4px;
    }
    .item-card {
        width: 100px;
        padding: 6px;
        font-size: clamp(11px, 0.65rem, 14px);
    }
    .craft-btn, .sell-btn {
        font-size: clamp(11px, 0.65rem, 14px);
        padding: 4px;
    }
    .resource-badge {
        font-size: clamp(10px, 0.6rem, 13px);
    }
    .achievement-item {
        font-size: clamp(11px, 0.65rem, 14px);
        padding: 6px;
    }
    .leaderboard-table {
        font-size: clamp(11px, calc(var(--index) * 0.55), 14px);
    }
    .leaderboard-table th, .leaderboard-table td {
        padding: 4px;
    }
}

@media (max-width: 480px) {
    :root {
        --index: calc(1vw + 1.5vh);
    }
    .cell {
        min-width: 50px;
        max-width: 60px;
    }
    .plant-card {
        min-width: 60px;
    }
}