/* ==========================================================================
   Media — Moey's audio / video player and click-to-load embeds (moey.js).
   ========================================================================== */

/* Player ------------------------------------------------------------------------ */
.player {
  container-type: inline-size;              /* its own width decides what fits */
  white-space: normal;                      /* inside a chat bubble (pre-wrap) the markup's line breaks must not show */
  position: relative;
  display: grid;
  overflow: hidden;
  color: var(--mo-fg-body);
  background: var(--mo-bg-surface);
  border-radius: var(--mo-radius-card);
  outline: none;
}
.player:focus-visible { box-shadow: 0 0 0 var(--mo-focus-ring-width) var(--mo-theme-focus-ring); }
.player-video { color: #fff; background: #000; }
.player-video > video { display: block; width: 100%; height: auto; max-height: 80dvh; cursor: pointer; }
.player-bar { display: flex; flex-wrap: wrap; gap: .125rem .25rem; align-items: center; min-width: 0; min-height: 3rem; padding: .375rem .5rem; }   /* min-width 0: a range input is 129px wide by nature — the bar must still fit a narrow player */
.player-video .player-bar {
  position: absolute;
  inset: auto 0 0;
  padding: 2rem .5rem max(.375rem, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgb(0 0 0 / .65));
  transition: opacity .25s, translate .25s;
}
.player-video.is-playing:not(.is-active) .player-bar { opacity: 0; translate: 0 .5rem; pointer-events: none; }
.player-video.is-playing:not(.is-active) > video { cursor: none; }
.player-btn {
  display: inline-grid;
  flex: none;
  place-items: center;
  min-width: 2.5rem;
  height: 2.5rem;
  padding: 0 .375rem;
  font: inherit;
  font-size: 1.125rem;
  color: inherit;
  cursor: pointer;
  background: none;
  border: 0;
  border-radius: 999px;
}
.player-btn:hover { background: color-mix(in oklab, currentcolor 12%, transparent); }
.player-btn:focus-visible { outline: var(--mo-focus-ring-width) solid var(--mo-theme-focus-ring); }
.player-speed { min-width: 3rem; font-size: .8125rem; font-weight: var(--mo-font-weight-semibold); font-variant-numeric: tabular-nums; }
.player-btn[aria-pressed="true"] { background: color-mix(in oklab, currentcolor 18%, transparent); }
.player-time { flex: none; padding: 0 .375rem; font-size: .8125rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.player-dur { opacity: .7; }
/* The seek bar and the volume: thin, with a played part and a buffered part */
.player :is(.player-seek, .player-volume) {
  --pl-fill: 0%;
  --pl-buffer: 0%;
  --pl-track: color-mix(in oklab, currentcolor 22%, transparent);
  height: 1.5rem;
  margin: 0;
  cursor: pointer;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
}
.player-seek { flex: 1 1 8rem; min-width: 6rem; }
/* Can't play: the message takes the place of the time and the seek bar */
.player-error { display: none; flex: 1 1 8rem; gap: .5rem; align-items: center; min-width: 0; padding: 0 .375rem; font-size: .8125rem; color: var(--mo-red-fg); }
.player-error > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-video .player-error { color: #fff; }
.player.is-error .player-error { display: flex; }
.player.is-error :is(.player-time, .player-seek) { display: none; }
.player.is-error .player-bar { opacity: 1; translate: none; pointer-events: auto; }
.player-retry { flex: none; padding: .25rem .5rem; margin-inline-start: auto; font: inherit; font-weight: var(--mo-font-weight-medium); color: inherit; cursor: pointer; background: color-mix(in oklab, currentcolor 12%, transparent); border: 0; border-radius: var(--mo-radius-control); }
.player-retry:hover { background: color-mix(in oklab, currentcolor 20%, transparent); }
.player-retry:focus-visible { outline: var(--mo-focus-ring-width) solid var(--mo-theme-focus-ring); outline-offset: 1px; }
.player-volume { flex: 0 0 5rem; }
.player :is(.player-seek, .player-volume)::-webkit-slider-runnable-track { height: 4px; background: linear-gradient(90deg, currentcolor var(--pl-fill), color-mix(in oklab, currentcolor 40%, transparent) var(--pl-fill) var(--pl-buffer), var(--pl-track) var(--pl-buffer)); border-radius: 2px; }
.player :is(.player-seek, .player-volume)::-moz-range-track { height: 4px; background: linear-gradient(90deg, currentcolor var(--pl-fill), color-mix(in oklab, currentcolor 40%, transparent) var(--pl-fill) var(--pl-buffer), var(--pl-track) var(--pl-buffer)); border-radius: 2px; }
.player :is(.player-seek, .player-volume)::-webkit-slider-thumb { width: 14px; height: 14px; margin-top: -5px; background: currentcolor; border: 0; border-radius: 50%; -webkit-appearance: none; }
.player :is(.player-seek, .player-volume)::-moz-range-thumb { width: 14px; height: 14px; background: currentcolor; border: 0; border-radius: 50%; }
.player :is(.player-seek, .player-volume):focus-visible { outline: var(--mo-focus-ring-width) solid var(--mo-theme-focus-ring); outline-offset: 2px; border-radius: 4px; }
/* The big play button over a video that hasn't started */
.player-big {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 4rem;
  height: 4rem;
  padding: 0;
  font-size: 1.75rem;
  color: #fff;
  cursor: pointer;
  background: rgb(0 0 0 / .55);
  border: 0;
  border-radius: 999px;
  translate: -50% -50%;
  backdrop-filter: blur(6px);
}
.player-big:hover { background: rgb(0 0 0 / .7); }
.player-big:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.player-big[hidden] { display: none; }
/* Audio: cover + title on top, the bar below */
.player-audio { gap: .25rem; padding: .5rem; }
.player-head { display: flex; gap: .75rem; align-items: center; padding: .25rem .25rem 0; }
.player-cover { flex: none; width: 3.5rem; height: 3.5rem; object-fit: cover; border-radius: .625rem; }
.player-title { font-weight: var(--mo-font-weight-semibold); line-height: 1.3; }
.player-sub { font-size: .8125rem; color: var(--mo-fg-3); }
.player-audio > audio { display: none; }
/* Narrow players: the volume slider goes (mute stays) */
@container (width < 28rem) { .player-volume, .player-wide { display: none; } }
/* Compact (voice notes, a narrow column): one row — play, seek, one time, speed. The time is the length until it
   starts, then where it is (like messaging apps). */
@container (width < 22rem) {
  .player-bar { flex-wrap: nowrap; }
  .player-seek { flex: 1 1 0; min-width: 2.5rem; }
  .player-time { padding: 0 .25rem; }
  .player-slash { display: none; }
  .player:is(.is-playing, .is-started) .player-dur,
  .player:not(.is-playing, .is-started) .player-cur { display: none; }
  .player-dur { opacity: 1; }
}
/* Very narrow (a voice note on the smallest phones): play, seek and time are what matter; speed steps aside */
@container (width < 12rem) { .player-speed { display: none; } .player-bar { padding-inline: .25rem; } }
/* Phones: the volume slider goes (phones use their own buttons); the rest stays big */
@media (width < 576px) {
  .player-volume, .player-wide { display: none; }
}
@media (prefers-reduced-motion: reduce) { .player-video .player-bar { transition: none; } }

/* Embeds ------------------------------------------------------------------------------- */
.embed {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  color: #fff;
  text-decoration: none;
  background: #111 center / cover no-repeat;
  border-radius: var(--mo-radius-card);
}
.embed-4x3 { aspect-ratio: 4 / 3; }
.embed-1x1 { aspect-ratio: 1; }
.embed-9x16 { aspect-ratio: 9 / 16; max-width: 22rem; }
.embed > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.embed > iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.embed:not(.is-loaded)::before { position: absolute; inset: 0; content: ""; background: linear-gradient(transparent 40%, rgb(0 0 0 / .55)); }
.embed-play { position: relative; display: grid; place-items: center; width: 4rem; height: 4rem; font-size: 1.75rem; background: rgb(0 0 0 / .6); border-radius: 999px; transition: scale var(--mo-duration) var(--mo-ease), background var(--mo-duration); }
.embed-play:empty::before { width: 1.5rem; height: 1.5rem; margin-inline-start: .25rem; content: ""; background: #fff; clip-path: polygon(10% 0, 100% 50%, 10% 100%); }
.embed:hover .embed-play { background: rgb(0 0 0 / .8); scale: 1.06; }
.embed:focus-visible { outline: var(--mo-focus-ring-width) solid var(--mo-theme-focus-ring); outline-offset: 2px; }
.embed-title { position: absolute; inset: auto 0 0; padding: .75rem 1rem; font-weight: var(--mo-font-weight-semibold); text-shadow: 0 1px 2px rgb(0 0 0 / .5); }
.embed-note { position: absolute; inset: .5rem .75rem auto auto; padding: .125rem .5rem; font-size: .6875rem; background: rgb(0 0 0 / .55); border-radius: 999px; }
