.chat-gifts-anchor {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  padding-inline-start: 6px;
}

.chat-gifts-anchor::before {
  position: absolute;
  inset-inline-start: 0;
  top: 4px;
  bottom: 4px;
  width: 1px;
  background: var(--line);
  content: "";
}

.chat-gifts-button,
.chat-gifts-close {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--studio-content-text, var(--text));
  cursor: pointer;
}

.chat-gifts-button {
  color: var(--stat-gift, #f398be);
}

.chat-gifts-button svg,
.chat-gifts-close svg {
  width: 18px;
  height: 18px;
}

.chat-gifts-button:hover,
.chat-gifts-button[aria-expanded="true"],
.chat-gifts-close:hover {
  border-color: var(--line);
  background: var(--panel2);
}

.chat-gifts-button:focus-visible,
.chat-gifts-close:focus-visible {
  outline: 2px solid var(--cyan, var(--accent));
  outline-offset: 2px;
}

.chat-gifts-panel {
  position: fixed;
  inset: auto 8px 65px;
  box-sizing: border-box;
  width: min(520px, calc(100vw - 16px));
  max-height: min(580px, calc(100vh - 85px));
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--studio-content-border, var(--line));
  border-radius: 10px;
  background: var(--studio-content-panel, var(--panel));
  color: var(--studio-content-text, var(--text));
  box-shadow: 0 14px 42px #0007;
}

.chat-gifts-panel:popover-open {
  display: flex;
  flex-direction: column;
}

.chat-gifts-panel > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
  padding: 8px 12px 8px 16px;
  border-bottom: 1px solid var(--studio-content-border, var(--line));
}

.chat-gifts-panel h2 {
  margin: 0;
  font-size: 15px;
}

.chat-gifts-content {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 12px;
}

.chat-gifts-content table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 12px;
}

.chat-gifts-content table + table {
  margin-top: 14px;
}

.chat-gifts-content caption {
  padding: 9px 10px;
  background: var(--studio-content-control, var(--panel2));
  text-align: left;
  overflow-wrap: anywhere;
}

.chat-gifts-content caption small {
  margin-inline-start: 8px;
  color: var(--studio-content-muted, var(--muted));
}

.chat-gifts-content :is(th, td) {
  box-sizing: border-box;
  padding: 7px 9px;
  border-bottom: 1px solid var(--studio-content-border, var(--line));
  text-align: left;
}

.chat-gifts-content thead th:first-child {
  width: 58%;
}

.chat-gifts-content :is(thead, tbody) tr > :not(:first-child),
.chat-gifts-content tfoot td {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.chat-gifts-content tfoot {
  background: var(--studio-content-control, var(--panel2));
  font-weight: 700;
}

.chat-gifts-label {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  gap: 7px;
  overflow-wrap: anywhere;
  vertical-align: middle;
}

.chat-gifts-thumbnail {
  position: relative;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  color: var(--stat-gift, #f398be);
}

.chat-gifts-thumbnail :is(svg, img) {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.chat-gifts-thumbnail svg {
  width: 16px;
  height: 16px;
}

.chat-gifts-thumbnail:has(img) svg {
  visibility: hidden;
}

.chat-gifts-quantity {
  margin-inline-start: 7px;
  color: var(--studio-content-muted, var(--muted));
  white-space: nowrap;
}

.chat-gifts-note,
.chat-gifts-empty {
  margin: 2px 0 10px;
  color: var(--studio-content-muted, var(--muted));
  font-size: 12px;
}

.chat-gifts-sparks {
  position: absolute;
  inset: 1px 0 1px 6px;
  pointer-events: none;
  color: var(--stat-gift, #f398be);
}

.chat-gifts-sparks i {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 5px 1px currentColor;
  opacity: 0;
  animation: gift-rising-spark 950ms ease-out 1;
}

.chat-gifts-sparks i:nth-child(1) { top: 4px; left: 49%; --spark-drift: -2px; --spark-far: -4px; }
.chat-gifts-sparks i:nth-child(2) { top: 7px; left: 82%; --spark-drift: 4px; --spark-far: 9px; animation-delay: 90ms; }
.chat-gifts-sparks i:nth-child(3) { top: 16px; left: 87%; --spark-drift: 6px; --spark-far: 12px; animation-delay: 200ms; }
.chat-gifts-sparks i:nth-child(4) { top: 22px; left: 63%; --spark-drift: 3px; --spark-far: 7px; animation-delay: 300ms; }
.chat-gifts-sparks i:nth-child(5) { top: 17px; left: 15%; --spark-drift: -4px; --spark-far: -9px; animation-delay: 150ms; }
.chat-gifts-sparks i:nth-child(6) { top: 8px; left: 20%; --spark-drift: -5px; --spark-far: -11px; animation-delay: 250ms; }

@keyframes gift-rising-spark {
  0%, 12% { opacity: 0; transform: translate3d(0, 0, 0) scale(.25); }
  19% { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
  43% { opacity: .9; transform: translate3d(var(--spark-drift), -10px, 0) scale(.8); }
  64%, 100% { opacity: 0; transform: translate3d(var(--spark-far), -19px, 0) scale(.2); }
}

@media (max-width: 1320px) {
  html:root[data-platform="desktop"] body.nova-ready #chat .chat-tts-bar:has(.chat-gifts-anchor) {
    grid-template-columns: auto minmax(80px, 1fr) 30px auto auto auto;
  }

  .chat-gifts-anchor {
    grid-column: 6;
    grid-row: 1;
  }
}

@media (max-width: 900px) {
  html:root[data-platform="desktop"] body.nova-ready #chat .chat-tts-bar:has(.chat-gifts-anchor) {
    grid-template-columns: auto minmax(56px, 1fr) 24px auto auto auto;
    column-gap: 4px !important;
  }

  html:root[data-platform="desktop"] body.nova-ready #chat .chat-tts-volume input {
    width: 42px;
  }

  .chat-gifts-anchor {
    padding-inline-start: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-gifts-sparks { display: none; }
}

.chat-gifts-fallback:not([hidden]) {
  z-index: 1500;
  display: flex;
  flex-direction: column;
}

.chat-gifts-fallback[hidden] {
  display: none !important;
}

.chat-gifts-header-anchor .chat-gifts-button {
  width: 36px;
  height: 36px;
}

.chat-gifts-header-anchor .chat-gifts-sparks i {
  animation-direction: reverse;
}

html[data-platform="mobile"] .chat-gifts-header-anchor .chat-gifts-button {
  width: 40px;
  height: 40px;
}
