/* ========================================
   Design System Tokens
   ======================================== */
:root {
    /* Colors - Backgrounds */
    --color-bg-primary: #0d0d0d;
    --color-bg-surface: #141414;
    --color-bg-elevated: #1e1e1e;
    --color-bg-overlay: #2a2a2a;
    --color-bg-input: #2a2a2a;
    --color-bg-input-hover: #333;

    /* Colors - Accent */
    --color-accent: #ff9000;
    --color-accent-hover: #ffab33;
    --color-accent-subtle: rgba(255, 144, 0, 0.12);

    /* Colors - Text */
    --color-text-primary: #f0f0f0;
    --color-text-secondary: #a0a0a0;
    --color-text-tertiary: #666;
    --color-text-muted: #999;

    /* Colors - Borders */
    --color-border: rgba(255, 255, 255, 0.08);
    --color-border-hover: rgba(255, 255, 255, 0.15);
    --color-border-input: #3a3a3a;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(255, 144, 0, 0.15);

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;

    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;

    /* Z-index Scale */
    --z-header: 100;
    --z-nav: 90;
    --z-overlay: 200;
    --z-menu: 210;
    --z-modal: 300;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background-color: var(--color-bg-primary);
    color: var(--color-text-primary);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.header {
    background-color: var(--color-bg-elevated);
    padding: 15px 0;
    border-bottom: 1px solid var(--color-border);
}

.header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.logo-text {
    font-size: 28px;
    font-weight: bold;
    color: var(--color-text-primary);
}

.logo-highlight {
    color: var(--color-accent);
}

.search-bar {
    flex: 1;
    max-width: 600px;
    display: flex;
    gap: 10px;
}

.search-bar input {
    flex: 1;
    padding: 10px 15px;
    background-color: var(--color-bg-input);
    border: 1px solid var(--color-border-input);
    border-radius: var(--radius-sm);
    color: var(--color-text-primary);
    font-size: 14px;
}

.search-bar input:focus {
    outline: none;
    border-color: var(--color-accent);
}

.search-btn {
    padding: 10px 25px;
    background-color: var(--color-accent);
    border: none;
    border-radius: var(--radius-sm);
    color: #000;
    font-weight: bold;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.search-btn:hover {
    background-color: var(--color-accent-hover);
}

.upload-btn {
    padding: 10px 20px;
    background-color: var(--color-bg-overlay);
    border: 1px solid var(--color-border-input);
    border-radius: var(--radius-sm);
    color: var(--color-text-primary);
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.upload-btn:hover {
    background-color: var(--color-border-input);
}

/* Navigation */
.nav {
    background-color: var(--color-bg-elevated);
    padding: 12px 0;
    border-bottom: 1px solid var(--color-border);
}

.nav .container {
    display: flex;
    gap: 25px;
}

.nav-link {
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: 14px;
    transition: color var(--transition-fast);
}

.nav-link:hover,
.nav-link.active {
    color: var(--color-accent);
}

/* Main Content */
.main {
    padding: 30px 0;
}

.section-title {
    font-size: 24px;
    margin-bottom: 20px;
    color: var(--color-text-primary);
}

/* Videos Grid */
.videos-section {
    margin-bottom: 50px;
}

.videos-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    width: 100%;
    max-width: 100%;
}

/* Desktop: ALWAYS 4 columns, never reflow */
@media (min-width: 769px) {
    .videos-grid {
        grid-template-columns: repeat(4, 1fr);
        grid-auto-flow: row;
    }
}

.video-card {
    background-color: var(--color-bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    display: flex;
    flex-direction: column;
}

.video-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 28px rgba(0,0,0,0.6);
    border-color: rgba(255,144,0,0.3);
}

.video-thumbnail {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background-color: var(--color-bg-overlay);
    overflow: hidden;
    /* Fallback for browsers without aspect-ratio */
    min-height: 0;
}

.video-thumbnail img,
.video-thumbnail .thumbnail-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Hover preview effect */
.video-thumbnail .preview-gif {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1;
}

.video-card:hover .video-thumbnail .preview-gif {
    opacity: 1;
}

/* Simple preview image that shows on hover */
.video-thumbnail .preview-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1;
}

.video-card:hover .video-thumbnail .preview-image {
    opacity: 1;
}

.video-card:hover .video-thumbnail .thumbnail-static {
    opacity: 0;
}

/* Preview loading indicator */
.video-thumbnail .preview-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--color-accent);
    font-size: 12px;
    opacity: 0;
    transition: opacity var(--transition-normal);
    z-index: 2;
    pointer-events: none;
}

.video-card:hover .video-thumbnail .preview-loading {
    opacity: 1;
}

/* Hover zoom effect removed - using preview image instead */

/* Preview play icon */
.video-thumbnail .preview-play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    background-color: rgba(255, 144, 0, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition-normal);
    z-index: 3;
    pointer-events: none;
}

.video-thumbnail .preview-play-icon::after {
    content: '';
    width: 0;
    height: 0;
    border-left: 20px solid #000;
    border-top: 12px solid transparent;
    border-bottom: 12px solid transparent;
    margin-left: 5px;
}

.video-card:hover .video-thumbnail .preview-play-icon {
    opacity: 0.8;
}

.video-duration {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: bold;
}

.video-quality {
    position: absolute;
    top: 8px;
    left: 8px;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: var(--color-accent);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.video-info {
    padding: 10px 12px 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.video-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.45;
    color: var(--color-text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    transition: color 0.15s ease;
}

.video-card:hover .video-title {
    color: #fff;
}

.video-channel {
    font-size: 11px;
    color: var(--color-accent);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--color-accent-subtle);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    width: fit-content;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.video-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--color-text-tertiary);
    margin-top: auto;
}

.video-meta .videoInfo {
    color: var(--color-text-tertiary);
    font-size: 11px;
}

/* Footer */
.footer {
    background-color: var(--color-bg-surface);
    padding: 30px 0;
    text-align: center;
    border-top: 1px solid var(--color-border);
    margin-top: 50px;
}

.footer p {
    color: var(--color-text-muted);
    font-size: 14px;
}

/* Responsive - Mobile First Approach */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) {
    .container {
        padding: 0 15px;
    }

    .videos-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 15px;
    }

    .categories-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

/* Mobile (max-width: 768px) */
@media (max-width: 768px) {
    .container {
        padding: 0 10px;
    }

    /* Header Mobile */
    .header {
        padding: 10px 0;
    }

    .header .container {
        flex-direction: column;
        gap: 10px;
    }

    .logo-text {
        font-size: 24px;
    }

    .search-bar {
        width: 100%;
        max-width: 100%;
    }

    .search-bar input {
        padding: 12px 15px;
        font-size: 16px;
        /* Prevents zoom on iOS */
    }

    .search-btn {
        padding: 12px 20px;
        font-size: 14px;
    }

    /* Navigation Mobile */
    .nav {
        padding: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .nav .container {
        gap: 0;
        padding: 0;
        display: flex;
        flex-wrap: nowrap;
        min-width: min-content;
    }

    .nav-link {
        padding: 12px 15px;
        white-space: nowrap;
        font-size: 13px;
        border-bottom: 2px solid transparent;
    }

    .nav-link.active {
        border-bottom-color: var(--color-accent);
    }

    /* Main Content Mobile */
    .main {
        padding: 15px 0;
    }

    .section-title {
        font-size: 20px;
        margin-bottom: 15px;
    }

    /* Section Header Mobile */
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .sort-bar {
        width: 100%;
    }

    .sort-select {
        width: 100%;
        padding: 10px 35px 10px 12px;
        font-size: 16px;
        /* Prevents zoom on iOS */
    }

    /* Categories Grid Mobile */
    .categories-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .category-card {
        min-height: 70px;
        padding: 15px;
    }

    .category-name {
        font-size: 14px;
    }

    /* Videos Grid Mobile - single column */
    .videos-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .video-card {
        border-radius: var(--radius-sm);
    }

    .video-thumbnail {
        border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    }

    .video-duration {
        bottom: 6px;
        right: 6px;
        padding: 2px 5px;
        font-size: 11px;
    }

    .video-quality {
        top: 6px;
        left: 6px;
        padding: 2px 6px;
        font-size: 10px;
    }

    .video-info {
        padding: 8px 10px 10px;
    }

    .video-title {
        font-size: 12px;
        -webkit-line-clamp: 2;
        line-clamp: 2;
    }

    .video-channel {
        font-size: 11px;
        margin-bottom: 4px;
    }

    .video-meta {
        font-size: 11px;
        gap: 3px;
    }

    /* Pagination Mobile */
    .pagination {
        gap: 5px;
        padding: 15px 0;
        margin: 20px 0;
        flex-wrap: wrap;
    }

    .pagination-btn {
        padding: 8px 12px;
        font-size: 13px;
        min-width: 35px;
    }

    .pagination-info {
        font-size: 12px;
        width: 100%;
        text-align: center;
        order: -1;
        margin-bottom: 10px;
    }

    /* Footer Mobile */
    .footer {
        padding: 20px 0;
        margin-top: 30px;
    }

    .footer p {
        font-size: 12px;
    }

    /* Hover Effects - Disable on Mobile */
    .video-card:hover {
        transform: none;
        box-shadow: none;
    }

    .category-card:hover {
        transform: none;
    }

    /* Preview GIF/image disabled on mobile (video preview is handled by JS touch events) */
    .video-thumbnail .preview-image,
    .video-thumbnail .preview-gif {
        display: none;
    }

    .hover-video-player {
        display: none;
    }
}

/* Small Mobile (max-width: 480px) */
@media (max-width: 480px) {
    .container {
        padding: 0 8px;
    }

    .logo-text {
        font-size: 20px;
    }

    .search-bar {
        gap: 8px;
    }

    .search-bar input {
        padding: 10px 12px;
    }

    .search-btn {
        padding: 10px 15px;
        font-size: 13px;
    }

    .nav-link {
        padding: 10px 12px;
        font-size: 12px;
    }

    .section-title {
        font-size: 18px;
    }

    .videos-grid {
        gap: 8px;
    }

    .video-info {
        padding: 6px;
    }

    .video-title {
        font-size: 12px;
    }

    .video-channel {
        font-size: 10px;
    }

    .video-meta {
        font-size: 10px;
    }

    .pagination-btn {
        padding: 6px 10px;
        font-size: 12px;
        min-width: 30px;
    }
}

/* Landscape Mobile - 2 columns */
@media (max-width: 768px) and (orientation: landscape) {
    .videos-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .header .container {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .search-bar {
        flex: 1;
        min-width: 300px;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {

    /* Larger tap targets for mobile */
    .nav-link,
    .search-btn,
    .pagination-btn,
    .category-card,
    .video-card {
        min-height: 44px;
        /* iOS recommended tap target */
    }

    /* Remove hover states on touch devices (keep .preview-video for JS touch preview) */
    .video-card:hover .video-thumbnail .preview-image,
    .video-card:hover .video-thumbnail .preview-gif {
        opacity: 0;
        display: none;
    }

    .video-card:hover .video-thumbnail img:not(.preview-gif) {
        opacity: 1;
    }
}


/* Video preview styling is handled by preview-hybrid.css and JS */
/* Legacy CSS-only hover preview rules removed — JS manages video visibility */


/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 40px 0;
    padding: 20px 0;
}

.pagination-btn {
    padding: 10px 16px;
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text-primary);
    cursor: pointer;
    border-radius: var(--radius-full);
    transition: all var(--transition-fast);
    font-size: 14px;
    min-width: 40px;
    text-align: center;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--color-bg-elevated);
    border-color: var(--color-border-hover);
}

.pagination-btn.active {
    background: var(--color-accent);
    color: #000;
    border-color: var(--color-accent);
    font-weight: 600;
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination-info {
    color: var(--color-text-muted);
    font-size: 14px;
    margin: 0 10px;
}


/* Categories Page */
.categories-section {
    padding: 40px 0;
}

.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 30px;
}

.category-card {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 20px;
    text-decoration: none;
    color: var(--color-text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all var(--transition-normal);
    cursor: pointer;
    min-height: 120px;
    position: relative;
    overflow: hidden;
    background-size: cover;
    background-position: center;
}

.category-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
    transition: transform var(--transition-normal);
}

.category-card:hover .category-img {
    transform: scale(1.05);
}

.category-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.55);
    transition: background var(--transition-normal);
}

.category-card:hover .category-overlay {
    background: rgba(0, 0, 0, 0.35);
}

.category-info {
    position: relative;
    z-index: 1;
    width: 100%;
    text-align: center;
}

.category-card:hover {
    border-color: var(--color-accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.category-name {
    font-size: 16px;
    font-weight: bold;
    margin: 0;
    text-align: center;
}

.category-count {
    font-size: 12px;
    color: var(--color-text-muted);
}

.category-arrow {
    display: none;
}


/* Hover Video Player */
.hover-video-player {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 10;
    border-radius: var(--radius-md);
    overflow: hidden;
}

.hover-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.hover-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.hover-scrubber {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.3);
    outline: none;
    border-radius: 2px;
    cursor: pointer;
}

.hover-scrubber::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    background: var(--color-accent);
    cursor: pointer;
    border-radius: 50%;
}

.hover-scrubber::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--color-accent);
    cursor: pointer;
    border-radius: 50%;
    border: none;
}

.hover-time {
    font-size: 11px;
    color: #fff;
    text-align: center;
}

.hover-time span {
    font-weight: bold;
}

/* Sort Bar */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.sort-bar {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sort-bar label {
    color: var(--color-text-muted);
    font-size: 14px;
}

.sort-select {
    padding: 8px 30px 8px 12px;
    background-color: var(--color-bg-input);
    border: 1px solid var(--color-border-input);
    border-radius: var(--radius-sm);
    color: var(--color-text-primary);
    font-size: 14px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23999' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: all var(--transition-fast);
}

.sort-select:hover {
    border-color: var(--color-accent);
    background-color: var(--color-bg-input-hover);
}

.sort-select:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-subtle);
}

.sort-select option {
    background-color: var(--color-bg-input);
    color: var(--color-text-primary);
}


/* Prevent layout breaking on zoom */
.container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
    box-sizing: border-box;
}

/* Allow horizontal scroll if content is too wide (zoomed in) */
body {
    overflow-x: auto;
    overflow-y: scroll;
}

html {
    overflow-x: auto;
    overflow-y: scroll;
}

/* Maintain grid structure on zoom */
.videos-grid {
    min-width: 0;
    /* Allow grid to shrink */
}

.video-card {
    min-width: 0;
    /* Prevent cards from forcing grid expansion */
    width: 100%;
}

/* Desktop: Always 4 columns */
@media (min-width: 769px) {
    .videos-grid {
        grid-template-columns: repeat(4, 1fr);
        grid-auto-flow: row;
    }

    .main {
        min-width: 0;
    }
}

/* Mobile: single column */
@media (max-width: 768px) {
    .videos-grid {
        grid-template-columns: 1fr;
        min-width: 0;
    }
}

/* Shared SEO Description Toggle Styles */
.description-wrapper {
    max-height: 100px;
    overflow: hidden;
    position: relative;
    transition: max-height 0.5s ease-out;
}

.description-wrapper.expanded {
    max-height: 2000px;
}

.description-wrapper.truncated::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40px;
    background: linear-gradient(transparent, var(--color-bg-primary));
    pointer-events: none;
}

/* If inside a card/section with lighter bg, override */
.category-seo-section .description-wrapper.truncated::after {
    background: linear-gradient(transparent, var(--color-bg-primary));
}

.show-more-desc-btn {
    background: none;
    border: none;
    color: var(--color-accent);
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    padding: 10px 0 0 0;
    display: none;
    /* JS toggles this */
    align-items: center;
    gap: 5px;
}

.show-more-desc-btn:hover {
    color: var(--color-accent-hover);
    text-decoration: underline;
}

/* SEO Internal Linking Style */
.seo-internal-link {
    color: var(--color-accent) !important;
    text-decoration: none !important;
    font-weight: 500;
    transition: var(--transition-fast);
}

.seo-internal-link:hover {
    color: var(--color-accent-hover) !important;
    text-decoration: underline !important;
}