/**
 * Современные стили для pixel-battle 2.0
 * Модульная архитектура с улучшенным UX
 */

/* CSS Custom Properties для темизации */
:root {
    /* Основные цвета */
    --primary-color: #2196F3;
    --primary-dark: #1976D2;
    --primary-light: #BBDEFB;
    --secondary-color: #4CAF50;
    --accent-color: #FF9800;
    --error-color: #F44336;
    --warning-color: #FFC107;
    --success-color: #4CAF50;
    
    /* Нейтральные цвета */
    --background-color: #FAFAFA;
    --surface-color: #FFFFFF;
    --surface-dark: #F5F5F5;
    --text-primary: #212121;
    --text-secondary: #757575;
    --text-hint: #9E9E9E;
    --divider: #E0E0E0;
    
    /* Тени */
    --shadow-1: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    --shadow-2: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
    --shadow-3: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
    --shadow-4: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
    --shadow-5: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);
    
    /* Радиусы */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    /* Переходы */
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Размеры */
    --header-height: 60px;
    --bottom-panel-height: 80px;
    
    /* Z-index */
    --z-tooltip: 1000;
    --z-modal: 1500;
    --z-dropdown: 2000;
    --z-notification: 3000;
    --z-loader: 10000;
}

/* Темная тема */
@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #121212;
        --surface-color: #1E1E1E;
        --surface-dark: #2D2D2D;
        --text-primary: #FFFFFF;
        --text-secondary: #AAAAAA;
        --text-hint: #666666;
        --divider: #333333;
    }
}

/* Глобальные стили */
* {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden; /* Предотвращаем скролл */
    user-select: none; /* Предотвращаем выделение текста при перетаскивании */
}

/* Основная структура приложения */
.app {
    position: relative;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

.canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    background: var(--surface-color);
    transition: all var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    z-index: 1;
    width: 100vw;
    height: 100vh;
}

.main-canvas {
    display: block;
    cursor: crosshair;
    width: 100vw;
    height: 100vh;
    touch-action: none; /* Отключаем стандартные touch жесты */
    position: absolute;
    top: 0;
    left: 0;
    max-width: none;
    max-height: none;
    object-fit: cover;
}

/* Верхняя панель */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--surface-color);
    border-bottom: 1px solid var(--divider);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 200;
    box-shadow: var(--shadow-1);
    transition: all var(--transition-normal);
}

.info-panel {
    display: flex;
    align-items: center;
    gap: 20px;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

.info-icon {
    font-size: 16px;
}

.status-indicator[data-status="connected"] {
    color: var(--success-color);
}

.status-indicator[data-status="disconnected"] {
    color: var(--error-color);
}

.status-indicator[data-status="connecting"] {
    color: var(--warning-color);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.control-buttons {
    display: flex;
    gap: 8px;
}

.control-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--surface-dark);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all var(--transition-fast);
    position: relative;
}

.control-btn:hover {
    background: var(--primary-light);
    color: var(--primary-color);
    transform: translateY(-1px);
}

.control-btn:active {
    transform: translateY(0);
}

.control-btn.active {
    background: var(--primary-color);
    color: white;
}

/* Нижняя панель управления */
.bottom-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface-color);
    border-top: 1px solid var(--divider);
    padding: 16px 20px;
    z-index: 300;
    box-shadow: var(--shadow-2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    transition: transform var(--transition-normal);
    transform: translateY(0);
    max-height: 80vh;
    overflow-y: auto;
}

.bottom-panel.hidden {
    transform: translateY(100%);
}

.bottom-panel-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.bottom-panel-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Палитра цветов в нижней панели */
.bottom-color-palette {
    display: flex;
    gap: 8px;
    align-items: center;
}

.bottom-color-option {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 2px solid transparent;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.bottom-color-option:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-2);
}

.bottom-color-option:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-light);
}

.bottom-color-option.selected {
    border-color: var(--primary-color);
    transform: scale(1.1);
    box-shadow: var(--shadow-3);
}

.bottom-color-option::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-weight: bold;
    opacity: 0;
    transition: opacity var(--transition-fast);
    text-shadow: 0 0 4px rgba(0,0,0,0.5);
}

.bottom-color-option.selected::after {
    opacity: 1;
}

/* Кнопка подтверждения в нижней панели */
.bottom-confirm-btn {
    padding: 8px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 120px;
    justify-content: center;
}

.bottom-confirm-btn:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-2);
}

.bottom-confirm-btn:disabled {
    background: var(--text-hint);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Информация о пикселе в нижней панели */
.bottom-pixel-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: var(--text-secondary);
}

.bottom-pixel-preview {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--divider);
    background: #FFFFFF;
}

/* Cooldown в нижней панели */
.bottom-cooldown {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

.bottom-cooldown-progress {
    width: 60px;
    height: 4px;
    background: var(--surface-dark);
    border-radius: 2px;
    overflow: hidden;
}

.bottom-cooldown-progress-bar {
    height: 100%;
    background: var(--warning-color);
    width: 0%;
    transition: width 0.1s linear;
    border-radius: 2px;
}

/* Плавающая кнопка размещения пикселя */
.floating-place-button {
    position: fixed;
    bottom: 100px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: var(--shadow-3);
    transition: all var(--transition-fast);
    z-index: 400;
    display: none;
}

.floating-place-button:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-4);
}

.floating-place-button:disabled {
    background: var(--text-hint);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.floating-place-button.visible {
    display: block;
}

/* Кнопка скрытия/показа нижней панели */
.toggle-bottom-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: white;
    font-size: 20px;
    cursor: pointer;
    box-shadow: var(--shadow-3);
    transition: all var(--transition-fast);
    z-index: 400;
}

.toggle-bottom-panel:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-4);
}

.toggle-bottom-panel.hidden {
    transform: translateY(100px);
}

/* Стили для скрытой нижней панели */
.bottom-panel.hidden {
    transform: translateY(100%);
}

.panel-title {
    margin: 0 0 16px 0;
    padding: 0 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}



/* Мобильные элементы управления */
.mobile-controls {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

.mobile-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: var(--shadow-3);
    transition: all var(--transition-fast);
}

.mobile-toggle:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-4);
}

.mobile-panel {
    position: fixed;
    bottom: 80px;
    right: 20px;
    background: var(--surface-color);
    border: 1px solid var(--divider);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-3);
    padding: 16px;
    min-width: 200px;
    max-width: calc(100vw - 40px);
    z-index: 999;
}

/* Показываем мобильные элементы только на мобильных устройствах */
@media (max-width: 768px) {
    .mobile-controls {
        display: block !important;
    }
    
    /* Адаптируем канвас для мобильных */
    .canvas-container {
        right: 0 !important;
        margin-right: 0 !important;
    }
    
    .top-bar {
        right: 0 !important;
    }
}

/* Показываем мобильные элементы на всех устройствах для тестирования */
.mobile-controls {
    display: block !important;
}

/* Адаптация для очень маленьких экранов */
@media (max-width: 480px) {
    .mobile-panel {
        right: 10px;
        left: 10px;
        max-width: none;
        width: calc(100vw - 20px);
    }
    
    .mobile-toggle {
        right: 10px;
        bottom: 10px;
    }
    
    .floating-place-button {
        bottom: 80px;
        right: 10px;
        width: 48px;
        height: 48px;
        font-size: 20px;
    }
    
    .bottom-panel {
        max-height: 60vh;
        padding: 12px 16px;
    }
}

/* Контекстное меню */
.context-menu {
    position: fixed;
    background: var(--surface-color);
    border: 1px solid var(--divider);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-3);
    padding: 8px 0;
    min-width: 160px;
    z-index: var(--z-dropdown);
}

.context-menu-item {
    padding: 12px 16px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.context-menu-item:hover {
    background: var(--surface-dark);
}

.context-menu-separator {
    height: 1px;
    background: var(--divider);
    margin: 8px 0;
}

/* Оверлеи холста */
.canvas-overlays {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.cursor-info {
    position: absolute;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-family: monospace;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-fast);
    z-index: 100;
}

.cursor-info.visible {
    opacity: 1;
}

/* Адаптивность */
@media (max-width: 480px) {
    .top-bar {
        right: 0;
    }
    
    .mobile-controls {
        display: block;
    }
    
    .control-buttons {
        display: none;
    }
    
    .info-panel {
        gap: 12px;
    }
    
    .info-item {
        font-size: 12px;
    }
    
    .info-text {
        display: none;
    }
}

@media (max-width: 480px) {
    .top-bar {
        padding: 0 12px;
        height: 50px;
    }
    
    :root {
        --header-height: 50px;
    }
    
    .info-panel {
        gap: 8px;
    }
    
    .info-icon {
        font-size: 14px;
    }
    
    .bottom-panel {
        padding: 10px 12px;
    }
    
    .bottom-color-palette {
        gap: 4px;
    }
    
    .bottom-color-option {
        width: 24px;
        height: 24px;
    }
    
    .bottom-confirm-btn {
        padding: 4px 8px;
        font-size: 11px;
        min-width: 80px;
    }
    
    .bottom-panel-left {
        gap: 12px;
    }
    
    .bottom-panel-right {
        gap: 8px;
    }
    
    .toggle-bottom-panel {
        bottom: 12px;
        right: 12px;
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
}

/* Высококонтрастная тема */
@media (prefers-contrast: high) {
    :root {
        --shadow-1: 0 0 0 1px var(--divider);
        --shadow-2: 0 0 0 2px var(--divider);
        --shadow-3: 0 0 0 3px var(--divider);
    }
    
    .bottom-color-option {
        border: 2px solid var(--divider);
    }
    
    .control-btn, .bottom-confirm-btn {
        border: 1px solid var(--divider);
    }
}

/* Анимации для улучшения UX */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.notification-container .notification {
    animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Улучшения доступности */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Фокус для клавиатурной навигации */
*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Анимация загрузки приложения */
.app {
    animation: fadeIn 0.5s ease-out;
}

/* Печать */
@media print {
    .bottom-panel, .top-bar, .mobile-controls {
        display: none;
    }
    
    .canvas-container {
        margin: 0;
    }
}

/* Стили для мобильной нижней панели */
@media (max-width: 768px) {
    .bottom-panel {
        padding: 12px 16px;
        max-height: 70vh;
        flex-wrap: wrap;
        gap: 12px;
    }
    
    .bottom-panel-left {
        gap: 12px;
        flex-wrap: wrap;
        align-items: center;
    }
    
    .bottom-panel-right {
        gap: 12px;
        margin-left: auto;
    }
    
    .bottom-color-palette {
        gap: 6px;
        flex-wrap: wrap;
    }
    
    .bottom-color-option {
        width: 28px;
        height: 28px;
    }
    
    .bottom-confirm-btn {
        padding: 6px 12px;
        font-size: 12px;
        min-width: 100px;
    }
    
    .toggle-bottom-panel {
        bottom: 16px;
        right: 16px;
        width: 44px;
        height: 44px;
        font-size: 18px;
    }
}
