:root {
    /* Colors */
    --player-bg: rgba(0, 0, 0, 0.5);
    --player-accent: #777AFF;
    --player-text: #FFF;
    --overlay-bg: rgba(0, 0, 0, 0.6);

    /* Progress Bar Theme Defaults */
    --progress-track-bg: #1B1C3A;
    --progress-track-shadow: 170, 170, 255;
    --progress-fill-top: #cccde7;
    --progress-fill-mid1: #6667b6;
    --progress-fill-mid2: #4b4c9f;
    --progress-fill-bottom: #a8a9d6;

    /* Dimensions & Scaling */
    --player-width: 350px;
    --player-scale: 1.25;
    --player-bottom: 20px;
    --player-left: 20px;
    --collapsed-offset: -480px;
    --btn-size: 34px;
    --progress-width: 225px;
    --cover-size: 111px;

    /* Visuals */
    --border-radius: 10px;
    --blur-amount: 7px;
    --transition-speed: 0.3s;

    /* Fonts */
    --font-main: "zpix";
    --font-icon: "icon";
}

[data-theme="dark"] {
    --progress-track-bg: #000;
    --progress-track-shadow: 0, 0, 0;
    --progress-fill-top: #D0D0D0;
    --progress-fill-mid1: #707070;
    --progress-fill-mid2: #555;
    --progress-fill-bottom: #AEAEAE;
}
[data-theme="orange"] {
    --progress-track-bg: #3E2900;
    --progress-track-shadow: 255, 170, 0;
    --progress-fill-top: #FFE0A1;
    --progress-fill-mid1: #E09500;
    --progress-fill-mid2: #AA7100;
    --progress-fill-bottom: #FFC95D;
}
[data-theme="pink"] {
    --progress-track-bg: #75003E;
    --progress-track-shadow: 250, 124, 198;
    --progress-fill-top: #FFF;
    --progress-fill-mid1: #FACCE7;
    --progress-fill-mid2: #FA7CC6;
    --progress-fill-bottom: #FFF;
}
[data-theme="4chan"] {
    --progress-track-bg: #FED6AF;
    --progress-track-shadow: 221, 0, 0;
    --progress-fill-top: #EEAA88;
    --progress-fill-mid1: #DD0000;
    --progress-fill-mid2: #AA0000;
    --progress-fill-bottom: #FFCCCC;
}
[data-theme="shimeji"] {
    --progress-track-bg: #000;
    --progress-track-shadow: 0, 0, 0;
    --progress-fill-top: #FFF;
    --progress-fill-mid1: #FFF;
    --progress-fill-mid2: #FFF;
    --progress-fill-bottom: #FFF;
}

/* Base Container */
#musicPlayer {
    position: fixed;
    bottom: var(--player-bottom);
    left: var(--player-left);
    z-index: 999;
    line-height: 1.0 !important;
    color: var(--player-text);
    font-family: var(--font-main) !important;
    transform: scale(var(--player-scale));
    transform-origin: bottom left;
    transition: transform var(--transition-speed) ease;
    user-select: none;

}

#musicPlayer.collapsed {
    transform: translateX(var(--collapsed-offset)) scale(var(--player-scale));
}

/* Main Box */
#playerMain {
    display: flex;
    align-items: center;
    background: var(--player-bg);
    padding: 12px;
    width: var(--player-width);
    border-radius: var(--border-radius);
    backdrop-filter: blur(var(--blur-amount));
    -webkit-backdrop-filter: blur(var(--blur-amount));
    corner-shape: bevel;
    box-shadow: 0 0 10px #000;
}

/* Toggle Arrow */
#playerToggle {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    font-family: var(--font-main) !important;
    padding: 40px 7px;
    background: var(--player-bg);
    border-radius: 0 30px 30px 0;
    backdrop-filter: blur(var(--blur-amount));
    font-size: 20px;
    cursor: pointer;
    corner-shape: bevel;
    
    box-shadow: 5px 0 15px rgba(0, 0, 0, 0.4); 
    border-left: none;

    -webkit-text-stroke-width: 3px;
    -webkit-text-stroke-color: #000;
    paint-order: stroke fill;
}

/* Song Information */
#playerText {
    overflow: hidden;
    flex-grow: 1;
    -webkit-text-stroke-color: #000;
    paint-order: stroke fill;
}

#playerText::selection {
    -webkit-text-stroke-color: #fff;
}

#songTitle {
    -webkit-text-stroke-width: 3px;
    font-family: var(--font-main);
    font-size: 17px;
    padding: 0 2px;
    user-select: text;
}

#songArtist {
    padding: 0 2px;
}

#songArtist, .time {
    -webkit-text-stroke-width: 2.5px;
    font-family: var(--font-main);
    font-size: 12px;
    padding: 0 2px;
    margin-top: 5px;
    user-select: text;
}

.time {
    user-select: none;
}

#songInfo {
    -webkit-text-stroke-width: 2.5px;
    display: flex;
    justify-content: space-between; /* Pushes left to start, right to end */
    align-items: center;
    width: var(--progress-width);
    margin-top: 4px;
    padding-bottom: 5px;
    height: 14px; 
}

#songInfo > span {
    flex: 1;
}

#playbackRate, #trackDisplay {
    cursor: pointer;
    display: inline-block;
    user-select: none;
    opacity: 0.5;
    transition: opacity 0.5s ease;
}

#playbackRate:is(:hover, :focus, :active),
#trackDisplay:is(:hover, :focus, :active) {
	opacity: 1;
}

#playbackRate {
    padding: 0 2px; /* fix left cutoff */
    text-align: left;
}

#trackDisplay {
    text-align: right;
}

#trackDisplay::before,
#playbackRate::before {
    content: "(";
}

#trackDisplay::after {
    content: "/" var(--total-tracks, "0") ")";
}

#playbackRate::after {
    content: "x)";
}

/* Visual cue when editing */
#playbackRate[contenteditable="true"],
#trackDisplay[contenteditable="true"] {
    outline: none;
    user-select: text;
}

/* Cover Art Section */
#coverWrap {
    position: relative;
    width: var(--cover-size);
    height: var(--cover-size);
    margin-left: 10px;
    cursor: default;
    filter: drop-shadow(0 0 5px rgba(0,0,0,0.5));
    image-rendering: auto !important;
    display: block; 
    text-decoration: none; 
    color: inherit;
}

#coverWrap.hasLink {
    cursor: pointer;
}

#coverArt {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    border-radius: 15px;
    corner-shape: squircle;
}

#coverArt.pixelated {
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#coverArt[src*="loading.png"] {
    image-rendering: auto !important;
}

#coverOverlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--overlay-bg);
    font-family: var(--font-icon);
    text-shadow: 0 0 10px #000;
    font-size: 40px;
    opacity: 0;
    transition: opacity 0.2s ease;
    border-radius: 15px;
    corner-shape: squircle;
}

#coverWrap.hasLink:hover #coverOverlay {
    opacity: 1;
}

/* Progress Bar Track */
#progressBar {
    width: var(--progress-width);
    height: 7px;
    appearance: none;
    border-radius: 999px;
    outline: 1px inset #000;
    cursor: pointer;
    touch-action: pan-y;
    transition: height 0.3s ease, filter 0.3s ease, background 0.5s ease;
    box-shadow: 0 0 4px rgba(var(--progress-track-shadow), 0.3);

    background: 
        linear-gradient(to right, transparent var(--progress-percent, 0%), var(--progress-track-bg) var(--progress-percent, 0%)),
        linear-gradient(to bottom, rgba(255,255,255,0.3), rgba(255,255,255,0)),
        linear-gradient(to bottom, 
            var(--progress-fill-top) 0%, 
            var(--progress-fill-mid1) 30%, 
            var(--progress-fill-mid2) 71%, 
            var(--progress-fill-bottom) 100%
        );
}

#progressBar:hover, 
#progressBar:active {
    height: 10px;
    filter: brightness(1.2);
}

/* Progress Bar Thumbs (Webkit) */
#progressBar::-webkit-slider-thumb {
    appearance: none;
    width: 7px;
    height: 17px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.5);
    outline: 1px outset #000;
    box-shadow: 0 0 4px rgba(var(--progress-track-shadow), 0.6), inset 0 1px 1px rgba(255, 255, 255, 0.5);
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.2s ease, transform 0.2s ease, background 0.5s ease;

    background: linear-gradient(to bottom, 
        var(--progress-fill-top) 0%, 
        var(--progress-fill-mid1) 50%, 
        var(--progress-fill-mid2) 51%, 
        var(--progress-fill-bottom) 100%
    );
}

#progressBar:hover::-webkit-slider-thumb,
#progressBar:active::-webkit-slider-thumb {
    opacity: 1;
    transform: scale(1);
}

/* Progress Bar Thumbs (Firefox) */
#progressBar::-moz-range-thumb {
    width: 7px;
    height: 13px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.5);

    transition: width 0.3s ease, height 0.3s ease, background 0.5s ease;

    background: linear-gradient(to bottom, 
        var(--progress-fill-top) 0%, 
        var(--progress-fill-mid1) 50%, 
        var(--progress-fill-mid2) 51%, 
        var(--progress-fill-bottom) 100%
    );
}

#progressBar:hover::-moz-range-thumb {
    width: 13px;
    height: 27.5px;
}

/* Control Buttons */
#controls {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin: 8px auto 0 auto;
    
    /* Ensure flex gaps can blend smoothly during the shift */
    gap: 5px; 
    transition: gap 0.5s ease;
}

.playerbtns {
    /* Reset Button Defaults */
    appearance: none;
    padding: 0;
    margin: 0;
    outline: none;
    box-sizing: border-box;

    /* Consistency Styles */
    color: var(--player-text);
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--btn-size);
    height: var(--btn-size);
    background: var(--player-bg);
    border: 2px outset rgba(255, 255, 255, 0.5);
    border-radius: 5px;

    font-family: var(--font-icon);
    font-size: 32px;
    text-shadow: none;
    line-height: 1;
    cursor: pointer;
    opacity: 0.5;

    transition: 
        opacity 0.2s ease, 
        border 0.1s ease, 
        width 0.5s ease, 
        margin 0.5s ease, 
        padding 0.5s ease;
    
    /* Prevent text or SVG icon content from leaking out while collapsing */
    overflow: hidden;
}

#controls.shuffle-active #prevBtn {
    width: 0px;
    padding-left: 0px;
    padding-right: 0px;
    margin-left: 0px;
    margin-right: 0px;
    border-left-width: 0px;
    border-right-width: 0px;
    opacity: 0;
    pointer-events: none; /* Disables clicking while invisible */
}

/* half of #controls gap */
#controls.shuffle-active #prevBtn {
    margin-right: -2.5px; 
}
#controls.shuffle-active #playPauseBtn {
    margin-left: -2.5px;
}

/* ===== NEXT BUTTON CONTENT POSITIONING ===== */
#nextBtn {
    position: relative;
}

/* Layer both icons directly on top of each other */
#nextBtn .icon-txt,
#nextBtn .icon-svg {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease;
    pointer-events: none;
}

#nextBtn .icon-txt {
    font-family: var(--font-icon);
}

#nextBtn .icon-svg {
    width: 31px;
    margin: auto;
}

/* ===== DEFAULT STATE (Shuffle Off) ===== */
#nextBtn .icon-txt {
    opacity: 1;
}
#nextBtn .icon-svg {
    opacity: 0;
}

/* ===== ACTIVE SHUFFLE STATE (Cross-fade) ===== */
#controls.shuffle-active #nextBtn .icon-txt {
    opacity: 0;
}
#controls.shuffle-active #nextBtn .icon-svg {
    opacity: 1;
}

.playerbtns:hover {
    opacity: 1;
}

.playerbtns:active {
    border-style: inset;
    border-color: rgba(255, 255, 255, 0.5);
}

/* Scrolling Text Animation */
.textWrap {
    max-width: var(--progress-width);
    overflow: hidden;
    white-space: nowrap;
    position: relative;

    padding-bottom: 4px;
    height: 18px; 
    margin-bottom: -4px;
}

.scrollText {
    display: inline-block;
    white-space: nowrap;
    min-width: 100%;
    box-sizing: border-box;
}

.scrolling {
    animation: textPingPong linear infinite;
    animation-timing-function: ease-in-out;
    animation-duration: 10s; /* Default duration */
}

@keyframes textPingPong {
    0%, 8%, 92%, 100% { transform: translateX(0); }
    42%, 50% { transform: translateX(var(--scroll-distance, -50%)); }
}