/* ========================================
   Shorts Fullscreen Viewer Styles
   TikTok/Instagram Reels Style
   ======================================== */

/* 다른 탭 보호: Shorts CSS가 영향을 주지 않도록 */
#videoTab,
#infoTab,
#shareTab,
#bookmarkTab {
    position: relative !important;
}

/* Shorts Tab - Only when active */
#shortsTab.active {
    position: fixed !important;
    top: var(--header-height) !important;
    bottom: var(--tab-bar-height) !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    height: calc(100vh - var(--header-height) - var(--tab-bar-height)) !important;
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #000 !important;
    overflow: visible !important;
    z-index: 10 !important;
}

/* Shorts Viewer Container */
.shorts-viewer {
    width: 100% !important;
    height: 100% !important;
    background: #000 !important;
    overflow: visible !important;
    display: flex !important;
    flex-direction: column !important;
    position: relative !important;
}

/* View Toggle Buttons */
.shorts-view-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 100;
    display: flex;
    gap: 10px;
    background: rgba(0, 0, 0, 0.7);
    padding: 8px;
    border-radius: 8px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.view-toggle-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.7);
    width: 40px;
    height: 40px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.3s;
}

.view-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    transform: scale(1.05);
}

.view-toggle-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

/* Grid View */
.shorts-grid-view {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    padding: 80px 20px 20px 20px;
    box-sizing: border-box;
    background: #000;
}

.shorts-grid {
    display: grid;
    gap: 16px;
    align-content: start;
    box-sizing: border-box;
    max-width: 1600px;
    margin: 0 auto;
}

/* 반응형 그리드: 모바일 1개, 태블릿 2개, PC 3-5개 */
@media (max-width: 767px) {
    /* 모바일: 1개 */
    .shorts-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    /* 태블릿: 2개 */
    .shorts-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
}

@media (min-width: 1024px) and (max-width: 1399px) {
    /* 작은 PC: 3개 */
    .shorts-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
    }
}

@media (min-width: 1400px) and (max-width: 1799px) {
    /* 중간 PC: 4개 */
    .shorts-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
    }
}

@media (min-width: 1800px) {
    /* 큰 PC: 5개 */
    .shorts-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 24px;
    }
}
}

.shorts-grid-item {
    position: relative;
    width: 100% !important;
    /* iOS Safari 14 fallback - padding-top creates 16:9 ratio */
    padding-top: 177.78%; /* 16/9 * 100% for 9:16 ratio */
    height: 0;
    /* Modern browsers */
    aspect-ratio: 9 / 16;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
    background: #111;
    box-sizing: border-box !important;
    display: block !important; /* Ensure block display */
}

/* 반응형 최소 높이 */
@media (max-width: 767px) {
    /* 모바일: 큰 크기 */
    .shorts-grid-item {
        min-height: 500px;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    /* 태블릿: 중간 크기 */
    .shorts-grid-item {
        min-height: 400px;
    }
}

@media (min-width: 1024px) {
    /* PC: 큰 크기 */
    .shorts-grid-item {
        min-height: 450px;
    }
}

/* Reset padding-top for browsers that support aspect-ratio */
@supports (aspect-ratio: 9 / 16) {
    .shorts-grid-item {
        padding-top: 0;
        height: auto;
    }
}

.shorts-grid-item:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 24px rgba(255, 0, 0, 0.3);
    z-index: 1;
}

.shorts-grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.shorts-grid-item-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px;
    background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
    color: white;
}

.shorts-grid-item-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.shorts-grid-item-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    background: rgba(255, 0, 0, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    transition: all 0.3s;
}

.shorts-grid-item:hover .shorts-grid-item-play {
    transform: translate(-50%, -50%) scale(1.1);
    background: rgba(255, 0, 0, 1);
}

/* Shorts Container - Snap Scroll */
.shorts-container {
    width: 100% !important;
    height: 100% !important;
    overflow-y: scroll !important;
    scroll-snap-type: y mandatory !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
}

.shorts-container::-webkit-scrollbar {
    display: none; /* Chrome, Safari */
}

/* Individual Short Item */
.short-item {
    position: relative !important;
    width: 100% !important;
    height: calc(100vh - var(--header-height) - var(--tab-bar-height)) !important;
    min-height: calc(100vh - var(--header-height) - var(--tab-bar-height)) !important;
    scroll-snap-align: start !important;
    scroll-snap-stop: always !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: #000 !important;
    flex-shrink: 0 !important;
    cursor: pointer !important;
}

/* Shorts YouTube Player Container */
.short-player-wrapper {
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100vw !important;
    max-height: calc(100vh - var(--header-height) - var(--tab-bar-height)) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: #000 !important;
}

/* YouTube iframe - 9:16 aspect ratio */
.short-youtube-player {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border: none !important;
    z-index: 10 !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    background: #000 !important;
}

/* Mobile: Full screen short */
@media (max-width: 768px) {
    .short-player-wrapper {
        width: 100% !important;
        height: 100% !important;
    }
    
    .short-youtube-player {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
    }
}

/* Desktop: Centered short with larger size */
@media (min-width: 769px) {
    .short-player-wrapper {
        width: 100% !important;
        height: 100% !important;
        max-width: 700px !important; /* PC에서 큰 크기 */
        margin: 0 auto !important;
    }
    
    .short-youtube-player {
        position: relative !important;
        width: 100% !important;
        height: 100% !important;
        aspect-ratio: 9 / 16 !important;
        object-fit: contain !important;
    }
}

@media (min-width: 1400px) {
    /* 큰 PC: 더 큰 크기 */
    .short-player-wrapper {
        max-width: 900px !important;
    }
}

/* Shorts Preview (Before Play) */
.short-preview {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    z-index: 2 !important;
    background: #000 !important;
}

.short-preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background-color: #222;
}

.short-play-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    transition: background 0.3s;
}

.short-play-btn {
    background: rgba(255, 0, 0, 0.9);
    color: white;
    border: none;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.short-play-btn:hover {
    background: rgba(255, 0, 0, 1);
    transform: scale(1.1);
}

.short-play-btn i {
    font-size: 2rem;
    margin-left: 4px;
}

/* No Content Message */
.shorts-no-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
    padding: 40px;
}

.shorts-no-content i {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.5;
}

.shorts-no-content p {
    font-size: 1.1rem;
}

/* Scroll Indicators (Optional) */
.short-scroll-indicator {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 10;
    pointer-events: none;
}

.short-scroll-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    transition: all 0.3s;
}

.short-scroll-dot.active {
    background: rgba(255, 255, 255, 0.9);
    transform: scale(1.5);
}

/* Mobile & Tablet: Full width, no category panel */
@media (max-width: 1023px) {
    #shortsTab.active {
        right: 0 !important;
        padding-right: 0 !important;
    }
    
    .shorts-grid-view {
        padding: 20px !important;
        box-sizing: border-box !important;
    }
    
    /* View toggle button - move to top-left on mobile */
    .shorts-view-toggle {
        top: 10px;
        right: 10px;
    }
}

/* Desktop: Adjust for category panel */
@media (min-width: 1024px) {
    .shorts-viewer {
        margin-right: 0;
    }
    
    /* Shorts tab leaves space for category panel on desktop */
    #shortsTab.active {
        right: 0 !important; /* Full width */
        padding-right: 280px !important; /* Space for category panel */
    }
    
    /* Grid view adjusts for category panel */
    .shorts-grid-view {
        padding-right: 300px !important; /* 280px panel + 20px gap */
        padding-left: 20px !important;
        box-sizing: border-box !important;
    }
}

/* Loading State */
.short-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 1.2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: 5;
}

.short-loading i {
    font-size: 3rem;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
