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

body {
    margin: 0;
    overflow: hidden;
    background-color: #4a4a4a; /* Flat dark gray from reference */
    font-family: 'Inter', sans-serif;
    color: white;
}

#canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
}

#css2d-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 2;
    pointer-events: none;
}

/* UI Overlay */
#ui-container {
    position: absolute;
    top: 40px;
    left: 40px;
    z-index: 10;
    pointer-events: auto;
}

.back-link {
    color: #888;
    text-decoration: none;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
    display: block;
    transition: color 0.3s ease;
}

.back-link:hover {
    color: #fff;
}

h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 4px;
    letter-spacing: -0.5px;
}

p {
    font-size: 12px;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.7);
}

#playlist-container {
    position: absolute;
    bottom: 40px;
    right: 40px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: flex-end; /* Align to the right edge */
}

.track-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-end;
}

.track-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.5);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    text-align: left;
    transition: all 0.3s ease;
}

.track-btn:hover {
    border-color: rgba(255, 255, 255, 0.5);
    color: #fff;
}

.track-btn.active {
    border-color: #fff;
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.control-btn {
    margin-top: 16px;
    background: #ffffff;
    color: #000000;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: transform 0.2s ease, background 0.2s ease;
}

.control-btn:hover {
    transform: scale(1.05);
    background: #e0e0e0;
}

/* Data Labels (CSS2D) */
.node-label {
    color: rgba(255, 255, 255, 0.9);
    font-size: 8px; /* Base size, overridden by JS */
    font-family: 'Inter', sans-serif;
    font-weight: 400;
    pointer-events: none;
    text-shadow: none; /* Keep shadow off so it remains clean */
    opacity: 0;
    transition: opacity 0.3s ease;
    white-space: nowrap;
}

/* --- MOBILE RESPONSIVENESS --- */
@media (max-width: 768px) {
    #ui-container {
        top: 20px;
        left: 20px;
        right: 20px;
    }
    #ui-container h1 {
        font-size: 1.2rem;
        margin-bottom: 2px;
    }
    #ui-container p {
        font-size: 0.75rem;
    }
    .node-label {
        font-size: 8px;
    }
    
    /* Make playlist compact and horizontal on mobile */
    #playlist-container {
        bottom: 20px;
        right: 20px;
        left: 20px; /* Stretch across bottom */
        align-items: flex-end; /* Keep buttons pushed to right */
    }
    .track-list {
        flex-direction: row; /* Horizontal layout to save vertical height */
        gap: 6px;
        flex-wrap: wrap;
        justify-content: flex-end;
    }
    .track-btn {
        padding: 6px 10px;
        font-size: 11px;
    }
    .control-btn {
        margin-top: 8px;
        padding: 8px 16px;
        font-size: 12px;
    }
}

/* Spectral Legend */
#legend-container {
    position: absolute;
    bottom: 40px;
    left: 40px;
    z-index: 10;
    display: flex;
    align-items: flex-end;
    pointer-events: none;
}

.legend-title {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-size: 10px;
    letter-spacing: 3px;
    color: rgba(255, 255, 255, 0.8);
    margin-right: 12px;
    height: 300px;
    text-align: center;
}

.legend-gradient {
    width: 20px;
    height: 300px;
    /* Map from reference: Blue (bottom) -> Purple -> Red -> Yellow -> Green (top) */
    background: linear-gradient(to top, 
        #2B3FFF 0%,    /* Blue (0 KHz) */
        #8A2BE2 20%,   /* Purple (~0.7 KHz) */
        #FF3333 40%,   /* Red (~1.4 KHz) */
        #FF8C00 55%,   /* Orange (~1.9 KHz) */
        #FFD700 70%,   /* Yellow (~2.4 KHz) */
        #ADFF2F 85%,   /* Green-Yellow (~3.0 KHz) */
        #7FFF00 100%   /* Light Green (3.5 KHz) */
    );
    border-radius: 4px;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
    margin-right: 12px;
}

.legend-labels {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 300px;
    font-size: 9px;
    color: rgba(255, 255, 255, 0.8);
    text-align: left;
    padding: 2px 0;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    #ui-container {
        top: 20px;
        left: 20px;
        right: 20px;
        padding: 16px;
    }
    #legend-container {
        bottom: 20px;
        left: 20px;
        transform: scale(0.8);
        transform-origin: bottom left;
    }
    h1 {
        font-size: 18px;
    }
    p {
        font-size: 10px;
    }
    #start-button {
        padding: 12px 24px;
        font-size: 14px;
    }
}
