body:has(#agent-launcher) {
  --agent-size: 92px;
  --agent-right: max(17px, calc(env(safe-area-inset-right) + 9px));
  --agent-bottom: max(13px, calc(env(safe-area-inset-bottom) + 8px));
  padding-bottom: calc(var(--agent-size) + var(--agent-bottom));
}
#agent-launcher {
  position: fixed;
  right: var(--agent-right);
  bottom: var(--agent-bottom);
  z-index: 12;
  display: grid;
  width: var(--agent-size);
  height: var(--agent-size);
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
}
#agent-launcher:focus-visible { outline: 3px solid #986035; outline-offset: 3px; }
.agent-spirit {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  pointer-events: none;
  transform-origin: 50% 78%;
  transition: transform .22s ease-out;
}
.agent-spirit::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: auto 24% 3%;
  height: 8%;
  border-radius: 50%;
  background: #3b2b20;
  filter: blur(4px);
  opacity: .22;
}
.agent-spirit img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 3px 3px #332c2347);
}
.agent-avatar {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  background: #efe7cc;
  border: 1px solid #d7c097;
  border-radius: 50%;
}
.agent-avatar img {
  display: block;
  width: 41px;
  height: 41px;
  object-fit: contain;
}
.agent-hint {
  position: absolute;
  right: 1px;
  bottom: calc(100% + 4px);
  width: max-content;
  max-width: min(210px, calc(100vw - 36px));
  padding: 6px 10px;
  background: #fff8e9;
  color: #304637;
  border: 1px solid #c5ac84;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transform: translateY(3px);
  transition: opacity .16s ease-out, transform .16s ease-out, visibility .16s;
}
#agent-launcher:focus-visible .agent-hint { opacity: 1; visibility: visible; transform: none; }
@media (hover: hover) {
  #agent-launcher:hover .agent-spirit { transform: translateY(-5px) rotate(-4deg) scale(1.04); }
  #agent-launcher:hover .agent-hint { opacity: 1; visibility: visible; transform: none; }
}
#agent-launcher:active .agent-spirit { transform: translateY(1px) scale(.96); }
#agent-launcher[aria-expanded="true"] .agent-hint { opacity: 0; visibility: hidden; }
#agent-panel {
  inset: auto var(--agent-right) calc(var(--agent-bottom) + var(--agent-size) + 7px) auto;
  width: min(440px, calc(100% - var(--agent-right) - 12px));
  max-height: min(72vh, 620px);
  max-height: min(72dvh, 620px);
  padding: 0;
  background: #fbf3e2;
  color: #292d24;
  margin: 0;
  border: 1px solid #b4a07f;
  border-radius: 10px;
  box-shadow: 0 9px 30px #39291949;
  overscroll-behavior: contain;
}
#agent-panel[open] {
  animation: agent-arrive .22s cubic-bezier(.19, .8, .33, 1) both;
  transform-origin: 92% 100%;
}
#agent-panel::backdrop { background: #30281f25; }
@keyframes agent-arrive {
  from { opacity: 0; transform: translateY(12px) scale(.965); }
  to { opacity: 1; transform: none; }
}
#agent-panel header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 15px;
  background: #204438;
  color: #fff3d5;
  border-bottom: 1px solid #9d8b60;
}
.agent-heading { display: flex; align-items: center; gap: 10px; min-width: 0; }
#agent-panel h2 { font: 700 24px KaiTi, serif; color: inherit; margin: 0; }
#agent-panel header p { font-size: 13px; margin: 2px 0 0; color: #eee0be; }
#agent-close {
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid #aa9872;
  border-radius: 5px;
  background: transparent;
  color: #fff3d5;
  font-size: 23px;
}
#agent-close:hover { background: #31594b; }
.agent-body { padding: 14px 15px; }
.agent-body form > div { display: flex; align-items: start; gap: 8px; }
.agent-body textarea {
  width: 100%;
  min-width: 0;
  flex: 1;
  padding: 7px 9px;
  border: 1px solid #af9d80;
  border-radius: 5px;
  resize: vertical;
  background: #fffaf0;
  color: #302b23;
  font: inherit;
}
.agent-body label { display: block; margin-bottom: 5px; }
.agent-body .primary { min-height: 42px; padding: 7px 12px; border: 1px solid #804532; border-radius: 4px; background: #804532; color: #fff2d5; }
#agent-quick { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
#agent-quick button { min-height: 36px; padding: 4px 10px; font-size: 13px; }
#agent-status:empty { display: none; }
#agent-status { white-space: pre-wrap; overflow-wrap: anywhere; }
#agent-sources summary { cursor: pointer; margin: 8px 0; }
#agent-sources article { border-top: 1px solid #cfbea4; padding: 8px 0; overflow-wrap: anywhere; }
#agent-sources :is(p, a) { margin: 3px 0; }
#agent-sources a { color: #35594c; text-decoration: underline; }
.agent-account { display: flex; gap: 9px; flex-wrap: wrap; justify-content: flex-start; }
.agent-account a { display: inline-flex; align-items: center; min-height: 40px; padding: 4px 12px; border: 1px solid #d4c3a7; border-radius: 4px; color: #5d4333; text-decoration: none; }
@media (max-width: 560px) {
  body:has(#agent-launcher) {
    --agent-size: 72px;
    --agent-right: max(9px, calc(env(safe-area-inset-right) + 6px));
    --agent-bottom: max(8px, calc(env(safe-area-inset-bottom) + 5px));
  }
}
@media (prefers-reduced-motion: reduce) {
  .agent-spirit, .agent-hint { transition: none; }
  #agent-launcher:hover .agent-spirit, #agent-launcher:active .agent-spirit { transform: none; }
  #agent-panel[open] { animation: none; }
}
