/* ══════════════════════════════════════════════
   Sprite — AI Site Guide Widget
   Scoped styles. Does not reset box-sizing globally;
   inherits the host page's font stack.
═══════════════════════════════════════════════ */

#sprite-widget {
  --sw-bg: #222222;
  --sw-bg-surface: #1a1a1a;
  --sw-text: #f0efe9;
  --sw-text-muted: #9e9e96;
  --sw-bubble-user: #f0efe9;
  --sw-bubble-user-text: #121212;
  --sw-bubble-sprite: #1e1e1e;
  --sw-border: rgba(255,255,255,0.08);
  --sw-input-bg: #1a1a1a;
  --sw-input-area-bg: rgba(0,0,0,0.2);
  --sw-status-online: #22c55e;
  --sw-status-waiting: #f59e0b;
  --sw-status-offline: #ef4444;
}

[data-theme="light"] #sprite-widget {
  --sw-bg: #ffffff;
  --sw-bg-surface: #fafaf7;
  --sw-text: #1a1a1a;
  --sw-text-muted: #6b6b63;
  --sw-bubble-user: #1a1a1a;
  --sw-bubble-user-text: #f0efe9;
  --sw-bubble-sprite: #f5f5f0;
  --sw-border: rgba(0,0,0,0.1);
  --sw-input-bg: #fafaf7;
  --sw-input-area-bg: rgba(0,0,0,0.03);
}

/* ── Widget container ── */
#sprite-widget {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 13.5px; line-height: 1.5;
}
#sprite-widget *, #sprite-widget *::before, #sprite-widget *::after { box-sizing: border-box; }
@media (max-width: 768px) { #sprite-widget { bottom: 16px; right: 16px; } }
@media (max-width: 420px) { #sprite-widget { bottom: 12px; right: 12px; } }

/* ── Pill (collapsed) ── */
.sprite-pill {
  display: flex; align-items: center; gap: 10px;
  height: 48px; padding: 0 18px 0 5px;
  background: var(--sw-bg);
  border: 1px solid var(--sw-border);
  border-radius: 9999px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  transition: all 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
  user-select: none;
  opacity: 0; transform: translateY(30px) scale(0.8);
  pointer-events: none;
}
.sprite-pill.visible {
  opacity: 1; transform: translateY(0) scale(1);
  pointer-events: all;
  animation: spriteFloat 4s cubic-bezier(0.37, 0, 0.63, 1) 0.6s infinite;
}
.sprite-pill:hover {
  transform: scale(1.04);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.sprite-pill.hidden { display: none; }
.sprite-pill .pill-text {
  font-size: 13px; font-weight: 500; color: var(--sw-text);
  white-space: nowrap; transition: opacity 0.2s;
}

@keyframes spriteFloat {
  0% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
  100% { transform: translateY(0); }
}

@media (max-width: 768px) {
  .sprite-pill { height: 44px; padding: 0 14px 0 4px; gap: 8px; }
  .sprite-pill .pill-text { font-size: 12px; }
  .sprite-pill .sprite-character { width: 30px; height: 30px; }
}
@media (max-width: 420px) {
  .sprite-pill { height: 40px; padding: 0 12px 0 3px; gap: 6px; }
  .sprite-pill .pill-text { font-size: 11px; }
  .sprite-pill .sprite-character { width: 28px; height: 28px; }
}

/* ── Panel (expanded) ── */
.sprite-panel {
  position: absolute; bottom: 0; right: 0;
  width: 380px; height: 540px;
  background: var(--sw-bg);
  border: 1px solid var(--sw-border);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  display: flex; flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  opacity: 0; transform: scale(0.6) translateY(20px);
  pointer-events: none;
}
.sprite-panel.open {
  opacity: 1; transform: scale(1) translateY(0);
  pointer-events: all;
}

/* ── Panel header ── */
.sprite-panel .panel-header {
  flex-shrink: 0; position: relative;
}
.sprite-panel .panel-banner {
  width: 100%; height: 140px;
  background-size: cover; background-position: center; background-repeat: no-repeat;
  border-radius: 20px 20px 0 0;
}
.sprite-panel .panel-close {
  position: absolute; top: 10px; right: 10px;
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(0,0,0,0.35); border: none;
  color: rgba(255,255,255,0.9); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; transition: all 0.2s;
  backdrop-filter: blur(4px); z-index: 1;
}
.sprite-panel .panel-close:hover { background: rgba(0,0,0,0.55); color: #fff; }

.panel-identity {
  position: relative;
  padding: 0 18px 10px;
  margin-top: -30px;
  display: flex; align-items: flex-end; gap: 12px;
}
.panel-identity .sprite-character {
  border: 3px solid var(--sw-bg); border-radius: 50%; flex-shrink: 0;
}
.panel-identity-info {
  display: flex; align-items: center; gap: 8px; padding-bottom: 4px;
}
.panel-identity-info .sprite-name { font-weight: 700; font-size: 14px; color: var(--sw-text); }

.panel-identity .sprite-status {
  font-size: 11px; display: flex; align-items: center; gap: 5px;
  transition: color 0.3s;
}
.panel-identity .sprite-status .status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  display: inline-block; transition: background 0.3s;
  animation: spriteStatusPulse 2s ease-in-out infinite;
}
.sprite-status[data-status="online"] { color: var(--sw-status-online); }
.sprite-status[data-status="online"] .status-dot { background: var(--sw-status-online); }
.sprite-status[data-status="waiting"] { color: var(--sw-status-waiting); }
.sprite-status[data-status="waiting"] .status-dot { background: var(--sw-status-waiting); }
.sprite-status[data-status="offline"] { color: var(--sw-status-offline); }
.sprite-status[data-status="offline"] .status-dot { background: var(--sw-status-offline); }

@keyframes spriteStatusPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Chat area ── */
.sprite-panel .chat-area {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  scroll-behavior: smooth;
}
.sprite-panel .chat-area::-webkit-scrollbar { width: 4px; }
.sprite-panel .chat-area::-webkit-scrollbar-track { background: transparent; }
.sprite-panel .chat-area::-webkit-scrollbar-thumb { background: rgba(128,128,128,0.2); border-radius: 4px; }

.chat-msg { display: flex; gap: 10px; max-width: 88%; animation: spriteMsgAppear 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.chat-msg.user { flex-direction: row-reverse; align-self: flex-end; }
@keyframes spriteMsgAppear { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.msg-bubble { padding: 10px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.5; }
.chat-msg.sprite .msg-bubble { background: var(--sw-bubble-sprite); color: var(--sw-text); border-bottom-left-radius: 4px; }
.chat-msg.user .msg-bubble { background: var(--sw-bubble-user); color: var(--sw-bubble-user-text); border-bottom-right-radius: 4px; font-weight: 500; }

.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #FFC710, #e0ad0e);
  display: flex; align-items: center; justify-content: center; margin-top: 2px;
}
.msg-avatar .mini-eyes { display: flex; gap: 4px; }
.msg-avatar .mini-eye { width: 4px; height: 5px; background: #1a1a1a; border-radius: 50%; }

/* ── Typing indicator ── */
.typing-indicator { display: flex; gap: 4px; padding: 12px 16px; }
.typing-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--sw-text-muted);
  animation: spriteTypingBounce 1.4s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes spriteTypingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Input area ── */
.sprite-panel .chat-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--sw-border);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
  background: var(--sw-input-area-bg);
}
.sprite-panel .chat-input {
  flex: 1; background: var(--sw-input-bg); border: 1px solid var(--sw-border);
  border-radius: 12px; padding: 10px 14px;
  color: var(--sw-text); font-size: 13.5px;
  outline: none; font-family: inherit;
  transition: border-color 0.2s;
}
.sprite-panel .chat-input::placeholder { color: var(--sw-text-muted); }
.sprite-panel .chat-input:focus { border-color: rgba(255,255,255,0.25); }
[data-theme="light"] .sprite-panel .chat-input:focus { border-color: rgba(0,0,0,0.2); }

.sprite-panel .input-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--sw-border);
  background: transparent; color: var(--sw-text-muted);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; flex-shrink: 0;
}
.sprite-panel .input-btn:hover { background: rgba(128,128,128,0.1); color: var(--sw-text); border-color: rgba(128,128,128,0.25); }
.sprite-panel .input-btn.active { background: var(--sw-text); color: var(--sw-bg); border-color: var(--sw-text); }
.sprite-panel .input-btn.recording { background: var(--sw-status-offline); border-color: var(--sw-status-offline); color: white; animation: spriteMicPulse 1s ease-in-out infinite; }
@keyframes spriteMicPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}
.sprite-panel .input-btn svg { width: 16px; height: 16px; }
.sprite-panel .send-btn { background: var(--sw-text); color: var(--sw-bg); border-color: var(--sw-text); }
.sprite-panel .send-btn:hover { opacity: 0.8; }

/* ── Sprite Character (CSS art) ── */
.sprite-character { position: relative; width: 34px; height: 34px; flex-shrink: 0; margin: 2px; }
.sprite-character.large { width: 52px; height: 52px; }

.sprite-body {
  width: 100%; height: 100%;
  background: linear-gradient(145deg, #FFC710, #e0ad0e);
  border-radius: 50%; position: relative;
  box-shadow: 0 4px 14px rgba(255,199,16,0.3), 0 0 20px rgba(255,199,16,0.12);
  transition: transform 0.3s;
}
.sprite-character:hover .sprite-body { transform: scale(1.08); }

.sprite-eyes { position: absolute; top: 34%; left: 50%; transform: translateX(-50%); display: flex; gap: 9px; }
.sprite-character.large .sprite-eyes { gap: 12px; }

.sprite-eye {
  width: 6px; height: 7px; background: #1a1a1a; border-radius: 50%;
  position: relative; transition: all 0.2s;
}
.sprite-character.large .sprite-eye { width: 8px; height: 9px; }
.sprite-eye::after {
  content: ''; position: absolute; top: 1px; right: 1px;
  width: 2px; height: 2px; background: rgba(255,255,255,0.7); border-radius: 50%;
}
.sprite-character.large .sprite-eye::after { width: 2.5px; height: 2.5px; }
.sprite-eye.blink { height: 2px !important; border-radius: 2px !important; }

.sprite-brow {
  position: absolute; width: 8px; height: 2px; background: #1a1a1a; border-radius: 2px;
  top: -5px; left: 50%; transform: translateX(-50%); opacity: 0; transition: all 0.2s;
}
.sprite-character.large .sprite-brow { width: 10px; top: -6px; }

.sprite-mouth {
  position: absolute; bottom: 24%; left: 50%; transform: translateX(-50%);
  width: 10px; height: 4px; background: #1a1a1a; border-radius: 0 0 6px 6px; transition: all 0.15s;
}
.sprite-character.large .sprite-mouth { width: 12px; height: 5px; }

/* ── Emotion states ── */
.sprite-character[data-emotion="happy"] .sprite-eye { height: 4px; border-radius: 4px 4px 0 0; }
.sprite-character[data-emotion="happy"] .sprite-mouth { width: 14px; height: 6px; border-radius: 0 0 8px 8px; }
.sprite-character.large[data-emotion="happy"] .sprite-mouth { width: 16px; height: 7px; }

.sprite-character[data-emotion="excited"] .sprite-eye { width: 8px; height: 9px; }
.sprite-character.large[data-emotion="excited"] .sprite-eye { width: 9px; height: 10px; }
.sprite-character[data-emotion="excited"] .sprite-mouth { width: 14px; height: 8px; border-radius: 0 0 10px 10px; }
.sprite-character.large[data-emotion="excited"] .sprite-mouth { width: 16px; height: 9px; }
.sprite-character[data-emotion="excited"] .sprite-body { animation: spriteExcited 0.3s ease-in-out infinite alternate; }
@keyframes spriteExcited { from { transform: translateY(0) scale(1); } to { transform: translateY(-3px) scale(1.06); } }

.sprite-character[data-emotion="surprised"] .sprite-eye { width: 9px; height: 11px; }
.sprite-character.large[data-emotion="surprised"] .sprite-eye { width: 10px; height: 12px; }
.sprite-character[data-emotion="surprised"] .sprite-mouth { width: 8px; height: 8px; border-radius: 50%; }

.sprite-character[data-emotion="thinking"] .sprite-mouth { width: 6px; height: 6px; border-radius: 50%; left: 58%; }
.sprite-character[data-emotion="thinking"] .sprite-eyes { transform: translateX(-50%) translateX(3px); }
.sprite-character[data-emotion="thinking"] .sprite-eye:first-child { height: 5px; }

.sprite-character[data-emotion="guessing"] .sprite-mouth { width: 8px; height: 3px; border-radius: 4px; }
.sprite-character[data-emotion="guessing"] .sprite-eyes { animation: spriteEyesDart 1s ease-in-out infinite; }
@keyframes spriteEyesDart { 0%, 100% { transform: translateX(-50%) translateX(-2px); } 50% { transform: translateX(-50%) translateX(2px); } }

.sprite-character[data-emotion="bored"] .sprite-eye { height: 4px; border-radius: 2px; }
.sprite-character.large[data-emotion="bored"] .sprite-eye { height: 5px; }
.sprite-character[data-emotion="bored"] .sprite-mouth { width: 10px; height: 2px; border-radius: 2px; }
.sprite-character[data-emotion="bored"] .sprite-body { animation: spriteBoredDrift 3s ease-in-out infinite; }
@keyframes spriteBoredDrift { 0%, 100% { transform: rotate(0deg); } 25% { transform: rotate(-2deg); } 75% { transform: rotate(2deg); } }

.sprite-character[data-emotion="sad"] .sprite-eye { transform: translateY(2px); }
.sprite-character[data-emotion="sad"] .sprite-brow { opacity: 1; transform: translateX(-50%) rotate(10deg); }
.sprite-character[data-emotion="sad"] .sprite-mouth { width: 12px; height: 5px; border-radius: 6px 6px 0 0; bottom: 22%; }

.sprite-character[data-emotion="angry"] .sprite-brow { opacity: 1; }
.sprite-character[data-emotion="angry"] .sprite-eye:first-child .sprite-brow { transform: translateX(-50%) rotate(-20deg); }
.sprite-character[data-emotion="angry"] .sprite-eye:last-child .sprite-brow { transform: translateX(-50%) rotate(20deg); }
.sprite-character[data-emotion="angry"] .sprite-mouth { width: 10px; height: 3px; border-radius: 2px; }
.sprite-character[data-emotion="angry"] .sprite-body { animation: spriteAngrySteam 0.15s ease-in-out infinite alternate; }
@keyframes spriteAngrySteam { from { transform: translateX(-1px); } to { transform: translateX(1px); } }

.sprite-character[data-emotion="talking"] .sprite-mouth { animation: spriteMouthTalk 0.25s ease-in-out infinite alternate; }
@keyframes spriteMouthTalk { 0% { height: 3px; width: 8px; border-radius: 0 0 4px 4px; } 100% { height: 8px; width: 10px; border-radius: 50%; } }
.sprite-character.large[data-emotion="talking"] .sprite-mouth { animation: spriteMouthTalkLg 0.25s ease-in-out infinite alternate; }
@keyframes spriteMouthTalkLg { 0% { height: 4px; width: 10px; border-radius: 0 0 5px 5px; } 100% { height: 10px; width: 12px; border-radius: 50%; } }

.sprite-character[data-emotion="waving"] .sprite-eye { height: 4px; border-radius: 4px 4px 0 0; }
.sprite-character[data-emotion="waving"] .sprite-mouth { width: 14px; height: 6px; border-radius: 0 0 8px 8px; }
.sprite-character[data-emotion="waving"] .sprite-body { animation: spriteWave 0.5s ease-in-out infinite alternate; }
@keyframes spriteWave { from { transform: rotate(-5deg); } to { transform: rotate(5deg); } }

.sprite-character[data-emotion="dancing"] .sprite-eye { height: 4px; border-radius: 4px 4px 0 0; }
.sprite-character[data-emotion="dancing"] .sprite-mouth { width: 14px; height: 6px; border-radius: 0 0 8px 8px; }
.sprite-character[data-emotion="dancing"] .sprite-body { animation: spriteDance 0.4s ease-in-out infinite; }
@keyframes spriteDance {
  0% { transform: translateX(-3px) rotate(-5deg); }
  25% { transform: translateX(3px) rotate(5deg) scale(1.05); }
  50% { transform: translateX(-2px) rotate(-3deg); }
  75% { transform: translateX(2px) rotate(3deg) scale(1.05); }
  100% { transform: translateX(-3px) rotate(-5deg); }
}

/* ── Quick chips ── */
.sprite-panel .quick-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 8px; }
.sprite-panel .quick-chip {
  padding: 5px 12px; border-radius: 20px;
  border: 1px solid var(--sw-border); background: transparent;
  color: var(--sw-text-muted); font-size: 12px; font-family: inherit;
  cursor: pointer; transition: all 0.2s;
}
.sprite-panel .quick-chip:hover { border-color: rgba(128,128,128,0.3); color: var(--sw-text); background: rgba(128,128,128,0.06); }

/* ── Nav link in chat ── */
.nav-link-inline { color: var(--sw-text); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.nav-link-inline:hover { opacity: 0.8; }

/* ── Responsive panel ── */
@media (max-width: 768px) { .sprite-panel { width: 340px; height: 500px; } }
@media (max-width: 420px) {
  .sprite-panel { width: calc(100vw - 24px); right: -6px; bottom: -6px; border-radius: 16px 16px 0 0; height: 70vh; }
}
