/* ── AI Chat page layout ─────────────────────────────────────── */
.aichat-wrap {
  max-width: 760px;
  margin: 24px auto 40px;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Mode selection screen ───────────────────────────────────── */
.aichat-setup {
  background: #fff;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.aichat-setup h2 {
  font-size: 22px;
  color: var(--dark-text);
  margin-bottom: 8px;
}

.aichat-setup .setup-sub {
  color: var(--light-text);
  font-size: 14px;
  margin-bottom: 24px;
}

/* Language picker */
.lang-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.lang-btn {
  padding: 8px 18px;
  border-radius: 20px;
  border: 2px solid var(--primary-color);
  background: #fff;
  color: var(--primary-color);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
}

.lang-btn.active,
.lang-btn:hover {
  background: var(--primary-color);
  color: #fff;
}

/* Mode cards */
.mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 24px;
}

@media (max-width: 500px) {
  .mode-cards { grid-template-columns: 1fr; }
}

.mode-card {
  border: 2px solid #e0e7ef;
  border-radius: 14px;
  padding: 20px 18px;
  cursor: pointer;
  transition: 0.2s;
  text-align: left;
  background: #fff;
}

.mode-card:hover {
  border-color: var(--primary-color);
  background: #f0f7ff;
}

.mode-card.selected {
  border-color: var(--primary-color);
  background: #e3f2fd;
}

.mode-card .mode-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.mode-card .mode-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--dark-text);
  margin-bottom: 4px;
}

.mode-card .mode-desc {
  font-size: 13px;
  color: var(--light-text);
}

/* General mode topic input */
.general-input-wrap {
  margin-bottom: 20px;
}

.general-input-wrap label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--dark-text);
  margin-bottom: 8px;
}

.general-input-wrap input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e0e7ef;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.general-input-wrap input:focus {
  border-color: var(--primary-color);
}

/* Fixed mode topic list */
.topics-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
  max-height: 260px;
  overflow-y: auto;
}

.topic-item {
  border: 2px solid #e0e7ef;
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: 0.2s;
  display: flex;
  align-items: center;
  gap: 14px;
}

.topic-item:hover { border-color: var(--primary-color); background: #f0f7ff; }
.topic-item.selected { border-color: var(--primary-color); background: #e3f2fd; }

.topic-item .topic-badge {
  background: var(--primary-color);
  color: #fff;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.topic-item .topic-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--dark-text);
}

.topic-item .topic-desc {
  font-size: 13px;
  color: var(--light-text);
}

.start-btn {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: none;
  background: var(--primary-color);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}

.start-btn:hover { background: var(--primary-dark); }
.start-btn:disabled { background: #b0bec5; cursor: not-allowed; }

/* ── Conversation screen ─────────────────────────────────────── */
.aichat-conversation {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.conv-header {
  background: #fff;
  border-radius: var(--border-radius) var(--border-radius) 0 0;
  box-shadow: var(--shadow);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #f0f2f5;
}

.conv-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.conv-topic-tag {
  background: #e3f2fd;
  color: var(--primary-color);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 600;
}

.conv-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--dark-text);
}

.end-btn {
  padding: 8px 16px;
  border-radius: 10px;
  border: 2px solid #ef5350;
  background: #fff;
  color: #ef5350;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s;
  white-space: nowrap;
}

.end-btn:hover { background: #ef5350; color: #fff; }

/* Messages area */
.conv-messages {
  background: #f7f9fc;
  padding: 20px 16px;
  min-height: 320px;
  max-height: 420px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.msg-row.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.msg-row.ai .msg-avatar { background: #e3f2fd; }
.msg-row.user .msg-avatar { background: #e8f5e9; }

.msg-bubble {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 16px;
  line-height: 1.6;
  position: relative;
}

.msg-row.ai .msg-bubble {
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  border-bottom-left-radius: 4px;
  color: var(--dark-text);
  font-family: var(--hanzi-font);
}

.msg-row.user .msg-bubble {
  background: var(--primary-color);
  color: #fff;
  border-bottom-right-radius: 4px;
  font-family: var(--hanzi-font);
}

/* Typing indicator */
.typing-dots {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 4px 0;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--primary-light);
  border-radius: 50%;
  animation: dotBounce 1.2s infinite;
}

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

@keyframes dotBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* Off-topic indicator */
.off-topic-badge {
  font-size: 12px;
  background: #fff3e0;
  color: #e65100;
  border-radius: 6px;
  padding: 2px 8px;
  margin-top: 6px;
  display: inline-block;
}

/* Voice input bar */
.conv-input-bar {
  background: #fff;
  border-radius: 0 0 var(--border-radius) var(--border-radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-top: 1px solid #f0f2f5;
}

.voice-row {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}

.mic-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: none;
  background: var(--primary-color);
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  transition: 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(25,118,210,0.35);
  user-select: none;
  -webkit-user-select: none;
}

.mic-btn:active,
.mic-btn.recording {
  background: #ef5350;
  box-shadow: 0 4px 20px rgba(239,83,80,0.45);
  transform: scale(1.07);
}

.mic-btn:disabled {
  background: #b0bec5;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

.mic-hint {
  font-size: 13px;
  color: var(--light-text);
  text-align: center;
}

.mic-hint.listening {
  color: #ef5350;
  font-weight: 600;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Text fallback input */
.text-fallback {
  display: flex;
  gap: 8px;
}

.text-fallback input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid #e0e7ef;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  font-family: var(--hanzi-font);
  transition: border-color 0.2s;
}

.text-fallback input:focus { border-color: var(--primary-color); }

.text-send-btn {
  padding: 10px 18px;
  border-radius: 10px;
  border: none;
  background: var(--primary-color);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}

.text-send-btn:hover { background: var(--primary-dark); }
.text-send-btn:disabled { background: #b0bec5; cursor: not-allowed; }

/* Speech transcript preview */
.transcript-preview {
  background: #f0f7ff;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 15px;
  color: var(--dark-text);
  font-family: var(--hanzi-font);
  min-height: 36px;
  border: 1px dashed var(--primary-light);
}

.transcript-preview.empty {
  color: var(--light-text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-style: italic;
}

/* ── Summary screen ──────────────────────────────────────────── */
.aichat-summary {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.summary-header {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: #fff;
  border-radius: var(--border-radius);
  padding: 28px 24px;
  text-align: center;
}

.summary-header h2 {
  font-size: 22px;
  margin-bottom: 8px;
}

.summary-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.stat-box {
  text-align: center;
}

.stat-box .stat-num {
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
}

.stat-box .stat-label {
  font-size: 13px;
  opacity: 0.85;
  margin-top: 4px;
}

.summary-card {
  background: #fff;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.summary-card h3 {
  font-size: 16px;
  color: var(--dark-text);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Strengths */
.strengths-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.strengths-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 14px;
  color: var(--dark-text);
}

.strengths-list li::before {
  content: '✓';
  color: var(--correct-color);
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

/* Error cards */
.error-card {
  border: 2px solid #ffebee;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  background: #fff;
}

.error-card:last-child { margin-bottom: 0; }

.error-original {
  font-family: var(--hanzi-font);
  font-size: 18px;
  color: #c62828;
  text-decoration: line-through;
  margin-bottom: 6px;
}

.error-corrected {
  font-family: var(--hanzi-font);
  font-size: 18px;
  color: var(--correct-color);
  font-weight: 700;
  margin-bottom: 10px;
}

.error-arrow {
  color: var(--light-text);
  font-size: 14px;
  margin: 0 6px;
}

.error-rule-tag {
  display: inline-block;
  background: #fff3e0;
  color: #e65100;
  border-radius: 6px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}

.error-explanation {
  font-size: 14px;
  color: var(--light-text);
  line-height: 1.6;
  margin-bottom: 8px;
}

.error-example {
  background: #f0f7ff;
  border-radius: 8px;
  padding: 8px 12px;
  font-family: var(--hanzi-font);
  font-size: 15px;
  color: var(--primary-dark);
}

/* Tip box */
.tip-box {
  background: linear-gradient(135deg, #e3f2fd, #f3e5f5);
  border-radius: 12px;
  padding: 16px;
  font-size: 14px;
  color: var(--dark-text);
  line-height: 1.6;
}

/* Overall feedback */
.overall-feedback {
  font-size: 15px;
  color: var(--dark-text);
  line-height: 1.7;
}

/* Summary action buttons */
.summary-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.summary-actions button {
  flex: 1;
  min-width: 130px;
  padding: 13px;
  border-radius: 12px;
  border: 2px solid var(--primary-color);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s;
}

.btn-primary-fill {
  background: var(--primary-color);
  color: #fff;
}

.btn-primary-fill:hover { background: var(--primary-dark); }

.btn-outline {
  background: #fff;
  color: var(--primary-color);
}

.btn-outline:hover { background: #e3f2fd; }

/* Loading overlay */
.summary-loading {
  text-align: center;
  padding: 48px 24px;
  background: #fff;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
}

.summary-loading .loading-spinner {
  width: 44px;
  height: 44px;
  border: 4px solid #e3f2fd;
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

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

.summary-loading p {
  color: var(--light-text);
  font-size: 15px;
}

/* Screen visibility helpers */
.screen { display: none; }
.screen.active { display: block; }
.aichat-conversation.active { display: flex; }
.aichat-summary.active { display: flex; }
