/* --- Google Fonts (In HTML) --- */
/* font-family: 'Orbitron', sans-serif; */
/* font-family: 'Poppins', sans-serif; */

/* --- Variables --- */
:root {
    --bg-color: #1a1d24; /* Very dark blue/grey */
    --container-bg: rgba(35, 40, 55, 0.6); /* Semi-transparent darker blue */
    --container-border: rgba(100, 110, 140, 0.3);
    --glass-highlight: rgba(255, 255, 255, 0.05);
    --glass-shadow: rgba(0, 0, 0, 0.3);
    --text-primary: #e8e8ff; /* Slightly bluish white */
    --text-secondary: #9090aa;
    --text-accent: #ffffff;
    --control-bg: rgba(60, 65, 85, 0.7);
    --control-border: rgba(120, 130, 160, 0.4);
    --control-hover-bg: rgba(75, 80, 100, 0.8);
    --button-inactive-bg: linear-gradient(145deg, rgba(50, 55, 70, 0.7), rgba(40, 45, 60, 0.7));
    --button-inactive-shadow: inset 3px 3px 5px rgba(0,0,0,0.2), inset -3px -3px 5px rgba(255,255,255,0.05);
    --button-active-shadow: 2px 2px 4px rgba(0,0,0,0.3), -2px -2px 4px rgba(255,255,255,0.1);
    --glow-opacity: 0.7;

    /* Stem Colors (Brighter) */
    --vocals-color: #ff5f57; /* Bright Red/Coral */
    --drums-color: #ffee58;  /* Bright Yellow */
    --bass-color: #ae5eff;   /* Bright Purple */
    --instruments-color: #57ffae; /* Bright Teal/Green */
    --mix-color-1: #5773ff; /* Bright Blue */
    --mix-color-2: var(--bass-color);
}

/* --- Basic Reset & Body (Single Page Setup) --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%; /* Ensure html takes full height */
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh; /* Fallback for browsers not supporting dvh */
    min-height: 100dvh; /* Dynamic viewport height */
    height: 100%;     /* Use full dynamic height */
    line-height: 1.4;
    padding: 15px; /* Small padding around container */
    overflow: hidden; /* Prevent scrolling */
    /* No need for position: fixed if min-height is set correctly */
    width: 100%;
}

/* --- Main Player Container --- */
.stem-player-container {
    background: var(--container-bg);
    backdrop-filter: blur(12px) saturate(150%); /* Stronger glass effect */
    border: 1px solid var(--container-border);
    border-radius: 25px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.2), /* Base shadow */
                inset 0 1px 1px var(--glass-highlight), /* Inner highlight */
                inset 0 -1px 1px var(--glass-shadow); /* Inner shadow */
    padding: 20px; /* Slightly reduced base padding */
    width: 100%;
    max-width: 400px; /* Smaller max-width for phone-like aspect */
    /* REMOVED aspect-ratio */
    max-height: 95vh; /* Limit height to viewport height */
    max-height: 95dvh; /* Use dynamic viewport height */
    display: flex;
    flex-direction: column;
    justify-content: space-between; /* Keep header/footer apart */
    position: relative;
    transition: box-shadow 0.4s ease;
    overflow-y: auto; /* Allow internal scroll ONLY if content exceeds max-height */
    /* Optional: Add subtle scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: var(--text-secondary) transparent;
}

/* --- Header --- */
.player-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px; /* Reduced */
    padding: 0 5px;
    flex-shrink: 0; /* Prevent header from shrinking */
}

.logo {
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-accent);
    letter-spacing: 1px;
    opacity: 0.8;
}

/* Loading Indicator (Dots) */
.loading { display: flex; align-items: center; gap: 4px; }
.loading span {
    width: 8px; height: 8px; background-color: var(--text-secondary);
    border-radius: 50%; animation: loading-bounce 1s infinite ease-in-out;
}
.loading span:nth-child(1) { animation-delay: -0.32s; }
.loading span:nth-child(2) { animation-delay: -0.16s; }
@keyframes loading-bounce {
    0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1.0); }
}

/* --- Song Selector --- */
.song-selector {
    margin-bottom: 15px; /* Reduced */
    flex-shrink: 0; /* Prevent shrinking */
}

#song-select {
    width: 100%;
    padding: 10px 15px; /* Adjusted */
    border: 1px solid var(--control-border);
    border-radius: 10px;
    font-size: 0.9rem; /* Adjusted */
    font-weight: 400;
    background-color: var(--control-bg);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%239090aa%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E');
    background-repeat: no-repeat;
    background-position: right 15px top 50%;
    background-size: 10px auto;
    padding-right: 40px;
}
#song-select:hover { border-color: #7a8ab0; }
#song-select:focus {
    outline: none;
    border-color: var(--mix-color-1);
    box-shadow: 0 0 0 2px rgba(87, 115, 255, 0.4);
}

/* --- Core Controls Area --- */
#controls {
    flex-grow: 1; /* Allow this area to take up remaining vertical space */
    display: flex;
    flex-direction: column;
    justify-content: center; /* Center items within this growing space */
    align-items: center; /* Center horizontally */
    opacity: 1;
    transition: opacity 0.4s ease, filter 0.4s ease;
    margin-bottom: 15px; /* Reduced */
    min-height: 0; /* Allow flex item to shrink properly */
    width: 100%; /* Ensure it spans width */
}

#controls.controls-disabled {
    opacity: 0.5;
    pointer-events: none;
    filter: grayscale(60%);
}

/* --- Visualizer --- */
.visualizer-container {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    height: 40px; /* Base height */
    margin-bottom: 20px; /* Reduced */
    gap: 4px;
    transition: opacity 0.3s ease;
    opacity: 0.4;
    width: clamp(150px, 70%, 250px); /* Responsive width */
    margin-left: auto;
    margin-right: auto;
    flex-shrink: 0; /* Don't let it shrink */
}

body.playing .visualizer-container { opacity: 0.9; }

.visualizer-container .bar {
    width: clamp(3px, 1.5vw, 5px); /* Responsive width */
    background: linear-gradient(to top, var(--mix-color-1), var(--mix-color-2), var(--instruments-color));
    border-radius: 2px 2px 0 0;
    height: 5%;
    animation: visualizer-pulse 1.1s ease-in-out infinite alternate;
    transform-origin: bottom;
}
/* Stagger animation delays (More bars) */
.visualizer-container .bar:nth-child(4n+1) { animation-delay: -0.7s; }
.visualizer-container .bar:nth-child(4n+2) { animation-delay: -0.5s; }
.visualizer-container .bar:nth-child(4n+3) { animation-delay: -0.3s; }
.visualizer-container .bar:nth-child(4n+4) { animation-delay: -0.5s; }

@keyframes visualizer-pulse {
    0%, 100% { height: 5%; opacity: 0.3; }
    50% { height: 100%; opacity: 1; }
}

body:not(.playing) .visualizer-container .bar {
    animation-play-state: paused; height: 5%; opacity: 0.3;
}

/* --- Stem Buttons (Grid) --- */
.stem-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px; /* Base gap */
    margin-bottom: 20px; /* Reduced */
    width: 100%;
    max-width: 280px; /* Limit max width of button grid */
    flex-shrink: 0;
}

.stem-buttons button {
    aspect-ratio: 1 / 1;
    font-size: clamp(0.6rem, 2.5vh, 0.75rem); /* Responsive font size */
    font-weight: 600;
    letter-spacing: 0.5px;
    border: none;
    border-radius: 18px;
    cursor: pointer;
    background: var(--button-inactive-bg);
    color: var(--text-secondary);
    box-shadow: var(--button-inactive-shadow);
    transition: all 0.15s ease-out;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-transform: uppercase;
    padding: 5px; /* Add some padding */
}
.stem-buttons button .shortcut { display: block; font-size: 0.8em; opacity: 0.6; margin-top: 3px;}
.stem-buttons button:hover:not([disabled]):not(.active) {
    background: linear-gradient(145deg, rgba(60, 65, 80, 0.8), rgba(50, 55, 70, 0.8));
    color: var(--text-primary);
    transform: scale(1.02);
}
.stem-buttons button:active:not([disabled]) {
    transform: scale(0.96);
    box-shadow: inset 4px 4px 6px rgba(0,0,0,0.3), inset -4px -4px 6px rgba(255,255,255,0.08);
}
.stem-buttons button[disabled] { cursor: not-allowed; opacity: 0.5; }
.stem-buttons button.active {
    color: var(--text-accent);
    font-weight: 700;
    transform: scale(1.01);
    box-shadow: var(--button-active-shadow),
                0 0 15px var(--glow-color, #fff),
                0 0 8px var(--glow-color, #fff) inset;
    background: var(--active-bg-color, #555);
}
#vocals-btn.active { --glow-color: var(--vocals-color); --active-bg-color: var(--vocals-color); }
#drums-btn.active { --glow-color: var(--drums-color); --active-bg-color: var(--drums-color); color: #222; }
#bass-btn.active { --glow-color: var(--bass-color); --active-bg-color: var(--bass-color); }
#instruments-btn.active { --glow-color: var(--instruments-color); --active-bg-color: var(--instruments-color); color: #222; }

/* --- Full Mix Button --- */
.mix-button {
    display: flex;
    justify-content: center;
    margin-top: -5px; /* Pull slightly closer to grid */
    flex-shrink: 0;
}

#full-mix-btn {
    width: clamp(55px, 15vh, 70px); /* Responsive size */
    height: clamp(55px, 15vh, 70px); /* Responsive size */
    font-size: clamp(0.7rem, 2vh, 0.8rem); /* Responsive font size */
    font-weight: 700;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    background: linear-gradient(145deg, var(--mix-color-1), var(--mix-color-2));
    color: var(--text-accent);
    transition: all 0.2s ease;
    box-shadow: 5px 5px 10px rgba(0,0,0,0.3), -5px -5px 10px rgba(255,255,255,0.08);
    letter-spacing: 0.5px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-transform: uppercase;
}
#full-mix-btn .shortcut { display: block; font-size: 0.8em; opacity: 0.6; }
#full-mix-btn:hover:not([disabled]) {
    transform: scale(1.05);
    box-shadow: 8px 8px 15px rgba(0,0,0,0.35), -8px -8px 15px rgba(255,255,255,0.1),
                0 0 20px color-mix(in srgb, var(--mix-color-1) 60%, var(--mix-color-2) 40%);
}
#full-mix-btn:active:not([disabled]) {
    transform: scale(0.95);
     box-shadow: inset 4px 4px 8px rgba(0,0,0,0.3), inset -4px -4px 8px rgba(255,255,255,0.1);
}
#full-mix-btn[disabled] {
    cursor: not-allowed; opacity: 0.5;
    background: #444;
    box-shadow: var(--button-inactive-shadow);
}


/* --- Footer --- */
.player-footer {
    margin-top: 10px; /* Reduced */
    font-size: 0.8rem; /* Base size */
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    padding: 8px 10px 5px 10px; /* Adjusted padding */
    border-top: 1px solid var(--container-border);
    flex-shrink: 0; /* Prevent shrinking */
}

#current-time {
    font-family: 'Orbitron', sans-serif; /* Digital clock font */
    font-weight: 700;
    color: var(--text-primary);
}

/* --- Error Message --- */
.error {
    color: var(--vocals-color); /* Use stem color */
    background-color: rgba(255, 95, 87, 0.1);
    padding: 8px 10px; /* Reduced padding */
    border-radius: 8px;
    border: 1px solid rgba(255, 95, 87, 0.4);
    font-weight: 400;
    font-size: 0.85rem; /* Adjusted */
    text-align: center;
    position: absolute;
    bottom: 45px; /* Position above footer+credit */
    left: 15px;
    right: 15px;
    z-index: 10;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    /* Initially hide it better */
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}
.error:not([style*="display: none"]) { /* Show when not hidden by JS */
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}


/* --- Made By Credit --- */
.made-by-credit {
    font-size: 0.65rem; /* Base size */
    color: var(--text-secondary);
    text-align: center;
    width: 100%;
    padding-bottom: 5px; /* Space from bottom edge */
    opacity: 0.6;
    pointer-events: none;
    flex-shrink: 0; /* Prevent shrinking */
     /* Position relative to flow */
    margin-top: 5px; /* Space above */
}

.made-by-credit .heart {
    color: var(--vocals-color);
    display: inline-block;
    font-size: 0.75rem;
}


/* --- Height-Based Responsive Adjustments --- */
@media (max-height: 700px) {
    .stem-player-container { padding: 15px; border-radius: 20px; }
    .logo { font-size: 1rem; }
    #song-select { padding: 9px 15px; font-size: 0.85rem; padding-right: 35px; } /* Added padding-right */
    .visualizer-container { height: 35px; margin-bottom: 15px; }
    .stem-buttons { gap: 12px; margin-bottom: 15px; max-width: 260px;}
    #controls { margin-bottom: 10px; }
    .player-footer { font-size: 0.75rem; margin-top: 8px; padding-top: 8px; }
    .error { bottom: 40px; font-size: 0.8rem;}
    .made-by-credit { font-size: 0.6rem; }
}

@media (max-height: 600px) {
     :root { /* Smaller base sizes */
        --button-inactive-shadow: inset 2px 2px 4px rgba(0,0,0,0.2), inset -2px -2px 4px rgba(255,255,255,0.05);
        --button-active-shadow: 1px 1px 3px rgba(0,0,0,0.3), -1px -1px 3px rgba(255,255,255,0.1);
    }
    .stem-player-container { padding: 12px; border-radius: 18px; }
    .logo { display: none; } /* Hide logo */
    .player-header { margin-bottom: 8px; justify-content: flex-end; /* Move loading indicator right */}
    #song-select { padding: 8px 12px; padding-right: 35px; font-size: 0.8rem;} /* Adjusted padding */
    .visualizer-container { height: 30px; margin-bottom: 12px; }
    .stem-buttons { gap: 10px; margin-bottom: 12px; max-width: 240px; }
    .stem-buttons button { border-radius: 15px; }
    .mix-button { margin-top: 0; }
    .player-footer { margin-top: 5px; padding-top: 6px; }
    .error { bottom: 35px; }
    .made-by-credit { display: none; } /* Hide credit on very short screens */
}

/* Optional: Further refinements for very narrow/wide but short screens */
@media (max-height: 600px) and (max-width: 350px) {
    .stem-player-container { padding: 10px; }
    .stem-buttons { gap: 8px; }
}

/* Ensure the credit line respects footer padding */
.player-footer {
    padding-bottom: 5px; /* Adjust space above credit */
}
/* Ensure error message is above footer+credit */
.error {
    /* Adjust 'bottom' based on final footer/credit height on different screens */
    /* Base value already set, potentially adjust in media queries if needed */
}