:root {
  /* Android Color.kt and MediaPagerScreen.kt player chrome are the source of truth. */
  --qp-brand-action: #79afc1;
  --qp-brand-action-rgb: 121, 175, 193;
  --qp-player-action: #83dcf4;
  --qp-player-action-rgb: 131, 220, 244;
  --qp-chrome: #111a2a;
  --qp-chrome-rgb: 17, 26, 42;
  --qp-canvas-top: #182134;
  --qp-canvas-bottom: #0b1019;
  --qp-text: #f5f7fa;
  --qp-text-secondary: #b4c0c9;
  --qp-outline: rgba(255, 255, 255, 0.18);
  --qp-error: #f06e4f;
  --qp-on-error: #ffc8af;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  font-family: "Roboto", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
}

body {
  color: var(--qp-text);
}

.receiver-backdrop {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  background: linear-gradient(180deg, var(--qp-canvas-top), var(--qp-chrome) 52%, var(--qp-canvas-bottom));
  transition: opacity 200ms ease, visibility 200ms ease;
}

.receiver-video {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: transparent;
}

.receiver-photo-detail {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
  visibility: hidden;
}

body.is-image .receiver-photo-detail { visibility: visible; }
.receiver-photo-detail > img {
  position: absolute;
  max-width: none;
  max-height: none;
  background: #000;
  transition: opacity 120ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .receiver-photo-detail > img { transition: none; }
}

.receiver-image {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 200ms ease;
}

/* The retained photo canvas owns replacement timing, including instant cuts.
   Never leave a startup backdrop fading above an already presented photo. */
body.is-photo-replacement .receiver-backdrop {
  transition: none;
}

/* Replacement loads use the badge; preserve initial startup and error feedback. */
body.has-presented-media.is-loading .receiver-center,
body.has-presented-media.is-buffering .receiver-center,
body.has-presented-media.is-video.is-video-not-ready:not(.is-error) .receiver-center {
  opacity: 0;
  visibility: hidden;
}

body.is-audio.is-audio-transcript .receiver-center {
  opacity: 0;
  visibility: hidden;
}

body.is-image .receiver-image {
  opacity: 1;
  visibility: visible;
}

body.is-image .receiver-video {
  opacity: 0;
  visibility: hidden;
}

body.is-video.is-playing.is-chrome-hidden .receiver-backdrop,
body.is-video.is-playing.is-chrome-hidden .receiver-center,
body.is-video.is-playing.is-chrome-hidden .receiver-badge,
body.is-image.is-chrome-hidden .receiver-badge {
  opacity: 0;
  visibility: hidden;
}

body.is-video.is-video-ready:not(.is-error) .receiver-backdrop {
  opacity: 0;
  visibility: hidden;
}

body.is-image.is-video-ready:not(.is-loading):not(.is-buffering):not(.is-error) .receiver-backdrop {
  opacity: 0;
  visibility: hidden;
}

.receiver-center {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}

/* One retained visual above incoming media and below status/error chrome. */
.receiver-transition {
  position: absolute;
  inset: 0;
  z-index: 4;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  overflow: hidden;
  background: linear-gradient(180deg, var(--qp-canvas-top), var(--qp-chrome) 52%, var(--qp-canvas-bottom));
}

.receiver-transition > canvas,
.receiver-transition > div,
.receiver-transition-image {
  width: 100%;
  height: 100%;
}

.receiver-transition > canvas,
.receiver-transition-image {
  position: absolute;
  inset: 0;
  display: block !important;
  visibility: visible !important;
  opacity: 1;
  object-fit: contain;
}

.receiver-transition .receiver-spinner,
.receiver-transition .receiver-visualizer { display: none !important; }

body.is-video.is-video-ready:not(.is-error) .receiver-center,
body.is-image:not(.is-loading):not(.is-buffering):not(.is-error) .receiver-center,
body.is-playing.is-video.is-video-ready .receiver-center,
body.is-playing.is-image .receiver-center,
body.is-showing:not(.is-audio) .receiver-center {
  opacity: 0;
  transform: translateY(10px);
  visibility: hidden;
}

body.is-error .receiver-panel {
  border-color: var(--qp-error);
}

body.is-error .receiver-kicker,
body.is-error .receiver-badge__status {
  color: var(--qp-on-error);
}

body.is-error .receiver-badge__spark {
  background: var(--qp-error);
}

.receiver-panel {
  display: grid;
  grid-template-columns: 164px minmax(0, 1fr);
  gap: 28px;
  width: min(820px, calc(100vw - 96px));
  padding: 30px;
  border: 1px solid var(--qp-outline);
  border-radius: 24px;
  background: rgba(var(--qp-chrome-rgb), 0.94);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.20);
}

.receiver-panel__art {
  min-height: 148px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.receiver-mark {
  position: relative;
  width: 86px;
  height: 86px;
  border-radius: 22px;
  object-fit: contain;
}

.receiver-visualizer {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 20px;
  display: none;
  align-items: end;
  justify-content: center;
  gap: 8px;
  height: 44px;
}

.receiver-visualizer span {
  width: 8px;
  height: 42px;
  transform-origin: bottom;
  border-radius: 999px;
  background: var(--qp-player-action);
  animation: receiver-eq 900ms ease-in-out infinite alternate;
  animation-play-state: paused;
}

.receiver-visualizer span:nth-child(2) {
  animation-delay: 120ms;
}

.receiver-visualizer span:nth-child(3) {
  animation-delay: 240ms;
}

.receiver-visualizer span:nth-child(4) {
  animation-delay: 80ms;
}

.receiver-visualizer span:nth-child(5) {
  animation-delay: 180ms;
}

body.is-audio .receiver-mark {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  align-self: start;
  margin-top: 8px;
}

body.is-audio .receiver-visualizer {
  display: flex;
}

body.is-audio.is-playing .receiver-visualizer span {
  animation-play-state: running;
}

.receiver-panel__copy {
  min-width: 0;
  align-self: center;
}

.receiver-kicker {
  color: var(--qp-text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.receiver-title {
  margin: 12px 0 0;
  max-width: 14ch;
  font-size: clamp(2.1rem, 4.2vw, 4rem);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: 0;
  text-wrap: balance;
}

body.is-audio .receiver-title {
  max-width: 18ch;
  font-size: clamp(2rem, 3.6vw, 3.9rem);
}

.receiver-detail {
  max-width: 46rem;
  margin: 16px 0 0;
  color: var(--qp-text-secondary);
  font-size: clamp(1rem, 1.4vw, 1.18rem);
  line-height: 1.55;
}

.receiver-spinner {
  width: 54px;
  height: 54px;
  margin-top: 24px;
  border: 4px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--qp-player-action);
  border-right-color: rgba(var(--qp-player-action-rgb), 0.45);
  border-radius: 999px;
  opacity: 0;
  animation: none;
  transition: opacity 180ms ease;
}

body.is-loading .receiver-spinner {
  opacity: 1;
  animation: receiver-spin 900ms linear infinite;
}

.receiver-badge {
  position: absolute;
  z-index: 4;
  top: 28px;
  left: 28px;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 26px;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(var(--qp-chrome-rgb), 0.70);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  transition: opacity 420ms ease, transform 420ms ease, visibility 420ms ease;
}

.receiver-badge__spark {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--qp-text-secondary);
}

body.is-playing .receiver-badge__spark,
body.is-showing .receiver-badge__spark,
body.is-loading .receiver-badge__spark,
body.is-buffering .receiver-badge__spark {
  background: var(--qp-player-action);
}

body.is-loading .receiver-badge__spark {
  animation: receiver-pulse 900ms ease-in-out infinite alternate;
}

.receiver-badge__logo {
  display: block;
  width: 156px;
  height: auto;
  object-fit: contain;
}

.receiver-badge__status {
  color: var(--qp-text-secondary);
  font-size: 0.92rem;
  font-weight: 500;
}

.receiver-playback {
  position: absolute;
  z-index: 4;
  left: max(48px, 5vw);
  right: max(48px, 5vw);
  bottom: max(34px, 5vh);
  display: grid;
  gap: 12px;
  padding: 16px 18px 14px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 18px;
  background: rgba(var(--qp-chrome-rgb), 0.70);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.20);
  pointer-events: none;
  opacity: 0;
  transform: translateY(12px);
  visibility: hidden;
  transition: opacity 420ms ease, transform 420ms ease, visibility 420ms ease;
}

body.is-video.is-chrome-visible .receiver-playback,
body.is-video.is-paused .receiver-playback,
body.is-video.is-buffering .receiver-playback,
body.is-audio .receiver-playback {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
}

/* Opt-in comparison: keep startup/error feedback and CAF captions, but let the
   device supply controls once a video frame is ready. This does not create or
   force the system overlay, and is never selected automatically. */
body.is-system-video-controls-trial.is-video.is-video-ready:is(.is-playing, .is-paused) .receiver-playback,
body.is-system-video-controls-trial.is-video.is-video-ready:is(.is-playing, .is-paused) .receiver-badge,
body.is-system-video-controls-trial.is-video.is-video-ready:is(.is-playing, .is-paused) .receiver-center {
  opacity: 0;
  visibility: hidden;
  transition: none;
}

body.is-audio .receiver-playback {
  left: 50%;
  right: auto;
  width: min(780px, calc(100vw - 96px));
  transform: translate(-50%, 0);
}

body.is-audio .receiver-playback__title {
  display: none;
}

.receiver-playback__copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-width: 0;
}

.receiver-playback__title {
  overflow: hidden;
  color: var(--qp-text);
  font-size: clamp(1rem, 1.7vw, 1.3rem);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.receiver-playback__time {
  flex: 0 0 auto;
  color: var(--qp-text-secondary);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.receiver-playback__bar {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.receiver-playback__bar span {
  display: block;
  width: 100%;
  transform: scaleX(0);
  transform-origin: left;
  height: 100%;
  border-radius: inherit;
  background: var(--qp-player-action);

  transition: transform 160ms linear;
}

.receiver-captions {
  position: fixed;
  left: 50%;
  bottom: max(12.5rem, 20vh);
  z-index: 4;
  max-width: min(74vw, 58rem);
  padding: 0.62rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0.55rem;
  background: rgba(var(--qp-chrome-rgb), 0.76);
  color: #ffffff;
  font-size: clamp(1.1rem, 2.2vw, 2rem);
  line-height: 1.28;
  text-align: center;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.72);
  white-space: pre-line;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 180ms ease;
}

body.is-audio .receiver-captions {
  top: max(8rem, 15vh);
  bottom: auto;
  display: grid;
  gap: 0.55rem;
  width: min(760px, calc(100vw - 7rem));
  max-width: none;
  max-height: 40vh;
  overflow: hidden;
  padding: 1rem;
  border-radius: 1.1rem;
  background: rgba(var(--qp-chrome-rgb), 0.82);
  text-align: left;
}

body.is-video .receiver-captions__line {
  padding: 0;
  border: 0;
  background: transparent;
  color: #ffffff;
  font-size: inherit;
  font-weight: 600;
}

.receiver-captions__line {
  padding: 0.55rem 0.72rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.82rem;
  background: rgba(255, 255, 255, 0.06);
  color: var(--qp-text-secondary);
  font-size: clamp(1rem, 1.55vw, 1.36rem);
  line-height: 1.34;
}

.receiver-captions__line--active {
  border-color: rgba(var(--qp-brand-action-rgb), 0.64);
  background: rgba(var(--qp-brand-action-rgb), 0.16);
  color: #ffffff;
  font-weight: 600;
}

.receiver-captions:not(:empty) {
  opacity: 1;
}

.receiver-captions--custom .receiver-captions__line {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  border: 0;
  background: transparent;
}

.receiver-captions--custom .receiver-captions__line:not(.receiver-captions__line--active) {
  opacity: 0.65;
}

/* Audio reading takes over the canvas, with a stable text size and no art behind it. */
body.is-audio.is-audio-transcript .receiver-captions {
  top: max(7rem, 14vh);
  bottom: max(10rem, 21vh) !important;
  width: min(1040px, 82vw);
  max-height: none;
  padding: 1rem 2rem !important;
  gap: 1rem;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  text-align: left;
  line-height: 1.4 !important;
}

body.is-audio-transcript .receiver-captions__line {
  padding: 0.35rem 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: inherit;
  line-height: 1.4;
}

body.is-audio-transcript .receiver-captions__line:not(.receiver-captions__line--active) {
  opacity: 0.58;
  font-weight: 400;
}

body.is-audio-transcript .receiver-captions__line--active {
  color: var(--qp-brand-action);
  opacity: 1;
  font-weight: 700;
}

body.is-audio-transcript .receiver-playback__title {
  display: block;
}

.receiver-debug {
  position: absolute;
  right: 20px;
  bottom: 20px;
  z-index: 5;
  max-width: min(620px, calc(100vw - 40px));
  padding: 12px 14px;
  border: 1px solid rgba(var(--qp-brand-action-rgb), 0.7);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.88);
  color: var(--qp-text);
  font-family: "Consolas", "SFMono-Regular", monospace;
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
  pointer-events: none;
  box-shadow: 0 14px 48px rgba(0, 0, 0, 0.42);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

body.is-debug-expanded .receiver-debug {
  opacity: 1;
  transform: translateY(0);
}

@keyframes receiver-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes receiver-pulse {
  from {
    opacity: 0.46;
    transform: scale(0.86);
  }
  to {
    opacity: 1;
    transform: scale(1.08);
  }
}

@keyframes receiver-eq {
  from {
    transform: scaleY(0.33);
  }
  to {
    transform: scaleY(1);
  }
}

@media (max-width: 760px) {
  .receiver-center {
    padding: 28px;
  }

  .receiver-panel {
    width: min(100%, calc(100vw - 56px));
    grid-template-columns: 1fr;
    gap: 18px;
    padding: 24px;
    margin: 0;
  }

  .receiver-panel__art {
    min-height: 112px;
  }

  .receiver-title,
  body.is-audio .receiver-title {
    max-width: 15ch;
    font-size: clamp(2rem, 11vw, 3.4rem);
  }
}
