.tts-chat {
  --chat-bg: #101b29;
  --chat-text: #f5f9ff;
  --chat-surface: #1a2b3f;
  --chat-accent: #6ce8f1;
  --chat-edge: #3b5969;
  position: fixed;
  z-index: 950;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  font: 15px/1.45 system-ui, sans-serif;
}

[data-theme="light"] .tts-chat {
  --chat-bg: #fff;
  --chat-text: #102437;
  --chat-surface: #eaf3f7;
  --chat-accent: #006579;
  --chat-edge: #9ab7c2;
}

.tts-chat button {
  cursor: pointer;
  font: inherit;
}

.tts-chat .tts-chat-form button {
  background: #8beaf0;
  border: 1px solid #318c9a;
  border-radius: 999px;
  color: #08252e !important;
  font-weight: 700;
  padding: 10px 16px;
}

.tts-chat-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  display: flex;
  flex-direction: column;
  width: min(370px, calc(100vw - 32px));
  height: min(480px, calc(100dvh - 102px));
  background: var(--chat-bg);
  border: 1px solid var(--chat-edge);
  border-radius: 16px;
  box-shadow: 0 12px 38px #0004;
  overflow: hidden;
}

.tts-chat-panel[hidden] { display: none; }

.tts-chat-header, .tts-chat-form, .tts-chat-choices {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
}

.tts-chat-header { justify-content: space-between; border-bottom: 1px solid var(--chat-edge); }
.tts-chat-header h2 { margin: 0; font: 700 16px/1.3 system-ui, sans-serif; }
.tts-chat-header button { padding: 3px 10px; }
.tts-chat-reset { margin-left: auto; }
.tts-chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; }
.tts-chat-message { background: var(--chat-surface); border-radius: 10px; padding: 9px 11px; margin-bottom: 8px; overflow-wrap: anywhere; }
.tts-chat-message p { margin: 0; }
.tts-chat-message a { display: block; margin-top: 6px; color: var(--chat-accent) !important; }
.tts-chat-visitor { margin-left: 20px; border-left: 2px solid var(--chat-accent); }
.tts-chat-choices { flex-wrap: wrap; padding-block: 5px; }
.tts-chat-choices button { padding: 4px 9px; }
.tts-chat-form { border-top: 1px solid var(--chat-edge); }
.tts-chat-form input { width: 100%; min-width: 0; padding: 9px; font: inherit; }
.tts-chat-header button, .tts-chat-choices button, .tts-chat-form input {
  background: var(--chat-bg);
  border: 1px solid var(--chat-edge);
  border-radius: 8px;
}
.tts-chat .tts-chat-panel :is(h2, p, input, .tts-chat-close, .tts-chat-reset, .tts-chat-choices button) { color: var(--chat-text) !important; }
.tts-chat :is(button, input, a):focus-visible { outline: 2px solid var(--chat-accent); outline-offset: 2px; }


.tts-chat .tts-chat-launch {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  padding: 0;
  border: 1px solid #318c9a;
  border-radius: 50%;
  background: #8beaf0;
  box-shadow: 0 5px 20px #092a3c44;
}

.tts-chat-robot {
  position: relative;
  scale: 1.55;
  pointer-events: none;
  width: 34px;
  height: 32px;
  animation: tts-robot-bob 3s ease-in-out infinite;
}

.tts-robot-antenna, .tts-robot-face, .tts-robot-body, .tts-robot-arm {
  position: absolute;
}

.tts-robot-antenna {
  top: 2px;
  left: 14px;
  width: 2px;
  height: 7px;
  background: #17445a;
}

.tts-robot-antenna::before {
  content: '';
  position: absolute;
  top: -2px;
  left: -2px;
  width: 6px;
  height: 6px;
  background: #a8ee57;
  border: 1px solid #17445a;
  border-radius: 50%;
}

.tts-robot-face {
  top: 8px;
  left: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 24px;
  height: 15px;
  border: 2px solid #f2fbff;
  border-radius: 6px;
  background: #133444;
  box-shadow: 0 0 0 1px #17445a;
}

.tts-robot-face > span {
  width: 4px;
  height: 5px;
  border-radius: 50%;
  background: #93fff4;
  animation: tts-robot-blink 4.5s linear infinite;
}

.tts-robot-body {
  left: 9px;
  bottom: 1px;
  width: 12px;
  height: 7px;
  border: 1px solid #17445a;
  border-radius: 3px 3px 5px 5px;
  background: #f2fbff;
}

.tts-robot-arm {
  left: 22px;
  bottom: 4px;
  width: 10px;
  height: 4px;
  border: 1px solid #17445a;
  border-radius: 4px;
  background: #f2fbff;
  transform-origin: 1px center;
}

.tts-chat-launch:is(:hover, :focus-visible, [aria-expanded="true"]) .tts-chat-robot .tts-robot-arm {
  animation: tts-robot-wave 800ms ease-in-out 2;
}

@keyframes tts-robot-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

@keyframes tts-robot-blink {
  0%, 44%, 50%, 100% { transform: scaleY(1); }
  46%, 48% { transform: scaleY(.15); }
}

@keyframes tts-robot-wave {
  0%, 100% { transform: rotate(0); }
  30%, 70% { transform: rotate(-58deg); }
  50% { transform: rotate(-22deg); }
}

@media (prefers-reduced-motion: reduce) {
  .tts-chat .tts-chat-robot,
  .tts-chat .tts-robot-face > span,
  .tts-chat .tts-chat-launch .tts-chat-robot .tts-robot-arm {
    animation: none;
  }
}
