/* Clipford's layer: the 3D overlay, his retro help balloon, and the chat. */

.clipford-canvas {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
}

html.clip-hover,
html.clip-hover * {
  cursor: grab !important;
}
html.clip-dragging,
html.clip-dragging * {
  cursor: grabbing !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

/* ---------------------------------------------------------------- balloon
   Deliberately 2003: pale yellow, hairline black border, Tahoma. */

.clip-balloon {
  --tail-x: 40px;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 70;
  max-width: min(270px, calc(100vw - 24px));
  padding: 11px 13px 12px;
  background: #ffffe1;
  color: #000;
  border: 1px solid #000;
  border-radius: 9px;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.22);
  font: 13.5px/1.42 Tahoma, Verdana, "Segoe UI", sans-serif;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s, visibility 0s linear 0.18s;
}
.clip-balloon.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.18s;
}
.clip-balloon::before,
.clip-balloon::after {
  content: "";
  position: absolute;
  left: var(--tail-x);
  border-style: solid;
}
.clip-balloon::before {
  bottom: -15px;
  border-width: 15px 9px 0 9px;
  border-color: #000 transparent transparent transparent;
  transform: skewX(20deg);
}
.clip-balloon::after {
  bottom: -13px;
  margin-left: 1px;
  border-width: 14px 8px 0 8px;
  border-color: #ffffe1 transparent transparent transparent;
  transform: skewX(20deg);
}
.clip-balloon.tail-right::before,
.clip-balloon.tail-right::after {
  transform: skewX(-20deg);
}
.clip-balloon p {
  margin: 0 0 6px;
}
.clip-balloon p:last-child {
  margin-bottom: 0;
}
.clip-balloon strong {
  font-weight: 700;
}
.clip-balloon__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.clip-balloon.has-buttons .clip-balloon__buttons {
  margin-top: 10px;
}
.clip-balloon__buttons button {
  min-width: 72px;
  min-height: 24px;
  padding: 2px 12px;
  font: 12px Tahoma, Verdana, sans-serif;
  color: #000;
  background: linear-gradient(#ffffff, #ece9d8);
  border: 1px solid #003c74;
  border-radius: 3px;
  cursor: pointer;
}
.clip-balloon__buttons button:hover {
  box-shadow: inset 0 0 0 2px #f8b636;
}
.clip-balloon__buttons button:focus-visible {
  outline: 1px dotted #000;
  outline-offset: -4px;
}

/* ---------------------------------------------------------------- launcher */

.launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 45;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 22px 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--white);
  font: inherit;
  font-weight: 750;
  font-variation-settings: "wdth" 108;
  box-shadow: 0 16px 34px -12px rgba(14, 26, 63, 0.55);
  cursor: pointer;
  transition: transform 0.2s, opacity 0.2s;
}
.launcher:hover {
  background: var(--ink-3);
}
.launcher__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #3bc48b;
  box-shadow: 0 0 0 0 rgba(59, 196, 139, 0.6);
  animation: ping 2.2s infinite;
}
@keyframes ping {
  0% {
    box-shadow: 0 0 0 0 rgba(59, 196, 139, 0.55);
  }
  80%,
  100% {
    box-shadow: 0 0 0 12px rgba(59, 196, 139, 0);
  }
}
.chat-open .launcher {
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
}

/* ---------------------------------------------------------------- chat */

.chat {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  width: 400px;
  height: min(660px, calc(100svh - 48px));
  background: var(--white);
  border: 1px solid var(--rule);
  border-radius: 20px;
  box-shadow:
    0 40px 80px -30px rgba(14, 26, 63, 0.45),
    0 0 0 1px rgba(14, 26, 63, 0.02);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.22s, transform 0.26s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.chat.is-open {
  opacity: 1;
  transform: none;
}
.chat[hidden] {
  display: none;
}
.chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 14px 16px;
  border-bottom: 1px solid var(--rule);
}
.chat__id {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.chat__avatar {
  flex: none;
  width: 38px;
  height: 38px;
}
.chat__name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-variation-settings: "wdth" 112;
  color: var(--ink);
  line-height: 1.2;
}
.verified {
  padding: 1px 6px;
  border-radius: 4px;
  background: #e5ecff;
  color: var(--pen);
  font-size: 0.68rem;
  font-weight: 800;
}
.chat__status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}
.chat__online {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3bc48b;
}
.chat__tools {
  display: flex;
  align-items: center;
  gap: 4px;
}
.chat__modelbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--rule);
  background: #fafbfc;
  font-size: 0.78rem;
  color: var(--muted);
}
.chat__model {
  flex: 1;
  height: 32px;
  padding: 0 6px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--paper);
  color: var(--ink);
}
.icon-btn svg {
  width: 20px;
  height: 20px;
}
#chat-mute .ico-off,
#chat-mute[data-muted="1"] .ico-on {
  display: none;
}
#chat-mute[data-muted="1"] .ico-off {
  display: block;
}

.chat__log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
}

.msg {
  max-width: 88%;
  font-size: 0.95rem;
  line-height: 1.5;
}
.msg--user {
  align-self: flex-end;
}
.msg--user .msg__body {
  padding: 10px 14px;
  background: var(--pen);
  color: var(--white);
  border-radius: 16px 16px 4px 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg--bot {
  align-self: flex-start;
}
.msg--bot .msg__body {
  padding: 11px 14px;
  background: var(--paper);
  border: 1px solid #e3e7ef;
  border-radius: 16px 16px 16px 4px;
  overflow-wrap: anywhere;
}
.msg__body p {
  margin: 0 0 8px;
}
.msg__body p:last-child {
  margin-bottom: 0;
}
.msg__body ul,
.msg__body ol {
  margin: 4px 0 8px;
  padding-left: 22px;
}
.msg__body code {
  padding: 1px 5px;
  border-radius: 4px;
  background: #e4e8f1;
  font-family: var(--mono);
  font-size: 0.85em;
}
.msg__body pre {
  margin: 8px 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: #e3e8f8;
  overflow-x: auto;
  font-size: 0.8rem;
  line-height: 1.5;
}
.msg__body pre code {
  padding: 0;
  background: none;
  font-size: inherit;
}
.msg__body.is-typing > :last-child::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1em;
  margin-left: 2px;
  vertical-align: -0.15em;
  background: var(--pen);
  animation: caret 0.7s steps(2) infinite;
}
@keyframes caret {
  50% {
    opacity: 0;
  }
}

.msg__think {
  margin-bottom: 6px;
  font-size: 0.8rem;
  color: var(--muted);
}
.msg__think summary {
  cursor: pointer;
  width: fit-content;
}
.msg__think ol {
  margin: 6px 0 4px;
  padding: 6px 0 6px 28px;
  border-left: 2px solid var(--rule);
}
.msg__tag {
  margin-bottom: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--gold);
}
.msg__foot {
  margin-top: 6px;
}
.msg__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 4px;
  font-size: 0.76rem;
  color: var(--muted);
}
.msg__conf {
  margin-right: 4px;
  font-variant-numeric: tabular-nums;
}
.msg__btn {
  min-height: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.msg__btn:hover {
  background: var(--paper);
  color: var(--ink);
}
.msg__btn--icon {
  width: 28px;
  padding: 0;
  position: relative;
}
.msg__btn--icon::before {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: var(--ico) center / contain no-repeat;
  mask: var(--ico) center / contain no-repeat;
}
.msg__btn.is-up {
  --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2 10h4v12H2zM8 21h9.5a2 2 0 0 0 2-1.6l1.4-7A2 2 0 0 0 19 10h-5.5l1-4.3A2 2 0 0 0 12.6 3L8 9.6z'/%3E%3C/svg%3E");
}
.msg__btn.is-down {
  --ico: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M22 14h-4V2h4zM16 3H6.5a2 2 0 0 0-2 1.6l-1.4 7A2 2 0 0 0 5 14h5.5l-1 4.3a2 2 0 0 0 1.9 2.7L16 14.4z'/%3E%3C/svg%3E");
}
.msg__btn--icon.is-on {
  color: var(--pen);
  background: #e5ecff;
}
.msg__sources {
  margin: 4px 0 0;
  padding: 8px 10px 8px 28px;
  border-radius: 8px;
  background: #fafbfc;
  border: 1px dashed var(--rule);
  font-size: 0.8rem;
  color: var(--text-2);
}

.msg--typing {
  display: flex;
  align-items: center;
  gap: 10px;
}
.typing {
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--paper);
  border: 1px solid #e3e7ef;
  border-radius: 16px 16px 16px 4px;
}
.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8d97ab;
  animation: hop 1s infinite;
}
.typing span:nth-child(2) {
  animation-delay: 0.15s;
}
.typing span:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes hop {
  0%,
  60%,
  100% {
    transform: none;
  }
  30% {
    transform: translateY(-5px);
  }
}
.typing__status {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

.chat__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 16px 10px;
}
.chat__chips[hidden] {
  display: none;
}
.chip {
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--white);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.chip:hover {
  border-color: var(--pen);
  background: #f2f5ff;
}

.chat__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 12px;
  padding: 8px 8px 8px 14px;
  border: 1.5px solid var(--rule);
  border-radius: 14px;
  background: var(--white);
  transition: border-color 0.15s;
}
.chat__form:focus-within {
  border-color: var(--pen);
}
.chat__form textarea {
  flex: 1;
  min-height: 24px;
  max-height: 140px;
  padding: 6px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.45;
}
.chat__send {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: var(--pen);
  color: var(--white);
  cursor: pointer;
}
.chat__send svg {
  width: 20px;
  height: 20px;
}
.chat__form.is-busy .chat__send {
  background: var(--steel);
  cursor: progress;
}
.chat__fine {
  padding: 8px 16px 12px;
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
}

@media (max-width: 760px) {
  .launcher {
    right: 16px;
    bottom: 16px;
  }
  .chat {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    height: min(76svh, 640px);
    border-radius: 18px;
  }
  .chat__status {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .launcher__dot,
  .typing span {
    animation: none;
  }
}
