/* ========================================
   StemiTV UI Enhancements
   專門處理首頁的視覺增強效果
   ======================================== */

/* ===== 內容字體加大 ===== */
body {
    font-size: 16px !important;
}

.body-content,
.container,
.content {
    font-size: 16px !important;
}

/* 段落文字加大 */
p,
.body-content p,
.container p {
    font-size: 16px !important;
    line-height: 1.8 !important;
}

/* 卡片標題加大 */
.card-title,
a.card-title,
.grid-item figure figcaption a {
    font-size: 20px !important;
    font-weight: 600 !important;
}

/* 標題加大 */
h1 {
    font-size: 2.5rem !important;
}

h2 {
    font-size: 2rem !important;
}

h3 {
    font-size: 1.75rem !important;
}

h4 {
    font-size: 1.5rem !important;
}

h5 {
    font-size: 1.25rem !important;
}

h6 {
    font-size: 1.1rem !important;
}

/* ===== 選單響應式修正 ===== */
/* 防止選單溢出螢幕 */
#menu-wrapper {
    overflow-x: auto !important;
    max-width: 100vw !important;
}

#menu,
.navbar,
.navbar-nav {
    flex-wrap: wrap !important;
}

.navbar-nav {
    overflow-x: auto !important;
    white-space: nowrap !important;
    -webkit-overflow-scrolling: touch !important;
}

/* 大螢幕優化 - 內容居中 */
@media (min-width: 1600px) {
    #menu-wrapper {
        width: 100%;
        overflow-x: visible !important;
    }

    #menu,
    #menu.container-fluid {
        max-width: 1600px !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }
}

@media (min-width: 2000px) {

    #menu,
    #menu.container-fluid {
        max-width: 1800px !important;
    }
}

/* 手機版選單調整 */
@media (max-width: 768px) {
    .navbar-nav {
        flex-wrap: wrap !important;
        white-space: normal !important;
        justify-content: center !important;
    }

    .nav-item,
    .navbar-nav .nav-link {
        flex: 0 0 auto !important;
    }
}

/* ===== 搜尋框與語言選擇器樣式 ===== */
#menu-wrapper input[name="searchTerm"] {
    width: 180px !important;
    height: 38px !important;
    padding: 8px 12px !important;
    font-size: 14px !important;
    border-radius: 4px 0 0 4px !important;
}

#menu-wrapper .input-group-append .btn {
    height: 38px !important;
    padding: 8px 15px !important;
}

#menu-wrapper #languageSelector {
    width: 80px !important;
    height: 38px !important;
    padding: 6px 8px !important;
    font-size: 14px !important;
    border-radius: 4px !important;
    margin-left: 10px !important;
}

/* ===== Logo 響應式修正 ===== */
/* Logo 容器 */
#menu-wrapper .col-xs-6.col-md-4,
#menu-wrapper .container .row>div:first-child {
    display: flex !important;
    align-items: center !important;
}

#menu-wrapper .container .row .col-xs-6.col-md-4 img,
#menu-wrapper img[src*="TV2.0"] {
    max-width: 200px !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
}

@media (max-width: 992px) {

    #menu-wrapper .container .row .col-xs-6.col-md-4 img,
    #menu-wrapper img[src*="TV2.0"] {
        max-width: 180px !important;
    }
}

@media (max-width: 768px) {

    /* Logo 縮小 */
    #menu-wrapper .container .row .col-xs-6.col-md-4 img,
    #menu-wrapper img[src*="TV2.0"] {
        max-width: 150px !important;
    }

    /* Header 佈局調整 - 保持橫向但允許換行 */
    #menu-wrapper .container .row {
        flex-wrap: wrap !important;
        justify-content: center !important;
        align-items: center !important;
    }

    #menu-wrapper .col-xs-6,
    #menu-wrapper .col-md-4 {
        flex: 0 0 auto !important;
        width: auto !important;
        max-width: 50% !important;
        text-align: center !important;
        margin-bottom: 10px !important;
    }

    #menu-wrapper .col-md-8 {
        flex: 1 1 auto !important;
        width: auto !important;
        max-width: 100% !important;
        justify-content: center !important;
    }

    /* 搜尋框調整 - 置中 */
    #menu-wrapper .navbar-form,
    #menu-wrapper .form-group {
        justify-content: center !important;
        flex-wrap: wrap !important;
        width: 100% !important;
    }

    #menu-wrapper .d-flex.justify-content-end {
        justify-content: center !important;
    }

    #menu-wrapper .input-group {
        max-width: 100% !important;
        justify-content: center !important;
    }

    #menu-wrapper input[name="searchTerm"] {
        width: 140px !important;
        max-width: 140px !important;
    }

    #menu-wrapper #languageSelector {
        margin-left: 5px !important;
        width: 70px !important;
    }
}

@media (max-width: 480px) {

    #menu-wrapper .container .row .col-xs-6.col-md-4 img,
    #menu-wrapper img[src*="TV2.0"] {
        max-width: 100px !important;
    }

    #menu-wrapper .col-xs-6,
    #menu-wrapper .col-md-4 {
        max-width: 40% !important;
    }

    /* 小螢幕搜尋區域置中 */
    #menu-wrapper .col-md-8 {
        width: 100% !important;
        justify-content: center !important;
        text-align: center !important;
    }

    #menu-wrapper input[name="searchTerm"] {
        width: 100px !important;
        max-width: 100px !important;
        font-size: 12px !important;
        height: 32px !important;
    }

    #menu-wrapper .input-group-append .btn {
        height: 32px !important;
        padding: 6px 10px !important;
    }

    #menu-wrapper #languageSelector {
        width: 60px !important;
        max-width: 60px !important;
        font-size: 11px !important;
        height: 32px !important;
        margin-left: 5px !important;
    }
}

/* ===== JWPlayer 響應式修正 ===== */
#container,
#StemiVideo {
    width: 100% !important;
    max-width: 100% !important;
}

.tm-white-box-margin-b,
.tm-textbox,
.tm-textbox-padding {
    max-width: 100% !important;
    overflow: hidden !important;
}

@media (max-width: 768px) {
    #container {
        min-height: 250px !important;
    }

    .tm-textbox-padding {
        padding: 10px !important;
    }
}

@media (max-width: 480px) {
    #container {
        min-height: 200px !important;
    }
}

/* ===== 背景圖響應式修正 ===== */
.cd-hero,
.cd-hero-slider,
.cd-hero-slider li {
    max-width: 100vw !important;
    overflow-x: hidden !important;
}

.cd-hero-slider li {
    background-size: cover !important;
    background-position: center center !important;
}

/* ===== 容器響應式修正 ===== */
.container,
.body-content {
    overflow-x: hidden !important;
    padding-left: 15px !important;
    padding-right: 15px !important;
}

.container-fluid {
    overflow-x: hidden !important;
}

@media (max-width: 768px) {

    .container,
    .body-content {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }
}

/* 大螢幕容器居中 */
@media (min-width: 1600px) {
    .container.body-content {
        max-width: 1600px !important;
        margin-left: auto !important;
        margin-right: auto !important;
        overflow: visible !important;
    }

    footer .container {
        max-width: 1600px !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }

    /* 確保內容可見 */
    .cd-hero,
    .cd-hero-slider,
    .home-wrapper {
        overflow: visible !important;
        height: auto !important;
        min-height: auto;
    }

    .cd-hero-slider li.selected {
        overflow: visible !important;
    }
}

@media (min-width: 2000px) {
    .container.body-content {
        max-width: 1800px !important;
    }

    footer .container {
        max-width: 1800px !important;
    }
}

/* ===== 防止全頁溢出 ===== */
html,
body {
    max-width: 100vw !important;
    overflow-x: hidden !important;
}


/* ===== 視頻播放器佈局修正 ===== */
/* 移除 video 容器的白色背景和內邊距 */
.tm-white-box-margin-b,
.tm-textbox {
    background-color: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: none !important;
}

/* 影片容器 - 與卡片網格同寬 */
.tm-textbox,
.tm-textbox-padding,
.tm-bg-white-translucent {
    max-width: 1400px !important;
    /* 與卡片網格容器相同 */
    margin: 0 auto 30px auto !important;
    /* 置中並添加底部間距 */
    padding: 30px 16px !important;
    /* 上方留空間 */
}

/* video 容器 */
#container {
    width: 100%;
    max-width: 100%;
    aspect-ratio: 16 / 9;
    /* 保持 16:9 比例 */
    position: relative;
    padding: 0 !important;
    margin: 0 auto !important;
    background-color: #000 !important;
    border-radius: 8px;
    overflow: hidden;
}

/* jwplayer 本身 - 保持 16:9 比例 */
#StemiVideo.jwplayer,
.jwplayer {
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
    aspect-ratio: 16 / 9 !important;
    background-color: #000 !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* 卡片區域的間距 */
.tm-img-gallery-container {
    margin-top: 50px !important;
}

/* ===== 視頻載入動畫 ===== */
.video-loading {
    min-height: 400px;
    background: linear-gradient(135deg, #2c343b 0%, #3d4952 100%);
    border-radius: 8px;
    position: relative;
}

.video-loading .spinner-border {
    width: 3rem;
    height: 3rem;
    border-width: 0.3rem;
}

/* 當視頻載入完成後隱藏載入動畫 */
#StemiVideo:not(.video-loading) .spinner-border {
    display: none;
}

/* ===== 圖片卡片懸停效果優化 ===== */
.grid-item {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform, box-shadow;
    position: relative;
    z-index: 1;
}

.grid-item:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3),
        0 6px 12px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

/* 圖片卡片內的圖片效果 */
.grid-item figure img {
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.grid-item:hover figure img {
    opacity: 0.95;
    transform: scale(1.05);
}

/* ===== 文字顯示邏輯：區分有圖片和無圖片卡片 ===== */

/* 有圖片的卡片：預設隱藏文字，hover 時顯示 */
.grid-item figure figcaption,
.grid-item figure.effect-ruby figcaption,
.grid-item figure.card-figure figcaption {
    position: absolute !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: auto !important;
    padding: 1rem !important;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8)) !important;
    opacity: 0 !important;
    /* 強制隱藏 */
    visibility: hidden !important;
    /* 強制隱藏 */
    transition: all 0.3s ease;
    pointer-events: auto !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-end !important;
    align-items: center !important;
}

/* figcaption 內的連結樣式 - 覆蓋整個卡片區域 */
.grid-item figure figcaption>a,
.grid-item figure figcaption a.card-title {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
    align-items: flex-end !important;
    justify-content: center !important;
    padding: 1rem !important;
    text-decoration: none !important;
    color: white !important;
    z-index: 10 !important;
}

/* 讓整個 figure 也可以點擊 */
.grid-item figure {
    cursor: pointer;
}

/* 滑鼠懸停時顯示文字 */
.grid-item:hover figure figcaption,
.grid-item:hover figure.effect-ruby figcaption,
.grid-item:hover figure.card-figure figcaption {
    opacity: 1 !important;
    visibility: visible !important;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.9)) !important;
}

/* 無圖片卡片：強制顯示文字（靜態和 hover 狀態） */
.grid-item figure.no-image figcaption {
    opacity: 1 !important;
    visibility: visible !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: linear-gradient(135deg, #2c343b 0%, #3d4952 100%) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    margin: 0 !important;
    padding: 2rem !important;
    text-align: center !important;
}

/* centered class 也要顯示 */
.grid-item figure figcaption.centered {
    opacity: 1 !important;
    visibility: visible !important;
    display: flex !important;
    background-color: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

/* .card-caption 特殊處理：預設顯示，讓連結可以點擊 */
.card-caption {
    opacity: 1 !important;
    visibility: visible !important;
    display: block !important;
    pointer-events: auto !important;
}

/* 連結文字效果 */
.grid-item figure figcaption a {
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease;
    display: inline-block;
    width: 100%;
    /* Ensure it takes full width for alignment */
}

.grid-item:hover figure figcaption a {
    transform: scale(1.05);
}

/* ===== 搜尋框增強 ===== */
.navbar-form .input-group {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border-radius: 0.25rem;
    overflow: hidden;
}

.navbar-form .form-control {
    border-right: none;
    transition: all 0.3s ease;
}

.navbar-form .form-control:focus {
    box-shadow: 0 0 0 0.2rem rgba(63, 151, 201, 0.25);
    border-color: #3f97c9;
}

.navbar-form .btn-primary {
    border-left: none;
    background-color: #3f97c9;
    border-color: #3f97c9;
    transition: all 0.3s ease;
}

.navbar-form .btn-primary:hover {
    background-color: #2d7ca8;
    border-color: #2d7ca8;
    transform: scale(1.05);
}

/* ===== 語言選擇器美化 ===== */
#languageSelector {
    transition: all 0.3s ease;
    border-color: #ced4da;
    cursor: pointer;
}

#languageSelector:hover {
    border-color: #3f97c9;
    box-shadow: 0 2px 8px rgba(63, 151, 201, 0.15);
}

#languageSelector:focus {
    border-color: #3f97c9;
    box-shadow: 0 0 0 0.2rem rgba(63, 151, 201, 0.25);
}

/* ===== 頁腳增強 ===== */
footer.bg-dark {
    background: linear-gradient(135deg, #1a1d23 0%, #2c343b 100%) !important;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
}

footer a {
    transition: all 0.3s ease;
    display: inline-block;
}

footer a:hover {
    transform: translateY(-3px) scale(1.1);
    filter: brightness(1.3);
}

/* ===== 視頻容器美化 ===== */
.tm-bg-white-translucent {
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
}

.tm-video-wrapper {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

/* ===== 響應式調整 ===== */
@media (max-width: 767.98px) {
    .grid-item:hover {
        transform: translateY(-4px);
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25),
            0 3px 8px rgba(0, 0, 0, 0.15);
    }

    .navbar-form .input-group {
        max-width: 100%;
    }

    .navbar-form .form-control {
        font-size: 14px;
    }

    footer a {
        font-size: 1.3rem !important;
    }
}

@media (max-width: 575.98px) {
    .grid-item:hover {
        transform: none;
        box-shadow: none;
    }

    /* 在小螢幕上簡化效果，提升性能 */
    .grid-item figure img {
        transform: none !important;
    }

    .video-loading {
        min-height: 250px;
    }
}

/* ===== 平滑滾動 ===== */
html {
    scroll-behavior: smooth;
}

/* ===== 載入狀態優化 ===== */
.loaded {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0.8;
    }

    to {
        opacity: 1;
    }
}

/* ===== 首頁深色模式樣式 ===== */
/* 確保整個頁面背景變深色 */
[data-theme="dark"] html,
[data-theme="dark"] body {
    background-color: #0f172a !important;
    color: #f1f5f9 !important;
}

[data-theme="dark"] .body-content {
    background-color: #0f172a !important;
}

[data-theme="dark"] .cd-hero,
[data-theme="dark"] .cd-hero-slider,
[data-theme="dark"] .cd-hero-slider li,
[data-theme="dark"] .cd-hero-slider li.selected {
    background-color: #0f172a !important;
    background-image: none !important;
}

[data-theme="dark"] .tm-bg-white-translucent {
    background-color: rgba(30, 41, 59, 0.95) !important;
    color: #f1f5f9 !important;
}

[data-theme="dark"] .tm-textbox,
[data-theme="dark"] .tm-white-box-margin-b,
[data-theme="dark"] .tm-textbox-padding {
    background-color: #1e293b !important;
    color: #f1f5f9 !important;
}

[data-theme="dark"] .container-fluid,
[data-theme="dark"] .container-fluid.js-tm-page-content {
    background-color: transparent !important;
}

[data-theme="dark"] .tm-flex {
    background-color: transparent !important;
}

[data-theme="dark"] .tm-img-gallery-container,
[data-theme="dark"] .tm-img-gallery {
    background-color: transparent !important;
}

/* 首頁卡片深色模式 */
[data-theme="dark"] .grid-item {
    background-color: #1e293b !important;
}

[data-theme="dark"] .card-figure,
[data-theme="dark"] .effect-ruby,
[data-theme="dark"] figure.effect-ruby {
    background-color: #1e293b !important;
}

[data-theme="dark"] .card-caption,
[data-theme="dark"] figcaption.card-caption {
    background-color: rgba(15, 23, 42, 0.95) !important;
    color: #f1f5f9 !important;
}

[data-theme="dark"] .card-title,
[data-theme="dark"] a.card-title {
    color: #f1f5f9 !important;
}

[data-theme="dark"] .card-title:hover,
[data-theme="dark"] a.card-title:hover {
    color: #3b82f6 !important;
}

[data-theme="dark"] figcaption {
    color: #f1f5f9 !important;
}

/* 深色模式下的 figcaption 漸層背景 */
[data-theme="dark"] .grid-item figure figcaption {
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.9)) !important;
}

/* 首頁影片區域 */
[data-theme="dark"] #container,
[data-theme="dark"] #StemiVideo {
    background-color: #1e293b !important;
    color: #f1f5f9 !important;
}

/* 首頁標題文字 */
[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3,
[data-theme="dark"] h4,
[data-theme="dark"] h5,
[data-theme="dark"] h6 {
    color: #f1f5f9 !important;
}

[data-theme="dark"] p {
    color: #94a3b8 !important;
}

/* 首頁無圖片卡片深色模式 */
[data-theme="dark"] .card-figure.no-image {
    background: linear-gradient(135deg, #1e40af 0%, #7c3aed 100%) !important;
}

[data-theme="dark"] .card-figure.no-image .card-caption {
    background-color: transparent !important;
}


/* ===== 輔助功能增強 ===== */
/* 確保焦點可見性 */
a:focus,
button:focus,
input:focus,
select:focus {
    outline: 3px solid #3f97c9;
    outline-offset: 2px;
}

/* 改善觸控目標大小 */
@media (hover: none) and (pointer: coarse) {
    .grid-item figure figcaption a {
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 12px;
    }
}

/* 只對無圖片卡片強制顯示文字內容 */
.grid-item figure.no-image figcaption>a {
    opacity: 1 !important;
    visibility: visible !important;
    text-indent: 0 !important;
    white-space: normal !important;
    color: #ffffff !important;
    font-size: 1.8em !important;
    font-weight: 700 !important;
    display: block !important;
    padding: 1rem !important;
    position: relative !important;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4) !important;
    line-height: 1.4 !important;
}

.grid-item figure figcaption.centered>a {
    opacity: 1 !important;
    text-indent: 0 !important;
    white-space: normal !important;
    color: #ffffff !important;
    font-size: 1.2em !important;
    font-weight: 600 !important;
    display: block !important;
    padding: 1rem !important;
    position: relative !important;
}

/* Fallback for missing images - Text Only Card */
body .card-text-fallback {
    width: 100%;
    min-height: 225px;
    /* Aspect ratio 16:9 approx */
    background: linear-gradient(135deg, #2c343b 0%, #3d4952 100%);
    color: #ffffff;
    display: flex;
    justify-content: flex-end !important;
    /* Force align flex content to the right */
    align-items: center;
    text-align: right !important;
    /* Force align text to the right */
    padding: 1.5rem;
    font-size: 1.4rem;
    font-weight: 600;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.card-text-fallback::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('/Image/TV2.0.png') center/40% no-repeat;
    opacity: 0.1;
    z-index: -1;
    filter: grayscale(100%);
}

.grid-item:hover .card-text-fallback {
    background: linear-gradient(135deg, #3f97c9 0%, #2d7ca8 100%);
}

/* Force static images to be visible and correct */
.grid-item figure img[src*="Request.jpg"],
.grid-item figure img[src*="QandA.jpg"],
.grid-item figure img[src*="linefriend.jpg"] {
    opacity: 1 !important;
    visibility: visible !important;
    display: block !important;
    transform: none !important;
    max-width: 100% !important;
    height: auto !important;
}

/* Grid Item 樣式 - 配合 grid 佈局 */
body .tm-img-gallery.gallery-two .grid-item {
    /* 移除 width: 100% !important; 以允許 grid 自動分配寬度 */
    max-width: none !important;
    height: auto;
    min-height: auto !important;
    aspect-ratio: 16 / 9 !important;
    margin-bottom: 0;
    padding: 0;
    float: none;
}

.grid-item figure {
    height: 100%;
    margin: 0;
}

.grid-item figure img {
    width: 100%;
    height: 100%;
    object-fit: cover !important;
}

/* 強化卡片連結可點擊性 */
.card-title {
    position: relative;
    z-index: 10;
    pointer-events: auto !important;
    cursor: pointer;
}

.card-caption {
    pointer-events: auto !important;
}

.card-figure {
    pointer-events: auto !important;
}
