* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ===== Дизайн-токены (единый источник правды для цвета/эффектов) =====
   Тёмная тема — значения по умолчанию в :root.
   Светлая тема — переопределения в :root[data-theme="light"] ниже.
   RGB-триплеты (--x-rgb) существуют для использования внутри rgba(var(--x-rgb), alpha),
   чтобы сохранять произвольный альфа-канал при этом оставаясь тематизируемыми. */
:root {
    color-scheme: dark;

    --bg: #0a0e17;
    --bg-rgb: 10, 14, 23;
    --surface: #0f172a;
    --surface-rgb: 15, 23, 42;
    --surface-elevated: #1e293b;
    --surface-elevated-rgb: 30, 41, 59;

    --accent: #00eaff;
    --accent-rgb: 0, 234, 255;
    --accent-2: #008cff;
    --accent-2-rgb: 0, 140, 255;
    --accent-alt: #39ff14;
    --accent-alt-rgb: 57, 255, 20;

    --text: #e2e8f0;
    --text-rgb: 226, 232, 240;
    --text-dim: #94a3b8;
    --text-dim-rgb: 148, 163, 184;
    --text-dimmer: #64748b;
    --text-dimmer-rgb: 100, 116, 139;

    --white-rgb: 255, 255, 255;
    --black-rgb: 0, 0, 0;

    --danger: #ff6b6b;
    --danger-rgb: 255, 107, 107;
    --warning: #ffd166;
    --warning-rgb: 255, 209, 102;

    --accent-glow-weak: rgba(var(--accent-rgb), 0.1);
    --accent-glow-soft: rgba(var(--accent-rgb), 0.2);
    --accent-glow: rgba(var(--accent-rgb), 0.3);
    --accent-glow-strong: rgba(var(--accent-rgb), 0.5);

    /* Стеклянные поверхности: полупрозрачная подложка + мягкая рассеянная тень
       вместо плоской заливки и жёсткой неоновой обводки */
    --glass-bg: rgba(var(--surface-rgb), 0.55);
    --glass-bg-strong: rgba(var(--surface-rgb), 0.75);
    --glass-border: rgba(var(--white-rgb), 0.08);
    --glass-shadow: 0 8px 32px rgba(var(--black-rgb), 0.25);

    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;

    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    /* На мобильных backdrop-filter дорог для GPU — уменьшаем радиус блюра */
    --blur-lg: 18px;
    --blur-md: 12px;
    --blur-sm: 6px;
}

:root[data-theme="light"] {
    color-scheme: light;

    --bg: #eef2f9;
    --bg-rgb: 238, 242, 249;
    --surface: #ffffff;
    --surface-rgb: 255, 255, 255;
    --surface-elevated: #f1f5f9;
    --surface-elevated-rgb: 241, 245, 249;

    --accent: #0891b2;
    --accent-rgb: 8, 145, 178;
    --accent-2: #2563eb;
    --accent-2-rgb: 37, 99, 235;
    --accent-alt: #16a34a;
    --accent-alt-rgb: 22, 163, 74;

    --text: #1e293b;
    --text-rgb: 30, 41, 59;
    --text-dim: #475569;
    --text-dim-rgb: 71, 85, 105;
    --text-dimmer: #64748b;
    --text-dimmer-rgb: 100, 116, 139;

    --white-rgb: 255, 255, 255;
    --black-rgb: 15, 23, 42;

    --danger: #dc2626;
    --danger-rgb: 220, 38, 38;
    --warning: #b45309;
    --warning-rgb: 180, 83, 9;

    --glass-bg: rgba(var(--surface-rgb), 0.65);
    --glass-bg-strong: rgba(var(--surface-rgb), 0.85);
    --glass-border: rgba(15, 23, 42, 0.08);
    --glass-shadow: 0 8px 32px rgba(15, 23, 42, 0.1);
}

@media (max-width: 768px) {
    :root {
        /* backdrop-filter/blur целиком отключаем на мобильных — дорогая
           GPU-операция, особенно вместе на нескольких fixed-элементах сразу */
        --blur-lg: 0px;
        --blur-md: 0px;
        --blur-sm: 0px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Индикатор загрузки */
.global-loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(var(--bg-rgb), 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(var(--blur-md, 10px));
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.global-loading.hidden {
    opacity: 0;
    visibility: hidden;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(var(--accent-rgb), 0.3);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
    box-shadow: 0 0 20px rgba(var(--accent-rgb), 0.5);
}

.loading-text {
    color: var(--accent);
    font-family: 'Orbitron', sans-serif;
    font-size: 1.2rem;
    text-shadow: 0 0 10px rgba(var(--accent-rgb), 0.5);
}

/* Canvas для фона */
.canvas-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

#bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.canvas-container canvas {
    pointer-events: none;
}

/* Модальные окна */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(var(--black-rgb), 0.7);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

/* Утилитарные классы */
.loading {
    opacity: 0.7;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(var(--white-rgb),0.1), transparent);
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* Мобильная навигация (фиксированная внизу) */
@media (max-width: 768px) {
    .mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--glass-bg-strong);
        backdrop-filter: blur(var(--blur-lg, 15px));
        border-top: 1px solid var(--glass-border);
        padding: 10px 5px calc(15px + env(safe-area-inset-bottom));
        display: flex;
        justify-content: space-around;
        z-index: 999;
        height: 70px;
        box-shadow: 0 -5px 25px rgba(var(--black-rgb), 0.4);
    }

    .mobile-nav-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 8px 5px 5px;
        max-width: 90px;
        height: 60px;
        border-radius: var(--radius-md);
        background: rgba(var(--surface-elevated-rgb), 0.7);
        border: 1px solid var(--glass-border);
        transition: all 0.2s ease;
        text-decoration: none;
        color: var(--text-dim);
    }
    
    .mobile-nav-btn i {
        font-size: 1.3rem;
        margin-bottom: 5px;
        transition: all 0.2s ease;
    }
    
    .mobile-nav-btn span {
        font-size: 0.75rem;
        font-weight: 600;
        letter-spacing: 0.3px;
    }
    
    .mobile-nav-btn:hover,
    .mobile-nav-btn.active {
        background: linear-gradient(135deg, rgba(var(--accent-rgb), 0.8) 0%, rgba(var(--accent-2-rgb), 0.8) 100%);
        border-color: var(--accent);
        color: var(--surface);
        box-shadow: 0 0 20px rgba(var(--accent-rgb), 0.3);
    }
    
    .main-container {
        padding-bottom: calc(90px + env(safe-area-inset-bottom)) !important;
    }

    .header-nav {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .mobile-bottom-nav {
        height: 65px;
        padding: 8px 4px 12px;
    }
    
    .mobile-nav-btn {
        padding: 7px 4px 4px;
        height: 55px;
        max-width: 80px;
    }
    
    .mobile-nav-btn i {
        font-size: 1.1rem;
        margin-bottom: 4px;
    }
    
    .mobile-nav-btn span {
        font-size: 0.7rem;
    }
    
    .main-container {
        padding-bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    }
}

@media (max-width: 360px) {
    .mobile-bottom-nav {
        height: 60px;
        padding: 7px 3px 10px;
    }
    
    .mobile-nav-btn {
        padding: 6px 3px 3px;
        height: 50px;
        max-width: 70px;
    }
    
    .mobile-nav-btn i {
        font-size: 1rem;
    }
    
    .mobile-nav-btn span {
        font-size: 0.65rem;
    }
    
    .main-container {
        padding-bottom: calc(75px + env(safe-area-inset-bottom)) !important;
    }
}

/* Анимация для обновления статистики */
.stat-updating {
    animation: statUpdate 0.4s ease-in-out;
}

@keyframes statUpdate {
    0% { 
        color: var(--accent);
        transform: scale(1);
    }
    50% { 
        color: var(--accent-alt);
        transform: scale(1.1);
    }
    100% { 
        color: var(--accent);
        transform: scale(1);
    }
}

/* Кнопка "Наверх" */
.scroll-to-top-btn {
    position: fixed;
    bottom: 100px;
    right: 65px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
    color: var(--surface);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 15px rgba(var(--accent-rgb), 0.3);
}

.scroll-to-top-btn.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.scroll-to-top-btn:hover {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 6px 20px rgba(var(--accent-rgb), 0.4);
}

.scroll-to-top-btn:active {
    transform: translateY(-2px) scale(0.98);
}

@media (max-width: 768px) {
    .scroll-to-top-btn {
        bottom: calc(120px + env(safe-area-inset-bottom));
        right: calc(10px + env(safe-area-inset-right));
        width: 45px;
        height: 45px;
        font-size: 1.1rem;
    }
}