/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Yandex-inspired color scheme */
    --primary-color: #FC3F1D;        /* Яндекс красный */
    --primary-dark: #E6381A;         /* Темнее красный */
    --primary-light: #FF5C3D;        /* Светлее красный */
    --success-color: #4CAF50;        /* Зеленый для успеха */
    --danger-color: #FC3F1D;         /* Красный для ошибок */
    --warning-color: #FFCA28;        /* Желтый для предупреждений */
    --bg-color: #FFFFFF;             /* Белый фон */
    --bg-secondary: #F5F5F5;         /* Светло-серый */
    --bg-tertiary: #FAFAFA;          /* Очень светло-серый */
    --text-primary: #000000;         /* Черный текст */
    --text-secondary: #666666;       /* Серый текст */
    --text-tertiary: #999999;        /* Светло-серый текст */
    --border-color: #E0E0E0;         /* Светлая граница */
    --border-dark: #CCCCCC;          /* Темнее граница */
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 16px rgba(252, 63, 29, 0.2);
    --metallic: #C0C0C0;             /* Металлический серый */
}

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

/* Screen Management */
.screen {
    display: none;
    width: 100%;
    height: 100vh;
}

.screen.active {
    display: flex;
}

/* Login Screen */
#loginScreen {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #FAFAFA 0%, #F5F5F5 100%);
}

.login-container {
    text-align: center;
    padding: 2rem;
    max-width: 400px;
}

.logo img {
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15));
    animation: float 3s ease-in-out infinite;
    border-radius: 8px;
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

.login-container h1 {
    margin-top: 1.5rem;
    font-size: 2.5rem;
    background: linear-gradient(135deg, #FC3F1D 0%, #FF5C3D 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 700;
}

.subtitle {
    color: var(--text-secondary);
    margin-top: 0.5rem;
    font-size: 1rem;
}

.auth-container {
    margin-top: 3rem;
    padding: 2rem;
    background: #FFFFFF;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.auth-container p {
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
}

#telegram-login {
    display: flex;
    justify-content: center;
    margin: 1rem 0;
}

.auth-note {
    margin-top: 1.5rem !important;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* PIN Login Section */
.pin-login-section {
    margin-top: 2rem;
}

.divider {
    display: flex;
    align-items: center;
    margin: 1.5rem 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.divider span {
    padding: 0 1rem;
}

.pin-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.pin-form label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-align: left;
}

.pin-form input[type="text"],
.pin-form input[type="password"] {
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.3s ease;
}

.pin-form input[type="text"] {
    text-align: left;
}

.pin-form input[type="password"] {
    text-align: center;
    letter-spacing: 0.2rem;
}

.pin-form input[type="text"]:focus,
.pin-form input[type="password"]:focus {
    outline: none;
    border-color: var(--primary-color);
    background: #FFFFFF;
    box-shadow: 0 0 0 3px rgba(252, 63, 29, 0.1);
}

.pin-form input[type="password"]::placeholder {
    letter-spacing: normal;
}

.pin-form button {
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.pin-form button:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.pin-form button:active {
    transform: translateY(0);
}

.pin-error {
    padding: 0.75rem;
    background: rgba(244, 67, 54, 0.1);
    border: 1px solid var(--danger-color);
    border-radius: 8px;
    color: var(--danger-color);
    font-size: 0.9rem;
    text-align: center;
}

/* Control Screen */
#controlScreen {
    flex-direction: column;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: #FFFFFF;
    border-bottom: 2px solid var(--border-color);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-small {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-small img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Status Indicator */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-radius: 20px;
    font-size: 0.875rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger-color);
    animation: pulse 2s ease-in-out infinite;
}

.status-indicator.connected .status-dot {
    background: var(--success-color);
}

.status-indicator.esp32-connected .status-dot {
    background: var(--primary-color);
}

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

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.2s;
}

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

/* Video Container */
.video-container {
    position: relative;
    flex: 1;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.video-placeholder {
    text-align: center;
    color: var(--text-secondary);
}

.video-placeholder svg {
    margin-bottom: 1rem;
    opacity: 0.5;
}

#videoCanvas {
    width: 100%;
    height: 100%;
    object-fit: contain;  transform: scaleX(-1); /* Отзеркаливание по горизонтали */
}

.video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.video-stats {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(0, 0, 0, 0.7);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    display: flex;
    gap: 1rem;
    backdrop-filter: blur(10px);
}

.time-remaining {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(252, 63, 29, 0.95);
    color: white;
    padding: 0.5rem 1.5rem;
    border-radius: 20px;
    font-size: 1.2rem;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(252, 63, 29, 0.3);
    font-weight: 600;
    font-family: 'Courier New', monospace;
    color: white;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    z-index: 10;
    transition: color 0.3s ease;
}

/* Controls Container */
.controls-container {
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

/* Joystick (Mobile) */
.joystick-container {
    display: none;
}

.joystick-zone {
    width: 200px;
    height: 200px;
    margin: 0 auto;
    position: relative;
}

.joystick-base {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: radial-gradient(circle, #FAFAFA 0%, #F0F0F0 100%);
    border: 3px solid var(--border-dark);
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
    position: relative;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
}

.joystick-stick {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    position: absolute;
    box-shadow: 0 4px 12px rgba(252, 63, 29, 0.3);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 4px 12px rgba(36, 129, 204, 0.5);
    transition: all 0.1s;
    cursor: grab;
}

.joystick-stick:active {
    cursor: grabbing;
    box-shadow: 0 2px 8px rgba(252, 63, 29, 0.7), 0 0 0 4px rgba(252, 63, 29, 0.2);
}

/* Keyboard Hint (Desktop) */
.keyboard-hint {
    text-align: center;
}

.keyboard-hint h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.key-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 1rem;
    max-width: 600px;
    margin: 0 auto 1rem;
}

.key-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.key {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #FFFFFF;
    border: 2px solid var(--border-dark);
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.key.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    box-shadow: 0 0 12px rgba(252, 63, 29, 0.6), var(--shadow-hover);
    transform: scale(0.95);
}

.key-item span {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.hint-text {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* User Info */
.user-info {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: #FFFFFF;
    border: 2px solid var(--border-color);
    border-radius: 25px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    box-shadow: var(--shadow);
    z-index: 100;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--primary-color);
}

#userName {
    font-size: 0.875rem;
    font-weight: 500;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1rem;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.loading-overlay.active {
    display: flex;
}

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

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

#loadingText {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Queue Panel */
.queue-panel {
    position: fixed;
    top: 80px;
    left: 20px;
    width: 280px;
    background: #FFFFFF;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    box-shadow: var(--shadow);
    z-index: 100;
}

.queue-panel h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.queue-panel h4 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.controller-info {
    margin-bottom: 1rem;
}

.controller-badge {
    padding: 0.75rem;
    border-radius: 8px;
    font-weight: 600;
    text-align: center;
    font-size: 0.9rem;
}

.time-info {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-color);
    border-radius: 6px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: 'Courier New', monospace;
}

.controller-badge:not(.empty) {
    background: linear-gradient(135deg, var(--success-color) 0%, #66bb6a 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.2);
}

.controller-badge.me {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
    box-shadow: var(--shadow-hover);
}

.controller-badge.empty {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 2px dashed var(--border-color);
}

.queue-section {
    margin-bottom: 1rem;
}

.queue-list {
    max-height: 200px;
    overflow-y: auto;
    border-radius: 8px;
    background: var(--bg-color);
    padding: 0.5rem;
}

.queue-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 6px;
    border: 2px solid var(--border-color);
}

.queue-item.me {
    background: rgba(252, 63, 29, 0.08);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 1px rgba(252, 63, 29, 0.1);
}

.queue-position {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 600;
}

.queue-name {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.queue-empty {
    text-align: center;
    padding: 1rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.queue-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.btn {
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
}

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

.btn-secondary {
    background: #FFFFFF;
    color: var(--text-primary);
    border: 2px solid var(--border-dark);
    font-weight: 500;
}

.btn-secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--text-secondary);
}

.btn-warning {
    background: var(--warning-color);
    color: #000000;
    font-weight: 600;
}

.btn-warning:hover {
    background: #FFB300;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 202, 40, 0.4);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    background: #FFFFFF;
    border: 2px solid var(--border-color);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 300px;
    animation: slideIn 0.3s ease-out;
}

.toast.success { border-left: 4px solid var(--success-color); }
.toast.error { border-left: 4px solid var(--danger-color); }
.toast.warning { border-left: 4px solid var(--warning-color); }

@keyframes slideIn {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .joystick-container {
        display: block;
    }

    .keyboard-hint {
        display: none;
    }

    .header h2 {
        font-size: 1rem;
    }

    .status-text {
        display: none;
    }

    .user-info {
        bottom: auto;
        top: 1rem;
        left: 1rem;
        right: auto;
    }
}

@media (min-width: 769px) {
    .joystick-container {
        display: none;
    }

    .keyboard-hint {
        display: block;
    }
}

/* Landscape Mode on Mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .header {
        padding: 0.5rem 1rem;
    }

    .controls-container {
        padding: 1rem;
    }

    .joystick-zone {
        width: 150px;
        height: 150px;
    }

    .joystick-stick {
        width: 60px;
        height: 60px;
    }
}

/* Headlights Button */
.btn-headlights {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid var(--border-dark);
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    z-index: 10;
}

.btn-headlights:hover {
    background: var(--bg-secondary);
    border-color: var(--text-secondary);
    transform: scale(1.05);
}

.btn-headlights:active {
    transform: scale(0.95);
}

.btn-headlights.active {
    background: var(--warning-color);
    border-color: var(--warning-color);
    box-shadow: 0 0 20px rgba(255, 202, 40, 0.6), 0 4px 16px rgba(255, 202, 40, 0.3);
    color: #000000;
}

.btn-headlights.active svg {
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.9));
}

@media (max-width: 768px) {
    .btn-headlights {
        width: 45px;
        height: 45px;
        bottom: 15px;
        right: 15px;
    }
    
    .btn-headlights svg {
        width: 20px;
        height: 20px;
    }

    .queue-panel {
        top: 70px;
        left: 10px;
        width: calc(100% - 20px);
        max-width: 300px;
    }
}

