/*
 * ATS Moknah – player additions that help readers start listening:
 * listening time up front, loading / error feedback, a labelled floating
 * button, and a clearer play button on phones.
 * Kept apart from mk-mp-d1.css so it also applies when a site owner uses an
 * edited copy of the player stylesheet (Player Design → Custom CSS).
 */

/* ---------- Title row: "Listen to the article · 4 min" ---------- */
#mk-mp-d1 .mk-mp-d1-heading {
    display: flex;
    flex: 1 1 auto;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: 6px;
    row-gap: 0;
    min-width: 0;
    /* One line only: when the title and the time don't both fit, the time wraps out of
       sight instead of cutting the title down to "Listen to the ar…". */
    line-height: 18px;
    max-height: 18px;
    overflow: hidden;
}

#mk-mp-d1 .mk-mp-d1-heading .mk-mp-d1-title {
    min-width: 0;
    max-width: 100%;
    line-height: 18px;
}

#mk-mp-d1 .mk-mp-d1-listen-time {
    flex-shrink: 0;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    color: var(--mk-mp-d1-text-secondary, inherit);
}

#mk-mp-d1 .mk-mp-d1-listen-time::before {
    content: "· ";
}

#mk-mp-d1 .mk-mp-d1-listen-time:empty {
    display: none;
}

/* ---------- Loading: spinner on the play buttons until sound starts ---------- */
#mk-mp-d1 .mk-mp-d1-play-pause,
#mk-mp-d1 #mk-mp-d1-car-play-pause {
    position: relative;
}

#mk-mp-d1.mk-mp-loading .mk-mp-d1-play-pause i,
#mk-mp-d1.mk-mp-loading #mk-mp-d1-car-play-pause i {
    visibility: hidden;
}

#mk-mp-d1.mk-mp-loading .mk-mp-d1-play-pause::after,
#mk-mp-d1.mk-mp-loading #mk-mp-d1-car-play-pause::after {
    content: "";
    position: absolute;
    inset: 0;
    width: 38%;
    height: 38%;
    margin: auto;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: mk-mp-d1-spin 0.8s linear infinite;
}

@keyframes mk-mp-d1-spin {
    to { transform: rotate(360deg); }
}

/* ---------- Error: message in place of the title, play retries ---------- */
#mk-mp-d1 .mk-mp-d1-status {
    display: none;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.35;
    white-space: normal;
}

#mk-mp-d1.mk-mp-error .mk-mp-d1-status {
    display: block;
    color: #ffb4a8;
}

#mk-mp-d1.mk-mp-error.mk-mp-theme-light .mk-mp-d1-status {
    color: #b32d2e;
}

#mk-mp-d1.mk-mp-error .mk-mp-d1-heading {
    max-height: none;
}

#mk-mp-d1.mk-mp-error .mk-mp-d1-title,
#mk-mp-d1.mk-mp-error .mk-mp-d1-listen-time {
    display: none;
}

/* ---------- Floating button (pinned player out of view): "Listen · 4 min" until the audio starts ---------- */
#mk-mp-d1 .mk-mp-d1-floating-stop .mk-mp-d1-floating-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#mk-mp-d1 .mk-mp-d1-floating-stop .mk-mp-d1-floating-label {
    display: none;
}

#mk-mp-d1 .mk-mp-d1-floating-stop.has-label:not(.is-started) {
    width: auto;
    height: 52px;
    gap: 10px;
    padding: 0 20px 0 18px;
    border-radius: 999px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
}

#mk-mp-d1 .mk-mp-d1-floating-stop.has-label:not(.is-started) .mk-mp-d1-floating-label {
    display: inline;
    white-space: nowrap;
}

#mk-mp-d1.mk-mp-loading .mk-mp-d1-floating-stop .mk-mp-d1-floating-icon i {
    visibility: hidden;
}

#mk-mp-d1.mk-mp-loading .mk-mp-d1-floating-stop .mk-mp-d1-floating-icon::after {
    content: "";
    position: absolute;
    inset: 0;
    width: 16px;
    height: 16px;
    margin: auto;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: mk-mp-d1-spin 0.8s linear infinite;
}

/* ---------- Phones: a clearly bigger play button, no volume slider ---------- */
@container (max-width: 480px) {
    #mk-mp-d1 .mk-mp-d1-play-pause {
        width: 54px;
        height: 54px;
        font-size: 18px;
    }

    #mk-mp-d1 .mk-mp-d1-progress-section {
        width: calc(100% - 68px);
    }
}

@container (max-width: 380px) {
    #mk-mp-d1 .mk-mp-d1-play-pause {
        width: 52px;
        height: 52px;
        font-size: 17px;
    }

    #mk-mp-d1 .mk-mp-d1-progress-section {
        width: calc(100% - 64px);
    }
}

/* Touch screens: the page cannot change the volume on iPhones, and phones have volume keys. */
@media (hover: none) and (pointer: coarse) {
    #mk-mp-d1 .mk-mp-d1-volume-wrapper {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    #mk-mp-d1.mk-mp-loading .mk-mp-d1-play-pause::after,
    #mk-mp-d1.mk-mp-loading #mk-mp-d1-car-play-pause::after {
        animation-duration: 2s;
    }
}

/* Keep the player's icons on the icon font even when a theme sets a font on every element
   (e.g. ":lang(ja) { font-family: … }" or "* { font-family: … !important }"). */
#mk-mp-d1 :is(.fa, .fas, .far),
.mk-mp-d1 :is(.fa, .fas, .far) {
    font-family: 'Font Awesome 5 Free', serif !important;
    font-style: normal !important;
}

/* ---------- Medium widths (481–700px): two rows, so the title isn't squeezed to "List…" ----------
   Same layout the player already uses below 480px. Class-only selectors, so presets and custom CSS
   (which start with #mk-mp-d1) still win. */
@container (min-width: 481px) and (max-width: 700px) {
    .mk-mp-d1-controls-wrapper {
        flex-wrap: wrap;
        row-gap: 12px;
    }

    .mk-mp-d1-progress-section {
        width: calc(100% - 80px);
    }

    .mk-mp-d1-right-controls {
        width: 100%;
        justify-content: space-between;
    }

    .mk-mp-d1-volume-wrapper {
        flex: 1;
        max-width: 220px;
    }

    .mk-mp-d1-volume-slider {
        width: 100%;
    }
}
