/* ===== AI チャット ===== */

/* 常設 CTA バッジ（AIに聞く） — キャラと同じ teal トーン、揺れも同期 */
.ai-cta-standalone {
  position: fixed;
  right: 18px;
  bottom: 150px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #5fd9d9 0%, #3fb5b5 100%);
  color: #0f2a2a;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 16px 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 6px 18px rgba(95, 217, 217, 0.55), 0 0 0 0 rgba(95, 217, 217, 0.5);
  cursor: pointer;
  white-space: nowrap;
  letter-spacing: 0.04em;
  font-family: inherit;
  animation: ai-cta-bob 4.5s ease-in-out infinite, ai-cta-pulse 4.5s ease-in-out infinite;
  transition:
    right 2s ease-in-out,
    bottom 2s ease-in-out,
    transform 0.18s ease,
    box-shadow 0.25s ease,
    opacity 0.45s ease-out;
}

.ai-cta-standalone:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 10px 26px rgba(95, 217, 217, 0.7);
}

.ai-cta-standalone:active {
  transform: translateY(0) scale(1.0);
}

.ai-cta-icon {
  font-size: 14px;
  line-height: 1;
}

@keyframes ai-cta-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

@keyframes ai-cta-pulse {
  0%, 100% { box-shadow: 0 6px 18px rgba(95, 217, 217, 0.55), 0 0 0 0 rgba(95, 217, 217, 0.5); }
  50% { box-shadow: 0 6px 18px rgba(95, 217, 217, 0.55), 0 0 0 12px rgba(95, 217, 217, 0); }
}

/* バッジは視覚的に後ろ(z-index 1) → クリック判定だけ前面に取る透明 hotzone */
.ai-cta-hotzone {
  position: fixed;
  right: 18px;
  bottom: 150px;
  width: 110px;
  height: 36px;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  z-index: 9000;
  -webkit-appearance: none;
  appearance: none;
  transition:
    right 2s ease-in-out,
    bottom 2s ease-in-out;
}
.ai-cta-hotzone:focus-visible {
  outline: 2px solid rgba(95, 217, 217, 0.7);
  outline-offset: 4px;
  border-radius: 999px;
}


/* クラウドAIくん フローティングコンテナ */
.chat-fab {
  position: fixed;
  right: 12px;
  bottom: 6px;
  z-index: 1;
  width: 102px;
  height: 138px;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  filter: drop-shadow(0 10px 22px rgba(95, 217, 217, 0.5));
  transition:
    right 2s ease-in-out,
    bottom 2s ease-in-out,
    transform 0.25s ease,
    filter 0.3s ease,
    opacity 0.5s ease-out;
}

.chat-fab:hover {
  transform: translateY(-4px) scale(1.04);
  filter: drop-shadow(0 16px 30px rgba(95, 217, 217, 0.7));
}

.chat-fab:active {
  transform: translateY(-1px) scale(1.0);
}

/* 背後のオーラ（円グロー） */
.ai-character-aura {
  position: absolute;
  left: 50%;
  bottom: 14px;
  width: 130px;
  height: 130px;
  margin-left: -65px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(95, 217, 217, 0.55) 0%, rgba(95, 217, 217, 0) 70%);
  filter: blur(2px);
  pointer-events: none;
  animation: ai-aura-pulse 3.4s ease-in-out infinite;
  z-index: 0;
}

@keyframes ai-aura-pulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 0.95; transform: scale(1.12); }
}

/* キャラ画像本体 */
.ai-character {
  position: relative;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom center;
  animation: ai-float 4.5s ease-in-out infinite;
  pointer-events: none;
  z-index: 1;
}

@keyframes ai-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

/* 移動中のテクテク歩行: 上下バウンス＋左右の傾き */
.chat-fab.is-walking .ai-character {
  animation: ai-walking 0.45s ease-in-out infinite;
}

@keyframes ai-walking {
  0% { transform: translateY(0) rotate(-3deg); }
  25% { transform: translateY(-8px) rotate(-2deg); }
  50% { transform: translateY(0) rotate(3deg); }
  75% { transform: translateY(-8px) rotate(2deg); }
  100% { transform: translateY(0) rotate(-3deg); }
}

/* 吹き出し */
.ai-speech {
  position: absolute;
  right: 110px;
  bottom: 100px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96) 0%, rgba(240, 240, 255, 0.96) 100%);
  color: #2a2a3e;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 18px;
  border-bottom-right-radius: 4px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateX(8px) translateY(4px) scale(0.9);
  transform-origin: bottom right;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.ai-speech.is-visible {
  opacity: 1;
  transform: translateX(0) translateY(0) scale(1);
}

.ai-speech::after {
  content: '';
  position: absolute;
  right: -8px;
  bottom: 8px;
  width: 14px;
  height: 14px;
  background: inherit;
  border-bottom-right-radius: 4px;
  transform: rotate(45deg);
  z-index: -1;
}

/* ----- パネル ----- */

.chat-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9001;
  width: min(380px, calc(100vw - 32px));
  height: min(600px, calc(100vh - 100px));
  background: rgba(18, 20, 32, 0.78);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px);
  opacity: 0;
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.22s ease;
}

.chat-panel.is-open {
  display: flex;
  transform: translateY(0);
  opacity: 1;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(110, 124, 255, 0.18) 0%, rgba(110, 124, 255, 0.02) 100%);
}

.chat-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.02em;
}

.chat-title-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5fd97b;
  box-shadow: 0 0 8px #5fd97b;
}

.chat-close {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.2s ease, color 0.2s ease;
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  font-size: 13.5px;
  line-height: 1.6;
}

.chat-msg.user {
  align-self: flex-end;
}

.chat-msg.assistant {
  align-self: flex-start;
}

.chat-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chat-msg.user .chat-bubble {
  background: linear-gradient(135deg, #6e7cff 0%, #b48cff 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg.assistant .chat-bubble {
  background: rgba(255, 255, 255, 0.06);
  color: #f0f0f5;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom-left-radius: 4px;
}

.chat-msg.system .chat-bubble {
  background: rgba(255, 200, 100, 0.1);
  color: #ffd28a;
  border: 1px solid rgba(255, 200, 100, 0.25);
  font-size: 12.5px;
  text-align: center;
  align-self: center;
}

.chat-msg.system {
  align-self: center;
  max-width: 100%;
}

.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  animation: chat-dot 1.2s ease-in-out infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chat-dot {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.18);
}

.chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: #fff;
  font-size: 13.5px;
  padding: 10px 12px;
  resize: none;
  min-height: 40px;
  max-height: 100px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.chat-input:focus {
  border-color: rgba(110, 124, 255, 0.6);
  background: rgba(255, 255, 255, 0.08);
}

.chat-input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

.chat-send {
  background: linear-gradient(135deg, #6e7cff 0%, #b48cff 100%);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.chat-send:hover:not(:disabled) {
  transform: translateY(-1px);
}

.chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.chat-disclaimer {
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.4);
  padding: 6px 12px 10px;
  text-align: center;
  background: rgba(0, 0, 0, 0.18);
}

/* モバイル */
@media (max-width: 600px) {
  /* スマホでは AIくん＆バッジを前面に (狭い画面でカードに隠されないため) */
  .chat-fab {
    right: 8px;
    bottom: 8px;
    width: 86px;
    height: 115px;
    z-index: 9000;
  }
  .ai-cta-standalone {
    right: 100px;
    bottom: 40px;
    font-size: 12px;
    padding: 7px 14px 7px 10px;
    z-index: 9001;
  }
  .ai-cta-hotzone {
    right: 100px;
    bottom: 40px;
    width: 96px;
    height: 32px;
  }
  .ai-character-aura {
    width: 90px;
    height: 90px;
    margin-left: -45px;
    bottom: 10px;
  }
  .ai-speech {
    right: 28px;
    bottom: 130px;
    font-size: 11.5px;
    padding: 8px 12px;
    width: 160px;
    max-width: 160px;
    white-space: normal;
    line-height: 1.45;
    text-align: center;
    box-sizing: border-box;
  }
  .ai-speech::after {
    right: 10px;
    bottom: -6px;
  }
  .chat-panel {
    right: 8px;
    left: 8px;
    bottom: 20px;
    width: auto;
    height: calc(100vh - 90px);
    max-height: 560px;
  }
}
