package com.mygdx.game;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.utils.Array;

public class BuildingRenderer {
    private final ShapeRenderer shapeRenderer;
    private final SpriteBatch batch;
    private final BitmapFont font;
    private final GlyphLayout glyphLayout;
    private final Texture whitePixel;

    public BuildingRenderer(ShapeRenderer shapeRenderer, SpriteBatch batch, BitmapFont font,
                            GlyphLayout glyphLayout, Texture whitePixel) {
        this.shapeRenderer = shapeRenderer;
        this.batch = batch;
        this.font = font;
        this.glyphLayout = glyphLayout;
        this.whitePixel = whitePixel;
    }

    public void renderBuildings(Array<Building> buildings, Building currentBuilding, float time, Planet planet) {
        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);

        for (Building building : buildings) {
            renderSingleBuilding(building, time, false, planet);
        }

        if (currentBuilding != null) {
            renderSingleBuilding(currentBuilding, time, true, planet);
        }

        shapeRenderer.end();

        // Рендерим детали поверх
        renderBuildingDetails(buildings, currentBuilding, time);
    }

    private void renderSingleBuilding(Building building, float time, boolean isCurrent, Planet planet) {
        float x = building.x;
        float y = building.y;
        float width = building.width;
        float height = building.height;
        float scale = building.getSizeScale();

        if (!building.isComplete()) {
            renderConstructionPhase(building, x, y, width, height, time, isCurrent, planet);
            return;
        }

        // Для Земли используем старые методы
        if (planet == Planet.EARTH) {
            switch (building.buildingTypeIndex) {
                case 0: renderCuteHouse(building, x, y, width, height, time, scale); break;
                case 1: renderHospital(building, x, y, width, height, time, scale); break;
                case 2: renderSchool(building, x, y, width, height, time, scale); break;
                case 3: renderPlayground(building, x, y, width, height, time, scale); break;
                case 4: renderBank(building, x, y, width, height, time, scale); break;
                case 5: renderPharmacy(building, x, y, width, height, time, scale); break;
                case 6: renderTheater(building, x, y, width, height, time, scale); break;
                case 7: renderCinema(building, x, y, width, height, time, scale); break;
            }
        } else {
            // Для Марса и Венеры используем универсальный рендеринг
            renderPlanetBuilding(building, x, y, width, height, time, scale, planet);
        }
    }

    private void renderConstructionPhase(Building building, float x, float y, float width, float height,
                                         float time, boolean isCurrent, Planet planet) {
        float floorHeight = height / 3.0f;
        Color buildingColor = building.colors[building.colorThemeIndex];
        float scale = building.getSizeScale();

        // Фундамент с узором
        shapeRenderer.setColor(new Color(0.7f, 0.6f, 0.5f, 1));
        shapeRenderer.rect(x - 10 * scale, y - 20 * scale, width + 20 * scale, 20 * scale);

        // Узор на фундаменте
        shapeRenderer.setColor(new Color(0.8f, 0.7f, 0.6f, 1));
        for (int i = 0; i < 5; i++) {
            shapeRenderer.rect(x - 8 * scale + i * (width + 16 * scale) / 5,
                y - 18 * scale,
                (width + 16 * scale) / 5 - 4 * scale,
                16 * scale);
        }

        // Построенные этажи
        for (int floor = 0; floor < building.constructionProgress; floor++) {
            float floorY = y + floor * floorHeight;
            shapeRenderer.setColor(buildingColor);
            shapeRenderer.rect(x, floorY, width, floorHeight);

            // Окна на этажах
            shapeRenderer.setColor(new Color(0.9f, 0.95f, 1.0f, 0.8f));
            int windows = 3;
            float windowWidth = 25 * scale;
            float windowHeight = 35 * scale;
            float spacing = (width - windows * windowWidth) / (windows + 1);

            for (int i = 0; i < windows; i++) {
                shapeRenderer.rect(x + spacing * (i + 1) + windowWidth * i,
                    floorY + floorHeight/2 - windowHeight/2,
                    windowWidth, windowHeight);
            }
        }

        if (isCurrent && building.isOverlapping) {
            shapeRenderer.setColor(new Color(1, 0, 0, 0.3f));
            shapeRenderer.rect(x - 5, y - 5, width + 10, height + 10);
        }
    }

    // Универсальный рендеринг для зданий Марса и Венеры
    private void renderPlanetBuilding(Building building, float x, float y, float width, float height,
                                      float time, float scale, Planet planet) {
        Color buildingColor = building.colors[building.colorThemeIndex];
        Color detailColor = building.getDetailColor();

        // Основное здание
        shapeRenderer.setColor(buildingColor);
        shapeRenderer.rect(x, y, width, height);

        // Специальные элементы в зависимости от планеты
        switch (planet) {
            case MARS:
                renderMarsFeatures(building, x, y, width, height, time, scale);
                break;
            case VENUS:
                renderVenusFeatures(building, x, y, width, height, time, scale);
                break;
        }

        // Крыша
        shapeRenderer.setColor(building.roofColor);
        shapeRenderer.rect(x - 10 * scale, y + height, width + 20 * scale, 15 * scale);

        // Окна
        shapeRenderer.setColor(new Color(0.9f, 0.95f, 1.0f, 0.8f));
        int windows = 4;
        float windowWidth = 20 * scale;
        float windowHeight = 30 * scale;
        float spacing = (width - windows * windowWidth) / (windows + 1);

        for (int i = 0; i < windows; i++) {
            shapeRenderer.rect(x + spacing * (i + 1) + windowWidth * i,
                y + height/2 - windowHeight/2,
                windowWidth, windowHeight);
        }

        // Детали
        shapeRenderer.setColor(detailColor);
        shapeRenderer.rect(x + width/2 - 15 * scale, y, 30 * scale, 50 * scale); // Дверь
    }

    private void renderMarsFeatures(Building building, float x, float y, float width, float height,
                                    float time, float scale) {
        // Антенны для Марса
        shapeRenderer.setColor(Color.GRAY);
        shapeRenderer.rect(x + width/2 - 2, y + height, 4, 40 * scale);
        shapeRenderer.circle(x + width/2, y + height + 40 * scale, 8 * scale);

        // Солнечные панели
        shapeRenderer.setColor(new Color(0.2f, 0.3f, 0.4f, 1));
        shapeRenderer.rect(x - 30 * scale, y + height/2, 20 * scale, 40 * scale);

        // Мигающие огни
        float flash = (float)Math.sin(time * 8) > 0 ? 1 : 0.3f;
        shapeRenderer.setColor(new Color(1, flash, 0, 1));
        shapeRenderer.circle(x + 20 * scale, y + height - 10 * scale, 5 * scale);
        shapeRenderer.circle(x + width - 20 * scale, y + height - 10 * scale, 5 * scale);
    }

    private void renderVenusFeatures(Building building, float x, float y, float width, float height,
                                     float time, float scale) {
        // Кристаллы для Венеры
        for (int i = 0; i < 3; i++) {
            float crystalX = x + width/4 * (i + 1);
            float crystalHeight = 30 * scale + i * 10 * scale;

            shapeRenderer.setColor(new Color(1.0f, 0.9f, 0.6f, 0.8f));
            shapeRenderer.triangle(crystalX - 8 * scale, y + height,
                crystalX + 8 * scale, y + height,
                crystalX, y + height + crystalHeight);
        }

        // Тепловые выбросы
        for (int i = 0; i < 2; i++) {
            float heatX = x + (i == 0 ? 30 * scale : width - 30 * scale);
            float heatY = y + 20 * scale + (float)Math.sin(time * 3 + i) * 5 * scale;

            shapeRenderer.setColor(new Color(1.0f, 0.5f, 0.2f, 0.7f));
            shapeRenderer.circle(heatX, heatY, 10 * scale);
        }
    }

    // ==================== ✨ УЮТНЫЙ ДОМИК ✨ ====================
    private void renderCuteHouse(Building building, float x, float y, float width, float height, float time, float scale) {
        Color buildingColor = building.colors[building.colorThemeIndex];
        Color detailColor = building.getDetailColor();

        // Основное здание с закругленными углами
        shapeRenderer.setColor(buildingColor);
        shapeRenderer.rect(x + 10, y, width - 20, height * 0.8f);

        // Закругленные углы (круги по углам)
        shapeRenderer.circle(x + 10, y + height * 0.8f, 10);
        shapeRenderer.circle(x + width - 10, y + height * 0.8f, 10);
        shapeRenderer.circle(x + 10, y, 10);
        shapeRenderer.circle(x + width - 10, y, 10);

        // Мультяшная крыша
        shapeRenderer.setColor(building.roofColor);
        shapeRenderer.triangle(
            x - 15, y + height * 0.8f,
            x + width + 15, y + height * 0.8f,
            x + width/2, y + height + 50
        );

        // Узор на крыше
        shapeRenderer.setColor(detailColor);
        for (int i = 0; i < 5; i++) {
            float tileX = x + i * (width / 5);
            shapeRenderer.rect(tileX, y + height * 0.8f + 5, width/5 - 5, 10);
        }

        // Дымящаяся труба
        shapeRenderer.setColor(new Color(0.6f, 0.5f, 0.4f, 1));
        shapeRenderer.rect(x + width * 0.7f, y + height * 0.7f, 20, 45);

        // Анимированный дым
        for (int i = 0; i < 3; i++) {
            float smokeSize = 15 + i * 5;
            float smokeY = y + height * 0.7f + 50 + i * 20 + (float)Math.sin(time * 2 + i) * 5;
            float alpha = 0.7f - i * 0.2f;
            shapeRenderer.setColor(new Color(0.95f, 0.95f, 0.95f, alpha));
            shapeRenderer.circle(x + width * 0.7f + 10, smokeY, smokeSize);
        }

        // Окна с шторами
        renderHouseWindows(building, x, y, width, height, time, scale);

        // Дверь с деталями
        shapeRenderer.setColor(detailColor);
        shapeRenderer.rect(x + width/2 - 25, y, 50, 70);

        // Дверная ручка
        shapeRenderer.setColor(Color.YELLOW);
        shapeRenderer.circle(x + width/2 + 15, y + 35, 8);

        // Клумба с цветами
        shapeRenderer.setColor(new Color(0.3f, 0.7f, 0.3f, 1));
        shapeRenderer.rect(x - 15, y - 25, width + 30, 25);

        // Цветы в клумбе
        for (int i = 0; i < 6; i++) {
            float flowerX = x + 20 + i * 30;
            float flowerY = y - 10 + (float)Math.sin(time * 3 + i) * 5;

            shapeRenderer.setColor(Color.RED);
            shapeRenderer.circle(flowerX, flowerY, 8);
            shapeRenderer.setColor(Color.YELLOW);
            shapeRenderer.circle(flowerX, flowerY, 4);
        }
    }

    private void renderHouseWindows(Building building, float x, float y, float width, float height, float time, float scale) {
        Color detailColor = building.getDetailColor();

        // Левое окно
        shapeRenderer.setColor(new Color(0.8f, 0.9f, 1.0f, 0.9f));
        shapeRenderer.rect(x + width * 0.25f - 20, y + height * 0.4f, 40, 50);

        // Рама окна
        shapeRenderer.setColor(detailColor);
        shapeRenderer.rect(x + width * 0.25f - 20, y + height * 0.4f + 22, 40, 3);
        shapeRenderer.rect(x + width * 0.25f, y + height * 0.4f, 3, 50);

        // Шторы
        shapeRenderer.setColor(new Color(1.0f, 0.8f, 0.9f, 0.6f));
        shapeRenderer.rect(x + width * 0.25f - 15, y + height * 0.4f + 35, 30, 15);

        // Правое окно
        shapeRenderer.setColor(new Color(0.8f, 0.9f, 1.0f, 0.9f));
        shapeRenderer.rect(x + width * 0.75f - 20, y + height * 0.4f, 40, 50);

        shapeRenderer.setColor(detailColor);
        shapeRenderer.rect(x + width * 0.75f - 20, y + height * 0.4f + 22, 40, 3);
        shapeRenderer.rect(x + width * 0.75f, y + height * 0.4f, 3, 50);

        shapeRenderer.setColor(new Color(0.9f, 0.8f, 1.0f, 0.6f));
        shapeRenderer.rect(x + width * 0.75f - 15, y + height * 0.4f + 35, 30, 15);

        // Подоконник с цветами
        for (int i = 0; i < 2; i++) {
            float potX = x + width * (i == 0 ? 0.25f : 0.75f) - 5;
            shapeRenderer.setColor(new Color(0.8f, 0.6f, 0.4f, 1));
            shapeRenderer.rect(potX, y + height * 0.4f - 10, 10, 10);

            // Цветок
            float flowerY = y + height * 0.4f - 5 + (float)Math.sin(time * 4 + i) * 3;
            shapeRenderer.setColor(Color.YELLOW);
            shapeRenderer.circle(potX + 5, flowerY, 6);
        }
    }

    // ==================== 🏥 ДЕТСКАЯ БОЛЬНИЦА 🏥 ====================
    private void renderHospital(Building building, float x, float y, float width, float height, float time, float scale) {
        Color buildingColor = building.colors[building.colorThemeIndex];
        Color detailColor = building.getDetailColor();

        // Основное здание
        shapeRenderer.setColor(buildingColor);
        shapeRenderer.rect(x, y, width, height);

        // Яркие разноцветные полосы
        Color[] stripeColors = {
            new Color(1.0f, 0.5f, 0.5f, 1),  // Коралловый
            new Color(0.5f, 0.8f, 1.0f, 1),  // Голубой
            new Color(0.8f, 1.0f, 0.5f, 1)   // Лаймовый
        };

        for (int i = 0; i < 3; i++) {
            shapeRenderer.setColor(stripeColors[i]);
            shapeRenderer.rect(x, y + height * (0.2f + i * 0.25f), width, 15 * scale);
        }

        // Плоская крыша с ограждением
        shapeRenderer.setColor(building.roofColor);
        shapeRenderer.rect(x - 15 * scale, y + height, width + 30 * scale, 20 * scale);

        // Ограждение
        shapeRenderer.setColor(detailColor);
        for (int i = 0; i <= 8; i++) {
            float postX = x - 10 * scale + i * ((width + 20 * scale) / 8);
            shapeRenderer.rect(postX, y + height + 5 * scale, 6 * scale, 12 * scale);
        }

        // Большой красный крест
        shapeRenderer.setColor(Color.RED);
        shapeRenderer.rect(x + width/2 - 25 * scale, y + height - 20 * scale, 50 * scale, 10 * scale);
        shapeRenderer.rect(x + width/2 - 10 * scale, y + height - 50 * scale, 20 * scale, 40 * scale);

        // Весёлые окна с животными
        shapeRenderer.setColor(new Color(0.9f, 0.95f, 1.0f, 0.9f));
        int windows = 5;
        float windowWidth = 25 * scale;
        float windowHeight = 30 * scale;
        float spacing = (width - windows * windowWidth) / (windows + 1);

        for (int i = 0; i < windows; i++) {
            float windowX = x + spacing * (i + 1) + windowWidth * i;
            shapeRenderer.rect(windowX, y + 60 * scale, windowWidth, windowHeight);

            // Наклейки животных в окнах
            shapeRenderer.setColor(Color.YELLOW);
            if (i % 3 == 0) shapeRenderer.circle(windowX + windowWidth/2, y + 60 * scale + windowHeight/2, 8 * scale); // Солнышко
            else if (i % 3 == 1) {
                shapeRenderer.triangle(windowX + 5 * scale, y + 60 * scale + 5 * scale,
                    windowX + windowWidth - 5 * scale, y + 60 * scale + 5 * scale,
                    windowX + windowWidth/2, y + 60 * scale + windowHeight - 5 * scale); // Сердечко
            } else {
                shapeRenderer.rect(windowX + 5 * scale, y + 60 * scale + 5 * scale,
                    windowWidth - 10 * scale, windowHeight - 10 * scale); // Звездочка
            }
            shapeRenderer.setColor(new Color(0.9f, 0.95f, 1.0f, 0.9f));
        }

        // Вход с пандусом
        shapeRenderer.setColor(detailColor);
        shapeRenderer.rect(x + width/2 - 40 * scale, y, 80 * scale, 50 * scale);

        // Пандус
        shapeRenderer.setColor(new Color(0.8f, 0.8f, 0.8f, 1));
        shapeRenderer.rect(x + width/2 - 45 * scale, y - 20 * scale, 90 * scale, 20 * scale);

        // Машинка скорой помощи
        renderAmbulance(building, x, y, time, scale);
    }

    private void renderAmbulance(Building building, float x, float y, float time, float scale) {
        float ambulanceX = x - 70 * scale;
        float ambulanceY = y - 30 * scale;

        // Кузов
        shapeRenderer.setColor(Color.WHITE);
        shapeRenderer.rect(ambulanceX, ambulanceY, 65 * scale, 30 * scale);

        // Красная полоса
        shapeRenderer.setColor(Color.RED);
        shapeRenderer.rect(ambulanceX, ambulanceY + 25 * scale, 65 * scale, 5 * scale);

        // Мигающие фары
        float flash = (float)Math.sin(time * 10) > 0 ? 1 : 0.3f;
        shapeRenderer.setColor(new Color(1, 1, flash, 1));
        shapeRenderer.circle(ambulanceX + 10 * scale, ambulanceY + 15 * scale, 6 * scale);
        shapeRenderer.circle(ambulanceX + 25 * scale, ambulanceY + 15 * scale, 6 * scale);

        // Сирена
        shapeRenderer.setColor(new Color(flash, 0, 0, 1));
        shapeRenderer.circle(ambulanceX + 50 * scale, ambulanceY + 15 * scale, 8 * scale);

        // Колеса
        shapeRenderer.setColor(Color.BLACK);
        shapeRenderer.circle(ambulanceX + 15 * scale, ambulanceY - 5 * scale, 7 * scale);
        shapeRenderer.circle(ambulanceX + 45 * scale, ambulanceY - 5 * scale, 7 * scale);

        // Дверь
        shapeRenderer.setColor(Color.RED);
        shapeRenderer.rect(ambulanceX + 30 * scale, ambulanceY + 5 * scale, 20 * scale, 20 * scale);
    }

    // ==================== 🎒 ВЕСЁЛАЯ ШКОЛА 🎒 ====================
    private void renderSchool(Building building, float x, float y, float width, float height, float time, float scale) {
        Color buildingColor = building.colors[building.colorThemeIndex];
        Color detailColor = building.getDetailColor();

        // Основное здание
        shapeRenderer.setColor(buildingColor);
        shapeRenderer.rect(x, y, width, height * 0.9f);

        // Кирпичный узор
        shapeRenderer.setColor(new Color(0.8f, 0.6f, 0.5f, 0.3f));
        int bricksX = 8;
        int bricksY = 4;
        float brickWidth = width / bricksX;
        float brickHeight = (height * 0.9f) / bricksY;

        for (int i = 0; i < bricksX; i++) {
            for (int j = 0; j < bricksY; j++) {
                if ((i + j) % 2 == 0) {
                    shapeRenderer.rect(x + i * brickWidth + 2,
                        y + j * brickHeight + 2,
                        brickWidth - 4,
                        brickHeight - 4);
                }
            }
        }

        // Яркая крыша
        shapeRenderer.setColor(building.roofColor);
        shapeRenderer.rect(x - 20 * scale, y + height * 0.9f, width + 40 * scale, 30 * scale);

        // Флагшток с анимированным флагом
        shapeRenderer.setColor(new Color(0.5f, 0.4f, 0.3f, 1));
        shapeRenderer.rect(x + width * 0.85f, y + height * 0.9f, 8 * scale, 60 * scale);

        float flagWave = (float)Math.sin(time * 3) * 20;
        shapeRenderer.setColor(Color.WHITE);
        shapeRenderer.rect(x + width * 0.85f + 8 * scale,
            y + height * 0.9f + 40 * scale + flagWave,
            35 * scale, 20 * scale);
        shapeRenderer.setColor(new Color(0.3f, 0.6f, 1.0f, 1));
        shapeRenderer.rect(x + width * 0.85f + 8 * scale,
            y + height * 0.9f + 40 * scale + flagWave,
            35 * scale, 10 * scale);

        // Большие школьные окна
        shapeRenderer.setColor(new Color(0.9f, 0.95f, 1.0f, 0.9f));
        int windowRows = 3;
        int windowCols = 4;
        float windowWidth = 35 * scale;
        float windowHeight = 45 * scale;
        float hSpacing = (width - windowCols * windowWidth) / (windowCols + 1);
        float vSpacing = (height * 0.7f - windowRows * windowHeight) / (windowRows + 1);

        for (int row = 0; row < windowRows; row++) {
            for (int col = 0; col < windowCols; col++) {
                float windowX = x + hSpacing * (col + 1) + windowWidth * col;
                float windowY = y + vSpacing * (row + 1) + windowHeight * row + height * 0.1f;
                shapeRenderer.rect(windowX, windowY, windowWidth, windowHeight);

                // Переплеты окон
                shapeRenderer.setColor(new Color(0.4f, 0.3f, 0.2f, 1));
                shapeRenderer.rect(windowX, windowY + windowHeight/2 - 2, windowWidth, 4);
                shapeRenderer.rect(windowX + windowWidth/2 - 2, windowY, 4, windowHeight);
                shapeRenderer.setColor(new Color(0.9f, 0.95f, 1.0f, 0.9f));
            }
        }

        // Вход с колоннами
        shapeRenderer.setColor(detailColor);
        shapeRenderer.rect(x + width/2 - 40 * scale, y, 80 * scale, 70 * scale);

        // Колонны
        shapeRenderer.setColor(new Color(0.7f, 0.6f, 0.5f, 1));
        shapeRenderer.rect(x + width/2 - 35 * scale, y, 12 * scale, 70 * scale);
        shapeRenderer.rect(x + width/2 + 23 * scale, y, 12 * scale, 70 * scale);

        // Доска объявлений
        shapeRenderer.setColor(Color.WHITE);
        shapeRenderer.rect(x + width + 20 * scale, y + 40 * scale, 50 * scale, 70 * scale);
        shapeRenderer.setColor(Color.BLACK);
        shapeRenderer.rect(x + width + 22 * scale, y + 42 * scale, 46 * scale, 66 * scale);

        // Надпись на доске
        shapeRenderer.setColor(Color.YELLOW);
        for (int i = 0; i < 3; i++) {
            shapeRenderer.rect(x + width + 30 * scale,
                y + 50 * scale + i * 15 * scale,
                30 * scale, 5 * scale);
        }

        // Игровая площадка рядом
        renderSchoolPlayground(building, x, y, width, height, time, scale);
    }

    private void renderSchoolPlayground(Building building, float x, float y, float width, float height, float time, float scale) {
        float playgroundX = x + width + 10 * scale;
        float playgroundY = y;

        // Площадка
        shapeRenderer.setColor(new Color(0.6f, 0.8f, 0.4f, 1));
        shapeRenderer.rect(playgroundX, playgroundY, 60 * scale, 40 * scale);

        // Качели
        float swingOffset = (float)Math.sin(time * 4) * 15 * scale;
        shapeRenderer.setColor(new Color(0.8f, 0.5f, 0.2f, 1));
        shapeRenderer.rect(playgroundX + 20 * scale, playgroundY, 5 * scale, 25 * scale);
        shapeRenderer.rect(playgroundX + 10 * scale, playgroundY + 25 * scale, 25 * scale, 5 * scale);

        shapeRenderer.setColor(Color.YELLOW);
        shapeRenderer.rect(playgroundX + 18 * scale, playgroundY + swingOffset, 10 * scale, 5 * scale);

        // Баскетбольное кольцо
        shapeRenderer.setColor(Color.ORANGE);
        shapeRenderer.rect(playgroundX + 45 * scale, playgroundY + 30 * scale, 4 * scale, 15 * scale);
        shapeRenderer.circle(playgroundX + 47 * scale, playgroundY + 45 * scale, 12 * scale);
    }

    // ==================== 🎪 ИГРОВАЯ ПЛОЩАДКА 🎪 ====================
    private void renderPlayground(Building building, float x, float y, float width, float height, float time, float scale) {
        Color buildingColor = building.colors[building.colorThemeIndex];
        Color detailColor = building.getDetailColor();

        // Трава
        shapeRenderer.setColor(new Color(0.4f, 0.8f, 0.4f, 1));
        shapeRenderer.rect(x, y, width, height * 0.6f);

        // Песочница
        shapeRenderer.setColor(new Color(0.95f, 0.85f, 0.6f, 1));
        shapeRenderer.rect(x + 30 * scale, y + 20 * scale, 60 * scale, 50 * scale);

        // Бортик песочницы
        shapeRenderer.setColor(new Color(0.8f, 0.6f, 0.4f, 1));
        shapeRenderer.rect(x + 28 * scale, y + 18 * scale, 64 * scale, 4 * scale);
        shapeRenderer.rect(x + 28 * scale, y + 70 * scale, 64 * scale, 4 * scale);
        shapeRenderer.rect(x + 28 * scale, y + 18 * scale, 4 * scale, 56 * scale);
        shapeRenderer.rect(x + 88 * scale, y + 18 * scale, 4 * scale, 56 * scale);

        // Замок из песка
        shapeRenderer.setColor(new Color(0.9f, 0.8f, 0.7f, 1));
        shapeRenderer.rect(x + 50 * scale, y + 40 * scale, 20 * scale, 15 * scale);
        shapeRenderer.triangle(x + 50 * scale, y + 55 * scale,
            x + 70 * scale, y + 55 * scale,
            x + 60 * scale, y + 65 * scale);

        // Качели
        float swingOffset = (float)Math.sin(time * 3) * 20 * scale;
        shapeRenderer.setColor(new Color(0.8f, 0.5f, 0.2f, 1));
        // Стойки
        shapeRenderer.rect(x + width - 50 * scale, y + 10 * scale, 6 * scale, 30 * scale);
        shapeRenderer.rect(x + width - 80 * scale, y + 10 * scale, 6 * scale, 30 * scale);
        // Перекладина
        shapeRenderer.rect(x + width - 82 * scale, y + 40 * scale, 40 * scale, 6 * scale);
        // Сиденье
        shapeRenderer.setColor(Color.RED);
        shapeRenderer.rect(x + width - 65 * scale, y + 10 * scale + swingOffset, 20 * scale, 5 * scale);
        // Цепи
        shapeRenderer.setColor(Color.GRAY);
        shapeRenderer.rectLine(x + width - 75 * scale, y + 40 * scale,
            x + width - 60 * scale, y + 15 * scale + swingOffset,
            3 * scale);
        shapeRenderer.rectLine(x + width - 55 * scale, y + 40 * scale,
            x + width - 50 * scale, y + 15 * scale + swingOffset,
            3 * scale);

        // Горка
        shapeRenderer.setColor(new Color(1.0f, 0.7f, 0.3f, 1));
        shapeRenderer.triangle(x + 10 * scale, y + 10 * scale,
            x + 50 * scale, y + 60 * scale,
            x + 90 * scale, y + 10 * scale);

        // Ступеньки горки
        shapeRenderer.setColor(new Color(0.7f, 0.5f, 0.3f, 1));
        for (int i = 0; i < 5; i++) {
            shapeRenderer.rect(x + 15 * scale + i * 7 * scale,
                y + 10 * scale + i * 5 * scale,
                5 * scale, 3 * scale);
        }

        // Карусель
        float carouselAngle = time * 50;
        shapeRenderer.setColor(Color.RED);
        shapeRenderer.circle(x + width/2, y + 40 * scale, 25 * scale);

        shapeRenderer.setColor(Color.YELLOW);
        for (int i = 0; i < 4; i++) {
            float angle = carouselAngle + i * 90;
            float seatX = x + width/2 + (float)Math.cos(Math.toRadians(angle)) * 18 * scale;
            float seatY = y + 40 * scale + (float)Math.sin(Math.toRadians(angle)) * 18 * scale;
            shapeRenderer.circle(seatX, seatY, 8 * scale);
        }

        // Деревья
        for (int i = 0; i < 2; i++) {
            float treeX = x + (i == 0 ? 10 * scale : width - 30 * scale);
            shapeRenderer.setColor(new Color(0.5f, 0.3f, 0.2f, 1));
            shapeRenderer.rect(treeX, y - 25 * scale, 8 * scale, 25 * scale);
            shapeRenderer.setColor(new Color(0.3f, 0.7f, 0.3f, 1));
            shapeRenderer.circle(treeX + 4 * scale, y, 15 * scale);
            shapeRenderer.circle(treeX - 6 * scale, y - 5 * scale, 12 * scale);
            shapeRenderer.circle(treeX + 14 * scale, y - 5 * scale, 12 * scale);
        }

        // Воздушные шарики
        Color[] balloonColors = {Color.RED, Color.BLUE, Color.YELLOW, Color.GREEN, Color.PINK};
        for (int i = 0; i < 5; i++) {
            float balloonX = x + 20 * scale + i * 25 * scale;
            float balloonY = y + height * 0.6f + 30 * scale + (float)Math.sin(time * 2 + i) * 10 * scale;

            shapeRenderer.setColor(balloonColors[i]);
            shapeRenderer.circle(balloonX, balloonY, 12 * scale);
            shapeRenderer.setColor(Color.BLACK);
            shapeRenderer.rectLine(balloonX, balloonY - 12 * scale,
                balloonX, balloonY - 25 * scale,
                2 * scale);
        }
    }

    // ==================== 💰 НАДЁЖНЫЙ БАНК 💰 ====================
    private void renderBank(Building building, float x, float y, float width, float height, float time, float scale) {
        Color buildingColor = building.colors[building.colorThemeIndex];
        Color detailColor = building.getDetailColor();

        // Основное здание
        shapeRenderer.setColor(buildingColor);
        shapeRenderer.rect(x, y, width, height);

        // Колонны
        shapeRenderer.setColor(new Color(0.9f, 0.85f, 0.75f, 1));
        int columns = 6;
        float columnWidth = 10 * scale;
        float spacing = (width - columns * columnWidth) / (columns + 1);

        for (int i = 0; i < columns; i++) {
            float colX = x + spacing * (i + 1) + columnWidth * i;
            shapeRenderer.rect(colX, y, columnWidth, height * 0.8f);

            // Капители колонн
            shapeRenderer.setColor(new Color(1.0f, 0.9f, 0.5f, 1));
            shapeRenderer.rect(colX - 2 * scale, y + height * 0.8f, columnWidth + 4 * scale, 8 * scale);
            shapeRenderer.setColor(new Color(0.9f, 0.85f, 0.75f, 1));
        }

        // Крыша с фронтоном
        shapeRenderer.setColor(building.roofColor);
        shapeRenderer.triangle(
            x - 25 * scale, y + height * 0.8f,
            x + width + 25 * scale, y + height * 0.8f,
            x + width/2, y + height + 60 * scale
        );

        // Золотая надпись "БАНК"
        shapeRenderer.setColor(Color.GOLD);
        for (int i = 0; i < 4; i++) {
            shapeRenderer.rect(x + width/2 - 60 * scale + i * 40 * scale,
                y + height * 0.85f,
                30 * scale, 8 * scale);
        }

        // Большие часы на фасаде
        shapeRenderer.setColor(Color.BLACK);
        shapeRenderer.circle(x + width/2, y + height * 0.5f, 40 * scale);
        shapeRenderer.setColor(Color.WHITE);
        shapeRenderer.circle(x + width/2, y + height * 0.5f, 38 * scale);

        // Стрелки часов
        float hourAngle = time * 30;
        float minuteAngle = time * 360;

        shapeRenderer.setColor(Color.BLACK);
        shapeRenderer.rectLine(x + width/2, y + height * 0.5f,
            x + width/2 + (float)Math.cos(Math.toRadians(hourAngle - 90)) * 20 * scale,
            y + height * 0.5f + (float)Math.sin(Math.toRadians(hourAngle - 90)) * 20 * scale,
            4 * scale);
        shapeRenderer.rectLine(x + width/2, y + height * 0.5f,
            x + width/2 + (float)Math.cos(Math.toRadians(minuteAngle - 90)) * 30 * scale,
            y + height * 0.5f + (float)Math.sin(Math.toRadians(minuteAngle - 90)) * 30 * scale,
            2 * scale);

        // Массивная дверь
        shapeRenderer.setColor(new Color(0.5f, 0.4f, 0.3f, 1));
        float doorWidth = width * 0.3f;
        shapeRenderer.rect(x + width/2 - doorWidth/2, y, doorWidth, 80 * scale);

        // Золотые детали двери
        shapeRenderer.setColor(Color.GOLD);
        // Ручки
        shapeRenderer.circle(x + width/2 - doorWidth/4, y + 40 * scale, 10 * scale);
        shapeRenderer.circle(x + width/2 + doorWidth/4, y + 40 * scale, 10 * scale);
        // Замок
        shapeRenderer.rect(x + width/2 - 5 * scale, y + 20 * scale, 10 * scale, 15 * scale);

        // Охранник
        renderBankSecurity(building, x, y, width, height, time, scale);

        // Банкомат
        shapeRenderer.setColor(Color.GRAY);
        shapeRenderer.rect(x + width + 20 * scale, y + 30 * scale, 40 * scale, 60 * scale);
        shapeRenderer.setColor(Color.BLUE);
        shapeRenderer.rect(x + width + 25 * scale, y + 40 * scale, 30 * scale, 20 * scale);
        shapeRenderer.setColor(Color.GREEN);
        shapeRenderer.circle(x + width + 40 * scale, y + 70 * scale, 8 * scale);
    }

    private void renderBankSecurity(Building building, float x, float y, float width, float height, float time, float scale) {
        float guardX = x - 50 * scale;
        float guardY = y + 20 * scale;

        // Тело
        shapeRenderer.setColor(Color.DARK_GRAY);
        shapeRenderer.rect(guardX - 10 * scale, guardY, 20 * scale, 45 * scale);

        // Голова
        shapeRenderer.setColor(new Color(0.95f, 0.8f, 0.6f, 1));
        shapeRenderer.circle(guardX, guardY + 50 * scale, 15 * scale);

        // Форма
        shapeRenderer.setColor(Color.NAVY);
        shapeRenderer.rect(guardX - 8 * scale, guardY + 15 * scale, 16 * scale, 25 * scale);

        // Шлем
        shapeRenderer.setColor(Color.BLACK);
        shapeRenderer.rect(guardX - 12 * scale, guardY + 45 * scale, 24 * scale, 8 * scale);

        // Рация
        shapeRenderer.setColor(Color.GRAY);
        shapeRenderer.rect(guardX + 12 * scale, guardY + 25 * scale, 10 * scale, 20 * scale);

        // Собака охраны
        float dogX = guardX + 30 * scale;
        float dogY = guardY;

        shapeRenderer.setColor(new Color(0.4f, 0.3f, 0.2f, 1));
        // Тело
        shapeRenderer.rect(dogX - 8 * scale, dogY, 16 * scale, 12 * scale);
        // Голова
        shapeRenderer.circle(dogX, dogY + 15 * scale, 8 * scale);
        // Уши
        shapeRenderer.triangle(dogX - 5 * scale, dogY + 20 * scale,
            dogX - 10 * scale, dogY + 30 * scale,
            dogX, dogY + 20 * scale);
        shapeRenderer.triangle(dogX + 5 * scale, dogY + 20 * scale,
            dogX + 10 * scale, dogY + 30 * scale,
            dogX, dogY + 20 * scale);
        // Хвост
        shapeRenderer.rectLine(dogX + 8 * scale, dogY + 6 * scale,
            dogX + 20 * scale, dogY + (float)Math.sin(time * 5) * 10 * scale,
            3 * scale);
    }

    // ==================== 💊 ЗДОРОВАЯ АПТЕКА 💊 ====================
    private void renderPharmacy(Building building, float x, float y, float width, float height, float time, float scale) {
        Color buildingColor = building.colors[building.colorThemeIndex];
        Color detailColor = building.getDetailColor();

        // Основное здание
        shapeRenderer.setColor(buildingColor);
        shapeRenderer.rect(x, y, width, height * 0.9f);

        // Зелёная крыша
        shapeRenderer.setColor(building.roofColor);
        shapeRenderer.rect(x - 10 * scale, y + height * 0.9f, width + 20 * scale, 20 * scale);

        // Большой зелёный крест
        shapeRenderer.setColor(new Color(0.2f, 0.8f, 0.2f, 1));
        shapeRenderer.rect(x + width/2 - 30 * scale, y + height * 0.7f, 60 * scale, 12 * scale);
        shapeRenderer.rect(x + width/2 - 12 * scale, y + height * 0.6f, 24 * scale, 40 * scale);

        // Неоновая вывеска
        float neon = 0.5f + 0.5f * (float)Math.sin(time * 8);
        shapeRenderer.setColor(new Color(0, neon, 0, 1));
        shapeRenderer.rect(x + width/2 - 40 * scale, y + height * 0.85f, 80 * scale, 8 * scale);

        // Большая витрина
        shapeRenderer.setColor(new Color(0.95f, 0.98f, 1.0f, 0.9f));
        shapeRenderer.rect(x + 20 * scale, y + 30 * scale, width - 40 * scale, 60 * scale);

        // Полки с лекарствами
        shapeRenderer.setColor(new Color(0.8f, 0.7f, 0.6f, 1));
        for (int i = 0; i < 4; i++) {
            shapeRenderer.rect(x + 25 * scale, y + 35 * scale + i * 15 * scale, width - 50 * scale, 5 * scale);
        }

        // Лекарства на полках
        renderMedicines(building, x, y, width, height, time, scale);

        // Вход
        shapeRenderer.setColor(detailColor);
        shapeRenderer.rect(x + width/2 - 25 * scale, y, 50 * scale, 50 * scale);

        // Автоматические двери
        shapeRenderer.setColor(new Color(0.9f, 0.95f, 1.0f, 0.7f));
        float doorOpen = (float)Math.sin(time * 5) * 0.5f + 0.5f;
        shapeRenderer.rect(x + width/2 - 22 * scale, y, 20 * scale * doorOpen, 45 * scale);
        shapeRenderer.rect(x + width/2 + 2 * scale, y, 20 * scale * doorOpen, 45 * scale);

        // Витрина с витаминами
        shapeRenderer.setColor(new Color(1.0f, 0.95f, 0.9f, 1));
        shapeRenderer.rect(x - 60 * scale, y + 40 * scale, 50 * scale, 70 * scale);

        // Витамины
        Color[] vitaminColors = {Color.ORANGE, Color.YELLOW, Color.RED, Color.GREEN, Color.PURPLE};
        for (int i = 0; i < 5; i++) {
            shapeRenderer.setColor(vitaminColors[i]);
            shapeRenderer.circle(x - 40 * scale + i % 3 * 15 * scale,
                y + 60 * scale + (i / 3) * 20 * scale,
                8 * scale);
        }

        // Гирлянда
        for (int i = 0; i < 8; i++) {
            float lightX = x + i * (width / 7);
            float brightness = 0.5f + 0.5f * (float)Math.sin(time * 4 + i);
            shapeRenderer.setColor(new Color(brightness, 1, brightness, 1));
            shapeRenderer.circle(lightX, y + height * 0.95f, 6 * scale);
        }
    }

    private void renderMedicines(Building building, float x, float y, float width, float height, float time, float scale) {
        // Разноцветные лекарства
        Color[] medicineColors = {
            Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW,
            new Color(1, 0.5f, 0, 1), new Color(0.5f, 0, 1, 1)
        };

        // Бутылочки
        for (int row = 0; row < 3; row++) {
            for (int col = 0; col < 5; col++) {
                float medX = x + 30 * scale + col * 25 * scale;
                float medY = y + 40 * scale + row * 20 * scale;
                int colorIndex = (row * 5 + col) % medicineColors.length;

                shapeRenderer.setColor(medicineColors[colorIndex]);
                // Бутылочка
                shapeRenderer.rect(medX, medY, 15 * scale, 25 * scale);
                // Горлышко
                shapeRenderer.rect(medX + 5 * scale, medY + 25 * scale, 5 * scale, 5 * scale);
                // Крышечка
                shapeRenderer.setColor(Color.WHITE);
                shapeRenderer.rect(medX + 5 * scale, medY + 30 * scale, 5 * scale, 3 * scale);
            }
        }

        // Таблетки
        for (int i = 0; i < 10; i++) {
            float pillX = x + 35 * scale + (i % 5) * 30 * scale;
            float pillY = y + 110 * scale + (i / 5) * 15 * scale;

            if (i % 2 == 0) {
                shapeRenderer.setColor(Color.WHITE);
                shapeRenderer.circle(pillX, pillY, 6 * scale);
                shapeRenderer.setColor(Color.RED);
                shapeRenderer.circle(pillX, pillY, 4 * scale);
            } else {
                shapeRenderer.setColor(Color.WHITE);
                shapeRenderer.rect(pillX - 8 * scale, pillY - 4 * scale, 16 * scale, 8 * scale);
                shapeRenderer.setColor(Color.BLUE);
                shapeRenderer.rect(pillX - 6 * scale, pillY - 3 * scale, 12 * scale, 6 * scale);
            }
        }
    }

    // ==================== 🎭 ВОЛШЕБНЫЙ ТЕАТР 🎭 ====================
    private void renderTheater(Building building, float x, float y, float width, float height, float time, float scale) {
        Color buildingColor = building.colors[building.colorThemeIndex];
        Color detailColor = building.getDetailColor();

        // Основное здание
        shapeRenderer.setColor(buildingColor);
        shapeRenderer.rect(x, y, width, height * 0.8f);

        // Величественный портик с колоннами
        shapeRenderer.setColor(new Color(0.95f, 0.9f, 0.8f, 1));
        shapeRenderer.rect(x - 30 * scale, y, width + 60 * scale, 100 * scale);

        // Большие колонны
        shapeRenderer.setColor(new Color(0.9f, 0.85f, 0.75f, 1));
        int columns = 8;
        float columnWidth = 12 * scale;
        float columnSpacing = (width + 60 * scale - columns * columnWidth) / (columns + 1);

        for (int i = 0; i < columns; i++) {
            float colX = x - 30 * scale + columnSpacing * (i + 1) + columnWidth * i;
            shapeRenderer.rect(colX, y, columnWidth, 90 * scale);

            // Капители
            shapeRenderer.setColor(new Color(1.0f, 0.9f, 0.7f, 1));
            shapeRenderer.rect(colX - 3 * scale, y + 90 * scale, columnWidth + 6 * scale, 10 * scale);
            shapeRenderer.setColor(new Color(0.9f, 0.85f, 0.75f, 1));
        }

        // Фронтон
        shapeRenderer.setColor(building.roofColor);
        shapeRenderer.triangle(
            x - 40 * scale, y + 100 * scale,
            x + width + 40 * scale, y + 100 * scale,
            x + width/2, y + 150 * scale
        );

        // Театральные маски на фронтоне
        shapeRenderer.setColor(Color.GOLD);
        // Комедия
        float smileMaskX = x + width/2 - 40 * scale;
        shapeRenderer.circle(smileMaskX, y + 120 * scale, 25 * scale);
        shapeRenderer.setColor(Color.BLACK);
        // Глаза
        shapeRenderer.circle(smileMaskX - 10 * scale, y + 125 * scale, 6 * scale);
        shapeRenderer.circle(smileMaskX + 10 * scale, y + 125 * scale, 6 * scale);
        // Улыбка
        shapeRenderer.arc(smileMaskX, y + 115 * scale, 15 * scale, 0, 180, 20);

        // Трагедия
        float sadMaskX = x + width/2 + 40 * scale;
        shapeRenderer.setColor(Color.GOLD);
        shapeRenderer.circle(sadMaskX, y + 120 * scale, 25 * scale);
        shapeRenderer.setColor(Color.BLACK);
        // Глазы
        shapeRenderer.circle(sadMaskX - 10 * scale, y + 125 * scale, 6 * scale);
        shapeRenderer.circle(sadMaskX + 10 * scale, y + 125 * scale, 6 * scale);
        // Грустный рот
        shapeRenderer.arc(sadMaskX, y + 135 * scale, 15 * scale, 180, 180, 20);

        // Красная ковровая дорожка
        shapeRenderer.setColor(Color.RED);
        shapeRenderer.rect(x + width/2 - 50 * scale, y - 30 * scale, 100 * scale, 30 * scale);

        // Золотые звёзды на дорожке
        shapeRenderer.setColor(Color.GOLD);
        for (int i = 0; i < 5; i++) {
            float starX = x + width/2 - 40 * scale + i * 20 * scale;
            shapeRenderer.circle(starX, y - 15 * scale, 8 * scale);
        }

        // Билборд с афишей
        shapeRenderer.setColor(new Color(0.2f, 0.1f, 0.3f, 1));
        shapeRenderer.rect(x - 100 * scale, y + 50 * scale, 80 * scale, 120 * scale);

        // Афиша
        shapeRenderer.setColor(Color.WHITE);
        shapeRenderer.rect(x - 96 * scale, y + 54 * scale, 72 * scale, 112 * scale);

        // Изображение на афише
        shapeRenderer.setColor(Color.RED);
        shapeRenderer.rect(x - 90 * scale, y + 60 * scale, 60 * scale, 40 * scale); // Занавес
        shapeRenderer.setColor(Color.GOLD);
        shapeRenderer.circle(x - 60 * scale, y + 120 * scale, 15 * scale); // Маска
        shapeRenderer.setColor(new Color(0.3f, 0.2f, 0.1f, 1));
        for (int i = 0; i < 3; i++) {
            shapeRenderer.rect(x - 85 * scale, y + 110 * scale + i * 15 * scale, 50 * scale, 5 * scale); // Текст
        }

        // Освещение
        for (int i = 0; i < 4; i++) {
            float spotX = x + i * (width / 3);
            float spotBrightness = 0.7f + 0.3f * (float)Math.sin(time * 3 + i);
            shapeRenderer.setColor(new Color(1, 1, spotBrightness, 0.8f));
            shapeRenderer.triangle(spotX - 15 * scale, y + 100 * scale,
                spotX + 15 * scale, y + 100 * scale,
                spotX, y + 130 * scale);
        }

        // Входные двери
        shapeRenderer.setColor(new Color(0.6f, 0.5f, 0.4f, 1));
        shapeRenderer.rect(x + width/2 - 40 * scale, y, 35 * scale, 70 * scale);
        shapeRenderer.rect(x + width/2 + 5 * scale, y, 35 * scale, 70 * scale);

        // Золотые ручки
        shapeRenderer.setColor(Color.GOLD);
        shapeRenderer.circle(x + width/2 - 25 * scale, y + 35 * scale, 8 * scale);
        shapeRenderer.circle(x + width/2 + 25 * scale, y + 35 * scale, 8 * scale);

        // Очередь (анимированная)
        for (int i = 0; i < 5; i++) {
            float personX = x + width + 20 * scale + i * 20 * scale;
            float personY = y + 20 * scale + (float)Math.sin(time * 2 + i) * 5 * scale;

            shapeRenderer.setColor(detailColor);
            shapeRenderer.rect(personX - 5 * scale, personY, 10 * scale, 20 * scale);
            shapeRenderer.setColor(new Color(0.95f, 0.8f, 0.6f, 1));
            shapeRenderer.circle(personX, personY + 25 * scale, 8 * scale);
        }
    }

    // ==================== 🎬 КИНОМИР 🎬 ====================
    private void renderCinema(Building building, float x, float y, float width, float height, float time, float scale) {
        Color buildingColor = building.colors[building.colorThemeIndex];
        Color detailColor = building.getDetailColor();

        // Основное здание
        shapeRenderer.setColor(buildingColor);
        shapeRenderer.rect(x, y, width, height * 0.7f);

        // Гигантский экран
        shapeRenderer.setColor(Color.BLACK);
        shapeRenderer.rect(x + 20 * scale, y + height * 0.7f - 100 * scale, width - 40 * scale, 80 * scale);

        // Анимированное кино на экране
        float movieTime = time * 5;
        Color[] movieColors = {Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW, Color.MAGENTA};

        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 4; j++) {
                float cellX = x + 30 * scale + i * 30 * scale;
                float cellY = y + height * 0.7f - 90 * scale + j * 20 * scale;
                int colorIndex = ((int)(movieTime) + i + j) % movieColors.length;
                float brightness = 0.3f + 0.7f * (float)Math.abs(Math.sin(movieTime + i * 0.3f + j * 0.2f));

                Color cellColor = movieColors[colorIndex];
                shapeRenderer.setColor(new Color(
                    cellColor.r * brightness,
                    cellColor.g * brightness,
                    cellColor.b * brightness,
                    1
                ));
                shapeRenderer.rect(cellX, cellY, 25 * scale, 15 * scale);
            }
        }

        // Неоновая вывеска "КИНО"
        shapeRenderer.setColor(building.roofColor);
        shapeRenderer.rect(x - 20 * scale, y + height * 0.7f, width + 40 * scale, 35 * scale);

        // Мигающие неоновые буквы
        for (int i = 0; i < 4; i++) {
            float letterX = x + 40 * scale + i * 60 * scale;
            float neonFlash = (float)Math.sin(time * 8 + i * 2) > 0 ? 1 : 0.3f;

            shapeRenderer.setColor(new Color(1, neonFlash, neonFlash, 1));
            shapeRenderer.rect(letterX, y + height * 0.7f + 10 * scale, 40 * scale, 20 * scale);
        }

        // Билборд с новинками
        shapeRenderer.setColor(new Color(0.4f, 0.2f, 0.6f, 1));
        shapeRenderer.rect(x - 120 * scale, y + 60 * scale, 100 * scale, 150 * scale);

        // Постеры на билборде
        shapeRenderer.setColor(Color.RED);
        shapeRenderer.rect(x - 115 * scale, y + 65 * scale, 90 * scale, 60 * scale);
        shapeRenderer.setColor(Color.YELLOW);
        shapeRenderer.rect(x - 115 * scale, y + 130 * scale, 90 * scale, 60 * scale);

        // Звёзды на постерах
        shapeRenderer.setColor(Color.WHITE);
        for (int i = 0; i < 5; i++) {
            float starX = x - 100 * scale + i * 20 * scale;
            shapeRenderer.circle(starX, y + 75 * scale, 4 * scale);
            shapeRenderer.circle(starX, y + 145 * scale, 4 * scale);
        }

        // Входная группа с билетными кассами
        shapeRenderer.setColor(new Color(0.3f, 0.3f, 0.4f, 1));
        shapeRenderer.rect(x + width/2 - 60 * scale, y, 120 * scale, 60 * scale);

        // Окошки касс
        shapeRenderer.setColor(new Color(0.9f, 0.95f, 1.0f, 0.9f));
        shapeRenderer.rect(x + width/2 - 50 * scale, y + 10 * scale, 40 * scale, 25 * scale);
        shapeRenderer.rect(x + width/2 + 10 * scale, y + 10 * scale, 40 * scale, 25 * scale);

        // Попкорн-машина
        shapeRenderer.setColor(Color.RED);
        shapeRenderer.rect(x - 80 * scale, y, 60 * scale, 80 * scale);
        shapeRenderer.setColor(Color.YELLOW);
        // Попкорн
        for (int i = 0; i < 20; i++) {
            float popcornX = x - 60 * scale + (building.random.nextFloat() - 0.5f) * 40 * scale;
            float popcornY = y + 30 * scale + (building.random.nextFloat() - 0.5f) * 40 * scale;
            float popcornSize = 3 * scale + building.random.nextFloat() * 4 * scale;

            shapeRenderer.setColor(new Color(1, 1, building.random.nextFloat() * 0.3f, 1));
            shapeRenderer.circle(popcornX, popcornY, popcornSize);
        }

        // Стаканчик с попкорном
        shapeRenderer.setColor(Color.RED);
        shapeRenderer.rect(x - 65 * scale, y + 85 * scale, 30 * scale, 40 * scale);
        shapeRenderer.setColor(Color.YELLOW);
        shapeRenderer.rect(x - 62 * scale, y + 88 * scale, 24 * scale, 34 * scale);

        // Напитки
        shapeRenderer.setColor(new Color(0, 0.5f, 1, 1));
        shapeRenderer.rect(x - 40 * scale, y, 25 * scale, 60 * scale);
        shapeRenderer.setColor(new Color(1, 0.5f, 0, 1));
        shapeRenderer.rect(x - 10 * scale, y, 25 * scale, 60 * scale);

        // Очередь в кино
        renderCinemaQueue(building, x, y, width, height, time, scale);

        // Проекционные лучи
        shapeRenderer.setColor(new Color(1, 1, 1, 0.3f));
        shapeRenderer.rectLine(x + width/2, y + height * 0.7f + 35 * scale,
            x + width/2, y + height * 0.7f - 20 * scale,
            10 * scale);
    }

    private void renderCinemaQueue(Building building, float x, float y, float width, float height, float time, float scale) {
        // Люди в очереди
        Color[] peopleColors = {
            new Color(1, 0.6f, 0.6f, 1),    // Розовый
            new Color(0.6f, 0.8f, 1, 1),    // Голубой
            new Color(0.8f, 1, 0.6f, 1),    // Лаймовый
            new Color(1, 1, 0.6f, 1),       // Жёлтый
            new Color(1, 0.8f, 1, 1)        // Сиреневый
        };

        for (int i = 0; i < 6; i++) {
            float personX = x + width + 20 * scale + i * 18 * scale;
            float personY = y + 30 * scale + (float)Math.sin(time * 2 + i) * 8 * scale;

            // Тело
            shapeRenderer.setColor(peopleColors[i % peopleColors.length]);
            shapeRenderer.rect(personX - 6 * scale, personY, 12 * scale, 25 * scale);

            // Голова
            shapeRenderer.setColor(new Color(0.95f, 0.8f, 0.6f, 1));
            shapeRenderer.circle(personX, personY + 30 * scale, 10 * scale);

            // Глазы
            shapeRenderer.setColor(Color.BLACK);
            shapeRenderer.circle(personX - 4 * scale, personY + 32 * scale, 2 * scale);
            shapeRenderer.circle(personX + 4 * scale, personY + 32 * scale, 2 * scale);

            // Рот
            shapeRenderer.rect(personX - 3 * scale, personY + 28 * scale, 6 * scale, 1 * scale);

            // Попкорн в руках (у каждого второго)
            if (i % 2 == 0) {
                shapeRenderer.setColor(Color.YELLOW);
                shapeRenderer.circle(personX + 8 * scale, personY + 20 * scale, 8 * scale);
            }
        }
    }

    private void renderBuildingDetails(Array<Building> buildings, Building currentBuilding, float time) {
        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);

        // Добавляем детали ко всем зданиям
        for (Building building : buildings) {
            if (building.isComplete()) {
                addSparkles(building, time);
            }
        }

        if (currentBuilding != null && currentBuilding.isComplete()) {
            addSparkles(currentBuilding, time);
        }

        shapeRenderer.end();
    }

    private void addSparkles(Building building, float time) {
        float x = building.x;
        float y = building.y;
        float width = building.width;
        float height = building.height;
        float scale = building.getSizeScale();

        // Блестки вокруг здания
        shapeRenderer.setColor(Color.YELLOW);
        for (int i = 0; i < 5; i++) {
            float sparkleX = x + (float)Math.sin(time * 3 + i) * width * 0.5f + width * 0.5f;
            float sparkleY = y + height + 20 + (float)Math.cos(time * 2 + i) * 10;
            float sparkleSize = 3 + (float)Math.sin(time * 4 + i) * 2;

            shapeRenderer.circle(sparkleX, sparkleY, sparkleSize);
        }

        // Сияние вокруг названия (если показывается)
        if (building.showName) {
            float nameX = building.x + building.width/2;
            float nameY = building.y + building.getCurrentHeight() + 80;
            float glowSize = 60 * scale + (float)Math.sin(time * 3) * 10;

            shapeRenderer.setColor(new Color(1, 1, 0.5f, 0.3f));
            shapeRenderer.circle(nameX, nameY, glowSize);
        }
    }

    public void renderBuildingNames(Array<Building> buildings, Building currentBuilding) {
        batch.begin();
        font.getData().setScale(1.0f);

        for (Building building : buildings) {
            if (building.showName && building.isComplete()) {
                drawBuildingName(building);
            } else if (building.constructionProgress > 0) {
                drawBuildingProgress(building);
            }
        }

        if (currentBuilding != null) {
            drawCurrentBuildingName(currentBuilding);
        }

        batch.end();
    }

    private void drawBuildingName(Building building) {
        float x = building.x + building.width/2 + building.getWobbleX();
        float y = building.y + building.getCurrentHeight() + 70 * building.getSizeScale() + building.nameYOffset + building.getWobbleY();

        float pulse = 0.8f + 0.2f * (float)Math.sin(building.namePulse * 2);
        Color pulseColor = new Color(
            building.nameColor.r * pulse,
            building.nameColor.g * pulse,
            building.nameColor.b * pulse,
            1
        );

        font.setColor(pulseColor);
        font.getData().setScale(1.1f * building.getSizeScale());

        glyphLayout.setText(font, building.type);
        float textWidth = glyphLayout.width;

        // Фон с закругленными краями
        batch.setColor(new Color(0, 0, 0, 0.6f));
        batch.draw(whitePixel, x - textWidth/2 - 15, y - 25, textWidth + 30, 40);

        // Блестящая рамка
        batch.setColor(building.getDetailColor());
        batch.draw(whitePixel, x - textWidth/2 - 15, y - 25, 5, 40); // Левая
        batch.draw(whitePixel, x + textWidth/2 + 10, y - 25, 5, 40); // Правая
        batch.draw(whitePixel, x - textWidth/2 - 15, y - 25, textWidth + 30, 5); // Верх
        batch.draw(whitePixel, x - textWidth/2 - 15, y + 10, textWidth + 30, 5); // Низ

        batch.setColor(Color.WHITE);
        font.draw(batch, building.type, x - textWidth/2, y);
        font.getData().setScale(1.0f);
    }

    private void drawBuildingProgress(Building building) {
        float x = building.x + building.width/2;
        float y = building.y + building.getCurrentHeight() + 50;

        font.setColor(Color.YELLOW);
        font.getData().setScale(0.9f * building.getSizeScale());

        String cleanType = building.type.replace("✨", "").replace("🏥", "").replace("🎒", "")
            .replace("🎪", "").replace("💰", "").replace("💊", "")
            .replace("🎭", "").replace("🎬", "").trim();
        String progressText = cleanType + " (" + building.constructionProgress + "/3)";
        glyphLayout.setText(font, progressText);
        float textWidth = glyphLayout.width;

        batch.setColor(0, 0, 0, 0.3f);
        batch.draw(whitePixel, x - textWidth/2 - 5, y - 15, textWidth + 10, 30);
        batch.setColor(Color.WHITE);

        font.draw(batch, progressText, x - textWidth/2, y);
        font.getData().setScale(1.0f);
    }

    private void drawCurrentBuildingName(Building building) {
        float x = building.x + building.width/2;
        float y = building.y + building.height + 50;

        font.setColor(Color.YELLOW);
        font.getData().setScale(1.0f * building.getSizeScale());

        String cleanType = building.type.replace("✨", "").replace("🏥", "").replace("🎒", "")
            .replace("🎪", "").replace("💰", "").replace("💊", "")
            .replace("🎭", "").replace("🎬", "").trim();
        String prefix = building.constructionProgress == 0 ? "Место для: " : "Строится: ";
        String progressText = prefix + cleanType + " (" + building.constructionProgress + "/3)";
        glyphLayout.setText(font, progressText);
        float textWidth = glyphLayout.width;

        batch.setColor(0, 0, 0, 0.3f);
        batch.draw(whitePixel, x - textWidth/2 - 5, y - 15, textWidth + 10, 30);
        batch.setColor(Color.WHITE);

        font.draw(batch, progressText, x - textWidth/2, y);

        if (building.isOverlapping) {
            font.setColor(Color.RED);
            font.getData().setScale(0.8f * building.getSizeScale());
            String warning = "⚠ Пересечение! ⚠";
            glyphLayout.setText(font, warning);
            font.draw(batch, warning, x - glyphLayout.width/2, y - 25);
            font.getData().setScale(1.0f);
        }

        font.getData().setScale(1.0f);
    }
}
