/* 
 * Homepage Responsive Design
 * Optimized layout and responsive styles for the StemiTV homepage
 */

/* ===== CSS Variables ===== */
:root {
    /* Spacing System */
    --spacing-xs: 0.5rem;
    /* 8px */
    --spacing-sm: 1rem;
    /* 16px */
    --spacing-md: 1.5rem;
    /* 24px */
    --spacing-lg: 2rem;
    /* 32px */
    --spacing-xl: 3rem;
    /* 48px */
    --spacing-xxl: 4rem;
    /* 64px */

    /* Colors */
    --color-primary: #3f97c9;
    --color-bg-translucent: rgba(255, 255, 255, 0.7);
    --color-bg-dark: #2c343b;
    --color-text-dark: #000000;
    --color-text-light: #ffffff;
    --color-overlay: rgba(23, 129, 156, 0.85);

    /* Typography */
    --font-family-base: 'Open Sans', Helvetica, Arial, sans-serif;

    /* Video Container */
    --video-max-width: 1600px;
    --video-aspect-ratio: 16 / 9;

    /* Grid */
    --grid-gap: var(--spacing-md);
    --grid-columns-mobile: 1;
    --grid-columns-tablet: 2;
    --grid-columns-tablet-landscape: 3;
    --grid-columns-desktop: 3;

    /* Touch Target */
    --touch-target-min: 44px;
}

/* ===== Video Container Optimization ===== */
.tm-video-container {
    max-width: var(--video-max-width);
    margin: 0 auto var(--spacing-xl);
    padding: 0 var(--spacing-sm);
}

.tm-video-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: var(--video-aspect-ratio);
    background-color: var(--color-bg-dark);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#StemiVideo {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ===== Gallery Grid System ===== */
.tm-img-gallery-container-3 {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 var(--spacing-sm);
}

.tm-img-gallery.gallery-two {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--grid-gap);
    width: 100%;
}

/* Grid Items */
.grid-item,
.gallery-two .grid-item {
    width: 100%;
    height: auto;
    min-height: auto;
    aspect-ratio: 16 / 9;
    margin-bottom: 0;
    padding: 0;
    float: none;
}

/* Card-specific classes */
.grid-item.card-3col {
    position: relative;
}

.card-figure {
    position: relative;
    margin: 0;
    overflow: hidden;
    border-radius: 8px;
    height: 100%;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 有圖片時的樣式 */
.card-figure img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

/* 卡片標題 - 始終可見以支持點擊 */
.card-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: var(--spacing-md);
    background-color: rgba(23, 129, 156, 0.85);
    color: var(--color-text-light);
    text-align: right;
    transition: background-color 0.3s ease, opacity 0.3s ease;
    z-index: 2;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* 無圖片時的卡片背景 */
.card-figure.no-image {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* 當沒有圖片時，讓標題文字置中顯示，移除內部背景框 */
.card-figure.no-image .card-caption,
.card-caption.centered {
    position: static;
    background-color: transparent;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--spacing-xl);
}

/* 無圖片時的文字樣式 - 不加背景框 */
.card-figure.no-image .card-title,
.card-caption.centered .card-title {
    color: #ffffff;
    font-size: 1.4rem;
    font-weight: 700;
    text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5);
    /* 移除背景色和內邊距，讓文字直接顯示在漸層背景上 */
}

/* 懸停效果 */
.card-figure.no-image:hover .card-title,
.card-caption.centered:hover .card-title {
    transform: scale(1.05);
    text-shadow: 3px 3px 12px rgba(0, 0, 0, 0.7);
}

.card-caption .card-title {
    color: var(--color-text-light);
    text-decoration: none;
    font-weight: 600;
    font-size: 1.1rem;
    display: inline-block;
    transition: transform 0.2s ease;
}

.card-caption .card-title:hover {
    color: var(--color-text-light);
    text-decoration: none;
    transform: scale(1.05);
}

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

.grid-item figure img {
    width: 100%;
    height: 100%;
    object-fit: cover !important;
    /* Force fill the 16:9 container */
}

/* ===== Touch Optimization ===== */
.grid-item figure figcaption>a {
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Improve touch feedback on mobile */
@media (hover: none) and (pointer: coarse) {
    .grid-item figure:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }

    .grid-item figure img {
        opacity: 0.9;
    }
}

/* ===== Responsive Typography ===== */
.cd-hero-slider h2.tm-text-title {
    font-size: clamp(1.5rem, 2vw + 1rem, 2.5rem);
    margin-bottom: var(--spacing-md);
}

.cd-hero-slider .tm-text {
    font-size: clamp(0.9rem, 1vw + 0.5rem, 1.1rem);
    line-height: 1.6;
}

.grid-item figure figcaption {
    font-size: clamp(1rem, 1.2vw + 0.5rem, 1.25rem);
}

/* ===== Responsive Breakpoints ===== */

/* Mobile Portrait (< 576px) */
@media (max-width: 575.98px) {
    :root {
        --grid-gap: var(--spacing-sm);
    }

    .tm-img-gallery.gallery-two {
        grid-template-columns: repeat(1, 1fr) !important;
    }

    .tm-video-container {
        padding: 0 var(--spacing-xs);
    }

    .tm-img-gallery-container-3 {
        padding: 0 var(--spacing-xs);
    }

    .grid-item {
        min-height: auto !important;
    }

    .tm-textbox-padding {
        padding: var(--spacing-md) var(--spacing-sm);
    }
}

/* Mobile Landscape / Small Tablet (576px - 767.98px) */
@media (min-width: 576px) and (max-width: 767.98px) {
    .tm-img-gallery.gallery-two {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .grid-item {
        min-height: auto !important;
    }
}

/* Tablet Portrait (768px - 991.98px) */
@media (min-width: 768px) and (max-width: 991.98px) {
    .tm-img-gallery.gallery-two {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .grid-item {
        min-height: auto !important;
    }

    .tm-video-container {
        margin-bottom: var(--spacing-xxl);
    }
}

/* Tablet Landscape / Small Desktop (992px - 1199.98px) */
@media (min-width: 992px) and (max-width: 1199.98px) {
    .tm-img-gallery.gallery-two {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    .grid-item {
        min-height: auto !important;
    }
}

/* Desktop (>= 1200px) */
@media (min-width: 1200px) {
    .tm-img-gallery.gallery-two {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    .grid-item {
        min-height: auto !important;
    }

    .tm-img-gallery-container-3 {
        padding: 0 var(--spacing-md);
    }
}

/* Large Desktop (>= 1600px) */
@media (min-width: 1600px) {
    .tm-img-gallery-container-3 {
        max-width: 1600px;
    }

    .tm-img-gallery.gallery-two {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: var(--spacing-lg);
    }

    .tm-video-container {
        max-width: 1600px;
    }
}

/* Ultrawide (>= 2000px) */
@media (min-width: 2000px) {
    .tm-img-gallery-container-3 {
        max-width: 1800px;
    }

    .tm-video-container {
        max-width: 1800px;
    }
}

/* ===== Improved Spacing ===== */
.tm-bg-white-translucent {
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

.tm-white-box-margin-b {
    margin-bottom: var(--spacing-lg);
}

/* ===== Accessibility Improvements ===== */
/* Ensure sufficient contrast */
.grid-item figure figcaption {
    background-color: var(--color-overlay);
    color: var(--color-text-light);
}

/* Focus states for keyboard navigation */
.grid-item figure figcaption>a:focus {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

/* ===== Print Styles ===== */
@media print {
    .tm-video-container {
        display: none;
    }

    .grid-item {
        page-break-inside: avoid;
    }
}

/* ===== High DPI / Retina Displays ===== */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
    .grid-item figure img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ===== 首頁深色模式 ===== */
[data-theme="dark"] {
    --color-background: #0f172a;
    --color-card-bg: #1e293b;
    --color-text: #f1f5f9;
    --color-text-secondary: #94a3b8;
    --color-overlay: rgba(15, 23, 42, 0.9);
}

[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"] .grid-item {
    background-color: #1e293b !important;
}

[data-theme="dark"] .grid-item figure {
    background-color: #1e293b !important;
}

[data-theme="dark"] .grid-item figure figcaption {
    background-color: rgba(15, 23, 42, 0.9) !important;
    color: #f1f5f9 !important;
}

[data-theme="dark"] .grid-item figure figcaption>a {
    color: #f1f5f9 !important;
}

[data-theme="dark"] .grid-item figure figcaption>a:hover {
    color: #3b82f6 !important;
}

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

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