/*
 * Swizzel reader -- Read aloud: the rail button and the player toast. Ported
 * from the designer prototype (styles.css, ".read-aloud-*" and ".t-toast"), with
 * the prototype's values and this app's class names and tokens (swizzel_reader.css
 * for the tokens, the stage and its container queries).
 *
 * The markup is ReadAloudPlayerComponent's and the rail button in
 * ChatSidebarComponent; reader-audio sets the state these rules key off:
 *   - the rail button's data-state:  idle | starting | playing
 *   - the rail download button's wrapper's hidden, and its data-state: idle | busy
 *   - the player's download item's aria-disabled and aria-busy
 *   - the toast's data-open, data-phase and data-speaking
 *   - the stage's data-audio-open (the toast is showing)
 *
 * Departures from the prototype, deliberately:
 *   - The toast is absolutely positioned in the STAGE, not fixed to the window,
 *     so it centres on the article and clears the side panel in focus mode too.
 *   - It has no Previous / Next (one panel at a time), and adds a gate, a message
 *     and Try again for the states the prototype never needed.
 *   - At rest it has no transform or filter (the prototype's blur(0) would make it
 *     the containing block for anything fixed inside it).
 */

.swizzel-reader {
  --read-aloud-swap-dur: 250ms;
  --read-aloud-swap-blur: 2px;
  --read-aloud-swap-scale: 0.25;
  --read-aloud-swap-ease: ease-in-out;
  --read-aloud-toast-open: 350ms;
  --read-aloud-toast-close: 250ms;
  --read-aloud-toast-distance: 16px;
  --read-aloud-toast-blur: 2px;
  --read-aloud-toast-scale: 0.97;
  --read-aloud-toast-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ------------------------------------------------------------ rail button ---
 * Three icons stacked in one cell, cross-fading with the button's data-state. */
.read-aloud-swap {
  position: relative;
  display: inline-grid;
  width: 20px;
  height: 20px;
}

.read-aloud-swap-icon {
  display: grid;
  grid-area: 1 / 1;
  place-items: center;
  opacity: 0;
  filter: blur(var(--read-aloud-swap-blur));
  transform: scale(var(--read-aloud-swap-scale));
  transition:
    opacity var(--read-aloud-swap-dur) var(--read-aloud-swap-ease),
    filter var(--read-aloud-swap-dur) var(--read-aloud-swap-ease),
    transform var(--read-aloud-swap-dur) var(--read-aloud-swap-ease);
}

.swizzel-reader-read-aloud[data-state="idle"] .read-aloud-swap-icon[data-icon="idle"],
.swizzel-reader-read-aloud[data-state="starting"] .read-aloud-swap-icon[data-icon="starting"],
.swizzel-reader-read-aloud[data-state="playing"] .read-aloud-swap-icon[data-icon="playing"],
.read-aloud-play[data-state="play"] .read-aloud-swap-icon[data-icon="play"],
.read-aloud-play[data-state="pause"] .read-aloud-swap-icon[data-icon="pause"],
.read-aloud-play[data-state="loading"] .read-aloud-swap-icon[data-icon="loading"],
.read-aloud-play[data-state="replay"] .read-aloud-swap-icon[data-icon="replay"] {
  opacity: 1;
  filter: blur(0);
  transform: scale(1);
}

.read-aloud-swap svg {
  display: block;
  width: 20px;
  height: 20px;
}

.read-aloud-spinner { animation: read-aloud-spin 0.7s linear infinite; }

/* A spinner that is not showing does not spin. */
.swizzel-reader-read-aloud:not([data-state="starting"]) .read-aloud-spinner,
.read-aloud-play:not([data-state="loading"]) .read-aloud-spinner {
  animation: none;
}

@keyframes read-aloud-spin {
  to { transform: rotate(360deg); }
}

/* Preparing: the ring spins; hover or focus swaps it for the cancel X. */
.read-aloud-load {
  position: relative;
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
}

.read-aloud-load > svg {
  grid-area: 1 / 1;
  transition: opacity 120ms linear;
}

.read-aloud-cancel {
  color: var(--text-quaternary);
  opacity: 0;
  pointer-events: none;
}

/* The prototype's X is the lighter grey, in both of its places. */
.swizzel-reader-read-aloud .read-aloud-swap-icon[data-icon="playing"] svg { color: var(--text-quaternary); }

.swizzel-reader-read-aloud[data-state="starting"]:is(:hover, :focus-visible) .read-aloud-spinner { opacity: 0; }
.swizzel-reader-read-aloud[data-state="starting"]:is(:hover, :focus-visible) .read-aloud-cancel { opacity: 1; }

/* No hover on touch: the X is always there, small, inside the spinning ring so
 * the reader can still see it is working. */
@media (hover: none) {
  .swizzel-reader-read-aloud[data-state="starting"] .read-aloud-cancel {
    opacity: 1;
    transform: scale(0.55);
  }
}

/* Download audio, under the button: only while the panel's audio is all made
 * (reader-audio un-hides it), and its icon a spinner while the file is on its way. */
.swizzel-reader-actions .read-aloud-rail-download-wrap[hidden] { display: none; }

.read-aloud-rail-download[data-state="idle"] .read-aloud-swap-icon[data-icon="idle"],
.read-aloud-rail-download[data-state="busy"] .read-aloud-swap-icon[data-icon="busy"] {
  opacity: 1;
  filter: blur(0);
  transform: scale(1);
}

.read-aloud-rail-download:not([data-state="busy"]) .read-aloud-spinner { animation: none; }
.read-aloud-rail-download[data-state="busy"] { cursor: progress; }

/* A podcast has its own player: the button stays (it keeps its tooltip) but
 * looks off. */
.swizzel-reader .swizzel-reader-read-aloud[aria-disabled="true"] {
  cursor: default;
  opacity: 0.35;
}
.swizzel-reader .swizzel-reader-read-aloud[aria-disabled="true"]:hover { background: transparent; }

/* ----------------------------------------------------------------- toast ---
 * Over the bottom of the stage, centred on the article. `--read-aloud-inset` is
 * how much of the stage's right edge the side panel covers. */
.read-aloud-player {
  --read-aloud-inset: 0px;
  --read-aloud-geometry-dur: var(--panel-close-dur);
  position: absolute;
  right: var(--read-aloud-inset);
  bottom: 32px;
  left: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  width: min(512px, 100% - 112px - var(--read-aloud-inset));
  margin-inline: auto;
  padding: 12px;
  gap: 10px 0;
  box-sizing: border-box;
  color: var(--text-primary);
  background: #fff;
  border: 1px solid rgb(0 0 0 / 8%);
  border-radius: 16px;
  box-shadow:
    0 0 4px rgb(0 0 0 / 4%),
    0 8px 16px rgb(0 0 0 / 4%);
  opacity: 0;
  visibility: hidden;
  filter: blur(var(--read-aloud-toast-blur));
  transform: translateY(var(--read-aloud-toast-distance)) scale(var(--read-aloud-toast-scale));
  pointer-events: none;
  transition:
    opacity var(--read-aloud-toast-close) var(--read-aloud-toast-ease),
    transform var(--read-aloud-toast-close) var(--read-aloud-toast-ease),
    filter var(--read-aloud-toast-close) var(--read-aloud-toast-ease),
    visibility 0s linear var(--read-aloud-toast-close),
    right var(--read-aloud-geometry-dur) var(--panel-ease),
    width var(--read-aloud-geometry-dur) var(--panel-ease),
    bottom var(--read-aloud-geometry-dur) var(--panel-ease);
}

.read-aloud-player[data-open="true"] {
  opacity: 1;
  visibility: visible;
  filter: none;
  transform: none;
  pointer-events: auto;
  transition:
    opacity var(--read-aloud-toast-open) var(--read-aloud-toast-ease),
    transform var(--read-aloud-toast-open) var(--read-aloud-toast-ease),
    filter var(--read-aloud-toast-open) var(--read-aloud-toast-ease),
    visibility 0s linear 0s,
    right var(--read-aloud-geometry-dur) var(--panel-ease),
    width var(--read-aloud-geometry-dur) var(--panel-ease),
    bottom var(--read-aloud-geometry-dur) var(--panel-ease);
}

/* Beside the side panel the toast centres in what is left of the stage, and
 * follows the panel's slide. */
.swizzel-reader-stage[data-panel-open="true"] .read-aloud-player {
  --read-aloud-inset: var(--reader-panel-width);
  --read-aloud-geometry-dur: var(--panel-open-dur);
}

/* reader-panel's instant protocol: state applied with no transitions at all. */
.swizzel-reader-stage.is-instant .read-aloud-player { transition: none !important; }

/* Every direct child spans the toast; the message and Try again share a line. */
.read-aloud-player > * { grid-column: 1 / -1; }
.read-aloud-player > .read-aloud-message { grid-column: 1; align-self: center; }
.read-aloud-player > .read-aloud-retry { grid-column: 2; align-self: center; margin-left: 10px; }

.read-aloud-player :is(.read-aloud-gate, .read-aloud-message, .read-aloud-retry)[hidden] { display: none; }

/* While the article is being read to you, the end of it must not sit under the
 * toast, and the progress pill has nowhere to go. */
.swizzel-reader-stage[data-audio-open="true"] .swizzel-reader-progress { display: none; }
.swizzel-reader-stage[data-audio-open="true"] .swizzel-reader-columns { padding-bottom: 80px; }

/* ---------------------------------------------------- gate, message, retry --- */
.read-aloud-gate {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 2px 2px 0;
}

.read-aloud-gate-text,
.read-aloud-message {
  margin: 0;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 400;
  line-height: 20px;
  letter-spacing: -0.14px;
}

.read-aloud-gate-text { flex: 1 1 auto; min-width: 0; }
.read-aloud-message { padding: 0 2px; }
.read-aloud-message[data-kind="error"] { color: #b42318; }

.read-aloud-gate-link,
.read-aloud-retry {
  display: inline-flex;
  flex: 0 0 auto;
  height: 36px;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  letter-spacing: -0.14px;
  text-decoration: none;
  white-space: nowrap;
}

.read-aloud-gate-link {
  color: #fff;
  background: var(--text-primary);
  transition: background-color 150ms ease-out;
}
.read-aloud-gate-link:hover { background: #292524; }

.read-aloud-retry {
  color: var(--text-primary);
  background: var(--surface-subtle);
  transition: background-color 150ms ease-out;
}
.read-aloud-retry:hover { background: var(--border-secondary); }

.read-aloud-gate-link:focus-visible,
.read-aloud-retry:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* The gate and the error are not players: no transport, no speed, no volume,
 * nothing to download. */
.read-aloud-player:is([data-phase="gate"], [data-phase="error"]) :is(.read-aloud-player-controls, .read-aloud-speed, .read-aloud-volume, .read-aloud-more, .read-aloud-player-progress) {
  display: none;
}

/* With the controls gone, the title gets the row and the close button just its own. */
.read-aloud-player:is([data-phase="gate"], [data-phase="error"]) .read-aloud-player-extras { flex: 0 0 auto; }

/* ------------------------------------------------------------- title row --- */
.read-aloud-player-row {
  display: flex;
  gap: 16px;
  align-items: center;
  width: 100%;
  min-width: 0;
}

.read-aloud-player-meta,
.read-aloud-player-extras {
  display: flex;
  flex: 1 1 0;
  min-width: 0;
  align-items: center;
}

.read-aloud-player-meta {
  gap: 16px;
  padding-left: 2px;
}

.read-aloud-player-extras {
  gap: 4px;
  justify-content: flex-end;
}

.read-aloud-player .read-aloud-player-orb {
  position: relative;
  z-index: 1;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
}

/* The orb turns only while the narration is actually advancing. */
.swizzel-reader .read-aloud-player[data-speaking="true"] .read-aloud-player-orb::before {
  animation-play-state: running;
}

.read-aloud-player-title {
  display: block;
  min-width: 0;
  flex: 1 1 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  color: var(--text-primary);
  background: transparent;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  letter-spacing: -0.14px;
  text-align: left;
  white-space: nowrap;
}

.read-aloud-player-title-text {
  display: inline-block;
  white-space: nowrap;
}

.read-aloud-player-title:hover .read-aloud-player-title-text { text-decoration: underline; }

.read-aloud-player-title:focus-visible {
  border-radius: 4px;
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* A title too long for its slot pans to its end and back; reader-audio adds
 * .is-overflow and sets --title-shift (px, negative) and --title-dur (s). The
 * left edge fades out only while it is panned away from the start. */
@property --title-fade-l {
  syntax: "<number>";
  inherits: false;
  initial-value: 1;
}

.read-aloud-player-title.is-overflow {
  --title-fade-l: 1;
  -webkit-mask-image: linear-gradient(90deg, rgb(0 0 0 / var(--title-fade-l)) 0, #000 20px, #000 calc(100% - 24px), transparent);
  mask-image: linear-gradient(90deg, rgb(0 0 0 / var(--title-fade-l)) 0, #000 20px, #000 calc(100% - 24px), transparent);
  animation: read-aloud-title-edge-fade var(--title-dur, 10s) ease-in-out infinite;
}

.read-aloud-player-title.is-overflow .read-aloud-player-title-text {
  animation: read-aloud-title-pan var(--title-dur, 10s) ease-in-out infinite;
}

@keyframes read-aloud-title-pan {
  0%, 18% { transform: translateX(0); }
  46%, 64% { transform: translateX(var(--title-shift, 0px)); }
  92%, 100% { transform: translateX(0); }
}

@keyframes read-aloud-title-edge-fade {
  0%, 18% { --title-fade-l: 1; }
  28%, 82% { --title-fade-l: 0; }
  92%, 100% { --title-fade-l: 1; }
}

/* -------------------------------------------------------------- controls --- */
.read-aloud-player-controls {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.swizzel-reader .read-aloud-player .icon-button {
  width: 36px;
  height: 36px;
  padding: 8px;
}

/* The prototype's volume icon is the tertiary grey; the close button matches it. */
.swizzel-reader .read-aloud-player :is(.read-aloud-volume .icon-button, .read-aloud-close) {
  color: var(--text-tertiary);
}

.read-aloud-play {
  display: inline-grid;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  place-items: center;
  padding: 8px;
  color: #0c0a09;
  background: var(--surface-subtle);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 150ms ease-out;
}
.read-aloud-play:hover { background: var(--border-secondary); }
.read-aloud-play:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 0;
}

/* Getting the first audio: nothing to press yet, nowhere to seek. Buffering
 * mid-listen is different -- the reader can still pause, and seek. */
.read-aloud-player[data-phase="starting"] .read-aloud-play,
.read-aloud-player[data-phase="starting"] .read-aloud-seek {
  cursor: default;
  pointer-events: none;
}

.read-aloud-speed,
.read-aloud-volume {
  position: relative;
  flex: 0 0 auto;
}

.read-aloud-speed-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 6px;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  letter-spacing: -0.14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: background-color 150ms ease-out, color 150ms ease-out;
}
.read-aloud-speed-btn:hover {
  color: var(--text-primary);
  background: var(--surface-subtle);
}
.read-aloud-speed-btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 0;
}

/* The "..." menu's popover (reader-menu toggles .is-open), opening upward from
 * the button and scaling in from its corner as the prototype's dropdowns do. */
.read-aloud-speed-menu.menu-field-popover {
  top: auto;
  right: -4px;
  bottom: calc(100% + 8px);
  left: auto;
  min-width: 112px;
  max-width: 140px;
  max-height: none;
  padding: 4px;
  transform: scale(0.97);
  transform-origin: bottom right;
  transition:
    transform 150ms var(--read-aloud-toast-ease),
    opacity 150ms var(--read-aloud-toast-ease),
    visibility 0s linear 150ms;
}
.read-aloud-speed-menu.menu-field-popover.is-open {
  transform: none;
  transition:
    transform 250ms var(--read-aloud-toast-ease),
    opacity 250ms var(--read-aloud-toast-ease),
    visibility 0s linear 0s;
}

.read-aloud-speed-menu .menu-field-option {
  font-variant-numeric: tabular-nums;
}
.read-aloud-speed-menu .menu-field-option[aria-checked="true"] {
  font-weight: 600;
}

/* The "..." menu opens upward the same way. */
.read-aloud-more {
  position: relative;
  flex: 0 0 auto;
}

.read-aloud-more-menu.menu-field-popover {
  top: auto;
  right: -4px;
  bottom: calc(100% + 8px);
  left: auto;
  min-width: 224px;
  max-height: none;
  padding: 4px;
  transform: scale(0.97);
  transform-origin: bottom right;
  transition:
    transform 150ms var(--read-aloud-toast-ease),
    opacity 150ms var(--read-aloud-toast-ease),
    visibility 0s linear 150ms;
}
.read-aloud-more-menu.menu-field-popover.is-open {
  transform: none;
  transition:
    transform 250ms var(--read-aloud-toast-ease),
    opacity 250ms var(--read-aloud-toast-ease),
    visibility 0s linear 0s;
}

/* Download audio, in the toast's menu: its icon turns into a spinner while the
 * file is on its way, and it says why it is off until all the audio is made
 * (aria-disabled, so that it can still be reached and read out). */
.read-aloud-download { gap: 8px; }

.read-aloud-download-icon {
  display: grid;
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  place-items: center;
  color: var(--text-secondary);
}
.read-aloud-download-icon > svg { grid-area: 1 / 1; }

.read-aloud-download:not([aria-busy="true"]) .read-aloud-spinner,
.read-aloud-download[aria-busy="true"] .read-aloud-download-icon > svg:not(.read-aloud-spinner) {
  display: none;
}

.read-aloud-download[aria-busy="true"] { cursor: progress; }

.read-aloud-download-text {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.read-aloud-download-hint {
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 400;
  line-height: 16px;
  letter-spacing: 0;
  text-wrap: balance;
}

.read-aloud-download:not([aria-disabled="true"]) .read-aloud-download-hint { display: none; }

.read-aloud-download[aria-disabled="true"] { cursor: default; }
.read-aloud-download[aria-disabled="true"]:hover { background: transparent; }
.read-aloud-download[aria-disabled="true"] :is(.read-aloud-download-icon, .menu-field-option-label) { opacity: 0.45; }

.read-aloud-volume-menu {
  position: absolute;
  right: -4px;
  bottom: calc(100% + 8px);
  z-index: 6;
  display: flex;
  width: 40px;
  height: 120px;
  align-items: center;
  justify-content: center;
  padding: 12px 0;
  overflow: hidden;
  box-sizing: border-box;
  background: #fff;
  border: 1px solid var(--border-secondary);
  border-radius: 12px;
  box-shadow:
    0 8px 16px -3px rgb(0 0 0 / 8%),
    0 4px 6px -4px rgb(0 0 0 / 12%);
  opacity: 0;
  visibility: hidden;
  transform: scale(0.97);
  transform-origin: bottom right;
  transition:
    transform 150ms var(--read-aloud-toast-ease),
    opacity 150ms var(--read-aloud-toast-ease),
    visibility 0s linear 150ms;
}
.read-aloud-volume-menu.is-open {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition:
    transform 250ms var(--read-aloud-toast-ease),
    opacity 250ms var(--read-aloud-toast-ease),
    visibility 0s linear 0s;
}

.read-aloud-volume.is-muted .icon-button { opacity: 0.45; }

/* A vertical slider: the filled part is --progress (reader-audio sets it). */
.read-aloud-volume-slider {
  width: 16px;
  height: 88px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
  direction: rtl;
  writing-mode: vertical-lr;
}
.read-aloud-volume-slider::-webkit-slider-runnable-track {
  width: 3px;
  background:
    linear-gradient(#0c0a09, #0c0a09) bottom / 100% var(--progress, 100%) no-repeat,
    #e7e5e4;
  border-radius: 999px;
}
.read-aloud-volume-slider::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
  margin-inline-start: -6.5px;
  appearance: none;
  background: transparent;
  border: 0;
  box-shadow: none;
}
.read-aloud-volume-slider::-moz-range-track {
  width: 3px;
  background: #e7e5e4;
  border: 0;
  border-radius: 999px;
}
.read-aloud-volume-slider::-moz-range-progress {
  width: 3px;
  background: #0c0a09;
  border-radius: 999px;
}
.read-aloud-volume-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: transparent;
  border: 0;
  box-shadow: none;
  opacity: 0;
}
.read-aloud-volume-slider:focus-visible {
  border-radius: 4px;
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* -------------------------------------------------------------- progress --- */
.read-aloud-player-progress {
  display: flex;
  gap: 16px;
  align-items: center;
  width: 100%;
}

.read-aloud-player-progress > span {
  flex: 0 0 40px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 400;
  line-height: 20px;
  letter-spacing: -0.14px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* The filled part is --progress (reader-audio sets it). The thumb shows on
 * hover and focus only. */
.read-aloud-seek {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  height: 16px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
.read-aloud-seek:focus-visible { outline: none; }
.read-aloud-seek::-webkit-slider-runnable-track {
  height: 3px;
  background:
    linear-gradient(#0c0a09, #0c0a09) 0 / var(--progress, 0%) 100% no-repeat,
    #e7e5e4;
  border-radius: 999px;
}
.read-aloud-seek::-webkit-slider-thumb {
  width: 12px;
  height: 12px;
  margin-top: -4.5px;
  appearance: none;
  background: #0c0a09;
  border: 0;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 120ms ease;
}
.read-aloud-seek:hover::-webkit-slider-thumb,
.read-aloud-seek:focus-visible::-webkit-slider-thumb { opacity: 1; }
.read-aloud-seek::-moz-range-track {
  height: 3px;
  background: #e7e5e4;
  border: 0;
  border-radius: 999px;
}
.read-aloud-seek::-moz-range-progress {
  height: 3px;
  background: #0c0a09;
  border-radius: 999px;
}
.read-aloud-seek::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: #0c0a09;
  border: 0;
  border-radius: 50%;
  opacity: 0;
}
.read-aloud-seek:hover::-moz-range-thumb,
.read-aloud-seek:focus-visible::-moz-range-thumb { opacity: 1; }

/* ---------------------------------------------------- container queries ---
 * On the stage's width, as swizzel_reader.css does. */
@container swizzel-reader (max-width: 880px) {
  .read-aloud-player { bottom: 16px; }

  /* The side panel is a bottom sheet here: the toast rides above it. */
  .swizzel-reader-stage[data-panel-open="true"] .read-aloud-player {
    --read-aloud-inset: 0px;
    bottom: calc(var(--reader-sheet-offset) + 16px);
  }
}

@container swizzel-reader (max-width: 600px) {
  /* Above the minds bar, nearly the stage's width. Volume is the device's. */
  .read-aloud-player {
    right: 12px;
    bottom: 76px;
    left: 12px;
    width: auto;
    margin-inline: 0;
  }
  .read-aloud-volume { display: none; }

  /* In the actions bar along the bottom, the minds bar gives up the room of the
   * fifth button while it shows. */
  .swizzel-reader-stage:has(.read-aloud-rail-download-wrap:not([hidden])) .swizzel-reader-minds { max-width: calc(100% - 252px); }

  /* Under the open sheet there is no room for a player, but a gate or an error
   * is something the reader has to see. */
  .swizzel-reader-stage[data-panel-open="true"] .read-aloud-player:not([data-phase="gate"], [data-phase="error"]) {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }
  .swizzel-reader-stage[data-panel-open="true"] .read-aloud-player:is([data-phase="gate"], [data-phase="error"]) {
    bottom: calc(var(--reader-sheet-offset) + 76px);
  }
}

/* -------------------------------------------------------- reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  .swizzel-reader :is(.read-aloud-player, .read-aloud-swap-icon, .read-aloud-load > svg, .read-aloud-volume-menu, .read-aloud-speed-menu,
                      .read-aloud-more-menu) {
    transition: none !important;
  }
  .read-aloud-seek::-webkit-slider-thumb { transition: none; }
  .swizzel-reader .read-aloud-spinner { animation: none; }
  .read-aloud-player-title.is-overflow {
    --title-fade-l: 1;
    animation: none;
  }
  .read-aloud-player-title.is-overflow .read-aloud-player-title-text { animation: none; }
}

/* ----------------------------------------------------------------- print --- */
@media print {
  .swizzel-reader-read-aloud,
  .read-aloud-player {
    display: none !important;
  }
}

/* ------------------------------------------------- the word being read --- */
/* Painted by the CSS Custom Highlight API (utils/read_aloud/highlighter.js): no
   element is added to the text, so nothing in the page, and nothing a highlight
   or note anchors to, changes. */
::highlight(swizzel-read-aloud) {
  background-color: rgb(250 204 21 / 45%);
  color: inherit;
}

/* Where that API is missing the paragraph being read is marked instead. */
.swizzel-reader [data-read-aloud-block] {
  background: rgb(250 204 21 / 22%);
  border-radius: 3px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  transition: background 120ms linear;
}

@media print {
  ::highlight(swizzel-read-aloud) { background-color: transparent; }
  .swizzel-reader [data-read-aloud-block] { background: none; }
}
