/* hl-ai.css — Happy Wipe, the Happy Light AI helper (see hl-ai.js).
   Shared verbatim across the apps that use the AI relay; keep the copies
   byte-identical. Follows the page's [data-theme], else the system. */

.hl-ai {
  --hlai-bg: #fffdf8; --hlai-ink: #2a2420; --hlai-sub: #6b625a; --hlai-line: #e6dfd4;
  --hlai-soft: #f4efe6; --hlai-accent: #f59e0b; --hlai-accent-ink: #1f1300;
  --hlai-live: #22a35a; --hlai-wait: #e0a800; --hlai-off: #9a938b; --hlai-bad: #c2410c;
  --hlai-shadow: 0 10px 30px rgba(40, 30, 20, .18);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--hlai-ink);
  z-index: 2147483000;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .hl-ai {
    --hlai-bg: #1f1b18; --hlai-ink: #f2ece4; --hlai-sub: #b3aaa0; --hlai-line: #3a332d;
    --hlai-soft: #2a2420; --hlai-shadow: 0 10px 30px rgba(0, 0, 0, .5); --hlai-bad: #fb923c;
  }
}
:root[data-theme="dark"] .hl-ai {
  --hlai-bg: #1f1b18; --hlai-ink: #f2ece4; --hlai-sub: #b3aaa0; --hlai-line: #3a332d;
  --hlai-soft: #2a2420; --hlai-shadow: 0 10px 30px rgba(0, 0, 0, .5); --hlai-bad: #fb923c;
}

.hl-ai-corner { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.hl-ai-inline { position: relative; display: inline-flex; }
.hl-ai-inline .hl-ai-panel { position: absolute; right: 0; top: calc(100% + 8px); }

/* the launcher: mascot + light + words, always on screen */
.hl-ai-launch {
  display: inline-flex; align-items: center; gap: 8px; max-width: min(320px, calc(100vw - 32px));
  padding: 4px 12px 4px 4px; border: 1px solid var(--hlai-line); border-radius: 999px;
  background: var(--hlai-bg); color: var(--hlai-ink); box-shadow: var(--hlai-shadow);
  font: inherit; font-weight: 600; cursor: pointer; position: relative;
}
.hl-ai-launch:hover { border-color: var(--hlai-accent); }
.hl-ai-launch:focus-visible, .hl-ai button:focus-visible, .hl-ai input:focus-visible,
.hl-ai select:focus-visible, .hl-ai textarea:focus-visible, .hl-ai pre:focus-visible {
  outline: 2px solid var(--hlai-accent); outline-offset: 2px;
}
.hl-ai-pill { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.hl-ai-face { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--hlai-soft); flex: none; position: relative; }
.hl-ai-face-big { width: 64px; height: 64px; }
.hl-ai-dot { position: absolute; left: 30px; top: 4px; width: 11px; height: 11px; border-radius: 50%; background: var(--hlai-off); border: 2px solid var(--hlai-bg); }
.hl-ai[data-presence="live"] .hl-ai-dot { background: var(--hlai-live); }
.hl-ai[data-presence="live"] .hl-ai-launch { border-color: var(--hlai-live); }
.hl-ai[data-presence="waiting"] .hl-ai-dot, .hl-ai[data-presence="idle"] .hl-ai-dot { background: var(--hlai-wait); }
.hl-ai[data-presence="ready"] .hl-ai-dot { background: var(--hlai-accent); }
.hl-ai[data-presence="off"] .hl-ai-mascot { filter: grayscale(.7); opacity: .85; }

/* the panel */
.hl-ai-panel {
  width: min(380px, calc(100vw - 32px)); max-height: min(620px, calc(100vh - 96px)); overflow: auto;
  background: var(--hlai-bg); border: 1px solid var(--hlai-line); border-radius: 16px; box-shadow: var(--hlai-shadow);
  display: flex; flex-direction: column;
}
.hl-ai-panel[hidden] { display: none; }
.hl-ai-head { display: flex; align-items: center; gap: 12px; padding: 14px 14px 10px; }
.hl-ai-head > div { flex: 1; min-width: 0; }
.hl-ai-head strong { display: block; font-size: 15px; }
.hl-ai-sub { margin: 2px 0 0; color: var(--hlai-sub); font-size: 12.5px; }
.hl-ai-x { border: 0; background: none; color: var(--hlai-sub); font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 8px; align-self: flex-start; }
.hl-ai-x:hover { background: var(--hlai-soft); }
.hl-ai-tabs { display: flex; gap: 4px; padding: 0 14px; border-bottom: 1px solid var(--hlai-line); }
.hl-ai-tab { flex: 1; border: 0; background: none; color: var(--hlai-sub); font: inherit; font-weight: 600; padding: 8px 6px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.hl-ai-tab[aria-selected="true"] { color: var(--hlai-ink); border-bottom-color: var(--hlai-accent); }
.hl-ai-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.hl-ai-body p { margin: 0; }
.hl-ai-primary {
  align-self: flex-start; border: 0; border-radius: 10px; padding: 9px 16px; cursor: pointer;
  background: var(--hlai-accent); color: var(--hlai-accent-ink); font: inherit; font-weight: 700;
}
.hl-ai-primary:disabled { opacity: .6; cursor: default; }
.hl-ai-small { padding: 6px 12px; font-size: 13px; margin-top: 6px; }
.hl-ai-link { border: 0; background: none; padding: 0; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; align-self: flex-start; }
.hl-ai-copytext {
  margin: 0; padding: 10px; max-height: 180px; overflow: auto; white-space: pre-wrap; word-break: break-word;
  background: var(--hlai-soft); border: 1px solid var(--hlai-line); border-radius: 10px; font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace;
  user-select: all;
}
.hl-ai-error { margin: 0 14px 14px; color: var(--hlai-bad); font-size: 13px; }
.hl-ai-input {
  font: inherit; color: var(--hlai-ink); background: var(--hlai-bg); border: 1px solid var(--hlai-line); border-radius: 8px; padding: 7px 9px; min-width: 0;
}
.hl-ai-notlistening {
  display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: 12px;
  background: var(--hlai-soft); border: 1px dashed var(--hlai-wait);
}
.hl-ai-notlistening[hidden] { display: none; }
.hl-ai-who { color: var(--hlai-sub); font-size: 11.5px; font-weight: 600; }

/* chat */
.hl-ai-log { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow: auto; }
.hl-ai-msg { padding: 8px 11px; border-radius: 12px; max-width: 92%; display: flex; flex-direction: column; gap: 6px; }
.hl-ai-msg p { white-space: pre-wrap; word-break: break-word; }
.hl-ai-msg pre { margin: 0; padding: 8px; max-height: 160px; overflow: auto; background: var(--hlai-bg); border-radius: 8px; font: 11.5px/1.4 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.hl-ai-user { align-self: flex-end; background: var(--hlai-accent); color: var(--hlai-accent-ink); }
.hl-ai-assistant { align-self: flex-start; background: var(--hlai-soft); }
.hl-ai-compose { display: flex; gap: 8px; align-items: flex-end; }
.hl-ai-input { flex: 1; resize: vertical; min-height: 40px; max-height: 160px; }
.hl-ai-compose .hl-ai-primary { align-self: stretch; }
.hl-ai-dots { flex-direction: row; gap: 5px; padding: 12px 14px; }
.hl-ai-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--hlai-sub); animation: hlai-dot 1s infinite ease-in-out; }
.hl-ai-dots span:nth-child(2) { animation-delay: .15s; }
.hl-ai-dots span:nth-child(3) { animation-delay: .3s; }

/* ── Happy Wipe moves ──
   idle: floats and blinks · listening (the person is typing): leans in,
   eyes wide · thinking: bobs and looks up, cheeks glow · live (an AI is
   connected): a happy bounce · error: one small shake. */
.hl-ai-mascot { overflow: visible; display: block; }
.hl-ai-ghost, .hl-ai-eyes, .hl-ai-cheeks, .hl-ai-tail, .hl-ai-mouth { transform-box: fill-box; transform-origin: center; }
.hl-ai-ghost { animation: hlai-float 3.2s ease-in-out infinite; }
.hl-ai-eyes { animation: hlai-blink 4.6s infinite; }
.hl-ai-tail { animation: hlai-wag 1.6s ease-in-out infinite; }
.hl-ai[data-state="listening"] .hl-ai-ghost { animation: hlai-lean 1.2s ease-in-out infinite; }
.hl-ai[data-state="listening"] .hl-ai-eyes { animation: hlai-wide 1.2s ease-in-out infinite; }
.hl-ai[data-state="thinking"] .hl-ai-ghost { animation: hlai-bob .7s ease-in-out infinite; }
.hl-ai[data-state="thinking"] .hl-ai-eyes { animation: hlai-look 1.4s ease-in-out infinite; }
.hl-ai[data-state="thinking"] .hl-ai-cheeks { animation: hlai-glow 1.4s ease-in-out infinite; }
.hl-ai[data-state="thinking"] .hl-ai-face::after {
  content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 2px dashed var(--hlai-accent);
  animation: hlai-spin 2.4s linear infinite;
}
.hl-ai[data-state="live"] .hl-ai-ghost { animation: hlai-happy 1.8s ease-in-out infinite; }
.hl-ai[data-state="live"] .hl-ai-cheeks { animation: hlai-glow 1.8s ease-in-out infinite; }
.hl-ai[data-state="live"] .hl-ai-face { box-shadow: 0 0 0 3px color-mix(in srgb, var(--hlai-live) 35%, transparent); }
.hl-ai[data-state="error"] .hl-ai-ghost { animation: hlai-shake .5s ease-in-out 1; }
.hl-ai[data-state="off"] .hl-ai-ghost { animation-duration: 5s; }

@keyframes hlai-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-1px); } }
@keyframes hlai-blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
@keyframes hlai-wag { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(.5px); } }
@keyframes hlai-lean { 0%, 100% { transform: rotate(-6deg) translateY(0); } 50% { transform: rotate(-9deg) translateY(-.6px); } }
@keyframes hlai-wide { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.25, 1.3); } }
@keyframes hlai-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-1.4px); } }
@keyframes hlai-look { 0%, 100% { transform: translate(0, -.6px); } 50% { transform: translate(.8px, -.8px); } }
@keyframes hlai-glow { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
@keyframes hlai-happy { 0%, 60%, 100% { transform: translateY(0) scale(1); } 20% { transform: translateY(-2px) scale(1.04, .97); } 35% { transform: translateY(0) scale(.97, 1.04); } }
@keyframes hlai-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-1px); } 75% { transform: translateX(1px); } }
@keyframes hlai-spin { to { transform: rotate(360deg); } }
@keyframes hlai-dot { 0%, 100% { transform: translateY(0); opacity: .4; } 50% { transform: translateY(-4px); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .hl-ai *, .hl-ai *::after { animation: none !important; }
  /* Still say "thinking" without motion: a steady ring. */
  .hl-ai[data-state="thinking"] .hl-ai-face::after { border-style: solid; }
}

@media (max-width: 480px) {
  .hl-ai-corner { right: 12px; bottom: 12px; }
  .hl-ai-panel { width: calc(100vw - 24px); max-height: calc(100vh - 88px); }
  .hl-ai-pill { max-width: 160px; }
}
