:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --text-color: #1f2937;
    --bg-color: #f9fafb;
    --console-bg: #f3f4f6;
    --card-bg: #ffffff;
    --border-color: #e5e7eb;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

.dark-theme {
    --primary-color: #60a5fa;
    --primary-hover: #93c5fd;
    --text-color: #d1d5db;
    --bg-color: #111827;
    --console-bg: #1f2937;
    --card-bg: #374151;
    --border-color: #4b5567;
    --card-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    /* Add a background image to see the glass effect */
    background-image: url('https://images.unsplash.com/photo-1519681393784-d120267933ba?auto=format&fit=crop&w=1950');
    background-size: cover;
    background-position: center;
    background-attachment: fixed; /* Keeps the background static during scroll */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    transition: background-color 0.3s, color 0.3s;
}

.main-content {
    /* Add a subtle overlay to ensure text is always readable */
    background-color: rgba(0, 0, 0, 0.2);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    min-height: 80vh;
}

.tool-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 25px;
    /* Glassmorphism effect */
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);

    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--card-shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.tool-header h2 {
    font-size: 1.2rem;
    margin: 0;
    color: var(--primary-color);
    font-weight: 600;
}

.theme-btn {
    background: var(--console-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1; /* Ensures button height is consistent */
}

.radiostream-player {
    /* Glassmorphism effect */
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);

    border-radius: 16px;
    box-shadow: var(--card-shadow);
    padding: 25px;
    width: 90%;
    max-width: 600px;
    min-width: 400px;
    margin: 0 auto;
    color: var(--text-color); /* This will be overridden by dark theme if active */
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
    display: flex;
    gap: 20px;
    align-items: stretch;
}

.dark-theme .tool-header,
.dark-theme .radiostream-player {
    background: rgba(31, 41, 55, 0.3); /* Darker glass for dark mode */
}

.dark-theme .radiostream-player {
    color: #e5e7eb; /* Use a lighter text color for better contrast on the dark glass */
}

/* Ensure the popout window shares the same background as the main page for a consistent glass effect */
body.popout-body {
    /* We don't need to override anything. The default body style with the 
       background image will apply, which is what we want. This rule can be removed. */
}

.popout-player {
    /* Glassmorphism effect for the popout player */
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);

    border-radius: 8px;
    padding: 10px;
    text-align: center;
    border: 1px solid var(--border-color);
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
}

.popout-player .control-bar {
    padding: 0 5px;
    margin-top: 5px;
}

.dark-theme .popout-player {
    background: rgba(31, 41, 55, 0.3); /* Darker glass for dark mode */
}


.vu-meters {
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 10px;
    width: 80px;
    align-items: stretch;
    position: relative;
}

/* VU Style Cycle Button */
.vu-style-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 10;
    transition: all 0.2s ease;
}

.vu-style-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
}

/* Base VU Meter Styles */
.vu-meter {
    background: var(--console-bg);
    border-radius: 8px;
    height: 100%;
    width: 30px;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Classic VU Style */
.vu-classic .vu-meter {
    width: 15px;
}

.vu-level {
    position: absolute;
    bottom: 0;
    width: 100%;
    background: #00ff00;
    transition: height 0.1s ease, background 0.1s ease;
}

/* LED VU Style */
.vu-led .vu-meter {
    width: 20px;
    padding: 1px;
}

.led-container {
    display: flex;
    flex-direction: column-reverse;
    gap: 1px;
    height: calc(100% - 2px);
    width: 100%;
    justify-content: flex-start;
}

.led-segment {
    width: 100%;
    flex: 1;
    min-height: 3px;
    background: #00ff00;
    border-radius: 1px;
    opacity: 0.1;
    transition: opacity 0.1s ease, background 0.1s ease;
}

/* Circular VU Style */
.vu-circular .vu-meter {
    width: 35px;
    height: 100%;
    border-radius: 0;
    background: var(--console-bg);
    border: 1px solid var(--border-color);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.vu-circular .vu-meters {
    width: 80px;
    gap: 10px;
}

.vu-circular svg {
    width: 30px;
    height: 30px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.circular-level {
    transition: stroke-dashoffset 0.1s ease, stroke 0.1s ease;
}

/* Waveform VU Style */
.vu-waveform .vu-meter {
    width: 60px;
    background: transparent;
    border: 1px solid var(--border-color);
}

.vu-waveform .vu-meters {
    width: 140px;
    gap: 20px;
}

.waveform-canvas {
    width: 100%;
    height: 100%;
    border-radius: 4px;
}

/* Spectrum VU Style */
.vu-spectrum .vu-meter {
    width: 60px;
    padding: 2px;
}

.vu-spectrum .vu-meters {
    width: 140px;
    gap: 20px;
}

.spectrum-container {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    height: 100%;
    width: 100%;
    gap: 1px;
}

.spectrum-bar {
    background: #00ff00;
    width: 3px;
    min-height: 2px;
    transition: height 0.1s ease, background 0.1s ease;
    border-radius: 1px 1px 0 0;
}

/* Retro VU Style */
.vu-retro .vu-meter {
    width: 35px;
    height: 80px;
    background: radial-gradient(ellipse at center bottom, var(--console-bg) 40%, var(--border-color) 80%);
    border-radius: 35px 35px 0 0;
    overflow: visible;
    position: relative;
    border: 1px solid var(--border-color);
}

.vu-retro .vu-meters {
    width: 80px;
    gap: 10px;
}

.retro-vu {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
}

.retro-scale {
    position: absolute;
    bottom: 2px;
    font-size: 4px;
    color: var(--text-color);
    opacity: 0.8;
    white-space: nowrap;
    letter-spacing: 0px;
    line-height: 1;
    transform: scale(0.8);
}

.retro-needle {
    position: absolute;
    bottom: 15px;
    left: 50%;
    width: 1px;
    height: 20px;
    border-left: 1px solid #00ff00;
    transform-origin: bottom center;
    transform: translate(-50%, 0) rotate(-45deg);
    transition: transform 0.2s ease, border-color 0.1s ease;
    z-index: 5;
}

.retro-needle::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: -1px;
    width: 3px;
    height: 3px;
    background: var(--primary-color);
    border-radius: 50%;
}

.player-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.station-selector label {
    /* The label is now hidden, but kept for accessibility.
       We use aria-label on the select element instead. */
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.station-selector select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--primary-color);
    border-radius: 8px;
    background: var(--console-bg);
    color: var(--text-color);
    font-size: 1rem;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.station-selector select:focus {
    outline: none;
    border-color: var(--primary-hover);
}

.control-bar {
    display: flex;
    align-items: center; /* Vertically align all items in the bar */
    gap: 10px;
    width: 100%;
}

.volume-control {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-grow: 1; /* Allow the volume control to take up remaining space */
    min-width: 100px;
}

.volume-control label {
    /* The label is now hidden, but kept for accessibility.
       We use aria-label on the range input instead. */
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.volume-control input[type="range"] {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 6px; /* Make the track slimmer */
    background: transparent; /* Background will be set by JS */
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.volume-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px; /* Slightly smaller thumb */
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid var(--card-bg); /* Creates a "halo" effect that looks good on the glass */
    box-shadow: var(--card-shadow);
    margin-top: -6px; /* Center the thumb on the track */
    transition: transform 0.2s ease;
}

.volume-control input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid var(--card-bg);
    box-shadow: var(--card-shadow);
}

.volume-control input[type="range"]:hover::-webkit-slider-thumb {
    transform: scale(1.1);
}

.now-playing {
    font-size: 1.2em;
    font-weight: 500;
    color: var(--primary-color);
    background: var(--console-bg);
    padding: 10px 15px;
    border-radius: 8px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: color 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Generic button style for standalone */
.console-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s;
}
.console-btn:hover {
    background-color: var(--primary-hover);
}

.console-btn .icon {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

#play-pause-btn {
    padding: 10px; /* Make the play/pause button square */
}

/* Adjustments for pop-out player */
.popout-player .now-playing {
    font-size: 0.9em;
    padding: 8px 10px;
    margin: 0 5px;
}

.popout-player .station-selector select {
    padding: 6px;
    font-size: 0.9rem;
}

.popout-player .console-btn {
    padding: 8px; /* Make buttons smaller */
}

.popout-player .volume-control {
    min-width: 80px; /* Ensure volume slider has some space */
}

.popout-player .volume-control input[type="range"]::-webkit-slider-thumb {
    width: 16px;
    height: 16px;
    margin-top: -5px; /* Re-center smaller thumb on track */
}

.popout-player .volume-control input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
}

/* Mobile Responsive Styles */
@media (max-width: 500px) {
    .radiostream-player {
        flex-direction: column;
        padding: 20px;
        min-width: 300px;
    }

    .vu-meters {
        flex-direction: row;
        width: 100%;
        justify-content: center;
        height: 60px;
    }

    /* Mobile Classic Style */
    .vu-classic .vu-meter {
        width: 60px;
        height: 20px;
    }

    .vu-classic .vu-level {
        height: 100%;
        width: 0%;
        bottom: auto;
        left: 0;
    }

    /* Mobile LED Style */
    .vu-led .vu-meter {
        width: 80px;
        height: 20px;
    }

    .vu-led .led-container {
        flex-direction: row;
        align-items: center;
    }

    .vu-led .led-segment {
        width: 3px;
        height: 100%;
    }

    /* Mobile Circular Style */
    .vu-circular .vu-meters {
        width: 100%;
        gap: 30px;
        justify-content: center;
    }

    .vu-circular .vu-meter {
        width: 50px;
        height: 50px;
    }

    /* Mobile Waveform Style */
    .vu-waveform .vu-meters {
        width: 100%;
        gap: 30px;
    }

    .vu-waveform .vu-meter {
        width: 80px;
        height: 40px;
    }

    /* Mobile Spectrum Style */
    .vu-spectrum .vu-meters {
        width: 100%;
        gap: 30px;
    }

    .vu-spectrum .vu-meter {
        width: 80px;
        height: 40px;
    }

    .vu-spectrum .spectrum-container {
        align-items: flex-end;
    }

    .vu-spectrum .spectrum-bar {
        width: 4px;
    }

    /* Mobile Retro Style */
    .vu-retro .vu-meters {
        width: 100%;
        gap: 30px;
        justify-content: center;
    }

    .vu-retro .vu-meter {
        width: 50px;
        height: 50px;
    }

    .vu-retro .retro-scale {
        font-size: 5px;
    }

    .vu-retro .retro-needle {
        height: 20px;
    }

    .station-selector label,
    .volume-control label {
        font-size: 1em;
    }

    .now-playing {
        font-size: 1em;
    }

    .vu-style-btn {
        top: -10px;
        right: -10px;
        width: 24px;
        height: 24px;
        font-size: 12px;
    }
}

/* Dark theme adjustments for VU meters */
.dark-theme .waveform-canvas {
    filter: brightness(1.2);
}

.dark-theme .retro-vu {
    background: radial-gradient(circle, var(--console-bg) 60%, var(--border-color) 100%);
}

.dark-theme .led-segment {
    box-shadow: 0 0 2px currentColor;
}

.dark-theme .spectrum-bar {
    box-shadow: 0 0 1px currentColor;
}

/* Animation enhancements */
.vu-meter {
    transition: all 0.3s ease;
}

.vu-style-btn {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
    50% { box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4); }
    100% { box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
}

/* Hover effects */
.vu-meters:hover .vu-style-btn {
    opacity: 1;
    transform: scale(1.1);
}

.vu-circular svg:hover .circular-level {
    stroke-width: 10;
}

.vu-retro .retro-vu:hover .retro-needle::after {
    box-shadow: 0 0 4px var(--primary-color);
}

/* Accessibility: Focus States */

/* Add a visible outline for keyboard users */
.console-btn:focus-visible,
.theme-btn:focus-visible,
.vu-style-btn:focus-visible,
.station-selector select:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* For range inputs, it's better to style the thumb */
.volume-control input[type="range"]:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 3px var(--bg-color), 0 0 0 5px var(--primary-color);
}

.volume-control input[type="range"]:focus-visible::-moz-range-thumb {
    box-shadow: 0 0 0 3px var(--bg-color), 0 0 0 5px var(--primary-color);
}
