/*
 * Article TTS player — Bootstrap 3 compatible.
 * Accent colour is injected per-article via the --tts-accent custom property
 * set on #tts-bar (falls back to the site pink).
 */

#tts-bar {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    transform: none !important;
    z-index: 1030; /* below BS3 modals (1040), above page content */
    background: #fff;
    border-top: 1px solid #ddd;
    border-bottom: 0 !important;
    border-left: 0 !important;
    border-right: 0 !important;
    border-radius: 0 !important;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, .09);
    padding: 16px 0;
}

#tts-bar[hidden] { display: none !important; }

#tts-bar .tts-container {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 20px;
    width: 100%;
}

/* Bootstrap's own .btn { display: inline-block; } is declared later in
   bootstrap.min.css than normalize's [hidden] rule, so at equal specificity
   it wins and defeats the plain [hidden] attribute on a `.btn`-classed
   element. #tts-bar isn't affected (its #tts-bar[hidden] selector above
   out-specifies #tts-bar's own display:flex), but #tts-open — the toolbar
   Listen button, styled with `class="btn btn-default"` — needs an explicit
   override or it renders visible on every page load, before any JS runs. */
#tts-open[hidden] { display: none !important; }

body.tts-open { padding-bottom: 88px; }

/* --- transport buttons --- */
#tts-bar .tts-ico {
    width: 44px;
    height: 44px;
    flex: none;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ccc;
    background: #fff;
    color: #555;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    cursor: pointer;
}

#tts-bar .tts-ico:hover { background: #f2f2f2; }

#tts-bar .tts-ico.tts-primary {
    background: var(--tts-accent);
    border-color: var(--tts-accent);
    color: #fff;
    font-size: 20px;
}

#tts-bar .tts-ico.tts-primary:hover { filter: brightness(.92); }

#tts-bar #tts-play .fa-play {
    margin-left: 3px;
}

#tts-bar .tts-ico.tts-flat {
    border-color: transparent;
    background: transparent;
    color: #777;
    width: 44px;
    height: 44px;
    font-size: 24px;
}

#tts-bar .tts-ico.tts-flat:hover {
    color: #333;
}

#tts-bar .tts-ico.tts-flat.active { color: var(--tts-accent); }

#tts-bar .tts-sep {
    width: 1px;
    height: 26px;
    background: #e8e8e8;
    flex: none;
}

/* --- progress range --- */
#tts-seek {
    flex: 1 1 auto;
    min-width: 50px;
    height: 16px;
    margin: 0;
    padding: 0;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
    cursor: default;
    pointer-events: none;
}

#tts-seek:disabled {
    opacity: 1;
    cursor: default;
}

#tts-seek::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(to right,
        var(--tts-accent) 0%, var(--tts-accent) var(--tts-pct, 0%),
        #e4e4e4 var(--tts-pct, 0%), #e4e4e4 100%);
}

#tts-seek::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: #e4e4e4;
}

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

#tts-seek::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    margin-top: -4.5px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--tts-accent);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}

#tts-seek::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border: 2px solid var(--tts-accent);
    border-radius: 50%;
    background: #fff;
}

#tts-count {
    flex: none;
    font-size: 11px;
    color: #999;
    font-variant-numeric: tabular-nums;
    min-width: 46px;
    text-align: right;
}

/* --- dropup panels --- */
#tts-bar .tts-pop { position: relative; flex: none; }

#tts-bar .tts-panel {
    position: absolute;
    right: 0;
    bottom: 40px;
    width: 246px;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 9px;
}

#tts-bar .tts-panel[hidden] { display: none; }

#tts-bar .tts-panel label {
    font-size: 11px;
    font-weight: 700;
    color: #777;
    text-transform: uppercase;
    letter-spacing: .06em;
    margin: 0;
}

#tts-bar .tts-field { display: flex; flex-direction: column; gap: 4px; }

#tts-bar .tts-panel select { width: 100%; }

#tts-bar .tts-slider { display: flex; align-items: center; gap: 8px; }
#tts-bar .tts-slider input[type=range] { flex: 1; }
#tts-bar .tts-slider output {
    font-size: 11px;
    color: #777;
    min-width: 36px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

#tts-bar .tts-meta {
    font-size: 11px;
    color: #999;
    border-top: 1px solid #eee;
    padding-top: 8px;
    line-height: 1.4;
}

/* --- screen-reader-only status --- */
.tts-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

@media (max-width: 767px) {
    #tts-bar {
        border-radius: 0;
        padding: 14px 0 calc(14px + env(safe-area-inset-bottom, 0px));
    }
    #tts-bar .tts-container {
        gap: 16px;
    }
    #tts-bar .tts-ico {
        width: 46px;
        height: 46px;
        min-width: 46px;
        min-height: 46px;
        font-size: 19px;
    }
    #tts-bar .tts-ico.tts-primary {
        font-size: 21px;
    }
    #tts-bar .tts-ico.tts-flat {
        width: 46px;
        height: 46px;
        font-size: 25px;
    }
    #tts-bar .tts-sep {
        height: 28px;
    }
    body.tts-open { padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px)); }
}

@media print {
    #tts-bar, #tts-open { display: none !important; }
    body.tts-open { padding-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
    #tts-bar { transition: none !important; }
}

#tts-bar :focus-visible {
    outline: 2px solid var(--tts-accent);
    outline-offset: 2px;
}

/* #tts-open lives in the article toolbar, outside #tts-bar, so it can't see
   --tts-accent (only defined inline on #tts-bar) — var() referencing an
   out-of-scope custom property makes the whole declaration invalid, which
   computed outline to none, silently deleting the button's focus ring.
   currentColor works instead: the button sets its own `color` inline from
   the article's accent. */
#tts-open:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* Fallback for browsers without :focus-visible */
#tts-bar button:focus,
#tts-bar input:focus,
#tts-bar select:focus {
    outline: 2px solid var(--tts-accent);
    outline-offset: 2px;
}

#tts-bar .tts-ico { min-width: 44px; min-height: 44px; }
