/* ==========================================================================
   Watch Page — использует токены из tokens.css
   ========================================================================== */

body {
    overflow: hidden;
    height: 100vh;
    /* dvh — мобильные браузеры с динамическими панелями */
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   Watch Header
   ========================================================================== */

.watch-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background-color: var(--surface);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
    gap: 16px;
    min-height: 52px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.header-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    color: var(--text-2);
    transition: background-color 0.15s, color 0.15s;
    flex-shrink: 0;
}

.header-back:hover {
    background-color: var(--raise);
    color: var(--text);
}

.header-back svg {
    width: 20px;
    height: 20px;
}

.header-title {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.header-title-en {
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-title-ru {
    font-size: 12px;
    color: var(--text-3);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    max-width: 40%;
}

.header-episode-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.2;
    white-space: nowrap;
}

.header-episode-name {
    font-family: var(--font-display);
    font-size: 12px;
    color: var(--text-3);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex: 1;
    min-width: 0;
}

.header-note {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid var(--line);
    color: var(--text-2);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: border-color 0.15s, color 0.15s;
    white-space: nowrap;
    margin-right: 8px;
}

.header-note:hover {
    border-color: var(--gold);
    color: var(--gold);
}

.header-note svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.header-next {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    background-color: var(--raise);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: background-color 0.15s, color 0.15s;
    white-space: nowrap;
}

.header-next:hover {
    background-color: var(--gold);
    color: var(--gold-ink);
}

.header-next svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.watch-container {
    display: flex;
    flex: 1;
    min-height: 0;
    width: 100%;
}

.panel {
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-left {
    flex: 1 1 60%;
    min-width: 30%;
    max-width: 75%;
    background-color: #000;
    display: flex;
    flex-direction: column;
}

.panel-right {
    flex: 1 1 40%;
    min-width: 25%;
    max-width: 70%;
    background-color: var(--surface);
}

/* ==========================================================================
   Resize Handle — grip dots
   ========================================================================== */

.resize-handle {
    width: 12px;
    background-color: var(--void);
    cursor: col-resize;
    flex-shrink: 0;
    transition: background-color 0.2s;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.resize-handle::after {
    content: '';
    width: 2px;
    height: 24px;
    background-image: radial-gradient(circle, var(--line-strong) 1px, transparent 1px);
    background-size: 2px 6px;
    background-repeat: repeat-y;
    background-position: center;
}

.resize-handle:hover,
.resize-handle.active {
    background-color: var(--raise);
}

.resize-handle:hover::after,
.resize-handle.active::after {
    background-image: radial-gradient(circle, var(--text-3) 1px, transparent 1px);
}

/* ==========================================================================
   Video Player
   ========================================================================== */

.video-wrapper {
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.video-wrapper video {
    width: 100%;
    flex: 1;
    /* без этого intrinsic-высота видео выдавливает контролы за пределы панели */
    min-height: 0;
    background-color: #000;
    object-fit: contain;
}

.video-error {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    background-color: rgba(0, 0, 0, 0.75);
    color: var(--text);
    font-size: 15px;
    pointer-events: none;
    z-index: 5;
}

/* ==========================================================================
   Video Controls
   ========================================================================== */

.video-controls {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background-color: var(--surface);
    box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.2);
    gap: 8px;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}

.controls-left,
.controls-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.controls-center {
    flex: 1;
    display: flex;
    align-items: center;
    min-width: 0;
}

.control-btn {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s;
}

.control-btn:hover {
    background-color: var(--raise);
}

.control-btn svg {
    width: 20px;
    height: 20px;
}

/* Переключатель панели субтитров: виден только в мобильной версии */
.phrases-toggle {
    display: none;
}

.phrases-toggle.is-open {
    color: var(--gold);
}

.hidden {
    display: none !important;
}

/* Volume */
.volume-control {
    display: flex;
    align-items: center;
    gap: 4px;
}

.volume-slider {
    width: 70px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--line-strong);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    background: var(--gold);
    border-radius: 50%;
    cursor: pointer;
}

.volume-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--gold);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Time display */
.time-display {
    font-size: 12px;
    color: var(--text-3);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* Progress bar */
.progress-bar {
    width: 100%;
    height: 6px;
    background-color: var(--line-strong);
    border-radius: 3px;
    cursor: pointer;
    position: relative;
    transition: height 0.15s;
}

.progress-bar:hover {
    height: 8px;
}

.progress-bar-fill {
    height: 100%;
    background-color: var(--gold);
    border-radius: 3px;
    width: 0;
    transition: width 0.1s linear;
}

.progress-bar-thumb {
    position: absolute;
    top: 50%;
    left: 0;
    width: 12px;
    height: 12px;
    background-color: var(--gold);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.progress-bar:hover .progress-bar-thumb {
    opacity: 1;
}

/* Subtitle control buttons */
.subtitle-controls {
    display: flex;
    gap: 2px;
    background: var(--raise);
    border-radius: 4px;
    padding: 2px;
}

.sub-btn {
    background: transparent;
    border: none;
    color: var(--text-3);
    padding: 4px 10px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: background-color 0.15s, color 0.15s;
    white-space: nowrap;
    min-width: 32px;
}

.sub-btn:hover:not(.disabled) {
    background-color: var(--raise-2);
    color: var(--text);
}

.sub-btn.active {
    background-color: var(--gold);
    color: var(--gold-ink);
}

.sub-btn.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ==========================================================================
   Subtitle Overlay
   ========================================================================== */

.subtitle-overlay {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    pointer-events: none;
    z-index: 10;
    max-width: 80%;
    transition: opacity 0.15s ease;
}

.subtitle-overlay.hidden {
    opacity: 0;
}

.subtitle-line {
    padding: 6px 16px;
    border-radius: 4px;
    font-size: 20px;
    line-height: 1.4;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9), 0 0 8px rgba(0, 0, 0, 0.7);
    transition: opacity 0.1s ease;
    white-space: pre-wrap;
}

.subtitle-en {
    color: #fff;
    font-weight: 600;
}

/* Русская строка — фирменное субтитровое золото */
.subtitle-ru {
    color: var(--gold);
    font-size: 17px;
    font-weight: 400;
    margin-top: 2px;
}

/* ==========================================================================
   Phrases Panel
   ========================================================================== */

.phrases-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.phrases-header h2 {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
}

.phrases-controls {
    display: flex;
    align-items: center;
}

.auto-scroll-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-3);
    user-select: none;
}

.auto-scroll-toggle input[type="checkbox"] {
    accent-color: var(--gold);
    cursor: pointer;
}

/* Кнопка закрытия панели субтитров — видна только на мобильных */
.phrases-close {
    display: none;
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, color 0.15s;
}

.phrases-close:hover {
    background-color: var(--raise);
    color: var(--text);
}

.phrases-close svg {
    width: 16px;
    height: 16px;
}

.phrases-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

/* Custom scrollbar */
.phrases-list::-webkit-scrollbar {
    width: 6px;
}

.phrases-list::-webkit-scrollbar-track {
    background: transparent;
}

.phrases-list::-webkit-scrollbar-thumb {
    background: var(--line-strong);
    border-radius: 3px;
}

.phrases-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-faint);
}

/* ==========================================================================
   Phrase Item
   ========================================================================== */

.phrase-item {
    padding: 10px 16px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background-color 0.15s, border-color 0.15s;
}

.phrase-item:hover {
    background-color: var(--raise);
}

.phrase-item.active {
    background-color: var(--gold-subtle);
    border-left-color: var(--gold);
}

.phrase-time {
    font-size: 11px;
    color: var(--text-3);
    margin-bottom: 4px;
    font-variant-numeric: tabular-nums;
}

/* Имя спикера: светлый фиолетовый — тёмный #731982 не читался на тёмном фоне */
.phrase-speaker {
    font-size: 11px;
    color: var(--violet);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 2px;
}

/* Английская реплика — антиква: язык контента отличим от перевода */
.phrase-text-en {
    font-family: var(--font-display);
    font-size: 15px;
    color: var(--text);
    font-weight: 500;
    line-height: 1.5;
    margin-bottom: 4px;
}

.phrase-text-ru {
    font-size: 13px;
    color: var(--text-2);
    line-height: 1.4;
}

.phrase-complex {
    display: inline-block;
    font-size: 10px;
    padding: 1px 6px;
    background-color: var(--violet-subtle);
    color: var(--violet);
    border-radius: 3px;
    margin-left: 8px;
    vertical-align: middle;
    font-weight: 600;
}

/* ==========================================================================
   Loading & Error States
   ========================================================================== */

.loading,
.error {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 16px;
    color: var(--text-3);
    font-size: 14px;
}

.error {
    color: var(--danger);
}

/* ==========================================================================
   Fullscreen
   ========================================================================== */

.video-wrapper:fullscreen {
    background-color: #000;
}

.video-wrapper:fullscreen video {
    height: 100%;
}

.video-wrapper:fullscreen .subtitle-overlay {
    bottom: 80px;
}

.video-wrapper:fullscreen .subtitle-line {
    font-size: 28px;
}

.video-wrapper:fullscreen .subtitle-ru {
    font-size: 22px;
}

.video-wrapper:fullscreen .phrases-toggle {
    display: none;
}

/* ==========================================================================
   Responsive — мобильная версия
   ========================================================================== */

@media (max-width: 768px) {
    .watch-header {
        padding: 8px 12px;
        gap: 10px;
        flex-wrap: wrap;
    }

    .header-center {
        order: 3;
        width: 100%;
        max-width: 100%;
        align-items: flex-start;
        padding-left: 48px;
    }

    .header-right {
        flex: 0 0 auto;
    }

    .header-next span {
        display: none;
    }

    .header-next {
        padding: 8px 10px;
    }

    .watch-container {
        flex-direction: column;
    }

    /* Видео занимает всё доступное место, панель субтитров скрыта
       и открывается кнопкой в контролах */
    .panel-left {
        flex: 1 1 auto;
        height: auto;
        min-width: 100%;
        max-width: 100%;
        position: relative;
        z-index: 2;
    }

    .panel-right {
        display: none;
        flex: 0 0 45%;
        height: auto;
        min-width: 100%;
        max-width: 100%;
        border-top: 1px solid var(--line);
        position: relative;
        z-index: 1;
    }

    .watch-container.phrases-open .panel-right {
        display: flex;
    }

    .watch-container.phrases-open .panel-left {
        flex: 0 0 55%;
    }

    .phrases-toggle {
        display: flex;
    }

    /* Регулировку перетаскиванием заменяет кнопка-переключатель */
    .resize-handle {
        display: none;
    }

    /* Компактная панель управления в две строки: прогресс сверху,
       кнопки снизу; громкость — аппаратными кнопками телефона */
    .video-controls {
        flex-wrap: wrap;
        padding: 6px 8px;
        gap: 4px 8px;
    }

    .controls-center {
        flex: 1 1 100%;
        order: -1;
    }

    .controls-left {
        flex: 1 1 auto;
        min-width: 0;
        gap: 2px;
    }

    .controls-right {
        gap: 2px;
    }

    .control-btn {
        padding: 6px;
    }

    .control-btn svg {
        width: 18px;
        height: 18px;
    }

    .sub-btn {
        padding: 4px 7px;
        min-width: 28px;
    }

    .volume-control {
        display: none;
    }

    .time-display {
        margin-left: auto;
        font-size: 11px;
    }

    .phrases-close {
        display: flex;
    }

    /* Компактные субтитры поверх видео, вплотную к панели управления */
    .subtitle-overlay {
        bottom: 50px;
        max-width: 88%;
    }

    .subtitle-line {
        font-size: 15px;
    }

    .subtitle-ru {
        font-size: 13px;
    }

    .video-wrapper:fullscreen .subtitle-overlay {
        bottom: 60px;
    }

    .video-wrapper:fullscreen .subtitle-line {
        font-size: 20px;
    }

    .video-wrapper:fullscreen .subtitle-ru {
        font-size: 16px;
    }
}

/* Очень узкие экраны: время не влезает, позиция видна на прогрессе */
@media (max-width: 360px) {
    .time-display {
        display: none;
    }
}

/* Ландшафт телефона или низкое окно: ширина экрана превышает мобильный
   брейкпоинт, поэтому ориентируемся на высоту. Экран отдан видео,
   панель субтитров — сбоку по кнопке. */
@media (max-height: 500px) and (orientation: landscape) {
    .watch-header {
        flex-wrap: nowrap;
        padding: 6px 12px;
        min-height: 44px;
        gap: 8px;
    }

    .header-center {
        display: none;
    }

    .header-title-ru {
        display: none;
    }

    .watch-container {
        flex-direction: row;
    }

    .panel-left {
        flex: 1 1 auto;
        height: auto;
        min-width: 0;
        max-width: none;
        position: relative;
        z-index: 2;
    }

    .panel-right {
        display: none;
        flex: 0 0 45%;
        height: auto;
        min-width: 0;
        max-width: 45%;
        border-top: none;
        border-left: 1px solid var(--line);
        position: relative;
        z-index: 1;
    }

    .watch-container.phrases-open .panel-right {
        display: flex;
    }

    .phrases-toggle {
        display: flex;
    }

    .resize-handle {
        display: none;
    }

    .phrases-close {
        display: flex;
    }

    .subtitle-overlay {
        bottom: 50px;
        max-width: 88%;
    }

    .subtitle-line {
        font-size: 15px;
    }

    .subtitle-ru {
        font-size: 13px;
    }

    .video-wrapper:fullscreen .subtitle-overlay {
        bottom: 60px;
    }

    .video-wrapper:fullscreen .subtitle-line {
        font-size: 20px;
    }

    .video-wrapper:fullscreen .subtitle-ru {
        font-size: 16px;
    }
}
