/* Stackable reactions (§19): stickers on media and bubbles, ghost chips, hover card, detail sheet,
   floating emoji. Colors only from the tokens in /styles.css (light and dark). */

/* ---------------------------------------------------------------- ghost chips (admin, unsent message) */
.rx-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 5px 0 2px; padding: 0 4px; position: relative; z-index: 1; }
.rx-row.own { justify-content: flex-end; }
.rx-wrap { position: relative; display: inline-flex; }
/* iOS / Android: holding a sticker must never select text, show the callout or drag the image. */
.rx-row, .rx-stickers, .rx-wrap, .rx-pick { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.rx-row img, .rx-stickers img, .rx-pick img { -webkit-user-drag: none; -webkit-touch-callout: none; pointer-events: none; }

.rx-chip {
  position: relative; display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 10px 0 6px;
  border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); color: var(--text-2);
  font-size: 13px; font-weight: 750; line-height: 1; font-variant-numeric: tabular-nums; box-shadow: var(--shadow-1);
}
.rx-chip .emoji-img { pointer-events: none; }
.rx-stk.rx-holding { transition: transform 0.08s cubic-bezier(0.3, 1.8, 0.5, 1); }
.rx-hint {
  position: absolute; bottom: calc(100% + 10px); left: 50%; transform: translateX(-50%); z-index: 30; display: inline-flex; align-items: center; gap: 4px;
  white-space: nowrap; padding: 6px 10px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: 13px; font-weight: 700;
  box-shadow: var(--shadow-2); pointer-events: none; animation: pop 0.16s ease-out;
}
.rx-hint::after { content: ''; position: absolute; top: 100%; left: 50%; margin-left: -6px; border: 6px solid transparent; border-top-color: var(--text); }
.rx-stickers .rx-hint { left: auto; right: 0; transform: none; }
.rx-stickers .rx-hint::after { left: auto; right: 14px; }
.rx-n { display: inline-block; }
.rx-bump { animation: rx-bump 0.34s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes rx-bump { 0% { transform: scale(1); } 40% { transform: scale(1.5); } 100% { transform: scale(1); } }

.rx-ghost { filter: grayscale(1); opacity: 0.55; }
.rx-ghost .rx-chip { box-shadow: none; border-style: dashed; }

/* ---------------------------------------------------------------- stickers on media */
.rx-media { position: relative; }
.bare .rx-media { display: inline-block; vertical-align: bottom; }
.rx-stickers {
  position: absolute; right: -6px; bottom: -18px; z-index: 3; display: flex; align-items: flex-end; flex-direction: row-reverse;
  pointer-events: none; max-width: calc(100% + 6px);
}
.other .rx-stickers { right: -2px; }
.bare .rx-stickers { right: -6px; bottom: -12px; }
.rx-stickers > * { pointer-events: auto; }
.rx-stickers > .rx-wrap + .rx-wrap, .rx-stickers > .rx-stk-more + .rx-wrap { margin-right: -9px; }
.rx-stk {
  position: relative; width: calc(var(--sz, 32px) + 6px); height: calc(var(--sz, 32px) + 6px); border: 0; padding: 3px; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; border-radius: 50%;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
  transform: rotate(var(--r, 0deg)) scale(var(--rx-hold, 1)); transition: transform 0.12s ease-out;
}
.rx-stk::before { content: ''; position: absolute; inset: -3px; }
.rx-stk.pile { margin-left: calc(var(--sz, 32px) * 0.38); }
.rx-copy { position: absolute; left: 3px; top: 3px; transform: translate(var(--ox, 0px), var(--oy, 0px)) rotate(var(--cr, 0deg)); line-height: 0; }
.rx-copy .emoji-img, .rx-copy .emoji-txt {
  display: block; pointer-events: none;
  /* die-cut sticker: white outline + soft drop shadow */
  filter: drop-shadow(1.4px 0 0 #fff) drop-shadow(-1.4px 0 0 #fff) drop-shadow(0 1.4px 0 #fff) drop-shadow(0 -1.4px 0 #fff)
          drop-shadow(0 2px 3px rgba(0, 0, 0, 0.28));
}
.rx-copy.back .emoji-img, .rx-copy.back .emoji-txt { filter: drop-shadow(1.4px 0 0 #fff) drop-shadow(-1.4px 0 0 #fff) drop-shadow(0 1.4px 0 #fff) drop-shadow(0 -1.4px 0 #fff) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.22)) brightness(0.97); }
.rx-stk.lv2 .rx-copy:not(.back) .emoji-img {
  filter: drop-shadow(1.4px 0 0 #fff) drop-shadow(-1.4px 0 0 #fff) drop-shadow(0 1.4px 0 #fff) drop-shadow(0 -1.4px 0 #fff)
          drop-shadow(0 0 8px color-mix(in srgb, var(--c03) 70%, transparent));
}
.rx-stk-n {
  position: absolute; right: -7px; bottom: -3px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px;
  background: var(--surface); color: var(--text); font-size: 11px; font-weight: 800; line-height: 19px; text-align: center;
  box-shadow: var(--shadow-2); font-variant-numeric: tabular-nums; transform: rotate(calc(var(--r, 0deg) * -1)); pointer-events: none;
}
.rx-stk.mine .rx-stk-n { background: var(--accent); color: var(--accent-ink); }
.rx-stk-n.rx-bump { animation: rx-bump-stk 0.34s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes rx-bump-stk { 0% { scale: 1; } 40% { scale: 1.5; } 100% { scale: 1; } }
.rx-stk-more.rx-dots { min-width: 26px; height: 22px; font-size: 14px; padding: 0 6px; }
.rx-stk-more {
  align-self: center; height: 24px; min-width: 30px; padding: 0 7px; margin-left: 2px; border-radius: 12px; border: 0;
  background: var(--surface); color: var(--text-2); font-size: 12px; font-weight: 800; box-shadow: var(--shadow-2);
}
/* Room for the stickers that hang below the media. */
.msg-row:has(.rx-stickers) { padding-bottom: 16px; }
.bubble-media:has(.rx-media .rx-stickers) .att-caption { padding-top: 14px; }
.menu-clone .rx-stickers, .menu-clone .rx-row { display: none; }

/* ---------------------------------------------------------------- stickers on a bubble (T44)
   Text, links, files, voice, big emoji…: the same sticker row overlaps the bubble's bottom-right
   corner. `.rx-tail` is the last thing in the bubble, in normal flow: its width takes part in the
   bubble's width (a short bubble widens to fit the whole row, so nothing sticks out past its left
   edge) while its height is only --rx-room, a strip that keeps every emoji (pile copies and rotations
   included) off the last line of text: BubbleReactions sets --rx-reach = how far above the bubble's
   bottom edge the highest one reaches, the strip is that minus the bottom padding plus 2px (a row of
   plain stickers: ~11–14px; a big ≥ 50 pile: ~40px). The negative margins reach into the bubble's padding:
   the row may start 4px from the bubble's left edge and ends --rx-out past its right edge; `top`
   drops it so the stickers hang --rx-drop below the bubble's bottom edge. The count badge pokes 7px
   (+2px when rotated) out of a sticker's right side: own bubbles keep it inside the row's 12px side
   padding (the screen edge), other people's keep it out of the 6px gap before the time on the right. */
.rx-tail {
  --rx-pl: 12px; --rx-pr: 12px; --rx-pb: 8px; --rx-out: 0px; --rx-drop: 18px; /* drop: BUBBLE_DROP in Reactions.js */
  --rx-room: max(0px, calc(var(--rx-reach, 0px) - var(--rx-pb) + 2px));
  display: flex; justify-content: flex-end; align-items: flex-end; height: var(--rx-room); overflow: visible;
  margin: 0 calc(-1 * (var(--rx-pr) + var(--rx-out))) 0 calc(4px - var(--rx-pl));
}
.other .rx-tail { --rx-out: -4px; }
.bubble-media > .rx-tail { --rx-pl: 4px; --rx-pr: 4px; --rx-pb: 4px; } /* file / voice */
.bare > .rx-tail { --rx-pl: 4px; --rx-pr: 0px; --rx-pb: 0px; --rx-drop: 12px; --rx-room: 0px; } /* big emoji */
.msg-row .rx-tail > .rx-stickers {
  position: relative; right: auto; bottom: auto; top: calc(var(--rx-pb) + var(--rx-drop)); max-width: none; flex: none;
}
/* The stickers hang 18px and their count badges ~3–6px more below the bubble: clear the next message
   (its bubble starts 3px into the next row) even when it comes right after from the same sender. */
.msg-row:has(> .msg-col > .msg-line > * > .rx-tail) { padding-bottom: 22px; }
.rx-stk-more { white-space: nowrap; }

/* ---------------------------------------------------------------- hover card (desktop) */
.rx-card {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); z-index: 30; width: max-content; max-width: 240px;
  background: var(--surface); color: var(--text-2); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-2);
  padding: 8px 10px; font-size: 13px; line-height: 1.4; animation: pop 0.12s ease-out; text-align: left;
}
.rx-stickers .rx-card { transform: translateX(-50%) rotate(0deg); }
/* Own messages sit against the right edge: open the card leftwards so it is not cut off. */
.own .rx-stickers .rx-card { left: auto; right: -4px; transform: none; }
.rx-card-head { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 15px; margin-bottom: 2px; }
.rx-card-who { overflow-wrap: anywhere; }
.rx-card-btn {
  margin-top: 6px; border: 0; background: var(--surface-2); color: var(--accent-text); font-weight: 700; font-size: 13px;
  border-radius: 8px; padding: 4px 10px; min-height: 28px;
}
.rx-card-btn:hover { background: var(--surface-3); }

/* ---------------------------------------------------------------- message menu */
.rx-pick { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; transform: scale(var(--rx-hold, 1)); }
.rx-pick.rx-holding { background: var(--accent-soft); }
button.rx-summary { border: 0; font: inherit; text-align: left; cursor: pointer; width: 100%; color: var(--text-2); }
.rx-summary .menu-reactor { align-items: center; }
.rx-summary .menu-reactor b { color: var(--text); font-variant-numeric: tabular-nums; min-width: 1.4em; }
.rx-summary .menu-reactor span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rx-summary-more { color: var(--accent-text); font-weight: 700; font-size: 13px; }
.rx-summary:hover { background: var(--surface-2); }

/* ---------------------------------------------------------------- detail sheet */
.rx-tabs {
  display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; margin: 0 -20px 4px; padding-left: 20px; padding-right: 20px;
  position: sticky; top: -4px; background: var(--surface); z-index: 2; scrollbar-width: none; border-bottom: 1px solid var(--line);
}
.rx-tabs::-webkit-scrollbar { display: none; }
.rx-tab {
  flex: none; display: inline-flex; align-items: center; gap: 5px; height: 40px; padding: 0 12px 0 9px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--text-2); font-weight: 750; font-size: 14px; font-variant-numeric: tabular-nums;
}
.rx-tab.mine { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.rx-tab.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.rx-people { display: flex; flex-direction: column; }
.rx-person { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.rx-person:last-child { border-bottom: 0; }
.rx-rank { width: 18px; text-align: center; color: var(--text-3); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; flex: none; }
.rx-person-name { flex: 1; min-width: 0; font-weight: 650; color: var(--ut, var(--text)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rx-person-n { font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; font-size: 15px; }
.rx-person.me .rx-person-n { color: var(--accent-text); }
.rx-person-acts { display: flex; gap: 6px; flex-basis: 100%; justify-content: flex-end; padding-left: 76px; }
.rx-person-acts .btn { gap: 4px; }
.rx-minus { min-width: 52px; font-weight: 800; font-variant-numeric: tabular-nums; }
.rx-note { color: var(--text-3); font-size: 13px; margin: 8px 0 0; }
@media (min-width: 420px) {
  .rx-person-acts { flex-basis: auto; padding-left: 0; }
}

/* ---------------------------------------------------------------- floating emoji */
.rx-fx { position: fixed; inset: 0; pointer-events: none; z-index: 92; overflow: hidden; contain: strict; }
.rx-float { position: absolute; left: 0; top: 0; display: block; pointer-events: none; will-change: transform, opacity; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.18)); }

@media (prefers-reduced-motion: reduce) {
  .rx-stk, .rx-pick { transform: none; transition: none; }
  .rx-stk { transform: rotate(var(--r, 0deg)); }
  .rx-fx { display: none; }
}
