/* Ensure JavaScript-applied width styles take precedence */
.now-playing[style*="width"] {
    /* This selector ensures that when JavaScript applies inline width styles, they take precedence */
}

/* Reset and base styles - Enhanced for consistency */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Additional reset for better cross-browser consistency */
html {
    line-height: 1.15;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Arial', sans-serif;
    color: white;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent; /* Always transparent for embedding */
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Allow container to expand to full width when needed */
    width: 100%;
}

/* Scoped now-playing panel styles for consistency */
.now-playing {
    /* Reset any inherited styles */
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;

    /* Apply consistent box model */
    box-sizing: border-box;

    /* Core layout styles */
    backdrop-filter: blur(20px);
    border-radius: 24px;
    padding: 40px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: 1fr;
    align-items: center;
    gap: 40px;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.4),
        0 8px 32px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.15);
    /* Removed width: 100% to allow JavaScript containerWidth setting to work */
    max-width: none;
    min-height: 240px;
    animation: fadeIn 1s ease-in-out;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.now-playing::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        135deg,
        rgba(255, 255, 255, calc(0.1 * var(--glassmorphism-opacity, 1))) 0%,
        rgba(255, 255, 255, calc(0.05 * var(--glassmorphism-opacity, 1))) 100%
    );
    border-radius: 24px;
    pointer-events: none;
    z-index: 0;
    opacity: var(--glassmorphism-opacity, 1);
    transition: opacity 0.3s ease;
}

/* Hide glassmorphism effect when disabled */
.now-playing:not(.glassmorphism-enabled)::before {
    display: none;
}

.now-playing > * {
    position: relative;
    z-index: 1;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Album Cover */
.album-cover {
    flex-shrink: 0;
    position: relative;
}

.album-cover img {
    width: 180px;
    height: 180px;
    border-radius: 20px;
    object-fit: cover;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.5s ease-in-out;
    position: relative;
    z-index: 2;
}

/* Add smooth fade transition for image loading */
.album-cover img:not(.loaded) {
    opacity: 0;
    transform: scale(0.95);
}

.album-cover img.loaded {
    opacity: 1;
    transform: scale(1);
}

/* Smooth transition during image changes */
.album-cover img.changing {
    opacity: 0; /* Was 0.3, fully fade out before swapping */
    transform: scale(0.98);
}

.album-cover::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    background: linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.1),
        rgba(255, 255, 255, 0.05)
    );
    border-radius: 30px;
    z-index: 1;
    opacity: 0;
    transition: opacity 0.6s ease;
}

.album-cover:hover::before {
    opacity: 1;
}

.album-cover img:hover {
    transform: scale(1.05) rotateY(2deg);
    filter: brightness(1.1) saturate(1.1) contrast(1.05);
}

/* Track Content Wrapper */
.track-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
    flex: 1;
}

/* Bottom Row Wrapper */
.bottom-row {
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
}

/* Track Information */
.track-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    text-align: left;
    min-height: 140px;
    padding: 30px 0;
    min-width: 0;
    gap: 16px; /* Default gap, will be overridden by JavaScript */
}

/* Add smooth transitions for text content changes */
.track-title {
    font-size: 2.8rem;
    font-weight: 800;
    margin-bottom: 0;
    color: #ffffff;
    text-shadow:
        0 4px 12px rgba(0, 0, 0, 0.4),
        0 2px 6px rgba(0, 0, 0, 0.3);
    line-height: 1.2;
    word-wrap: break-word;
    hyphens: auto;
    max-width: 100%;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #ffffff 0%, #f0f0f0 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    /* Add smooth transitions for content changes */
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease-in-out;
}

/* Smooth transition states for track title */
.track-title.updating {
    opacity: 0;
    transform: translateY(-8px) scale(0.96); /* Added slight scale for smoother re-entry */
}

.artist-name {
    font-size: 1.6rem;
    color: #b8c5d6;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    line-height: 1.3;
    word-wrap: break-word;
    hyphens: auto;
    max-width: 100%;
    font-style: normal;
    /* Add smooth transitions for content changes */
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease-in-out;
}

/* Smooth transition states for artist name */
.artist-name.updating {
    opacity: 0;
    transform: translateY(-6px) scale(0.96); /* Added slight scale */
}

.artist-name-text {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease-in-out;
}

.artist-name-text.updating {
    opacity: 0;
    transform: translateY(-6px) scale(0.96); /* Sync scale with parent for stagger */
}

.track-duration {
    /* Styles will be applied dynamically via theme settings */
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 2.2em; /* Match admin preview exactly */
    white-space: nowrap;
    position: relative;
    overflow: visible; /* Allow text shadows to extend beyond container */
    font-variant-numeric: tabular-nums; /* Use tabular numbers for consistent width */
    padding: 20px; /* Add padding to accommodate text shadows */
}

.track-duration::before {
    display: none;
}

.track-duration .duration-content {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    font-weight: 600;
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums; /* Ensure consistent digit widths */
}

/* Fixed-width three-cell layout system (similar to clock character spacing) */
/* Only applies when .fixed-width class is present on parent */
/* Layout: [CURRENT (equal space)] [SEPARATOR (fixed, centered)] [TOTAL (equal space)] */
.track-duration.fixed-width .duration-content {
    display: grid !important;
    grid-template-columns: 1fr var(--duration-separator-width, 0.8em) 1fr !important; /* CURRENT and TOTAL get equal space, SEPARATOR is fixed */
    grid-template-rows: 1fr !important; /* Single row for horizontal layout */
    grid-auto-flow: column !important; /* Ensure items flow horizontally (left to right) */
    align-items: center;
    justify-items: stretch; /* Stretch items to fill their grid cells */
    width: 100%;
    gap: 0 !important; /* No gap between grid cells */
    /* Explicitly override any flex properties that might interfere */
    flex-direction: unset !important;
    flex-wrap: unset !important;
    /* Ensure grid is properly centered */
    place-items: center stretch;
}

.track-duration.fixed-width .duration-current {
    grid-column: 1; /* First column - equal space with TOTAL */
    grid-row: 1;
    width: 100%;
    min-width: 0; /* Allow grid to control sizing */
    display: flex !important;
    align-items: center;
    justify-content: flex-end; /* Right-align current time within its cell */
    overflow: visible; /* Changed from hidden to visible to prevent truncation */
    box-sizing: border-box;
    flex: none !important;
    /* Ensure cell fills its grid column */
    justify-self: stretch;
}

.track-duration.fixed-width .duration-separator-container {
    grid-column: 2; /* Second column - fixed width, always centered */
    grid-row: 1;
    width: 100%;
    min-width: 0; /* Allow grid to control sizing */
    display: flex !important;
    align-items: center;
    justify-content: center;
    text-align: center; /* Ensure text content is centered */
    box-sizing: border-box;
    /* Separator is always centered and never moves */
    flex: none !important;
    /* Ensure separator cell is centered in the grid */
    justify-self: center;
}

.track-duration.fixed-width .duration-total {
    grid-column: 3; /* Third column - equal space with CURRENT */
    grid-row: 1;
    width: 100%;
    min-width: 0; /* Allow grid to control sizing */
    display: flex !important;
    align-items: center;
    justify-content: flex-start; /* Left-align total time within its cell */
    overflow: visible; /* Changed from hidden to visible to prevent truncation */
    box-sizing: border-box;
    flex: none !important;
    /* Ensure cell fills its grid column */
    justify-self: stretch;
}

/* Normal mode - no fixed widths, use natural font rendering */
.duration-digit {
    display: inline-block;
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum"; /* Enable tabular numbers for consistent digit widths */
}

.duration-colon {
    display: inline-block;
    text-align: center;
}

/* Fixed-width character spans (created by wrapDurationCharacters) */
.duration-char {
    display: inline-block;
    text-align: center;
    vertical-align: middle; /* Center vertically to prevent vertical displacement */
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Remove any spacing between inline-block elements */
    font-size: inherit;
    line-height: 1; /* Use line-height of 1 to prevent vertical shifting */
    height: 1em; /* Fixed height to prevent vertical displacement */
}

.duration-number {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum"; /* Enable tabular numbers for consistent digit widths */
}

.duration-separator-container {
    display: inline-block;
    text-align: center !important;
}

/* Individual sections with precise control */
/* CRITICAL: Separator must ALWAYS be centered, even when fixed-width is off */
.track-duration:not(.fixed-width) .duration-content {
    display: grid !important;
    grid-template-columns: 1fr auto 1fr !important; /* Equal space for current/total, auto for separator */
    grid-template-rows: 1fr !important;
    align-items: center;
    width: 100%;
    gap: 0 !important;
}

.track-duration:not(.fixed-width) .duration-current {
    grid-column: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-width: 3.5em; /* Fixed minimum width for MM:SS */
}

.track-duration:not(.fixed-width) .duration-separator-container {
    grid-column: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: auto;
    flex: none !important;
    /* Separator is always centered and never moves */
}

.track-duration:not(.fixed-width) .duration-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 1em; /* Fixed width for separator */
}

.track-duration:not(.fixed-width) .duration-total {
    grid-column: 3;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    min-width: 3.5em; /* Fixed minimum width for MM:SS */
}

/* Sophisticated animation classes */
.track-info-element {
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
}

.track-info-element.updating {
    opacity: 0.6;
    transform: translateY(5px) scale(0.98);
    filter: blur(1px);
}

.track-info-element.updated {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
}

.album-cover {
    transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
    cursor: pointer;
}

.album-cover:hover {
    transform: scale(1.05) rotateY(5deg);
    filter: brightness(1.1) saturate(1.1);
}

.album-cover.loading {
    opacity: 0.6;
    transform: scale(0.9) rotateY(15deg);
    filter: blur(3px) brightness(1.2) saturate(1.3);
    animation: coverLoading 1.2s ease-in-out infinite alternate;
}

.album-cover.loaded {
    opacity: 1;
    transform: scale(1) rotateY(0deg);
    filter: blur(0) brightness(1) saturate(1);
    animation: coverLoaded 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.duration-updating {
    opacity: 0.6;
    transform: scale(0.95) translateY(-2px);
    filter: blur(1px);
}

.duration-updated {
    opacity: 1;
    transform: scale(1) translateY(0);
    filter: blur(0);
}

/* Beautiful keyframe animations */
@keyframes slideInFromLeft {
    0% {
        opacity: 0;
        transform: translateX(-30px) scale(0.9);
        filter: blur(3px);
    }
    50% {
        opacity: 0.8;
        transform: translateX(-10px) scale(0.95);
        filter: blur(1px);
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
        filter: blur(0);
    }
}

@keyframes slideInFromRight {
    0% {
        opacity: 0;
        transform: translateX(30px) scale(0.9);
        filter: blur(3px);
    }
    50% {
        opacity: 0.8;
        transform: translateX(10px) scale(0.95);
        filter: blur(1px);
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
        filter: blur(0);
    }
}

@keyframes slideInFromBottom {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.9);
        filter: blur(2px);
    }
    50% {
        opacity: 0.8;
        transform: translateY(5px) scale(0.95);
        filter: blur(1px);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

@keyframes gentlePulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

@keyframes float {
    0%,
    100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-5px);
    }
}

@keyframes coverLoading {
    0% {
        transform: scale(0.9) rotateY(15deg) rotateX(5deg);
        filter: blur(3px) brightness(1.2) saturate(1.3) hue-rotate(10deg);
    }
    50% {
        transform: scale(0.95) rotateY(8deg) rotateX(2deg);
        filter: blur(2px) brightness(1.1) saturate(1.1) hue-rotate(5deg);
    }
    100% {
        transform: scale(0.9) rotateY(15deg) rotateX(5deg);
        filter: blur(3px) brightness(1.2) saturate(1.3) hue-rotate(10deg);
    }
}

@keyframes coverLoaded {
    0% {
        opacity: 0.6;
        transform: scale(0.9) rotateY(15deg) rotateX(5deg);
        filter: blur(3px) brightness(1.2) saturate(1.3);
    }
    30% {
        opacity: 0.8;
        transform: scale(1.05) rotateY(5deg) rotateX(2deg);
        filter: blur(1px) brightness(1.1) saturate(1.1);
    }
    60% {
        opacity: 0.95;
        transform: scale(0.98) rotateY(2deg) rotateX(1deg);
        filter: blur(0.5px) brightness(1.05) saturate(1.05);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotateY(0deg) rotateX(0deg);
        filter: blur(0) brightness(1) saturate(1);
    }
}

/* Animation control classes */
.no-animations * {
    animation: none !important;
    transition: none !important;
}

.no-hover *:hover {
    transform: none !important;
    filter: none !important;
    box-shadow: none !important;
}

/* Animation classes */
.slide-in-left {
    animation: slideInFromLeft 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.slide-in-right {
    animation: slideInFromRight 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.slide-in-bottom {
    animation: slideInFromBottom 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.gentle-pulse {
    animation: gentlePulse 2s ease-in-out infinite;
}

.shimmer {
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.2),
        transparent
    );
    background-size: 200% 100%;
    animation: shimmer 2s infinite;
}

.float {
    animation: float 3s ease-in-out infinite;
}

/* Loading state */
.now-playing.loading .track-title,
.now-playing.loading .artist-name {
    color: #888;
}

/* Responsive design */

@media (max-width: 768px) {
    .now-playing {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        text-align: center;
        gap: 30px;
        padding: 30px;
        min-height: auto;
    }

    .album-cover {
        grid-column: 1;
        grid-row: 1;
        justify-self: center;
    }

    .album-cover img {
        width: 160px;
        height: 160px;
    }

    .track-info {
        grid-column: 1;
        grid-row: 2;
        align-items: center;
        text-align: center;
        min-height: auto;
        padding: 20px 0;
    }

    .track-title {
        font-size: 2.4rem;
    }

    .artist-name {
        font-size: 1.4rem;
    }

    .artist-name .by-text {
        /* Styles will be applied dynamically via theme settings */
    }

    .track-duration {
        grid-column: 1;
        grid-row: 3;
        justify-self: center;
        /* Styles will be applied dynamically via theme settings */
        height: 60px;
        min-width: 120px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 15px;
    }

    .now-playing {
        padding: 25px;
        /* Removed width: 95% to allow JavaScript containerWidth setting to work in mobile */
        gap: 25px;
    }

    .album-cover img {
        width: 140px;
        height: 140px;
    }

    .track-title {
        font-size: 2rem;
    }

    .artist-name {
        font-size: 1.3rem;
    }

    .artist-name .by-text {
        /* Styles will be applied dynamically via theme settings */
    }

    .track-duration {
        /* Styles will be applied dynamically via theme settings */
        height: 55px;
        white-space: nowrap;
        display: flex;
        align-items: center;
        /* Width will be set dynamically by JavaScript */
    }

    .track-duration .duration-current {
        text-align: right;
        width: 45%;
    }

    .track-duration .duration-separator {
        text-align: center;
        width: 10%;
    }

    .track-duration .duration-total {
        text-align: left;
        width: 45%;
    }
}

/* Embed-specific styles */
.embed-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    padding: 10px;
}

/* Preview Styles */
.preview-now-playing {
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 30px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: 1fr;
    align-items: center;
    gap: 30px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 100%;
    max-width: none;
    min-height: 200px;
}

.preview-cover {
    width: 120px;
    height: 120px;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

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

.preview-bottom-row {
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
}

.preview-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    text-align: left;
    min-height: 120px;
    padding: 20px 0;
    min-width: 0;
}

.preview-title {
    font-size: 2.4rem;
    font-weight: 700;
    margin-bottom: 8px;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}

.preview-artist {
    font-size: 1.6rem;
    font-weight: 500;
    opacity: 0.9;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}

.preview-duration {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 600;
    padding: 12px 16px;
    border-radius: 15px;
    background: var(--duration-background, rgba(255, 255, 255, 0.1)) !important;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    min-width: 0;
    max-width: 300px;
    width: fit-content;
}

/* Compact mode for embedded contexts */
.compact .now-playing {
    padding: 15px;
    gap: 15px;
    min-height: 100px;
}

/* Full coverage mode - remove external margins, keep internal spacing */
.full-coverage .container {
    padding: 0 !important;
    margin: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
}

.full-coverage .now-playing {
    margin: 0 !important;
    border-radius: 0 !important;
    width: 100vw !important;
    min-height: 100vh !important;
    box-shadow: none !important;
    /* Keep internal padding and gap for content spacing */
}

.compact .album-cover img {
    width: 80px;
    height: 80px;
}

.compact .track-title {
    /* Styles will be applied dynamically via theme settings */
}

.compact .artist-name {
    /* Styles will be applied dynamically via theme settings */
}

.compact .track-duration {
    /* Styles will be applied dynamically via theme settings */
    white-space: nowrap;
    display: flex;
    align-items: center;
    /* Width will be set dynamically by JavaScript */
}

/* Crossfade album cover enhancements */
.album-cover { position: relative; }
.album-cover img.crossfade-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
    opacity: 0;
    transform: scale(1.04);
    transition: opacity 0.8s ease, transform 0.8s ease;
    z-index: 3;
    pointer-events: none;
}
.album-cover img.crossfade-image.fade-in {
    opacity: 1;
    transform: scale(1);
}
/* Outgoing subtle deemphasis (applied temporarily via inline style or class if needed) */
.album-cover img.outgoing-cover {
    transition: opacity 0.6s ease, transform 0.6s ease;
    opacity: 0;
    transform: scale(0.98);
}

/* Track type-based visibility transitions */
.now-playing-wrapper {
    transition: opacity 0.8s ease-in-out, transform 0.8s ease-in-out;
    opacity: 1;
    transform: translateY(0);
}

.now-playing-wrapper.fade-out {
    opacity: 0;
    transform: translateY(-20px);
    pointer-events: none;
}

.now-playing-wrapper.fade-in {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}
