/* Design System Variables */
:root {
    --bg-main: #0b0f17;
    --bg-surface: rgba(22, 28, 45, 0.6);
    --bg-surface-hover: rgba(30, 41, 59, 0.8);
    --bg-header: rgba(15, 23, 42, 0.85);
    
    --accent: #f97316; /* Baseball Orange */
    --accent-rgb: 249, 115, 22;
    --accent-secondary: #ef4444; /* Stitch Red */
    --accent-secondary-rgb: 239, 68, 68;
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    --border-color: rgba(255, 255, 255, 0.08);
    --border-active: rgba(249, 115, 22, 0.5);
    
    --glow: 0 0 20px rgba(249, 115, 22, 0.15);
    --glow-active: 0 0 30px rgba(249, 115, 22, 0.3);
    
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    --header-height: 70px;
}

/* Global Reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    line-height: 1.5;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.3);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Header */
.app-header {
    height: var(--header-height);
    background: var(--bg-header);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 1.8rem;
    animation: spin 12s linear infinite;
    display: inline-block;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.logo-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.logo-title .highlight {
    background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-search {
    position: relative;
    width: 350px;
    max-width: 100%;
}

.header-search input {
    width: 100%;
    padding: 0.6rem 1rem 0.6rem 2.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 30px;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition);
}

.header-search input:focus {
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 15px rgba(249, 115, 22, 0.1);
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.header-stats {
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

.stats-count {
    color: var(--accent);
    font-weight: 700;
}

/* Error Container */
.error-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - var(--header-height) - 100px);
    width: 100%;
    padding: 2rem;
}

.error-box {
    background: var(--bg-surface);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 16px;
    padding: 3rem;
    text-align: center;
    max-width: 600px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(16px);
}

.error-icon {
    font-size: 3.5rem;
    display: block;
    margin-bottom: 1.5rem;
}

.error-box h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.8rem;
    margin-bottom: 1rem;
    color: #ef4444;
}

.error-box p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 1rem;
}

.error-tip {
    background: rgba(255, 255, 255, 0.03);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    text-align: left;
    font-size: 0.85rem;
    line-height: 1.6;
}

.error-tip code {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
}

/* Main Layout Grid */
.app-main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1.5rem;
    padding: 1.5rem;
    max-width: 1800px;
    width: 100%;
    margin: 0 auto;
}

/* Video Player Section */
.player-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.video-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    box-shadow: var(--glow);
    transition: var(--transition);
}

.video-container:focus-within,
.video-container:hover {
    border-color: var(--border-active);
    box-shadow: var(--glow-active);
}

#mainVideoPlayer {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Custom OSD (On-Screen Display) Overlay */
.video-osd {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, 0) 25%, rgba(0, 0, 0, 0) 70%, rgba(0, 0, 0, 0.6) 100%);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
}

/* Show OSD when hovering, focusing, or active class is set */
.video-container:hover .video-osd,
.video-osd.active {
    opacity: 1;
    pointer-events: auto;
}

/* Center Play/Pause Overlay Button */
.osd-center-controls {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.osd-center-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(249, 115, 22, 0.95);
    border: none;
    color: white;
    font-size: 1.8rem;
    display: flex;
    justify-content: center;
    align-items: center;
    padding-left: 4px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5), 0 0 30px rgba(249, 115, 22, 0.3);
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.osd-center-btn:hover {
    transform: scale(1.1);
    background: #ffa15c;
    box-shadow: 0 4px 30px rgba(249, 115, 22, 0.6);
}

.osd-center-btn:active {
    transform: scale(0.95);
}

/* Bottom Control Bar */
.osd-bottom-bar {
    background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.4) 60%, rgba(0, 0, 0, 0) 100%);
    padding: 1.5rem 1rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

/* Custom Progress Bar (Scrubber) */
.osd-progress-container {
    cursor: pointer;
    padding: 6px 0;
}

.osd-progress-bg {
    height: 5px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    position: relative;
    transition: height 0.15s ease;
    overflow: hidden;
}

.osd-progress-container:hover .osd-progress-bg {
    height: 7px;
}

.osd-progress-play {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: linear-gradient(to right, var(--accent), var(--accent-secondary));
    width: 0%;
    border-radius: 3px;
}

/* Controls Alignment */
.osd-controls-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.osd-left-controls,
.osd-right-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* General OSD Buttons */
.osd-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition);
    opacity: 0.85;
}

.osd-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--accent);
    transform: scale(1.08);
    opacity: 1;
}

.osd-btn:active {
    transform: scale(0.92);
}

/* Time Display */
.osd-time {
    font-size: 0.85rem;
    color: #e5e7eb;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    margin-left: 0.5rem;
}

/* Volume Slider Overlay */
.osd-volume-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.osd-volume-slider {
    width: 0px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
    transition: width 0.2s ease, background 0.2s ease;
    cursor: pointer;
    opacity: 0;
}

/* Expand Volume Slider on Container Hover */
.osd-volume-container:hover .osd-volume-slider,
.osd-volume-slider:focus {
    width: 80px;
    opacity: 1;
}

.osd-volume-slider::-webkit-slider-runnable-track {
    background: transparent;
}

.osd-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
    margin-top: -4px;
    transition: transform 0.1s ease;
}

.osd-volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* Player Meta Information */
.player-info {
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
}

.player-video-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
    word-break: break-all;
}

.player-video-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.meta-item {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* Autoplay Slider Switch */
.autoplay-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    margin-left: auto;
}

.autoplay-toggle input {
    display: none;
}

.toggle-slider {
    width: 44px;
    height: 22px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    position: relative;
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: var(--transition);
}

.autoplay-toggle input:checked + .toggle-slider {
    background-color: rgba(249, 115, 22, 0.2);
    border-color: var(--accent);
}

.autoplay-toggle input:checked + .toggle-slider::before {
    background-color: var(--accent);
    transform: translateX(22px);
}

.toggle-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    user-select: none;
}

.autoplay-toggle:hover .toggle-label {
    color: var(--text-primary);
}

/* Navigation Buttons */
.player-controls-extra {
    display: flex;
    gap: 1rem;
}

.control-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
    display: flex;
    justify-content: center;
    align-items: center;
}

.control-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--text-secondary);
}

.control-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Playlist Section */
.playlist-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    height: calc(100vh - var(--header-height) - 3rem);
}

.playlist-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.playlist-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
    padding-right: 4px;
}

/* Video Card (Playlist Item) */
.video-card {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: 0.75rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.6rem;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.video-card:hover {
    background: var(--bg-surface-hover);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.video-card.active {
    background: rgba(249, 115, 22, 0.08);
    border-color: var(--border-active);
    box-shadow: 0 0 15px rgba(249, 115, 22, 0.1);
}

/* Card Thumbnail Box */
.card-thumbnail-wrapper {
    position: relative;
    aspect-ratio: 16/9;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.thumbnail-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.65;
    transition: var(--transition);
}

.video-card:hover .thumbnail-video,
.video-card.active .thumbnail-video {
    opacity: 0.9;
}

/* Thumbnail Play Overlay */
.card-play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.9rem;
    opacity: 0;
    transition: var(--transition);
    padding-left: 2px;
}

.video-card:hover .card-play-icon {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.video-card.active .card-play-icon {
    opacity: 1;
    background: var(--accent);
    border-color: var(--accent);
}

/* Card Details */
.card-details {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-width: 0;
}

.card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.35;
    word-break: break-all;
}

.video-card.active .card-title {
    color: var(--accent);
}

.card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Status Indicators */
.status-badge {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
}

.status-badge.watched {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.status-badge.playing {
    background: rgba(249, 115, 22, 0.15);
    color: var(--accent);
    border: 1px solid rgba(249, 115, 22, 0.2);
}

/* Watch Progress Bar on Card */
.card-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: var(--accent);
    width: 0;
    transition: width 0.1s ease;
}

.card-progress-bar.completed {
    background: #22c55e;
}

/* Dialog Overlay */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 200;
}

.dialog-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.dialog-box {
    background: #111827;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.8);
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.dialog-overlay.active .dialog-box {
    transform: translateY(0);
}

.dialog-box h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
}

.dialog-box p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.dialog-buttons {
    display: flex;
    gap: 1rem;
}

.dialog-btn {
    flex: 1;
    padding: 0.65rem 1rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: var(--transition);
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: #ffa15c;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ==========================================
   Responsive Layout (Media Queries)
   ========================================== */

/* 1. 세로 레이아웃 (Portrait) - Mobile & Tablet
   화면 가로 너비가 1024px 미만일 때 작동
   ========================================== */
@media (max-width: 1024px) {
    .app-main {
        grid-template-columns: 1fr; /* 1열로 변경 */
        padding: 0.75rem;
        gap: 1rem;
    }
    
    .app-header {
        padding: 0 1rem;
    }
    
    .header-search {
        width: 180px; /* 검색창 너비 축소 */
    }
    
    /* 모바일 세로 고정(Sticky) 비디오 플레이어 */
    .player-section {
        position: sticky;
        top: var(--header-height);
        background-color: var(--bg-main);
        z-index: 90;
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
        border-bottom: 1px solid var(--border-color);
        gap: 0.5rem;
    }
    
    .video-container {
        border-radius: 8px; /* 모바일에서는 둥근 모서리 반경 축소 */
    }
    
    .player-info {
        padding: 1rem;
        border-radius: 10px;
    }
    
    .player-video-title {
        font-size: 1.15rem;
    }
    
    .player-video-meta {
        padding-bottom: 0.75rem;
        margin-bottom: 0.75rem;
        gap: 0.75rem;
    }
    
    .autoplay-toggle {
        margin-left: 0;
        width: 100%;
        margin-top: 0.5rem;
        border-top: 1px solid rgba(255, 255, 255, 0.05);
        padding-top: 0.5rem;
    }
    
    .control-btn {
        padding: 0.6rem 0.8rem;
        font-size: 0.8rem;
    }
    
    /* 플레이리스트 */
    .playlist-section {
        height: auto;
        margin-top: 0.5rem;
    }
    
    .playlist-container {
        overflow-y: visible; /* 메인 스크롤 활용 */
    }
    
    .video-card {
        grid-template-columns: 110px 1fr;
        padding: 0.5rem;
    }
    
    .card-title {
        font-size: 0.85rem;
    }
}

/* 2. 초소형 화면 (Mobile portrait)
   ========================================== */
@media (max-width: 576px) {
    .app-header {
        flex-wrap: wrap;
        height: auto;
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }
    
    .header-logo {
        width: 100%;
        justify-content: center;
    }
    
    .header-search {
        flex: 1;
        width: 100%;
    }
    
    .header-stats {
        display: none; /* 공간 절약을 위해 제거 */
    }
    
    /* 헤더 높이가 커졌으므로 플레이어 sticky 위치 조정 */
    .player-section {
        top: 96px;
    }
}
