/* ============================================
   RESPONSIVE DESIGN - PERCENTAGE-BASED
   ============================================ */

/* Large screens - optimize spacing */
@media (min-width: 1600px) {
    #main-container {
        padding: 1.5% 3%;
    }
    
    #playlist {
        width: 25%;
        min-width: 350px;
    }
    
    #map {
        width: 73%;
    }
}

/* Medium-Large screens */
@media (min-width: 1200px) and (max-width: 1599px) {
    #main-container {
        padding: 1% 2%;
    }
    
    #playlist {
        width: 28%;
        min-width: 320px;
    }
    
    #map {
        width: 70%;
    }
}

/* Small-Medium screens */
@media (min-width: 992px) and (max-width: 1199px) {
    #main-container {
        padding: 1% 1.5%;
    }
    
    #playlist {
        width: 30%;
        min-width: 280px;
    }
    
    #map {
        width: 68%;
    }
}

/* Tablet Portrait and below - STACK LAYOUT */
@media (max-width: 991px) {
    #main-container {
        flex-direction: column;
        padding: 2%;
        gap: 15px;
    }
    
    #map {
        width: 100%;
        height: 45vh;
        min-height: 300px;
        max-height: 400px;
    }
    
    #playlist {
        width: 100%;
        max-width: 100%;
        min-width: unset;
        height: auto;
        max-height: 50vh;
        overflow-y: auto;
    }
    
    #search-container {
        flex-direction: row;
        gap: 2%;
        margin-bottom: 15px;
    }
    
    #search-box {
        width: 70%;
    }
    
    #search-button {
        width: 28%;
        padding: 3% 2%;
    }
}

/* Tablet Small and Mobile Large */
@media (max-width: 768px) {
    #intro h1 {
        font-size: clamp(22px, 4vw, 32px);
    }
    
    #intro p {
        font-size: clamp(13px, 2vw, 16px);
        padding: 0 10px;
    }
    
    #search-container {
        flex-direction: column;
        gap: 10px;
        padding: 0 5%;
        margin-bottom: 15px;
    }
    
    #search-box {
        width: 100%;
        padding: 12px;
        font-size: 15px;
    }
    
    #search-button {
        width: 100%;
        padding: 12px;
        font-size: 15px;
    }
    
    #map {
        height: 40vh;
        min-height: 280px;
        max-height: 350px;
    }
    
    #playlist {
        max-height: 55vh;
        padding: 15px;
    }
    
    /* Playlist buttons - better mobile layout */
    #playlist-buttons {
        display: flex;
        gap: 6px;
        margin-bottom: 15px;
    }
    
    #playlist-buttons button {
        flex: 1;
        padding: 10px 8px;
        font-size: 12px;
        font-weight: 600;
        white-space: nowrap;
    }
    
    .featured-video-item,
    .category-video-item {
        padding: 10px !important;
        margin-bottom: 10px !important;
    }
    
    .featured-video-item img,
    .category-video-item img {
        width: 30% !important;
        height: auto !important;
        aspect-ratio: 16/9;
    }
    
    .featured-video-item h4,
    .category-video-item h4 {
        font-size: 13px !important;
        line-height: 1.3;
    }
    
    .featured-video-item span,
    .category-video-item span {
        font-size: 10px !important;
    }
}

/* Mobile */
@media (max-width: 576px) {
    /* Intro section */
    #intro {
        padding: 15px;
    }
    
    #intro h1 {
        font-size: clamp(20px, 5vw, 28px);
        margin-bottom: 8px;
    }
    
    #intro p {
        font-size: clamp(12px, 2.5vw, 14px);
        padding: 0 10px;
    }
    
    /* Search - equal spacing with nav and map */
    #search-container {
        padding: 0 15px;
        gap: 10px;
        margin-top: 15px;
        margin-bottom: 15px;
    }
    
    #search-box {
        padding: 12px 15px;
        font-size: 14px;
    }
    
    #search-button {
        padding: 12px;
        font-size: 14px;
    }
    
    /* Main container - equal spacing */
    #main-container {
        padding: 0 10px 10px 10px;
        gap: 15px;
        margin-top: 0;
    }
    
    /* Map - smaller on mobile */
    #map {
        height: 30vh;
        min-height: 220px;
        max-height: 280px;
        border-radius: 10px;
    }
    
    /* Playlist - MUCH MORE SPACE */
    #playlist {
        max-height: 70vh;
        padding: 12px;
        border-radius: 10px;
    }
    
    /* Playlist toggle buttons - MOBILE OPTIMIZED */
    #playlist-buttons {
        display: flex;
        gap: 5px;
        margin-bottom: 12px;
        padding: 0;
        flex-wrap: nowrap;
    }
    
    #playlist-buttons button {
        flex: 1;
        padding: 11px 6px;
        font-size: 11px;
        font-weight: 700;
        white-space: nowrap;
        min-width: 0;
        border-radius: 8px;
        letter-spacing: -0.3px;
    }
    
    /* Video items */
    .featured-video-item,
    .category-video-item {
        padding: 10px !important;
        margin-bottom: 10px !important;
        border-radius: 8px;
    }
    
    .featured-video-item > div,
    .category-video-item > div {
        gap: 10px !important;
    }
    
    .featured-video-item img,
    .category-video-item img {
        width: 90px !important;
        height: 50px !important;
        object-fit: cover;
        border-radius: 6px;
        flex-shrink: 0;
    }
    
    .featured-video-item h4,
    .category-video-item h4 {
        font-size: 13px !important;
        line-height: 1.4;
        margin-bottom: 4px;
    }
    
    .featured-video-item span,
    .category-video-item span {
        font-size: 10px !important;
        padding: 3px 8px !important;
    }
    
    /* Selected video */
    #selected-video {
        margin-bottom: 15px !important;
        padding-bottom: 15px !important;
    }
    
    #selected-video iframe {
        height: 50vw !important;
        min-height: 200px !important;
        max-height: 250px !important;
        border-radius: 10px;
    }
    
    /* Categories section - VERY COMPACT */
    #categories-quick-browse {
        padding: 8px 10px;
        background: white;
    }
    
    /* Categories grid - 5 COLUMNS, VERY SMALL */
    .categories-grid-compact {
        grid-template-columns: repeat(5, 1fr) !important;
        gap: 4px !important;
        padding: 0;
        max-width: 100%;
    }
    
    .category-compact-card {
        padding: 6px 4px !important;
        border-radius: 5px;
        min-height: 50px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        background: white;
        border: 1px solid #e5e5ea;
        transition: all 0.3s ease;
    }
    
    .category-compact-card:active {
        transform: scale(0.95);
        background: #e8f5ee;
        border-color: #52c77a;
    }
    
    .category-icon {
        font-size: 12px !important;
        margin-bottom: 1px;
    }
    
    .category-name {
        font-size: 8px !important;
        font-weight: 700;
        line-height: 1;
        text-align: center;
        color: #2c3e50;
    }
    
    .category-count {
        display: none !important;
    }
    
    /* Category header - MOBILE */
    #category-videos-list h3 {
        font-size: 15px !important;
    }
    
    #category-videos-list button {
        font-size: 11px !important;
        padding: 6px 12px !important;
    }
}

/* Very Small Mobile */
@media (max-width: 400px) {
    #intro h1 {
        font-size: clamp(18px, 6vw, 24px);
    }
    
    #map {
        height: 35vh;
        min-height: 250px;
    }
    
    .featured-video-item img,
    .category-video-item img {
        width: 40% !important;
    }
    
    /* Extra small buttons */
    #playlist-buttons button {
        font-size: 10px;
        padding: 8px 6px;
    }
    
    /* Categories - 5 columns on tiny screens too */
    .categories-grid-compact {
        grid-template-columns: repeat(5, 1fr) !important;
        gap: 3px !important;
    }
    
    .category-compact-card {
        padding: 5px 3px !important;
        min-height: 45px;
    }
    
    .category-icon {
        font-size: 11px !important;
    }
    
    .category-name {
        font-size: 7px !important;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Larger tap targets for touch */
    .nav-tab {
        min-height: 44px;
        padding: 15px 20px;
    }
    
    #playlist-buttons button {
        min-height: 44px;
        padding: 12px 10px;
    }
    
    .featured-video-item,
    .category-video-item {
        min-height: 60px;
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(82, 199, 122, 0.1);
    }
    
    .category-compact-card {
        min-height: 100px;
        -webkit-tap-highlight-color: rgba(82, 199, 122, 0.1);
    }
    
    /* Remove hover effects on touch */
    .featured-video-item:hover,
    .category-video-item:hover,
    .category-compact-card:hover {
        transform: none;
    }
    
    /* Active state instead */
    .featured-video-item:active,
    .category-video-item:active {
        transform: scale(0.98);
        background: #e8f5ee !important;
    }
    
    .category-compact-card:active {
        transform: scale(0.95);
        background: #e8f5ee !important;
    }
}


/* Landscape mode optimization */
@media (max-height: 600px) and (orientation: landscape) {
    #intro {
        padding: 1.5%;
    }
    
    #intro h1 {
        font-size: clamp(18px, 3vh, 24px);
        margin-bottom: 0.5%;
    }
    
    #intro p {
        font-size: clamp(11px, 2vh, 14px);
    }
    
    #search-container {
        margin: 1% 0;
    }
    
    #main-container {
        padding: 1%;
    }
    
    #map {
        min-height: 250px;
        height: 70vh;
    }
    
    #playlist {
        max-height: 70vh;
    }
}

/* High DPI screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    #map,
    #playlist {
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    }
}

/* Print */
@media print {
    #nav-menu,
    #search-container,
    #playlist {
        display: none !important;
    }
    
    #main-container {
        padding: 0;
    }
    
    #map {
        width: 100%;
        height: 80vh;
        page-break-inside: avoid;
    }
}

/* ============================================
   iOS SAFARI SPECIFIC FIXES
   ============================================ */

/* Fix for iOS Safari address bar */
@supports (-webkit-touch-callout: none) {
    #map {
        height: calc(40vh - 70px);
    }
    
    #playlist {
        max-height: calc(55vh - 70px);
    }
}

/* Prevent zoom on input focus (iOS) */
@media screen and (max-width: 576px) {
    input[type="text"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Smooth scrolling for mobile */
@media (max-width: 768px) {
    #playlist {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    body {
        -webkit-overflow-scrolling: touch;
    }
}

/* Fix for safe area (notch) on iPhone X and newer */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        #nav-menu {
            padding-top: max(15px, env(safe-area-inset-top));
            padding-left: max(15px, env(safe-area-inset-left));
            padding-right: max(15px, env(safe-area-inset-right));
        }
        
        #main-container {
            padding-left: max(3%, env(safe-area-inset-left));
            padding-right: max(3%, env(safe-area-inset-right));
            padding-bottom: max(3%, env(safe-area-inset-bottom));
        }
    }
}
