/*
 * PAC Media Player: everything the player needs, and nothing else.
 *
 * Load this file unchanged on any page that holds the player. It has no
 * page-wide rule: every selector names the <video-player> element, the
 * `.player` box inside it, one of the player's own classes (`.player__*`,
 * `.ctl*`, `.slider*`, `.time__divider`), or one of the player's controls
 * by its `data-control` name. It sets the
 * player's own font family and line height, so the controls measure the
 * same on every page, and reads nothing from the host page's styles. The
 * sample pages' own chrome (page, headings, links, the disclosure) is in
 * sample.css, which an integration does not load.
 *
 * The controls are native buttons and range inputs, and no Video.js skin is
 * used, so nothing styles the player but this file: the media box, the
 * control bar, the icons, the sliders, and the two dialogs are all composed
 * here.
 * The PAC modules drive the visuals through state attributes on the buttons
 * (`[data-paused]`, `[data-muted]`, `[data-active]`, ...) and two custom
 * properties on the sliders (`--pac-slider-fill`, `--pac-slider-buffer`).
 * Caption cues are the browser's own rendering of the showing text track,
 * styled with ::cue.
 */

/*
 * The base rules the player relies on, scoped to the player so the host
 * page's own elements are untouched: border-box sizing, native buttons that
 * take the player's font, a `hidden` attribute that always hides (several
 * player rules set `display`, which would otherwise outrank it), and the
 * visually hidden live region js/announce.js adds for volume announcements.
 */
.player,
.player * {
  box-sizing: border-box;
}

.player button {
  font: inherit;
}

video-player[hidden],
.player[hidden],
.player [hidden] {
  display: none !important;
}

.player .visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  border: 0;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/*
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Player + composed control bar
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

/* <video-player> holds the player state and draws nothing; the visible
   player box is the <media-container> inside it (.player), which is also
   what goes fullscreen. */
video-player {
  display: contents;
}

/*
 * Before the script has run. A page writes only the <video-player> element;
 * js/template.js puts the stage and the control bar inside it once the
 * module has loaded, which is after the page first paints. Until then the
 * element holds the room they will take, so the page below the player does
 * not jump when they arrive: the 16:9 stage, and the bar at the height it
 * has before the first play, at default text size. Until a player is first
 * played its bar shows Play alone (the "Before the first play" rules at the
 * end of this file), which is one row at every width: the transport row on a
 * narrow player, the whole bar from 44.5rem (the tiers further down; the
 * sums below are those rules' padding and control sizes). It paints nothing:
 * the player's colors are not known until its configuration has loaded.
 *
 * Measured in Chromium with the module held back 600ms, the content below a
 * video player then moves 0px, where without this rule it moved 612px on a
 * 1440px-wide page and 330px on a 360px-wide one. Three cases still move:
 * at enlarged text on a wide player the bar wraps to more rows than are held
 * here; an audio player has no stage, which is not known until its
 * configuration is read; and a narrow player configured to show every
 * control from the start (`controlsBeforePlay: "all"`) gains its other two
 * rows when its configuration arrives.
 *
 * A page that writes the player markup itself already holds a .player, so
 * none of this applies to it.
 */
video-player[data-pac-media-player]:not(:has(.player)) {
  display: block;
  container-type: inline-size;
}

video-player[data-pac-media-player]:not(:has(.player))::before {
  content: "";
  display: block;
  aspect-ratio: 16 / 9;
}

/* Compact tier: the bar's 0.4rem padding twice and one row of square
   buttons, or the bar's own minimum height where that is more. */
video-player[data-pac-media-player]:not(:has(.player))::after {
  content: "";
  display: block;
  height: max(3.25rem, calc(0.8rem + max(44px, 2rem)));
}

/* Wide tier: the bar's padding and one 2.75rem row. */
@container (min-width: 44.5rem) {
  video-player[data-pac-media-player]:not(:has(.player))::after {
    height: 3.55rem;
  }
}

/*
 * The player is a column: the video stage on top, the control bar below it in
 * normal flow. The bar never overlays the video, so on a phone, where the
 * controls wrap onto several rows, the picture stays fully visible (the first
 * finding from testing was a bar covering the whole video). The stage keeps
 * the 16:9 ratio; Video.js gives media no default size.
 */
/*
 * The player's colors. Every color the player paints comes from one of
 * these custom properties, which the `colors` section of config.json
 * overrides by name (see js/colors.js and README.md): background, controlBar,
 * controlText, focus, sliderTrack, sliderBuffer, sliderFill, sliderThumb,
 * menuBackground, menuText, selectedOption (the three that color the
 * playback-rate and audio-track dialogs, under the names they had when those
 * were menus), captionText, captionBackground.
 * Hover and border shades are mixed from them. The Windows Contrast Themes
 * rules further down this file use system colors directly, so configured
 * colors never outrank them. The host page's colors are its own; the player
 * reads none of them.
 *
 * The font family and line height are set here rather than inherited, so the
 * time read-out, the playback-rate text, and the dialogs' choices measure the
 * same on every host page (the breakpoints below were measured with them).
 */
.player {
  --pac-color-background: #000;
  --pac-color-control-bar: rgb(12 16 14 / 0.86);
  --pac-color-control-text: #f5f5f5;
  --pac-color-focus: #b54b2a;
  --pac-color-slider-track: rgb(255 255 255 / 0.45);
  --pac-color-slider-buffer: rgb(255 255 255 / 0.5);
  --pac-color-slider-fill: #d8efe6;
  --pac-color-slider-thumb: #fff;
  --pac-color-menu-background: rgb(12 16 14 / 0.96);
  --pac-color-menu-text: #f5f5f5;
  --pac-color-selected-option: rgb(255 255 255 / 0.14);
  --pac-color-caption-text: #fff;
  --pac-color-caption-background: rgb(0 0 0 / 0.75);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  aspect-ratio: auto;
  position: relative;
  background: var(--pac-color-background);
  border-radius: 6px;
  overflow: hidden;
  container-type: inline-size;
}

/* The stage holds the media. It keeps a 16:9 area at every width; caption
   cues are drawn by the browser inside the video's own box, so the stage
   does not grow for enlarged cues. */
.player__stage {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--pac-color-background);
}

/* The media element (a <video>, or <youtube-video>, whose iframe fills it)
   fills the stage and letterboxes. <youtube-video>'s own host styles ask for
   a 300x150 minimum, which would overflow a phone-width stage. */
.player__media {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  background: var(--pac-color-background);
}

/* Caption cues: the browser draws the showing track inside the video's box,
   which sits in the stage above the control bar, so no control ever covers
   a cue. ::cue accepts only text styles (color, background, font,
   line-height, text-shadow, outline, opacity, visibility, white-space): no
   padding, border radius, or positioning.

   Size (issue #9) follows the player's width (the player is a size
   container, and cqi resolves inside ::cue); the browser's own default would
   follow the video's height. Three terms, the largest wins:
   - 2cqi: 2% of the player's width, the size on a desktop-width player
     (19.8px on the sample page's 988px player), unchanged from before.
   - min(1rem, 4.2cqi): the reader's text size, but never more than lets a
     42-character line (the sample captions' maximum) fit across the player:
     at about half an em per character, 42 characters take 21em, and 4.2cqi
     keeps that within 88% of the width. Before, the floor was a plain 1rem,
     so 200% text on a phone made cues 32px tall on a 276px player.
   - 12px: the readable minimum on the smallest players. */
.player__media::cue {
  color: var(--pac-color-caption-text);
  background: var(--pac-color-caption-background);
  font-family: Arial, Helvetica, sans-serif;
  font-size: max(12px, 2cqi, min(1rem, 4.2cqi));
  line-height: 1.25;
}

/* Fullscreen puts the player (the media-container) in the viewport: the
   stage takes whatever height the bar leaves and the media letterboxes in
   it, keeping a fifth of the viewport at minimum. When enlarged controls
   exceed a short viewport, scroll this surface instead of clipping its last
   controls. */
.player:fullscreen {
  overflow: auto;
}

.player:fullscreen .player__stage {
  flex: 1 1 auto;
  aspect-ratio: auto;
  min-height: 20vh;
}

/*
 * The control bar is plain markup, not Video.js's auto-hiding
 * <media-controls>. Before the first play it shows Play alone (the "Before
 * the first play" rules at the end of this file). From then on every control
 * is always visible: the bar never fades or hides, and it stays in the
 * accessibility tree and tab order through playback, pause, and the end. It
 * paints above the stage.
 */
/*
 * The bar holds three layout groups in source order: transport (skip, play,
 * skip, mute, volume), timeline (time, seek), and extras (rate, captions,
 * audio, picture-in-picture, fullscreen). Grouping is layout only: names,
 * source order, and tab order are unchanged.
 *
 * Compact tier (the default, below 44.5rem of player width): each group is a
 * row of its own, every button is the same square, and the volume slider is
 * hidden while Mute stays. On a phone that is three rows at default text
 * size, where the plain wrap gave four or five; the breakpoint is in rem, so
 * a wide player at enlarged text gets the same treatment and each group then
 * wraps within itself. Hiding the volume slider there is a responsive-layout
 * choice the tester asked for, not an availability state: Mute remains, the
 * keyboard volume shortcuts still work, and the device's own volume control
 * is the better slider on a phone.
 *
 * Wide tier (44.5rem and up): the groups dissolve (display: contents) into
 * one row with the volume and seek sliders inline. The breakpoint is where
 * that row genuinely fits: measured at default text, the row's narrowest fit
 * is 42.9rem for a video under ten minutes (M:SS times), 43.9rem under an
 * hour (MM:SS), and 45.6rem from an hour (H:MM:SS), with the volume slider at
 * 4rem and the seek slider at its 4rem minimum. 44.5rem (712px) keeps 0.6rem
 * of room over the under-an-hour fit and still gives a player in an 800px
 * content column (about 730px after a wrapper's padding and borders) the one
 * row, with 18px to spare for a wider wrapper. The row may wrap rather than
 * overflow, so the rare hour-long video between 44.5rem and 45.6rem drops
 * its last control to a second line instead of clipping it.
 */
.player__bar {
  position: relative;
  z-index: 10;
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  width: 100%;
  min-height: 3.25rem;
  padding: 0.4rem 0.6rem;
  background: var(--pac-color-control-bar);
}

.player__group {
  display: flex;
  flex: 1 1 100%;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-width: 0;
}

/* The timeline row: the seek slider takes whatever the time read-out leaves.
   At enlarged text on a phone the two no longer fit side by side, and the
   slider drops to a row of its own rather than shrinking to a sliver. */
.player__group--timeline .slider--time {
  flex: 1 1 4rem;
}

.player__group--transport .slider--volume {
  display: none;
}

/* Square buttons: 44px at default text, growing with text but more slowly
   than the 2.75rem of the wide tier, so a phone at enlarged text keeps more
   controls per row without dropping under the 44px target. */
.player__group .ctl {
  width: var(--pac-ctl-size);
  min-width: var(--pac-ctl-size);
  height: var(--pac-ctl-size);
}

/* Buttons: every one is a native <button>, restyled from the browser's
   default to an icon on the bar. */
.ctl {
  --pac-ctl-size: max(44px, 2rem);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-width: 2.75rem;
  height: 2.75rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--pac-color-control-text);
  cursor: pointer;
}

.ctl:hover {
  background: color-mix(in srgb, var(--pac-color-control-text) 18%, transparent);
}

.ctl__icon {
  width: 1.4rem;
  height: 1.4rem;
  fill: currentColor;
  pointer-events: none;
}

/* The skip buttons read as one glyph: a circular arrow with the number
   inside it. The arrow is a stroked ring, open for a quarter turn, with a
   round-capped chevron head that sits on the ring rather than reaching into
   the middle, so it never touches the number (the replay glyph on the play
   button is the same ring). The number is centered over the whole button
   and lands in the ring. The visible "15" is
   contained in the accessible name ("Skip backward 15 seconds"), which says
   the unit in full so screen readers do not spell out "sec". */
.ctl--skip {
  position: relative;
}

.ctl__icon--skip {
  width: 1.9rem;
  height: 1.9rem;
}

.ctl__skip {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 0.05rem;
  font-size: 0.55rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  pointer-events: none;
}

/* Captions on: the rectangle fills and the text lines are cut out of it, so
   the state is visible as well as named. js/captions.js sets data-active on
   the button while captions are showing; the icon stays aria-hidden because
   the button's name ("Turn captions off" / "Turn captions on") carries the
   state. */
.ctl__icon--captions rect {
  fill: none;
  stroke: currentColor;
}

[data-control="captions"][data-active] .ctl__icon--captions rect {
  fill: currentColor;
}

[data-control="captions"][data-active] .ctl__icon--captions path {
  stroke: var(--pac-color-control-bar);
}

/* Icon swaps, driven by the state attributes each button's module sets. */
[data-control="play"]:not([data-paused]) .ctl__icon--play,
[data-control="play"][data-ended] .ctl__icon--play,
[data-control="play"][data-paused] .ctl__icon--pause,
[data-control="play"][data-ended] .ctl__icon--pause,
[data-control="play"]:not([data-ended]) .ctl__icon--replay {
  display: none;
}

/* On the mute button `data-muted` means the media is muted and nothing else:
   a volume of zero is not muted (js/volume.js). */
[data-control="mute"]:not([data-muted]) .ctl__icon--muted,
[data-control="mute"][data-muted] .ctl__icon--volume {
  display: none;
}

[data-control="pip"][data-pip] .ctl__icon--pip-enter,
[data-control="pip"]:not([data-pip]) .ctl__icon--pip-exit,
[data-control="fullscreen"][data-fullscreen] .ctl__icon--fs-enter,
[data-control="fullscreen"]:not([data-fullscreen]) .ctl__icon--fs-exit {
  display: none;
}

/* Time read-out. */
.player__time {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0 0.35rem;
  color: var(--pac-color-control-text);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.time__divider {
  color: color-mix(in srgb, var(--pac-color-control-text) 70%, transparent);
}

/*
 * Sliders: native range inputs, painted here. `appearance: none` hands the
 * drawing to this file and nothing else: the browser keeps the role, the
 * tab stop, the value, and the pointer and touch handling. The input is as
 * tall as a button, so it is as easy to hit, and its rail is a 5px line
 * across its middle.
 *
 * The rail is one background in three layers, top to bottom: the fill (up to
 * the current value), the buffered part (seek slider only), and the track.
 * js/seek.js and js/volume.js set `--pac-slider-fill` and
 * `--pac-slider-buffer` on the input, as percentages; the layers are sized
 * from them. `direction: ltr` keeps the value growing to the right on a
 * right-to-left page, where the layers are anchored.
 *
 * A browser exposes the rail and the thumb as pseudo-elements under its own
 * names: ::-webkit-slider-runnable-track and ::-webkit-slider-thumb in
 * Chromium and Safari, ::-moz-range-track and ::-moz-range-thumb in Firefox.
 * A rule whose selector list has a name the browser does not know is dropped
 * whole, so each part is styled in two rules that say the same thing.
 */
.slider {
  --pac-slider-rail:
    linear-gradient(var(--pac-color-slider-fill), var(--pac-color-slider-fill)) 0 0 / var(--pac-slider-fill, 0%) 100% no-repeat,
    linear-gradient(var(--pac-color-slider-buffer), var(--pac-color-slider-buffer)) 0 0 / var(--pac-slider-buffer, 0%) 100% no-repeat,
    var(--pac-color-slider-track);
  -webkit-appearance: none;
  appearance: none;
  height: 2.75rem;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  outline: none;
  direction: ltr;
  cursor: pointer;
}

.slider::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 2px;
  /* Clear of 3:1 against the bar even over the lightest video frame. */
  background: var(--pac-slider-rail);
}

.slider::-moz-range-track {
  height: 5px;
  border-radius: 2px;
  background: var(--pac-slider-rail);
}

/* The thumb shows while a pointer is over the slider or holds it, and
   while the slider has keyboard focus. Chromium and Safari place the thumb
   at the top of the rail, so it is moved up by half the difference in their
   heights; Firefox centers it. */
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
  width: 14px;
  height: 14px;
  margin-top: -4.5px;
  border: 2px solid var(--pac-color-control-bar);
  border-radius: 50%;
  background: var(--pac-color-slider-thumb);
  opacity: 0;
  transition: opacity 0.15s ease-in;
}

.slider::-moz-range-thumb {
  box-sizing: border-box;
  width: 14px;
  height: 14px;
  border: 2px solid var(--pac-color-control-bar);
  border-radius: 50%;
  background: var(--pac-color-slider-thumb);
  opacity: 0;
  transition: opacity 0.15s ease-in;
}

.slider:hover::-webkit-slider-thumb,
.slider:active::-webkit-slider-thumb,
.slider:focus-visible::-webkit-slider-thumb {
  opacity: 1;
}

.slider:hover::-moz-range-thumb,
.slider:active::-moz-range-thumb,
.slider:focus-visible::-moz-range-thumb {
  opacity: 1;
}

.slider[aria-disabled="true"] {
  cursor: default;
}

.player__group--timeline .slider--time {
  min-width: 4rem;
  margin: 0;
}

.player__group--timeline .player__time {
  flex: 0 0 auto;
}

/* Wide tier: one row, groups dissolved, sliders inline. The group selectors
   keep the same specificity as the compact rules they override. */
@container (min-width: 44.5rem) {
  .player__group {
    display: contents;
  }

  .player__group .ctl {
    width: auto;
    min-width: 2.75rem;
    height: 2.75rem;
  }

  .player__group .ctl--rate {
    min-width: 3.2rem;
  }

  /* A range input has a width of its own, which a flex basis of `auto`
     would take; the sliders are sized here instead, the seek slider from a
     4rem basis up to whatever the row has left. */
  .player__group--transport .slider--volume {
    display: inline-block;
    width: 4rem;
    flex-shrink: 0;
  }

  .player__group--timeline .slider--time {
    flex: 1 1 4rem;
    min-width: 4rem;
    margin: 0 0.4rem;
  }
}

/*
 * Keyboard focus shows a 4px accent outline, around the whole control: a
 * button's square, or the full height and width of a slider.
 */
.ctl:focus-visible,
.slider:focus-visible {
  outline: 4px solid var(--pac-color-focus);
  outline-offset: 2px;
}

/* The player box itself has no focus style: it is a named group around the
   controls, not a control, and js/container.js keeps it from taking focus.
   The keyboard shortcuts work from the controls inside it. */

/* The rate button shows the current rate as text. */
.ctl__text {
  font-size: 1rem;
  font-weight: 800;
  pointer-events: none;
}

.ctl--rate {
  min-width: 3.2rem;
}

/*
 * The playback-rate and audio-track dialogs: a native <dialog> each, opened
 * modally by its control-bar button (js/template.js has the markup,
 * js/option-dialogs.js the behavior). Closed, the browser hides it. Open, it
 * is in the browser's top layer, centered in the viewport and above
 * everything, including a fullscreen player, so the player's own size and
 * `overflow` do not clip it. It is sized in relative units and capped to
 * the viewport, so at large text or on a small screen it scrolls inside
 * itself instead of running off the screen. It takes the player's menu
 * colors.
 */
.player__dialog {
  min-width: min(16rem, calc(100vw - 1rem));
  max-width: calc(100vw - 1rem);
  max-height: calc(100dvh - 1rem);
  overflow: auto;
  overflow-wrap: anywhere;
  /* The side padding gives way on a narrow screen, where enlarged text
     needs the width for the choices. */
  padding: 1rem min(1.25rem, 4vw) 1.25rem;
  border: 1px solid color-mix(in srgb, var(--pac-color-menu-text) 35%, transparent);
  border-radius: 8px;
  background: var(--pac-color-menu-background);
  color: var(--pac-color-menu-text);
  box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 0.4);
}

/* The browser's own backdrop dims the page behind an open dialog. It
   reinforces that the page is unavailable; the dialog being modal is what
   makes it so. */
.player__dialog::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.player__dialog-title {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.2;
}

/* Close is a text button across the bottom of the dialog, after the
   choices: at least 44px tall, and as wide as the dialog. */
.player__dialog-close {
  display: block;
  width: 100%;
  min-height: 2.75rem;
  margin-top: 0.75rem;
  padding: 0 0.9rem;
  border: 1px solid color-mix(in srgb, var(--pac-color-menu-text) 60%, transparent);
  border-radius: 6px;
  background: transparent;
  color: var(--pac-color-menu-text);
  cursor: pointer;
}

.player__dialog-close:hover {
  background: color-mix(in srgb, var(--pac-color-menu-text) 20%, transparent);
}

.player__dialog-close:focus-visible {
  outline: 4px solid var(--pac-color-focus);
  outline-offset: 2px;
}

/* Each choice is a row, at least 44px tall, that its label makes one
   target: the radio button and its text. */
.player__option {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 2.75rem;
  padding: 0 0.4rem;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
}

/* The radio button takes the dialog's text color in place of the browser's
   default field color, like everything else the player paints. Its scroll
   margin is the rest of its row's height: where the dialog scrolls, moving
   to a choice brings the whole row, and the focus indicator drawn around
   it, into view. */
.player__option input {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  color: inherit;
  cursor: pointer;
  scroll-margin-block: 0.75rem;
}

.player__option:hover {
  background: color-mix(in srgb, var(--pac-color-menu-text) 20%, transparent);
}

/* The choice in use: the checked radio button, and a heavier row. */
.player__option:has(input:checked) {
  font-weight: 800;
  background: var(--pac-color-selected-option);
}

/* Focus is drawn around the whole row, inset so the dialog's edge does not
   clip it, rather than around the small radio button alone. */
.player__option input:focus-visible {
  outline: none;
}

.player__option:has(input:focus-visible) {
  outline: 4px solid var(--pac-color-focus);
  outline-offset: -2px;
}

/* Unavailable controls stay visible but read and look disabled. */
.ctl[disabled],
.ctl[aria-disabled="true"] {
  opacity: 0.5;
  cursor: default;
}

@media (forced-colors: active) {
  /* Cues in the system palette, so they keep the user's contrast. */
  .player__media::cue {
    color: CanvasText;
    background: Canvas;
  }

  .player__bar {
    border-top: 1px solid CanvasText;
    background: Canvas;
  }

  .ctl,
  .player__time,
  .time__divider {
    color: CanvasText;
  }

  .ctl[disabled],
  .ctl[aria-disabled="true"] {
    color: GrayText;
    opacity: 1;
  }

  /* The filled captions state in the system palette: text-colored block with
     the lines cut out in the bar's Canvas. */
  [data-control="captions"][data-active] .ctl__icon--captions {
    forced-color-adjust: none;
  }

  [data-control="captions"][data-active] .ctl__icon--captions rect {
    fill: CanvasText;
    stroke: CanvasText;
  }

  [data-control="captions"][data-active] .ctl__icon--captions path {
    stroke: Canvas;
  }

  .ctl:focus-visible,
  .slider:focus-visible,
  .player__dialog-close:focus-visible,
  .player__option:has(input:focus-visible) {
    outline-color: Highlight;
  }

  /* Keep the sliders' authored shapes, in the user's system palette: the
     track, the buffered part, the fill, and a thumb that is always shown.
     Without this narrow opt-out the browser drops the rail's layers. The
     rail takes its colors from these properties, so naming system colors
     here outranks any configured color. */
  .slider {
    forced-color-adjust: none;
    --pac-color-slider-track: GrayText;
    --pac-color-slider-buffer: CanvasText;
    --pac-color-slider-fill: Highlight;
  }

  .slider::-webkit-slider-thumb {
    border-color: Canvas;
    background: CanvasText;
    opacity: 1;
  }

  .slider::-moz-range-thumb {
    border-color: Canvas;
    background: CanvasText;
    opacity: 1;
  }

  /* The dialogs in the system palette: a solid border keeps each distinct
     from the page, the checked radio button is the browser's own, and the
     choice in use keeps its heavier text without a painted background. */
  .player__dialog {
    border: 2px solid CanvasText;
    background: Canvas;
    color: CanvasText;
  }

  .player__dialog-close {
    border-color: ButtonText;
    background: ButtonFace;
    color: ButtonText;
  }

  .player__option:has(input:checked) {
    background: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .slider::-webkit-slider-thumb {
    transition: none;
  }

  .slider::-moz-range-thumb {
    transition: none;
  }
}

/*
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * YouTube pre-play cover
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * js/youtube.js creates this element inside the stage, for a YouTube source
 * only, and removes it on the first play. It sits over the media showing
 * the video's own thumbnail (black until that loads, or if it cannot) so
 * YouTube's painted play button is not a second Play beside ours while the
 * page still previews the video; it is aria-hidden and not focusable, so
 * nothing changes for a screen reader, and a click on it reaches the
 * stage's click-to-play.
 */
.player__cover {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: var(--pac-color-background);
}

/* The video's own thumbnail fills the cover; `cover` crops the letterbox
   bars of the 4:3 fallback frame on the 16:9 stage. */
.player__cover-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/*
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Audio player
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * js/player-config.js marks the player data-media-type="audio" for an audio
 * source. There is no picture, so no stage, and the captions,
 * picture-in-picture, and fullscreen controls are not part of an audio
 * player: they are removed, not shown unavailable.
 */
.player[data-media-type="audio"] .player__stage,
.player[data-media-type="audio"] [data-control="captions"],
.player[data-media-type="audio"] [data-control="pip"],
.player[data-media-type="audio"] [data-control="fullscreen"] {
  display: none;
}

/*
 * The audio bar uses the row's width and never leaves a control alone on a
 * row. Compact (the default) keeps three unbreakable groups, in source order:
 * the transport buttons on a row of their own (the volume slider hidden, as
 * on a narrow video player); the time read-out with the seek slider, which
 * labels it; and the playback-rate and audio-track pair. The timeline and the
 * pair share a row where they fit, and the seek slider grows to fill it.
 * Measured down to a 320px viewport at 200% text, where the timeline needs
 * its narrowest form: a 1.25rem seek minimum and a tighter read-out.
 */
.player[data-media-type="audio"] .player__bar {
  justify-content: center;
}

.player[data-media-type="audio"] .player__group--timeline {
  flex: 1 1 auto;
  flex-wrap: nowrap;
  gap: 0.25rem;
}

.player[data-media-type="audio"] .player__group--extras {
  flex: 0 0 auto;
  flex-wrap: nowrap;
}

.player[data-media-type="audio"] .player__group--timeline .player__time {
  padding: 0 0.1rem;
}

.player[data-media-type="audio"] .player__group--timeline .slider--time {
  flex: 1 1 1.25rem;
  min-width: 1.25rem;
}

/* The four transport buttons make a 2x2 block when a row of four does not
   fit: each button is max(44px, 2rem) square with 0.4rem between, inside the
   bar's 0.6rem padding, so four need max(176px, 8rem) + 2.4rem. */
@container (width < calc(176px + 2.4rem)) or (width < 10.4rem) {
  .player[data-media-type="audio"] .player__group--transport {
    display: grid;
    grid-template-columns: repeat(2, max-content);
    justify-content: center;
  }
}

/* One row with the volume slider where every audio control fits. Measured
   as for the video bar (see the wide tier above), the audio row's narrowest
   fit at default text is 33.9rem (M:SS times), 34.9rem (MM:SS), and 36.6rem
   (H:MM:SS); from 37rem it fits whatever the duration, so it never wraps. */
@container (min-width: 37rem) {
  .player[data-media-type="audio"] .player__bar {
    flex-wrap: nowrap;
  }

  .player[data-media-type="audio"] .player__group {
    display: contents;
  }

  .player[data-media-type="audio"] .player__group .ctl {
    width: auto;
    min-width: 2.75rem;
    height: 2.75rem;
  }

  .player[data-media-type="audio"] .player__group .ctl--rate {
    min-width: 3.2rem;
  }

  .player[data-media-type="audio"] .player__group--transport .slider--volume {
    display: inline-block;
    width: 4rem;
    flex-shrink: 0;
  }

  .player[data-media-type="audio"] .player__group--timeline .slider--time {
    flex: 1 1 4rem;
    min-width: 4rem;
    margin: 0 0.4rem;
  }
}

/*
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Before the first play
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Until a player is first played it shows one control, Play (js/start.js).
 * The player box carries `data-started` from the first request to play, so
 * these rules apply while it is absent, which includes the moment the markup
 * arrives, before any configuration has loaded.
 *
 * `visibility: hidden` takes the other controls and the time read-out off
 * the screen, out of the tab order, and out of the accessibility tree, and
 * leaves each in its place in the layout. That is what keeps Play where it
 * is: its neighbours in the transport group still take their room, so when
 * they appear the button under the viewer's finger has not moved and a
 * second press lands on it. It is set on each control, not on the groups,
 * so Play is never a visible element inside a hidden one.
 *
 * On a wide player the bar is one row, so every control keeps its place and
 * nothing moves at all when the rest appear. On a narrow player the bar
 * would be three rows with two of them empty, so the timeline and extras
 * groups are not laid out until the first play: the bar is the transport row
 * alone, and the other rows arrive below it, where the viewer has just asked
 * for the player to start. The tiers are the bar's own: 44.5rem for a video
 * player and 37rem for an audio player.
 */
.player:not([data-started]) .player__bar [data-control]:not([data-control="play"]),
.player:not([data-started]) .player__bar .player__time {
  visibility: hidden;
}

@container (width < 44.5rem) {
  .player:not([data-started]):not([data-media-type="audio"]) .player__group--timeline,
  .player:not([data-started]):not([data-media-type="audio"]) .player__group--extras {
    display: none;
  }
}

@container (width < 37rem) {
  .player[data-media-type="audio"]:not([data-started]) .player__group--timeline,
  .player[data-media-type="audio"]:not([data-started]) .player__group--extras {
    display: none;
  }
}
