.botty {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  justify-items: end;
  align-items: start;
  column-gap: 8px;
  row-gap: 8px;
  z-index: 9999;
  pointer-events: none;
}
.botty[data-state="hidden"] { display: none; }

.botty > * { pointer-events: auto; }

/* Panel sits across both columns, above the bubble + sprite row. */
.botty-panel  { grid-row: 1; grid-column: 1 / span 2; }
/* Bubble: left column, top-aligned with the sprite. */
.botty-bubble { grid-row: 2; grid-column: 1; align-self: start; }
/* Sprite: right column, taller, defines the row height. */
.botty-sprite { grid-row: 2; grid-column: 2; align-self: start; }
.botty-turnstile-mount { grid-row: 2; grid-column: 2; }

.botty-sprite {
  width: 84px;
  height: 84px;
  background: var(--card-body, #fffbe6);
  border: 3px solid #000;
  box-shadow: 5px 5px 0 #000;
  cursor: pointer;
  padding: 0;
  position: relative;
  display: block;
}
.botty-sprite:active {
  transform: translate(2px, 2px);
  box-shadow: 3px 3px 0 #000;
}

/* SVG face fills the inner sprite area. */
.botty-face {
  position: absolute;
  inset: 10px;
  width: calc(100% - 20px);
  height: calc(100% - 20px);
  fill: #000;
  pointer-events: none;
  will-change: transform;
}
/* Hide every part-group by default. JS toggles which one is visible. */
.botty-face g[data-part] { display: none; }

/* Speech bubble — top-aligned with the sprite's face. */
.botty-bubble {
  position: relative;
  background: #fff;
  border: 2px solid #000;
  padding: 6px 10px;
  font-family: var(--font-mono, "VT323", monospace);
  font-size: 14px;
  line-height: 1.3;
  max-width: 240px;
  box-shadow: 2px 2px 0 #000;
  animation: botty-bubble-in 280ms cubic-bezier(.2,.8,.4,1.2) both;
}
/* SVG tail: base sits on the bubble's bottom edge, tip slants down-right
   toward the sprite. Two polygons (black outer + white inner) form the
   border. */
.botty-bubble-tail {
  position: absolute;
  right: 8px;
  top: 100%;
  width: 22px;
  height: 16px;
  /* Pull up 2px so the white polygon's flat top hides the bubble's border line. */
  margin-top: -2px;
  pointer-events: none;
  display: block;
}
@keyframes botty-bubble-in {
  from { transform: translateY(4px) scale(.94); opacity: 0; }
  to   { transform: translateY(0) scale(1);     opacity: 1; }
}

/* Panel */
.botty-panel {
  width: 320px;
  background: var(--card-body, #fffbe6);
  border: 3px solid #000;
  box-shadow: 5px 5px 0 #000;
  display: flex;
  flex-direction: column;
}
.botty-panel[hidden] { display: none; }
.botty-bubble[hidden] { display: none; }
.botty-panel-head {
  background: var(--accent-pink, #ff6fb3);
  border-bottom: 3px solid #000;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono, "VT323", monospace);
  font-weight: 700;
  font-size: 13px;
}
.botty-panel-close {
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
}
.botty-panel-log {
  padding: 10px;
  height: 220px;
  overflow-y: auto;
  font-family: var(--font-mono, "VT323", monospace);
  font-size: 14px;
  line-height: 1.35;
  background: #fff;
  border-bottom: 2px solid #000;
}
.botty-panel-log .msg { margin: 0 0 8px; word-wrap: break-word; }
.botty-panel-log .msg .who { font-weight: 700; margin-right: 4px; }
.botty-panel-log .msg.bot .who { color: #2f7a4d; }
.botty-panel-log .msg.you .who { color: #c14b8c; }
.botty-panel-log .msg.err .who { color: #b53b3b; }

.botty-panel-form {
  padding: 8px;
  display: flex;
  gap: 6px;
}
.botty-panel-form input {
  flex: 1;
  border: 2px solid #000;
  background: #fff;
  padding: 6px 8px;
  font-family: var(--font-mono, "VT323", monospace);
  font-size: 13px;
}
.botty-panel-form button {
  border: 2px solid #000;
  background: var(--accent-yellow, #ffe14d);
  padding: 6px 12px;
  font-family: var(--font-mono, "VT323", monospace);
  font-weight: 700;
  font-size: 12px;
  box-shadow: 2px 2px 0 #000;
  cursor: pointer;
}
.botty-panel-form button:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 #000;
}
/* Turnstile mount: lives inside the chat panel. With Managed mode, it
   stays invisible for clean traffic and renders a checkbox for VPN /
   suspect traffic. The :empty selector keeps the panel tight when the
   widget hasn't rendered anything. */
.botty-turnstile-mount { padding: 0 8px; }
.botty-turnstile-mount:empty { padding: 0; }

/* Mobile takeover */
@media (max-width: 540px) {
  /* Don't pin the left edge — let the grid shrink to content so the
     bubble sits right next to the sprite instead of stretching to fill. */
  .botty { bottom: 12px; right: 12px; }
  .botty-panel {
    /* Panel still spans full available width when open. */
    width: calc(100vw - 24px);
    max-width: 360px;
    max-height: 60vh;
  }
  .botty-bubble { max-width: 60vw; }
}
