:root {
    --theme-bg: #0f3ea5; 
    --theme-btn-active: #3498db;
    --theme-menu-bg: rgba(0, 0, 0, 0.75);
    --theme-text-color: #ffffff;
    --nav-height-desktop: 70px;
    --nav-height-mobile: 55px; 
}

body, html {
    margin: 0; padding: 0; width: 100%; height: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--theme-bg); color: var(--theme-text-color);
    overflow: hidden; transition: background-color 0.5s ease;
    user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}

#webgl-canvas {
    position: absolute; top: 0; left: 0; width: 100vw; height: 100vh;
    z-index: 0; display: block; outline: none;
}

#bg-video {
    display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; 
    object-fit: cover; z-index: -2; pointer-events: none;
    opacity: 0; transition: opacity 1.5s ease-in-out; 
}

/* ==========================================================
   💡 ข้อ 4: โลโก้ Desktop (ย่อให้เล็กลง)
   ========================================================== */
.desktop-nav {
    position: fixed; top: 0; left: 0; width: 100%; height: var(--nav-height-desktop);
    background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
    z-index: 200; display: flex; align-items: center; justify-content: space-between; padding: 0 40px;
    opacity: 0; pointer-events: none; transition: opacity 1.5s ease-in-out;
}
.desktop-nav .logo, #site-logo { 
    max-height: 40px !important; 
    max-width: 90px !important;  
    object-fit: contain; pointer-events: auto; 
}
.desktop-nav .menu-items { display: flex; gap: 20px; pointer-events: auto; }
.desktop-nav a {
    color: #fff; text-decoration: none; font-weight: bold; font-size: 1.1em;
    padding: 8px 15px; border-radius: 8px; transition: 0.3s; display: inline-flex; align-items: center; gap: 8px;
}
.desktop-nav a:hover, .desktop-nav a.active { background-color: var(--theme-btn-active); }

.mobile-nav {
    display: none; position: fixed; bottom: 0; left: 0; width: 100%; height: var(--nav-height-mobile);
    background-color: rgba(0, 0, 0, 0.95); backdrop-filter: blur(10px);
    z-index: 200; box-shadow: 0 -4px 15px rgba(0,0,0,0.8);
    opacity: 0; pointer-events: none; transition: opacity 1.5s ease-in-out;
}
.mobile-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: rgba(255,255,255,0.6); text-decoration: none; font-size: 0.75em;
    transition: 0.3s; padding-bottom: 5px;
}
.mobile-nav a i { font-size: 1.5em; margin-bottom: 3px; }
.mobile-nav a.active { color: var(--theme-btn-active); font-weight: bold; }

#app-content {
    position: fixed; z-index: 10;
    width: 360px; right: 20px; top: calc(var(--nav-height-desktop) + 20px);
    height: calc(100vh - var(--nav-height-desktop) - 40px);
    background-color: var(--theme-menu-bg); border-radius: 12px;
    backdrop-filter: blur(8px); box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    display: flex; flex-direction: column; overflow: hidden;
    opacity: 0; pointer-events: none; transition: opacity 0.5s ease;
}

/* ==========================================================
   💡 ข้อ 2: ปุ่มกล้อง L F R บน Desktop เอากรอบ/เบลอออก
   ========================================================== */
#camera-controls { 
    position: fixed; z-index: 20; display: flex; gap: 8px; 
    opacity: 0; pointer-events: none; transition: opacity 1.5s ease-in-out;
    right: 400px; bottom: 20px; flex-direction: column;
}
#camera-controls button {
    background-color: transparent !important; 
    border: none !important;
    color: rgba(255, 255, 255, 0.4) !important; 
    width: 45px; height: 40px; border-radius: 8px;
    font-size: 1.1em; font-weight: normal !important; cursor: pointer; 
    backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
    transition: all 0.2s; display: flex; justify-content: center; align-items: center;
    box-shadow: none !important; text-shadow: 1px 1px 2px rgba(0,0,0,0.8) !important;
}
#camera-controls button:hover { color: #fff !important; }
#camera-controls button:active { transform: scale(0.9); }

@media (max-width: 768px) {
    .desktop-nav .menu-items, 
    .desktop-nav a { 
        display: none !important; 
    }
    
    .desktop-nav { 
        display: block !important; 
        background: transparent; 
        padding: 15px 20px; 
        height: auto; 
        pointer-events: none; 
    }
    
    /* 💡 ข้อ 4: ลดขนาดโลโก้ลงครึ่งนึง (Mobile) */
    .desktop-nav .logo, #site-logo { 
        display: block !important;
        max-width: 70px !important;  
        max-height: 30px !important; 
        pointer-events: auto; 
        margin: 0; 
        float: left; 
    }

    .mobile-nav { display: flex; }
    
    /* 🚨🚨🚨 รื้อทิ้งข้อจำกัด: ปลดล็อกกล่อง #app-content ให้ทิ้งตัวลงพื้นและกางเต็ม 100% 🚨🚨🚨 */
    #app-content {
        width: 100% !important; right: 0 !important; left: 0 !important; 
        bottom: 0 !important; /* 🔥 ดันติดพื้น ลบ var(--nav-height-mobile) ทิ้ง */
        top: 0 !important;    /* 🔥 ดันติดเพดาน */
        height: 100vh !important; /* 🔥 ยืดเต็ม 100% ลบ 38vh ทิ้ง */
        margin: 0 !important;
        border-radius: 0 !important; padding: 0 !important;
        display: block !important; 
        overflow-y: auto !important;
        background-color: var(--theme-menu-bg) !important;
        opacity: 1 !important;
        backdrop-filter: none !important; /* 🔥 ปลดล็อกกรงขัง */
        -webkit-backdrop-filter: none !important;
    }
    
    /* 🚨 แก้บั๊กเหวี่ยงแห: ละเว้นกล่อง Loading และระบบ Player ไม่ให้โดนบังคับ height: auto */
    #app-content > div:not(#fullscreen-loader):not(#view-player):not(#dtv-popup-canvas-pane):not(.modal) { 
        height: auto !important; 
        display: block !important; 
    }

    #home-anim-list-wrapper, #sentences-wrapper, #dtv-wrapper, #blank-wrapper, #member-wrapper { 
        overflow: visible !important; height: auto !important; flex: none !important; 
    }
    
    .settings-accordion { margin-top: 15px !important; margin-bottom: 20px !important; }

    /* ==========================================================
       💡 ข้อ 2: ปุ่มกล้อง L F R บน Mobile (ย้ายไปริมขวาล่าง, เรียงแนวตั้ง)
       ========================================================== */
    #camera-controls { 
        width: auto !important; right: 15px !important; left: auto !important; padding: 0 !important; 
        bottom: calc(38vh + var(--nav-height-mobile) + 15px) !important; 
        flex-direction: column !important; justify-content: flex-end !important;
        pointer-events: none !important; 
    }
    #camera-controls button { 
        width: 35px !important; height: 35px !important; font-size: 0.9em !important; font-weight: normal !important;
        background-color: transparent !important; 
        border: none !important; 
        backdrop-filter: none !important; -webkit-backdrop-filter: none !important; 
        color: rgba(255, 255, 255, 0.4) !important; 
        pointer-events: auto !important; 
        margin-bottom: 8px !important;
        box-shadow: none !important; text-shadow: 1px 1px 2px rgba(0,0,0,0.8) !important;
    }
}

/* ====================================================================
   CSS UI ทั้งหมด สำหรับกล่องคำศัพท์และส่วนประกอบ (Components)
   ==================================================================== */
::-webkit-scrollbar { width: 8px; height: 6px; }
::-webkit-scrollbar-track { background-color: transparent; }
::-webkit-scrollbar-thumb { background-color: rgba(255,255,255,0.3); border-radius: 4px; }

/* 💡 เปิดใช้งาน Scrollbar แนวนอน ให้เห็นเป็นเส้นบางๆ สวยงาม และเลื่อนบน Desktop ได้ง่าย */
.horizontal-scroller::-webkit-scrollbar, .tabs-container::-webkit-scrollbar { height: 4px; display: block; }
.horizontal-scroller::-webkit-scrollbar-thumb, .tabs-container::-webkit-scrollbar-thumb { background-color: rgba(255,255,255,0.25); border-radius: 4px; }
.horizontal-scroller::-webkit-scrollbar-track, .tabs-container::-webkit-scrollbar-track { background-color: transparent; }
.horizontal-scroller, .tabs-container { -ms-overflow-style: auto; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.25) transparent; }

.control-group { margin-bottom: 15px; flex-shrink: 0; }
.control-group label { display: block; margin-bottom: 8px; font-size: 0.9em; opacity: 0.8; }

/* 💡 ข้อ 3: ลบเส้นคั่นและขยับหมวดหมู่ย่อยให้ชิดขึ้นมาก */
#home-category-tabs {
    border-bottom: none !important;
    margin-bottom: 0 !important;
    padding-bottom: 5px !important;
}
#home-subcategory-wrapper {
    margin-top: -5px !important; 
}

/* 💡 ทำให้ปุ่ม Loading สลับเมนู เป็นสีเทาเหมือนกล่องคำศัพท์ */
.fa-spinner { 
    color: #888888 !important; 
}
#app-content > div[style*="display:flex"]:not(#fullscreen-loader) {
    flex-direction: column !important;
    color: rgba(255,255,255,0.5) !important;
    font-size: 0.9em !important;
}
#app-content > div[style*="display:flex"]:not(#fullscreen-loader) .fa-spinner {
    font-size: 1.5rem !important;
    margin-bottom: 10px !important;
}

/* 🚨🚨🚨 THE GHOST BUSTER: CSS ของหน้า Loading เต็มจอ 🚨🚨🚨 */
body #app-content > #fullscreen-loader { 
    position: fixed !important; 
    top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
    width: 100vw !important; height: 100vh !important; max-height: 100vh !important;
    background: #000 !important; z-index: 9999999 !important;
    display: none !important; 
    flex-direction: column !important; 
    align-items: center !important; 
    justify-content: center !important;
    opacity: 0; transition: opacity 0.5s ease;
    transform: none !important; margin: 0 !important; border-radius: 0 !important;
}
body #app-content > #fullscreen-loader.loading { 
    display: flex !important; 
    opacity: 1 !important;
}
body #app-content > #fullscreen-loader .spinner-border { color: #888888 !important; }
body #app-content > #fullscreen-loader #loading-text {
    color: rgba(255, 255, 255, 0.5) !important;
    font-size: 0.9em !important;
    font-weight: normal !important;
}

/* 💡 แก้บั๊ก CSS กล่องคำศัพท์แตก (บังคับให้ Style นี้ทำงานเฉพาะตัวกล่อง Loading เท่านั้น ไม่ให้ไปกวนปุ่มคำศัพท์) */
#home-anim-buttons > div:not(.anim-item-container) {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 120px;
}

.anim-list { display: flex; flex-direction: column; gap: 5px; min-height: 50px; }
.anim-item-container { display: flex; gap: 5px; align-items: stretch; }

.anim-item-container button {
    background-color: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2);
    color: var(--theme-text-color); padding: 10px; border-radius: 6px; cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s; font-size: 0.9em;
}
.anim-item-container button:hover:not(:disabled) { background-color: rgba(255,255,255,0.2); }

.btn-star {
    flex: 0 0 35px; background-color: transparent !important; display: flex; justify-content: center;
    align-items: center; padding: 0 !important; font-size: 1.1em; opacity: 0.6; border: 1px solid rgba(255,255,255,0.1) !important;
}
.btn-star.fav { color: #f1c40f; opacity: 1; text-shadow: 0 0 5px rgba(241, 196, 15, 0.5); }
.btn-star:hover { background-color: rgba(255,255,255,0.1) !important; opacity: 1; }

.btn-speak {
    flex: 0 0 60px; background-color: rgba(255, 255, 255, 0.15) !important; display: flex; justify-content: center; 
    align-items: center; padding: 0 !important; font-size: 0.85em; font-weight: bold; color: #f1c40f !important;
    position: relative; overflow: hidden; border: 1px solid rgba(255,255,255,0.2) !important;
}
.btn-speak:hover:not(:disabled) { background-color: rgba(255, 255, 255, 0.25) !important; color: var(--theme-text-color) !important;}
.btn-speak span { position: relative; z-index: 2; }

.btn-action {
    flex: 1; text-align: left; display: flex; flex-direction: column;
    justify-content: center; position: relative; overflow: hidden; padding-top: 6px !important; padding-bottom: 6px !important;
}
.text-main { display: block; font-size: 1.15em; font-weight: bold; line-height: 1.2; word-wrap: break-word; }
.text-sub { display: block; font-size: 0.8em; opacity: 0.7; margin-top: 3px; font-weight: normal; word-wrap: break-word; color: var(--theme-text-color); }

.btn-action.active { border-color: var(--theme-btn-active) !important; background-color: rgba(255,255,255,0.25) !important; }
.btn-action.active .text-main { color: var(--theme-text-color); }
.btn-action.active .text-sub { opacity: 0.85; }

.locked-tab { filter: grayscale(100%); opacity: 0.6; cursor: not-allowed !important; border-color: rgba(255,255,255,0.2) !important; }
.locked-item .btn-action, .locked-item .btn-speak { opacity: 0.5; filter: grayscale(80%); cursor: not-allowed !important; background-color: rgba(0,0,0,0.3) !important; }

.horizontal-scroller {
    display: flex; overflow-x: auto; gap: 8px; padding: 5px 0 10px 0; margin-bottom: 5px;
    border-bottom: 1px solid rgba(255,255,255,0.1); 
}

.lang-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background-color: rgba(255,255,255,0.05); border: 2px solid transparent; border-radius: 8px;
    padding: 5px 10px; cursor: pointer; min-width: 55px; transition: all 0.2s; user-select: none;
}
.lang-btn:hover { background-color: rgba(255,255,255,0.1); }
.lang-btn.active { border-color: var(--theme-btn-active); background-color: rgba(255,255,255,0.15); }
.lang-flag { font-size: 1.8em; line-height: 1; margin-bottom: 3px; font-family: 'Twemoji Country Flags', 'Segoe UI Emoji', 'Apple Color Emoji', sans-serif; }
.lang-name { font-size: 0.65em; white-space: nowrap; font-weight: bold; opacity: 0.8; }
.lang-btn.active .lang-name { opacity: 1; }

.tabs-container { display: flex; overflow-x: auto; gap: 10px; padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px solid rgba(255,255,255,0.1); align-items: center; padding-top: 1px; }
.tab-btn { 
    background-color: rgba(255,255,255,0.1); border: 2px solid rgba(255, 255, 255, 0.4); border-radius: 8px; padding: 0; cursor: pointer; white-space: nowrap; font-size: 0.85em; 
    transition: transform 0.3s, border-color 0.2s, box-shadow 0.2s; display: flex; align-items: flex-end; justify-content: center; height: 65px; min-width: 105px; 
    background-size: cover; background-position: center; background-repeat: no-repeat; position: relative; overflow: hidden; box-shadow: 0 2px 4px rgba(0,0,0,0.2); flex-shrink: 0;
}
.tab-btn:hover:not(.locked-tab) { border-color: rgba(255, 255, 255, 0.8); }
.tab-btn.active { border-color: #ffffff; border-width: 3px; transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.4); background-color: transparent; }
.tab-btn span { background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.4) 60%, transparent 100%); width: 100%; text-align: center; padding: 15px 0 4px 0; position: relative; z-index: 2; color: rgba(255,255,255,0.95); font-weight: 300; font-size: 0.75em; text-shadow: 1px 1px 2px rgba(0,0,0,0.9); pointer-events: none; }

.sub-tab-card {
    background-color: rgba(255,255,255,0.1); border: 2px solid rgba(255, 255, 255, 0.4); 
    border-radius: 8px; cursor: pointer; display: flex; align-items: flex-end; justify-content: center;
    height: 50px; min-width: 90px; max-width: 110px; position: relative; overflow: hidden; flex-shrink: 0;
    transition: 0.2s; box-shadow: 0 2px 4px rgba(0,0,0,0.2); padding: 0;
    background-size: cover; background-position: center; background-repeat: no-repeat;
}
.sub-tab-card:hover:not(.locked-tab) { border-color: rgba(255, 255, 255, 0.8); }
.sub-tab-card.active { border-color: #ffffff; border-width: 2px; transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.4); background-color: transparent; }
.sub-tab-card span {
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.4) 60%, transparent 100%); 
    width: 100%; text-align: center; padding: 10px 4px 4px 4px;
    position: relative; z-index: 2; color: rgba(255,255,255,0.95); 
    font-weight: 300; font-size: 0.7em; text-shadow: 1px 1px 2px rgba(0,0,0,0.9); pointer-events: none;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.img-box-btn { 
    background-color: rgba(255,255,255,0.1); border: 2px solid transparent; border-radius: 12px; padding: 0; cursor: pointer; transition: all 0.2s; display: flex; align-items: flex-end; justify-content: center;
    height: 120px; min-width: 120px; background-size: cover; background-position: center; background-repeat: no-repeat; position: relative; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.2); flex-shrink: 0;
}
.img-box-btn.active { border-color: #ffffff !important; transform: translateY(-4px); box-shadow: 0 6px 12px rgba(0,0,0,0.4); background-color: transparent; }
.img-box-btn-label { background-color: rgba(0, 0, 0, 0.5); width: 100%; text-align: center; padding: 6px 0; font-size: 0.85em; font-weight: bold; color: white; z-index: 2; position: relative; pointer-events: none; }

.settings-accordion { background-color: rgba(0,0,0,0.4); border: 1px solid rgba(255,255,255,0.2); border-radius: 8px; margin-top: auto; margin-bottom: 5px; overflow: hidden; flex-shrink: 0; }
.settings-toggle { padding: 12px 15px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-weight: bold; color: var(--theme-text-color); transition: background-color 0.2s; }
.settings-toggle:hover { background-color: rgba(255,255,255,0.1); }
.settings-content { padding: 15px; border-top: 1px solid rgba(255,255,255,0.1); display: none; background-color: rgba(0,0,0,0.2); }

.voice-type-container { display: flex; gap: 8px; justify-content: space-between; }
.voice-type-btn { flex: 1; background-color: rgba(255,255,255,0.05); border: 2px solid transparent; border-radius: 8px; padding: 8px; color: var(--theme-text-color); cursor: pointer; font-size: 0.9em; transition: all 0.2s; display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 8px; }
.voice-type-btn.active { border-color: var(--theme-btn-active); background-color: rgba(255,255,255,0.15); color: #f1c40f; font-weight: bold;}

.empty-msg { text-align: center; padding: 15px; opacity: 0.7; font-size: 0.9em; font-style: italic; }

@media (max-width: 768px) {
    .text-main { font-size: 1.05em; }
    .text-sub { font-size: 0.75em; }
    .btn-speak { flex: 0 0 55px; font-size: 0.8em; }
}