/* Building together (js/net/coopui.js): the Together panel, the floating friend chip with the preset
   reactions, and the hand-off card. Everything is scoped under .tb-coop. The TardiGREATS clubhouse look:
   cream panels, ink sticker borders, chunky drop shadows, big touch targets (44 px and up). */

.tb-coop {
  --tbc-ink: #16223A;
  --tbc-cream: #FBF7F0;
  --tbc-paper: #FFFDF8;
  --tbc-teal: #0F9D8A;
  --tbc-teal-tint: #E2F6F2;
  --tbc-blue: #2E8BC9;
  --tbc-blue-tint: #E3F0FA;
  --tbc-orange: #FF8A3D;
  --tbc-orange-tint: #FFEBDD;
  --tbc-purple: #8A4FD1;
  --tbc-purple-tint: #EFE6FA;
  --tbc-yellow: #F2C14E;
  --tbc-yellow-tint: #FDF3D8;
  --tbc-coral: #F0525F;
  --tbc-green: #2F9E5B;
  --tbc-soft: #5B6478;
  --tbc-line: 3px solid var(--tbc-ink);
  --tbc-shadow: 0 4px 0 var(--tbc-ink);
  --tbc-title: "Bricolage Grotesque", "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  --tbc-text: "Nunito Sans", "Avenir Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-family: var(--tbc-text);
  color: var(--tbc-ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  box-sizing: border-box;
}
.tb-coop *, .tb-coop *::before, .tb-coop *::after { box-sizing: border-box; }
.tb-coop button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
.tb-coop button:disabled { cursor: default; }
.tb-coop button:focus-visible { outline: 3px solid var(--tbc-blue); outline-offset: 3px; }
.tb-coop h2, .tb-coop h3, .tb-coop h4 { font-family: var(--tbc-title); margin: 0; letter-spacing: -0.01em; }
.tb-coop p { margin: 0; }
.tb-coop .ic { display: block; flex: none; }

/* ------------------------------------------------------------------ the panel */

.tb-coop.tbc-panel {
  position: relative;
  width: min(780px, calc(100% - 32px));
  max-height: calc(100% - 24px);
  margin: 12px auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--tbc-cream);
  border: var(--tbc-line);
  border-radius: 24px;
  box-shadow: 0 6px 0 var(--tbc-ink), 0 18px 40px rgba(22, 34, 58, 0.18);
  animation: tbc-rise 0.32s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.tbc-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px 14px;
  border-bottom: var(--tbc-line);
  background: var(--tbc-teal-tint);
  border-radius: 21px 21px 0 0;
  position: sticky;
  top: 0;
  z-index: 2;
}
.tbc-head-ic {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--tbc-teal);
  color: #fff;
  border: var(--tbc-line);
  box-shadow: var(--tbc-shadow);
  flex: none;
}
.tbc-head-text { flex: 1; min-width: 0; }
.tbc-head h2 { font-size: 26px; font-weight: 800; line-height: 1.1; }
.tbc-head p { font-size: 15px; color: var(--tbc-soft); font-weight: 600; margin-top: 2px; }
.tbc-icon-btn {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: var(--tbc-line);
  background: var(--tbc-paper);
  box-shadow: var(--tbc-shadow);
  flex: none;
}
.tbc-icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--tbc-ink); }

.tbc-body { padding: 20px; display: flex; flex-direction: column; gap: 18px; }
.tbc-center { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 16px; }
.tbc-center h3 { font-size: 24px; font-weight: 800; }
.tbc-intro { text-align: center; display: flex; flex-direction: column; gap: 6px; }
.tbc-intro h3 { font-size: 24px; font-weight: 800; }
.tbc-intro p { font-size: 17px; line-height: 1.4; color: var(--tbc-soft); font-weight: 600; max-width: 34em; margin: 0 auto; }

/* the three big choices */
.tbc-choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.tbc-choice {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  min-height: 196px;
  padding: 18px 12px 16px;
  border: var(--tbc-line);
  border-radius: 22px;
  background: var(--tbc-paper);
  box-shadow: 0 6px 0 var(--tbc-ink);
  text-align: center;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.tbc-choice:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--tbc-ink); }
.tbc-choice-art {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  border-radius: 26px;
  border: var(--tbc-line);
  margin-bottom: 6px;
  color: #fff;
  transition: transform 0.2s cubic-bezier(0.2, 1.6, 0.4, 1);
}
.tbc-choice:active .tbc-choice-art { transform: scale(0.92) rotate(-4deg); }
.tbc-art-pics { display: flex; align-items: center; justify-content: center; gap: 0; padding: 4px; background: var(--tbc-paper); }
.tbc-art-pics .tb-pic + .tb-pic { margin-left: -10px; transform: rotate(10deg); }
.tbc-choice-title { font-family: var(--tbc-title); font-size: 21px; font-weight: 800; line-height: 1.15; }
.tbc-choice-sub { font-size: 15px; font-weight: 600; color: var(--tbc-soft); line-height: 1.3; }
.tbc-c-same { background: var(--tbc-yellow-tint); }
.tbc-c-same .tbc-choice-art { background: var(--tbc-orange); }
.tbc-c-host { background: var(--tbc-teal-tint); }
.tbc-c-host .tbc-choice-art { background: #fff; }
.tbc-c-join { background: var(--tbc-purple-tint); }
.tbc-c-join .tbc-choice-art { background: var(--tbc-purple); }
.tbc-lock {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  padding: 5px 10px;
  border-radius: 999px;
  border: 2px solid var(--tbc-ink);
  background: var(--tbc-paper);
  font-size: 13px;
  font-weight: 800;
}

.tbc-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 16px;
  font-size: 15px;
  font-weight: 700;
  color: var(--tbc-soft);
}
.tbc-foot > span { display: inline-flex; align-items: center; gap: 6px; }
.tbc-link {
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  background: none;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
  color: var(--tbc-ink);
}

.tbc-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: var(--tbc-line);
  border-radius: 18px;
  background: var(--tbc-yellow-tint);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.35;
  animation: tbc-wobble-in 0.5s ease both;
}

/* buttons */
.tbc-actions, .tbc-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; }
.tbc-row-center { justify-content: center; }
/* the picture pad: Back on its own at the start, the pad's own buttons together at the end */
.tbc-pad-actions { align-self: stretch; justify-content: space-between; }
.tbc-actions-end { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; }
.tbc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 20px;
  border: var(--tbc-line);
  border-radius: 16px;
  background: var(--tbc-paper);
  box-shadow: var(--tbc-shadow);
  font-family: var(--tbc-title);
  font-size: 18px;
  font-weight: 800;
  transition: transform 0.1s ease, box-shadow 0.1s ease, opacity 0.15s ease;
}
.tbc-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--tbc-ink); }
.tbc-btn:disabled { opacity: 0.45; box-shadow: 0 2px 0 var(--tbc-ink); }
.tbc-primary { background: var(--tbc-teal); color: #fff; }
.tbc-soft { background: var(--tbc-yellow); }
.tbc-ghost { background: var(--tbc-paper); }

/* same-screen roles */
.tbc-roles { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: stretch; gap: 14px; }
.tbc-role {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 12px 18px;
  border: var(--tbc-line);
  border-radius: 22px;
  box-shadow: 0 5px 0 var(--tbc-ink);
  text-align: center;
  animation: tbc-pop 0.35s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.tbc-role b { font-family: var(--tbc-title); font-size: 22px; font-weight: 800; }
.tbc-role small { font-size: 15px; font-weight: 700; color: var(--tbc-soft); }
.tbc-role-builder { background: var(--tbc-blue-tint); }
.tbc-role-brain { background: var(--tbc-orange-tint); }
.tbc-role-ic {
  display: grid;
  place-items: center;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: var(--tbc-line);
  color: #fff;
  margin: 4px 0;
}
.tbc-role-builder .tbc-role-ic { background: var(--tbc-blue); }
.tbc-role-brain .tbc-role-ic { background: var(--tbc-orange); }
.tbc-role-builder .tbc-role-ic .ic { animation: tbc-stack 2.4s ease-in-out infinite; }
.tbc-role-brain .tbc-role-ic .ic { animation: tbc-think 2.4s ease-in-out infinite; }
.tbc-side {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--tbc-paper);
  border: 2px solid var(--tbc-ink);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tbc-swap {
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 76px;
  min-height: 76px;
  padding: 10px 8px;
  border: var(--tbc-line);
  border-radius: 20px;
  background: var(--tbc-paper);
  box-shadow: var(--tbc-shadow);
  font-size: 13px;
  font-weight: 800;
}
.tbc-swap:active { transform: translateY(3px) rotate(-8deg); box-shadow: 0 1px 0 var(--tbc-ink); }
.tbc-tip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--tbc-soft);
  text-align: center;
}
.tbc-tip .ic { color: var(--tbc-yellow); stroke: var(--tbc-ink); }

/* the grown-up gate */
.tbc-gate { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; }
.tbc-gate h3 { font-size: 24px; font-weight: 800; }
.tbc-gate > p { font-size: 16px; font-weight: 600; color: var(--tbc-soft); max-width: 30em; line-height: 1.4; }
.tbc-gate-ic {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 20px;
  border: var(--tbc-line);
  background: var(--tbc-blue);
  color: #fff;
  box-shadow: var(--tbc-shadow);
}
.tbc-hold {
  --p: 0;
  position: relative;
  display: grid;
  place-items: center;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  border: var(--tbc-line);
  background: var(--tbc-paper);
  box-shadow: 0 6px 0 var(--tbc-ink);
  touch-action: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.tbc-hold.is-holding { transform: translateY(4px) scale(calc(1 + var(--p) * 0.06)); box-shadow: 0 2px 0 var(--tbc-ink); }
.tbc-hold-ring { position: absolute; inset: 4px; width: calc(100% - 8px); height: calc(100% - 8px); transform: rotate(-90deg); pointer-events: none; }
.tbc-hold-track { fill: none; stroke: var(--tbc-teal-tint); stroke-width: 10; }
.tbc-hold-fill { fill: none; stroke: var(--tbc-teal); stroke-width: 10; stroke-linecap: round; stroke-dasharray: 327; stroke-dashoffset: 327; }
.tbc-hold-ic { position: relative; color: var(--tbc-ink); }
.tbc-hold.is-holding .tbc-hold-ic { animation: tbc-shake 0.5s ease-in-out infinite; }
.tbc-hold-label { font-size: 16px; font-weight: 800; }
.tbc-words {
  font-family: var(--tbc-title);
  font-size: 30px;
  font-weight: 800;
  padding: 8px 18px;
  border: var(--tbc-line);
  border-radius: 16px;
  background: var(--tbc-yellow-tint);
}
.tbc-typed { display: flex; gap: 10px; }
.tbc-typed-slot {
  display: grid;
  place-items: center;
  width: 52px;
  height: 56px;
  border: var(--tbc-line);
  border-radius: 14px;
  background: var(--tbc-paper);
  font-family: var(--tbc-title);
  font-size: 26px;
  font-weight: 800;
}
.tbc-typed-slot.is-on { background: var(--tbc-teal-tint); animation: tbc-pop 0.25s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
.tbc-keypad { display: grid; grid-template-columns: repeat(5, 64px); gap: 10px; }
.tbc-key {
  height: 60px;
  border: var(--tbc-line);
  border-radius: 16px;
  background: var(--tbc-paper);
  box-shadow: var(--tbc-shadow);
  font-family: var(--tbc-title);
  font-size: 26px;
  font-weight: 800;
}
.tbc-key:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--tbc-ink); background: var(--tbc-teal-tint); }
.tbc-soft-note { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; color: var(--tbc-soft); }

/* picture codes */
.tb-pic { color: var(--tbc-ink, #16223A); display: block; }
.tbc-code { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.tbc-code-pic {
  --d: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 104px;
  padding: 12px 10px 10px;
  border: var(--tbc-line);
  border-radius: 20px;
  background: var(--tbc-paper);
  box-shadow: 0 5px 0 var(--tbc-ink);
  font-weight: 800;
  font-size: 15px;
  animation: tbc-deal 0.45s cubic-bezier(0.2, 1.5, 0.4, 1) both;
  animation-delay: calc(var(--d) * 0.12s);
}
.tbc-code-pic:nth-child(odd) { transform: rotate(-2deg); }
.tbc-code-pic:nth-child(even) { transform: rotate(2deg); }
.tbc-code-pic.is-empty { min-height: 128px; background: var(--tbc-teal-tint); overflow: hidden; position: relative; }
.tbc-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, 0.8) 50%, transparent 80%);
  animation: tbc-shimmer 1.2s linear infinite;
}
.tbc-joining .tbc-code-pic { min-width: 72px; padding: 8px 6px 6px; font-size: 12px; }
.tbc-joining .tbc-code-pic.is-empty { min-height: 90px; }
.tbc-say { font-size: 17px; font-weight: 700; color: var(--tbc-soft); }
.tbc-wait, .tbc-net {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 800;
}
.tbc-net {
  padding: 6px 14px;
  border-radius: 999px;
  border: 2px solid var(--tbc-ink);
  background: var(--tbc-paper);
  font-size: 14px;
}
.tbc-net.is-up { background: var(--tbc-teal-tint); }
.tbc-dots { display: inline-flex; gap: 4px; margin-left: 4px; }
.tbc-dots i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: tbc-dot 1.2s ease-in-out infinite; }
.tbc-dots i:nth-child(2) { animation-delay: 0.15s; }
.tbc-dots i:nth-child(3) { animation-delay: 0.3s; }

.tbc-slots { display: flex; gap: 10px; }
.tbc-slot {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border: 3px dashed var(--tbc-ink);
  border-radius: 18px;
  background: var(--tbc-paper);
  font-family: var(--tbc-title);
  font-size: 22px;
  color: var(--tbc-soft);
}
.tbc-slot.is-next { border-color: var(--tbc-purple); background: var(--tbc-purple-tint); animation: tbc-breathe 1.4s ease-in-out infinite; }
.tbc-slot.is-on { border-style: solid; background: var(--tbc-paper); box-shadow: var(--tbc-shadow); animation: tbc-pop 0.3s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
.tbc-picgrid { display: grid; grid-template-columns: repeat(4, minmax(72px, 104px)); gap: 10px; }
.tbc-pic {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 88px;
  padding: 8px 4px 6px;
  border: var(--tbc-line);
  border-radius: 18px;
  background: var(--tbc-paper);
  box-shadow: var(--tbc-shadow);
  font-size: 13px;
  font-weight: 800;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.tbc-pic:active:not(:disabled) { transform: translateY(3px) scale(0.96); box-shadow: 0 1px 0 var(--tbc-ink); background: var(--tbc-purple-tint); }
.tbc-pic:disabled { opacity: 0.5; }
.tbc-knock { color: var(--tbc-teal); animation: tbc-knock 1.1s ease-in-out infinite; transform-origin: 50% 100%; }

/* the friend asks to join */
.tbc-asking h3 { font-size: 26px; }
.tbc-avatar {
  --c: #2E8BC9;
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  border: var(--tbc-line);
  background: var(--c);
  color: #fff;
  font-family: var(--tbc-title);
  font-weight: 800;
  font-size: 20px;
  text-shadow: 0 2px 0 rgba(22, 34, 58, 0.35);
  box-shadow: inset 0 -4px 0 rgba(22, 34, 58, 0.18);
}
.tbc-avatar-lg { width: 72px; height: 72px; font-size: 34px; }
.tbc-avatar-xl { width: 116px; height: 116px; font-size: 56px; box-shadow: inset 0 -8px 0 rgba(22, 34, 58, 0.18), 0 6px 0 var(--tbc-ink); }
.tbc-pop { animation: tbc-bounce-in 0.6s cubic-bezier(0.2, 1.6, 0.4, 1) both; }

/* live session */
.tbc-status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: var(--tbc-line);
  border-radius: 18px;
  background: var(--tbc-teal-tint);
  font-size: 17px;
}
.tbc-status > span { display: flex; flex-direction: column; gap: 2px; }
.tbc-status small { font-size: 15px; font-weight: 600; color: var(--tbc-soft); }
.tbc-status.is-resting { background: var(--tbc-blue-tint); }
.tbc-status.is-resting .ic { animation: tbc-think 2.4s ease-in-out infinite; }
.tbc-pair { display: flex; align-items: center; justify-content: center; gap: 18px; }
.tbc-person { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 18px; }
.tbc-person b { font-family: var(--tbc-title); font-weight: 800; }
.tbc-plus { color: var(--tbc-soft); }
.tbc-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 2px solid var(--tbc-ink);
  font-size: 14px;
  font-weight: 800;
}
.tbc-badge-builder { background: var(--tbc-blue-tint); }
.tbc-badge-brain { background: var(--tbc-orange-tint); }
.tbc-sub { font-size: 18px; font-weight: 800; text-align: center; }
.tbc-reacts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.tbc-askcard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border: var(--tbc-line);
  border-radius: 20px;
  background: var(--tbc-yellow-tint);
  box-shadow: var(--tbc-shadow);
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  animation: tbc-bounce-in 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.tbc-ended .tbc-big-ic, .tbc-handoff .tbc-big-ic {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: var(--tbc-line);
  background: var(--tbc-yellow);
  box-shadow: 0 6px 0 var(--tbc-ink);
  animation: tbc-bounce-in 0.6s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.tbc-ended p { font-size: 17px; font-weight: 700; color: var(--tbc-soft); }

/* the preset reactions (panel and floating tray) */
.tbc-react {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 56px;
  min-height: 60px;
  padding: 6px 4px;
  border: var(--tbc-line);
  border-radius: 16px;
  background: var(--tbc-paper);
  box-shadow: var(--tbc-shadow);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.1;
}
.tbc-react > span { max-width: 100%; overflow-wrap: normal; hyphens: manual; }
.tbc-tray .tbc-react { font-size: 12px; letter-spacing: -0.01em; }
.tbc-react-lg { min-height: 78px; font-size: 14px; }
.tbc-react:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--tbc-ink); }
.tbc-react[data-kind="wave"] .ic, .tbc-react[data-kind="help"] .ic { color: var(--tbc-orange); }
.tbc-react[data-kind="cheer"] .ic { color: var(--tbc-yellow); stroke: var(--tbc-ink); }
.tbc-react[data-kind="ping"] .ic { color: var(--tbc-blue); }
.tbc-react[data-kind="heart"] .ic { color: var(--tbc-coral); }
.tbc-react[data-kind="thinking"] .ic { color: var(--tbc-purple); }
.tbc-react[data-kind="yes"] .ic { color: var(--tbc-green); }
.tbc-react[data-kind="no"] .ic { color: var(--tbc-coral); }
.tbc-react.is-sent { animation: tbc-sent 0.45s cubic-bezier(0.2, 1.6, 0.4, 1); }
.tbc-react.is-sent::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 20px;
  border: 3px solid var(--tbc-teal);
  animation: tbc-ring 0.6s ease-out forwards;
  pointer-events: none;
}

/* ------------------------------------------------------------------ the floating friend chip */

.tb-coop.tbc-hud {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  top: max(84px, calc(env(safe-area-inset-top) + 72px));
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  width: min(340px, calc(100vw - 28px));
  pointer-events: none;
}
.tbc-hud > * { pointer-events: auto; }
.tbc-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 6px 12px 6px 6px;
  border: var(--tbc-line);
  border-radius: 999px;
  background: var(--tbc-cream);
  box-shadow: var(--tbc-shadow);
  text-align: left;
  animation: tbc-rise 0.35s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
button.tbc-chip:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--tbc-ink); }
.tbc-chip .tbc-avatar { width: 42px; height: 42px; }
.tbc-chip-text { display: flex; flex-direction: column; line-height: 1.1; }
.tbc-chip-text b { font-family: var(--tbc-title); font-size: 17px; font-weight: 800; }
.tbc-chip-text small { font-size: 13px; font-weight: 700; color: var(--tbc-soft); }
.tbc-chip-state {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--tbc-teal-tint);
  border: 2px solid var(--tbc-ink);
}
.tbc-chip-state .ic { animation: tbc-wave 2.6s ease-in-out infinite; transform-origin: 70% 80%; }
.tbc-chip.is-resting { background: var(--tbc-blue-tint); }
.tbc-chip.is-resting .tbc-avatar { filter: saturate(0.5); opacity: 0.8; }
.tbc-chip.is-resting .tbc-chip-state { background: var(--tbc-paper); }
.tbc-chip.is-resting .tbc-chip-state .ic { animation: tbc-think 2.4s ease-in-out infinite; }
/* the same-screen chip: two halves in the roles' colours, an arrow at each half's own side of the screen */
.tbc-chip-same { gap: 0; padding: 0; align-items: stretch; overflow: hidden; }
.tbc-half { display: flex; align-items: center; gap: 6px; padding: 4px 14px 4px 10px; }
.tbc-half-right { flex-direction: row-reverse; padding: 4px 10px 4px 14px; border-left: var(--tbc-line); }
.tbc-half-builder { background: var(--tbc-blue-tint); }
.tbc-half-brain { background: var(--tbc-orange-tint); }
.tbc-half-ic {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--tbc-ink);
  color: #fff;
}
.tbc-half-builder .tbc-half-ic { background: var(--tbc-blue); }
.tbc-half-brain .tbc-half-ic { background: var(--tbc-orange); }
.tbc-half-builder .tbc-half-ic .ic { animation: tbc-stack 2.4s ease-in-out 2; }
.tbc-half-brain .tbc-half-ic .ic { animation: tbc-think 2.4s ease-in-out 2; }
.tbc-half-text { display: flex; flex-direction: column; line-height: 1.12; white-space: nowrap; }
.tbc-half-right .tbc-half-text { align-items: flex-end; text-align: right; }
.tbc-half-text small {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--tbc-soft);
}
.tbc-half-text b { font-family: var(--tbc-title); font-size: 16px; font-weight: 800; }

/* side arrows (role cards and chip): a quarter turn makes them point up and down in the tall layout */
.tbc-dir { --nx: -3px; --ny: 0px; display: inline-grid; place-items: center; flex: none; }
.tbc-dir-right { --nx: 3px; }
.tbc-dir.is-tall { --nx: 0px; --ny: -3px; }
.tbc-dir-right.is-tall { --ny: 3px; }
.tbc-dir.is-tall .ic { transform: rotate(90deg); }
.tbc-half .tbc-dir { animation: tbc-nudge 0.9s ease-in-out 0.4s 3 both; }
.tbc-tray {
  display: none;
  grid-template-columns: repeat(4, 80px);
  gap: 8px;
  padding: 10px;
  border: var(--tbc-line);
  border-radius: 20px;
  background: var(--tbc-cream);
  box-shadow: var(--tbc-shadow);
}
.tbc-hud[data-open="1"] .tbc-tray { display: grid; animation: tbc-drop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
.tbc-hud .tbc-askcard { width: 100%; }
.tbc-hud .tbc-askcard .tbc-btn { min-height: 48px; font-size: 16px; padding: 0 14px; }

/* Docked (js/net/coopui.js place()): the chip sits in the free middle of the shell's top bar, level with
   the robot's name, so it never covers a side panel. --tbc-x is the middle of that gap. The tray, the ask
   cards and the reaction bubbles hang under it. Too narrow for the words: icons only (is-tight). */
.tb-coop.tbc-hud.is-docked {
  top: calc(var(--safe-t, 0px) + 10px + (var(--hud-h, 56px) - 50px) / 2);
  left: var(--tbc-x, 50%);
  right: auto;
  width: min(372px, calc(100vw - 24px));
  transform: translateX(-50%);
  align-items: center;
}
.tbc-hud.is-docked .tbc-chip { min-height: 50px; }
.tbc-hud.is-docked button.tbc-chip { padding: 4px 10px 4px 4px; gap: 8px; }
.tbc-hud.is-docked button.tbc-chip .tbc-avatar { width: 38px; height: 38px; font-size: 18px; }
.tbc-hud.is-docked .tbc-chip-state { width: 32px; height: 32px; }
.tbc-hud.is-docked .tbc-bubbles { align-items: center; }
.tbc-hud.is-tight .tbc-chip-text,
.tbc-hud.is-tight .tbc-half-text { display: none; }
.tbc-hud.is-tight .tbc-half { padding: 4px 10px 4px 8px; }
.tbc-hud.is-tight .tbc-half-right { padding: 4px 8px 4px 10px; }
/* the Together panel is open: it already shows the roles, the friend and the signs */
.tbc-hud.is-docked.has-panel > .tbc-chip,
.tbc-hud.is-docked.has-panel > .tbc-tray,
.tbc-hud.is-docked.has-panel > .tbc-askcard { display: none !important; }
.tbc-hud.is-docked.has-panel .tbc-bubbles { margin-top: 64px; }
/* no top bar (title, photo booth): the role reminder steps away with the rest of the chrome */
.tb-coop.tbc-hud.is-away { display: none; }

/* reaction bubbles that pop and float away */
.tbc-bubbles {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  min-height: 0;
  pointer-events: none !important;
}
.tbc-bubble {
  --c: #2E8BC9;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 6px;
  border: var(--tbc-line);
  border-radius: 999px;
  background: var(--tbc-paper);
  box-shadow: var(--tbc-shadow);
  font-family: var(--tbc-title);
  font-size: 17px;
  font-weight: 800;
  animation: tbc-bubble 2.6s cubic-bezier(0.2, 1.2, 0.4, 1) forwards;
}
.tbc-bubble.is-me { padding-left: 10px; opacity: 0.92; }
.tbc-bubble .tbc-avatar { width: 34px; height: 34px; font-size: 16px; }
.tbc-bubble-ic {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--c) 22%, #fff);
  border: 2px solid var(--tbc-ink);
}
.tbc-anim-wave .tbc-bubble-ic .ic { animation: tbc-wave 0.5s ease-in-out 4; transform-origin: 70% 85%; }
.tbc-anim-cheer .tbc-bubble-ic .ic { animation: tbc-cheer 0.7s cubic-bezier(0.2, 1.6, 0.4, 1) 2; }
.tbc-anim-ping .tbc-bubble-ic { animation: tbc-ping 0.9s ease-out 2; }
.tbc-anim-heart .tbc-bubble-ic .ic { animation: tbc-beat 0.6s ease-in-out 3; color: var(--tbc-coral); fill: var(--tbc-coral); }
.tbc-anim-thinking .tbc-bubble-ic .ic { animation: tbc-think 1.2s ease-in-out 2; }
.tbc-anim-yes .tbc-bubble-ic .ic { animation: tbc-nod 0.45s ease-in-out 3; color: var(--tbc-green); }
.tbc-anim-no .tbc-bubble-ic .ic { animation: tbc-shake 0.4s ease-in-out 3; color: var(--tbc-coral); }
.tbc-anim-help .tbc-bubble-ic .ic { animation: tbc-hop 0.5s ease-in-out 4; color: var(--tbc-orange); }

/* ------------------------------------------------------------------ the hand-off card (same screen) */

.tb-coop.tbc-handoff {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(22, 34, 58, 0.45);
  animation: tbc-fade 0.25s ease both;
}
.tbc-handoff-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(420px, 100%);
  padding: 28px 24px 24px;
  border: var(--tbc-line);
  border-radius: 28px;
  background: var(--tbc-cream);
  box-shadow: 0 8px 0 var(--tbc-ink);
  text-align: center;
  animation: tbc-bounce-in 0.55s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.tbc-handoff-card h3 { font-size: 30px; font-weight: 800; }
.tbc-handoff-card p { font-size: 18px; font-weight: 700; color: var(--tbc-soft); }

/* ------------------------------------------------------------------ layout for smaller screens */

@media (max-width: 760px) {
  .tbc-choices { grid-template-columns: 1fr; }
  .tbc-choice { min-height: 0; flex-direction: row; flex-wrap: wrap; justify-content: flex-start; text-align: left; gap: 4px 14px; padding: 14px; }
  .tbc-choice-art { width: 64px; height: 64px; margin: 0; border-radius: 20px; }
  .tbc-choice-title, .tbc-choice-sub { flex: 1 1 60%; }
  .tbc-choice-art + .tbc-choice-title { align-self: flex-end; }
  .tbc-lock { margin-top: 4px; }
  .tbc-roles { grid-template-columns: 1fr; }
  .tbc-swap { flex-direction: row; min-height: 52px; justify-self: center; padding: 6px 16px; }
  .tbc-reacts { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tbc-picgrid { grid-template-columns: repeat(4, minmax(0, 1fr)); width: 100%; }
  .tbc-keypad { grid-template-columns: repeat(5, minmax(48px, 64px)); }
  .tbc-code-pic { min-width: 76px; }
}
/* landscape tablets: the 16 pictures in two rows of 8, so the whole pad (and its Join button) clears the dock */
@media (min-width: 761px) and (max-height: 900px) {
  .tbc-picgrid { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; width: 100%; }
  .tbc-pic { padding: 8px 2px 6px; }
  /* (the button's own font-size loses to ".tb-coop button { font: inherit }", so size the label itself) */
  .tbc-pic > span { max-width: 100%; text-align: center; line-height: 1.15; font-size: 14px; }
  .tbc-pic.is-long > span { font-size: 12px; letter-spacing: -0.01em; }
}
@media (max-height: 760px) {
  .tbc-body { gap: 14px; padding: 16px; }
  .tbc-pic { min-height: 76px; }
  .tbc-slot { width: 64px; height: 64px; }
}

/* ------------------------------------------------------------------ motion */

@keyframes tbc-rise { from { opacity: 0; transform: translateY(14px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes tbc-drop { from { opacity: 0; transform: translateY(-10px) scale(0.95); } to { opacity: 1; transform: none; } }
@keyframes tbc-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes tbc-pop { 0% { transform: scale(0.6); } 70% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes tbc-bounce-in { 0% { opacity: 0; transform: scale(0.4) translateY(20px); } 60% { opacity: 1; transform: scale(1.08) translateY(-4px); } 80% { transform: scale(0.97, 1.03); } 100% { transform: none; } }
@keyframes tbc-deal { 0% { opacity: 0; transform: translateY(-30px) rotate(-12deg) scale(0.7); } 70% { opacity: 1; transform: translateY(3px) rotate(3deg) scale(1.04); } 100% { opacity: 1; } }
@keyframes tbc-wobble-in { 0% { opacity: 0; transform: translateX(-10px); } 40% { opacity: 1; transform: translateX(6px); } 70% { transform: translateX(-3px); } 100% { transform: none; } }
@keyframes tbc-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
@keyframes tbc-dot { 0%, 80%, 100% { transform: translateY(0); opacity: 0.35; } 40% { transform: translateY(-5px); opacity: 1; } }
@keyframes tbc-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes tbc-knock { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-8deg) scale(1.05, 0.95); } 40% { transform: rotate(6deg); } 60% { transform: rotate(-3deg); } }
@keyframes tbc-stack { 0%, 100% { transform: translateY(0); } 30% { transform: translateY(-4px) scale(1.05, 0.95); } 50% { transform: translateY(0) scale(0.95, 1.05); } }
@keyframes tbc-think { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-3px) rotate(-6deg); } }
@keyframes tbc-wave { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(18deg); } 75% { transform: rotate(-12deg); } }
@keyframes tbc-cheer { 0% { transform: scale(0.6) rotate(-30deg); } 60% { transform: scale(1.3) rotate(15deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes tbc-ping { 0% { box-shadow: 0 0 0 0 rgba(46, 139, 201, 0.7); } 100% { box-shadow: 0 0 0 18px rgba(46, 139, 201, 0); } }
@keyframes tbc-beat { 0%, 100% { transform: scale(1); } 30% { transform: scale(1.3); } 60% { transform: scale(0.95); } }
@keyframes tbc-nod { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(5px); } }
@keyframes tbc-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes tbc-hop { 0%, 100% { transform: translateY(0) scale(1); } 40% { transform: translateY(-7px) scale(0.95, 1.08); } 70% { transform: translateY(0) scale(1.08, 0.92); } }
@keyframes tbc-sent { 0% { transform: scale(1); } 40% { transform: scale(1.15) rotate(-4deg); } 100% { transform: scale(1); } }
@keyframes tbc-nudge { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(var(--nx), var(--ny)); } }
@keyframes tbc-ring { from { opacity: 1; transform: scale(0.9); } to { opacity: 0; transform: scale(1.25); } }
@keyframes tbc-bubble {
  0% { opacity: 0; transform: translateX(30px) scale(0.5); }
  12% { opacity: 1; transform: translateX(-4px) scale(1.06); }
  20% { transform: none; }
  82% { opacity: 1; transform: translateY(-6px); }
  100% { opacity: 0; transform: translateY(-34px) scale(0.92); }
}

@media (prefers-reduced-motion: reduce) {
  .tb-coop *, .tb-coop *::before, .tb-coop *::after, .tb-coop.tbc-panel, .tb-coop.tbc-handoff {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .tbc-bubble { animation: tbc-fade 0.01ms both !important; }
}
