body {
    font-family: Arial, sans-serif;
    background-color: #1a202c;
    color: white;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
}

/* Accessibility: Hide visually but keep for screen readers */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0.5rem;
    position: relative;
}

/* Header row with title left, links right */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
    padding: 0 0.5rem;
}

.top-links {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
}
.top-links a {
    color: white;
    text-decoration: none;
    font-size: 0.75rem;
    white-space: nowrap;
}
.top-links a:hover {
    text-decoration: underline;
}
.page-title {
    color: white;
    font-size: 2rem;
    margin: 0;
    font-weight: bold;
    text-align: left;
}

/* Main content area with banners and video */
.main-content {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.banner-left,
.banner-right {
    width: 160px;
    min-height: 600px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Hide banners on screens too narrow for ads */
@media (max-width: 1100px) {
    .banner-left,
    .banner-right {
        display: none;
    }
}

.video-wrapper {
    flex: 1;
    min-width: 0;
}
.video-container {
    position: relative;
    aspect-ratio: 16 / 9;
    margin-bottom: 0.5rem;
    width: 100%;
}

/* Desktop: Constrain video height on short viewports to ensure buttons stay visible */
@media (min-width: 768px) and (max-height: 850px) {
    .video-container {
        max-height: calc(100vh - 150px);
    }
}

@media (min-width: 768px) and (max-height: 750px) {
    .video-container {
        max-height: calc(100vh - 160px);
    }
}

/* Narrower widths (768-900px) need more aggressive constraints */
@media (min-width: 768px) and (max-width: 900px) and (max-height: 720px) {
    .video-container {
        max-height: calc(100vh - 245px);
    }
}

/* Mid-range widths (900-1023px) need strong constraints */
@media (min-width: 901px) and (max-width: 1023px) and (max-height: 720px) {
    .video-container {
        max-height: calc(100vh - 245px);
    }
}

/* Specific fix for 1000px width - prioritize button visibility over perfect aspect ratio */
@media (min-width: 950px) and (max-width: 1050px) and (max-height: 720px) {
    .video-container {
        max-height: calc(100vh - 245px);
    }
}

/* Wider widths (1024px+) need less aggressive constraints */
@media (min-width: 1024px) and (max-height: 720px) {
    .video-container {
        max-height: calc(100vh - 150px);
    }
}

#videoPlayer {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background-color: black;
}
.controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.3s ease;
}
/* Controls always visible on desktop and mobile */
.control-group {
    display: flex;
    gap: 0.5rem;
}
.btn {
    background-color: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.5rem;
    font-size: 1rem;
}
.btn:hover {
    opacity: 0.8;
}
.volume-slider {
    width: 100px;
    height: 40px;
    padding: 0 10px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}
.volume-slider::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    background: #444;
    border-radius: 2px;
    border: none;
}
.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    margin-top: -6px;
}
#volumeSlider {
    width: 100px;
    height: 40px;
    padding: 0 10px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}
#volumeSlider::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    background: #444;
    border-radius: 2px;
    border: none;
}
#volumeSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    margin-top: -6px;
}
.channels {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.channel-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    height: auto;
    padding: 0.25rem;
    background-color: black;
    border: 2px solid #4a5568;
    border-radius: 0.5rem;
    transition: border-color 0.2s ease-in-out;
    color: white;
}
.channel-btn:hover {
    border-color: white;
}
.channel-btn.active {
    border-color: #9b2c2c;
}
.channel-btn img {
    width: 1.5rem;
    height: 1.5rem;
    object-fit: contain;
}
.channel-btn span {
    font-size: 0.7rem;
    text-align: center;
    white-space: pre-line;
    line-height: 1.25;
}


/* Tablet: 6 columns for medium screens */
@media (min-width: 600px) and (max-width: 1023px) {
    .channels {
        grid-template-columns: repeat(6, 1fr);
        gap: 0.75rem;
    }
    .channel-btn {
        padding: 0.5rem;
    }
    .channel-btn img {
        width: 2rem;
        height: 2rem;
    }
    .channel-btn span {
        font-size: 0.75rem;
    }
    .container {
        max-width: 900px;
    }
}

/* Desktop: 9 columns for large screens */
@media (min-width: 1024px) {
    .channels {
        grid-template-columns: repeat(9, 1fr);
    }
    .container {
        max-width: 1280px;
    }
}

@media (max-width: 767px) {
    .container {
        padding: 0;
        display: flex;
        flex-direction: column;
    }
    .header-row {
        flex-direction: column;
        align-items: center;
        padding: 0.5rem;
        order: 0;
    }
    .page-title {
        text-align: center;
        margin-bottom: 0.5rem;
    }
    .main-content {
        order: 1;
    }
    .banner-left,
    .banner-right {
        display: none;
    }
    .video-wrapper {
        width: 100%;
    }
    .video-container {
        margin-bottom: 0;
    }
    .channels {
        grid-template-columns: repeat(3, 1fr);
        padding: 0.5rem;
        gap: 0.25rem;
        order: 2;
    }
    .top-links {
        order: 3;
        padding: 1rem 0.5rem;
        align-items: center;
        text-align: center;
    }
    .top-links a {
        color: white;
    }
    .channel-btn {
        height: auto;
        padding: 0.25rem;
    }
    .channel-btn img {
        width: 1.5rem;
        height: 1.5rem;
    }
    .channel-btn span {
        font-size: 0.7rem;
    }
    #qrOverlay {
        display: none !important;
    }
}

/* Mobile landscape only: Hide title to prevent video cropping */
@media (max-width: 767px) and (orientation: landscape) {
    .page-title {
        display: none;
    }
}

/* Mobile landscape: Force 3-column grid regardless of width */
@media (orientation: landscape) and (max-height: 500px) {
    .channels {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.25rem;
        padding: 0.5rem;
    }
    .channel-btn {
        padding: 0.25rem;
    }
    .channel-btn img {
        width: 1.5rem;
        height: 1.5rem;
    }
    .channel-btn span {
        font-size: 0.7rem;
    }
    .top-links {
        padding: 1rem 0.5rem;
        align-items: center;
    }
    .banner-left,
    .banner-right {
        display: none;
    }
}
/* Desktop: 9 columns for large screens */
@media (min-width: 1024px) {
    .channels {
        grid-template-columns: repeat(9, 1fr);
    }
    .container {
        max-width: 1280px;
    }
    /*
    #fullscreenBtn {
        display: none;
    }
    */
}
.qr-overlay {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 10px;
    z-index: 3;
}

/* Ensure QR overlay is visible on desktop */
@media (min-width: 768px) {
    #qrOverlay {
        display: flex !important;
    }
}
.remote-icon {
    width: 24px;
    height: 24px;
    cursor: pointer;
    fill: white;
    display: block;
}
.remote-icon:hover {
    opacity: 0.8;
}
.qr-container {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 10px;
    z-index: 999;
}

/* Show QR code on hover - CSS fallback */
.qr-overlay:hover .qr-container {
    display: block !important;
}

.qr-overlay:hover .qr-tooltip {
    display: block !important;
}
.qr-inner {
    background: white;
    padding: 10px;
    border-radius: 4px;
}
.qr-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 14px;
    white-space: nowrap;
    display: none;
    margin-bottom: 5px;
    z-index: 1001;
    pointer-events: none;
}
.qr-text {
    margin-top: 8px;
    color: white;
    text-align: center;
    font-size: 14px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}
#airplayBtn {
    cursor: pointer;
    opacity: 1;
    transition: opacity 0.2s;
}
#airplayBtn:hover {
    opacity: 0.8;
}
#airplayBtn:active {
    opacity: 0.6;
}
#airplayBtn.available {
    display: block;
}
#airplayBtn.not-available {
    display: none;
}

/* Pulse animation for fullscreen button */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.pulse {
    animation: pulse 0.6s ease-in-out 3;
}

/* Highlight fullscreen button when remote is connected */
#fullscreenBtn.highlight-connected {
    transform: scale(1.3);
    background: rgba(76, 175, 80, 0.3);
    box-shadow:
        0 0 20px rgba(76, 175, 80, 0.8),
        0 0 40px rgba(255, 255, 255, 0.6),
        0 0 0 2px rgba(255, 255, 255, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.9);
    transition: all 0.3s ease;
}

#fullscreenBtn.highlight-connected:hover {
    transform: scale(1.4);
    background: rgba(76, 175, 80, 0.5);
    box-shadow:
        0 0 30px rgba(76, 175, 80, 1),
        0 0 50px rgba(255, 255, 255, 0.8),
        0 0 0 3px rgba(255, 255, 255, 1);
    border: 2px solid rgba(255, 255, 255, 1);
}

.player-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0 10px;
}
.connection-status {
    display: none;
}

/* Swipe tip for first-time mobile users */
.swipe-tip {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background-color: #9b2c2c;
    color: white;
    padding: 0.75rem 1rem;
    margin: 0.5rem 0;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    opacity: 1;
    transition: opacity 0.3s ease;
    position: relative;
}

.dismiss-tip {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    padding: 0;
    transition: background 0.2s ease;
}

.dismiss-tip:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Hide swipe tip on desktop */
@media (min-width: 768px) {
    .swipe-tip {
        display: none !important;
    }
}

/* Audio Player Specific Styles */
.audio-container {
    position: relative;
    margin-bottom: 0.5rem;
    width: 100%;
}

.artwork-display {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin: 0 auto 1rem auto;
    background-color: black;
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.channel-artwork {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    display: block;
}

.channel-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
    padding: 2rem 1rem 1rem 1rem;
}

.current-channel-name {
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

#audioPlayer {
    display: none;
}

/* Mobile adjustments for audio player */
@media (max-width: 767px) {
    .artwork-display {
        max-width: 100%;
        border-radius: 0;
        margin-bottom: 0;
    }

    .current-channel-name {
        font-size: 1.25rem;
    }
}