/* ═══════════════════════════════════════════════════════
   pet.css — Neko, the interactive site mascot + chat widget.
   Sprite: public-domain "Neko" (oneko) sheet, 256×128, 32px cells.
   ═══════════════════════════════════════════════════════ */

/* ── Pet container (walks along the bottom of the viewport) ── */
#ci-pet {
  position: fixed;
  left: 0;
  bottom: 6px;
  width: 64px;
  height: 64px;
  z-index: 900;
  pointer-events: none;            /* only the sprite itself is clickable */
  will-change: transform;
}
#ci-pet.is-hidden { display: none; }

.pet-sprite {
  position: absolute;
  inset: 0;
  width: 64px;
  height: 64px;
  background-image: url('../assets/pet/oneko.gif');
  background-repeat: no-repeat;
  background-size: 512px 256px;     /* 2× the 256×128 sheet */
  image-rendering: pixelated;
  cursor: pointer;
  pointer-events: auto;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.55));
  transition: transform 0.12s ease;
}
.pet-sprite:hover { transform: scale(1.08); }

/* little shadow blob under the cat */
#ci-pet::after {
  content: '';
  position: absolute;
  left: 12px;
  bottom: 2px;
  width: 40px;
  height: 8px;
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.45), transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

/* ── "Click me" call-to-action tag ── */
.pet-cta {
  position: absolute;
  left: 58px;
  top: -6px;
  white-space: nowrap;
  font-family: var(--font-mono, monospace);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  color: var(--bg-primary, #0a0e17);
  background: var(--accent-cyan, #00d4ff);
  padding: 0.28rem 0.55rem;
  border-radius: 10px 10px 10px 2px;
  box-shadow: 0 4px 14px rgba(0, 212, 255, 0.4);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px) scale(0.9);
  transition: opacity 0.3s ease, transform 0.3s ease;
  animation: pet-cta-bob 2.4s ease-in-out infinite;
}
#ci-pet.cta-on .pet-cta { opacity: 1; transform: translateY(0) scale(1); }
@keyframes pet-cta-bob {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -4px; }
}

/* ── Speech / thought bubble ── */
.pet-bubble {
  position: fixed;
  z-index: 901;
  max-width: 240px;
  padding: 0.7rem 0.9rem;
  font-family: var(--font-body, system-ui, sans-serif);
  font-size: 0.82rem;
  line-height: 1.45;
  color: #0c1622;
  background: #eef5ff;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px) scale(0.92);
  transform-origin: bottom left;
  transition: opacity 0.28s ease, transform 0.28s ease;
}
.pet-bubble.show { opacity: 1; transform: translateY(0) scale(1); }
.pet-bubble::after {                 /* speech tail */
  content: '';
  position: absolute;
  left: 22px;
  bottom: -8px;
  border-width: 9px 9px 0;
  border-style: solid;
  border-color: #eef5ff transparent transparent;
}
.pet-bubble.is-cta {
  color: #04222e;
  background: #c8f3ff;
  font-weight: 600;
}
.pet-bubble.is-cta::after { border-top-color: #c8f3ff; }
/* thought-bubble variant: soft + dotted tail */
.pet-bubble.is-thought {
  background: #e9ecf5;
  font-style: italic;
  color: #2a3142;
}
.pet-bubble.is-thought::after {
  border: none;
  left: 18px;
  bottom: -14px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e9ecf5;
  box-shadow: -7px -7px 0 -1px #e9ecf5, 6px 8px 0 -2px #e9ecf5;
}

/* ═══ CHAT WIDGET ═══ */
#ci-chat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 370px;
  max-width: calc(100vw - 24px);
  height: 540px;
  max-height: calc(100vh - 90px);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  background: rgba(10, 15, 24, 0.92);
  border: 1px solid rgba(0, 212, 255, 0.32);
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(0, 212, 255, 0.06);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  transform-origin: bottom right;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}
#ci-chat.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

.chat-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(0, 212, 255, 0.18);
  background: linear-gradient(180deg, rgba(0, 212, 255, 0.08), transparent);
}
.chat-head-avatar {
  width: 38px;
  height: 38px;
  flex: none;
  background-image: url('../assets/pet/oneko.gif');
  background-repeat: no-repeat;
  background-size: 304px 152px;       /* ~4.75× so one 32px cell ≈ 38px */
  background-position: -114px -114px;  /* idle cell (-3,-3) scaled */
  image-rendering: pixelated;
  border-radius: 10px;
  background-color: rgba(0, 212, 255, 0.1);
}
.chat-head-meta { flex: 1; min-width: 0; }
.chat-head-title { font-size: 0.98rem; font-weight: 700; color: var(--text-primary, #e8edf5); }
.chat-head-sub {
  font-size: 0.7rem;
  color: var(--accent-cyan, #00d4ff);
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.chat-head-sub .founder-dot { width: 6px; height: 6px; }
.chat-close {
  flex: none;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary, #e8edf5);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s;
}
.chat-close:hover { background: rgba(255, 51, 102, 0.25); }

.chat-banner {
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--text-primary, #e8edf5);
  padding: 0.6rem 1rem;
  background: rgba(0, 212, 255, 0.07);
  border-bottom: 1px solid rgba(0, 212, 255, 0.12);
}
.chat-banner b { color: var(--accent-cyan, #00d4ff); }

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  scrollbar-width: thin;
}
.chat-msg {
  max-width: 84%;
  padding: 0.55rem 0.8rem;
  border-radius: 13px;
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-msg.bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-primary, #e8edf5);
  border-bottom-left-radius: 4px;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--accent-cyan, #00d4ff);
  color: #06121b;
  font-weight: 500;
  border-bottom-right-radius: 4px;
}
.chat-msg.sys {
  align-self: center;
  background: transparent;
  color: var(--text-muted, #c4d0e2);
  font-size: 0.74rem;
  text-align: center;
  font-style: italic;
}
.chat-typing { align-self: flex-start; display: inline-flex; gap: 4px; padding: 0.7rem 0.8rem; }
.chat-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent-cyan, #00d4ff);
  animation: chat-typing 1s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-typing { 0%, 60%, 100% { opacity: 0.25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }

.chat-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0 1rem 0.6rem; }
.chat-chip {
  font-size: 0.72rem;
  padding: 0.32rem 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(0, 212, 255, 0.3);
  background: rgba(0, 212, 255, 0.06);
  color: var(--text-primary, #e8edf5);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.chat-chip:hover { background: rgba(0, 212, 255, 0.16); border-color: var(--accent-cyan, #00d4ff); }

.chat-human-btn {
  margin: 0 1rem 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem;
  border: 1px solid rgba(255, 170, 0, 0.45);
  border-radius: 10px;
  background: rgba(255, 170, 0, 0.1);
  color: var(--accent-amber, #ffaa00);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.chat-human-btn:hover { background: rgba(255, 170, 0, 0.2); }

.chat-input-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.7rem 0.8rem;
  border-top: 1px solid rgba(0, 212, 255, 0.16);
}
.chat-input-row input {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.7rem;
  border: 1px solid rgba(0, 212, 255, 0.25);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--text-primary, #e8edf5);
  font-family: var(--font-body, system-ui, sans-serif);
  font-size: 0.85rem;
}
.chat-input-row input:focus { outline: none; border-color: var(--accent-cyan, #00d4ff); }
.chat-send {
  flex: none;
  width: 42px;
  border: none;
  border-radius: 10px;
  background: var(--accent-cyan, #00d4ff);
  color: #06121b;
  font-size: 1.1rem;
  cursor: pointer;
  transition: filter 0.2s;
}
.chat-send:hover { filter: brightness(1.1); }
.chat-send:disabled { opacity: 0.4; cursor: default; }

/* human-handoff mini form */
.chat-human-form { padding: 0.4rem 1rem 0.9rem; display: none; flex-direction: column; gap: 0.5rem; }
.chat-human-form.show { display: flex; }
.chat-human-form label { font-size: 0.72rem; color: var(--text-muted, #c4d0e2); }
.chat-human-form input, .chat-human-form textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid rgba(0, 212, 255, 0.25);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--text-primary, #e8edf5);
  font-family: var(--font-body, system-ui, sans-serif);
  font-size: 0.82rem;
  resize: vertical;
}
.chat-human-form button {
  padding: 0.55rem;
  border: none;
  border-radius: 9px;
  background: var(--accent-amber, #ffaa00);
  color: #1a1200;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}

@media (max-width: 480px) {
  #ci-chat { right: 8px; bottom: 8px; height: calc(100vh - 80px); }
  .pet-bubble { max-width: 200px; }
}

@media (prefers-reduced-motion: reduce) {
  .pet-cta { animation: none; }
}
