body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--tg-theme-bg-color, #111);
    color: var(--tg-theme-text-color, #fff);
    margin: 0;
    padding: 0;
    padding-bottom: 160px; /* Увеличенный отступ под меню */
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

/* --- СЕТКА --- */
.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 12px;
}
.card {
    position: relative;
    background: var(--tg-theme-secondary-bg-color, #222);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
.card:active {
    transform: scale(0.97);
}
.card img {
    width: 100%;
    height: 250px;
    object-fit: cover;
    display: block;
}
.card-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 3px 6px;
    border-radius: 6px;
    backdrop-filter: blur(4px);
}
.card-content {
    padding: 10px;
}
.card-title {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.card-sub {
    font-size: 11px;
    color: #888;
    margin-top: 2px;
}

/* --- ПОИСК --- */
.search-box {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 12px;
    background: var(--tg-theme-bg-color);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: none;
}
.search-box input {
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: none;
    background: var(--tg-theme-secondary-bg-color, #222);
    color: white;
    font-size: 16px;
    outline: none;
    box-sizing: border-box;
}
.search-item {
    padding: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.search-actions {
    display: flex;
    gap: 8px;
}
.btn-action {
    flex: 1;
    border: none;
    padding: 8px 0;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    color: white;
}
.btn-watch {
    background: #3390ec;
}
.btn-later {
    background: #8e8e93;
}
.btn-done {
    background: #32d74b;
}
.btn-delete {
    background: #ff3b30;
}

/* Внутри панели управления элементы переносятся на две колонки, 
   чтобы кнопки не выходили за пределы экрана на маленьких устройствах. */
.manage-box .btn-action {
    flex: 1 1 calc(50% - 5px);
    text-align: center;
}

/* --- МЕНЮ (Tab Bar) --- */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(20, 20, 20, 0.98);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    z-index: 50;
    padding-bottom: max(30px, env(safe-area-inset-bottom));
    padding-top: 10px;
}
.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: #666;
    font-size: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
}
.tab-btn.active {
    color: var(--tg-theme-button-color, #3390ec);
}
.tab-icon {
    font-size: 24px;
    margin-bottom: 4px;
}

/* --- ДЕТАЛИ --- */
#details {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--tg-theme-bg-color);
    z-index: 100;
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    padding-bottom: 120px;
}
#details.open {
    transform: translateX(0);
}
.hero {
    position: relative;
    height: 350px;
}
.hero img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.hero-gradient {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.2) 0%, transparent 60%, var(--tg-theme-bg-color) 100%);
}
.hero-title {
    position: absolute;
    bottom: 20px;
    left: 15px;
    right: 15px;
    font-size: 22px;
    font-weight: 800;
    text-shadow: 0 2px 10px black;
}

/* КНОПКА НАЗАД */
.back-btn {
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 200;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.manage-box {
    padding: 15px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: var(--tg-theme-bg-color);
}
.episodes-list {
    padding: 15px;
}
.season-title {
    font-size: 18px;
    font-weight: bold;
    margin: 30px 0 10px;
    color: #aaa;
}
.ep-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.ep-row.watched {
    opacity: 0.5;
}
.check {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid #555;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}
.check.active {
    background: #32d74b;
    border-color: #32d74b;
}
.check.active::after {
    content: '✔';
    font-size: 14px;
    color: black;
    font-weight: bold;
}

/* --- Франшизы (Горизонтальный скролл) --- */
.franchise-list {
    padding: 0;
    margin-bottom: 10px;
}

/* Заголовок франшизы (использует стиль season-title, но с отступами) */
.franchise-list .season-title {
    margin-left: 15px;
    margin-bottom: 10px;
    margin-top: 20px;
}

.franchise-scroll {
    display: flex;
    overflow-x: auto;
    gap: 10px;
    padding: 0 15px;
    padding-bottom: 10px;
    -webkit-overflow-scrolling: touch; /* Плавный скролл на iOS */
    /* Скрываем скроллбар */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}
.franchise-scroll::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.franchise-card {
    width: 100px;
    min-width: 100px; /* Чтобы карточки не сжимались */
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.franchise-card img {
    width: 100px;
    height: 150px;
    object-fit: cover;
    border-radius: 8px;
    background: #333;
    margin-bottom: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.f-info {
    display: flex;
    flex-direction: column;
}

.f-title {
    font-size: 11px;
    font-weight: 500;
    line-height: 1.3;
    color: var(--tg-theme-text-color, #fff);
    /* Обрезаем текст до 2 строк */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.f-year {
    font-size: 10px;
    color: #888;
    margin-top: 2px;
}