/*
 * Audio player. Used for the full edition on index.html and once per topic on share.html.
 * main.js sets body[data-audio] to "playing" or "paused", which switches the play/pause icons.
 */

.player {
    --player-track: color-mix(in srgb, var(--color-muted) 35%, transparent);
    display: flex;
    flex-direction: column;
    gap: 1.125rem;
    padding: 1.25rem;
    border-radius: var(--radius);
    background: var(--color-surface);
}

.player-head {
    display: flex;
    align-items: center;
    gap: 0.875rem;
}

.player-toggle {
    display: grid;
    place-items: center;
    flex: none;
    width: 3rem;
    height: 3rem;
    border: 0;
    border-radius: 50%;
    background: var(--color-accent);
    color: var(--color-on-accent);
    cursor: pointer;
    transition: transform 150ms ease;
}

.player-toggle:hover {
    transform: scale(1.04);
}

.player-toggle:active {
    transform: scale(0.97);
}

.player-toggle .icon {
    width: 1.375rem;
    height: 1.375rem;
}

[data-player-toggle] .icon-pause,
body[data-audio="playing"] [data-player-toggle] .icon-play {
    display: none;
}

body[data-audio="playing"] [data-player-toggle] .icon-pause {
    display: block;
}

.player-title {
    flex: 1;
    min-width: 0;
}

.player-label {
    margin: 0;
    color: var(--color-ink);
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.3;
}

.player-time {
    margin: 0.125rem 0 0;
    color: var(--color-muted);
    font-size: 0.8125rem;
}

.player-progress {
    position: relative;
    display: flex;
    align-items: center;
}

/*
 * Below the progress bar: skip and next topic as plain icon buttons, the speed as an outlined chip on
 * the right. Play stays the one filled button. The negative margin lines the first icon up with the
 * play button, the buttons are wider than their icons.
 */
.player-controls {
    display: flex;
    align-items: center;
    gap: 0.125rem;
    margin: -0.25rem 0 -0.375rem -0.5rem;
}

.player-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    flex: none;
    min-width: 2.5rem;
    height: 2.5rem;
    padding: 0 0.5rem;
    border: 0;
    border-radius: var(--radius);
    background: none;
    color: var(--color-muted);
    font: 600 0.75rem/1 var(--font-sans);
    cursor: pointer;
    transition: color 150ms ease, background-color 150ms ease;
}

.player-button:hover:not(:disabled) {
    background: color-mix(in srgb, var(--color-muted) 14%, transparent);
    color: var(--color-ink);
}

.player-button:active:not(:disabled) {
    transform: translateY(1px);
}

.player-button:disabled {
    opacity: 0.4;
    cursor: default;
}

.player-button .icon {
    width: 1.125rem;
    height: 1.125rem;
}

.player-speed {
    flex: none;
    min-width: 2.75rem;
    height: 1.75rem;
    margin-left: auto;
    padding: 0 0.5rem;
    border: 1px solid var(--color-rule);
    border-radius: var(--radius);
    background: none;
    color: var(--color-ink);
    font: 600 0.8125rem/1 var(--font-sans);
    cursor: pointer;
}

.player-speed:hover {
    border-color: currentColor;
}

@media (pointer: coarse) {
    .player-button {
        min-width: 2.75rem;
        height: 2.75rem;
    }
}

/* A native range input, so seeking works with keyboard and screen readers. */
.player-seek {
    --progress: 0%;
    width: 100%;
    height: 1.25rem;
    margin: 0;
    background: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.player-seek:focus-visible {
    outline-offset: 4px;
}

.player-seek::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(to right, var(--color-accent) var(--progress), var(--player-track) var(--progress));
}

.player-seek::-webkit-slider-thumb {
    width: 0.75rem;
    height: 0.75rem;
    margin-top: -4px;
    border-radius: 50%;
    background: var(--color-ink);
    -webkit-appearance: none;
    appearance: none;
}

.player-seek::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: var(--player-track);
}

.player-seek::-moz-range-progress {
    height: 4px;
    border-radius: 2px;
    background: var(--color-accent);
}

.player-seek::-moz-range-thumb {
    width: 0.75rem;
    height: 0.75rem;
    border: 0;
    border-radius: 50%;
    background: var(--color-ink);
}

/* A gap in the track where the next topic starts. main.js positions it once the duration is known. */
.player-chapter {
    position: absolute;
    top: 50%;
    width: 2px;
    height: 4px;
    background: var(--color-surface);
    transform: translate(-50%, -50%);
    pointer-events: none;
}
