/* Compact DOM companion layer, using the existing campfire UI palette. */
.companion-speech-bubble {
  --bubble-paper: #172025f2; --bubble-ink: #f4e8d3; --bubble-edge: #d3b17c80;
  position: fixed; z-index: 22; top: 0; left: 0; box-sizing: border-box;
  color: var(--bubble-ink); background: var(--bubble-paper); border: 1px solid var(--bubble-edge);
  border-radius: 15px; box-shadow: 0 5px 20px #0007; pointer-events: auto;
  font: 14px/1.6 "Noto Sans TC", system-ui, sans-serif; text-align: left;
  will-change: transform; isolation: isolate;
}
.companion-speech-bubble[hidden] { display: none; }
.companion-speech-text {
  box-sizing: border-box; padding: 10px 13px; overflow-y: auto; overflow-wrap: anywhere;
  white-space: pre-wrap; overscroll-behavior: contain; scrollbar-width: thin; user-select: text;
}
.companion-speech-bubble[data-placement="above"]::after {
  content: ""; position: absolute; width: 10px; height: 10px; left: var(--bubble-tail-x, 50%);
  bottom: -6px; background: var(--bubble-paper); border-right: 1px solid var(--bubble-edge);
  border-bottom: 1px solid var(--bubble-edge); transform: translateX(-50%) rotate(45deg);
}
@media (max-width: 650px) {
  .companion-speech-bubble { font-size: 13px; line-height: 1.55; border-radius: 12px; }
  .companion-speech-text { padding: 8px 10px; }
}
#toolButtons.has-companion-chat { grid-template-columns: repeat(16, 50px); }
#companionChatPanel {
  --companion-panel: #10191bf5;
  position: fixed; z-index: 30; left: 50%; bottom: max(112px, env(safe-area-inset-bottom));
  transform: translateX(-50%); width: min(540px, calc(100vw - 24px)); box-sizing: border-box;
  padding: 12px; border: 1px solid var(--ui-line, #bfa77b55); border-radius: 18px; overflow-y: auto;
  background: var(--companion-panel); color: var(--ui-ink, #f0e5d0); box-shadow: 0 8px 32px #0008;
  font: 14px/1.45 system-ui, sans-serif; pointer-events: auto;
}
#companionChatPanel[hidden] { display: none; }
#companionChatPanel .companion-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
#companionChatPanel .companion-heading > span { font-size: 13px; color: var(--ui-muted, #c2b5a0); white-space: nowrap; }
#companionChatPanel .companion-options { display: flex; gap: 3px; }
#companionChatPanel button { display: grid; place-items: center; flex: 0 0 44px; width: 44px; height: 44px; min-height: 44px; padding: 8px; border-radius: 13px; }
#companionChatPanel svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linejoin: round; stroke-linecap: round; }
#companionChatPanel button:disabled { opacity: .42; cursor: default; }
#companionChatPanel button[aria-pressed="true"] { background: var(--ui-selected, #88592eda); border-color: var(--ui-warm, #d5a16a); }
#companionChatPanel .companion-entry { display: flex; gap: 6px; width: 100%; margin: 0; }
#companionChatPanel input { min-width: 0; width: 100%; flex: 1 1 auto; border: 1px solid var(--ui-line, #bfa77b55); background: #070d10; color: var(--ui-ink, #f0e5d0); border-radius: 12px; padding: 10px 12px; font: 16px/1.35 system-ui, sans-serif; box-sizing: border-box; }
#companionChatPanel input::placeholder { color: #b0aaa0; }
#companionChatPanel .companion-answer { margin: 0 0 10px; max-height: min(110px, 20dvh); overflow-y: auto; white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; }
#companionChatPanel .companion-status { font-size: 12px; margin: 7px 2px 0; color: #e6be89; }
#companionChatPanel .companion-privacy { font-size: 11px; margin: 4px 2px 0; color: var(--ui-muted, #c2b5a0); }
.companion-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 960px) {
  #toolButtons.has-companion-chat { grid-template-columns: repeat(8, 48px); }
  #companionChatPanel { bottom: 172px; }
}
@media (max-width: 650px) {
  #toolButtons.has-companion-chat { grid-template-columns: repeat(5, 48px); }
  #companionChatPanel { bottom: max(12px, env(safe-area-inset-bottom)); left: 12px; transform: none; width: calc(100vw - 24px); max-height: calc(100dvh - 24px); overflow-y: auto; }
  body:has(#companionChatPanel:not([hidden])) #tools { visibility: hidden; }
  #companionChatPanel .companion-answer { max-height: 23dvh; }
}
@media (max-width: 350px) { #toolButtons.has-companion-chat { grid-template-columns: repeat(5, 44px); } }
@media (max-height: 600px) and (min-width: 651px) {
  #toolButtons.has-companion-chat { grid-template-columns: repeat(16, 44px); }
  #companionChatPanel { bottom: 86px; padding: 8px 12px; max-height: calc(100dvh - 100px); overflow-y: auto; }
}
@media (max-height: 600px) and (min-width: 651px) and (max-width: 900px) {
  #toolButtons.has-companion-chat { grid-template-columns: repeat(8, 44px); }
  #companionChatPanel { bottom: 130px; }
}
