/* Root-level extension: styles stay scoped, leaving Butterfly and custom assets intact. */
.blog-ai {
  --ai-bg: #f5fbff;
  --ai-inset: #e7f4fd;
  --ai-text: #1f3a4d;
  --ai-muted: #4a7286;
  --ai-accent: #0e76be;
  --ai-border: #c3e2f6;
  --ai-focus: #1e97e0;
  color: var(--ai-text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.65;
  text-align: left;
  color-scheme: light;
}

[data-theme="dark"] .blog-ai {
  --ai-bg: #16232e;
  --ai-inset: #1f3040;
  --ai-text: #e3f2fb;
  --ai-muted: #a9c6d9;
  --ai-accent: #6cc4f7;
  --ai-border: #33505f;
  --ai-focus: #8ed6ff;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .blog-ai {
    --ai-bg: #16232e;
    --ai-inset: #1f3040;
    --ai-text: #e3f2fb;
    --ai-muted: #a9c6d9;
    --ai-accent: #6cc4f7;
    --ai-border: #33505f;
    --ai-focus: #8ed6ff;
    color-scheme: dark;
  }
}

.blog-ai *, .blog-ai *::before, .blog-ai *::after { box-sizing: border-box; }
.blog-ai [hidden] { display: none !important; }
.blog-ai button, .blog-ai textarea { font: inherit; }
.blog-ai button {
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--ai-border);
  border-radius: 12px;
  background: var(--ai-inset);
  color: var(--ai-text);
  cursor: pointer;
  line-height: 1.5;
  white-space: normal;
}
.blog-ai button:not(:disabled):hover { border-color: var(--ai-accent); }
.blog-ai button:disabled { cursor: default; opacity: .6; }
.blog-ai :focus-visible { outline: 3px solid var(--ai-focus); outline-offset: 3px; }

.blog-ai-assistant {
  position: fixed;
  right: max(72px, env(safe-area-inset-right));
  bottom: max(40px, env(safe-area-inset-bottom));
  z-index: 101;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}
.blog-ai-assistant > * { pointer-events: auto; }
.blog-ai .blog-ai-launcher {
  position: relative;
  display: block;
  width: 64px;
  height: 64px;
  padding: 4px;
  border: 0;
  border-radius: 32px;
  background: none;
  box-shadow: none;
  transform-origin: bottom center;
  transition: transform .22s ease-out;
}
.blog-ai .blog-ai-launcher:hover,
.blog-ai .blog-ai-launcher:focus-visible { transform: translateY(-4px) scale(1.06); }
.blog-ai .blog-ai-launcher:active { transform: translateY(1px) scale(.95); }
/* The ground shadow stays put while the body bounces, so it breathes out of phase. */
.blog-ai .blog-ai-launcher::after {
  content: '';
  position: absolute;
  right: 4px;
  bottom: -1px;
  width: 56px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(50% 50% at 50% 50%, rgb(37 128 196 / 48%) 0%, rgb(37 128 196 / 0%) 72%);
  filter: blur(2px);
  animation: blog-ai-shadow 3.4s ease-in-out infinite;
  pointer-events: none;
}
.blog-ai .blog-ai-blob {
  position: relative;
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 47% 53% 44% 56% / 53% 47% 53% 47%;
  background:
    radial-gradient(72% 62% at 24% 16%, rgb(255 255 255 / 45%) 0%, rgb(255 255 255 / 0%) 62%),
    linear-gradient(148deg, #9bdcff 0%, #6cc6fb 30%, #49b1f5 58%, #2f92dd 82%, #1f7cc8 100%);
  box-shadow:
    inset -5px -7px 14px rgb(13 82 138 / 34%),
    inset 4px 5px 12px rgb(255 255 255 / 34%),
    0 9px 22px rgb(45 146 221 / 40%);
  animation: blog-ai-bounce 3.4s ease-in-out infinite;
}
.blog-ai .blog-ai-eye {
  position: absolute;
  top: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 19px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgb(18 66 100 / 35%);
  animation: blog-ai-face 7.6s ease-in-out infinite;
}
.blog-ai .blog-ai-eye--left { left: 13px; }
.blog-ai .blog-ai-eye--right { right: 13px; }
.blog-ai .blog-ai-pupil {
  width: 6px;
  height: 9px;
  border-radius: 999px;
  background: #123a55;
  transform: translate(calc(var(--ai-look-x, 0) * 3px), calc(var(--ai-look-y, 0) * 2.5px));
  transition: transform .18s ease-out, width .18s ease-out, height .18s ease-out;
}
.blog-ai .blog-ai-launcher:hover .blog-ai-pupil,
.blog-ai .blog-ai-launcher:focus-visible .blog-ai-pupil { width: 7px; height: 12px; }
.blog-ai .blog-ai-launcher-label {
  position: absolute;
  right: 68px;
  top: 50%;
  padding: 7px 12px;
  border: 1px solid var(--ai-border);
  border-radius: 14px;
  background: var(--ai-bg);
  box-shadow: 0 5px 18px rgb(16 58 86 / 14%);
  color: var(--ai-accent);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(-50%) translateX(8px);
  transition: opacity .2s ease-out, transform .2s ease-out;
  pointer-events: none;
}
.blog-ai .blog-ai-launcher:hover .blog-ai-launcher-label,
.blog-ai .blog-ai-launcher:focus-visible .blog-ai-launcher-label { opacity: 1; transform: translateY(-50%); }
/* An open conversation leaves nothing to advertise, and a touch screen has no hover to earn it. */
.blog-ai .blog-ai-launcher[aria-expanded="true"]:hover .blog-ai-launcher-label,
.blog-ai .blog-ai-launcher[aria-expanded="true"]:focus-visible .blog-ai-launcher-label {
  opacity: 0;
  transform: translateY(-50%) translateX(8px);
}

/* A generation in progress reads as a face working, not as a stuck picture: the launcher bounces
   quicker and its pupils search while the answer is still being made. */
.blog-ai .blog-ai-launcher[data-thinking="true"] .blog-ai-blob { animation-duration: 1.1s; }
.blog-ai .blog-ai-launcher[data-thinking="true"] .blog-ai-pupil {
  transform: none;
  animation: blog-ai-roam 1.4s ease-in-out infinite;
}
.blog-ai .blog-ai-launcher[data-thinking="true"] .blog-ai-eye--right .blog-ai-pupil { animation-delay: .18s; }

@keyframes blog-ai-bounce {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  30% { transform: translateY(-7px) scale(.98, 1.03); }
  50% { transform: translateY(0) scale(1.05, .93); }
  62% { transform: translateY(-3px) scale(.99, 1.02); }
  74% { transform: translateY(0) scale(1.02, .97); }
}
@keyframes blog-ai-shadow {
  0%, 100% { transform: scaleX(1); opacity: .9; }
  30% { transform: scaleX(.74); opacity: .45; }
  50% { transform: scaleX(1.1); opacity: 1; }
  62% { transform: scaleX(.88); opacity: .62; }
  74% { transform: scaleX(1.04); opacity: .95; }
}
@keyframes blog-ai-face {
  0%, 100% { transform: translate(0, 0) scaleY(1); }
  14% { transform: translate(-2px, 1px) scaleY(1); }
  32% { transform: translate(2px, -1px) scaleY(1); }
  44% { transform: translate(2px, -1px) scaleY(1); }
  47% { transform: translate(2px, -1px) scaleY(.12); }
  50% { transform: translate(2px, -1px) scaleY(1); }
  68% { transform: translate(-1px, 2px) scaleY(1); }
  84% { transform: translate(1px, -2px) scaleY(1); }
}
@keyframes blog-ai-caret {
  0%, 55% { opacity: 1; }
  55.01%, 100% { opacity: 0; }
}
/* The thinking pulse for both faces: dots breathe, pupils search. Each keeps a visible resting
   state, because prefers-reduced-motion turns every animation off below. */
@keyframes blog-ai-breathe {
  0%, 70%, 100% { opacity: .35; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-3px); }
}
@keyframes blog-ai-roam {
  0%, 100% { transform: translate(-2px, 1px); }
  50% { transform: translate(2px, -1px); }
}

@media (hover: none) { .blog-ai .blog-ai-launcher-label { display: none; } }
.blog-ai-panel {
  display: flex;
  flex-direction: column;
  position: relative;
  width: min(370px, calc(100vw - 96px));
  /* resize needs a scroll container, and the corner grip is the only affordance it gets. */
  min-width: 240px;
  min-height: 220px;
  max-width: min(720px, calc(100vw - 96px));
  max-height: calc(100vh - 150px);
  max-height: calc(100dvh - 150px);
  resize: both;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 20px;
  border: 1px solid var(--ai-border);
  border-radius: 20px;
  background: var(--ai-bg);
  box-shadow: 0 12px 42px rgb(16 58 86 / 18%);
  scrollbar-width: thin;
}
/* A corner grip that pulls against the anchored bottom-right, so it has the whole screen to grow
   into. The two grooves read as a handle without stealing anything from the heading next to it. */
.blog-ai .blog-ai-grip {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  background: none;
  box-shadow: none;
  cursor: nw-resize;
  touch-action: none;
  opacity: .4;
}
.blog-ai .blog-ai-grip::before,
.blog-ai .blog-ai-grip::after {
  content: '';
  position: absolute;
  left: 4px;
  width: 14px;
  height: 2px;
  border-radius: 2px;
  background: var(--ai-muted);
  transform-origin: left center;
  transform: rotate(45deg);
}
.blog-ai .blog-ai-grip::before { top: 4px; }
.blog-ai .blog-ai-grip::after { top: 9px; width: 9px; }
.blog-ai .blog-ai-grip:hover,
.blog-ai .blog-ai-grip:focus-visible,
.blog-ai-panel[data-resizing="true"] .blog-ai-grip { opacity: 1; }
/* While a drag is running the transcript must not highlight every word the pointer crosses. */
.blog-ai-panel[data-resizing="true"] { user-select: none; }
.blog-ai-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.blog-ai .blog-ai-heading {
  margin: 0;
  padding: 0;
  color: var(--ai-text);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.6;
}
/* Avoid theme-generated heading anchors inside the client-side summary card. */
.blog-ai .blog-ai-heading::before, .blog-ai .blog-ai-heading::after { display: none; }
.blog-ai .blog-ai-close { min-width: 44px; padding: 4px 10px; border: 0; background: none; font-size: 26px; }
.blog-ai .blog-ai-hint { margin: 8px 0 12px; color: var(--ai-muted); font-size: 12px; line-height: 1.7; }
/* The conversation absorbs every constraint, so dragging the corner grows the transcript and not the chrome. */
.blog-ai-messages { min-height: 140px; flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; }
.blog-ai-turn { padding: 11px 13px; margin: 8px 0; border-radius: 12px; background: var(--ai-inset); }
.blog-ai-turn--user { margin-left: 20px; background: transparent; border: 1px solid var(--ai-border); }
.blog-ai-turn-label { color: var(--ai-muted); font-size: 11px; font-weight: 600; }
/* The waiting face. Dots keep their base opacity so a visitor who asked for reduced motion still
   sees a complete line, just a still one, instead of three invisible specks. */
.blog-ai .blog-ai-thinking { display: flex; align-items: center; gap: 10px; color: var(--ai-muted); }
.blog-ai .blog-ai-blob--mini { position: relative; flex: none; width: 28px; height: 28px; animation: none; }
.blog-ai .blog-ai-blob--mini .blog-ai-eye { top: 8px; width: 6px; height: 10px; }
.blog-ai .blog-ai-blob--mini .blog-ai-eye--left { left: 6px; }
.blog-ai .blog-ai-blob--mini .blog-ai-eye--right { right: 6px; }
.blog-ai .blog-ai-blob--mini .blog-ai-pupil { width: 3px; height: 5px; transform: none; animation: blog-ai-roam 1.7s ease-in-out infinite; }
.blog-ai .blog-ai-blob--mini .blog-ai-eye--right .blog-ai-pupil { animation-delay: .12s; }
.blog-ai .blog-ai-thinking-line { display: flex; align-items: baseline; gap: 4px; font-size: 12px; }
.blog-ai .blog-ai-thinking-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ai-accent);
  opacity: .9;
  animation: blog-ai-breathe 1.3s ease-in-out infinite;
}
.blog-ai .blog-ai-thinking-dot--two { animation-delay: .16s; }
.blog-ai .blog-ai-thinking-dot--three { animation-delay: .32s; }
.blog-ai .blog-ai-output { margin: 6px 0; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ai-text); line-height: 1.8; }
/* Answers arrive as markdown. The theme resets margins and list markers globally, so every
   structure the renderer builds states its own, and the bubble keeps its rhythm either way. */
.blog-ai .blog-ai-md-title { margin: 12px 0 4px; color: var(--ai-text); font-size: 15px; font-weight: 700; line-height: 1.7; }
.blog-ai .blog-ai-md-para { margin: 6px 0; }
.blog-ai .blog-ai-md-list { margin: 6px 0; padding-left: 22px; list-style: disc; }
.blog-ai .blog-ai-md-list--ordered { list-style: decimal; }
.blog-ai .blog-ai-md-item { margin: 2px 0; }
.blog-ai .blog-ai-md-quote { margin: 8px 0; padding: 2px 0 2px 12px; border-left: 3px solid var(--ai-border); color: var(--ai-muted); }
.blog-ai .blog-ai-md-pre {
  margin: 8px 0;
  padding: 10px 12px;
  overflow-x: auto;
  border: 1px solid var(--ai-border);
  border-radius: 10px;
  background: var(--ai-bg);
  color: var(--ai-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.7;
  text-align: left;
  white-space: pre;
}
.blog-ai .blog-ai-md-code {
  padding: 1px 5px;
  border: 1px solid var(--ai-border);
  border-radius: 6px;
  background: var(--ai-bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}
.blog-ai .blog-ai-md-pre .blog-ai-md-code { padding: 0; border: 0; background: none; font-size: inherit; }
.blog-ai .blog-ai-md-strong { font-weight: 700; }
.blog-ai .blog-ai-md-em { font-style: italic; }
.blog-ai .blog-ai-md-link { color: var(--ai-accent); text-decoration: underline; }
.blog-ai .blog-ai-output > :first-child { margin-top: 0; }
.blog-ai-form { margin-top: 4px; }
.blog-ai-label { display: block; margin-bottom: 6px; font-size: 13px; }
.blog-ai .blog-ai-input {
  display: block;
  width: 100%;
  line-height: 1.6;
  /* Two lines reserved, written in the box's own font so the reservation stays exactly two lines
     whether the textarea renders at the desktop 14px or the mobile 16px (3.2em + padding + border). */
  min-height: calc(3.2em + 22px);
  max-height: 180px;
  padding: 10px 12px;
  resize: vertical;
  border: 1px solid var(--ai-border);
  border-radius: 12px;
  background: var(--ai-bg);
  color: var(--ai-text);
}
.blog-ai .blog-ai-input::placeholder { color: var(--ai-muted); opacity: 1; }
.blog-ai-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.blog-ai-counter { color: var(--ai-muted); font-size: 11px; }
.blog-ai .blog-ai-primary { background: var(--ai-accent); color: var(--ai-bg); border-color: var(--ai-accent); min-width: 76px; }
.blog-ai .blog-ai-status { margin: 8px 0 0; font-size: 12px; color: var(--ai-muted); overflow-wrap: anywhere; }
.blog-ai-status:empty { display: none; }
.blog-ai-summary { margin: 0 0 28px; padding: 20px 24px; border: 1px solid var(--ai-border); border-radius: 16px; background: var(--ai-bg); }
.blog-ai-summary .blog-ai-output { margin: 12px 0; }
.blog-ai-summary .blog-ai-hint { margin-bottom: 0; }
/* The card types its summary out, and a bar after the revealed text is what says more is coming.
   Where "after the revealed text" is depends on what the renderer produced: plain text stays a node
   of the output itself, but the first inline marker wraps every block in an element, and a bar left
   on the output would then sit alone on the next line — the exact moment a visitor reads as stalled.
   So the bar hangs on the last block instead, one level deeper when that block is a list. */
.blog-ai-summary .blog-ai-output[aria-busy="true"]:not([data-md])::after,
.blog-ai-summary .blog-ai-output[data-md][aria-busy="true"] > :last-child:not(.blog-ai-md-list)::after,
.blog-ai-summary .blog-ai-output[data-md][aria-busy="true"] > .blog-ai-md-list:last-child > :last-child::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 3px;
  vertical-align: -0.15em;
  background: var(--ai-accent);
  animation: blog-ai-caret .8s steps(1, end) infinite;
}

@media (max-width: 600px) {
  .blog-ai-assistant { right: max(64px, env(safe-area-inset-right)); bottom: max(24px, env(safe-area-inset-bottom)); }
  .blog-ai-panel { width: min(370px, calc(100vw - 80px)); max-height: calc(100vh - 112px); max-height: calc(100dvh - 112px); padding: 15px; border-radius: 16px; resize: none; }
  /* A phone screen already is the panel's whole range, and its padding would put the grip under the heading. */
  .blog-ai .blog-ai-grip { display: none; }
  .blog-ai .blog-ai-input { font-size: 16px; }
  .blog-ai-summary { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .blog-ai *, .blog-ai *::before, .blog-ai *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

@media print { .blog-ai { display: none !important; } }
