/* ===== Chat ===== */
.chat-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 768px;
  margin: 0 auto;
  width: 100%;
}

.mode-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.mode-tab {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.813rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.mode-tab:hover {
  color: var(--text);
}

.mode-tab.active {
  background: rgba(139, 92, 246, 0.2);
  color: var(--accent);
  border-color: rgba(139, 92, 246, 0.4);
}

.chat-body {
  flex: 1;
  padding: 24px 16px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

#aiSlot,
#userSlot {
  width: 100%;
  max-width: none;
  position: static;
  display: flex;
}

#aiSlot {
  align-items: flex-start;
  min-height: min(34vh, 260px);
}

#userSlot {
  justify-content: flex-end;
  align-items: flex-end;
  min-height: min(8vh, 64px);
  margin-top: clamp(24px, 8vh, 72px);
  padding-top: 8px;
  padding-bottom: 12px;
  border-top: 1px solid var(--border);
}

.chat-body:empty::after {
  content: "";
  flex: 1;
}

.message {
  display: flex;
  width: fit-content;
  max-width: min(85%, 520px);
  animation: msgIn 0.3s ease-out;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
}

.message.noesis {
  align-self: flex-start;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.6;
  font-size: 0.938rem;
  word-break: break-word;
  white-space: pre-wrap;
}

.message.user .message-bubble {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.4), rgba(6, 182, 212, 0.3));
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.message.noesis .message-bubble {
  background: var(--bg-card);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
}

.chat-input-wrap {
  margin-bottom: 22px;
  padding: 12px 16px 16px;
  background: var(--glass);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
}

.chat-input {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  max-width: 640px;
  margin: 0 auto;
}

.chat-input textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 22px;
  color: var(--text);
  font-size: 0.938rem;
  font-family: inherit;
  resize: none;
  transition: border-color 0.2s;
}

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

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

.chat-input textarea:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.send-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 1.125rem;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.start-btn-wrap {
  display: flex;
  justify-content: center;
  padding: 16px;
}

.start-btn {
  padding: 10px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 22px;
  color: var(--text-muted);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
}

.start-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.start-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ===== RPG Mode ===== */

.rpg-message-area {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100%;
  padding: 2rem 1.5rem;
  text-align: center;
}

.rpg-message-area .message {
  max-width: 520px;
  width: 100%;
  animation: none;
}

.rpg-message-area .message.noesis {
  align-self: center;
}

.rpg-message-area .message.user {
  align-self: center;
}

.rpg-question .message-bubble {
  font-size: 1.05rem;
  line-height: 1.8;
  text-align: center;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 20px 24px;
}

.rpg-thinking {
  color: var(--text-muted);
  font-size: 0.875rem;
  animation: rpgPulse 1.2s ease-in-out infinite;
}

@keyframes rpgPulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.8; }
}

.rpg-fade-in {
  animation: rpgFadeIn 0.5s ease-out forwards;
}

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

.rpg-cursor::after {
  content: "\25CD";
  margin-left: 2px;
  animation: rpgBlink 0.6s step-end infinite;
  color: var(--accent);
}

@keyframes rpgBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
@media (max-width: 640px) {
  .chat-screen {
    max-width: none;
  }
  .mode-tabs {
    padding: 8px 10px;
    gap: 8px;
  }
  .mode-tab {
    padding: 10px 12px;
    font-size: 0.75rem;
  }
  .chat-body {
    padding: 16px 12px 12px;
    gap: 16px;
  }
  .chat-body.input-active {
    justify-content: flex-end;
    padding-top: 8px;
    gap: 6px;
  }
  .chat-body.input-active #aiSlot {
    min-height: 0;
  }
  .chat-body.input-active #userSlot {
    min-height: 0;
    margin-top: 0;
    padding-top: 4px;
    padding-bottom: 2px;
  }
  #aiSlot {
    min-height: min(28vh, 180px);
  }
  #userSlot {
    min-height: min(6vh, 44px);
    padding-top: 6px;
    padding-bottom: 8px;
    margin-top: clamp(18px, 6vh, 40px);
  }
  .message {
    max-width: 100%;
  }
  .message-bubble {
    padding: 12px 14px;
    font-size: 0.9rem;
    line-height: 1.7;
  }
  .rpg-question .message-bubble {
    padding: 12px 4px;
    font-size: 0.98rem;
    line-height: 1.75;
  }
  .chat-input-wrap {
    margin-bottom: 14px;
    padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  }
  .chat-input {
    gap: 8px;
    align-items: stretch;
  }
  .chat-input textarea {
    min-height: 48px;
    padding: 12px 14px;
    border-radius: 18px;
    font-size: 16px;
  }
  .send-btn {
    width: 48px;
    height: 48px;
  }
  .start-btn-wrap {
    padding: 10px 12px 4px;
  }
  .start-btn {
    width: 100%;
    min-height: 44px;
    padding: 12px 16px;
  }
}

