/* static/css/styles.css */

/* ========= Общие стили и переменные ========= */
:root {
    --base-bg: #151F28;
    --matrix-color: #00ff00;
    --matrix-shadow:
        0 0 5px   #00ff00,
        0 0 10px  #00ff00,
        0 0 15px  #00ff00,
        0 0 20px  #00ff00;
    --active-color: #29fd53;
    --clr: #151F28;
    --primary-font: 'Roboto', sans-serif; /* Основной шрифт */
    --secondary-font: 'MyCustomFont', sans-serif; /* Вторичный шрифт, если используется */
    
    /* Safe Area переменные для устройств с "чёлкой" */
    --safe-area-top: 0px;
    --safe-area-bottom: 0px;
    --safe-area-left: 0px;
    --safe-area-right: 0px;
    
    /* Переменная для корректной высоты на мобильных */
    --vh: 1vh;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--primary-font);
}

body {
    background: var(--base-bg);
    color: #fff;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding-bottom: 70px; /* Чтобы контент не заходил под нижнюю навигацию */
    
    /* Safe Area Insets для Telegram Mini App */
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px));
}

/* Утилитарный класс для скрытия элементов */
.hidden {
    display: none !important;
}

/* Фоновый слой */
.background-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--base-bg);
    opacity: 0.3;
    z-index: 1;
}

/* Контент */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Размещает содержимое сверху */
    align-items: center;          /* Центрирование по горизонтали */
    position: relative;
    z-index: 3; /* Выше, чем background-layer */
    padding-top: 50px; /* Верхний внутренний отступ */
    gap: 40px; /* Пространство между элементами */
}

/* Стили для поиска */
.search-container {
    position: relative;
    width: 100%;
    max-width: 300px;
    margin: 20px auto 15px; /* уменьшили расстояние до карусели */
    z-index: 10;
}

#search-input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(0, 255, 0, 0.4);
    border-radius: 12px;
    color: #fff;
    font-size: 16px;
    outline: none;
    transition: all 0.3s ease;
    appearance: none;
    -webkit-appearance: none;
    -webkit-border-radius: 12px;
    transform: scale(1);
    transform-origin: center;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

#search-input:focus {
    border-color: var(--active-color);
    box-shadow: 0 0 15px rgba(0, 255, 0, 0.4), 0 4px 20px rgba(0, 0, 0, 0.3);
    background: rgba(0, 0, 0, 0.4);
    transform: scale(1);
}

#search-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid rgba(0, 255, 0, 0.4);
    border-top: none;
    border-radius: 0 0 12px 12px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 11;
    display: none;
    backdrop-filter: blur(15px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
}

.search-result-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid rgba(0, 255, 0, 0.2);
    transition: all 0.3s ease;
    color: #fff;
}

.search-result-item:hover {
    background: rgba(0, 255, 0, 0.15);
    transform: translateX(2px);
    box-shadow: 0 2px 8px rgba(0, 255, 0, 0.2);
}

.search-result-item:last-child {
    border-bottom: none;
}

.no-results {
    text-align: center;
    padding: 20px;
    color: rgba(255, 255, 255, 0.6);
    font-style: italic;
}

/* Галерея */
.gallery {
    position: relative;
    width: 100%;
    max-width: 300px; /* Увеличили для области свайпа */
    margin: 20px 0;
    margin-top: 20px; /* уменьшили расстояние от поиска */
    height: 220px; /* Увеличили для области свайпа */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20;
    transform: translateY(20px);
    /* Центрируем галерею */
    padding: 20px 40px;
}

.gallery__container {
    position: relative;
    width: 140px;
    height: 180px;
    transform-style: preserve-3d;
    animation: rotate 20s linear infinite;
    transition: transform 0.5s ease;
}

.gallery__container span {
    position: absolute;
    top: 0;
    left: 0;
    width: 95%;
    height: 95%;
    margin: 2.5%;
    transform-origin: center;
    transform: rotateY(calc(var(--i) * 45deg)) translateZ(160px); /* Сделали еще уже */
    transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden; /* Предотвращаем выход видео за границы контейнера */
}

.gallery__container span img {
    position: absolute;
    width: 100%;
    height: 120%;
    border-radius: 12px;
    object-fit: cover;
    cursor: pointer;
    transition: 0.5s;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(0, 255, 0, 0.2);
    /* Улучшение качества изображений */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Отдельные стили для видео */
.gallery__container span video {
    position: absolute;
    width: 100%;
    height: 120%;
    border-radius: 12px;
    object-fit: cover;
    cursor: pointer;
    transition: 0.5s;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(0, 255, 0, 0.2);
    /* Предотвращаем изменение размеров видео */
    max-width: none;
    max-height: none;
    min-width: 0;
    min-height: 0;
}

/* Анимация вращения галереи */
@keyframes rotate {
    0% {
        transform: perspective(1000px) rotateY(0deg);
    }
    100% {
        transform: perspective(1000px) rotateY(360deg);
    }
}

/* Остановка анимации при взаимодействии */
.gallery.paused .gallery__container {
    animation-play-state: paused;
}

/* Стили для кликабельных карточек тем */
.topic-card {
    position: relative;
    cursor: pointer;
    transition: all 0.5s ease;
    border-radius: 8px;
    overflow: hidden;
}

/* Контейнер для увеличенной карточки */
.selected-card-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center; /* Центрируем по вертикали */
    /* Учитываем Safe Areas Telegram */
    padding-top: env(safe-area-inset-top, 20px);
    padding-bottom: calc(70px + env(safe-area-inset-bottom, 20px)); /* Учитываем навигацию */
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    box-sizing: border-box;
}

/* Адаптивные отступы для overlay */
@media (max-width: 480px) {
    .selected-card-overlay {
        /* На мобильных центрируем с учетом навигации */
        align-items: center;
    }
}

@media (min-width: 1025px) {
    .selected-card-overlay {
        /* На десктопе тоже центрируем */
        align-items: center;
    }
}

.selected-card-container {
    position: relative;
    width: 350px;
    height: 600px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 25px 50px rgba(0, 255, 0, 0.4);
    transform: scale(0.8);
    transition: transform 0.3s ease;
}

/* Адаптивные размеры для выбранной карточки */
@media (max-width: 480px) {
    .selected-card-container {
        width: 320px;
        height: 550px;
    }
}

@media (min-width: 481px) and (max-width: 1024px) {
    .selected-card-container {
        width: 400px;
        height: 650px;
    }
}

@media (min-width: 1025px) {
    .selected-card-container {
        width: 450px;
        height: 700px;
        max-height: 80vh; /* Ограничиваем высоту на десктопе */
    }
}

.selected-card-container .card-overlay {
    opacity: 1 !important;
    background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.3) 50%, rgba(0, 0, 0, 0.9) 100%) !important;
    padding: 30px 25px 20px !important;
    border-radius: 0 0 12px 12px !important;
    top: auto !important;
    bottom: 0 !important;
}

.selected-card-container .card-overlay h3 {
    font-size: 22px !important;
    margin-bottom: 10px !important;
    font-weight: 600 !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8), 0 0 12px rgba(0, 255, 0, 0.4) !important;
    opacity: 1 !important;
    color: #ffffff !important;
    letter-spacing: 0.5px !important;
}

.selected-card-container .card-overlay p {
    font-size: 14px !important;
    margin: 4px 0 !important;
    line-height: 1.3 !important;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
    opacity: 1 !important;
}

.selected-card-container .card-actions {
    display: flex !important;
    gap: 12px;
    margin-top: 15px;
    justify-content: center;
}

.selected-card-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.selected-card-overlay.active .selected-card-container {
    transform: scale(1);
}

/* Скрываем оригинальную выбранную карточку */
.topic-card.selected {
    opacity: 0.3 !important;
    transition: opacity 0.3s ease;
}

.topic-card.selected img {
    filter: brightness(1.1) saturate(1.2);
    width: 100% !important;
    height: 100% !important;
    border-radius: 12px !important;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Затемнение остальных карточек при выборе */
.gallery__container.has-selection .topic-card:not(.selected) {
    opacity: 0.2;
    filter: blur(2px);
}

/* Overlay для выбранной карточки - увеличенные размеры */
.topic-card.selected .card-overlay {
    opacity: 1 !important;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.9)) !important;
    padding: 25px 20px 18px !important;
    border-radius: 0 0 12px 12px !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    top: auto !important;
    bottom: 0 !important;
}

.topic-card.selected .card-overlay h3 {
    font-size: 20px !important;
    margin-bottom: 8px !important;
    font-weight: 600 !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8), 0 0 10px rgba(0, 255, 0, 0.4) !important;
    opacity: 1 !important;
    color: #ffffff !important;
    letter-spacing: 0.3px !important;
}

.topic-card.selected .card-overlay p {
    font-size: 14px !important;
    margin: 4px 0 !important;
    line-height: 1.3 !important;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
    opacity: 1 !important;
}

/* Кнопки действий для выбранной карточки */
.topic-card.selected .card-actions {
    display: flex;
    gap: 12px;
    margin-top: 15px;
    justify-content: center;
}

.card-actions {
    display: none;
    gap: 10px;
}

.card-actions button {
    padding: 10px 18px;
    border: none;
    border-radius: 18px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    min-width: 65px;
    letter-spacing: 0.5px;
}

.card-actions .btn-start {
    background: linear-gradient(45deg, var(--active-color), #00cc44);
    color: white;
    box-shadow: 0 3px 10px rgba(41, 253, 83, 0.4);
}

.card-actions .btn-back {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(10px);
}

.card-actions button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);
}

.card-actions .btn-start:hover {
    box-shadow: 0 6px 15px rgba(41, 253, 83, 0.5);
}

.card-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.6) 50%, transparent 100%);
    color: white;
    padding: 8px 6px;
    border-radius: 12px 12px 0 0;
    opacity: 1 !important;
    transition: all 0.3s ease;
    text-align: center;
    height: auto;
    min-height: 28px;
    border: 1px solid rgba(0, 255, 0, 0.2);
    border-bottom: none;
}

.card-overlay h3 {
    font-size: 10px;
    font-weight: 600;
    margin: 0;
    padding: 0;
    color: var(--active-color);
    /* Название всегда видно */
    opacity: 1 !important;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8), 0 0 8px rgba(0, 255, 0, 0.5);
    letter-spacing: 0.3px;
}

.card-overlay p {
    font-size: 9px;
    margin: 1px 0;
    /* Детали скрыты по умолчанию в галерее */
    opacity: 0 !important;
    transition: opacity 0.3s ease;
}

.card-overlay .difficulty {
    color: #ffcc00;
    font-weight: 500;
}

.card-overlay .questions {
    color: #cccccc;
}

/* Отключаем hover эффекты на десктопе */
@media (hover: hover) and (pointer: fine) {
    .topic-card:hover .card-overlay p {
        opacity: 1 !important;
    }
}

/* Название темы всегда видно */
.topic-card .card-overlay h3 {
    opacity: 1 !important;
    display: block !important;
    visibility: visible !important;
}

.centered-text {
    text-align: center;
    margin: 20px 0;
    z-index: 5;
    position: relative;
}

.centered-text h1 {
    font-size: 2.5rem;
    color: #fff;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
}

/* Нижняя навигация - точная копия оригинала */
.navigation {
    position: fixed;
    bottom: env(safe-area-inset-bottom, 0px);
    left: 50%;
    transform: translateX(-50%);
    width: 400px;
    height: 70px;
    background: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    z-index: 9999;
}

.navigation ul {
    display: flex;
    width: 350px;
    position: relative;
    list-style: none;
    margin: 0;
    padding: 0;
}

.navigation ul li {
    position: relative;
    list-style: none;
    width: 70px;
    height: 70px;
    z-index: 1;
}

.navigation ul li a {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    width: 100%;
    text-align: center;
    font-weight: 500;
    text-decoration: none;
}

.navigation ul li a .icon {
    position: relative;
    display: block;
    line-height: 75px;
    font-size: 1.5rem;
    text-align: center;
    transition: transform 1s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    will-change: transform; /* Оптимизация для мобильных устройств */
    color: var(--clr);
}

.navigation ul li.active a .icon {
    transform: translate3d(0, -32px, 0); /* Используем translate3d для аппаратного ускорения */
}

.navigation ul li a .text {
    position: absolute;
    color: var(--clr);
    font-weight: 400;
    font-size: 0.75em;
    letter-spacing: 0.05em;
    transition: all 1s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    opacity: 0;
    transform: translateY(20px);
}

.navigation ul li.active a .text {
    transform: translateY(10px);
    opacity: 1;
}

/* Hover эффекты только для тачскринов */
@media (hover: none) {
    .navigation ul li:hover a .icon {
        transform: translateY(-28px);
    }
    
    .navigation ul li:hover a .text {
        opacity: 1;
        transform: translateY(5px);
    }
}

/* Индикатор (ползунок) */
.indicator {
    position: absolute;
    top: -48%;
    width: 70px;
    height: 70px;
    background: var(--active-color);
    border-radius: 50%;
    border: 6px solid var(--clr);
    transition: transform 1s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    will-change: transform; /* Оптимизация для мобильных устройств */
    z-index: 0;
}

.indicator::before {
    display: none;
}

.indicator::after {
    display: none;
}

/* Позиционирование индикатора для каждого элемента */
.navigation ul li:nth-child(1).active ~ .indicator {
    transform: translate3d(calc(70px * 0), 0, 0); /* Используем translate3d для аппаратного ускорения */
}
.navigation ul li:nth-child(2).active ~ .indicator {
    transform: translate3d(calc(70px * 1), 0, 0);
}
.navigation ul li:nth-child(3).active ~ .indicator {
    transform: translate3d(calc(70px * 2), 0, 0);
}
.navigation ul li:nth-child(4).active ~ .indicator {
    transform: translate3d(calc(70px * 3), 0, 0);
}
.navigation ul li:nth-child(5).active ~ .indicator {
    transform: translate3d(calc(70px * 4), 0, 0);
}

/* Адаптивность меню (для мобильных устройств) */
@media (max-width: 480px) {
    .navigation {
        width: 350px;
    }
    .navigation ul {
        width: 310px;
    }
    .navigation ul li {
        width: 60px;
    }
    /* На мобильных устройствах используем ту же логику, что и на десктопе */
    /* Но добавляем задержку для иконки, чтобы она начинала движение после индикатора */
    /* На мобильных браузеры обрабатывают селектор ~ медленнее, поэтому нужна задержка */
    .navigation ul li a .icon {
        transition-delay: 0.25s; /* Увеличенная задержка для синхронизации с индикатором на мобильных */
    }
    .navigation ul li.active a .icon {
        transition-delay: 0.25s; /* Увеличенная задержка для синхронизации с индикатором на мобильных */
    }
    .indicator {
        width: 60px;
        height: 60px;
        /* Индикатор без задержки - начинает движение сразу */
    }
    .navigation ul li:nth-child(1).active ~ .indicator {
        transform: translate3d(calc(60px * 0), 0, 0); /* Используем translate3d для аппаратного ускорения */
    }
    .navigation ul li:nth-child(2).active ~ .indicator {
        transform: translate3d(calc(60px * 1), 0, 0);
    }
    .navigation ul li:nth-child(3).active ~ .indicator {
        transform: translate3d(calc(60px * 2), 0, 0);
    }
    .navigation ul li:nth-child(4).active ~ .indicator {
        transform: translate3d(calc(60px * 3), 0, 0);
    }
    .navigation ul li:nth-child(5).active ~ .indicator {
        transform: translate3d(calc(60px * 4), 0, 0);
    }

    /* Адаптация размеров текста и галереи для мобильных устройств */
    .typewriter {
        font-size: 2.5em; /* Уменьшенный размер шрифта */
        width: 22ch;
        margin-top: 15px; /* Уменьшенный верхний отступ */
        margin-bottom: 30px; /* Уменьшенный нижний отступ */
    }

    .gallery {
        max-width: 180px; /* Уменьшенная ширина галереи */
        height: 130px; /* Уменьшенная высота контейнера */
        margin-top: 50px; /* Опущена на дополнительные 20px */
        transform: translateY(20px); /* Дополнительное опускание */
    }
}

/* Плавные переходы для текстовых элементов */
.typewriter, .gallery {
    transition: all 0.3s ease-in-out;
}

/* Дополнительные стили для кастомного курсора (опционально) */
#cursor {
    display: inline-block;
    background-color: #ffffff; /* Цвет курсора */
    width: 2px;
    height: 1em;
    margin-left: 2px;
    animation: blink 0.7s infinite;
}

@keyframes blink {
    0% { opacity: 1; }
    50% { opacity: 0; }
    100% { opacity: 1; }
}

/* Стили для страницы детального просмотра темы */
.topic-detail {
    width: 350px;
    height: 600px;
    margin: 60px auto 100px; /* Отступы как у увеличенной карточки */
    padding: 20px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-sizing: border-box;
    position: relative;
    top: -60px; /* Поднимаем выше, чтобы совпадало с увеличенной карточкой */
    display: flex;
    flex-direction: column;
}

.topic-header {
    text-align: center;
    margin-bottom: 30px;
}

.topic-header h1 {
    color: var(--active-color);
    font-size: 2em;
    margin: 0 0 10px 0;
}

.topic-description {
    color: #cccccc;
    font-size: 1.1em;
    margin: 0;
    line-height: 1.4;
}

.topic-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.topic-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

.topic-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    color: white;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    max-width: 280px;
    margin: 0 auto;
    backdrop-filter: blur(5px);
}

.topic-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(255, 255, 255, 0.1);
}

.subtopic-btn {
    border-color: rgba(255, 193, 7, 0.5);
    background: rgba(255, 193, 7, 0.1);
}

.subtopic-btn:hover {
    background: rgba(255, 193, 7, 0.2);
    box-shadow: 0 4px 15px rgba(255, 193, 7, 0.3);
}

.btn-icon {
    font-size: 1.2em;
    margin-right: 10px;
}

.btn-text {
    font-weight: 500;
    flex: 1;
    text-align: left;
}

.btn-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 8px;
    border-radius: 10px;
    font-size: 0.9em;
    font-weight: 500;
    min-width: 30px;
    text-align: center;
}

.topic-actions {
    display: flex;
    justify-content: center;
    margin-top: auto;
    padding-top: 20px;
}

.btn {
    padding: 12px 25px;
    border: none;
    border-radius: 25px;
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 150px;
}

.btn-primary {
    background: linear-gradient(45deg, var(--active-color), #00cc44);
    color: white;
    box-shadow: 0 4px 15px rgba(41, 253, 83, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(41, 253, 83, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}



/* Адаптивность для мобильных устройств */
@media (max-width: 480px) {
    .topic-header h1 {
        font-size: 1.5em;
    }
    
    .topic-description {
        font-size: 1em;
    }
    
    .topic-btn {
        max-width: 100%;
        padding: 12px 15px;
    }
    
    .btn-icon {
        font-size: 1.1em;
        margin-right: 8px;
    }
    
    .btn-text {
        font-size: 0.9em;
    }
    
    .btn-count {
        font-size: 0.8em;
        padding: 3px 6px;
    }
    
    .btn {
        width: 100%;
        max-width: 250px;
    }
}

/* Индикатор выбора */
.topic-card.selected::before {
    content: '';
    position: absolute;
    top: 10px;
    right: 10px;
    width: 20px;
    height: 20px;
    background: var(--active-color);
    border-radius: 50%;
    z-index: 101;
    box-shadow: 0 0 10px rgba(41, 253, 83, 0.8);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

/* Подготовка для видео элементов */
.topic-card video {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.topic-card.has-video:hover video {
    opacity: 1;
}

.topic-card.has-video:hover img {
    opacity: 0;
}

/* Полноэкранный режим карточки */
.topic-card.fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9999 !important;
    background: rgba(0, 0, 0, 0.9) !important;
    margin: 0 !important;
    border-radius: 0 !important;
    transform: none !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.topic-card.fullscreen img {
    width: 90% !important;
    height: 90% !important;
    max-width: 500px !important;
    max-height: 500px !important;
    border-radius: 15px !important;
    object-fit: cover !important;
    box-shadow: 0 20px 60px rgba(0, 255, 0, 0.3) !important;
}

.topic-card.fullscreen .card-overlay {
    position: absolute !important;
    bottom: 10% !important;
    left: 5% !important;
    right: 5% !important;
    top: auto !important;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.9)) !important;
    padding: 20px !important;
    border-radius: 15px !important;
    opacity: 1 !important;
    text-align: center !important;
}

.topic-card.fullscreen .card-overlay h3 {
    font-size: 24px !important;
    margin-bottom: 10px !important;
}

.topic-card.fullscreen .card-overlay p {
    font-size: 16px !important;
}

/* Кнопка закрытия для полноэкранного режима */
.topic-card.fullscreen::before {
    content: '✕';
    position: fixed;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    z-index: 10000;
    backdrop-filter: blur(10px);
}

.card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    color: white;
    padding: 15px 10px 10px;
    border-radius: 0 0 8px 8px;
    opacity: 0;
    transition: opacity 0.3s ease;
    text-align: center;
}

.topic-card:hover .card-overlay {
    opacity: 1;
}

.card-overlay h3 {
    font-size: 16px;
    font-weight: bold;
    margin: 0 0 5px 0;
    color: var(--active-color);
}

.card-overlay p { display: none; }
.card-overlay .difficulty { display: none; }
.card-overlay .questions { display: none; }

.card-overlay .difficulty {
    color: #ffcc00;
    font-weight: 500;
}

.card-overlay .questions {
    color: #cccccc;
}

/* Убираем все лишние анимации при полноэкранном режиме */
body.fullscreen-active {
    overflow: hidden;
}

body.fullscreen-active .gallery__container {
    animation-play-state: paused;
}

/* ========= Стили для страницы профиля ========= */

/* Переопределяем стили для content на странице профиля */
.profile-page .content {
    display: block !important;
    padding: 20px !important;
    min-height: calc(100vh - 70px);
}

.loader-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 140px);
    text-align: center;
}

.loader-text {
    font-size: 18px;
    color: rgba(255, 255, 255, 0.8);
    margin-top: 20px;
}

/* Профильные стили перенесены в отдельный файл profile.css */

/* Стили для социальных сетей */
.social-section { 
    margin-bottom: 30px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 20px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(10px);
}

.social-links {
    display: grid;
    gap: 12px;
}

.social-link-card {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    padding: 16px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    text-decoration: none;
    color: white;
    position: relative;
    overflow: hidden;
}

.social-link-card:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.social-link-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.1),
        transparent
    );
    transition: left 0.5s ease;
}

.social-link-card:hover::before {
    left: 100%;
}

.social-icon {
    font-size: 24px;
    margin-right: 16px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    transition: all 0.3s ease;
}

.social-link-card:hover .social-icon {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.2);
}

.social-info {
    flex: 1;
}

.social-name {
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 16px;
}

.social-url {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    gap: 6px;
    word-break: break-all;
}

.social-url::after {
    content: '↗';
    font-size: 12px;
    opacity: 0;
    transform: translateX(-10px);
    transition: all 0.3s ease;
}

.social-link-card:hover .social-url::after {
    opacity: 1;
    transform: translateX(0);
}

.social-empty {
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
    padding: 20px;
    font-style: italic;
}

/* Стили для модального окна редактирования */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    /* Учитываем safe areas Telegram */
    padding-top: var(--tg-safe-area-inset-top, var(--safe-area-top, env(safe-area-inset-top, 0px)));
    padding-bottom: var(--tg-safe-area-inset-bottom, var(--safe-area-bottom, env(safe-area-inset-bottom, 0px)));
    padding-left: var(--tg-safe-area-inset-left, var(--safe-area-left, env(safe-area-inset-left, 0px)));
    padding-right: var(--tg-safe-area-inset-right, var(--safe-area-right, env(safe-area-inset-right, 0px)));
}

.modal-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    margin: 2% auto;
    padding: 0;
    border-radius: 20px;
    width: 95%;
    max-width: 500px;
    max-height: calc(95vh - var(--tg-safe-area-inset-top, var(--safe-area-top, env(safe-area-inset-top, 0px))) - var(--tg-safe-area-inset-bottom, var(--safe-area-bottom, env(safe-area-inset-bottom, 0px))));
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease;
    position: relative;
}

@media (max-width: 768px) {
    .modal-content {
        margin: 10px auto 20px auto; /* Улучшенное позиционирование для мобильных */
        width: 95%;
        max-width: 400px;
        max-height: 85vh; /* Увеличиваем высоту для мобильных устройств */
        border-radius: 15px;
    }
}

@media (max-width: 480px) {
    .modal-content {
        margin: 5px auto 15px auto; /* Еще меньше отступы для маленьких экранов */
        width: 98%;
        max-width: 350px;
        max-height: 90vh; /* Максимальная высота для маленьких экранов */
        border-radius: 12px;
    }
}

@media (max-width: 360px) {
    .modal-content {
        margin: 2px auto 10px auto; /* Минимальные отступы */
        width: 99%;
        max-width: 320px;
        max-height: 95vh; /* Почти на весь экран */
        border-radius: 10px;
    }
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    padding: 20px 25px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    color: white;
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.close {
    color: rgba(255, 255, 255, 0.7);
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.close:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.form-group {
    margin-bottom: 20px;
    padding: 0 25px;
}

.form-group:first-of-type {
    padding-top: 20px;
}

.form-group label {
    display: block;
    color: white;
    font-weight: 500;
    margin-bottom: 8px;
    font-size: 14px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 16px;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.form-group input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
}

.form-group input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.avatar-preview {
    margin-top: 10px;
    text-align: center;
}

.avatar-preview img {
    max-width: 100px;
    max-height: 100px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.3);
}

.modal-actions {
    padding: 20px 25px 25px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-cancel,
.btn-save {
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 100px;
}

.btn-cancel {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.btn-cancel:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-save {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: white;
}

.btn-save:hover {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

/* Адаптивные стили для профиля перенесены в profile.css */

/* ========= АДАПТИВНОСТЬ ДЛЯ РАЗНЫХ ПЛАТФОРМ ========= */

/* Стили для мобильной платформы */
.mobile-platform {
    /* Используем --vh для корректной высоты на мобильных */
    min-height: calc(var(--vh, 1vh) * 100);
}

/* Стили когда клавиатура открыта на мобильных */

.keyboard-open .content {
    padding-bottom: 20px; /* Уменьшаем нижний отступ */
}

.keyboard-open .navigation {
    bottom: 10px; /* Поднимаем навигацию */
}

/* Адаптация поиска для разных платформ */
.mobile-platform .search-container {
    max-width: 280px;
}

.desktop-platform .search-container {
    max-width: 350px;
}

.browser-platform .search-container {
    max-width: 320px;
}

/* Адаптация галереи для разных платформ */
@media (max-width: 480px) {
    .gallery {
        max-width: 180px;
        height: 130px;
        margin-top: 15px;
    }
}

@media (min-width: 481px) and (max-width: 1024px) {
    .gallery {
        max-width: 200px;
        height: 150px;
        margin-top: 18px;
    }
}

@media (min-width: 1025px) {
    .gallery {
        max-width: 250px;
        height: 180px;
        margin-top: 20px;
    }
    
    .search-container {
        max-width: 350px;
        margin: 25px auto 20px;
    }
    
    .topic-list-container {
        max-width: 500px;
    }
    
    .topic-item {
        padding: 20px;
    }
    
    .topic-info h3 {
        font-size: 20px;
    }
    
    .topic-questions {
        font-size: 16px;
    }
}

/* Адаптация навигации для разных платформ */
.mobile-platform .navigation {
    width: 320px;
    bottom: calc(10px + var(--safe-area-bottom));
}

.desktop-platform .navigation {
    width: 400px;
    bottom: 20px;
}

.browser-platform .navigation {
    width: 350px;
    bottom: 15px;
}

/* Адаптация карточек для разных платформ */
@media (max-width: 480px) {
    .topic-card {
        width: 160px;
        height: 160px;
    }
}

@media (min-width: 481px) and (max-width: 1024px) {
    .topic-card {
        width: 180px;
        height: 180px;
    }
}

@media (min-width: 1025px) {
    .topic-card {
        width: 170px;
        height: 170px;
    }
}

/* Адаптация текста для разных платформ */
.mobile-platform .card-overlay h3 {
    font-size: 14px;
}

.desktop-platform .card-overlay h3 {
    font-size: 16px;
}

.browser-platform .card-overlay h3 {
    font-size: 16px;
}

/* Адаптация отступов между карточками */
@media (max-width: 480px) {
    .gallery__container span {
        margin: 0 5px;
    }
}

@media (min-width: 481px) and (max-width: 1024px) {
    .gallery__container span {
        margin: 0 6px;
    }
}

@media (min-width: 1025px) {
    .gallery__container span {
        margin: 0 8px;
    }
}

/* Адаптация кнопок для разных платформ */
.mobile-platform .card-actions button {
    padding: 6px 10px;
    font-size: 12px;
}

.desktop-platform .card-actions button {
    padding: 8px 14px;
    font-size: 14px;
}

.browser-platform .card-actions button {
    padding: 7px 12px;
    font-size: 13px;
}

/* Адаптация профиля для разных платформ перенесена в profile.css */

/* Адаптация модальных окон для разных платформ */
.mobile-platform .modal-content {
    width: 90%;
    max-width: 320px;
    margin: 20px auto;
}

.desktop-platform .modal-content {
    width: 80%;
    max-width: 500px;
    margin: 40px auto;
}

.browser-platform .modal-content {
    width: 85%;
    max-width: 400px;
    margin: 30px auto;
}

/* Дополнительные медиа-запросы для экстремальных случаев */
@media (max-width: 320px) {
    .mobile-platform .gallery {
        max-width: 140px;
        height: 100px;
    }
    
    .mobile-platform .topic-card {
        width: 120px;
        height: 120px;
    }
    
    .mobile-platform .navigation {
        width: 280px;
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    .desktop-platform .gallery {
        max-width: 200px;
        height: 150px;
    }
    
    .desktop-platform .topic-card {
        width: 170px;
        height: 170px;
    }
}

/* Стили для устройств с высоким DPI */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .topic-card img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Общие улучшения качества для всех изображений в карточках */
.topic-card img,
.topic-card video,
.topic-card-enlarged img,
.topic-card-enlarged video {
    image-rendering: -webkit-optimize-contrast;
}

/* Стили для списка тем под каруселью */
.topic-list-container {
    width: 100%;
    max-width: 380px; /* Увеличена максимальная ширина */
    margin: 40px auto 20px;
    padding: 0 15px;
    z-index: 10;
    position: relative;
}

.topic-list-container h2 {
    font-size: 24px;
    color: #fff;
    margin-bottom: 25px;
    text-align: center;
    font-weight: 700;
    text-shadow: 0 0 10px rgba(0, 255, 0, 0.3);
}

.topic-item {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(0, 255, 0, 0.4);
    border-radius: 15px;
    padding: 18px;
    margin-bottom: 20px;
    display: flex; /* вернулись к flex для стабильности и единообразия с mobile */
    justify-content: flex-start; /* кнопки нет, контент сжимаем влево */
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.topic-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 25px rgba(0, 255, 0, 0.4);
    background: rgba(0, 0, 0, 0.5);
    border-color: rgba(0, 255, 0, 0.6);
}

.topic-info {
    flex: 1;
    margin-right: 15px;
    text-align: left; /* фикс: всегда выравниваем контент блока слева */
}

/* Принудительно сбрасываем любые правые выравнивания, которые могли попасть из динамики */
.topic-item *,
.topic-item .topic-info *,
.topic-item .progress-text {
    text-align: left !important;
}

/* Защита от наследованных flex-правил: не даём последним дочерним элементам растягивать контент вправо */
.topic-item > *:last-child {
    margin-left: 0 !important;
}

.topic-info h3 {
    font-size: 18px;
    color: var(--active-color);
    margin-bottom: 8px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.topic-questions {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 10px;
}

.progress-bar-container {
    width: 100%;
    height: 10px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 5px;
    overflow: hidden;
    margin-top: 5px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
    position: relative; /* гарантируем позиционирование заполнителя от левого края */
    border: 1px solid rgba(0, 255, 0, 0.2);
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--active-color), var(--matrix-color));
    border-radius: 5px;
    transition: width 0.5s ease-in-out;
    transform-origin: left center; /* чтобы заливка начиналась строго с левого края */
    display: block; /* гарантируем блочный поток без отступов */
    margin: 0; /* исключаем возможные внешние отступы */
    position: absolute; /* фикс: всегда от левого края контейнера */
    left: 0;
    top: 0;
    box-shadow: 0 0 8px rgba(0, 255, 0, 0.4);
}

/* Если прогресс 100%, закрашиваем полностью и убираем визуальные щели */
.progress-bar[style*="width: 100%"] {
    width: 100% !important;
    border-radius: 5px;
}

.progress-text {
    font-size: 13px;
    color: var(--active-color);
    margin-top: 8px;
    text-align: left; /* выравниваем текст слева, чтобы не "уплывал" вправо */
    font-weight: 500;
    display: block;
    text-shadow: 0 0 5px rgba(0, 255, 0, 0.3);
}

.no-tasks, .not-started {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
    font-style: italic;
}

/* Удалили кнопку "Начать" на карточке темы */

/* Адаптивные стили для списка тем */
@media (max-width: 480px) {
    .topic-list-container {
        max-width: 100%;
        padding: 0 10px;
        margin-top: 30px;
    }

    .topic-list-container h2 {
        font-size: 20px;
        margin-bottom: 20px;
    }

    .topic-item {
        padding: 15px;
        margin-bottom: 15px;
        flex-direction: column;
        align-items: flex-start;
    }

    .topic-info {
        margin-right: 0;
        margin-bottom: 15px;
        width: 100%;
    }

    .topic-info h3 {
        font-size: 16px;
    }

    .topic-questions {
        font-size: 13px;
    }

    .progress-text {
        text-align: left;
    }

    .btn-start {
        width: 100%;
        padding: 12px;
        font-size: 14px;
    }
}

/* Стили для устройств без поддержки hover (тачскрины) */
@media (hover: none) {
    .topic-card:active {
        transform: scale(0.95);
    }
}

/* ========= SAFE AREA СТИЛИ ДЛЯ TELEGRAM MINI APP ========= */

/* Заголовки страниц с учетом Safe Area */
.page-header {
    margin-top: max(20px, env(safe-area-inset-top));
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
}

/* Контейнеры с кнопками в верхней части */
.top-controls {
    margin-top: max(10px, env(safe-area-inset-top));
    padding-left: max(15px, env(safe-area-inset-left));
    padding-right: max(15px, env(safe-area-inset-right));
}

/* Кнопки закрытия и меню */
.close-button, .menu-button {
    margin-top: max(10px, env(safe-area-inset-top));
}

/* Фильтры и кнопки в верхней части */
.filter-buttons {
    margin-top: max(15px, env(safe-area-inset-top));
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
}



















