/* ============================================================
   AI音声会話システム — LINE風チャットUI + 通話オーバーレイ
   スマートフォン向けダークテーマ
   ============================================================ */

/* ---------- Google Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Noto+Sans+JP:wght@400;500;600;700&display=swap');

/* ---------- CSS Variables (Design Tokens) ---------- */
:root {
  /* カラーパレット（ダークテーマ） */
  --bg-primary:    #0a0a0f;
  --bg-secondary:  #141420;
  --bg-tertiary:   #1c1c2e;
  --bg-card:       #1e1e30;
  --bg-overlay:    rgba(10, 10, 15, 0.92);

  --surface-1:     #252540;
  --surface-2:     #2e2e4a;
  --surface-3:     #383860;

  --text-primary:  #f0f0f8;
  --text-secondary:#a0a0c0;
  --text-muted:    #6a6a8a;

  --accent-green:  #00e676;
  --accent-green-dim: rgba(0, 230, 118, 0.15);
  --accent-red:    #ff1744;
  --accent-red-dim:rgba(255, 23, 68, 0.15);
  --accent-blue:   #448aff;
  --accent-blue-dim:rgba(68, 138, 255, 0.15);
  --accent-purple: #7c4dff;

  /* 吹き出し */
  --bubble-self:   linear-gradient(135deg, #00c853 0%, #00e676 100%);
  --bubble-other:  #252540;
  --bubble-system: rgba(68, 138, 255, 0.12);

  /* フォント */
  --font-primary:  'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;

  /* レイアウト */
  --header-height: 56px;
  --footer-height: 56px;
  --debug-bar-height: 64px;
  --safe-top:      env(safe-area-inset-top, 0px);
  --safe-bottom:   env(safe-area-inset-bottom, 0px);
  --safe-left:     env(safe-area-inset-left, 0px);
  --safe-right:    env(safe-area-inset-right, 0px);

  /* 影 */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

  /* ボーダー */
  --border-subtle: 1px solid rgba(255, 255, 255, 0.06);

  /* 遷移 */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-med:  250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  /* アニメーション用 */
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-primary);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  position: fixed;
  top: 0;
  left: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  border: none;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

input, textarea {
  font-family: inherit;
  border: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- App Container ---------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* ---------- API Key Modal ---------- */
.api-key-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-overlay);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 24px;
  animation: fadeIn 0.3s var(--ease-out-expo);
}

.api-key-modal.hidden {
  display: none;
}

.api-key-card {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
  border: var(--border-subtle);
}

.api-key-card h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--accent-green), var(--accent-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.api-key-card p {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

.api-key-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: 12px;
  font-size: 0.875rem;
  margin-bottom: 16px;
  border: 1px solid transparent;
  transition: border-color var(--transition-fast);
}

.api-key-input:focus {
  border-color: var(--accent-green);
}

.api-key-submit {
  width: 100%;
  padding: 14px;
  background: var(--accent-green);
  color: #000;
  font-size: 0.9375rem;
  font-weight: 600;
  border-radius: 12px;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.api-key-submit:active {
  transform: scale(0.97);
}

.api-key-submit:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* ---------- Setup Step Badge ---------- */
.setup-step-badge {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--surface-1);
  padding: 3px 10px;
  border-radius: 99px;
  margin-bottom: 16px;
}

/* ---------- Mic Permission Step ---------- */
.mic-icon-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.mic-icon {
  width: 56px;
  height: 56px;
  fill: var(--accent-blue);
  animation: micPulse 2s ease-in-out infinite;
  filter: drop-shadow(0 0 12px rgba(68, 138, 255, 0.5));
}

@keyframes micPulse {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%       { transform: scale(1.1); opacity: 0.8; }
}

.mic-note {
  font-size: 0.75rem !important;
  color: var(--text-muted) !important;
  margin-bottom: 20px !important;
  text-align: center;
  background: var(--surface-1);
  padding: 10px 14px;
  border-radius: 8px;
  border-left: 3px solid var(--accent-blue);
  line-height: 1.6 !important;
}

.mic-error {
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--accent-red);
  background: var(--accent-red-dim);
  padding: 10px 14px;
  border-radius: 8px;
  line-height: 1.5;
  text-align: center;
}

.mic-error.hidden {
  display: none;
}

/* ---------- Debug Bar (Phase Tabs) ---------- */
.debug-bar {
  flex-shrink: 0;
  padding: calc(var(--safe-top) + 8px) var(--safe-left) 8px var(--safe-right);
  background: var(--bg-secondary);
  border-bottom: var(--border-subtle);
}

.phase-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 16px 8px;
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-snap-type: x mandatory;
}

.phase-tabs::-webkit-scrollbar {
  display: none;
}

.phase-tab {
  flex-shrink: 0;
  padding: 8px 16px;
  background: var(--surface-1);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 20px;
  white-space: nowrap;
  transition: all var(--transition-fast);
  scroll-snap-align: start;
}

.phase-tab.active {
  background: var(--accent-green);
  color: #000;
  box-shadow: 0 0 16px rgba(0, 230, 118, 0.3);
}

.phase-tab:active {
  transform: scale(0.95);
}

.phase-info {
  padding: 4px 16px;
  font-size: 0.6875rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

/* ---------- Header Bar ---------- */
.header-bar {
  flex-shrink: 0;
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: var(--border-subtle);
}

.header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.header-info {
  flex: 1;
  min-width: 0;
}

.header-name {
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-status {
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.call-button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent-green);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: 0 0 12px rgba(0, 230, 118, 0.25);
}

.call-button:active {
  transform: scale(0.9);
}

.call-button svg {
  width: 20px;
  height: 20px;
  fill: #000;
}

.call-button.connecting {
  animation: pulse-green 1.5s infinite;
}

/* ---------- Chat Timeline ---------- */
.chat-timeline {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* メッセージバブル */
.message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
  animation: messageIn 0.3s var(--ease-out-expo);
}

.message.self {
  align-self: flex-end;
  background: var(--bubble-self);
  color: #000;
  border-bottom-right-radius: 6px;
}

.message.other {
  align-self: flex-start;
  background: var(--bubble-other);
  color: var(--text-primary);
  border-bottom-left-radius: 6px;
}

.message.system {
  align-self: center;
  background: var(--bubble-system);
  color: var(--accent-blue);
  font-size: 0.75rem;
  border-radius: 12px;
  text-align: center;
  max-width: 90%;
}

.message-time {
  font-size: 0.625rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.message.self .message-time {
  text-align: right;
  color: rgba(0, 0, 0, 0.5);
}

/* 通話ログ */
.call-log {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--surface-1);
  border-radius: 24px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  animation: messageIn 0.3s var(--ease-out-expo);
}

.call-log-icon {
  font-size: 1rem;
}

/* ---------- Footer Bar ---------- */
.footer-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px calc(var(--safe-bottom) + 8px);
  background: var(--bg-secondary);
  border-top: var(--border-subtle);
}

.text-input {
  flex: 1;
  padding: 10px 16px;
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: 24px;
  font-size: 0.875rem;
}

.text-input::placeholder {
  color: var(--text-muted);
}

.send-button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform var(--transition-fast);
}

.send-button:active {
  transform: scale(0.9);
}

.send-button svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

/* ============================================================
   通話オーバーレイ（全画面モーダル）
   ============================================================ */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #0d0d1a 0%, #1a1a3a 50%, #0d0d1a 100%);
  transition: opacity var(--transition-slow), visibility var(--transition-slow);
  opacity: 1;
  visibility: visible;
}

.call-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.call-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 40px 24px;
  width: 100%;
  max-width: 360px;
}

/* タイマー */
.call-timer-container {
  text-align: center;
}

.call-timer {
  font-size: 2rem;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  letter-spacing: 2px;
}

.call-timer-limit {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* アバター */
.call-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  font-weight: 700;
  color: #fff;
  position: relative;
}

.call-avatar::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid transparent;
  animation: none;
}

.call-overlay.active .call-avatar::after {
  border-color: var(--accent-green);
  animation: avatarRing 2s infinite;
}

.call-name {
  font-size: 1.25rem;
  font-weight: 600;
  text-align: center;
}

.call-status {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-align: center;
}

/* 波形ビジュアライザ */
.visualizer-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 48px;
  width: 200px;
}

.visualizer-bar {
  width: 4px;
  background: var(--accent-green);
  border-radius: 2px;
  min-height: 4px;
  transition: height 80ms ease-out;
}

.visualizer-bar.ai {
  background: var(--accent-blue);
}

/* 切断ボタン */
.end-call-button {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent-red);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 24px;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: 0 4px 24px rgba(255, 23, 68, 0.35);
}

.end-call-button:active {
  transform: scale(0.9);
}

.end-call-button svg {
  width: 28px;
  height: 28px;
  fill: #fff;
  transform: rotate(135deg);
}

/* 通話中の音量表示ラベル */
.volume-labels {
  display: flex;
  justify-content: space-between;
  width: 200px;
  font-size: 0.625rem;
  color: var(--text-muted);
}

/* ============================================================
   アニメーション
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 12px rgba(0, 230, 118, 0.25); }
  50%      { box-shadow: 0 0 24px rgba(0, 230, 118, 0.5); }
}

@keyframes avatarRing {
  0%   { transform: scale(1);    opacity: 1; }
  50%  { transform: scale(1.15); opacity: 0.4; }
  100% { transform: scale(1.3);  opacity: 0; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* タイマー警告 */
.call-timer.warning {
  color: var(--accent-red);
  animation: timerBlink 1s infinite;
}

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

/* ============================================================
   レスポンシブ / ユーティリティ
   ============================================================ */
@media (min-width: 481px) {
  #app {
    border-left: var(--border-subtle);
    border-right: var(--border-subtle);
  }
}

.hidden { display: none !important; }

/* スクロールバー */
.chat-timeline::-webkit-scrollbar {
  width: 4px;
}
.chat-timeline::-webkit-scrollbar-track {
  background: transparent;
}
.chat-timeline::-webkit-scrollbar-thumb {
  background: var(--surface-2);
  border-radius: 2px;
}

/* 接続中インジケーター */
.connecting-dots::after {
  content: '';
  animation: dots 1.5s steps(4) infinite;
}

@keyframes dots {
  0%  { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}
