:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #1a1d29;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --border: #e5e7eb;
  --user-bubble: #4f46e5;
  --user-bubble-text: #ffffff;
  --ai-bubble: #ffffff;
  --ai-bubble-text: #1a1d29;
  --correction-bg: #fff7e6;
  --correction-border: #f5c542;
  --error-bg: #fef2f2;
  --error-text: #b91c1c;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --surface: #1b1e2a;
    --text: #edeef2;
    --text-muted: #9aa0ac;
    --primary: #818cf8;
    --primary-dark: #6366f1;
    --border: #2b2f3d;
    --user-bubble: #6366f1;
    --user-bubble-text: #ffffff;
    --ai-bubble: #232636;
    --ai-bubble-text: #edeef2;
    --correction-bg: #2c2610;
    --correction-border: #b58a1a;
    --error-bg: #2a1414;
    --error-text: #f38a8a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 800px;
  margin: 0 auto;
}

.brand-icon { font-size: 32px; }
.brand h1 { margin: 0; font-size: 20px; }
.tagline { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }

.view {
  flex: 1;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

.intro {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 16px;
}

.scenario-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.scenario-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  color: inherit;
  font: inherit;
}

.scenario-card:hover,
.scenario-card:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  border-color: var(--primary);
  outline: none;
}

.scenario-card .icon { font-size: 28px; display: block; margin-bottom: 8px; }
.scenario-card .title-zh { font-weight: 600; font-size: 16px; }
.scenario-card .title-en { font-size: 12px; color: var(--text-muted); margin: 2px 0 8px; }
.scenario-card .desc-zh { font-size: 13px; color: var(--text-muted); line-height: 1.4; }

/* Chat view */

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

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  color: var(--text);
}

.chat-title { display: flex; align-items: center; gap: 10px; flex: 1; }
.chat-icon { font-size: 24px; }
.chat-title-zh { font-weight: 600; font-size: 15px; }
.chat-title-en { font-size: 12px; color: var(--text-muted); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 300px;
}

.msg-row { display: flex; flex-direction: column; max-width: 80%; }
.msg-row.user { align-self: flex-end; align-items: flex-end; }
.msg-row.assistant { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.msg-row.user .bubble {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
}

.msg-row.assistant .bubble {
  background: var(--ai-bubble);
  color: var(--ai-bubble-text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.replay-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  margin-top: 4px;
  color: var(--text-muted);
  padding: 0;
}
.replay-btn:hover { color: var(--primary); }

.corrections {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 100%;
}

.correction-card {
  background: var(--correction-bg);
  border: 1px solid var(--correction-border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.5;
}

.correction-card .line {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.correction-card .original { text-decoration: line-through; color: var(--text-muted); }
.correction-card .arrow { color: var(--text-muted); }
.correction-card .corrected { font-weight: 600; color: var(--text); }
.correction-card .explanation { margin-top: 4px; color: var(--text-muted); }

.thinking-indicator {
  font-size: 13px;
  color: var(--text-muted);
  padding: 4px 0;
}

.error-banner {
  background: var(--error-bg);
  color: var(--error-text);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 8px;
}

.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.mic-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.15s ease;
}

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

.mic-btn.listening {
  background: #ef4444;
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  70% { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.mic-btn:disabled { opacity: 0.4; cursor: not-allowed; animation: none; }

#text-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
}

#text-input:focus { outline: 2px solid var(--primary); }

.send-btn {
  padding: 10px 18px;
  border-radius: 22px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
}

.send-btn:hover { background: var(--primary-dark); }
.send-btn:disabled, .mic-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.mic-status {
  font-size: 13px;
  color: var(--text-muted);
  padding-top: 6px;
  min-height: 18px;
}

@media (max-width: 480px) {
  .view { padding: 14px; }
  .scenario-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
