/* Kit the fox, soft-bot's mascot, in the bottom-right corner
   (templates/layout.html, web/src/kit-boot.ts, web/src/kit/).
   html.kit-on is set in <head> by theme-init.js unless the visitor hid Kit,
   so the corner never swaps from the pill to Kit after paint.
   .kit-live goes on the dock once the 3D model has drawn its first frame. */

.kit-dock {
  position: fixed;
  inset-block-end: 16px;
  inset-inline-end: 16px;
  z-index: 40;
  display: flex;
  align-items: flex-start;
  gap: 4px;
}

/* Kit hidden by the visitor: members keep the plain soft-bot pill, and the
   page link disappears for everyone else. */
html:not(.kit-on) .kit-dock { inset-block-end: 20px; inset-inline-end: 20px; }
html:not(.kit-on) .kit-stage, html:not(.kit-on) .kit-hide { display: none; }
html:not(.kit-on) .kit-dock.kit-link { display: none; }
.kit-dock .softbot-open { position: static; }

html.kit-on .kit-btn {
  position: relative;
  display: grid;
  place-items: center;
  inline-size: 96px;
  block-size: 96px;
  padding: 0;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 50%;
  box-shadow: none;
  cursor: pointer;
  text-decoration: none;
}
html.kit-on .kit-btn:focus-visible { outline: 3px solid var(--accent-deep); outline-offset: 2px; }
html.kit-on .kit-label {
  position: absolute; inline-size: 1px; block-size: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}

.kit-stage {
  position: relative;
  display: block;
  inline-size: 100%;
  block-size: 100%;
}
.kit-stage > * { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; }
.kit-poster { object-fit: contain; filter: drop-shadow(0 4px 6px rgb(0 0 0 / .18)); }
.kit-stage canvas { opacity: 0; }
.kit-live .kit-stage canvas { opacity: 1; }
.kit-live .kit-poster { opacity: 0; }

/* Hide control. It stays visible because Kit moves for more than five seconds
   next to the page content, so WCAG 2.2.2 wants a way to stop him in plain view. */
.kit-hide {
  order: -1;
  inline-size: 24px;
  block-size: 24px;
  padding: 0;
  font: 600 16px/1 var(--sans, system-ui, sans-serif);
  color: var(--ink-2);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  opacity: .6;
}
.kit-dock:hover .kit-hide, .kit-dock:focus-within .kit-hide { opacity: 1; }
.kit-hide:focus-visible { outline: 2px solid var(--accent-deep); outline-offset: 2px; }
@media (hover: none) { .kit-hide { opacity: .85; } }
html:not(.kit-on) .kit-hide { display: none; }

/* While Kit chases the cursor he never takes a click from the page. */
.kit-chasing { pointer-events: none; will-change: transform; }
.kit-chasing .kit-hide { visibility: hidden; }

/* The one greeting, shown once ever. */
.kit-bubble {
  position: absolute;
  inset-block-end: calc(100% + 6px);
  inset-inline-end: 8px;
  inline-size: max-content;
  max-inline-size: 220px;
  margin: 0;
  padding: 8px 12px;
  font-size: .85rem;
  line-height: 1.35;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px 12px 4px 12px;
  box-shadow: var(--shadow-high);
}

/* The panel opens above Kit instead of over him. */
html.kit-on .softbot-panel { inset-block-end: 124px; max-block-size: min(640px, calc(100dvh - 150px)); }
.softbot-kit { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); }

@media (max-width: 560px) {
  .kit-dock { inset-block-end: 10px; inset-inline-end: 10px; }
  html.kit-on .kit-btn { inline-size: 64px; block-size: 64px; }
  html.kit-on .softbot-panel { inset-block-end: 86px; max-block-size: calc(100dvh - 110px); }
}

@media (prefers-reduced-motion: no-preference) {
  html.kit-on .kit-btn { transition: transform .15s ease; }
  html.kit-on .kit-btn:hover { transform: translateY(-2px); }
  .kit-hide { transition: opacity .15s ease; }
  .kit-poster, .kit-stage canvas { transition: opacity .3s ease; }
  .kit-bubble { animation: kit-pop .25s ease-out; }
  @keyframes kit-pop { from { opacity: 0; transform: translateY(6px) scale(.96); } }
}
