/* hikoya-ai.css */
#hikoya-ai-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: "Noto Sans JP", sans-serif;
}

/* Launcher Button */
.hikoya-ai-launcher {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  /* 4788b4 base with warm orange/pink gradient for bubble effect */
  background: linear-gradient(135deg, #4788b4, #6ab0de, #f2c9c2, #4788b4);
  background-size: 300% 300%;
  animation: hikoyaBubbleGradient 6s ease infinite;
  box-shadow: 0 6px 20px rgba(71, 136, 180, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  border: 2px solid #fff;
  position: relative;
  /* コロコロ転がる表現のためのアニメーション */
  animation: hikoyaBubbleGradient 6s ease infinite, rollBubble 4s ease-in-out infinite alternate;
}

@keyframes rollBubble {
  0% { transform: translateY(0) rotate(0deg); border-radius: 50% 50% 50% 50% / 50% 50% 50% 50%; }
  50% { transform: translateY(-5px) rotate(10deg); border-radius: 55% 45% 50% 50% / 50% 55% 45% 50%; }
  100% { transform: translateY(2px) rotate(-10deg); border-radius: 45% 55% 50% 50% / 50% 45% 55% 50%; }
}

.hikoya-ai-launcher.pop-effect {
  animation: popAnim 0.4s cubic-bezier(0.36, -0.24, 0.2, 1.38);
}

@keyframes popAnim {
  0% { transform: scale(1); }
  40% { transform: scale(0.7) scaleX(1.3); border-radius: 40% 40% 60% 60%; }
  100% { transform: scale(1); border-radius: 50%; }
}

/* Tooltip Styles */
.hikoya-ai-tooltip {
  position: absolute;
  right: calc(100% + 15px);
  top: 50%;
  transform: translateY(-50%);
  background: #fff;
  color: #4788b4;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0.9;
  border: 1px solid #e0e0e0;
}
.hikoya-ai-tooltip::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  border-width: 6px 0 6px 6px;
  border-style: solid;
  border-color: transparent transparent transparent #fff;
}
.tooltip-sp {
  display: none;
}
.hikoya-ai-launcher:hover {
  transform: scale(1.05) scaleX(1.02) scaleY(0.98) !important;
  box-shadow: 0 8px 25px rgba(71, 136, 180, 0.5);
  /* 触れる度に色が変わる表現 */
  background: linear-gradient(135deg, #f2c9c2, #6ab0de, #4788b4, #f2c9c2);
  background-size: 300% 300%;
}
.hikoya-ai-launcher:active {
  /* PCでもクリック時に少し潰れるぷにぷに感 */
  transform: scale(0.9) scaleX(1.15) scaleY(0.85) !important;
  transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);
  /* 押した時に色が変わる */
  background: linear-gradient(135deg, #e6b3ab, #5a9cc7, #367099, #e6b3ab);
}

.hikoya-ai-launcher svg {
  width: 32px;
  height: 32px;
  fill: #fff;
}

@keyframes hikoyaBubbleGradient {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* Chat Window */
.hikoya-ai-window {
  position: absolute;
  bottom: 90px;
  right: 0;
  width: 350px;
  height: 550px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.hikoya-ai-window.hikoya-ai-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* Header */
.hikoya-ai-header {
  padding: 16px 20px;
  background: linear-gradient(135deg, #4788b4, #73a9cc, #e6c5bf, #4788b4);
  background-size: 300% 300%;
  animation: hikoyaBubbleGradient 8s ease infinite;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hikoya-ai-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.15);
  letter-spacing: 0.5px;
}
.hikoya-ai-close {
  cursor: pointer;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  transition: background 0.2s;
  padding-bottom: 2px; /* optical alignment */
}
.hikoya-ai-close:hover {
  background: rgba(255, 255, 255, 0.4);
}

/* Messages Body */
.hikoya-ai-body {
  flex: 1;
  padding: 20px;
  background-color: #fcfaf7; /* warm off-white background */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.hikoya-ai-body::-webkit-scrollbar {
  width: 6px;
}
.hikoya-ai-body::-webkit-scrollbar-track {
  background: transparent;
}
.hikoya-ai-body::-webkit-scrollbar-thumb {
  background-color: rgba(0,0,0,0.1);
  border-radius: 10px;
}

/* Message Bubbles */
.hikoya-message {
  display: flex;
  max-width: 88%;
  flex-direction: column;
}

.hikoya-message-bot {
  align-self: flex-start;
}

.hikoya-message-user {
  align-self: flex-end;
  align-items: flex-end;
}

.hikoya-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.6;
  color: #333;
}

.hikoya-message-bot .hikoya-bubble {
  background-color: #fff;
  border-bottom-left-radius: 4px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.08);
  border: 1px solid #e2ded5;
}

.hikoya-message-user .hikoya-bubble {
  background-color: #4788b4;
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(71, 136, 180, 0.25);
}

/* Input Area */
.hikoya-ai-footer {
  padding: 12px 16px;
  background: #fff;
  border-top: 1px solid #f0eee9;
  display: flex;
  gap: 12px;
  align-items: flex-end;
  box-shadow: 0 -4px 15px rgba(0,0,0,0.05);
}

.hikoya-ai-input {
  flex: 1;
  border: 1.5px solid #d0d0d0;
  background-color: #fcfcfc;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 16px; /* iOSの自動ズーム防止のため16pxに変更 */
  outline: none;
  resize: none;
  max-height: 80px;
  overflow-y: auto;
  transition: border-color 0.2s, background-color 0.2s;
  font-family: inherit;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}
.hikoya-ai-input:focus {
  border-color: #4788b4;
  background-color: #fff;
}

.hikoya-ai-send {
  background-color: #4788b4;
  color: #fff;
  border: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(71, 136, 180, 0.3);
}
.hikoya-ai-send:hover {
  background-color: #386c91;
}
.hikoya-ai-send:active {
  transform: scale(0.95);
}
.hikoya-ai-send svg {
  width: 18px;
  height: 18px;
  fill: #fff;
  margin-left: 2px;
}

/* Voice Input Mic Button */
.hikoya-ai-mic {
  background: transparent;
  border: none;
  color: #888;
  width: 42px;
  height: 42px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s, color 0.2s;
  flex-shrink: 0;
}
.hikoya-ai-mic:hover {
  background: #f0f0f0;
  color: #4788b4;
}
.hikoya-ai-mic.recording {
  color: #e53935;
  animation: pulseRecording 1.5s infinite;
}
@keyframes pulseRecording {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
.hikoya-ai-mic svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* Typing Indicator */
.hikoya-typing {
  display: none;
  gap: 5px;
  padding: 14px 18px;
  background: #fff;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  border: 1px solid #f0eee9;
}
.hikoya-typing.active {
  display: flex;
}
.hikoya-typing span {
  width: 8px;
  height: 8px;
  background-color: #4788b4;
  border-radius: 50%;
  animation: hikoyaTyping 1.4s infinite both;
  opacity: 0.7;
}
.hikoya-typing span:nth-child(1) { animation-delay: -0.32s; }
.hikoya-typing span:nth-child(2) { animation-delay: -0.16s; }

@keyframes hikoyaTyping {
  0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* Mobile Responsive: インスタ風ボトム・すりガラスカプセルバー（Idea 1） */
@media (max-width: 600px) {
  #hikoya-ai-widget {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 0;
    z-index: 9999;
  }
  .hikoya-ai-launcher {
    position: absolute !important;
    bottom: max(88px, calc(80px + env(safe-area-inset-bottom, 20px))) !important;
    left: 50% !important;
    right: auto !important;
    top: auto !important;
    transform: translateX(-50%) !important;
    width: auto !important;
    height: 50px !important;
    padding: 0 22px 0 16px !important;
    border-radius: 30px !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    /* 普段：インスタ風の透けるすりガラス効果（裏側の写真・文字が見える） */
    background: rgba(255, 255, 255, 0.45) !important;
    backdrop-filter: blur(14px) saturate(180%);
    -webkit-backdrop-filter: blur(14px) saturate(180%);
    border: 1.5px solid rgba(255, 255, 255, 0.75) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12) !important;
    opacity: 0.78;
    animation: none !important; /* スマホ時は回転やローリングアニメーションをOFFにして洗練させる */
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }
  
  /* スクロール中はさらに透過させて邪魔しない */
  .hikoya-ai-launcher.is-scrolling {
    opacity: 0.42 !important;
    background: rgba(255, 255, 255, 0.28) !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06) !important;
  }

  /* 触れた時・タップした時（アクティブ時）にくっきり鮮やかに浮き出る */
  .hikoya-ai-launcher:hover,
  .hikoya-ai-launcher:active,
  .hikoya-ai-launcher.sp-active {
    opacity: 1 !important;
    background: linear-gradient(135deg, #4788b4, #6ab0de, #f2c9c2, #4788b4) !important;
    background-size: 300% 300% !important;
    animation: hikoyaBubbleGradient 4s ease infinite !important;
    border-color: rgba(255, 255, 255, 0.9) !important;
    box-shadow: 0 8px 26px rgba(71, 136, 180, 0.45) !important;
    transform: translateX(-50%) scale(1.04) translateY(-3px) !important;
  }

  .tooltip-pc { display: none !important; }
  .tooltip-sp { display: inline !important; }
  
  .hikoya-ai-tooltip {
    position: static !important;
    transform: none !important;
    background: transparent !important;
    color: #1e3a5f !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    white-space: nowrap !important;
    pointer-events: none !important;
    opacity: 1 !important;
    transition: color 0.3s ease !important;
  }
  .hikoya-ai-tooltip::after {
    display: none !important;
  }

  /* 触れた時に文字とアイコンが白色に変化 */
  .hikoya-ai-launcher:hover .hikoya-ai-tooltip,
  .hikoya-ai-launcher:active .hikoya-ai-tooltip,
  .hikoya-ai-launcher.sp-active .hikoya-ai-tooltip {
    color: #ffffff !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  }
  
  .hikoya-ai-launcher svg {
    width: 24px !important;
    height: 24px !important;
    fill: #1e3a5f !important;
    transition: fill 0.3s ease, transform 0.3s ease !important;
    flex-shrink: 0;
  }
  
  .hikoya-ai-launcher:hover svg,
  .hikoya-ai-launcher:active svg,
  .hikoya-ai-launcher.sp-active svg {
    fill: #ffffff !important;
    transform: scale(1.1);
  }

  .hikoya-ai-window {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
    z-index: 10000;
  }
  .hikoya-ai-footer {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
  .hikoya-ai-input {
    font-size: 16px; /* SPで必ず16pxにしてズームを防ぐ */
  }
}
