/* HaiGames SDK — Shared chat panel styles
 *
 * Namespace: .hg-cp-*
 * Depends on .hg-overlay (z-index 600) as the shell; panel sits at 650.
 * Self-contained (no CSS vars required from host); dark theme + purple accent
 * so it visually matches TTT / RPS / Emoji sheets and companion.html bubbles.
 */

.hg-cp-panel {
  --hg-cp-max-h: 100%;
  box-sizing: border-box;
  color: #fff;
  font-family: inherit;
  z-index: 650;
  display: flex;
  flex-direction: column;
}
.hg-cp-panel *, .hg-cp-panel *::before, .hg-cp-panel *::after { box-sizing: border-box; }

.hg-cp-sr-only {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ── Desktop / "right" docked column ────────────────────────────────── */
.hg-cp-panel.hg-cp-pos-right {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 320px;
  max-width: 90vw;
  background: rgba(10, 8, 22, 0.92);
  backdrop-filter: blur(24px) saturate(1.4);
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.35);
}
.hg-cp-panel.hg-cp-pos-right .hg-cp-handle { display: none; }
.hg-cp-panel.hg-cp-pos-right .hg-cp-body { height: 100%; }
.hg-cp-panel.hg-cp-pos-right.hg-cp-collapsed { width: 44px; }
.hg-cp-panel.hg-cp-pos-right.hg-cp-collapsed .hg-cp-body > :not(.hg-cp-header) { display: none; }
.hg-cp-panel.hg-cp-pos-right.hg-cp-collapsed .hg-cp-header .hg-cp-avatar,
.hg-cp-panel.hg-cp-pos-right.hg-cp-collapsed .hg-cp-header .hg-cp-title { display: none; }

/* ── Mobile / "bottom" drawer ───────────────────────────────────────── */
.hg-cp-panel.hg-cp-pos-bottom {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: rgba(10, 8, 22, 0.96);
  backdrop-filter: blur(24px) saturate(1.5);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.45);
  transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}
.hg-cp-panel.hg-cp-pos-bottom.hg-cp-collapsed .hg-cp-body { display: none; }
.hg-cp-panel.hg-cp-pos-bottom.hg-cp-expanded .hg-cp-handle { display: none; }

.hg-cp-handle {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom)) 18px;
  background: transparent;
  border: 0; color: rgba(255, 255, 255, 0.88);
  font: inherit; font-weight: 600; font-size: 14px; letter-spacing: 0.2px;
  cursor: pointer; text-align: left;
}
.hg-cp-handle::before {
  content: ''; position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  width: 40px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.25);
}
.hg-cp-panel.hg-cp-pos-bottom .hg-cp-handle { position: relative; }
.hg-cp-handle-icon { font-size: 18px; }
.hg-cp-handle-label { flex: 1; }
.hg-cp-handle-chev { opacity: 0.6; font-size: 12px; }

/* ── Body / header / list / input ───────────────────────────────────── */
.hg-cp-body {
  display: flex; flex-direction: column;
  height: min(60vh, var(--hg-cp-max-h));
}
.hg-cp-panel.hg-cp-pos-right .hg-cp-body {
  height: 100%;
}

.hg-cp-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}
.hg-cp-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  overflow: hidden; flex-shrink: 0;
  background: rgba(255, 255, 255, 0.1);
  border: 1.5px solid rgba(167, 139, 250, 0.35);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.hg-cp-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hg-cp-title { flex: 1; min-width: 0; }
.hg-cp-name {
  font-size: 14px; font-weight: 700; color: rgba(255, 255, 255, 0.94);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hg-cp-sub {
  font-size: 11px; color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0.1em; text-transform: uppercase;
}
.hg-cp-collapse {
  width: 30px; height: 30px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, 0.06); color: rgba(255, 255, 255, 0.7);
  cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.hg-cp-collapse:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
.hg-cp-panel.hg-cp-collapsed .hg-cp-collapse { transform: rotate(180deg); }

.hg-cp-list {
  flex: 1; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  padding: 14px 12px;
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}
.hg-cp-list::-webkit-scrollbar { width: 6px; }
.hg-cp-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12); border-radius: 3px;
}

.hg-cp-empty {
  margin: auto; padding: 24px 12px;
  text-align: center; font-size: 13px; line-height: 1.5;
  color: rgba(255, 255, 255, 0.55);
  max-width: 240px;
}

/* ── Message bubbles (mirrors companion.html visual language) ───────── */
.hg-cp-msg {
  display: flex; align-items: flex-end; gap: 8px;
  animation: hgCpFadeUp 0.18s ease;
}
@keyframes hgCpFadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.hg-cp-msg-user { flex-direction: row-reverse; }

.hg-cp-msg-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  overflow: hidden; flex-shrink: 0;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
}
.hg-cp-msg-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.hg-cp-msg-bubble {
  position: relative;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px; line-height: 1.45;
  max-width: 78%;
  overflow-wrap: break-word;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.2);
}
.hg-cp-msg-ai .hg-cp-msg-bubble {
  background: rgba(180, 20, 60, 0.55);
  color: #fff;
  border: 1px solid rgba(236, 72, 153, 0.3);
  border-bottom-left-radius: 4px;
}
.hg-cp-msg-user .hg-cp-msg-bubble {
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.55), rgba(139, 92, 246, 0.75));
  color: #fff;
  border: 1px solid rgba(167, 139, 250, 0.5);
  border-bottom-right-radius: 4px;
}

.hg-cp-msg-text { display: inline; }

.hg-cp-msg-ts {
  display: none;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.55);
  margin-left: 8px;
  vertical-align: baseline;
}
.hg-cp-msg-bubble:hover .hg-cp-msg-ts { display: inline; }

.hg-cp-msg-error .hg-cp-msg-bubble {
  background: rgba(220, 38, 38, 0.35);
  border-color: rgba(248, 113, 113, 0.4);
  color: rgba(255, 228, 228, 0.95);
  font-size: 12.5px;
}

/* Typing indicator — three fading dots */
.hg-cp-typing {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 0;
}
.hg-cp-typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  animation: hgCpDot 1.1s infinite ease-in-out;
}
.hg-cp-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.hg-cp-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes hgCpDot {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40%           { opacity: 1;    transform: translateY(-2px); }
}

/* ── Input row ──────────────────────────────────────────────────────── */
.hg-cp-input-row {
  flex-shrink: 0;
  display: flex; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)) 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.25);
}
.hg-cp-input {
  flex: 1; min-width: 0;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: #fff; font: inherit; font-size: 14px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.hg-cp-input::placeholder { color: rgba(255, 255, 255, 0.4); }
.hg-cp-input:focus {
  border-color: rgba(167, 139, 250, 0.6);
  background: rgba(255, 255, 255, 0.1);
}
.hg-cp-send {
  padding: 8px 16px;
  border: 0; border-radius: 999px;
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.85), rgba(139, 92, 246, 1));
  color: #fff; font: inherit; font-size: 13px; font-weight: 700;
  cursor: pointer; transition: transform 0.08s, opacity 0.15s;
}
.hg-cp-send:hover { transform: translateY(-1px); }
.hg-cp-send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  /* On mobile, right-docked panels still convert to bottom drawer for usability. */
  .hg-cp-panel.hg-cp-pos-right {
    position: fixed;
    top: auto; right: 0; left: 0; bottom: 0;
    width: 100%; max-width: 100%;
    border-left: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.45);
  }
  .hg-cp-panel.hg-cp-pos-right .hg-cp-handle { display: flex; }
  .hg-cp-panel.hg-cp-pos-right.hg-cp-collapsed { width: 100%; }
  .hg-cp-panel.hg-cp-pos-right.hg-cp-collapsed .hg-cp-body { display: none; }
  .hg-cp-panel.hg-cp-pos-right.hg-cp-collapsed .hg-cp-body > :not(.hg-cp-header) { display: block; }
  .hg-cp-panel.hg-cp-pos-right.hg-cp-collapsed .hg-cp-header .hg-cp-avatar,
  .hg-cp-panel.hg-cp-pos-right.hg-cp-collapsed .hg-cp-header .hg-cp-title { display: block; }

  .hg-cp-body { height: 60vh; }
  .hg-cp-msg-bubble { font-size: 14px; }
}
