/* Chat Page Layout */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

/* Chat Header */
.chat-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
  z-index: 10;
}

.chat-header__back {
  font-size: var(--text-xl);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  transition: background var(--transition-fast);
  text-decoration: none;
  color: var(--color-text);
}

.chat-header__back:hover {
  background: var(--color-surface-alt);
}

.chat-header__info {
  flex: 1;
  min-width: 0;
}

.chat-header__title {
  font-size: var(--text-base);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header__subtitle {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* Scene Intro */
.scene-intro {
  background: var(--color-surface-alt);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-4);
  text-align: center;
  animation: slideDown var(--transition-slow) both;
}

.scene-intro__text {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
  max-width: 500px;
  margin: 0 auto;
  font-style: italic;
}

.scene-intro__npc {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
}

.scene-intro__npc-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-base);
  overflow: hidden;
  border: 2px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

/* Chat Messages Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  scroll-behavior: smooth;
}

/* Chat Bubble */
.chat-bubble {
  max-width: 85%;
  animation: slideUp 300ms both;
}

.chat-bubble--npc {
  align-self: flex-start;
}

.chat-bubble--user {
  align-self: flex-end;
}

/* NPC Character with Avatar */
.npc-character {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
}

.npc-character__avatar {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--color-surface-alt);
  border: 2px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.npc-avatar-svg {
  display: block;
}

.npc-character__speech {
  flex: 1;
  min-width: 0;
}

/* Speech bubble tail */
.speech-tail {
  position: absolute;
  left: -8px;
  bottom: 12px;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 10px solid var(--color-npc-bubble);
}

.chat-bubble__content {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-xl);
  font-size: var(--text-base);
  line-height: 1.5;
  position: relative;
}

.chat-bubble--npc .chat-bubble__content {
  background: var(--color-npc-bubble);
  border-bottom-left-radius: var(--radius-sm);
}

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

/* User Character with Avatar */
.user-character {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  justify-content: flex-end;
}

.user-character__speech {
  flex: 1;
  min-width: 0;
}

.user-character__avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--color-surface-alt);
  border: 2px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-avatar-svg {
  display: block;
}

.chat-bubble__score {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  color: white;
  animation: bounceIn 400ms both;
}

.chat-bubble__score--excellent { background: var(--color-success); }
.chat-bubble__score--good { background: var(--color-warning); }
.chat-bubble__score--failed { background: var(--color-error); }

/* Translation Toggle */
.chat-bubble__translation-toggle {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  cursor: pointer;
  user-select: none;
  border: none;
  background: none;
  padding: 0;
}

.chat-bubble__translation-toggle:hover {
  color: var(--color-text);
}

.chat-bubble__translation {
  display: none;
  margin-top: var(--space-1);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-style: italic;
  padding-top: var(--space-1);
  border-top: 1px solid var(--color-border);
}

.chat-bubble__translation.visible {
  display: block;
}

/* NPC Name */
.chat-bubble__sender {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}

/* Typing Indicator Bubble */
.typing-bubble {
  align-self: flex-start;
  max-width: 85%;
}

.typing-bubble .npc-character__avatar {
  animation: pulse 1.5s ease-in-out infinite;
}

.typing-bubble .chat-bubble__content {
  background: var(--color-npc-bubble);
  border-bottom-left-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-5);
}

/* Fill-in-the-blank slot */
.fill-blank-slot {
  display: inline-block;
  min-width: 60px;
  padding: 2px 8px;
  border-bottom: 2px solid var(--color-primary);
  color: var(--color-primary);
  font-weight: 600;
  border-radius: 4px;
  background: var(--color-primary-light, rgba(197, 48, 48, 0.08));
}

/* User Prompt Area */
.user-prompt {
  background: var(--color-surface-alt);
  padding: var(--space-3) var(--space-4);
  text-align: center;
  border-top: 1px solid var(--color-border);
  animation: slideUp 300ms both;
}

.user-prompt__instruction {
  font-size: var(--text-sm);
  color: var(--color-text);
  font-weight: 500;
}

.user-prompt__english {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

/* Feedback Area */
.feedback {
  padding: var(--space-2) var(--space-4);
  text-align: center;
  font-size: var(--text-sm);
  animation: fadeIn 200ms both;
  flex-shrink: 0;
}

.feedback--excellent {
  background: var(--color-success-light);
  color: var(--color-success);
}

.feedback--good {
  background: var(--color-success-light);
  color: var(--color-success);
}

.feedback--close {
  background: var(--color-warning-light);
  color: var(--color-warning);
}

.feedback--try_again {
  background: var(--color-error-light);
  color: var(--color-error);
}

.feedback--failed {
  background: var(--color-error-light);
  color: var(--color-error);
}

.feedback__suggestion {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  opacity: 0.9;
}

.feedback__attempts {
  display: block;
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  opacity: 0.7;
}

/* Cultural Note */
.cultural-note {
  margin: var(--space-2) var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--color-primary-light);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-primary);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--color-text);
  animation: slideUp 400ms both;
}

.cultural-note__header {
  font-weight: 600;
  margin-bottom: var(--space-1);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-primary);
}

/* Input Bar */
.input-bar {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-4);
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-shrink: 0;
}

.input-bar__field {
  flex: 1;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
  background: var(--color-surface-alt);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-full);
  transition: border-color var(--transition-fast);
}

.input-bar__field:focus {
  border-color: var(--color-primary);
  background: var(--color-surface);
}

.input-bar__field:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.input-bar__submit {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-lg);
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.input-bar__submit:hover:not(:disabled) {
  background: var(--color-primary-hover);
  transform: scale(1.05);
}

.input-bar__submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.input-bar__hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.input-bar__hint:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

/* Progress Bar (bottom) */
.chat-progress {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: var(--space-2) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.chat-progress__label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
}

.chat-progress .progress-bar {
  flex: 1;
}

/* Responsive */
@media (min-width: 640px) {
  .chat-messages {
    max-width: 640px;
    margin: 0 auto;
    width: 100%;
  }

  .chat-bubble {
    max-width: 75%;
  }
}

@media (max-width: 640px) {
  .input-bar {
    padding: var(--space-2) var(--space-3);
  }
  .input-bar__field {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
  }
  .input-bar__submit {
    width: 38px;
    height: 38px;
    font-size: var(--text-base);
  }
  .input-bar__hint {
    padding: var(--space-1) var(--space-2);
    font-size: var(--text-xs);
  }
  .chat-header {
    padding: var(--space-2) var(--space-3);
    gap: var(--space-2);
  }
  .chat-header__title {
    font-size: var(--text-sm);
  }
}

@media (max-width: 400px) {
  .npc-character__avatar {
    width: 36px;
    height: 36px;
  }

  .npc-character__avatar .npc-avatar-svg {
    width: 36px;
    height: 36px;
  }

  .user-character__avatar {
    width: 30px;
    height: 30px;
  }
}
