/* ==========================================
 * 財商學院 - 單元播放頁樣式
 * lesson.css
 * ========================================== */

/* Hero 區樣式 */
.lesson-hero {
    position: relative;
    overflow: hidden;
}

/* 手機版移除 overflow 限制，讓 fixed 元素可以正常顯示 */
@media (max-width: 1023px) {
    .lesson-hero {
        overflow: visible;
    }
}

/* PC 版：整個 Hero 區浮動 */
@media (min-width: 1024px) {
    .lesson-hero.is-sticky {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    }

    .lesson-hero-placeholder {
        display: none;
    }

    .lesson-hero.is-sticky+.lesson-hero-placeholder {
        display: block;
    }
}

/* 手機版：只有影片浮動 */
@media (max-width: 1023px) {
    .video-wrapper.is-sticky {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
        z-index: 9999;
        background: #000;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
        overflow: hidden;
    }

    /* 當影片浮動時隱藏 header */
    body:has(.video-wrapper.is-sticky)>nav {
        display: none !important;
    }

    .video-wrapper.is-sticky .video-container {
        border-radius: 0;
        position: relative;
        width: 100%;
        height: 0;
        padding-bottom: 56.25%;
        overflow: hidden;
    }

    .video-wrapper.is-sticky .video-container iframe {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }

    .video-wrapper-placeholder {
        display: none;
    }

    .video-wrapper.is-sticky~.video-wrapper-placeholder {
        display: block;
    }
}

.lesson-hero-bg {
    position: absolute;
    inset: -20px;
    background-size: cover;
    background-position: center;
    filter: blur(20px) brightness(0.4);
    transform: scale(1.1);
    z-index: 0;
}

/* 手機版移除 inset 負值 */
@media (max-width: 1023px) {
    .lesson-hero-bg {
        inset: 0;
    }
}

.lesson-hero-content {
    position: relative;
    z-index: 10;
}

/* Hero 區網格：影片 + 字幕 */
.hero-grid {
    display: grid;
    gap: 1rem;
}

@media (min-width: 1024px) {
    .hero-grid {
        grid-template-columns: 2fr 1fr;
        align-items: start;
    }

    /* 字幕面板與影片同高 - 由 JS 動態設定 */
    #subtitleContainer {
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    #subtitlePanel {
        flex: 1;
        overflow-y: auto;
    }
}

@media (max-width: 1023px) {
    #subtitlePanel {
        max-height: 350px;
        overflow-y: auto;
    }

    /* 手機版：字幕控制區優化，防止溢出 */
    #subtitleContainer > .p-3 {
        padding: 0.5rem !important;
    }

    /* 字幕控制列換行 */
    #subtitleContainer > .p-3 > .flex:last-child {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* 字幕偏移控制簡化 (手機版) */
    #subtitleContainer [title*="字幕時間偏移"] {
        flex: 1 1 100%;
        min-width: 0;
        order: 2;
        margin-top: 0.25rem;
    }

    /* 滑桿縮短 */
    #subtitleOffsetSlider {
        min-width: 60px;
    }

    /* 播放控制提示換行 */
    .play-control-hint {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 8px 10px;
    }

    .play-control-hint > div:last-child {
        flex: 1 1 100%;
        max-width: 100%;
        justify-content: center;
    }
}

.video-container {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
    border-radius: 12px;
}

.video-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* 可調整大小的 Hero 區 */
.hero-grid-resizable {
    transition: none;
}

.hero-resize-handle {
    position: relative;
    height: 24px;
    cursor: ns-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 8px;
    user-select: none;
}

.hero-resize-handle::before {
    content: '';
    width: 60px;
    height: 5px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
    transition: all 0.2s;
}

.hero-resize-handle:hover::before {
    background: rgba(16, 185, 129, 0.7);
    width: 80px;
}

.hero-resize-handle.dragging::before {
    background: #10b981;
    width: 100px;
}

/* 尺寸控制按鈕 */
.hero-size-controls {
    position: absolute;
    right: 1rem;
    bottom: 0.5rem;
    display: flex;
    gap: 0.5rem;
    z-index: 20;
}

.hero-size-btn {
    padding: 0.25rem 0.5rem;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
}

.hero-size-btn:hover {
    background: rgba(16, 185, 129, 0.7);
    border-color: #10b981;
}

.hero-size-btn.active {
    background: #10b981;
    border-color: #10b981;
}

/* 桌面版才顯示拖曳把手 */
@media (max-width: 1023px) {
    .hero-resize-handle {
        display: none;
    }
}

/* 字幕項目樣式 */
.subtitle-item {
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    touch-action: pan-y;
    user-select: none;
}

.subtitle-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.subtitle-item.active {
    background: rgba(16, 185, 129, 0.2);
    border-left-color: #10b981;
}

.subtitle-item .original {
    color: #f1f5f9;
    font-weight: 500;
    line-height: 1.5;
    font-size: 0.9rem;
}

.subtitle-item .translated {
    color: #94a3b8;
    font-size: 0.85em;
    margin-top: 4px;
    line-height: 1.4;
}

.subtitle-item .timestamp {
    font-size: 0.7em;
    color: #64748b;
    font-family: monospace;
    cursor: pointer;
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    display: inline-block;
    margin-bottom: 4px;
}

.subtitle-item .timestamp:hover {
    background: #10b981;
    color: white;
}

/* 字幕面板深色主題 */
#subtitleContainer {
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#subtitlePanel {
    scroll-behavior: smooth;
}

/* 可點擊單字 */
.clickable-word {
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.15s ease;
}

.clickable-word:hover {
    background: rgba(16, 185, 129, 0.3);
    color: #6ee7b7;
}

/* 單字查詢 Modal */
.word-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.word-modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.word-modal {
    background: white;
    border-radius: 20px;
    max-width: 420px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(0.9) translateY(20px);
    transition: all 0.2s ease;
}

.word-modal-overlay.show .word-modal {
    transform: scale(1) translateY(0);
}

.word-modal-header {
    padding: 1.5rem;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border-radius: 20px 20px 0 0;
    position: relative;
}

.word-modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
}

.word-modal-body {
    padding: 1.5rem;
}

.word-modal-word {
    font-size: 2rem;
    font-weight: 800;
}

.word-modal-phonetic {
    font-size: 1rem;
    opacity: 0.9;
}

.word-modal-section {
    margin-bottom: 1rem;
}

.word-modal-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.word-modal-def-zh {
    color: #1e293b;
    font-weight: 500;
    font-size: 1.1rem;
}

.play-control-hint {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    text-align: center;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.2s ease;
}

.play-control-hint.paused {
    background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
}

.mode-btn.active {
    background: rgba(16, 185, 129, 0.3) !important;
    color: #6ee7b7 !important;
}

/* 發音練習按鈕 */
.word-modal-practice-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.word-modal-practice-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.word-modal-practice-btn.recording {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    animation: pulse-recording 1s infinite;
}

@keyframes pulse-recording {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

.word-modal-pronunciation-result {
    background: #f0fdf4;
    border-radius: 12px;
    padding: 1rem;
    margin-top: 0.75rem;
    display: none;
}

.word-modal-pronunciation-result.show {
    display: block;
}

.quiz-option {
    transition: all 0.2s ease;
}

.quiz-option:hover {
    transform: translateX(4px);
}

.quiz-option.correct {
    background: #dcfce7 !important;
    border-color: #22c55e !important;
}

.quiz-option.incorrect {
    background: #fee2e2 !important;
    border-color: #ef4444 !important;
}

/* 錄音按鈕樣式 */
.record-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 2px 6px;
    margin-left: 6px;
    border-radius: 4px;
    transition: all 0.2s;
    opacity: 0.6;
}

.record-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.record-btn.recording {
    animation: pulse-recording 1s infinite;
    opacity: 1;
    background: rgba(239, 68, 68, 0.3);
}

/* YouTube 延遲載入縮圖樣式 */
.video-thumbnail-wrapper {
    position: absolute;
    inset: 0;
    cursor: pointer;
    z-index: 10;
}

.video-thumbnail-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-thumbnail-wrapper .play-button-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    transition: background 0.3s;
}

.video-thumbnail-wrapper:hover .play-button-overlay {
    background: rgba(0, 0, 0, 0.5);
}

.video-thumbnail-wrapper .play-icon {
    width: 68px;
    height: 48px;
    background: #ff0000;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.video-thumbnail-wrapper:hover .play-icon {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.4);
}

.video-thumbnail-wrapper .play-icon::after {
    content: '';
    border: solid white;
    border-width: 0 0 12px 20px;
    border-color: transparent transparent transparent white;
    margin-left: 4px;
}

/* ==========================================
 * 播放模式切換器樣式
 * ========================================== */
.playback-toggle {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    font-size: 0.65rem;
}

.playback-toggle input[type="checkbox"] {
    display: none;
}

.playback-toggle .toggle-slider {
    width: 28px;
    height: 14px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 7px;
    position: relative;
    transition: background 0.2s;
}

.playback-toggle .toggle-slider::before {
    content: '';
    position: absolute;
    width: 10px;
    height: 10px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
}

.playback-toggle input:checked+.toggle-slider {
    background: #10b981;
}

.playback-toggle input:checked+.toggle-slider::before {
    transform: translateX(14px);
}

.playback-toggle .toggle-label {
    color: rgba(255, 255, 255, 0.6);
    transition: color 0.2s;
}

.playback-toggle input:checked~.toggle-label {
    color: #10b981;
    font-weight: 600;
}

/* ==========================================
 * 側邊模式 (Side Mode) - 桌面版 1440px+
 * 策略：使用 CSS fixed 定位將 Hero 區移到右側
 * ========================================== */

/* 側邊模式切換按鈕 */
.side-mode-toggle {
    display: none;
    padding: 0.25rem 0.75rem;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
    gap: 0.25rem;
    align-items: center;
}

.side-mode-toggle:hover {
    background: rgba(16, 185, 129, 0.7);
    border-color: #10b981;
}

.side-mode-toggle.active {
    background: #10b981;
    border-color: #10b981;
}

/* 僅 1440px+ 顯示切換按鈕 */
@media (min-width: 1440px) {
    .side-mode-toggle {
        display: flex;
    }

    /* 關閉按鈕預設隱藏，側邊模式時才顯示 */
    .side-mode-close {
        display: none;
    }

    body.side-mode-enabled .side-mode-close {
        display: flex;
    }

    /* 右側模式時隱藏右側按鈕 */
    body.side-mode-right #sideModeRight {
        display: none;
    }

    /* 左側模式時隱藏左側按鈕 */
    body.side-mode-left #sideModeLeft {
        display: none;
    }
}

/* 側邊模式啟用時的佈局 - 僅 1440px+ */
@media (min-width: 1440px) {

    /* 側邊模式共用：將 Hero 區固定 */
    body.side-mode-enabled .lesson-hero {
        position: fixed !important;
        top: 0 !important;
        width: 450px !important;
        height: 100vh !important;
        z-index: 1000;
        background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    /* 右側模式 */
    body.side-mode-right .lesson-hero {
        right: 0 !important;
        left: auto !important;
        border-left: 1px solid rgba(255, 255, 255, 0.1);
        border-right: none;
    }

    /* 左側模式 */
    body.side-mode-left .lesson-hero {
        left: 0 !important;
        right: auto !important;
        border-right: 1px solid rgba(255, 255, 255, 0.1);
        border-left: none;
    }

    body.side-mode-enabled .lesson-hero .lesson-hero-bg {
        display: none;
    }

    body.side-mode-enabled .lesson-hero .lesson-hero-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        padding: 0;
        max-width: 100%;
        overflow: hidden;
    }

    /* 側邊模式：Hero Grid 改為垂直排列 */
    body.side-mode-enabled .lesson-hero .hero-grid {
        display: flex !important;
        flex-direction: column !important;
        flex: 1;
        min-height: 0;
    }

    /* 側邊模式：影片區 */
    body.side-mode-enabled .lesson-hero .video-wrapper {
        width: 100%;
        flex-shrink: 0;
    }

    body.side-mode-enabled .lesson-hero .video-container {
        border-radius: 0;
    }

    /* 側邊模式：字幕區佔滿剩餘空間 */
    body.side-mode-enabled .lesson-hero .subtitle-wrapper {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    body.side-mode-enabled .lesson-hero #subtitleContainer {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        border-radius: 0;
        border: none;
    }

    body.side-mode-enabled .lesson-hero #subtitlePanel {
        flex: 1;
        min-height: 0;
        max-height: none;
        overflow-y: auto;
    }

    /* 側邊模式：覆蓋 is-sticky 的定位 */
    body.side-mode-right .lesson-hero.is-sticky {
        left: auto !important;
        right: 0 !important;
        width: 450px !important;
    }

    body.side-mode-left .lesson-hero.is-sticky {
        left: 0 !important;
        right: auto !important;
        width: 450px !important;
    }

    /* 側邊模式：隱藏尺寸按鈕和拖曳把手，但保留切換按鈕 */
    body.side-mode-enabled .lesson-hero .hero-size-btn,
    body.side-mode-enabled .lesson-hero .hero-resize-handle {
        display: none !important;
    }
}

/* ==========================================
 * 全螢幕專注模式 - Absolute Layout (最終修正版)
 * 不需要 Grid 支援，相容性最高
 * ========================================== */
/* 隱藏側邊欄 HTML 結構（不再需要） */
.lesson-sidebar {
    display: none !important;
}

/* ==========================================
 * 側邊模式 (Restored)
 * ========================================== */

/* 側邊模式：將控制區放在字幕區頂部 */
body.side-mode-enabled .lesson-hero .hero-size-controls {
    position: static;
    justify-content: flex-end;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.3);
}

/* 側邊模式：隱藏 placeholder */
body.side-mode-enabled .lesson-hero-placeholder {
    display: none !important;
}

/* 右側模式：主內容區右側留空 */
body.side-mode-right .lesson-page-wrapper {
    margin-right: 450px;
    margin-left: 0;
}

/* 左側模式：主內容區左側留空 */
body.side-mode-left .lesson-page-wrapper {
    margin-left: 450px;
    margin-right: 0;
}

body.side-mode-enabled .lesson-main-content {
    max-width: 100%;
}

/* 右側模式：讓 header 和 footer 避開側邊欄 */
body.side-mode-right>header,
body.side-mode-right>nav,
body.side-mode-right>footer,
body.side-mode-right .site-header,
body.side-mode-right .site-footer {
    margin-right: 450px;
    margin-left: 0;
}

/* 左側模式：讓 header 和 footer 避開側邊欄 */
body.side-mode-left>header,
body.side-mode-left>nav,
body.side-mode-left>footer,
body.side-mode-left .site-header,
body.side-mode-left .site-footer {
    margin-left: 450px;
    margin-right: 0;
}