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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    /* iOS Safari specific fixes */
    -webkit-text-size-adjust: 100%;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

.warning {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    color: #856404;
    padding: 10px 15px;
    border-radius: 8px;
    margin: 15px 0;
    font-size: 0.9rem;
    text-align: center;
}

main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
}

.scanner-container {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    text-align: center;
    position: relative;
}

#video {
    width: 100%;
    max-width: 400px;
    height: 300px;
    border-radius: 10px;
    background: #f0f0f0;
    border: 2px solid #ddd;
    object-fit: cover;
    /* Мобильные улучшения */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    backface-visibility: hidden;
    position: relative;
    /* iOS Safari specific fixes */
    -webkit-playsinline: true;
    -webkit-appearance: none;
    appearance: none;
    /* Предотвращаем зум при двойном тапе */
    touch-action: manipulation;
}

/* Полоска сканирования */
.scan-line {
    position: absolute;
    top: 0;
    left: 5%;
    width: 90%;
    height: 3px;
    background: linear-gradient(90deg, transparent, #00ff00, transparent);
    box-shadow: 0 0 15px #00ff00, 0 0 30px #00ff00;
    border-radius: 2px;
    animation: scanAnimation 2s linear infinite;
    z-index: 15;
    display: none;
}

@keyframes scanAnimation {
    0% {
        top: 2px;
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
    100% {
        top: calc(300px - 5px); /* Высота video минус высота полоски */
        opacity: 1;
    }
}

/* Дополнительная анимация для video элемента */
.scanning {
    position: relative;
    overflow: hidden;
}

.scanning::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    border: 3px solid #00ff00;
    border-radius: 13px;
    animation: pulse 1.5s ease-in-out infinite;
    z-index: 5;
    pointer-events: none;
}

.controls {
    margin: 20px 0;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.camera-select {
    margin-top: 15px;
}

.camera-select label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}

.camera-select select {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    background: white;
}

.result-container,
.history-container {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.result-container h3,
.history-container h3 {
    color: #555;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

.result-box {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 15px;
    min-height: 80px;
    word-break: break-all;
    font-family: 'Courier New', monospace;
}

.result-box.success {
    background: #d4edda;
    border-color: #c3e6cb;
    color: #155724;
}

.result-box .placeholder {
    color: #6c757d;
    font-style: italic;
    text-align: center;
}

.history-list {
    max-height: 300px;
    overflow-y: auto;
    border: 2px solid #e9ecef;
    border-radius: 10px;
    padding: 15px;
    background: #f8f9fa;
}

.history-item {
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    word-break: break-all;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    position: relative;
}

.history-item:last-child {
    margin-bottom: 0;
}

.history-item .timestamp {
    font-size: 0.8rem;
    color: #6c757d;
    margin-bottom: 5px;
}

.history-item .content {
    color: #333;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #5a6268;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(108, 117, 125, 0.4);
}

footer {
    text-align: center;
    margin-top: 40px;
    color: white;
    opacity: 0.8;
}

/* Адаптивность */
@media (max-width: 768px) {
    main {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .controls {
        flex-direction: column;
        align-items: center;
    }
    
    .btn {
        width: 100%;
        max-width: 250px;
    }
    
    #video {
        max-width: 100%;
        height: 250px;
    }
    
    /* Адаптивная полоска сканирования для мобильных */
    @keyframes scanAnimation {
        0% {
            top: 2px;
            opacity: 1;
        }
        50% {
            opacity: 0.7;
        }
        100% {
            top: calc(250px - 5px); /* Высота video на мобильных минус высота полоски */
            opacity: 1;
        }
    }
}

/* Анимации */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0% { 
        box-shadow: 0 0 0 0 rgba(0, 255, 0, 0.7);
        border-color: #00ff00;
    }
    50% { 
        box-shadow: 0 0 0 10px rgba(0, 255, 0, 0);
        border-color: #00dd00;
    }
    100% { 
        box-shadow: 0 0 0 0 rgba(0, 255, 0, 0);
        border-color: #00ff00;
    }
}

.scanner-container,
.result-container,
.history-container {
    animation: fadeIn 0.6s ease-out;
}

/* iOS Safari specific styles */
@supports (-webkit-appearance: none) {
    /* Стили специально для iOS Safari */
    body {
        /* Исправляем проблему с viewport на iOS */
        min-height: -webkit-fill-available;
    }
    
    .container {
        /* Учитываем safe area на iPhone X и новее */
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    #video {
        /* Улучшенная производительность на iOS */
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        -webkit-perspective: 1000px;
        perspective: 1000px;
        /* Предотвращаем автоматический зум */
        -webkit-user-select: none;
        user-select: none;
    }
    
    .btn {
        /* Убираем стандартные стили кнопок iOS */
        -webkit-appearance: none;
        appearance: none;
        border-radius: 8px;
        /* Предотвращаем выделение текста */
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
    }
}
