/* Record player of the music rounds (shared/client/music-player.ts): «Угадай мелодию» and «Квиз» / «Музыка».
   Layout and motion only; colours come from the game's *-theme.css (--bg-card, --text-secondary, --accent-pink,
   --accent-coral, overridable per game on .audio-player-bar / .audio-progress-fill / .vinyl-base).
   --music-beat (0…1, kicks), --music-level (0…1, bass loudness), --music-hue and --music-on are set on <body>
   by the player from the track's bass. */

.music-player {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex-shrink: 0;
}

.music-player[hidden],
.music-player.hidden { display: none; }

.music-player .vinyl-container {
    position: relative;
    width: 200px;
    max-width: 200px;
    aspect-ratio: 1;
    margin: 0 auto 16px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
    isolation: isolate;
    /* transform, not `scale`: the «record drops in» animations animate `scale` with fill-mode both,
       which would hold the record at 1 for the whole round and hide the pulse. */
    transform: scale(calc(1 + var(--music-level, 0) * 0.05 + var(--music-beat, 0) * 0.1));
}

.music-player .vinyl-container::before {
    content: '';
    position: absolute;
    inset: -30%;
    z-index: -1;
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(circle,
        hsl(var(--music-hue, 200) 95% 60% / calc(0.18 + var(--music-beat, 0) * 0.55)) 0%,
        hsl(calc(var(--music-hue, 200) + 70) 95% 55% / calc(var(--music-beat, 0) * 0.4)) 42%,
        transparent 70%);
    opacity: var(--music-on, 0);
    transition: opacity 0.5s;
}

.music-player .vinyl-base {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.music-player .vinyl-label {
    position: absolute;
    top: 32.8125%;
    left: 32.8125%;
    width: 34.375%;
    height: 34.375%;
    border-radius: 50%;
    object-fit: cover;
}

.music-player .vinyl-container.spinning .vinyl-label {
    animation: music-vinyl-spin 3s linear infinite;
}

.music-player .vinyl-play-overlay {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s;
}

.music-player .vinyl-container.spinning .vinyl-play-overlay {
    opacity: 0;
    pointer-events: none;
}

.music-player .vinyl-play-icon {
    font-size: 40px;
    color: white;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.5));
}

.music-player .vinyl-container.needs-interaction .vinyl-play-overlay {
    animation: music-tap-pulse 1s ease infinite alternate;
}

.music-player .audio-player-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-card);
    padding: 12px 16px;
    border-radius: 16px;
    margin-bottom: 20px;
}

.music-player .audio-hint {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.music-player .audio-progress-bar {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.music-player .audio-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-pink, #a677ef), var(--accent-coral, #edc945));
    border-radius: 3px;
    width: 0%;
    transition: width 0.3s linear;
}

.music-player .audio-time {
    font-size: 13px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    min-width: 36px;
    text-align: right;
    flex-shrink: 0;
}

/* The album cover of the round reveal swells on the beat while the track keeps playing under the host. */
body.has-music-player #round-results-screen .rr-context-image {
    scale: calc(1 + var(--music-level, 0) * 0.04 + var(--music-beat, 0) * 0.08);
    box-shadow: 0 0 calc(14px + var(--music-beat, 0) * 40px)
        hsl(var(--music-hue, 200) 95% 60% / calc(var(--music-on, 0) * (0.25 + var(--music-beat, 0) * 0.5)));
}

@keyframes music-vinyl-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes music-tap-pulse {
    from { transform: scale(1); }
    to { transform: scale(1.1); }
}

@keyframes music-record-drop {
    from { opacity: 0; scale: 1.45; }
    to { opacity: 1; scale: 1; }
}

/* The record drops in with each new track (games may override with their own spring). */
@media (prefers-reduced-motion: no-preference) {
    .screen.active .music-player:not(.hidden) .vinyl-container { animation: music-record-drop 360ms cubic-bezier(.2, .9, .25, 1.15) both; }
}

@media (max-width: 480px) {
    .music-player .vinyl-container { width: 160px; max-width: 160px; }
    .music-player .vinyl-play-icon { font-size: 32px; }
    .music-player .audio-player-bar { padding: 10px 14px; }
}

@media (min-width: 768px) {
    .music-player .vinyl-container { width: 240px; max-width: 240px; }
}

@media (prefers-reduced-motion: reduce) {
    .music-player .vinyl-container { transform: none; }
    body.has-music-player #round-results-screen .rr-context-image { scale: none; }
    .music-player .vinyl-container::before { background: radial-gradient(circle, hsl(var(--music-hue, 200) 95% 60% / 0.25), transparent 70%); }
}
