:root {
    --primary: #D0BCFF;
    --on-primary: #381E72;
    --primary-container: #4F378B;
    --on-primary-container: #EADDFF;
    --surface: #141218;
    --surface-container: #1D1B20;
    --surface-container-high: #2B2930;
    --surface-variant: #49454F; 
    --on-surface-variant: #CAC4D0;
    --on-surface: #E6E1E5;
    --outline: #938F99;
    --outline-variant: #49454F;
    --error: #F2B8B5;
    --ease-emphasized: cubic-bezier(0.2, 0.0, 0.0, 1.0);
    --ease-standard: cubic-bezier(0.2, 0.0, 0, 1.0);
    --ease-in-out: cubic-bezier(0.4, 0.0, 0.2, 1);
    --safe-area-bottom: env(safe-area-inset-bottom, 20px);
    --safe-area-top: env(safe-area-inset-top, 24px);
    --player-width-desktop: 420px;
}

* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; -webkit-tap-highlight-color: transparent; font-family: 'DM Sans', sans-serif; }
html, body { height: 100%; width: 100%; background-color: var(--surface); color: var(--on-surface); overflow: hidden; overscroll-behavior: none; }
.hidden { display: none !important; }

.ripple-surface {
    position: absolute; border-radius: 50%; transform: scale(0);
    animation: ripple 600ms linear; background-color: rgba(255, 255, 255, 0.1);
    pointer-events: none;
}
@keyframes ripple { to { transform: scale(4); opacity: 0; } }

.m3-icon-btn {
    position: relative; background: transparent; border: none;
    color: var(--on-surface-variant); width: 48px; height: 48px;
    border-radius: 50%; cursor: pointer; display: flex;
    align-items: center; justify-content: center; overflow: hidden; z-index: 10;
    transition: background 0.2s, color 0.2s;
}
.m3-icon-btn:hover { background: rgba(255,255,255,0.05); color: var(--on-surface); }
.m3-icon-btn.active { color: var(--primary); background: rgba(208, 188, 255, 0.1); }
.m3-icon-btn span { font-size: 24px; }

.m3-backdrop {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); opacity: 0; pointer-events: none;
    transition: opacity 0.4s var(--ease-in-out); z-index: 190;
    backdrop-filter: blur(4px);
}
.m3-backdrop.visible { opacity: 1; pointer-events: auto; }

.m3-sheet {
    position: fixed; bottom: 0; left: 0; right: 0; width: 100%;
    background: var(--surface-container-high);
    border-radius: 28px 28px 0 0; padding-bottom: var(--safe-area-bottom);
    z-index: 200; 
    transform: translateY(100%);
    opacity: 1;
    transition: transform 0.5s var(--ease-emphasized);
    max-height: 90vh; display: flex; flex-direction: column;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.4);
}

.m3-sheet.open { transform: translateY(0); }
.m3-sheet.dragging { transition: none; }

.m3-drag-handle {
    width: 100%; height: 32px; display: flex;
    justify-content: center; align-items: center; flex-shrink: 0;
    touch-action: none; cursor: grab; opacity: 0.8;
}
.m3-drag-handle::after {
    content: ''; width: 32px; height: 4px; background: var(--outline);
    border-radius: 2px; opacity: 0.4;
}

.m3-sheet-header { padding: 0 24px 12px 24px; display: flex; justify-content: space-between; align-items: center; }
.m3-sheet-header h3 { font-size: 1.3rem; font-family: 'Space Grotesk'; margin: 0; color: var(--on-surface); }
.m3-sheet-content { overflow-y: auto; padding: 0 16px 16px 16px; display: flex; flex-direction: column; gap: 12px; }

.m3-fullscreen {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--surface); z-index: 150; display: flex; flex-direction: column;
    transform: translateY(100%); 
    transition: transform 0.5s var(--ease-emphasized), width 0.5s var(--ease-emphasized), left 0.5s var(--ease-emphasized);
    will-change: transform;
}
.m3-fullscreen.open { transform: translateY(0); }
.m3-fullscreen.dragging { transition: none; }

.m3-list-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; background: transparent; border-radius: 16px;
    cursor: pointer; transition: background 0.2s;
}
.m3-list-item:hover { background: rgba(255,255,255,0.03); }
.m3-list-text { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow: hidden; }
.m3-list-title { font-size: 1rem; font-weight: 400; color: var(--on-surface); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m3-list-sub { font-size: 0.875rem; color: var(--on-surface-variant); }

.m3-switch { display: inline-block; width: 52px; height: 32px; position: relative; cursor: pointer; flex-shrink: 0; }
.m3-switch input { opacity: 0; width: 0; height: 0; }
.m3-switch-track {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--surface-variant); border-radius: 32px;
    border: 2px solid var(--outline); transition: .2s;
    overflow: hidden;
}
.m3-switch-thumb {
    position: absolute; height: 16px; width: 16px; left: 6px; bottom: 6px;
    background-color: var(--outline); border-radius: 50%; transition: .2s var(--ease-emphasized);
}
input:checked + .m3-switch-track { background-color: var(--primary); border-color: var(--primary); }
input:checked + .m3-switch-track .m3-switch-thumb {
    transform: translateX(20px); background-color: var(--on-primary);
    width: 24px; height: 24px; bottom: 2px; left: 2px;
}

.m3-slider-container { width: 100%; padding: 12px 0; position: relative; display: flex; align-items: center; }
.m3-slider-input {
    -webkit-appearance: none; appearance: none; width: 100%; height: 44px;
    background: transparent; position: absolute; z-index: 2; margin: 0; cursor: pointer;
}
.m3-slider-track-bg {
    width: 100%; height: 4px; background: var(--surface-variant);
    border-radius: 2px; position: absolute; z-index: 1; pointer-events: none; opacity: 0.6;
}
.m3-slider-input::-webkit-slider-thumb {
    -webkit-appearance: none; width: 20px; height: 20px; background: var(--primary);
    border-radius: 50%; margin-top: -8px; box-shadow: 0 2px 5px rgba(0,0,0,0.3); border: none;
    transition: transform 0.1s;
}
.m3-slider-input::-webkit-slider-thumb:hover { transform: scale(1.2); }
.m3-slider-input::-webkit-slider-runnable-track { width: 100%; height: 4px; background: transparent; }

.m3-toast {
    position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%) translateY(20px);
    background: #333; color: #fff; padding: 12px 24px; border-radius: 30px;
    opacity: 0; pointer-events: none; transition: 0.4s var(--ease-emphasized); z-index: 300;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3); text-align: center; font-size: 0.9rem; white-space: nowrap;
}
.m3-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background-color: var(--surface-variant); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background-color: var(--outline); }
* { scrollbar-width: thin; scrollbar-color: var(--surface-variant) transparent; }

@media (min-width: 960px) {
    .m3-backdrop { z-index: 150; } 

    .m3-fullscreen {
        top: 0; left: auto; right: 0;
        width: var(--player-width-desktop); height: 100vh;
        transform: translateY(0) !important;
        border-left: 1px solid rgba(255,255,255,0.08);
        background: var(--surface-container);
        z-index: 100; border-radius: 0 !important;
    }
    
    .m3-drag-handle { display: none; }
    
    .m3-sheet {
        position: fixed; top: 50%; left: 50%; right: auto; bottom: auto;
        width: 450px; height: auto; max-height: 80vh;
        border-radius: 28px; padding-top: 24px; 
        transform: translate(-50%, -50%) scale(0.95);
        opacity: 0; pointer-events: none;
        box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    }

    .m3-sheet.open {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1; pointer-events: auto;
    }

    .m3-toast { bottom: 40px; }
}

.progress-container {
    width: 100%;
    margin-top: 20px;
    display: none;
    flex-direction: column;
    gap: 8px;
}
.progress-container.visible { display: flex; }

.progress-track {
    width: 100%;
    height: 6px;
    background: var(--surface-variant);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.progress-bar-indeterminate {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    background: var(--primary);
    width: 50%;
    animation: indeterminate 1.5s infinite ease-in-out;
    border-radius: 3px;
}

@keyframes indeterminate {
    0% { left: -50%; width: 50%; }
    50% { left: 25%; width: 50%; }
    100% { left: 100%; width: 50%; }
}

.status-text {
    font-size: 0.85rem;
    color: var(--primary);
    text-align: center;
    font-weight: 500;
}