*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6750A4;
  --primary-light: #EADDFF;
  --text: #1C1B1F;
  --text-muted: #666;
  --border: #e0e0e0;
  --bg: #FFFBFE;
  --white: #ffffff;
  --correct: #155724;
  --correct-bg: #d4edda;
  --near-miss: #856404;
  --near-miss-bg: #fff3cd;
  --incorrect: #721c24;
  --incorrect-bg: #f8d7da;
  --teacher-bg: #FFD8E4;
  --teacher-border: #7D5260;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Page system ─────────────────────────────────────────────────────────── */

.page { display: none; min-height: 100vh; }
.page.active { display: flex; flex-direction: column; }

/* ── Quiz page ───────────────────────────────────────────────────────────── */

.page-quiz {
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.quiz-container {
  width: 100%;
  max-width: 480px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark {
  width: 40px;
  height: 40px;
  background: var(--primary);
  color: var(--white);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
}

.logo-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.tagline {
  color: var(--text-muted);
  font-size: 15px;
  margin-top: -8px;
}

.quiz-group { display: flex; flex-direction: column; gap: 10px; }

.quiz-group label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.pill-group { display: flex; flex-wrap: wrap; gap: 8px; }

.pill {
  padding: 8px 16px;
  border: 2px solid var(--border);
  border-radius: 20px;
  background: var(--white);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}

.pill:hover { border-color: var(--primary); color: var(--primary); }

.pill.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--white);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary:not(:disabled):hover { opacity: 0.9; }

.quiz-note {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: -8px;
}

/* ── Conversation page ───────────────────────────────────────────────────── */

.page-conversation { background: var(--bg); }

.conv-header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
}

.word-chips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }

.chip {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  background: #eee;
  color: var(--text-muted);
  transition: all 0.2s;
}

.chip.pending   { background: #eee; color: var(--text-muted); }
.chip.correct   { background: var(--correct-bg); color: var(--correct); }
.chip.nearMiss  { background: var(--near-miss-bg); color: var(--near-miss); }
.chip.incorrect { background: var(--incorrect-bg); color: var(--incorrect); }

.turn-counter {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.scenario-intro {
  background: var(--primary-light);
  border-bottom: 1px solid #D0BEF8;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.scenario-roles {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.role-badge {
  padding: 3px 10px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 12px;
}

.user-role  { background: var(--primary); color: var(--white); }
.ai-role    { background: var(--white); color: var(--primary); border: 1px solid var(--primary); }
.role-divider { color: var(--text-muted); }

.scenario-intro h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.scenario-intro p {
  font-size: 14px;
  color: var(--text-muted);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.bubble {
  max-width: 78%;
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
}

.bubble-user {
  align-self: flex-end;
  background: #EADDFF;
  color: #21005D;
  border-radius: 18px 18px 4px 18px;
}

.bubble-assistant {
  align-self: flex-start;
  background: #E6E0E9;
  color: var(--text);
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.bubble-teacher {
  align-self: flex-start;
  background: var(--teacher-bg);
  border: 1px solid var(--teacher-border);
  color: #31111D;
  border-radius: 18px 18px 18px 4px;
  font-size: 13px;
  font-style: italic;
  max-width: 85%;
}

.bubble-streaming { opacity: 0.85; }

.chat-input-area {
  background: var(--white);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  text-align: right;
  padding: 0;
  text-decoration: underline;
}

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

.input-row { display: flex; gap: 8px; }

#chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 22px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}

#chat-input:focus { border-color: var(--primary); }

.btn-send {
  padding: 10px 20px;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: 22px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-send:not(:disabled):hover { opacity: 0.9; }

.conversation-end-area {
  background: var(--white);
  border-top: 1px solid var(--border);
  padding: 20px 16px;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.end-message { color: var(--text-muted); font-size: 14px; text-align: center; }

/* ── Report page ─────────────────────────────────────────────────────────── */

.page-report { background: var(--bg); }

.report-container {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.report-header { text-align: center; }
.report-header h1 { font-size: 24px; font-weight: 700; }
.report-subtitle { font-size: 14px; color: var(--text-muted); margin-top: 4px; }

.report-section {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.report-section h2 {
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.communication-summary { font-size: 15px; line-height: 1.7; color: var(--text); }

.vocab-cards { display: flex; flex-direction: column; gap: 8px; }

.vocab-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
}

.vocab-card.correct   { background: var(--correct-bg); }
.vocab-card.incorrect { background: var(--incorrect-bg); }
.vocab-card.unused    { background: #f0f0f0; }

.vocab-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.vocab-word { font-weight: 600; flex: 1; }
.vocab-status { font-size: 12px; color: var(--text-muted); text-transform: capitalize; }

.usage-list { display: flex; flex-direction: column; gap: 10px; }

.usage-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.usage-phrase {
  font-size: 14px;
  font-style: italic;
  color: var(--text);
}

.usage-note { font-size: 13px; color: var(--text-muted); }

.next-steps {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.next-steps li { font-size: 14px; line-height: 1.5; }

.metrics { display: flex; flex-direction: column; gap: 12px; }

.metric-row { display: flex; flex-direction: column; gap: 4px; }

.metric-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.metric-name { font-size: 13px; font-weight: 600; color: var(--text); }
.metric-value { font-size: 12px; color: var(--text-muted); }

.metric-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.metric-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--primary);
  transition: width 0.6s ease;
}

.level-high .metric-fill { width: 85%; }
.level-mid  .metric-fill { width: 55%; }
.level-low  .metric-fill { width: 25%; }

.level-high .metric-fill { background: #22a06b; }
.level-mid  .metric-fill { background: var(--primary); }
.level-low  .metric-fill { background: #e5793a; }

.report-cta {
  background: var(--primary);
  border-radius: var(--radius);
  padding: 28px 24px;
  color: var(--white);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.report-cta h2 { font-size: 20px; font-weight: 700; }
.report-cta p  { font-size: 14px; opacity: 0.85; }

.store-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 4px;
}

.store-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  background: rgba(255,255,255,0.15);
  border: 1.5px solid rgba(255,255,255,0.5);
  border-radius: 10px;
  color: var(--white);
  text-decoration: none;
  transition: background 0.15s;
  min-width: 140px;
}

.store-btn:hover { background: rgba(255,255,255,0.25); }

.store-icon { font-size: 22px; }

.store-label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.1;
}

.store-sub { font-size: 10px; font-weight: 400; opacity: 0.8; }

.btn-outline {
  padding: 13px;
  background: var(--white);
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: all 0.15s;
}

.btn-outline:hover { background: var(--primary-light); }

/* ── Error toast ─────────────────────────────────────────────────────────── */

.error-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #c0392b;
  color: var(--white);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  max-width: 320px;
  text-align: center;
  display: none;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.error-toast.visible { display: block; }

/* ── Loading indicator ───────────────────────────────────────────────────── */

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: #E6E0E9;
  border-radius: 18px 18px 18px 4px;
  align-self: flex-start;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.2s infinite;
}

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

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

/* ── Mobile tweaks ───────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  .quiz-container { padding: 24px 20px; }
  .bubble { max-width: 88%; }
  .store-buttons { flex-direction: column; align-items: center; }
}
