/* ===== ОСНОВНЫЕ НАСТРОЙКИ ===== */
:root {
    --bg: #0a0c10;
    --surface: #111317;
    --surface--min: rgba(17, 19, 23, 0.8); /* полупрозрачный */
    --card: #1a1c22;
    --text: #ffffff;
    --text-soft: #a0a3b1;
    --text-muted: #6b6f7c;
    --accent: #ffd966;
    --border: #2a2d36;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    --radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 24px;
    width: 100%;
}

/* ===== ШАПКА ===== */
.header {
    flex-shrink: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 12px 0;
    flex-wrap: wrap;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    font-size: 1.4rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent), #4a9eff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
}

.nav-back-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.95rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
}

.nav-back-btn:hover {
    background: var(--surface);
}

/* Поиск */
.search {
    flex: 1;
    max-width: 400px;
    position: relative;
}

.search-input {
    width: 100%;
    padding: 8px 36px 8px 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 30px;
    color: var(--text);
    font-size: 0.95rem;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
}

.search-clear {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    display: none;
    padding: 4px;
}

.search-clear.visible {
    display: block;
}

.search-clear:hover {
    color: var(--text);
}

/* Фильтры */
.filters {
    display: flex;
    gap: 8px;
}

.filter {
    position: relative;
}

.filter-btn {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text-soft);
    padding: 8px 12px;
    border-radius: 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.9rem;
    white-space: nowrap;
}

.filter-btn:hover {
    border-color: var(--accent);
    color: var(--text);
}

.filter-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 180px;
    max-height: 300px;
    overflow-y: auto;
    display: none;
    z-index: 1000;
    box-shadow: var(--shadow);
}

.filter-dropdown.show {
    display: block;
}

.filter-option {
    padding: 10px 16px;
    cursor: pointer;
    color: var(--text-soft);
}

.filter-option:hover {
    background: var(--surface);
    color: var(--text);
}

.filter-option.active {
    background: var(--accent);
    color: var(--bg);
    font-weight: 500;
}

/* Статистика */
.stats {
    color: var(--text-muted);
    background: var(--card);
    padding: 6px 14px;
    border-radius: 30px;
    border: 1px solid var(--border);
    white-space: nowrap;
}

/* ===== ОСНОВНОЙ КОНТЕНТ ===== */
.main-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ===== ЛЕНТА ФИЛЬМОВ ===== */
.movies-page {
    min-height: 100%;
    padding: 24px 0;
}

.movies {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    min-height: 400px;
    width: 100%;
}

/* Карточка */
.movie-card {
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: 0.2s;
    width: 100%;
    min-width: 0;
    border: 3px solid transparent; /* резервируем место под рамку */
}

.movie-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
    border: 3px solid var(--accent); /* рамка при ховере */
}

.movie-poster {
    position: relative;
    aspect-ratio: 2/3;
    overflow: hidden;
    background: var(--surface);
    width: 100%;
}

.movie-poster::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40%; /* высота градиента */
    background: linear-gradient(
        to top,
        rgba(0, 0, 0, 0.9) 0%,
        rgba(0, 0, 0, 0.5) 50%,
        transparent 100%
    );
    pointer-events: none; /* чтобы градиент не мешал кликам */
    z-index: 1;
}

/* Чтобы рейтинг был поверх градиента */
.movie-rating {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
}

.movie-poster img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: 0.3s;
}

.movie-card:hover .movie-poster img {
    transform: none; /* вместо scale(1.05) */
}

.rating-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    backdrop-filter: blur(4px);
}

.movie-info {
    padding: 12px;
}

.movie-title {
    font-weight: 500;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    /* Фиксируем высоту для двух строк */
    height: calc(1.5em * 2); /* 1.5em - высота строки, умножаем на 2 строки */
    line-height: 1.5;
    word-break: break-word;
}

.movie-meta {
    color: var(--text-muted);
    font-size: 0.8rem;
    /* Эта строка всегда одной высоты */
    height: 1.5em;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* ===== СТРАНИЦА ФИЛЬМА ===== */
.movie-page {
    min-height: 100%;
    padding: 24px 0;
}

/* Полная карточка с постером и подложкой */
.movie-full {
    position: relative;
    min-height: 100%;
}

.movie-full-backdrop {
    position: fixed;
    top: 0px;
    left: 0px;
    right: 20px;
    height: 80vh;

    overflow: hidden;
    z-index: 0;
    pointer-events: none;
    /* box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3); */
}

.movie-full-backdrop img {
    width: 100%;
    height: 100%;
    object-fit: cover;

}

.movie-full-backdrop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        to bottom, 
        rgba(0, 0, 0, 0.4) 0%,    /* сверху почти прозрачно */
        rgba(0, 0, 0, 0.8) 50%,    /* в середине затемнение */
        var(--bg) 100%              /* внизу сливается с фоном */
    );
}

.movie-full-container {
    position: relative;
    z-index: 2;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px 20px 40px;
}

.movie-full-header {
    display: flex;
    gap: 30px;
    margin-bottom: 40px;
    align-items: flex-start;
}

.movie-full-poster {
    flex-shrink: 0;
    width: 220px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.movie-full-poster img {
    width: 100%;
    height: auto;
    display: block;
}

.movie-full-info {
    flex: 1;
    padding-top: 20px;
}

.movie-full-header-mini {
    font-size: 0.9rem;
    color: rgba(255,255,255,0.9);
    margin-bottom: 8px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.movie-full-header-mini .separator {
    margin: 0 6px;
    opacity: 0.5;
}

.movie-full-title {
    font-size: 2.2rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 4px;
    color: #ffffff;
    text-shadow: 0 2px 8px rgba(0,0,0,0.7);
}

.movie-full-original {
    font-size: 1rem;
    color: rgba(255,255,255,0.8);
    margin-bottom: 12px;
    text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

.movie-full-tagline {
    font-size: 1.1rem;
    font-style: italic;
    color: var(--accent);
    margin-bottom: 16px;
    text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

.movie-full-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.badge {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    background: rgba(26, 28, 34, 0.8);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.2);
    color: #ffffff;
}

.badge.rating {
    font-weight: 600;
}

.movie-full-meta-line {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 20px;
    font-size: 0.95rem;
    color: rgba(255,255,255,0.9);
    text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

.runtime {
    white-space: nowrap;
}

.genres {
    color: rgba(255,255,255,0.7);
}

.trailer-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #ff0000;
    color: white;
    padding: 10px 20px;
    border-radius: 4px;
    text-decoration: none;
    font-weight: 500;
    transition: 0.2s;
}

.trailer-btn:hover {
    background: #cc0000;
}

.movie-full-body {
    background: var(--surface--min);
    border-radius: 8px;
    padding: 30px;
    margin-top: 20px;
}

.movie-full-section {
    margin-bottom: 24px;
}

.movie-full-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.movie-full-section p {
    line-height: 1.7;
    color: var(--text-soft);
    font-size: 1.2em;
}

.movie-cast {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.movie-cast-item {
    text-align: center;
}

.movie-cast-item img {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 6px;
    background: var(--surface);
}

.movie-cast-name {
    font-weight: 500;
    font-size: 0.85rem;
    line-height: 1.3;
}

.movie-cast-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.movie-cast-more {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--text-muted);
    height: 100%;
}

/* ===== ЗАГРУЗКА ===== */
.loading {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.spinner {
    width: 44px;
    height: 44px;
    margin: 0 auto 16px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-more {
    text-align: center;
    padding: 30px 0;
    color: var(--text-muted);
}

.spinner-small {
    width: 30px;
    height: 30px;
    margin: 0 auto 10px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Полноэкранная загрузка */
.movies.loading-fullscreen {
    min-height: 400px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.movies.loading-fullscreen::after {
    content: '';
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.movies.loading-fullscreen .movie-card {
    display: none;
}

/* ===== КНОПКА НАВЕРХ ===== */
.back-top {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg);
    border: none;
    font-size: 24px;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: 0.2s;
    box-shadow: var(--shadow);
    z-index: 1000;
}

.back-top.visible {
    opacity: 1;
    visibility: visible;
}

.back-top:hover {
    transform: translateY(-4px);
}

/* ===== ФУТЕР ===== */
.footer {
    flex-shrink: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 20px 0;
    text-align: center;
    color: var(--text-muted);
}

.footer a {
    color: var(--accent);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* ===== АДАПТИВНОСТЬ ===== */
@media (max-width: 1024px) {
    .movie-full-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    
    .movie-full-poster {
        width: 200px;
    }
    
    .movie-full-badges {
        justify-content: center;
    }
    
    .movie-full-meta-line {
        justify-content: center;
    }
}

@media (max-width: 900px) {
    .movies {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 16px;
    }
    
    .movie-cast {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}

@media (max-width: 700px) {
    .header-content {
        flex-direction: column;
        align-items: stretch;
    }
    
    .header-left {
        justify-content: space-between;
    }
    
    .search {
        max-width: none;
    }
    
    .filters {
        justify-content: space-between;
    }
    
    .movie-full-title {
        font-size: 1.8rem;
    }
}

@media (max-width: 600px) {
    .container {
        padding: 0 16px;
    }
    
    .movies {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 12px;
    }
    
    .movie-full-poster {
        width: 160px;
    }
    
    .movie-cast {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 12px;
    }
    
    .back-top {
        bottom: 16px;
        right: 16px;
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    .movie-full-backdrop {
        left: 0;
        right: 0;
        border-radius: 0;
    }
}

.trailer-btn.search-btn {
    background: #1a1a1a;
    border: 1px solid var(--border);
}

.trailer-btn.search-btn:hover {
    background: #2a2a2a;
    border-color: var(--accent);
}

.torrent-item {
    padding: 15px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    margin-bottom: 10px;
    border-radius: 6px;
}

.torrent-item:last-child {
    margin-bottom: 0;
}

.torrent-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 10px;
    color: var(--text);
    word-break: break-word;
}

.torrent-meta {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: var(--text-soft);
}

.torrent-tracker {
    color: var(--accent);
}

.torrent-peers {
    display: flex;
    gap: 15px;
    margin-bottom: 8px;
}

.torrent-seeders {
    color: #4caf50;
}

.torrent-leechers {
    color: #ff9800;
}

.torrent-voices {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding: 4px 0;
}

.torrent-links {
    display: flex;
    gap: 10px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.torrent-magnet-link, .torrent-url-link {
    padding: 6px 12px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.9rem;
    transition: 0.2s;
}

.torrent-magnet-link {
    background: var(--accent);
    color: var(--bg);
}

.torrent-url-link {
    background: var(--card);
    color: var(--text-soft);
    border: 1px solid var(--border);
}

.torrent-magnet-link:hover {
    opacity: 0.9;
}

.torrent-url-link:hover {
    background: var(--surface);
    color: var(--text);
}

.torrent-updated {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 5px;
}

.torrent-videotype {
    background: var(--card);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.8rem;
}
/* ===== КНОПКИ ДЕЙСТВИЙ ===== */
.movie-full-buttons {
    display: flex;
    gap: 10px;
    margin: 20px 0;
    flex-wrap: wrap;
}

.action-btn {
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: 0.2s;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.youtube-btn {
    background: #ff0000;
    color: white;
}

.youtube-btn:hover {
    background: #cc0000;
}

.search-yt-btn {
    background: #1a1a1a;
    color: var(--text);
    border: 1px solid var(--border);
}

.search-yt-btn:hover {
    border-color: var(--accent);
}

.search-btn {
    background: var(--accent);
    color: var(--bg);
}

.search-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* ===== ВЫПАДАЮЩИЙ БЛОК РЕЗУЛЬТАТОВ ===== */
.search-results {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin: 10px 0 20px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.search-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    font-weight: 500;
}

.close-results-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 4px;
}

.close-results-btn:hover {
    color: var(--text);
}

.search-results-content {
    padding: 16px;
    max-height: 500px;
    overflow-y: auto;
}

/* ===== ПОЛЕ ВВОДА КЛЮЧА ===== */
.api-key-prompt {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.api-key-input {
    flex: 1;
    padding: 8px 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.95rem;
}

.api-key-input:focus {
    outline: none;
    border-color: var(--accent);
}

.api-key-submit {
    padding: 8px 20px;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
}

.api-key-submit:hover {
    opacity: 0.9;
}

/* ===== РЕЗУЛЬТАТЫ ПОИСКА ===== */
.torrent-placeholder {
    color: var(--text-muted);
    text-align: center;
    padding: 30px 20px;
    font-style: italic;
}

.torrent-item {
    padding: 15px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    margin-bottom: 10px;
    border-radius: 6px;
}

.torrent-item:last-child {
    margin-bottom: 0;
}

.torrent-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 10px;
    color: var(--text);
    word-break: break-word;
}

.torrent-meta {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: var(--text-soft);
}

.torrent-voices {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding: 4px 0;
}

.torrent-links {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.torrent-magnet-link, .torrent-url-link {
    padding: 6px 12px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.9rem;
    transition: 0.2s;
}

.torrent-magnet-link {
    background: var(--accent);
    color: var(--bg);
}

.torrent-url-link {
    background: var(--card);
    color: var(--text-soft);
    border: 1px solid var(--border);
}

.torrent-magnet-link:hover {
    opacity: 0.9;
}

.torrent-url-link:hover {
    background: var(--surface);
    color: var(--text);
}

.torrent-error {
    color: #ff6b6b;
    padding: 15px;
    text-align: center;
    background: rgba(255, 107, 107, 0.1);
    border-radius: 4px;
}

.movie-card:focus-visible,
.action-btn:focus-visible,
.filter-btn:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
    transform: scale(1.02);
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between; /* Раздвигает левую и правую части */
    gap: 20px;
    padding: 12px 0;
    flex-wrap: wrap;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0; /* Запрещает сжиматься */
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: flex-end; /* Прижимает содержимое к правому краю */
    flex: 1; /* Занимает всё доступное пространство */
}

/* Для десктопа - ограничиваем ширину поиска */
@media (min-width: 901px) {
    .search {
        max-width: 300px;
    }
}

/* На мобилках правый блок едет вниз */
@media (max-width: 900px) {
    .header-right {
        justify-content: flex-start;
        width: 100%;
    }
}