/* assets/css/view_lesson.css */

/* =========================================
   1. Base Structure (Unrestricted Scrolling)
   ========================================= */
body { 
    background-color: #f8fafc; 
    font-family: 'Kanit', sans-serif; 
    margin: 0;
    padding: 0;
    overflow-x: hidden; 
}

/* =========================================
   2. Media Layout (Adaptive Flow)
   ========================================= */
#main-structure {
    display: flex;
    justify-content: center;
    align-items: flex-start; 
    padding: 10px 15px 120px 15px; 
    width: 100%;
}

#interactive-container {
    position: relative;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    max-width: 100%;
    transition: all 0.5s cubic-bezier(0.25, 1, 0.5, 1);
    transform-origin: bottom right;
}

#base-img { 
    max-width: 100%;
    max-height: 80vh; 
    width: auto;
    height: auto;
    display: block;
    object-fit: contain; 
    border-radius: 16px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.15);
    background-color: #fff; 
    transition: border-radius 0.5s;
}

/* =========================================
   3. Floating Action Buttons (Bottom Fixed)
   ========================================= */
.floating-bottom-btn {
    position: fixed !important;
    bottom: 25px !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 1050 !important;
    animation: popUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popUp {
    from { transform: translateY(100px) scale(0.8); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

body.menu-open #action-links-container.floating-bottom-btn {
    display: none !important;
}

/* =========================================
   4. Picture-in-Picture (PIP) Mode
   ========================================= */
body.menu-open #interactive-container {
    position: fixed !important;
    bottom: 30px !important;
    right: 20px !important;
    transform: scale(0.35) !important;
    z-index: 10000 !important;
}

body.menu-open #base-img {
    border-radius: 35px !important;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5) !important;
}

body.menu-open .student-pin {
    opacity: 0 !important;
    pointer-events: none !important;
    transition: opacity 0.2s;
}

body.menu-open #interactive-container::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.1);
    z-index: 999; 
    cursor: pointer;
    border-radius: 35px;
}

/* =========================================
   5. Topic Panel (Centered Overlay)
   ========================================= */
#topic-panel {
    width: 90%;
    max-width: 400px;
    height: 80vh;
    background-color: #fff;
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    border: none;
    
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    z-index: 9999 !important; 
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

body.menu-open #topic-panel {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    visibility: visible;
}

.panel-content { 
    padding: 25px; 
    height: 100%; 
    display: flex; 
    flex-direction: column; 
}

/* 🌟 แก้ไขตรงนี้: เพิ่ม padding-bottom กันโดน PiP บัง 🌟 */
.panel-scroll { 
    flex-grow: 1; 
    overflow-y: auto; 
    padding-right: 5px; 
    padding-bottom: 150px; 
}

.panel-scroll::-webkit-scrollbar { width: 6px; }
.panel-scroll::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 10px; }
.panel-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
.panel-scroll::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.topic-btn { 
    transition: all 0.3s ease; 
    border: 2px solid #e2e8f0; 
    background-color: #fff; 
    margin-bottom: 10px;
}
.topic-btn:hover { 
    transform: translateY(-3px); 
    border-color: #4f46e5; 
    box-shadow: 0 10px 20px rgba(79, 70, 229, 0.1) !important;
}

/* =========================================
   6. Panel Toggle Button
   ========================================= */
#panel-toggle-btn {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    width: 35px;
    height: 70px;
    background-color: #fff;
    border: 1px solid #e2e8f0;
    border-right: none;
    border-radius: 12px 0 0 12px;
    box-shadow: -5px 0 15px rgba(0,0,0,0.05);
    z-index: 9999 !important; 
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    transition: all 0.3s ease;
}
#panel-toggle-btn:hover { background-color: #f1f5f9; color: #4f46e5; }
#panel-toggle-btn i { transition: transform 0.5s ease; }
body.menu-open #panel-toggle-btn { transform: translateY(-50%) translateX(100%); }

/* =========================================
   7. Basic UI & Interactive Pins
   ========================================= */
.top-nav { background-color: transparent; padding: 10px 0; }
.lesson-header { 
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%); 
    color: white; 
    padding: 20px 15px 30px 15px; 
    border-radius: 0 0 24px 24px; 
    box-shadow: 0 10px 20px rgba(79, 70, 229, 0.2); 
    text-align: center; 
}

/* Pin marker with dynamic CSS variable support */
.student-pin { 
    position: absolute; 
    width: 30px; 
    height: 30px; 
    background-color: var(--pin-color, #ffc107); /* Default to yellow if no color is provided */
    border: 3px solid #fff; 
    border-radius: 50%; 
    transform: translate(-50%, -50%); 
    cursor: pointer; 
    z-index: 10; 
    box-shadow: 0 0 10px rgba(0,0,0,0.4); 
    animation: pulse-dynamic 1.5s infinite; 
    transition: transform 0.2s, filter 0.2s;
}

.student-pin:hover, .student-pin:active { 
    transform: translate(-50%, -50%) scale(1.15); 
    filter: brightness(1.2); /* Slight brightness increase on interaction */
}

/* Dynamic pulse animation adapting to pin color */
@keyframes pulse-dynamic { 
    0% { box-shadow: 0 0 0 0 var(--pin-color, #ffc107); } 
    70% { box-shadow: 0 0 0 15px transparent; } 
    100% { box-shadow: 0 0 0 0 transparent; } 
}

/* =========================================
   8. Modal & Flip Card Mechanics
   ========================================= */
.modal { z-index: 99999 !important; }
.modal-backdrop { z-index: 99998 !important; }

.modal.fade .modal-dialog { transform: scale(0.7) translateY(50px); opacity: 0; transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
.modal.show .modal-dialog { transform: scale(1) translateY(0); opacity: 1; }
.modal-content { border-radius: 20px; border: none; overflow: hidden; }

/* Removed background styling to support smooth JS color transition */
.modal-header { 
    color: white; 
    border-bottom: none; 
    transition: background 0.2s ease; 
}

#video-container { background-color: #000; width: 100%; display: flex; justify-content: center; overflow: hidden; position: relative; }
#modal-video-player { width: 100%; max-width: 400px; aspect-ratio: 9 / 16; object-fit: cover; pointer-events: none; }
#mute-toggle-btn { position: absolute; bottom: 15px; right: 15px; width: 40px; height: 40px; border-radius: 50%; background-color: rgba(0, 0, 0, 0.6); border: 2px solid rgba(255, 255, 255, 0.8); color: white; display: flex; align-items: center; justify-content: center; z-index: 50; cursor: pointer; pointer-events: auto; transition: all 0.2s ease;}
#mute-toggle-btn:hover { background-color: rgba(225, 29, 72, 0.9); transform: scale(1.1); }

.question-box { background-color: #f8fafc; border-left: 4px solid #e11d48; border-radius: 8px; }

.flip-card { background-color: transparent; perspective: 1000px; }
.flip-card-inner { display: grid; width: 100%; }
.flip-card-front, .flip-card-back { grid-area: 1 / 1; width: 100%; backface-visibility: hidden; -webkit-backface-visibility: hidden; transition: transform 0.6s cubic-bezier(0.4, 0.2, 0.2, 1); }
.flip-card-front { transform: rotateY(0deg); z-index: 2; background: #fff; }
.flip-card-back { transform: rotateY(-180deg); background: #fff; padding: 20px; }
.flip-card.flipped .flip-card-front { transform: rotateY(180deg); }
.flip-card.flipped .flip-card-back { transform: rotateY(0deg); z-index: 3; }

/* =========================================
   9. Main Video Mute Toggle (Transparent Style)
   ========================================= */
#main-mute-btn {
    position: absolute;
    bottom: 15px;
    right: 15px;
    width: 35px;       
    height: 35px;
    background-color: transparent; 
    border: none;      
    color: rgba(255, 255, 255, 0.9); 
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    cursor: pointer;
    transition: all 0.2s ease;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7); 
}

#main-mute-btn:hover, #main-mute-btn:active {
    opacity: 0.4;
    transform: scale(0.9);
}

body.menu-open #main-mute-btn {
    display: none !important;
}

/* =========================================
   10. Video Loading/Buffering Overlay
   ========================================= */
.loader-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.95); /* Dark navy background for a professional look */
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100; /* Top-most layer covering media and pins */
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

/* Match border-radius in PIP mode */
body.menu-open .loader-overlay {
    border-radius: 35px;
}

.tracking-wide {
    letter-spacing: 1px;
}