.chat-player {
  --player-progress: 0%;
  --player-focus: var(--brand);
  position: relative;
  max-width: 100%;
  min-width: 0;
}

.chat-player [hidden], .chat-player audio { display: none !important; }
.chat-player button { -webkit-tap-highlight-color: transparent; }
.chat-player button:disabled { cursor: default; opacity: .48; }
.chat-player :is(button, a):focus-visible, #device .chat-player :is(button, a):focus-visible {
  outline: 2px solid var(--player-focus);
  outline-offset: -2px;
}

.chat-player-time {
  font-size: 11px;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chat-player[data-player="voice"] {
  display: grid;
  grid-template: "play track speed" 44px "status status status" auto / 44px minmax(0, 1fr) 44px;
  align-items: center;
  column-gap: 8px;
  width: min(73vw, 320px);
}

.chat-player[data-player="voice"] :is(.chat-player-play, .chat-player-speed) {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
}
.chat-player[data-player="voice"] .chat-player-play {
  position: relative;
  grid-area: play;
  border-radius: 50%;
  background: color-mix(in srgb, var(--brand) 86%, #10205f);
  color: #fff;
}
.chat-player[data-player="voice"] .chat-player-play:focus-visible,
#device .chat-player[data-player="voice"] .chat-player-play:focus-visible {
  outline-color: #fff;
  outline-offset: -4px;
}
.chat-player[data-player="voice"] .chat-player-play .ico { width: 19px; height: 19px; }
.chat-player[data-player="voice"] .chat-player-speed {
  grid-area: speed;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chat-player-track {
  position: relative;
  grid-area: track;
  display: flex;
  align-items: flex-end;
  align-self: stretch;
  min-width: 0;
  min-height: 44px;
  border-radius: 6px;
}
.chat-player-wave {
  position: absolute;
  inset: 3px 1px auto;
  height: 21px;
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  align-items: center;
  gap: clamp(1px, .34vw, 3px);
  pointer-events: none;
}
.chat-player-wave i {
  display: block;
  width: 100%;
  min-height: 3px;
  height: var(--bar, 30%);
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand) 33%, var(--surface-3));
}
.chat-player-wave i[data-played]:not([data-played="false"]) { background: color-mix(in srgb, var(--brand) 83%, var(--ink)); }
.chat-player[data-player="voice"] .chat-player-seek {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}
.chat-player[data-player="voice"] .chat-player-seek:disabled { cursor: default; }
.chat-player-track:has(.chat-player-seek:focus-visible) { outline: 2px solid var(--player-focus); outline-offset: 2px; }
.chat-player-meta {
  display: flex;
  align-items: baseline;
  gap: 5px;
  min-width: 0;
  padding-block-end: 2px;
  color: var(--ink-2);
  pointer-events: none;
}
.chat-player-status { display: flex; flex-wrap: wrap; align-items: center; gap: 0 6px; font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }
.chat-player-status a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding-inline: 5px;
  border-radius: 6px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: .17em;
}
.chat-player[data-player="voice"] > .chat-player-status { grid-area: status; margin-top: 5px; }
.chat-player[data-player="voice"][data-state="error"] .chat-player-status { color: color-mix(in srgb, var(--danger) 80%, var(--ink)); }

.chat-compose-preview[data-kind="voice"]:has(.chat-player) { flex-basis: min(320px, 100%); padding: 4px; }
.chat-compose-preview[data-kind="voice"] .chat-compose-preview-media:has(.chat-player) {
  display: flex;
  align-items: center;
  flex: 1;
  width: auto;
  height: auto;
  min-height: 44px;
  overflow: visible;
  color: var(--ink);
}
.chat-compose-preview .chat-player[data-player="voice"] { width: 100%; column-gap: 5px; }
.chat-compose-preview[data-kind="voice"]:has(.chat-player) .chat-compose-remove { width: 44px; height: 44px; }

.chat-player[data-player="video"] {
  --player-focus: #fff;
  width: min(74vw, 420px);
  border-radius: 12px;
  background: #080b12;
  color: #fff;
}
.chat-player-screen {
  position: relative;
  isolation: isolate;
  min-height: 156px;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: inherit;
  background: #080b12;
}
.chat-player-screen video {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.chat-player-cover {
  position: absolute;
  z-index: 1;
  inset-block-start: clamp(29px, calc(50% - 16px), calc(100% - 119px));
  inset-inline-start: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  padding: 0;
  border: 1px solid #ffffff3d;
  border-radius: 50%;
  background: #20293ddc;
  color: #fff;
  box-shadow: 0 4px 24px #0005;
}
.chat-player-cover .ico { width: 24px; height: 24px; }
.chat-player:is([data-state="playing"], [data-state="error"]) .chat-player-cover { display: none; }
.chat-player-screen .chat-player-status {
  position: absolute;
  z-index: 2;
  inset: 7px 7px auto;
  justify-self: center;
  max-width: calc(100% - 14px);
  margin: 0;
  padding: 0 8px;
  justify-content: center;
  border-radius: 7px;
  background: #080b12df;
  color: #fff;
  text-align: center;
}
.chat-player-video-controls {
  position: absolute;
  z-index: 2;
  inset-inline: 0;
  inset-block-end: 0;
  padding: 0 4px 2px;
  border-end-start-radius: inherit;
  border-end-end-radius: inherit;
  background: linear-gradient(transparent, #080b12d9 48%, #080b12f5);
}
.chat-player-video-controls .chat-player-seek {
  display: block;
  width: calc(100% - 12px);
  height: 44px;
  margin: 0 6px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
.chat-player-video-controls .chat-player-seek:disabled { cursor: default; }
.chat-player-video-controls .chat-player-seek:focus-visible, #device .chat-player-video-controls .chat-player-seek:focus-visible {
  outline: 2px solid var(--player-focus);
  outline-offset: -5px;
}
.chat-player-video-controls .chat-player-seek::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(to right, #7d9dff var(--player-progress), #ffffff73 var(--player-progress));
}
.chat-player-video-controls .chat-player-seek::-webkit-slider-thumb {
  width: 11px;
  height: 11px;
  margin-top: -4px;
  border: 0;
  border-radius: 50%;
  -webkit-appearance: none;
  appearance: none;
  background: #fff;
}
.chat-player-video-controls .chat-player-seek::-moz-range-track { height: 3px; border-radius: 999px; background: #ffffff73; }
.chat-player-video-controls .chat-player-seek::-moz-range-progress { height: 3px; border-radius: 999px; background: #7d9dff; }
.chat-player-video-controls .chat-player-seek::-moz-range-thumb { width: 11px; height: 11px; border: 0; border-radius: 50%; background: #fff; }
.chat-player-video-toolbar { position: relative; display: flex; align-items: center; min-width: 0; }
.chat-player-video-toolbar button, .chat-player-dialog-head button {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 9px;
  color: #fff;
}
.chat-player-video-toolbar button .ico, .chat-player-dialog-head button .ico { width: 19px; height: 19px; }
.chat-player-video-toolbar .chat-player-time {
  flex: 1;
  min-width: 0;
  padding-inline: 1px;
  color: #fff;
}

.chat-player-dialog {
  width: min(940px, calc(100% - 20px));
  max-width: none;
  max-height: calc(100dvh - 20px);
  margin: auto;
  padding: 8px;
  overflow: auto;
  border: 1px solid #ffffff1f;
  border-radius: 16px;
  background: #101523;
  color: #fff;
  box-shadow: 0 22px 65px #0008;
}
.chat-player-dialog::backdrop { background: #050813db; }
.chat-player-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 0 4px 6px; }
.chat-player-dialog-head > :first-child { min-width: 0; overflow-wrap: anywhere; }
.chat-player-dialog-head button:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.chat-player[data-player="video"][data-large], .chat-player[data-player="video"]:fullscreen { width: 100%; border-radius: 10px; }
.chat-player[data-large] .chat-player-screen { max-height: calc(100dvh - 90px); }
.chat-player[data-player="video"]:fullscreen .chat-player-screen, .chat-player-screen:fullscreen { height: 100%; max-height: none; border-radius: 0; }

.chat-player[data-state="loading"] .chat-player-cover::after,
.chat-player[data-player="voice"][data-state="loading"] .chat-player-play::after {
  position: absolute;
  inset: 5px;
  border: 2px solid #ffffff56;
  border-top-color: #fff;
  border-radius: 50%;
  content: '';
  animation: chat-player-buffer .9s linear infinite;
  pointer-events: none;
}
@keyframes chat-player-buffer { to { transform: rotate(1turn); } }
@media (prefers-reduced-motion: reduce) {
  .chat-player[data-state="loading"] .chat-player-cover::after,
  .chat-player[data-player="voice"][data-state="loading"] .chat-player-play::after { animation: none; }
}

@media (hover: hover) {
  .chat-player[data-player="voice"] .chat-player-play:not(:disabled):hover { background: var(--brand-press); }
  .chat-player[data-player="voice"] .chat-player-speed:not(:disabled):hover { background: var(--surface-3); color: var(--ink); }
  .chat-player-cover:not(:disabled):hover { background: #304468; }
  .chat-player-video-toolbar button:not(:disabled):hover, .chat-player-dialog-head button:hover { background: #ffffff23; }
}
