/* ============================================
   Coffee Empire — Стили игры
   ============================================ */

:root {
    /* Уровень 1: Кофейный киоск — тёплые уютные тона */
    --bg-primary: #1a1207;
    --bg-secondary: #2d1f0e;
    --bg-card: #3a2815;
    --bg-card-hover: #4a3520;
    --accent: #d4943a;
    --accent-light: #e8b56a;
    --accent-glow: rgba(212, 148, 58, 0.3);
    --text-primary: #f5e6d3;
    --text-secondary: #b89a7a;
    --text-muted: #8a7260;
    --success: #4caf50;
    --danger: #e74c3c;
    --border: rgba(212, 148, 58, 0.15);
    --shadow: rgba(0, 0, 0, 0.4);

    /* Размеры */
    --radius: 16px;
    --radius-sm: 10px;
    --radius-lg: 24px;
    --gap: 12px;
    --header-height: auto;
}

/* Уровень 2: Кофейня — более изысканные тона */
body.level-2 {
    --bg-primary: #0f1a1a;
    --bg-secondary: #162626;
    --bg-card: #1e3333;
    --bg-card-hover: #264040;
    --accent: #26a69a;
    --accent-light: #4db6ac;
    --accent-glow: rgba(38, 166, 154, 0.3);
    --text-primary: #e0f2f1;
    --text-secondary: #80cbc4;
    --text-muted: #5f9ea0;
    --border: rgba(38, 166, 154, 0.15);
}

/* Уровень 3: Кофейная сеть — премиальные тёмно-золотые тона */
body.level-3 {
    --bg-primary: #0d0a14;
    --bg-secondary: #1a1528;
    --bg-card: #25203a;
    --bg-card-hover: #302a4a;
    --accent: #c9a44a;
    --accent-light: #e0c068;
    --accent-glow: rgba(201, 164, 74, 0.3);
    --text-primary: #f0e8d8;
    --text-secondary: #c9a44a;
    --text-muted: #8a7a5a;
    --border: rgba(201, 164, 74, 0.15);
}

/* ============================================
   Сброс и базовые стили
   ============================================ */

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

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    transition: background 0.8s ease, color 0.5s ease;
    position: relative;
}

/* ============================================
   Фоновые частицы
   ============================================ */

#particles-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.particle {
    position: absolute;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.08;
    animation: float-particle linear infinite;
}

@keyframes float-particle {
    0% {
        transform: translateY(100vh) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 0.08;
    }
    90% {
        opacity: 0.08;
    }
    100% {
        transform: translateY(-10vh) rotate(360deg);
        opacity: 0;
    }
}

/* ============================================
   Основной контейнер
   ============================================ */

#app {
    position: relative;
    z-index: 1;
    max-width: 480px;
    margin: 0 auto;
    padding: 0 16px 32px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ============================================
   Шапка
   ============================================ */

#header {
    padding: 16px 0 12px;
    position: sticky;
    top: 0;
    z-index: 10;
    background: linear-gradient(to bottom, var(--bg-primary) 70%, transparent);
    padding-bottom: 24px;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.level-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 50px;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--accent-light);
    transition: all 0.3s ease;
}

.level-icon {
    font-size: 1.2rem;
}

.reset-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 8px 12px;
    border-radius: 50px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.leaderboard-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 50px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-right: 8px;
}

.leaderboard-btn:hover {
    background: var(--bg-card-hover);
}

.leaderboard-list {
    margin-bottom: 20px;
    max-height: 250px;
    overflow-y: auto;
    text-align: left;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    padding: 8px;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    color: var(--text-primary);
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.leaderboard-rank {
    font-weight: bold;
    color: var(--accent);
    width: 25px;
}

.leaderboard-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 10px;
}

.leaderboard-score {
    font-weight: bold;
    color: var(--success);
}

.reset-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.balance-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.balance-container, .income-container {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    text-align: center;
}

.balance-label, .income-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.balance-value {
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--accent-light);
    text-shadow: 0 0 20px var(--accent-glow);
}

.income-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--success);
}

/* Прогресс до уровня */
.level-progress-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 16px;
}

.level-progress-container.hidden {
    display: none;
}

.level-progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.level-progress-bar {
    height: 6px;
    background: var(--bg-primary);
    border-radius: 3px;
    overflow: hidden;
}

.level-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    border-radius: 3px;
    width: 0%;
    transition: width 0.5s ease;
}

/* ============================================
   Область клика
   ============================================ */

#click-area {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px 0 24px;
}

.click-zone {
    text-align: center;
}

.cup-container {
    position: relative;
    width: 160px;
    height: 160px;
    margin: 0 auto 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.cup-glow {
    position: absolute;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--accent-glow), transparent 70%);
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.15); opacity: 0.8; }
}

.cup-emoji {
    font-size: 6rem;
    position: relative;
    z-index: 2;
    transition: transform 0.1s ease;
    filter: drop-shadow(0 4px 20px var(--accent-glow));
}

.cup-emoji.clicked {
    transform: scale(0.88);
}

.click-value-display {
    position: absolute;
    top: 50%;
    left: 50%;
    pointer-events: none;
    z-index: 3;
}

.floating-value {
    position: absolute;
    font-size: 1.3rem;
    font-weight: 900;
    color: var(--accent-light);
    text-shadow: 0 0 10px var(--accent-glow);
    animation: float-up 0.9s ease-out forwards;
    pointer-events: none;
    white-space: nowrap;
}

@keyframes float-up {
    0% {
        transform: translate(-50%, 0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -80px) scale(0.6);
        opacity: 0;
    }
}

.click-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.click-power {
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent);
}

/* ============================================
   Панель улучшений
   ============================================ */

#upgrades-panel {
    flex: 1;
}

.upgrades-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.upgrades-header h2 {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-primary);
}

.upgrades-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-card);
    border-radius: 50px;
    padding: 3px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: 50px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
}

.tab-btn.active {
    background: var(--accent);
    color: var(--bg-primary);
}

.upgrades-list {
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

/* Карточка улучшения */
.upgrade-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    cursor: pointer;
    transition: all 0.25s ease;
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

.upgrade-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--accent-glow), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.upgrade-card:hover::before {
    opacity: 0.3;
}

.upgrade-card:active {
    transform: scale(0.98);
}

.upgrade-card.affordable {
    border-color: var(--accent);
    box-shadow: 0 0 15px var(--accent-glow);
}

.upgrade-card.locked {
    opacity: 0.45;
    cursor: not-allowed;
    filter: grayscale(0.5);
}

.upgrade-card.locked::after {
    content: '🔒';
    position: absolute;
    top: 8px;
    right: 12px;
    font-size: 1rem;
}

.upgrade-card.max-level {
    border-color: var(--success);
    opacity: 0.7;
}

.upgrade-icon {
    font-size: 2rem;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.upgrade-info {
    flex: 1;
    min-width: 0;
    position: relative;
    z-index: 1;
}

.upgrade-name {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 2px;
    color: var(--text-primary);
}

.upgrade-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    line-height: 1.3;
}

.upgrade-effect {
    font-size: 0.8rem;
    color: var(--success);
    font-weight: 600;
}

.upgrade-right {
    text-align: right;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.upgrade-price {
    font-size: 1rem;
    font-weight: 800;
    color: var(--accent-light);
    white-space: nowrap;
}

.upgrade-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ============================================
   Панель статистики
   ============================================ */

#stats-panel {
    margin-top: 24px;
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

#stats-panel h2 {
    font-size: 1rem;
    font-weight: 800;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat-item {
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    padding: 12px;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1rem;
    font-weight: 800;
    color: var(--text-primary);
}

/* ============================================
   Модальные окна
   ============================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--accent);
    border-radius: var(--radius-lg);
    padding: 32px 28px;
    max-width: 360px;
    width: 90%;
    text-align: center;
    transform: scale(0.8) translateY(20px);
    transition: transform 0.3s ease;
    box-shadow: 0 20px 60px var(--shadow), 0 0 40px var(--accent-glow);
}

.modal-overlay.visible .modal-content {
    transform: scale(1) translateY(0);
}

.modal-icon {
    font-size: 4rem;
    margin-bottom: 12px;
    animation: bounce-icon 0.6s ease;
}

@keyframes bounce-icon {
    0% { transform: scale(0); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.modal-content h2 {
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--accent-light);
    margin-bottom: 8px;
}

.modal-content p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.modal-rewards {
    margin-bottom: 20px;
}

.modal-reward-item {
    font-size: 0.85rem;
    color: var(--success);
    margin: 4px 0;
    font-weight: 600;
}

.modal-btn {
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    color: var(--bg-primary);
    border: none;
    padding: 14px 32px;
    border-radius: 50px;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    min-width: 140px;
}

.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--accent-glow);
}

.modal-btn-danger {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* ============================================
   Анимация покупки
   ============================================ */

.upgrade-card.purchased {
    animation: purchase-flash 0.4s ease;
}

@keyframes purchase-flash {
    0% { background: var(--bg-card); }
    50% { background: rgba(76, 175, 80, 0.2); }
    100% { background: var(--bg-card); }
}

/* ============================================
   Анимация перехода уровня
   ============================================ */

body.level-transition {
    animation: level-shift 1s ease;
}

@keyframes level-shift {
    0% { filter: brightness(1); }
    50% { filter: brightness(1.5); }
    100% { filter: brightness(1); }
}

/* ============================================
   Адаптивность
   ============================================ */

@media (max-width: 400px) {
    .balance-value {
        font-size: 1.2rem;
    }

    .cup-emoji {
        font-size: 5rem;
    }

    .cup-container {
        width: 130px;
        height: 130px;
    }

    .cup-glow {
        width: 170px;
        height: 170px;
    }

    .upgrade-card {
        padding: 12px;
        gap: 10px;
    }
}

@media (min-width: 481px) {
    #app {
        padding-top: 16px;
    }
}

/* ============================================
   Скроллбар
   ============================================ */

::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 2px;
}
