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

:root {
    --bg-color: var(--tg-theme-bg-color, #0f0f1a);
    --text-color: var(--tg-theme-text-color, #ffffff);
    --hint-color: var(--tg-theme-hint-color, #8a8a9e);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #1a1a2e);

    --primary: #ff6b35;
    --primary-dark: #e55a2b;
    --gold: #ffd700;
    --token: #a855f7;
    --danger: #ef4444;
    --success: #22c55e;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

#app {
    height: 100vh;
    overflow: hidden;
}

/* === ЭКРАНЫ === */
.screen {
    display: none;
    height: 100vh;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.screen.active {
    display: flex;
}

/* === ЗАГРУЗКА === */
#loading-screen {
    justify-content: center;
    align-items: center;
    gap: 20px;
}

.loader {
    width: 50px;
    height: 50px;
    border: 4px solid var(--secondary-bg);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === ГЛАВНОЕ МЕНЮ === */
#main-menu {
    padding: 16px;
    padding-bottom: 30px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: linear-gradient(135deg, var(--secondary-bg) 0%, #252545 100%);
    border-radius: 16px;
    margin-bottom: 16px;
    border: 1px solid rgba(255,255,255,0.05);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    object-fit: cover;
    border: 2px solid var(--primary);
}

.user-details {
    display: flex;
    flex-direction: column;
}

#user-name {
    font-weight: 600;
    font-size: 15px;
}

#user-level {
    font-size: 11px;
    color: var(--hint-color);
}

.currency-display {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.currency {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 700;
    font-size: 13px;
    padding: 5px 10px;
    background: rgba(255, 215, 0, 0.1);
    border-radius: 10px;
    border: 1px solid rgba(255, 215, 0, 0.2);
}

.currency.token {
    background: rgba(168, 85, 247, 0.1);
    border-color: rgba(168, 85, 247, 0.2);
}

/* === ЗАГОЛОВОК ИГРЫ === */
.menu-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 10px;
}

.game-title {
    font-size: 38px;
    font-weight: 900;
    text-align: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--gold) 50%, var(--primary) 100%);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 25px;
    line-height: 1.1;
    animation: shimmer 3s ease infinite;
}

@keyframes shimmer {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

/* === КНОПКИ МЕНЮ === */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 280px;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 20px;
    border: none;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, #ff8c5a 100%);
    color: white;
    box-shadow: 0 4px 20px rgba(255, 107, 53, 0.4);
}

.btn-play {
    padding: 18px 24px;
    font-size: 18px;
}

.btn-secondary {
    background: var(--secondary-bg);
    color: var(--text-color);
    border: 1px solid rgba(255,255,255,0.08);
}

.btn-daily {
    background: linear-gradient(135deg, var(--success) 0%, #16a34a 100%);
    color: white;
}

.btn-daily:disabled {
    background: var(--secondary-bg);
    color: var(--hint-color);
    opacity: 0.6;
}

.btn-small {
    padding: 10px 16px;
    font-size: 13px;
}

.btn-icon {
    font-size: 18px;
}

/* === СТАТИСТИКА === */
.stats-mini {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: auto;
    padding-top: 25px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 12px 16px;
    background: var(--secondary-bg);
    border-radius: 12px;
    min-width: 80px;
}

.stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 9px;
    color: var(--hint-color);
    text-transform: uppercase;
    text-align: center;
}

/* === ЗАГОЛОВОК ЭКРАНА === */
.screen-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    padding-bottom: 12px;
}

.btn-back {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 12px;
    background: var(--secondary-bg);
    color: var(--text-color);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.screen-header h2 {
    font-size: 20px;
    font-weight: 700;
}

/* === КАРТЫ === */
#map-select {
    padding: 0;
}

.maps-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 0 16px 20px;
}

.map-card {
    background: linear-gradient(145deg, var(--secondary-bg) 0%, #1f1f3a 100%);
    border-radius: 16px;
    padding: 18px 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.05);
    text-align: center;
}

.map-card:active {
    transform: scale(0.97);
}

.map-card.locked {
    opacity: 0.4;
    cursor: not-allowed;
}

.map-card .map-icon {
    font-size: 40px;
    margin-bottom: 10px;
    display: block;
}

.map-card .map-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 6px;
}

.map-card .map-difficulty {
    font-size: 12px;
}

.map-card .lock-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}

.map-card .lock-overlay small {
    font-size: 11px;
    margin-top: 5px;
    color: var(--hint-color);
}

/* === ДОСТИЖЕНИЯ === */
#achievements {
    padding: 0;
}

.achievements-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 16px 20px;
}

.achievement-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--secondary-bg);
    border-radius: 14px;
    padding: 12px;
    border: 1px solid rgba(255,255,255,0.05);
}

.achievement-card.locked {
    opacity: 0.45;
}

.achievement-card.unlocked {
    border-left: 3px solid var(--success);
    background: linear-gradient(90deg, rgba(34, 197, 94, 0.1) 0%, var(--secondary-bg) 30%);
}

.achievement-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    flex-shrink: 0;
}

.achievement-info {
    flex: 1;
    min-width: 0;
}

.achievement-name {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 2px;
}

.achievement-desc {
    font-size: 11px;
    color: var(--hint-color);
}

.achievement-reward {
    padding: 6px 10px;
    background: rgba(168, 85, 247, 0.15);
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
}

.btn-claim {
    background: linear-gradient(135deg, var(--token) 0%, #9333ea 100%);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 11px;
    cursor: pointer;
    flex-shrink: 0;
}

/* === РЕЙТИНГ === */
#leaderboard {
    padding: 0;
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 16px 20px;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--secondary-bg);
    border-radius: 12px;
    padding: 10px 12px;
}

.leaderboard-item.top-3 {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.1) 0%, var(--secondary-bg) 50%);
    border: 1px solid rgba(255, 215, 0, 0.15);
}

.rank {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

.rank.gold { background: linear-gradient(135deg, #ffd700 0%, #ffb700 100%); color: #000; }
.rank.silver { background: linear-gradient(135deg, #c0c0c0 0%, #a0a0a0 100%); color: #000; }
.rank.bronze { background: linear-gradient(135deg, #cd7f32 0%, #b06f2c 100%); color: #fff; }

.leaderboard-info {
    flex: 1;
    min-width: 0;
}

.leaderboard-name {
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leaderboard-stat {
    font-size: 11px;
    color: var(--hint-color);
}

.leaderboard-score {
    font-weight: 700;
    font-size: 13px;
    color: var(--primary);
    flex-shrink: 0;
}

/* === КОШЕЛЁК === */
#wallet {
    padding: 0;
}

.wallet-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 0 16px 20px;
}

.token-balance {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 20px;
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.2) 0%, rgba(168, 85, 247, 0.05) 100%);
    border-radius: 20px;
    border: 1px solid rgba(168, 85, 247, 0.2);
}

.token-icon-large {
    font-size: 44px;
    margin-bottom: 10px;
}

.balance-amount {
    font-size: 38px;
    font-weight: 700;
}

.balance-label {
    font-size: 13px;
    color: var(--hint-color);
}

.wallet-address-section,
.withdraw-section,
.earning-methods {
    background: var(--secondary-bg);
    border-radius: 16px;
    padding: 16px;
}

.wallet-address-section label,
.withdraw-section h3,
.earning-methods h3 {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    font-size: 14px;
}

.wallet-address-section input,
.withdraw-section input {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
    font-size: 14px;
    margin-bottom: 10px;
}

.wallet-address-section input::placeholder,
.withdraw-section input::placeholder {
    color: var(--hint-color);
}

.info-text {
    font-size: 11px;
    color: var(--hint-color);
    margin-bottom: 10px;
}

.earning-methods ul {
    list-style: none;
}

.earning-methods li {
    padding: 8px 0;
    font-size: 13px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.earning-methods li:last-child {
    border-bottom: none;
}

/* ============================================ */
/* ============== ИГРОВОЙ ЭКРАН ============== */
/* ============================================ */

#game-screen {
    padding: 0;
    background: #0a0a15;
}

#game-screen.active {
    display: flex;
}

.game-ui {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: linear-gradient(180deg, #1a1a2e 0%, #15152a 100%);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
    gap: 8px;
}

.btn-back-game {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 8px;
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.game-header .wave-info,
.game-header .lives-info,
.game-header .gold-info {
    font-weight: 700;
    font-size: 14px;
    padding: 6px 10px;
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
}

.game-header .lives-info {
    color: #ef4444;
}

.game-header .gold-info {
    color: var(--gold);
}

.game-canvas-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #0d0d1a 0%, #0a0a12 100%);
    overflow: hidden;
    padding: 8px;
}

#game-canvas {
    border-radius: 8px;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
}

/* === ПАНЕЛЬ БАШЕН === */
.tower-panel {
    display: flex;
    gap: 6px;
    padding: 10px;
    background: linear-gradient(180deg, #15152a 0%, #1a1a2e 100%);
    border-top: 1px solid rgba(255,255,255,0.1);
    overflow-x: auto;
    flex-shrink: 0;
    justify-content: center;
}

.tower-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    min-width: 56px;
    transition: all 0.1s ease;
}

.tower-btn:active {
    transform: scale(0.93);
}

.tower-btn.selected {
    border-color: var(--primary);
    background: rgba(255, 107, 53, 0.2);
    box-shadow: 0 0 15px rgba(255, 107, 53, 0.3);
}

.tower-btn.disabled {
    opacity: 0.35;
}

.tower-btn .tower-icon {
    font-size: 22px;
}

.tower-btn .tower-cost {
    font-size: 9px;
    color: var(--gold);
    font-weight: 700;
}

.tower-btn.start-wave {
    background: linear-gradient(135deg, var(--success) 0%, #16a34a 100%);
    min-width: 50px;
    border: none;
}

.tower-btn.start-wave .tower-icon {
    font-size: 18px;
}

/* === УВЕДОМЛЕНИЯ === */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 20px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 13px;
    z-index: 9999;
    animation: toastIn 0.25s ease;
    max-width: 90%;
    text-align: center;
}

.toast.success {
    background: linear-gradient(135deg, var(--success) 0%, #16a34a 100%);
    color: white;
    box-shadow: 0 4px 20px rgba(34, 197, 94, 0.4);
}

.toast.error {
    background: linear-gradient(135deg, var(--danger) 0%, #dc2626 100%);
    color: white;
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* === АДАПТИВ === */
@media (max-height: 600px) {
    .game-title {
        font-size: 28px;
        margin-bottom: 15px;
    }

    .menu-buttons {
        gap: 8px;
    }

    .btn {
        padding: 12px 18px;
    }

    .btn-play {
        padding: 14px 20px;
    }

    .stats-mini {
        padding-top: 15px;
    }

    .stat {
        padding: 8px 12px;
        min-width: 70px;
    }

    .stat-value {
        font-size: 18px;
    }
}
