/* ════════════════════════════════════════════════════════════════════════════
   Design tokens — change a value here to update it everywhere
   ════════════════════════════════════════════════════════════════════════════ */
:root {
  --bg-page:        #0A1628;
  --bg-panel:       #112240;
  --bg-input:       #0D1B35;
  --bg-card:        #112240;
  --bg-bubble-rasa: #1E3A5F;
  --bg-bubble-user: #3B82F6;

  --accent:         #3B82F6;
  --accent-hover:   #2563EB;
  --accent-glow:    rgba(59, 130, 246, 0.30);

  --border:         #1E3A5F;
  --border-subtle:  #162034;

  --text-primary:   #FFFFFF;
  --text-secondary: #94A3B8;
  --text-disabled:  #3D5A80;

  --transition:     200ms ease-out;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

/* ── Welcome screen ───────────────────────────────────────────────────────── */
#welcome-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg-page);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.4s ease;
}

#welcome-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.welcome-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 48px 44px 44px;
  box-shadow: 0 0 60px rgba(59, 130, 246, 0.12), 0 12px 40px rgba(0, 0, 0, 0.5);
  max-width: 400px;
  width: 90%;
}

/* ── Character selector ── */
.char-select {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-bottom: 4px;
}

.char-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition),
              transform 0.1s;
}

.char-card:hover {
  border-color: var(--accent);
}

.char-card:active {
  transform: scale(0.97);
}

.char-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 16px var(--accent-glow);
}

.char-card img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top center;
  display: block;
}

.char-card span {
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.char-card.selected span {
  color: var(--text-primary);
}

/* ── Welcome logo & heading ── */
.welcome-logo {
  width: 140px;
  height: auto;
  display: block;
  margin: 0 auto;
}

.welcome-heading {
  font-family: 'Teko', sans-serif;
  font-size: 1.6rem;
  font-weight: 500;
  letter-spacing: 1.5px;
  color: var(--text-primary);
  text-align: center;
  margin-top: 4px;
}

/* ── Welcome input ── */
#name-input {
  width: 100%;
  margin-top: 8px;
  padding: 14px 20px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: 24px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  text-align: center;
  transition: border-color var(--transition), box-shadow var(--transition);
}

#name-input::placeholder {
  color: var(--text-disabled);
}

#name-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Welcome button ── */
#start-btn {
  width: 100%;
  padding: 14px 24px;
  background: var(--accent);
  color: var(--text-primary);
  border: none;
  border-radius: 24px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition), transform 0.1s;
}

#start-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 0 20px var(--accent-glow);
}

#start-btn:active:not(:disabled) {
  transform: scale(0.98);
}

#start-btn:disabled {
  background: var(--border);
  color: var(--text-disabled);
  cursor: not-allowed;
}

/* ── Two-column layout ────────────────────────────────────────────────────── */
.layout {
  display: flex;
  width: 100%;
  max-width: 1140px;
  height: 100vh;
}

/* ── Left: chat panel ─────────────────────────────────────────────────────── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-subtle);
  padding: 28px 24px 20px;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

/* ── Avatar ── */
.chat-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top center;
  display: block;
  box-shadow: 0 0 0 2px var(--bg-panel), 0 0 0 3px var(--border),
              0 0 12px var(--accent-glow);
}

.avatar-online {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10B981;
  border: 2px solid var(--bg-panel);
}

.chat-title {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--text-primary);
}

#mute-btn {
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: none;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--accent);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

#mute-btn:hover {
  background: var(--border-subtle);
  border-color: var(--border);
}

/* Show/hide the two SVGs based on muted state */
#mute-btn .icon-muted         { display: none; }
#mute-btn.muted .icon-unmuted { display: none; }
#mute-btn.muted .icon-muted   { display: block; color: var(--text-disabled); }

/* ── Messages area ────────────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.messages::-webkit-scrollbar        { width: 4px; }
.messages::-webkit-scrollbar-track  { background: transparent; }
.messages::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 2px; }

.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 1rem;
  line-height: 1.6;
}

/* Rasa's messages — dark blue, left-aligned */
.message.rasa {
  background: var(--bg-bubble-rasa);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

/* Child's messages — electric blue, right-aligned */
.message.child {
  background: var(--bg-bubble-user);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

/* ── Input bar ────────────────────────────────────────────────────────────── */
.input-area {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  align-items: center;
}

.input-area input[type="text"] {
  flex: 1;
  padding: 12px 18px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: 24px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  min-width: 0;
}

.input-area input[type="text"]::placeholder {
  color: var(--text-disabled);
}

.input-area input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Upload (+) button ────────────────────────────────────────────────────── */
#upload-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  flex-shrink: 0;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  border-radius: 50%;
  font-size: 1.5rem;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

#upload-btn:hover {
  background: var(--border);
  color: var(--text-primary);
  border-color: var(--accent);
}

#upload-btn:disabled {
  color: var(--text-disabled);
  border-color: var(--border-subtle);
  cursor: not-allowed;
}

/* ── Mic button ───────────────────────────────────────────────────────────── */
#mic-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  flex-shrink: 0;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition),
              color var(--transition), box-shadow var(--transition);
}

#mic-btn:hover {
  background: var(--border);
  color: var(--accent);
  border-color: var(--accent);
}

#mic-btn.recording {
  background: var(--accent);
  color: var(--text-primary);
  border-color: var(--accent);
  animation: mic-pulse 1.2s ease-in-out infinite;
}

#mic-btn:disabled {
  color: var(--text-disabled);
  border-color: var(--border-subtle);
  cursor: not-allowed;
  animation: none;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0   4px var(--accent-glow); }
  50%       { box-shadow: 0 0 0  10px var(--accent-glow); }
}

/* ── Input field interim (speech recognition in progress) ─────────────────── */
#user-input.interim {
  font-style: italic;
  color: var(--text-secondary);
}

/* ── Send button ──────────────────────────────────────────────────────────── */
#send-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  flex-shrink: 0;
  background: var(--accent);
  color: var(--text-primary);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), box-shadow var(--transition);
}

#send-btn:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 14px var(--accent-glow);
}

#send-btn:disabled {
  background: var(--border);
  cursor: not-allowed;
  box-shadow: none;
}

#send-btn.auto-send-pending {
  animation: send-pulse 0.7s ease-in-out infinite;
}

@keyframes send-pulse {
  0%, 100% { transform: scale(1);    box-shadow: 0 0 0  4px var(--accent-glow); }
  50%       { transform: scale(1.10); box-shadow: 0 0 0 12px var(--accent-glow); }
}

/* ── Image preview above input bar ───────────────────────────────────────── */
.image-preview-area {
  position: relative;
  display: inline-flex;
  align-items: flex-start;
  margin-bottom: 8px;
}

.image-preview-area img {
  height: 72px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  display: block;
}

#remove-img {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #C0392B;
  color: white;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background var(--transition);
}

#remove-img:hover { background: #96281B; }

/* ── Speaking indicator (SVG speaker on active Rasa bubble) ───────────────── */
.message.rasa.speaking {
  position: relative;
}

.message.rasa.speaking::after {
  content: '';
  position: absolute;
  bottom: -5px;
  right: -5px;
  width: 16px;
  height: 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%233B82F6' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='11 5 6 9 2 9 2 15 6 15 11 19 11 5'/%3E%3Cpath d='M15.54 8.46a5 5 0 0 1 0 7.07'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: contain;
  animation: speaker-pulse 1.5s ease-in-out infinite;
}

@keyframes speaker-pulse {
  0%, 100% { opacity: 1;   transform: scale(1);    }
  50%       { opacity: 0.4; transform: scale(0.85); }
}

/* ── Typing indicator (three bouncing dots) ───────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  min-width: 64px;
}

.typing-indicator span {
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: typing-bounce 1.2s ease-in-out infinite;
  opacity: 0.4;
}

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

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

/* ── Image thumbnail inside a child chat bubble ───────────────────────────── */
.chat-thumb {
  max-width: 180px;
  max-height: 130px;
  border-radius: 8px;
  display: block;
  margin-bottom: 4px;
}

/* ── Right: character panel ───────────────────────────────────────────────── */
.character-panel {
  flex: 0 0 440px;
  background: var(--bg-page);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;    /* anchor character to the bottom */
  overflow: hidden;
  position: relative;
  padding-bottom: 24px;         /* feet land here — shadow anchors to this same value */
}

/* Ambient layer: blue glow behind character + grounding shadow + floor plane.
   Kept in ::before (not ::after) so it renders under .character-wrap naturally,
   with no z-index changes needed. Character animations translate .character-wrap
   only, so the shadow stays anchored while the character floats above it. */
.character-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    /* blue character glow — centered on lower body */
    radial-gradient(circle at 50% 65%, rgba(59,130,246,0.10) 0%, transparent 45%),
    /* foot shadow — ellipse center matches padding-bottom exactly */
    radial-gradient(ellipse 180px 25px at 50% calc(100% - 24px), rgba(0,0,0,0.35) 0%, transparent 100%),
    /* floor plane — subtle lighter-blue gradient rising from the base */
    linear-gradient(to top, rgba(26,52,90,0.45) 0%, transparent 30%);
  pointer-events: none;
}

/* Crossfade wrapper — both imgs stacked */
.character-wrap {
  position: relative;
  width: 380px;
  height: 88vh;                 /* increased from 78vh for a larger character */
}

.character-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom center;
  transition: opacity 0.3s ease;
}

/* Back layer fades out, front layer is always opaque */
#rasa-back  { opacity: 0; }
#rasa-front { opacity: 1; }

/* ── Character animation ──────────────────────────────────────────────────── */

/* Single gentle float applied to all states — expression image changes per
   state but the motion is always the same calm up-and-down levitation.
   State classes (.talking, .celebrating, etc.) are still added by JS so the
   image crossfade and mouth animation logic continues to work unchanged. */
.character-wrap {
  animation: rasa-idle 4s ease-in-out infinite;
}

@keyframes rasa-idle {
  0%, 100% { transform: translateY(0);    }
  50%       { transform: translateY(-8px); }
}
