/* chat-kit pro / chat.css
   ──────────────────────────
   free 版と互換 + リンクカード / 終了モーダル / フェード遷移用クラス
*/

:root {
  --chat-bg: #ffffff;
  --chat-text: #0f1419;
  --chat-sub: #536471;
  --chat-bubble-from: #eff3f4;
  --chat-bubble-to: #b8e986;        /* 自分の吹き出し（黄緑） */
  --chat-bubble-to-text: #1c3812;   /* 自分の吹き出しの文字色（濃い緑） */
  --chat-border: #cfd9de;
  --chat-radius: 18px;
  --chat-max-width: 600px;

  --chat-end-bg: #8b6f47;
  --chat-end-fg: #fef9f3;
  --chat-end-overlay: rgba(42, 33, 24, 0.55);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--chat-bg);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  overflow-x: hidden;
}

.chat-app {
  max-width: var(--chat-max-width);
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.chat-app.fade-out { animation: chat-fade-out 1.8s ease forwards; }
.chat-app.fade-in  { animation: chat-fade-in  2.4s ease forwards; }
@keyframes chat-fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes chat-fade-in  { from { opacity: 0; } to { opacity: 1; } }

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--chat-bubble-from);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.chat-header img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}
.chat-name   { font-weight: 700; font-size: 15px; color: var(--chat-text); }
.chat-handle { font-size: 13px; color: var(--chat-sub); }

.chat-thread {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--chat-radius);
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-line;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.chat-msg.show { opacity: 1; transform: translateY(0); }

.chat-msg.from {
  align-self: flex-start;
  background: var(--chat-bubble-from);
  color: var(--chat-text);
  border-bottom-left-radius: 4px;
}
.chat-msg.to {
  align-self: flex-end;
  background: var(--chat-bubble-to);
  color: var(--chat-bubble-to-text);
  border-bottom-right-radius: 4px;
}
.chat-msg.from + .chat-msg.to,
.chat-msg.to + .chat-msg.from { margin-top: 12px; }

.chat-image {
  align-self: flex-start;
  max-width: 70%;
  margin-top: 6px;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.chat-image.show { opacity: 1; transform: translateY(0); }
.chat-image img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 16px;
  max-height: 360px;
  object-fit: cover;
}

.chat-link {
  align-self: flex-start;
  max-width: 80%;
  margin-top: 6px;
  padding: 12px 16px;
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  font-size: 14px;
  color: var(--chat-bubble-to);
  text-decoration: none;
  cursor: pointer;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.4s ease, transform 0.4s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-link.show { opacity: 1; transform: translateY(0); }
.chat-link::after { content: '↗'; margin-left: auto; color: #8b98a5; }

.chat-typing {
  align-self: flex-start;
  padding: 12px 16px;
  background: var(--chat-bubble-from);
  border-radius: var(--chat-radius);
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 3px;
  margin-top: 12px;
}
.chat-typing span {
  width: 6px;
  height: 6px;
  background: #8b98a5;
  border-radius: 50%;
  animation: chat-bounce 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.chat-time {
  align-self: center;
  font-size: 12px;
  color: #8b98a5;
  margin: 12px 0;
}

/* 画面下部のフッター（入力 / 選択肢 / 終了ボタンを置く領域） */
.chat-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--chat-bubble-from);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--chat-bg);
}
.chat-footer:empty { display: none; }

.chat-input-form {
  width: 100%;
  display: flex;
  gap: 8px;
  align-items: center;
}
.chat-input-form input {
  flex: 1 1 0;
  min-width: 0;
  padding: 10px 14px;
  background: var(--chat-bubble-from);
  border: none;
  border-radius: 9999px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  color: var(--chat-text);
}
.chat-input-form button {
  background: var(--chat-bubble-to);
  color: var(--chat-bubble-to-text);
  border: none;
  border-radius: 9999px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  flex-shrink: 0;
}

.chat-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-choice {
  display: block;
  width: 100%;
  padding: 14px 18px;
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  color: var(--chat-text);
  border-radius: 16px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.chat-choice:hover {
  background: var(--chat-bubble-to);
  border-color: var(--chat-bubble-to);
  color: var(--chat-bubble-to-text);
}

.chat-end-text {
  align-self: center;
  font-size: 12px;
  color: #8b98a5;
  margin: 16px 0;
  font-style: italic;
}

/* 終了モーダル発火ボタン（フッターに表示） */
.chat-end-trigger {
  display: block;
  width: 100%;
  padding: 14px 40px;
  background: var(--chat-end-bg);
  color: var(--chat-end-fg);
  border: none;
  border-radius: 30px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 0.2em;
  transition: all 0.3s;
}
.chat-end-trigger:hover {
  filter: brightness(0.9);
  transform: translateY(-1px);
}

.chat-end-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--chat-end-overlay);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  transition: opacity 0.5s ease;
}
.chat-end-overlay.open    { display: flex; }
.chat-end-overlay.visible { opacity: 1; }

.chat-end-modal {
  background: #fff;
  border-radius: 4px;
  padding: 48px 28px 36px;
  width: 100%;
  max-width: 420px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 16px 48px rgba(42, 33, 24, 0.16);
  transform: translateY(40px) scale(0.96);
  transition: transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
  position: relative;
}
.chat-end-overlay.visible .chat-end-modal {
  transform: translateY(0) scale(1);
}

.chat-end-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: transparent;
  border: none;
  font-size: 1.4rem;
  color: #999;
  cursor: pointer;
  padding: 8px;
}

.chat-end-message {
  font-size: 0.95rem;
  color: #555;
  margin-bottom: 24px;
  white-space: pre-line;
  line-height: 1.85;
}

.chat-end-share {
  display: inline-block;
  padding: 12px 22px;
  background: var(--chat-end-bg);
  color: var(--chat-end-fg);
  text-decoration: none;
  border-radius: 30px;
  font-size: 0.9rem;
  letter-spacing: 0.15em;
}
.chat-end-share:hover { filter: brightness(0.9); }

/* 「最初から」ボタン — モーダル末尾の控えめなセカンダリ */
.chat-end-replay {
  display: block;
  margin: 16px auto 0;
  padding: 10px 22px;
  background: transparent;
  color: #555;
  border: 1px solid #ccc;
  border-radius: 30px;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 0.15em;
  transition: all 0.2s;
}
.chat-end-replay:hover {
  background: #f5f5f5;
  border-color: #999;
  color: #000;
}

.chat-header .chat-speed-toggle {
  margin-inline-start: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  padding: 0.25rem 0.55rem;
  border: 1px solid var(--chat-border);
  border-radius: 999px;
  background: var(--chat-bg);
  color: var(--chat-text);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.chat-speed-toggle__state {
  min-width: 2.4em;
  padding: 0.2em 0.35em;
  border-radius: 999px;
  background: var(--chat-bubble-from);
  color: var(--chat-sub);
  text-align: center;
}

.chat-speed-toggle[aria-checked="true"] .chat-speed-toggle__state {
  background: var(--chat-bubble-to);
  color: var(--chat-bubble-to-text);
}

.chat-speed-toggle:focus-visible {
  outline: 2px solid var(--chat-sub);
  outline-offset: 2px;
}

/* ヒントページ移動用に追加 */
a.chat-end-trigger {
  text-align: center;
  text-decoration: none;
  max-width: 240px;
  margin-inline: auto;
}


/* hintリセットボタン用に追加 */
.chat-header--hint {
  gap: 8px;
}

.chat-header--hint > img + div {
  min-width: 0;
  overflow-wrap: anywhere;
}

.chat-header--hint .chat-hint-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 6px;
  margin-inline-start: auto;
}

.chat-header--hint .chat-speed-toggle {
  margin-inline-start: 0;
}

.chat-header--hint .chat-hint-reset {
  min-height: 44px;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--chat-border);
  border-radius: 999px;
  background: var(--chat-bg);
  color: var(--chat-sub);
  font: inherit;
  font-size: 0.75rem;
  white-space: nowrap;
  cursor: pointer;
}

.chat-header--hint .chat-hint-reset:focus-visible {
  outline: 2px solid var(--chat-sub);
  outline-offset: 2px;
}

@media (hover: hover) {
  .chat-header--hint .chat-hint-reset:hover {
    background-color: #e8f5db;
    border-color: #c9dfa9;
    color: var(--chat-bubble-to-text);
  }
}