/* =============== IMMERSIVE WORKOUT SCREEN =============== */
/* Модульный CSS для полноэкранного режима тренировки */

/* Экран — контейнер для fullscreen видео */
#active-workout {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100dvh !important;
    height: var(--tg-viewport-stable-height, 100dvh) !important;
    overflow: hidden;
    background: #1E1B14 !important;
    z-index: 9999;
}

#active-workout .header {
    display: none;
}

#active-workout .main-content {
    padding: 0;
    max-height: none;
    overflow: visible;
}

/* ---- Fullscreen видео ---- */
.immersive-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
    transition: object-fit 0.3s;
}

/* Фоновое размытое видео (для горизонтальных) */
.immersive-video-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
    filter: blur(30px) brightness(0.4);
    transform: scale(1.1);
    display: none;
}

/* Горизонтальное видео на вертикальном экране */
.immersive-video--landscape {
    object-fit: contain;
    z-index: 1;
}

/* Landscape режим — убираем градиенты, приоритет высоты */
#active-workout.landscape-mode .workout-overlay-top {
    background: none !important;
    padding-bottom: 8px;
}
#active-workout.landscape-mode .workout-overlay-bottom {
    background: none !important;
    padding-top: 12px;
}
#active-workout.landscape-mode .immersive-video {
    object-fit: none;
    width: auto;
    height: 100%;
    left: 50%;
    transform: translateX(-50%);
}

/* Подсказка "Поверни телефон" */
.rotate-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 24px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 16px;
    animation: fadeIn 0.3s ease-out;
    pointer-events: auto;
}
.rotate-hint-icon {
    animation: rotatePhone 2.5s ease-in-out infinite;
}
.rotate-hint-text {
    color: white;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    white-space: nowrap;
}
@keyframes rotatePhone {
    0%, 15% { transform: rotate(0deg); }
    35%, 65% { transform: rotate(-90deg); }
    85%, 100% { transform: rotate(0deg); }
}
@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Лоадер видео */
.immersive-video-loader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background: linear-gradient(145deg, #2C2417 0%, #1E1B14 100%);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}
.immersive-video-loader.active {
    display: flex;
}
.immersive-video-loader-ring {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.15);
    border-top-color: rgba(255,255,255,0.7);
    border-radius: 50%;
    animation: loaderSpin 0.8s linear infinite;
}
.immersive-video-loader-text {
    color: rgba(255,255,255,0.5);
    font-size: 13px;
    font-weight: 500;
}
@keyframes loaderSpin {
    to { transform: rotate(360deg); }
}

.immersive-fallback {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    background: linear-gradient(145deg, #2C2417 0%, #1E1B14 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.immersive-fallback-icon {
    font-size: 80px;
    opacity: 0.15;
}

/* ---- Top overlay (название, таймер, прогресс) ---- */
.workout-overlay-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    background: linear-gradient(to bottom, rgba(0,0,0,0.75) 0%, rgba(0,0,0,0.4) 70%, transparent 100%);
    padding: 12px 16px 24px;
    padding-top: max(12px, env(safe-area-inset-top));
}

.overlay-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.immersive-back-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.immersive-back-btn:active {
    background: rgba(255,255,255,0.3);
}

.immersive-top-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.immersive-timer {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 8px 14px;
    border-radius: 20px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.5px;
}

.immersive-sound-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.immersive-sound-btn:active {
    background: rgba(255,255,255,0.3);
}

/* Ручной масштаб видео — растянуть на весь экран */
.immersive-video.scale-fill {
    object-fit: cover !important;
}

.immersive-exercise-info {
    text-align: left;
    color: #fff;
    flex: 1;
    min-width: 0;
}

.immersive-exercise-counter {
    font-size: 11px;
    font-weight: 500;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.immersive-exercise-name {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.immersive-exercise-reps {
    font-size: 12px;
    font-weight: 500;
    opacity: 0.7;
    margin-top: 2px;
}

/* Progress bar */
.immersive-progress {
    height: 3px;
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
    margin-bottom: 12px;
    overflow: hidden;
}

.immersive-progress-fill {
    height: 100%;
    background: var(--primary, #C06A3E);
    border-radius: 2px;
    transition: width 0.4s ease;
    width: 0%;
}

/* ---- Bottom overlay (подходы, навигация) ---- */
.workout-overlay-bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0.5) 50%, transparent 100%);
    padding: 40px 20px 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}

/* ---- Описание техники (сворачиваемое) ---- */
.immersive-description {
    margin-bottom: 16px;
}

.immersive-description-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 0;
    transition: color 0.2s;
}

.immersive-description-toggle:active {
    color: #fff;
}

.immersive-description-toggle svg {
    transition: transform 0.2s;
}

.immersive-description-toggle.expanded svg {
    transform: rotate(180deg);
}

.immersive-description-text {
    display: none;
    font-size: 13px;
    color: rgba(255,255,255,0.8);
    line-height: 1.5;
    background: rgba(255,255,255,0.08);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 12px;
    border-radius: 10px;
    margin-top: 8px;
}

.immersive-description-text.visible {
    display: block;
    animation: fadeSlideUp 0.2s ease-out;
}

/* ---- Таймер отдыха ---- */
.rest-timer-card {
    text-align: center;
    background: rgba(255,255,255,0.1);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 16px;
    border: 1px solid rgba(255,255,255,0.1);
    animation: fadeSlideUp 0.3s ease-out;
}

.rest-timer-label {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255,255,255,0.6);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 8px;
}

.rest-timer-value {
    font-size: 48px;
    font-weight: 700;
    color: #fff;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    margin-bottom: 12px;
}

.rest-timer-skip {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    padding: 8px 24px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.rest-timer-skip:active {
    background: rgba(255,255,255,0.3);
}

/* ---- Кнопки подходов ---- */
.immersive-sets-label {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255,255,255,0.5);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.immersive-sets-row {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    margin-bottom: 16px;
}
.immersive-sets {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.immersive-set-btn {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    border: 1.5px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.08);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.immersive-set-btn:active {
    transform: scale(0.97);
}

.immersive-set-btn.completed {
    background: var(--success, #7B8F6B);
    border-color: var(--success, #7B8F6B);
    animation: immSetComplete 0.4s ease-out;
}

.immersive-set-btn.completed::after {
    content: '✓';
    position: absolute;
    font-size: 18px;
    font-weight: 700;
}

.immersive-set-btn.completed .set-num {
    opacity: 0;
}

@keyframes immSetComplete {
    0% { transform: scale(1); }
    40% { transform: scale(1.06); }
    100% { transform: scale(1); }
}

/* ---- Строка подходов с навигацией ---- */
.immersive-sets-row {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}
.immersive-sets-nav {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    border: 1.5px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}
.immersive-sets-nav:active {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.95);
}

/* ---- Кнопка завершить ---- */
.immersive-finish-btn {
    width: 100%;
    height: 50px;
    border-radius: 14px;
    border: none;
    background: var(--primary, #C06A3E);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.immersive-finish-btn:active {
    background: var(--primary-dark, #A45832);
    transform: scale(0.98);
}

/* ---- Кнопка назад (выход из тренировки) ---- */
.immersive-back-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    flex-shrink: 0;
    margin-right: 8px;
}
.immersive-back-btn:active {
    background: rgba(255, 255, 255, 0.3);
}

/* ---- Кнопка паузы ---- */
.immersive-pause-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}
.immersive-pause-btn:active {
    background: rgba(255, 255, 255, 0.3);
}
.immersive-timer.paused {
    animation: timerBlink 1s ease-in-out infinite;
}
@keyframes timerBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Убираем синие outline на всех кнопках тренировки */
#active-workout button,
#active-workout .immersive-side-btn {
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

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

@keyframes immExerciseChange {
    0% {
        opacity: 0;
        transform: translateX(30px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

.immersive-animate-in .immersive-exercise-info,
.immersive-animate-in .immersive-sets,
.immersive-animate-in .immersive-description {
    animation: immExerciseChange 0.35s ease-out;
}

/* ---- Медиа-запросы ---- */
@media (max-height: 600px) {
    .immersive-exercise-name {
        font-size: 20px;
    }
    .rest-timer-value {
        font-size: 36px;
    }
    .immersive-set-btn {
        width: 44px;
        height: 44px;
        border-radius: 12px;
    }
}
