/* Emoji reactions (member request, henry: "Add emoji reactions to messages"; after E-chat's port of 🅱️chat's tapbacks).
   Under the bubble: a wrapping row of paper chips, emoji + count; yours is indigo, like your own bubbles.
   Holding a bubble lifts it over the dimmed chat with the reaction strip above it: a piece of the felt letterboard,
   its two little dots pointing at the bubble, and who reacted + Copy on a paper card below. The strip's + raises
   every other emoji on a sheet from the bottom. */

/* ---------- the reaction row ---------- */
.msg .bubble, .msg .ph-bub { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.msg .tbs {
  display: flex; flex-wrap: wrap; gap: 4px; max-width: min(80%, 540px); margin: 4px 0 0 46px;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.msg.own .tbs { justify-content: flex-end; margin: 4px 46px 0 0; }
.tbc {
  position: relative; display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 10px 0 8px; border: 0;
  border-radius: 14px; background: var(--paper); color: var(--ink-2); box-shadow: 0 1px 0 #1d214040;
  font: 700 14px/1 var(--font); font-variant-numeric: tabular-nums; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.tbc::before { content: ""; position: absolute; inset: -8px -2px; } /* a finger-sized hit area over the gaps */
.tbc .tbn { min-width: .6em; }
.tbc.on { background: var(--indigo); color: var(--indigo-ink); box-shadow: 0 0 0 1.5px #ffffffb0; }
/* the add chip sits straight on the fjord film, so it's a small paper round like the others */
.tbc.add { width: 28px; padding: 0; justify-content: center; color: var(--ink-3); }
.msg.own .tbc.add { order: -1; } /* on your side it sits on the inner edge */
.tbc.add svg { width: 18px; height: 18px; display: block; }
.tbc:focus-visible, .tb-pick:focus-visible, .tb-copy:focus-visible { outline: 2px solid #7c8cff; outline-offset: 2px; }
.tbc:active > * { transform: scale(.88); }
.tbc.pop > * { animation: tb-pop .38s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes tb-pop { from { transform: scale(.3); opacity: 0; } }

.tb-emo {
  display: block; font: 400 16px/1 "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-variant-emoji: emoji;
}

/* ---------- the lifted bubble ---------- */
.tb-layer {
  position: fixed; inset: 0; z-index: 30; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.tb-scrim { position: absolute; inset: 0; background: #0d1020a0; animation: tb-fade .18s ease both; }
.tb-layer.out { animation: tb-fade .15s ease reverse both; pointer-events: none; }
@keyframes tb-fade { from { opacity: 0; } }

.tb-layer .tb-lift {
  position: fixed; margin: 0; display: flex; flex-direction: column; align-items: flex-start;
  transform-origin: left center; animation: tb-lift .26s cubic-bezier(.2, .9, .3, 1.15) both;
}
.tb-layer .tb-lift.own { align-items: flex-end; transform-origin: right center; }
.tb-layer .tb-lift .bubble, .tb-layer .tb-lift .ph-stack { max-width: none; flex: none; }
.tb-layer .tb-lift .nisse-hat { display: none; }
.tb-layer .tb-lift.cut .bubble, .tb-layer .tb-lift.cut .ph-stack { max-height: 100%; overflow: hidden; }
.tb-layer .tb-lift.cut .bubble { border-radius: 16px; }
@keyframes tb-lift { from { transform: translateY(var(--dy, 0)) scale(1); } 55% { transform: scale(1.04); } to { transform: scale(1.02); } }

.tb-bar {
  position: fixed; display: flex; gap: 1px; padding: 5px; border-radius: 28px;
  background: var(--felt); box-shadow: 0 0 0 1px #ffffff14 inset;
  transform-origin: var(--tail, 24px) 100%; animation: tb-bar .28s cubic-bezier(.3, 1.5, .55, 1) both;
}
.tb-bar::before, .tb-bar::after { content: ""; position: absolute; border-radius: 50%; background: var(--felt); }
.tb-bar::before { width: 11px; height: 11px; left: var(--tail, 24px); bottom: -6px; }
.tb-bar::after { width: 5px; height: 5px; left: calc(var(--tail, 24px) + 7px); bottom: -13px; }
.tb-layer.own .tb-bar::after { left: calc(var(--tail, 24px) - 1px); }
@keyframes tb-bar { from { transform: scale(.3); opacity: 0; } }
.tb-pick {
  position: relative; z-index: 1; display: grid; place-items: center; width: 42px; height: 42px; padding: 0; border: 0;
  border-radius: 50%; background: none; color: var(--letter); cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.tb-bar .tb-pick { animation: tb-glyph .3s cubic-bezier(.3, 1.6, .5, 1) both; animation-delay: calc(40ms + var(--n, 0) * 22ms); }
.tb-pick:nth-child(2) { --n: 1; } .tb-pick:nth-child(3) { --n: 2; } .tb-pick:nth-child(4) { --n: 3; }
.tb-pick:nth-child(5) { --n: 4; } .tb-pick:nth-child(6) { --n: 5; } .tb-pick:nth-child(7) { --n: 6; }
@keyframes tb-glyph { from { transform: scale(.4) translateY(6px); opacity: 0; } }
.tb-pick .tb-emo { font-size: 26px; transition: transform .12s; }
.tb-pick:active .tb-emo { transform: scale(1.25); }
.tb-pick.on { background: var(--indigo); }
.tb-more { margin-left: 3px; background: var(--felt-groove); box-shadow: 0 0 0 1px #ffffff1c inset; }
.tb-more svg { width: 20px; height: 20px; display: block; transition: transform .2s; }
.tb-more.on { background: var(--letter); color: var(--felt); }
.tb-more.on svg { transform: rotate(45deg); }

.tb-menu {
  position: fixed; min-width: 190px; max-width: calc(100vw - 16px); border-radius: 12px; background: var(--paper); color: var(--ink);
  box-shadow: 0 0 0 1px var(--rule); overflow: hidden; animation: tb-menu .22s ease both .04s;
}
.tb-layer.all .tb-menu { visibility: hidden; }
@keyframes tb-menu { from { opacity: 0; transform: translateY(-6px); } }
.tb-who { list-style: none; margin: 0; padding: 6px 0; max-height: 196px; overflow-y: auto; }
.tb-who li { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 14px 0 10px; font-size: 16px; font-weight: 700; }
.tb-who .tb { display: grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--wall); }
.tb-who .tb.mine { background: var(--indigo); }
.tb-who .tb .tb-emo { font-size: 15px; }
.tb-who span { color: var(--c, var(--ink)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (prefers-color-scheme: dark) { .tb-who span { color: color-mix(in oklab, var(--c, var(--ink)) 55%, white); } }
.tb-copy {
  display: block; width: 100%; min-height: 46px; padding: 0 16px; border: 0; background: none; color: var(--ink);
  font: 700 16px/1 var(--font); text-align: left; cursor: pointer;
}
.tb-who + .tb-copy, .tb-copy + .tb-copy { border-top: 1px solid var(--rule); }
.tb-copy:active { background: var(--wall); }
/* Delete: only on your own bubbles, red, and it takes two taps; then the bubble folds away to nothing */
.tb-del { color: var(--danger); }
.tb-del.armed { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.tb-layer.gone .tb-lift { animation: tb-gone .2s cubic-bezier(.5, 0, .9, .4) both; }
.tb-layer.gone .tb-bar, .tb-layer.gone .tb-menu { animation: tb-fade .14s ease reverse both; }
.tb-layer.gone { pointer-events: none; }
@keyframes tb-gone { from { transform: scale(1.02); } to { transform: scale(.6, .2); opacity: 0; } }

/* ---------- every emoji: a sheet from the bottom ---------- */
.tb-all {
  position: fixed; left: 0; right: 0; bottom: 0; max-width: 560px; margin: 0 auto; z-index: 2;
  background: var(--wall-2); color: var(--ink); border-radius: 20px 20px 0 0; box-shadow: 0 -1px 0 var(--rule);
  animation: tb-sheet .26s cubic-bezier(.2, .8, .2, 1) both;
}
.tb-all[hidden] { display: none; }
@keyframes tb-sheet { from { transform: translateY(100%); } }
.tb-grip { width: 38px; height: 5px; margin: 8px auto 0; border-radius: 3px; background: var(--rule); }
.tb-scroll {
  max-height: min(44vh, 360px); overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 0 10px calc(12px + env(safe-area-inset-bottom));
}
.tb-all h3 { margin: 12px 6px 4px; font-size: 14px; font-weight: 700; color: var(--ink-2); }
.tb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); justify-items: center; }
.tb-all .tb-pick { width: 44px; height: 44px; }
.tb-all .tb-pick .tb-emo { font-size: 28px; }

@media (prefers-reduced-motion: reduce) {
  .tb-scrim, .tb-layer .tb-lift, .tb-layer.gone .tb-lift, .tb-bar, .tb-bar .tb-pick, .tb-menu, .tb-all, .tbc.pop > * { animation: none; }
}
