* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Базовые стили для экранов */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: none;
    overflow: hidden;
    flex-direction: column;
}

.screen.hidden {
    display: none !important;
}

.screen.active {
    display: flex;
}

.screen.active.hidden {
    display: none !important;
}

/* Экран входа - центрирование */
#login-screen {
    background: linear-gradient(180deg, var(--dark-bg), #1A1A2E);
    justify-content: center;
    align-items: center;
}

:root {
    --primary: #5B9BD5;
    --primary-variant: #4A8AC4;
    --secondary: #7B68EE;
    --dark-bg: #121212;
    --surface: #1E1E1E;
    --surface-variant: #2A2A2A;
    --glass: rgba(30, 30, 30, 0.85);
    --success: #4CAF50;
    --error: #E53935;
    --warning: #FF9800;
    
    /* Акценты для секций */
    --anilibria-accent: #FF6B6B;
    --youtube-accent: #FF0000;
    --movies-accent: #FFD700;
    
    --text: #FFFFFF;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-tertiary: rgba(255, 255, 255, 0.4);
    
    /* Размеры */
    --padding-small: 8px;
    --padding-medium: 16px;
    --padding-large: 24px;
    --padding-xlarge: 32px;
    
    --radius-small: 8px;
    --radius-medium: 12px;
    --radius-large: 16px;
    --radius-xlarge: 24px;
    
    --button-height: 56px;
    --button-height-small: 48px;
    --icon-size: 24px;
    --icon-size-large: 32px;
    
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-large: 0 8px 24px rgba(0, 0, 0, 0.4);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--dark-bg);
    color: var(--text);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

html {
    height: -webkit-fill-available;
}

/* Экран входа - удалено дублирование, стили объединены выше */

.login-container {
    text-align: center;
    padding: 32px;
    width: 100%;
    max-width: 400px;
}

.logo-image {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto 24px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(91, 155, 213, 0.4);
}

.logo-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.login-container h1 {
    font-size: 32px;
    font-weight: bold;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 48px;
}

#username-input {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font-size: 16px;
    margin-bottom: 24px;
    outline: none;
}

#username-input:focus {
    box-shadow: 0 0 0 2px var(--primary);
}

#login-btn {
    width: 100%;
    height: var(--button-height);
    border: none;
    border-radius: var(--radius-large);
    background: linear-gradient(135deg, var(--primary), var(--primary-variant));
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--padding-small);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

#login-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

#login-btn:hover::before {
    left: 100%;
}

#login-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-large);
}

#login-btn:active {
    transform: translateY(0);
}

#login-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Главный экран */
#main-screen {
    /* Стили уже определены в .screen */
}

/* Адаптивный layout для планшетов и десктопов */
@media (min-width: 768px) {
    #main-screen.active {
        display: grid !important;
        grid-template-columns: 1fr 320px;
        grid-template-rows: auto 1fr auto;
        grid-template-areas:
            "topbar topbar"
            "video chat"
            "controls chat";
    }
    
    #main-screen.hidden {
        display: none !important;
    }
    
    #top-bar {
        grid-area: topbar;
    }
    
    #video-container {
        grid-area: video;
    }
    
    #sync-controls {
        grid-area: controls;
    }
    
    #chat-section {
        grid-area: chat;
        min-height: 0;
        border-left: 1px solid rgba(255, 255, 255, 0.1);
        border-top: none;
    }
    
    /* Оптимизация чата для планшетов */
    #chat-section-header {
        padding: 10px 16px;
        font-size: 15px;
        background: var(--dark-bg);
    }
    
    #chat-section-messages {
        padding: 12px;
        gap: 8px;
    }
    
    #chat-section-input {
        padding: 12px;
        background: var(--dark-bg);
    }
    
    /* Сообщения в боковом чате могут быть шире */
    .message {
        max-width: 90%;
    }
}

/* Для больших экранов - еще шире чат */
@media (min-width: 1200px) {
    #main-screen {
        grid-template-columns: 1fr 380px;
    }
    
    #chat-section-messages {
        padding: 16px;
        gap: 10px;
    }
    
    .message {
        max-width: 85%;
    }
}

#top-bar {
    display: flex;
    align-items: center;
    padding: 8px;
    background: var(--surface);
    gap: 8px;
    z-index: 100;
    flex-shrink: 0;
    flex-wrap: wrap;
    min-height: 56px;
    position: relative;
    pointer-events: all; /* Всегда кликабельны */
}

@media (max-width: 768px) {
    #top-bar {
        padding: 6px;
        gap: 6px;
    }
}

@media (max-width: 480px) {
    #top-bar {
        padding: 4px;
        gap: 4px;
    }
    
    #url-input {
        font-size: 12px;
        padding: 8px 12px;
    }
    
    .icon-btn {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }
}

#url-input {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 20px;
    background: var(--dark-bg);
    color: var(--text);
    font-size: 14px;
    outline: none;
}

#url-input:focus {
    box-shadow: 0 0 0 2px var(--primary);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--surface-variant);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 100; /* ВЫШЕ canvas (z-index: 10) */
}

.icon-btn:hover {
    background: var(--primary);
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(91, 155, 213, 0.4);
}

.icon-btn:active {
    transform: scale(0.95);
}

.badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: #E91E63;
    color: white;
    font-size: 11px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 4px;
}

.badge.hidden {
    display: none;
}


/* Видео контейнер */
#video-container {
    width: 100%;
    aspect-ratio: 16 / 9;
    position: relative;
    background: #000;
    flex-shrink: 0;
    max-height: 50dvh; /* dvh адаптируется под клавиатуру */
}

/* На планшетах и десктопах - больше места для видео */
@media (min-width: 768px) {
    #video-container {
        max-height: none;
        height: 100%;
        aspect-ratio: auto; /* Растягиваем на всю высоту */
    }
}

@media (max-width: 768px) {
    #video-container {
        max-height: 40dvh;
    }
}

@media (max-width: 480px) {
    #video-container {
        max-height: 35dvh;
    }
}

#youtube-player {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

#hls-player {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    object-fit: contain;
    background: #000;
}

#video-info {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    z-index: 30;
    pointer-events: none;
}

#video-title {
    color: white;
    font-size: 14px;
    font-weight: bold;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#video-episode {
    color: rgba(255,255,255,0.8);
    font-size: 12px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

/* Кнопка Picture-in-Picture */
.pip-button {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 40;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pip-button:hover {
    background: rgba(91, 155, 213, 0.9);
    border-color: rgba(91, 155, 213, 1);
    transform: scale(1.1);
}

.pip-button:active {
    transform: scale(0.95);
}

.pip-button.active {
    background: rgba(91, 155, 213, 1);
    border-color: rgba(91, 155, 213, 1);
}

/* Canvas для рисования на весь экран */
#drawing-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10; /* НИЖЕ всех кнопок */
    pointer-events: none !important; /* НИКОГДА не ловит события - рисование через document */
    cursor: default;
}

/* Когда активен - только меняем курсор, НЕ включаем pointer-events */
#drawing-canvas.active {
    cursor: crosshair;
}

/* Панель инструментов рисования */
.draw-tools {
    position: absolute;
    top: 60px; /* Под кнопкой рисования на мобильном */
    left: 50%;
    transform: translateX(-50%);
    z-index: 150; /* ВЫШЕ canvas (z-index: 10) */
    background: rgba(30, 30, 40, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 16px;
    padding: 12px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    animation: slideDown 0.2s ease-out;
    pointer-events: all !important;
    max-width: 90vw;
}

/* На десктопе (>= 768px) - показываем инструменты ВЫШЕ кнопки */
@media (min-width: 768px) {
    .draw-tools {
        top: auto;
        bottom: 60px; /* Над кнопкой рисования */
        animation: slideUp 0.2s ease-out;
    }
    
    @keyframes slideUp {
        from {
            opacity: 0;
            transform: translateX(-50%) translateY(10px);
        }
        to {
            opacity: 1;
            transform: translateX(-50%) translateY(0);
        }
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Группа с выпадающим меню */
.draw-tool-group {
    position: relative;
}

/* Выпадающее меню толщины */
.thickness-popup {
    position: absolute;
    top: 55px; /* Вниз от кнопки на мобильном */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 30, 40, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 12px;
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 250; /* ЕЩЕ ВЫШЕ для popup */
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    pointer-events: all !important;
}

.thickness-popup.hidden {
    display: none;
}

/* На десктопе (>= 768px) - popup открывается ВВЕРХ */
@media (min-width: 768px) {
    .thickness-popup {
        top: auto;
        bottom: 55px; /* Вверх от кнопки */
    }
}

/* Единый стиль для всех кнопок */
.draw-btn-tool {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: all !important;
}

.draw-btn-tool:hover {
    transform: scale(1.1);
    border-color: white;
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.3);
}

.draw-btn-tool.active {
    background: linear-gradient(135deg, #FFC107, #FF9800);
    border-color: #FFC107;
    box-shadow: 0 0 16px rgba(255, 193, 7, 0.6);
}

/* Кнопки которые должны быть поверх canvas */
.draw-btn-top {
    z-index: 250 !important;
    position: relative;
    pointer-events: all !important;
}

/* Сетка цветов 4x4 */
.color-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

/* Цветные кнопки */
.draw-color {
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.draw-color.active {
    border-width: 3px;
    border-color: white;
    box-shadow: 0 0 16px rgba(255, 255, 255, 0.8);
    transform: scale(1.1);
}

/* Разделитель */
.draw-divider {
    width: 1px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    margin: 0 4px;
}

/* Кнопка очистки */
.draw-clear {
    background: linear-gradient(135deg, #F44336, #D32F2F) !important;
    border-color: rgba(244, 67, 54, 0.5) !important;
}

.draw-clear:hover {
    background: linear-gradient(135deg, #E53935, #C62828) !important;
    box-shadow: 0 0 16px rgba(244, 67, 54, 0.6) !important;
}.draw-clear:hover {
    background: linear-gradient(135deg, #FF5252, #F44336);
    box-shadow: 0 0 12px rgba(244, 67, 54, 0.5);
}

/* Кнопки синхронизации */
#sync-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 10px;
    background: var(--surface);
    flex-shrink: 0;
    position: relative;
    z-index: 100; /* Выше canvas */
    pointer-events: all !important; /* ВСЕГДА кликабельны */
}

.sync-btn {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s, background 0.2s, border 0.2s;
    pointer-events: all !important; /* ВСЕГДА кликабельны */
    position: relative;
    z-index: 100; /* ВЫШЕ canvas (z-index: 10) */
}

.sync-btn:active {
    transform: scale(0.9);
}

.sync-btn:hover {
    background: #4A8AC4;
}

.sync-btn.active {
    background: linear-gradient(135deg, #FFC107, #FF9800);
    box-shadow: 0 0 12px rgba(255, 193, 7, 0.5);
}

/* Кнопки перемотки - белая обводка */
#seek-back-btn,
#seek-forward-btn {
    background: transparent;
    border: 2px solid white;
}

#seek-back-btn:hover,
#seek-forward-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: white;
}

/* Кнопка реакции - белая обводка */
#reaction-btn {
    background: transparent;
    border: 2px solid white;
}

#reaction-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: white;
}

/* Кнопка рисования - без фона */
#draw-btn {
    background: transparent;
    border: 2px solid white;
}

#draw-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: white;
}

#draw-btn.active {
    background: linear-gradient(135deg, #FFC107, #FF9800);
    border-color: #FFC107;
    box-shadow: 0 0 12px rgba(255, 193, 7, 0.5);
}

#play-pause-btn {
    width: 56px;
    height: 56px;
    font-size: 24px;
    background: transparent;
    border: 2px solid white;
}

#play-pause-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: white;
}

#no-video {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-secondary);
    z-index: 2;
    pointer-events: none;
}

#no-video.hidden {
    display: none;
}

#no-video .info-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

#no-video p {
    margin-bottom: 8px;
}

#no-video .hint {
    font-size: 12px;
    opacity: 0.6;
}

/* Кнопки управления - удалены */

/* Панель реакций - над кнопками синхронизации */
#reaction-picker {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--glass);
    border-radius: 24px;
    padding: 8px;
    display: flex;
    gap: 4px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 60;
}

#sync-controls {
    position: relative;
}

#reaction-picker.hidden {
    display: none;
}

.reaction-btn {
    background: var(--glass) !important;
}

.reaction-item {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: transparent;
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.2s;
}

.reaction-item:hover {
    transform: scale(1.2);
}

/* Реакции overlay */
#reactions-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 40;
    pointer-events: none;
    overflow: hidden;
}

.reaction-bubble {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.9), rgba(118, 75, 162, 0.9));
    border-radius: 20px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    animation: reactionFloat 3s ease-out forwards;
}

@keyframes reactionFloat {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-100px) scale(0.5); }
}

/* Снегопад смайликов */
.reaction-snowflake {
    position: absolute;
    font-size: 3rem;
    pointer-events: none;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
    will-change: transform, opacity;
    z-index: 1000;
}

/* Уведомление */
#user-notification {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(76, 175, 80, 0.9);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    z-index: 40;
}

#user-notification.hidden {
    display: none;
}

/* Панель чата - встроенная снизу */
#chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    min-height: 120px;
    overflow: hidden;
    position: relative;
    z-index: 5; /* Под canvas (z-index: 10) */
}

/* Отключаем взаимодействие с чатом во время рисования */
#chat-section.drawing-active {
    pointer-events: none !important;
    user-select: none !important;
}

#chat-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 14px;
    font-weight: bold;
    flex-shrink: 0;
}

#chat-section-messages {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#chat-section-input {
    display: flex;
    padding: 8px;
    gap: 8px;
    background: var(--dark-bg);
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
}

#chat-input-inline {
    flex: 1;
    min-width: 0;
    padding: 10px 14px;
    border: none;
    border-radius: 20px;
    background: var(--surface);
    color: var(--text);
    font-size: 16px;
    outline: none;
    -webkit-appearance: none;
}

#chat-input-inline:focus {
    box-shadow: 0 0 0 2px var(--primary);
}

#send-btn-inline {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

/* Фикс для мобильной клавиатуры */
@supports (height: 100dvh) {
    .screen {
        height: 100dvh;
    }
}

/* Панель чата - всплывающая (для планшета) */
#chat-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    display: flex;
    flex-direction: column;
    z-index: 200;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

#chat-panel:not(.hidden) {
    transform: translateY(0);
}

#chat-panel.hidden {
    transform: translateY(100%);
}

#chat-header, #users-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 18px;
    font-weight: bold;
    flex-shrink: 0;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    word-wrap: break-word;
}

.message.own {
    align-self: flex-end;
    background: var(--primary);
    border-bottom-right-radius: 4px;
}

.message.other {
    align-self: flex-start;
    background: var(--dark-bg);
    border-bottom-left-radius: 4px;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.message-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 10px;
    font-weight: bold;
}

.message-user {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
}

.message-link {
    color: #90CAF9;
    text-decoration: underline;
}

.message-time {
    color: #FFD700; /* Золотой цвет для лучшей видимости */
    font-weight: 600;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(255, 215, 0, 0.15);
    transition: all 0.2s;
    display: inline-block;
    text-decoration: underline;
    text-decoration-style: dotted;
}

.message-time:hover {
    background: rgba(255, 215, 0, 0.3);
    transform: scale(1.05);
}

.message-time:active {
    transform: scale(0.95);
}

#chat-input-container {
    display: flex;
    padding: 12px;
    gap: 8px;
    background: var(--dark-bg);
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: 24px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    outline: none;
}

#send-btn {
    background: var(--primary);
}

/* Панель пользователей */
#users-panel {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    max-height: 50%;
    background: var(--surface);
    border-radius: 0 0 20px 20px;
    display: flex;
    flex-direction: column;
    z-index: 200;
}

#users-panel.hidden {
    display: none;
}

#users-list {
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.user-item {
    display: flex;
    align-items: center;
    padding: 12px;
    background: var(--dark-bg);
    border-radius: 12px;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    font-weight: bold;
}

.user-info { flex: 1; }
.user-name { font-size: 15px; font-weight: 500; }
.user-status { font-size: 12px; }
.user-status.online { color: var(--success); }
.user-status.offline { color: var(--text-secondary); }
.user-indicator { width: 10px; height: 10px; border-radius: 50%; }
.user-indicator.online { background: var(--success); }
.user-indicator.offline { background: gray; }

/* Цвета аватарок */
.avatar-0 { background: #E91E63; }
.avatar-1 { background: #9C27B0; }
.avatar-2 { background: #673AB7; }
.avatar-3 { background: #3F51B5; }
.avatar-4 { background: #2196F3; }
.avatar-5 { background: #00BCD4; }
.avatar-6 { background: #009688; }
.avatar-7 { background: #4CAF50; }
.avatar-8 { background: #FF9800; }
.avatar-9 { background: #FF5722; }
.avatar-10 { background: #795548; }
.avatar-11 { background: #607D8B; }

/* Планшет */
@media (min-width: 800px) {
    #chat-panel {
        top: 56px;
        right: 0;
        bottom: 0;
        left: auto;
        width: 350px;
        height: auto;
        border-radius: 20px 0 0 20px;
    }
    
    #users-panel {
        right: 0;
        left: auto;
        width: 280px;
    }
}

/* Safe area для iPhone */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    #chat-section-input {
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }
    
    #chat-input-container {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    
    #controls-right {
        bottom: calc(16px + env(safe-area-inset-bottom));
    }
}

.hidden { display: none !important; }

/* Экран списка комнат */
#rooms-screen {
    background: linear-gradient(180deg, var(--dark-bg), #1A1A2E);
}

.rooms-header {
    background: linear-gradient(135deg, #667eea, #764ba2);
    padding-top: env(safe-area-inset-top, 0);
}

.rooms-header-content {
    padding: 20px;
}

.rooms-header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}

.rooms-header-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.rooms-header-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

.rooms-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.rooms-header-info h1 {
    font-size: 28px;
    font-weight: bold;
    color: white;
    margin-bottom: 4px;
}

.rooms-subtitle {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
}

/* Кнопки действий в header */
.rooms-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.action-btn {
    flex: 1;
    height: 52px;
    border-radius: 16px;
    border: none;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.action-btn .action-icon {
    font-size: 20px;
}

.create-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.create-btn:active {
    transform: scale(0.98);
}

.join-btn {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    backdrop-filter: blur(10px);
}

.join-btn:active {
    transform: scale(0.98);
}


.fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: white;
    color: #667eea;
    border: none;
    font-size: 32px;
    font-weight: 300;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}

.fab:active {
    transform: scale(0.95);
}

.rooms-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
}

.rooms-tab {
    flex: 1;
    padding: 12px 16px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: color 0.2s;
}

.rooms-tab.active {
    color: white;
    font-weight: 600;
}

.rooms-tab.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 3px;
    background: white;
    border-radius: 3px 3px 0 0;
}

.tab-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
}

.rooms-tab.active .tab-count {
    background: rgba(255, 255, 255, 0.3);
}

.rooms-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.rooms-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.room-card {
    background: var(--surface);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.2s;
}

.room-card:active {
    transform: scale(0.98);
}

.room-card-accent {
    height: 4px;
    background: linear-gradient(90deg, #667eea, #764ba2);
}

.room-card-content {
    padding: 20px;
}

.room-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.room-card-main {
    display: flex;
    gap: 16px;
    flex: 1;
}

.room-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.room-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.room-info {
    flex: 1;
    min-width: 0;
}

.room-name {
    font-size: 18px;
    font-weight: bold;
    color: white;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.room-creator {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
}

.room-creator-icon {
    font-size: 14px;
}

.room-delete-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: #E53935;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.2s;
}

.room-delete-btn:hover {
    background: rgba(229, 57, 53, 0.1);
}

.room-chips {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.room-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
}

.room-chip.online {
    background: rgba(76, 175, 80, 0.2);
    color: #4CAF50;
}

.room-chip.offline {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.7);
}

.room-chip.time {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.7);
}

.room-chip-icon {
    font-size: 16px;
}

.room-join-btn {
    width: 100%;
    height: 48px;
    border-radius: 12px;
    background: var(--primary);
    color: white;
    border: none;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

.room-join-btn:hover {
    background: #4A8AC4;
}

.rooms-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.empty-icon {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 24px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.empty-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.rooms-empty h2 {
    font-size: 20px;
    font-weight: bold;
    color: white;
    margin-bottom: 8px;
}

.rooms-empty p {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 24px;
}

/* Простой список комнат */
.room-item {
    background: var(--surface);
    border-radius: 16px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.room-item .room-info {
    flex: 1;
    min-width: 0;
}

.room-item .room-name {
    font-size: 16px;
    font-weight: 600;
    color: white;
    margin-bottom: 4px;
}

.room-item .room-code {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
    font-family: monospace;
}

.room-item .room-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.room-item .btn-primary {
    padding: 10px 16px;
    height: auto;
    font-size: 14px;
}

.room-item .btn-danger {
    padding: 10px;
    width: 40px;
    height: 40px;
    font-size: 18px;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 14px;
}


/* Диалоги */
.dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.dialog-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.dialog-content {
    position: relative;
    background: var(--surface);
    border-radius: 20px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* Кнопка закрытия диалога (крестик) */
.dialog-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
}

.dialog-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.dialog-close:active {
    transform: scale(0.95);
}

.dialog-icon {
    font-size: 48px;
    text-align: center;
    margin-bottom: 16px;
}

.dialog-content h2 {
    font-size: 20px;
    font-weight: bold;
    color: white;
    margin-bottom: 8px;
    text-align: center;
}

.dialog-subtitle {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 20px;
    text-align: center;
}

.dialog-content input {
    width: 100%;
    padding: 14px 16px;
    border: none;
    border-radius: 12px;
    background: var(--dark-bg);
    color: white;
    font-size: 16px;
    margin-bottom: 20px;
    outline: none;
}

.dialog-content input:focus {
    box-shadow: 0 0 0 2px var(--primary);
}

.dialog-buttons {
    display: flex;
    gap: 12px;
}

.btn-primary, .btn-secondary, .btn-danger {
    flex: 1;
    padding: 14px 20px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: opacity 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.btn-danger {
    background: #E53935;
    color: white;
}

/* Кнопка выхода из комнаты */
#leave-room-btn {
    background: rgba(229, 57, 53, 0.2);
    color: #E53935;
    font-size: 20px;
    font-weight: bold;
}

.room-name-badge {
    padding: 8px 16px;
    background: rgba(91, 155, 213, 0.2);
    border-radius: 20px;
    color: var(--primary);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

/* Кнопки действий */
.rooms-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.action-btn {
    flex: 1;
    padding: 16px 20px;
    border: none;
    border-radius: 16px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s;
    animation: fadeInUp 0.5s ease-out 0.3s backwards;
}

.create-btn {
    background: white;
    color: #667eea;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.create-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.join-btn {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.join-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

.action-icon {
    font-size: 20px;
}

/* Диалог с кодом */
.success-icon {
    font-size: 64px;
    text-align: center;
    margin-bottom: 16px;
    animation: scaleIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.room-code-display {
    background: var(--dark-bg);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 24px;
    text-align: center;
}

.code-label {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.code-value {
    font-size: 32px;
    font-weight: bold;
    color: var(--primary);
    letter-spacing: 4px;
    margin-bottom: 16px;
    font-family: 'Courier New', monospace;
    text-shadow: 0 2px 8px rgba(91, 155, 213, 0.3);
}

.copy-btn {
    width: 100%;
    padding: 12px 20px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    background: transparent;
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s;
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary);
}

.copy-btn.copied {
    background: rgba(76, 175, 80, 0.2);
    border-color: #4CAF50;
    color: #4CAF50;
}

.copy-icon {
    font-size: 18px;
}

.full-width {
    width: 100%;
}

/* Вход по коду */
.code-input-wrapper {
    margin-bottom: 12px;
}

.error-message {
    color: #E53935;
    font-size: 13px;
    text-align: center;
    margin-bottom: 16px;
    padding: 8px 12px;
    background: rgba(229, 57, 53, 0.1);
    border-radius: 8px;
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

/* Карточка комнаты с кодом */
.room-code-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(91, 155, 213, 0.2);
    border-radius: 12px;
    font-size: 13px;
    font-weight: bold;
    color: var(--primary);
    font-family: 'Courier New', monospace;
    letter-spacing: 1px;
    margin-top: 8px;
}

.room-code-icon {
    font-size: 14px;
}


/* Sources dropdown */
.sources-dropdown {
    position: relative;
}

.sources-btn {
    font-size: 13px !important;
    font-weight: bold;
    padding: 0 12px !important;
    background: linear-gradient(135deg, #667EEA, #764BA2) !important;
}

.sources-menu {
    position: absolute;
    top: 100%;
    right: -40px;
    margin-top: 8px;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    min-width: 180px;
    z-index: 1000;
    overflow: hidden;
}

.source-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    color: white;
    font-size: 15px;
    cursor: pointer;
    transition: background 0.2s;
}

.source-item:hover {
    background: rgba(255,255,255,0.1);
}

.source-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.source-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    margin-left: auto;
}

.source-badge.sync-full {
    background: rgba(76, 175, 80, 0.2);
    color: #4CAF50;
}

.source-badge.sync-partial {
    background: rgba(255, 193, 7, 0.2);
    color: #FFC107;
}

.source-badge.sync-none {
    background: rgba(244, 67, 54, 0.2);
    color: #F44336;
}

.source-hint {
    padding: 12px 16px;
    background: rgba(255, 193, 7, 0.1);
    border-top: 1px solid rgba(255, 193, 7, 0.2);
    color: rgba(255, 193, 7, 0.9);
    font-size: 12px;
    text-align: center;
    line-height: 1.4;
}

/* Search screens */
#movies-screen,
#youtube-screen,
#anilibria-screen {
    flex-direction: column !important;
    background: var(--dark-bg);
}

#movies-screen.active,
#youtube-screen.active,
#anilibria-screen.active {
    display: flex;
    flex-direction: column;
}

.search-screen-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 16px;
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top));
    background: var(--surface);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
    width: 100%;
}

.back-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.back-btn:hover {
    opacity: 0.8;
}

.search-container {
    padding: 16px;
    flex-shrink: 0;
}

.search-container input {
    width: 100%;
    padding: 12px 16px;
    background: var(--surface);
    border: 2px solid transparent;
    border-radius: 12px;
    color: white;
    font-size: 15px;
    transition: border-color 0.2s;
}

.search-container input:focus {
    outline: none;
    border-color: var(--primary);
}

.loading-indicator {
    text-align: center;
    padding: 20px;
    color: rgba(255,255,255,0.6);
}

.no-results {
    text-align: center;
    padding: 40px 20px;
    color: rgba(255,255,255,0.5);
    font-size: 16px;
}

/* Movie results grid */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    grid-auto-rows: min-content; /* Строки не сжимаются */
    gap: 12px;
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}

/* Mobile responsive */
@media (max-width: 600px) {
    .results-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        grid-auto-rows: min-content; /* Строки не сжимаются */
        gap: 8px;
        padding: 8px;
    }
    
    .movie-poster {
        height: 280px !important;
        min-height: 280px !important;
    }
}

.results-list {
    overflow-y: auto;
    flex: 1;
    padding: 16px;
}

.movie-card {
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.movie-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.3);
}

.movie-card:hover .movie-details-overlay {
    opacity: 1;
    pointer-events: auto;
}

.movie-details-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, 
        rgba(0, 0, 0, 0.7) 0%,
        rgba(0, 0, 0, 0.85) 50%,
        rgba(0, 0, 0, 0.95) 100%
    );
    backdrop-filter: blur(10px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 2;
}

.movie-details-content {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

.movie-details-content::-webkit-scrollbar {
    width: 0px;
    display: none;
}

.movie-details-content::-webkit-scrollbar-track {
    background: transparent;
}

.movie-details-content::-webkit-scrollbar-thumb {
    background: transparent;
}

.movie-details-title {
    font-size: 16px;
    font-weight: 700;
    color: white;
    margin: 0 0 4px 0;
    line-height: 1.3;
}

.movie-details-original {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
    margin: 0 0 8px 0;
    font-style: italic;
}

.movie-details-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.meta-item {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    background: rgba(102, 126, 234, 0.2);
    padding: 4px 8px;
    border-radius: 6px;
    white-space: nowrap;
}

.movie-details-genres,
.movie-details-countries {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    margin: 0 0 6px 0;
    line-height: 1.4;
}

.movie-details-description {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.5;
    margin: 0 0 12px 0;
    flex: 1;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
}

.movie-details-action {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    color: white;
    margin-top: auto;
    width: fit-content;
    align-self: center;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
}

.movie-details-action:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.6);
}

.play-icon {
    font-size: 16px;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.movie-poster {
    width: 100%;
    height: 220px; /* Фиксированная высота для читаемости */
    object-fit: cover;
    object-position: center;
    display: block;
    background: #1a1a1a;
}

.movie-poster-fallback {
    width: 100%;
    aspect-ratio: 2/3; /* Стандартное соотношение для постеров фильмов */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
}

.fallback-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.9;
}

.fallback-title {
    color: white;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.movie-info {
    padding: 12px;
}

.movie-title {
    font-size: 14px;
    font-weight: bold;
    color: white;
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.movie-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: rgba(255,255,255,0.6);
}

.movie-rating {
    color: #FFD700;
    font-weight: bold;
}

/* YouTube results list */
.results-list {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.youtube-card {
    display: flex;
    gap: 12px;
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.youtube-card:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.youtube-thumbnail {
    position: relative;
    width: 160px;
    aspect-ratio: 16/9; /* YouTube стандарт */
    flex-shrink: 0;
}

.youtube-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.youtube-duration {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
}

.youtube-info {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.youtube-title {
    font-size: 14px;
    font-weight: 500;
    color: white;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.youtube-channel {
    font-size: 12px;
    color: rgba(255,255,255,0.6);
}

/* Mobile responsive */
@media (max-width: 600px) {
    .results-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 8px;
        padding: 8px;
    }
    
    /* Постеры уже адаптивные через aspect-ratio */
    
    .youtube-thumbnail {
        width: 120px;
        /* aspect-ratio уже установлен выше */
    }
}


/* AniLibria styles */
.anime-card {
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.anime-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.3);
}

.anime-poster {
    width: 100%;
    aspect-ratio: 2/3; /* Стандартное соотношение для постеров аниме */
    object-fit: cover;
}

.anime-info {
    padding: 12px;
}

.anime-title {
    font-size: 14px;
    font-weight: bold;
    color: white;
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

.anime-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: rgba(255,255,255,0.6);
}

.episodes-header {
    padding: 16px;
    background: var(--surface);
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.episodes-header h3 {
    margin: 12px 0 0 0;
    color: white;
    font-size: 18px;
}

.episodes-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 140px));
    gap: 12px;
    padding: 16px;
    justify-content: start;
}

/* Translations list */
.translations-list {
    padding: 16px;
}

.translations-list h4 {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.translation-btn {
    background: linear-gradient(135deg, var(--surface) 0%, var(--surface-variant) 100%);
    color: white;
    border: 2px solid var(--primary);
    padding: 16px 20px;
    border-radius: var(--radius-medium);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: left;
    width: 100%;
    margin-bottom: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.translation-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    border-color: var(--secondary);
}

.translation-btn:active {
    transform: translateY(0);
}

.kodik-badge {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 4px rgba(76, 175, 80, 0.3);
}

.translation-name {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 8px 0 0 0;
    padding: 0 16px;
}

.episode-btn {
    background: linear-gradient(135deg, var(--surface) 0%, var(--surface-variant) 100%);
    color: white;
    border: 2px solid var(--primary);
    padding: 16px 12px;
    border-radius: var(--radius-medium);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    position: relative;
    z-index: 1;
}

.episode-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    opacity: 0;
    transition: opacity 0.3s;
    border-radius: var(--radius-medium);
    z-index: -1;
}


.episode-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(91, 155, 213, 0.4);
}

.episode-btn:hover::before {
    opacity: 1;
}

.episode-btn:active {
    transform: translateY(0);
}

@media (max-width: 600px) {
    .anime-poster {
        height: 180px;
    }
    
    .episodes-list {
        grid-template-columns: repeat(auto-fill, minmax(110px, 110px));
        gap: 8px;
        padding: 12px;
    }
    
    .episode-btn {
        padding: 12px 8px;
        font-size: 13px;
    }
}

/* Диалог выбора источника видео */
.video-source-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease;
}

.video-source-dialog {
    background: #1A1F3A;
    border-radius: 20px;
    padding: 24px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

.dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}

.dialog-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: bold;
    color: white;
}

.movie-title-small {
    margin: 4px 0 0 0;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
}

.close-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.sources-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.source-item {
    background: #0A0E27;
    border-radius: 12px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
}

.source-item:hover {
    background: #0F1535;
    transform: translateY(-2px);
}

.source-info {
    flex: 1;
}

.source-name {
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 4px;
}

.source-translation {
    font-size: 13px;
    color: #FFB74D;
    font-weight: 500;
    margin-bottom: 2px;
}

.source-language {
    font-size: 13px;
    color: #9C27B0;
    font-weight: 500;
    margin-bottom: 2px;
}

.source-quality {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
}

.source-quality span {
    color: #4CAF50;
    font-weight: 500;
}

.dialog-footer {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.dialog-hint {
    margin: 0;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    text-align: center;
    line-height: 1.4;
}

.play-btn {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #667EEA 0%, #764BA2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* ========================================
   ЕДИНАЯ НИЖНЯЯ НАВИГАЦИЯ (как в Android)
   ======================================== */

.filmach-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 80px;
    background: var(--surface);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    padding: 0 var(--padding-small);
    z-index: 1000;
}

.filmach-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--padding-small);
    border-radius: var(--radius-medium);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex: 1;
    max-width: 100px;
    position: relative;
}

.filmach-nav-item:active {
    transform: scale(0.95);
}

.filmach-nav-icon-wrapper {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 4px;
}

.filmach-nav-item.active .filmach-nav-icon-wrapper {
    transform: scale(1.1);
}

.filmach-nav-icon {
    font-size: var(--icon-size);
    transition: all 0.3s;
}

.filmach-nav-label {
    font-size: 12px;
    font-weight: 400;
    transition: all 0.3s;
    text-align: center;
}

.filmach-nav-item.active .filmach-nav-label {
    font-weight: 600;
}

/* Цвета для разных секций */
.filmach-nav-item[data-section="rooms"] .filmach-nav-icon {
    color: var(--text-secondary);
}

.filmach-nav-item[data-section="rooms"].active .filmach-nav-icon {
    color: var(--primary);
}

.filmach-nav-item[data-section="rooms"].active .filmach-nav-icon-wrapper {
    background: rgba(91, 155, 213, 0.2);
}

.filmach-nav-item[data-section="rooms"].active .filmach-nav-label {
    color: var(--primary);
}

.filmach-nav-item[data-section="anilibria"] .filmach-nav-icon {
    color: var(--text-secondary);
}

.filmach-nav-item[data-section="anilibria"].active .filmach-nav-icon {
    color: var(--anilibria-accent);
}

.filmach-nav-item[data-section="anilibria"].active .filmach-nav-icon-wrapper {
    background: rgba(255, 107, 107, 0.2);
}

.filmach-nav-item[data-section="anilibria"].active .filmach-nav-label {
    color: var(--anilibria-accent);
}

.filmach-nav-item[data-section="movies"] .filmach-nav-icon {
    color: var(--text-secondary);
}

.filmach-nav-item[data-section="movies"].active .filmach-nav-icon {
    color: var(--movies-accent);
}

.filmach-nav-item[data-section="movies"].active .filmach-nav-icon-wrapper {
    background: rgba(255, 215, 0, 0.2);
}

.filmach-nav-item[data-section="movies"].active .filmach-nav-label {
    color: var(--movies-accent);
}

.filmach-nav-item[data-section="youtube"] .filmach-nav-icon {
    color: var(--text-secondary);
}

.filmach-nav-item[data-section="youtube"].active .filmach-nav-icon {
    color: var(--youtube-accent);
}

.filmach-nav-item[data-section="youtube"].active .filmach-nav-icon-wrapper {
    background: rgba(255, 0, 0, 0.2);
}

.filmach-nav-item[data-section="youtube"].active .filmach-nav-label {
    color: var(--youtube-accent);
}

/* Неактивные элементы */
.filmach-nav-item:not(.active) .filmach-nav-label {
    color: var(--text-secondary);
}

/* Анимация при переключении */
@keyframes navBounce {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
}

.filmach-nav-item.active .filmach-nav-icon-wrapper {
    animation: navBounce 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Адаптация контента под нижнюю навигацию */
.main-content-with-nav {
    padding-bottom: 80px;
}


/* Модальное окно с информацией о фильме */
.movie-details-content {
    max-width: 900px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 0;
}

.movie-details-layout {
    display: flex;
    gap: 24px;
    padding: 24px;
}

.movie-details-poster {
    flex-shrink: 0;
    width: 300px;
}

.movie-details-poster img {
    width: 100%;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.movie-details-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.movie-details-info h2 {
    margin: 0;
    font-size: 28px;
    color: var(--text-primary);
}

.movie-meta {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 14px;
    color: var(--text-secondary);
}

.movie-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.movie-genres {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.movie-genres span {
    padding: 6px 12px;
    background: rgba(103, 126, 234, 0.2);
    border-radius: 16px;
    font-size: 13px;
    color: #667eea;
}

.movie-description {
    line-height: 1.6;
    color: var(--text-secondary);
}

.movie-countries {
    font-size: 14px;
    color: var(--text-secondary);
}

.watch-btn {
    align-self: flex-start;
    padding: 12px 32px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.watch-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(103, 126, 234, 0.4);
}

.watch-btn i {
    font-size: 20px;
}

@media (max-width: 768px) {
    .movie-details-layout {
        flex-direction: column;
        padding: 16px;
    }
    
    .movie-details-poster {
        width: 100%;
        max-width: 300px;
        margin: 0 auto;
    }
    
    .movie-details-info h2 {
        font-size: 22px;
    }
}

/* Модальное окно с информацией о фильме */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
    backdrop-filter: blur(5px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(135deg, #1a1f3a 0%, #0f1428 100%);
    border-radius: 20px;
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

.movie-details-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 30px;
}

.movie-details-header {
    display: flex;
    gap: 20px;
}

.movie-details-poster {
    width: 200px;
    height: 300px;
    object-fit: cover;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.movie-details-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.movie-details-title {
    font-size: 28px;
    font-weight: bold;
    color: white;
    margin: 0;
}

.movie-details-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    font-size: 16px;
    color: rgba(255, 255, 255, 0.8);
}

.movie-details-meta i {
    margin-right: 5px;
}

.movie-details-genres {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.movie-details-genres span {
    background: rgba(0, 255, 255, 0.1);
    color: #00FFFF;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 14px;
    border: 1px solid rgba(0, 255, 255, 0.3);
}

.movie-details-description {
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.6;
    font-size: 15px;
}

.movie-details-countries {
    color: rgba(255, 255, 255, 0.8);
    font-size: 15px;
}

.movie-details-countries i {
    margin-right: 5px;
}

.movie-details-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.btn-watch {
    background: linear-gradient(135deg, #00FFFF 0%, #00CCCC 100%);
    color: #000;
    border: none;
    padding: 15px 40px;
    border-radius: 12px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-watch:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(0, 255, 255, 0.3);
}

.btn-watch i {
    font-size: 20px;
}

/* Адаптивность для мобильных */
@media (max-width: 768px) {
    .modal {
        padding: 10px;
    }
    
    .movie-details-content {
        padding: 20px;
    }
    
    .movie-details-header {
        flex-direction: column;
        align-items: center;
    }
    
    .movie-details-poster {
        width: 150px;
        height: 225px;
    }
    
    .movie-details-title {
        font-size: 22px;
        text-align: center;
    }
    
    .movie-details-meta {
        justify-content: center;
        font-size: 14px;
    }
    
    .btn-watch {
        width: 100%;
        justify-content: center;
    }
}


/* Anime365 Tabs */
.tabs-container {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(255,255,255,0.05);
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.tab-btn {
    flex: 1;
    padding: 10px 16px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: rgba(255,255,255,0.7);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn:hover {
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.9);
}

.tab-btn.active {
    background: linear-gradient(135deg, #FF9800, #F57C00);
    border-color: #FF9800;
    color: white;
}

.tab-content {
    display: block;
}

.tab-content.hidden {
    display: none;
}

.episode-btn {
    padding: 12px 16px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: white;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.episode-btn:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.2);
    transform: translateX(4px);
}

.genre-tag {
    display: inline-block;
    padding: 4px 12px;
    background: rgba(255,255,255,0.1);
    border-radius: 12px;
    font-size: 12px;
    margin-right: 6px;
    margin-bottom: 6px;
}
