:root {
  --message-media-max-width: 90vw;
  --message-media-max-height: 400px;
}

/* The row uses all of its existing 90% allowance. The avatar, when present,
   consumes part of this width; the bubble receives only the remainder. */
.cp-msg.cp-msg-media {
  box-sizing: border-box;
  width: min(90%, var(--message-media-max-width));
  max-width: min(90%, var(--message-media-max-width));
}

.cp-msg-media > .cp-bubble-media,
.cp-msg-media > .ch-media-col,
.cp-msg-media > .ch-media-col > .cp-bubble-media {
  box-sizing: border-box;
  min-width: 0;
  width: 100%;
  max-width: min(100%, var(--message-media-max-width)) !important;
}

.cp-msg-media > .cp-bubble-media,
.cp-msg-media > .ch-media-col {
  flex: 1 1 auto;
}

.cp-bubble-media {
  box-sizing: border-box;
  padding: 1px !important;
  border: 1px solid rgba(0, 0, 0, 0.13) !important;
  box-shadow: 0 3px 2px rgba(0, 0, 0, 0.13) !important;
  max-width: min(100%, var(--message-media-max-width)) !important;
}

.cp-media-frame,
.cp-media-album {
  box-sizing: border-box;
  width: 100%;
  max-width: min(100%, var(--message-media-max-width));
  max-height: var(--message-media-max-height);
  overflow: hidden;
}

.cp-media-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 60px;
  max-height: var(--message-media-max-height);
  overflow: hidden;
  border-radius: 13px;
  background: #111;
  cursor: pointer;
  -webkit-touch-callout: none;
}

.cp-media-wrap-lqip {
  flex-shrink: 0;
  min-height: unset !important;
}

.cp-media-backdrop {
  position: absolute;
  inset: -10%;
  z-index: 0;
  width: 120%;
  height: 120%;
  object-fit: cover;
  object-position: center;
  filter: blur(24px) saturate(1.08);
  transform: scale(1.16);
  pointer-events: none;
  user-select: none;
}

.cp-media-foreground,
.cp-media-main-img,
.cp-media-main-vid,
.ch-reserved-vid {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  max-height: var(--message-media-max-height);
  object-fit: contain;
  object-position: center;
  background: transparent !important;
}

.cp-lqip-full {
  opacity: 0;
  transition: opacity 0.35s ease;
}

.cp-lqip-full-loaded {
  opacity: 1;
}

.cp-lqip-spinner {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.cp-lqip-spinner svg {
  animation: cp-spin 1.1s linear infinite;
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.4));
}

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

.cp-media-wrap-video {
  position: relative;
  overflow: hidden;
  background: #111;
}

.cp-media-wrap-video .cp-vid-poster {
  z-index: 1;
}

.cp-media-wrap-video .cp-media-main-vid,
.cp-media-wrap-video .ch-reserved-vid {
  z-index: 2;
}

.cp-video-poster-foreground {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain !important;
  object-position: center;
  filter: none !important;
  transform: none !important;
  pointer-events: none;
}

.cp-vid-poster-full {
  object-fit: contain !important;
  object-position: center;
}

.ch-album {
  box-sizing: border-box;
  display: grid;
  gap: 2px;
  width: 100%;
  max-width: min(100%, var(--message-media-max-width));
  max-height: var(--message-media-max-height);
  overflow: hidden;
  border-radius: 12px;
}

.ch-album-2v {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
}

.ch-album-2h {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr 1fr;
}

.ch-album-3l {
  grid-template-columns: 4fr 3fr;
  grid-template-rows: 1fr 1fr;
}

.ch-album-3t {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 9fr 8fr;
}

.ch-album-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  cursor: pointer;
  background: #111;
  -webkit-tap-highlight-color: transparent;
}

.ch-album-3l .ch-album-cell:first-child {
  grid-row: 1 / 3;
}

.ch-album-3t .ch-album-cell:first-child {
  grid-column: 1 / 3;
}

.cp-album-image {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transition: opacity 0.25s ease;
}

.ch-album-more {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 28px;
  font-weight: 600;
}
