/* The tapback: the one owner of how a reaction badge looks. Every Messages demo, the blog's static threads and the
   legend use it; none draws its own. Motion and room-making live in js/tapback.js.

   Markup (inside the message bubble's positioning wrapper, which must be position: relative):
     <span class="tb" data-tb="heart|like|dislike|haha|emphasize|question" data-on="in|out"
           role="img" aria-label="Sam loved this message"></span>
   data-on    the side of the bubble it sits on. "in" (default, the grey bubbles on the left): top-right corner, iMessage-blue badge.
              "out" (the blue bubbles on the right): top-left corner, grey badge. The tail dots mirror across the badge.
              In a one-to-one thread who reacted follows from the side: only the phone's owner reacts to an incoming bubble (blue badge),
              only the other person to an outgoing one (grey). So the fill is derived from data-on, never passed in.
   data-who   "me" | "them": an explicit fill, only for what the side cannot say: a group thread (several people react), or a badge
              standing alone as in the legend.
   data-tb="emoji" shows the text content instead of a drawn glyph.
   Add .has-tb to the message ROW so the room above it is made (static pages put it in the markup; the demos call ZSTapback.land,
   which adds it at the moment the badge lands, so the text is built in its normal place first).
   Hosts set only --tb-size, an ABSOLUTE length (px, cqw, or a calc of --kT), and may point --tb-theirs / --tb-ring at their own
   thread tokens. Everything else derives from the size. */

:root {
  /* ---- colours: sampled from Messages screenshots (the first pass is the hero's sampled values; change them here, nowhere else) ---- */
  --tb-mine: #2E6CD2;            /* the badge fill of a reaction from "me" (iMessage blue, sampled, the same in both themes) */
  --tb-theirs: #E9E9EB;          /* the badge fill of a reaction from "them": the incoming-bubble grey */
  --tb-ring: #fff;               /* the cut-out around the badge: the thread's background */
  /* the six glyphs are full-colour; their colours are the PALETTE in scripts/build-tapback-glyphs.mjs (a data URI cannot read these tokens) */
  --tb-size: 34px;
}
[data-theme="dark"] { --tb-theirs: #262629; --tb-ring: #000; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --tb-theirs: #262629; --tb-ring: #000; }
}

.tb {
  --u: calc(var(--tb-size) / 34);                       /* one unit = 1 / 34 of the badge: the measure everything below is written in */
  --tb-fill: var(--tb-mine);
  position: absolute; z-index: 1; box-sizing: border-box; display: grid; place-items: center;
  width: calc(34 * var(--u)); height: calc(34 * var(--u));
  top: calc(-27.3 * var(--u)); right: calc(-14 * var(--u));
  border-radius: 50%; background: var(--tb-fill); box-shadow: 0 0 0 calc(.6 * var(--u)) var(--tb-ring);
  transform-origin: 58.8% 80.3%;                        /* the bubble's corner */
  font-size: calc(18 * var(--u)); line-height: 1; pointer-events: none;
}
.tb[data-on="out"] { --tb-fill: var(--tb-theirs); right: auto; left: calc(-14 * var(--u)); transform-origin: 41.2% 80.3%; }
.tb[data-who="me"] { --tb-fill: var(--tb-mine); }
.tb[data-who="them"] { --tb-fill: var(--tb-theirs); }

/* the glyph: a full-colour picture (generated block below), as large as reads clearly at the badge size */
.tb::before { content: ""; position: absolute; z-index: 1; inset: 20%; background: center / contain no-repeat; }
.tb[data-tb="heart"]::before { inset: 15%; }
.tb[data-tb="like"]::before, .tb[data-tb="dislike"]::before { inset: 9%; }
.tb[data-tb="haha"]::before { inset: 8% 4%; }
.tb[data-tb="emphasize"]::before { inset: 0; }
.tb[data-tb="question"]::before { inset: 12% 20%; }
.tb[data-tb="emoji"]::before { content: none; }
/* glyphs:begin (generated by scripts/build-tapback-glyphs.mjs; edit the PALETTE there) */
.tb[data-tb="heart"]::before { background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='4.1 5.3 15.8 15.2'><defs><linearGradient id='g' x1='0' y1='0' x2='0' y2='1'><stop offset='0' stop-color='%23FFB1D6'/><stop offset='.45' stop-color='%23FF6FB0'/><stop offset='1' stop-color='%23EC3E8F'/></linearGradient><radialGradient id='h' cx='.3' cy='.22' r='.5'><stop offset='0' stop-color='%23fff' stop-opacity='.5'/><stop offset='1' stop-color='%23fff' stop-opacity='0'/></radialGradient></defs><path fill='url(%23g)' d='M12 20.3s-7.8-4.7-7.8-10.4A4.4 4.4 0 0 1 12 7.2a4.4 4.4 0 0 1 7.8 2.7c0 5.7-7.8 10.4-7.8 10.4z'/><ellipse cx='8.6' cy='9' rx='3.2' ry='2.2' fill='url(%23h)'/></svg>"); }
.tb[data-tb="haha"]::before { background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 92'><defs><filter id='b' x='-20%' y='-20%' width='140%' height='140%'><feGaussianBlur stdDeviation='2.6'/></filter><filter id='c' x='-20%' y='-20%' width='140%' height='140%'><feGaussianBlur stdDeviation='1.6'/></filter></defs><g fill='none' stroke-linecap='round' stroke-linejoin='round' ><path d='M21 18v18M41 18v18M21 27h20M61 36l13-18 13 18M65 31h18M21 56v18M41 56v18M21 65h20M61 74l13-18 13 18M65 69h18' stroke='%233CBBFF' stroke-opacity='.55' stroke-width='21' filter='url(%23b)'/><path d='M21 18v18M41 18v18M21 27h20M61 36l13-18 13 18M65 31h18M21 56v18M41 56v18M21 65h20M61 74l13-18 13 18M65 69h18' stroke='%232DB0FF' stroke-width='17'/><path d='M21 18v18M41 18v18M21 27h20M61 36l13-18 13 18M65 31h18M21 56v18M41 56v18M21 65h20M61 74l13-18 13 18M65 69h18' stroke='%239EE0FF' stroke-width='4' stroke-opacity='.85' filter='url(%23c)'/></g></svg>"); }
.tb[data-tb="emphasize"]::before { background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='1.4 1.5 31.2 31.2'><defs><radialGradient id='g' cx='.4' cy='.14' r='1'><stop offset='0' stop-color='%23FFD8CB'/><stop offset='.2' stop-color='%23FA9A80'/><stop offset='.46' stop-color='%23F2644A'/><stop offset='.74' stop-color='%23E6442E'/><stop offset='1' stop-color='%23CC3123'/></radialGradient><radialGradient id='d' cx='.38' cy='.28' r='.85'><stop offset='0' stop-color='%23FDB8A5'/><stop offset='.45' stop-color='%23F15D43'/><stop offset='1' stop-color='%23CE3325'/></radialGradient></defs><g fill='url(%23g)' stroke='%23AE2B20' stroke-opacity='.18' stroke-width='.5'><path d='M10.85 13.51L12.09 19.61A1.8 1.8 0 0 0 15.65 19.32L15.9 13.1A2.55 2.55 0 1 0 10.85 13.51Z'/><circle cx='14.33' cy='24.6' r='1.95' fill='url(%23d)'/></g><g fill='url(%23g)' stroke='%23AE2B20' stroke-opacity='.18' stroke-width='.5'><path d='M17.76 10.68L18.25 18.22A1.75 1.75 0 0 0 21.72 18.44L23.2 11.04A2.75 2.75 0 1 0 17.76 10.68Z'/><circle cx='19.5' cy='23.3' r='2.05' fill='url(%23d)'/></g></svg>"); }
.tb[data-tb="question"]::before { background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><defs><radialGradient id='g' gradientUnits='userSpaceOnUse' cx='40' cy='22' r='80'><stop offset='0' stop-color='%23CDB2FF'/><stop offset='.5' stop-color='%23A27BFA'/><stop offset='1' stop-color='%237E4FEA'/></radialGradient></defs><g fill='none' stroke='url(%23g)' stroke-linecap='round'><path d='M27 38a22 22 0 1 1 35 17c-8 6-12 9-12 15' stroke-width='24'/></g><circle cx='50' cy='89' r='11' fill='url(%23g)'/><path d='M30 35a19 19 0 0 1 16-14' fill='none' stroke='%23fff' stroke-opacity='.45' stroke-width='3.5' stroke-linecap='round'/></svg>"); }
.tb[data-tb="like"]::before { background-image: url("/images/tapback/like.png"); background-image: -webkit-image-set(url("/images/tapback/like.png") 1x, url("/images/tapback/like@2x.png") 2x); background-image: image-set(url("/images/tapback/like.png") 1x, url("/images/tapback/like@2x.png") 2x); }
.tb[data-tb="dislike"]::before { background-image: url("/images/tapback/dislike.png"); background-image: -webkit-image-set(url("/images/tapback/dislike.png") 1x, url("/images/tapback/dislike@2x.png") 2x); background-image: image-set(url("/images/tapback/dislike.png") 1x, url("/images/tapback/dislike@2x.png") 2x); }
/* glyphs:end */

/* the two tail dots, one layer: the badge's trailing thought bubbles, MEASURED from a real iOS screenshot (images/imessage/reactions.jpg),
   in badge units: a 10.2 dot at (22.86, 26.99) and a 5.2 dot at (31.69, 37.7), both solid circles in the badge fill, lower right of
   the badge on an incoming bubble. The big dot is the element and the small one its box-shadow (a negative spread shrinks the copy to 5.2),
   so both are true circles. They sit on the badge's own fill with no ring of their own, under the glyph. On an outgoing bubble they mirror
   across the badge's vertical axis. */
.tb::after {
  --sx: 1;
  content: ""; position: absolute; left: calc(22.86 * var(--u)); top: calc(26.99 * var(--u));
  width: calc(10.2 * var(--u)); height: calc(10.2 * var(--u)); border-radius: 50%; background: var(--tb-fill);
  box-shadow: calc(6.33 * var(--sx) * var(--u)) calc(8.21 * var(--u)) 0 calc(-2.5 * var(--u)) var(--tb-fill);
}
.tb[data-on="out"]::after { --sx: -1; left: calc(.94 * var(--u)); }

/* a badge standing alone, as in a legend: no corner, no tail */
.tb.tb-inline { position: relative; top: auto; right: auto; left: auto; flex: none; }
.tb.tb-inline::after { content: none; }

/* the room above a bubble that carries a badge. Made when it lands, never before. It replaces the host's usual gap above the bubble,
   so a host that spaces rows with flex gap sets --tb-room to the badge's overhang minus that gap. */
.has-tb { margin-top: var(--tb-room, calc(38 * var(--tb-size) / 34)) !important; }
