:root {
    --primary-bg: #1a1d24;
    --secondary-bg: #2a2d35;
    --accent-color: #00aaff;
    --text-color: #e0e0e0;
    --text-muted: #888;
    --button-glow: 0 0 15px rgba(0, 170, 255, 0.7);
    --button-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

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

html, body {
    height: 100%;
    font-family: 'Roboto', sans-serif;
    background-color: var(--primary-bg);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    margin: 0; /* Ensure no default browser margins */
    padding: 0; /* Ensure no default browser paddings */
}

#radio-container {
    width: 100%;
    max-width: 900px;
    height: 100%;
    max-height: 600px;
    background-color: var(--secondary-bg);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow: hidden;
}

header {
    text-align: center;
    padding-bottom: 15px;
    border-bottom: 1px solid #444;
    display: grid;
    grid-template-columns: 1fr 2fr;
    align-items: center;
    gap: 15px;
}

header h1 {
    font-family: 'Orbitron', sans-serif;
    color: var(--accent-color);
    letter-spacing: 2px;
    font-size: clamp(1rem, 3vw, 1.4rem); /* Increased font size for desktop and mobile */
    margin-bottom: 0;
    text-shadow: 0 0 10px var(--accent-color);
    text-align: left;
}

#now-playing {
    background: #111;
    border-radius: 8px;
    padding: 10px;
    font-size: clamp(0.9rem, 2.5vw, 1.1rem); /* Increased font size */
    min-height: 45px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    text-align: center;
    position: relative;
}

#player-status {
    color: var(--text-muted);
    font-size: clamp(0.8rem, 2.3vw, 1rem); /* Increased font size */
    transition: all 0.3s ease;
    min-height: 20px;
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

#player-status.rds-update {
    color: var(--accent-color);
    text-shadow: 0 0 5px var(--accent-color);
    animation: rds-blink 1s ease-in-out;
}

@keyframes rds-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* RDS-style display for track info */
#player-status::before {
    content: "♪ ";
    margin-right: 5px;
    color: var(--accent-color);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

#category-selector {
    display: flex;
    justify-content: space-around;
    padding: 15px 0;
    gap: 5px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.category-btn {
    flex-shrink: 0;
    padding: 4px 8px;
    font-size: clamp(0.8rem, 2vw, 0.9rem); /* Increased font size */
    font-weight: 500;
    font-family: 'Orbitron', sans-serif;
    background: #333842;
    color: var(--text-muted);
    border: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--button-shadow);
    min-width: 70px;
}

.category-btn:hover {
    background: #404550;
    color: var(--text-color);
}

.category-btn.active {
    background: var(--accent-color);
    color: var(--primary-bg);
    border-color: var(--accent-color);
    box-shadow: var(--button-glow);
}

#station-grid {
    flex-grow: 1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: clamp(8px, 1.5vw, 15px);
    padding: 10px;
    overflow-y: auto;
}

.station-btn {
    background-color: var(--primary-bg);
    color: var(--text-color);
    border: 2px solid #444;
    border-radius: 12px;
    padding: clamp(10px, 2vw, 15px);
    text-align: center;
    font-size: clamp(0.9rem, 2.2vw, 1.1rem); /* Increased font size */
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    box-shadow: var(--button-shadow);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 70px;
    word-break: break-word;
}

.station-btn:hover {
    transform: translateY(-3px);
    border-color: #666;
}

.station-btn.playing {
    background-color: var(--accent-color);
    color: var(--primary-bg);
    border-color: var(--accent-color);
    box-shadow: var(--button-glow);
    font-weight: 700;
}

/* Scrollbar for station grid */
#station-grid::-webkit-scrollbar {
  width: 8px;
}
#station-grid::-webkit-scrollbar-track {
  background: var(--primary-bg);
  border-radius: 4px;
}
#station-grid::-webkit-scrollbar-thumb {
  background-color: var(--accent-color);
  border-radius: 4px;
}

#station-nav {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: none;
    margin-top: 0;
    gap: 0;
    position: absolute;
    left: 0;
    right: 0;
    padding: 0 10px;
    top: 15px; /* Adjusted to move further up */
}

.nav-btn {
    background: var(--primary-bg);
    color: var(--accent-color);
    border: 2px solid var(--accent-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--button-glow);
}

.nav-btn:hover {
    background: var(--accent-color);
    color: var(--primary-bg);
    transform: scale(1.1);
}

.nav-btn:active {
    transform: scale(0.9);
}

@media (max-width: 600px) {
    body {
        background-color: var(--secondary-bg);
        display: block; /* Override flex properties from html, body */
        height: 100vh; /* Ensure body takes full viewport height */
        width: 100vw; /* Ensure body takes full viewport width */
    }
    
    #radio-container {
        border-radius: 0;
        height: 100vh;
        max-height: none;
        padding: 40px 0; /* Add top and bottom padding, keep horizontal padding 0 */
        width: 100vw; /* Ensure it takes full viewport width */
        max-width: 100vw; /* Ensure it takes full viewport width */
        box-shadow: none; /* Remove shadow to blend seamlessly with body background */
    }

    #category-selector {
        gap: 3px;
        padding: 10px;
    }

    .category-btn {
        font-size: clamp(0.75rem, 1.9vw, 0.85rem); /* Increased font size */
        padding: 3px 6px;
        min-width: 65px;
    }

    #station-grid {
        grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
        gap: 6px;
        padding: 10px 5px;
    }
    
    .station-btn {
        font-size: clamp(0.8rem, 2vw, 1rem); /* Increased font size */
        padding: 6px;
        min-height: 55px;
    }
}

@media (max-width: 400px) {
    #station-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .category-btn {
        font-size: 0.7rem;
        min-width: 60px;
    }

    .station-btn {
        font-size: 0.95rem;
    }
}

@media (max-height: 500px) {
    #radio-container {
        padding: 0;
    }
    
    header {
        padding: 10px;
    }
    
    #category-selector {
        padding: 8px 10px;
    }
}

@media (max-width: 500px) {
    header {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    header h1 {
        text-align: center;
        font-size: clamp(1.1rem, 3.5vw, 1.5rem); /* Adjusted for mobile header title */
    }
    
    #station-nav {
        top: 15px; /* Also adjust for mobile viewports */
    }
}