/* style.css
   配色・フォント・レイアウトはCSS変数で管理し、後から調整しやすくしている。
   design_doc.md に沿った実装。 */

:root {
  /* --- 配色 --- */
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-primary: #06c755;      /* LINE風のアクセントグリーン */
  --color-primary-dark: #049c43;
  --color-text: #1c1c1e;
  --color-text-muted: #6b7280;
  --color-border: #e2e5e9;
  --color-bubble-user: #06c755;
  --color-bubble-user-text: #ffffff;
  --color-bubble-assistant: #ffffff;
  --color-bubble-assistant-text: #1c1c1e;
  --color-danger: #d93025;

  /* --- フォント --- */
  --font-base: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Segoe UI", sans-serif;
  --font-size-base: 16px;

  /* --- レイアウト --- */
  --radius-card: 16px;
  --radius-bubble: 18px;
  --header-height: 60px;
  --input-bar-height: 64px;
  --max-content-width: 720px;
  --chat-bg-image: none;

  /* --- アニメーション --- */
  --transition-fast: 0.15s ease;
  --transition-base: 0.25s ease;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-base);
  font-size: var(--font-size-base);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* hidden属性をCSSでも確実に効かせる(JavaScriptで制御するため重要) */
[hidden] {
  display: none !important;
}

/* =============================================================================
   キャラクター選択画面 (index.html)
   ============================================================================= */

.select-screen {
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: 32px 20px 120px;
}

.select-header h1 {
  font-size: 1.4rem;
  text-align: center;
  margin-bottom: 24px;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

@media (min-width: 640px) {
  .character-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.loading-text {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--color-text-muted);
}

.character-card {
  background: var(--color-surface);
  border: 2px solid transparent;
  border-radius: var(--radius-card);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.character-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
}

.character-card--selected {
  border-color: var(--color-primary);
}

.character-card__image-wrap {
  width: 100%;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  background: var(--color-bg);
}

.character-card__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.character-card__body {
  padding: 12px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.character-card__label {
  font-weight: 600;
  font-size: 1rem;
}

.character-card__description {
  margin: 0;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.entry-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 16px 20px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: slide-up var(--transition-base);
}

.entry-panel__selected {
  display: flex;
  align-items: center;
  margin: 0;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.entry-panel__label {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.entry-panel__input {
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  font-size: 1rem;
}

.entry-panel__button {
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 1rem;
  font-weight: 600;
  transition: background var(--transition-fast);
}

.entry-panel__button:hover {
  background: var(--color-primary-dark);
}

.entry-panel__button:disabled {
  opacity: 0.6;
  cursor: default;
}

.entry-panel__error {
  color: var(--color-danger);
  font-size: 0.85rem;
  margin: 0;
}

.entry-panel__close {
  background: transparent;
  border: none;
  font-size: 1.2rem;
  color: var(--color-text-muted);
  padding: 0 4px;
  cursor: pointer;
  transition: color var(--transition-fast);
  flex-shrink: 0;
  margin-left: auto;
}

.entry-panel__close:hover {
  color: var(--color-text);
}
/* =============================================================================
   チャット画面 (chat.html)
   ============================================================================= */

.chat-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: var(--max-content-width);
  margin: 0 auto;
  background: var(--color-bg);
  overflow: hidden;
}

.chat-header {
  height: var(--header-height);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.chat-header__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.chat-header__name {
  font-size: 1.05rem;
  margin: 0;
  flex: 1;
}

.chat-header__leave {
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  transition: background var(--transition-fast);
}

.chat-header__leave:hover {
  background: var(--color-bg);
}

.chat-message-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  background-image: var(--chat-bg-image, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.chat-bubble-row {
  display: flex;
  margin-bottom: 10px;
}

.chat-bubble-row:last-child {
  margin-bottom: 0;
}

.chat-bubble-row--assistant {
  justify-content: flex-start;
}

.chat-bubble-row--user {
  justify-content: flex-end;
}

.chat-bubble {
  max-width: 72%;
  padding: 10px 14px;
  border-radius: var(--radius-bubble);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
}

.chat-bubble--assistant {
  background: var(--color-bubble-assistant);
  color: var(--color-bubble-assistant-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.chat-bubble--user {
  background: var(--color-bubble-user);
  color: var(--color-bubble-user-text);
  border-bottom-right-radius: 4px;
}

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

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-muted);
  opacity: 0.6;
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

.chat-error {
  color: var(--color-danger);
  font-size: 0.85rem;
  text-align: center;
  margin: 0;
  padding: 6px 16px;
}

.chat-input-bar {
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 2;
  min-height: var(--input-bar-height);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}

.chat-input-bar__textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-family: inherit;
  max-height: 120px;
  line-height: 1.4;
}

.chat-input-bar__textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.chat-input-bar__send {
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 10px 18px;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background var(--transition-fast), opacity var(--transition-fast);
}

.chat-input-bar__send:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

.chat-input-bar__send:disabled {
  opacity: 0.5;
  cursor: default;
}

/* --- メッセージ表示アニメーション(フェードイン・スライドイン) --- */
.message-pop-enter-active {
  animation: message-in var(--transition-base);
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slide-up {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =============================================================================
   レスポンシブ調整
   ============================================================================= */

@media (max-width: 480px) {
  .chat-bubble {
    max-width: 85%;
  }
}

/* --- モーション低減設定を尊重 --- */
@media (prefers-reduced-motion: reduce) {
  .message-pop-enter-active,
  .entry-panel,
  .character-card,
  .typing-dot {
    animation: none !important;
    transition: none !important;
  }

  .typing-dot {
    opacity: 1;
  }
}
