/*
    The Transcript panel (ADR-0177): the toggle that replaces "Subtitles" in a
    Listening player and joins a Speaking prompt player, the panel of the
    recording's words under the bar, and the bar it makes seekable. Its own
    stylesheet because a Speaking page loads no audio-player.css. Every class
    here is js/transcript-panel.js's; the colours are tokens in main.css.
*/

/* ---- toggle ---- */

.subtitle-toggle-btn.tv-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 34px;
    height: 34px;
    padding: 0 13px;
    background-color: var(--surface);
    color: var(--tv-toggle-ink);
    border: 1px solid var(--tv-toggle-line);
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.subtitle-toggle-btn.tv-toggle:hover {
    background-color: var(--tv-toggle-hover);
    color: var(--tv-toggle-ink-strong);
}

.subtitle-toggle-btn.tv-toggle[aria-expanded="true"] {
    background-color: var(--tv-toggle-open);
    color: var(--tv-toggle-ink-strong);
}

.subtitle-toggle-btn.tv-toggle:focus-visible {
    outline: 2px solid var(--brand-blue);
    outline-offset: 2px;
}

.tv-toggle .nav-icon {
    --nav-icon-size: 11px;
    transition: transform 0.15s ease;
}

.tv-toggle[aria-expanded="true"] .nav-icon {
    transform: rotate(180deg);
}

.transcript-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* In a Listening player's controls row the toggle and its hint share the row
   with the play button, the time and the volume. The Subtitles toggle's rule
   (audio-player.css) holds its control at full width, and with the hint in it
   that pushed the volume out of the player. Here the control gives way: the
   toggle keeps its size, and the hint wraps into the room that is left. */
.subtitle-control.transcript-control {
    flex: 0 1 auto;
    min-width: 0;
}

.tv-toggle {
    flex: none;
}

.transcript-control[hidden],
.tv-hint[hidden],
.tv-panel[hidden] {
    display: none;
}

.tv-hint {
    min-width: 0;
    margin-left: auto;
    font-size: 13px;
    line-height: 1.3;
    color: var(--ink-muted);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* ---- panel ---- */

.tv-panel {
    --tv-key-band: var(--tv-key-band-rest);
    max-height: max(42vh, 240px);
    overflow-y: auto;
    margin-top: 10px;
    padding: 10px 12px;
    border: 1px solid var(--tv-border);
    border-radius: 6px;
    /* Scroll shadows: a shade at an edge with more words past it. */
    background:
        linear-gradient(var(--surface) 40%, rgba(255, 255, 255, 0)) top / 100% 28px no-repeat local,
        linear-gradient(rgba(255, 255, 255, 0), var(--surface) 60%) bottom / 100% 28px no-repeat local,
        linear-gradient(rgba(53, 50, 63, 0.16), rgba(53, 50, 63, 0)) top / 100% 10px no-repeat scroll,
        linear-gradient(rgba(53, 50, 63, 0), rgba(53, 50, 63, 0.16)) bottom / 100% 10px no-repeat scroll;
    background-color: var(--surface);
    text-align: left;
}

.tv-panel:focus-visible {
    outline: 2px solid var(--brand-blue);
    outline-offset: -2px;
}

.tv-p {
    margin: 0 auto 0.85em;
    max-width: 72ch;
    font-family: var(--font-passage);
    /* Follows the page's text size, and starts smaller than the passage. */
    font-size: calc(16px * var(--task-text-scale, 1));
    font-weight: 400;
    line-height: 1.85;
    color: var(--tv-words);
}

.tv-p:last-child {
    margin-bottom: 0;
}

/* SGD speaker label: its own line over the turn it names, smaller and
   faded so the words stay the loudest thing. Read by a screen reader. */
.tv-speaker {
    display: block;
    margin: 0 0 -5px;
    font-weight: 600;
    font-size: 0.8em;
    line-height: 1.3;
    color: var(--ink-tertiary);
    letter-spacing: 0.01em;
    user-select: none;
}

/* Collapses with the 13px bottom margin. */
.tv-p:has(> .tv-speaker) + .tv-p:has(> .tv-speaker) {
    margin-top: 22px;
}

.tv-note {
    margin: 12px 0 0;
    font-size: 14px;
    color: var(--ink-muted);
}

/* ---- words ---- */

.tv-w {
    cursor: pointer;
}

.tv-panel--untimed .tv-w {
    cursor: text;
}

.tv-gap {
    padding: 0 0.6px;
    margin: 0 -0.6px;
}

.tv-g {
    border-radius: 4px;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
    transition: background-color 0.15s, box-shadow 0.15s;
}

.tv-w.key {
    font-weight: 600;
    color: var(--tv-key-ink);
    background-image: linear-gradient(to top, var(--tv-key-band) 0, var(--tv-key-band) 0.58em, transparent 0.58em);
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

@media (hover: hover) {
    .tv-w:hover {
        background-color: rgba(60, 70, 90, 0.1);
        border-radius: 3px;
    }

    .tv-w.key:hover {
        --tv-key-band: var(--tv-key-band-hover);
    }

    .tv-panel--untimed .tv-w:hover {
        background-color: transparent;
    }
}

.tv-g.on {
    background-color: rgba(255, 193, 7, 0.27);
    box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.27);
}

.tv-g.on .tv-w {
    color: var(--tv-words-on);
}

.tv-g.on .tv-w.key {
    color: var(--tv-key-ink);
    background-image: none;
}

.tv-w.now,
.tv-g.on .tv-w.now {
    background-color: rgba(255, 193, 7, 0.78);
    box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.78);
    background-image: none;
    border-radius: 3px;
    color: var(--ink);
}

/* ---- inside a Speaking prompt player ----

   On a Speaking page the controls row is `display: contents`
   (css/speaking-cards.css), so the toggle and the panel are grid items of the
   player. Left to auto-placement, the toggle fell into the play-button column
   and the panel squeezed in beside it, one letter wide. They are placed
   outright instead: the toggle in row 1's middle (the prompt player, below),
   and the panel, or the note that says there is none, across the whole
   player under the bar. The rule right below is the saved-answer player's. */

.speaking-cards-page .recording-player > .controls-row > .transcript-control {
    grid-column: 3;
    grid-row: 3;
    justify-self: center;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 8px;
}

/* The prompt player is the Listening layout (css/speaking-cards.css): the
   toggle is row 1's centre, between play and Skip, on the middle track. */
.speaking-cards-page .speaking-question-audio .recording-player > .controls-row > .transcript-control {
    grid-column: 3;
    grid-row: 1;
    margin-top: 0;
}

.speaking-cards-page .speaking-question-audio .recording-player .tv-toggle {
    min-height: 34px;
    height: 34px;
    padding-top: 0;
    padding-bottom: 0;
}

.speaking-cards-page .recording-player > .controls-row > .transcript-control .tv-hint {
    margin-left: 0;
    text-align: center;
}

.speaking-cards-page .recording-player > .tv-panel,
.speaking-cards-page .recording-player > .tv-note {
    grid-column: 1 / -1;
    grid-row: 4;
    min-width: 0;
}

/* ---- the bar a transcript makes seekable ---- */

.audio-player:not(.recording-box--playback) .progress-bar.is-seekable,
.progress-bar.is-seekable {
    overflow: visible;
    cursor: pointer;
    touch-action: none;
}

.progress-bar.is-seekable::before {
    content: "";
    position: absolute;
    inset: -9px 0;
}

.progress-bar.is-seekable:focus-visible {
    outline: 2px solid var(--brand-blue);
    outline-offset: 3px;
}

/* ---- phone ---- */

@media (max-width: 768px) {
    /* As tight as the Subtitles toggle it replaces, so the volume control
       still fits the row on a phone. */
    .subtitle-toggle-btn.tv-toggle {
        min-height: 34px;
        height: 34px;
        padding: 0 8px;
        gap: 4px;
        font-size: 12px;
    }

    .tv-panel {
        margin-top: 10px;
        padding: 8px 10px;
    }

    .tv-p {
        font-size: calc(15.5px * var(--task-text-scale, 1));
        line-height: 1.8;
    }

    .progress-bar.is-seekable::before {
        inset: -12px 0;
    }
}

/* ---- preferences ---- */

@media (prefers-reduced-motion: reduce) {
    .tv-g,
    .tv-toggle .nav-icon {
        transition: none;
    }
}

@media (forced-colors: active) {
    .tv-w.key {
        text-decoration: underline;
    }

    .tv-g.on {
        outline: 1px solid Highlight;
    }

    .tv-w.now,
    .tv-g.on .tv-w.now {
        forced-color-adjust: none;
        background-color: Highlight;
        color: HighlightText;
    }
}
