/* ─── Design tokens ───────────────────────────────────────────────────── */
:root {
  --bg:         #1a1a2e;
  --surface:    #16213e;
  --surface-2:  #0f3460;
  --accent:     #e94560;
  --accent-dim: #c73652;
  --text:       #e8e8f0;
  --text-muted: #8888aa;
  --border:     #2a2a4a;
  --bubble-ai:  #1e2a45;
  --bubble-user:#2d1f35;
  --radius:     14px;
  --radius-sm:  8px;
  --font:       -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --shadow:     0 4px 20px rgba(0,0,0,0.4);
}

/* ─── Reset / Base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px; /* keep ≥16px so iOS doesn't auto-zoom on input focus */
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  overflow: hidden;
  overscroll-behavior: none; /* prevent pull-to-refresh on mobile */
}

/* Larger tap targets on touch devices */
@media (hover: none) and (pointer: coarse) {
  .icon-btn, .mode-pill, .tab-btn { min-height: 44px; }
  button, input, select, textarea { font-size: 16px; }
}

/* ─── Screen layout ──────────────────────────────────────────────────── */
.screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.hidden { display: none !important; }

/* ─── Login card ─────────────────────────────────────────────────────── */
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.logo-emoji { font-size: 2.5rem; display: block; margin-bottom: 0.5rem; }

.logo-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.logo-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ─── Placement card ─────────────────────────────────────────────────── */
.placement-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.75rem;
  box-shadow: var(--shadow);
}

.placement-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.placement-header h2 { font-size: 1.4rem; margin: 0.5rem 0 0.25rem; }
.placement-header p { color: var(--text-muted); font-size: 0.9rem; }

.placement-form { display: flex; flex-direction: column; gap: 0.75rem; }

.radio-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.radio-card:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--bg));
}

.radio-card input[type="radio"] { accent-color: var(--accent); width: 18px; height: 18px; flex-shrink: 0; }

.radio-card__body { display: flex; flex-direction: column; }
.radio-card__body strong { font-size: 0.95rem; }
.radio-card__body span { font-size: 0.8rem; color: var(--text-muted); }

/* ─── Forms ──────────────────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 1rem; }

.form-group { display: flex; flex-direction: column; gap: 0.35rem; }

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  padding: 0.65rem 0.9rem;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

.form-group input:focus { border-color: var(--accent); }
.form-group input::placeholder { color: var(--text-muted); }

.form-error {
  font-size: 0.85rem;
  color: var(--accent);
  min-height: 1.2em;
}

/* ─── Buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.65rem 1.2rem;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
}

.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--accent-dim); }
.btn--primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn--ghost:hover { border-color: var(--text-muted); color: var(--text); }

.btn--full { width: 100%; }

.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  padding: 0.4rem;
  min-width: 44px;
  min-height: 36px;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: background 0.15s;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn--ghost { opacity: 0.5; }
.icon-btn--ghost:hover { opacity: 1; }

/* ─── App shell ──────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  /* Respect iPhone notch / Dynamic Island */
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background: var(--bg);
}

/* ─── App header ─────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
  gap: 0.5rem;
  min-height: 52px;
}

@media (max-width: 480px) {
  .app-header__logo { display: none; } /* free up width for mode pills */
  .app-header { padding: 0.5rem; }
}

.app-header__logo {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.3px;
}

.app-header__actions { display: flex; gap: 0.25rem; align-items: center; }

/* ─── 3-mode pill selector ──────────────────────────────────────────── */
.mode-pills {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: transparent;
  border: none;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  font-family: inherit;
}

.mode-pill:hover { color: var(--text); }
.mode-pill--active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.mode-pill--active:hover { color: #fff; }

.mode-pill__icon { font-size: 0.95rem; line-height: 1; }
.mode-pill__label { line-height: 1; }

@media (max-width: 480px) {
  .mode-pill__label { display: none; } /* icons-only on small screens */
  .mode-pill { padding: 0.4rem 0.55rem; }
}

/* ─── History panel ─────────────────────────────────────────────────── */
.history-panel {
  width: 320px;
  max-height: calc(100dvh - 4.5rem);
  overflow-y: auto;
}

@media (max-width: 480px) {
  .history-panel { width: calc(100vw - 1rem); }
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 1.5rem 0.5rem;
  line-height: 1.6;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}

.history-item:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 5%, var(--bg)); }

.history-item__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  gap: 0.5rem;
}

.history-item__date { font-weight: 500; }

.history-item__tag {
  background: color-mix(in srgb, var(--accent) 15%, var(--surface));
  color: var(--accent);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 600;
}

.history-item__preview {
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-item__count { font-size: 0.7rem; color: var(--text-muted); }

/* ─── Medical banner extras ─────────────────────────────────────────── */
.medical-banner__note {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-style: italic;
}

/* ─── Toast ─────────────────────────────────────────────────────────── */
.toast-host {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 2rem);
}

.toast {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.6rem 1.1rem;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: auto;
}

.toast--show { opacity: 1; transform: translateY(0); }
.toast--error { border-color: #d9534f; color: #ff8a85; }
.toast--success { border-color: #5cb85c; color: #98e1a0; }

/* ─── Focus card (Today's Focus, shown on empty chat) ───────────────── */
.focus-card {
  background: linear-gradient(135deg, var(--surface) 0%, color-mix(in srgb, var(--accent) 8%, var(--surface)) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.1rem;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  animation: fadeUp 0.3s ease;
}

.focus-card__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.focus-card__streak {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.focus-card__streak-emoji { font-size: 1.5rem; }
.focus-card__streak-label { font-weight: 600; font-size: 0.95rem; }

.focus-card__cta {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
.focus-card__cta:hover { filter: brightness(1.1); transform: translateY(-1px); }

.focus-card__focus {
  padding: 0.65rem 0.85rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}

.focus-card__focus-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.2rem;
}

.focus-card__focus-text { font-size: 0.92rem; line-height: 1.4; color: var(--text); }

.focus-card__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.focus-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  font-size: 0.78rem;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.focus-chip:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg));
  transform: translateY(-1px);
}

.focus-chip:active { transform: translateY(0); }

/* ─── Vocab tab ─────────────────────────────────────────────────────── */
.vocab-panel { max-width: 720px; margin: 0 auto; }

.vocab-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.vocab-header h2 { font-size: 1.4rem; margin-bottom: 0.25rem; }
.vocab-stats { font-size: 0.85rem; color: var(--text-muted); }

.btn--small { padding: 0.4rem 0.85rem; font-size: 0.85rem; }

.vocab-cta { margin-bottom: 1rem; }
.vocab-review-btn { width: 100%; padding: 0.85rem; font-size: 1rem; }

.vocab-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.vocab-list { display: flex; flex-direction: column; gap: 0.5rem; }

.vocab-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  transition: border-color 0.15s;
}
.vocab-row:hover { border-color: var(--accent); }
.vocab-row__main { flex: 1; min-width: 0; }
.vocab-row__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
  flex-wrap: wrap;
}
.vocab-row__spanish { font-weight: 700; font-size: 1rem; }
.vocab-row__cat {
  font-size: 0.65rem;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-weight: 700;
}
.vocab-row__english { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 0.25rem; }
.vocab-row__example {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 0.3rem;
  line-height: 1.4;
}
.vocab-row__meta {
  display: flex;
  gap: 0.4rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}
.vocab-row__actions { display: flex; gap: 0.25rem; flex-shrink: 0; }

/* ─── Flashcard review ──────────────────────────────────────────────── */
.flashcard-session {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 1rem;
}

.flashcard-progress {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 500;
}

.flashcard {
  flex: 1;
  perspective: 1200px;
  display: flex;
  flex-direction: column;
}

.flashcard__inner {
  flex: 1;
  position: relative;
  transition: transform 0.55s cubic-bezier(.22,.86,.32,1.05);
  transform-style: preserve-3d;
}

.flashcard--flipped .flashcard__inner { transform: rotateY(180deg); }

.flashcard__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1rem;
}

.flashcard__face--back { transform: rotateY(180deg); }

.flashcard__cat {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  color: #fff;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}

.flashcard__spanish {
  font-size: 2rem;
  font-weight: 700;
  margin: 0.5rem 0;
  line-height: 1.2;
}

.flashcard__hint { padding: 0.4rem 0.85rem; font-size: 0.85rem; }

.flashcard__english {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.flashcard__example {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.5;
  max-width: 340px;
}

.flashcard__buttons {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  margin-top: 1rem;
}

.flashcard__btn { flex: 1; padding: 0.85rem 0; font-size: 0.95rem; font-weight: 600; }
.flashcard__btn--forgot { background: #d9534f; color: #fff; }
.flashcard__btn--hard   { background: #f0ad4e; color: #1a1a2e; }
.flashcard__btn--easy   { background: #5cb85c; color: #fff; }
.flashcard__btn:hover { filter: brightness(1.1); }

.vocab-done {
  text-align: center;
  padding: 3rem 1rem;
}
.vocab-done__emoji { font-size: 4rem; margin-bottom: 1rem; }
.vocab-done h2 { margin-bottom: 0.5rem; }
.vocab-done p { color: var(--text-muted); margin-bottom: 1.5rem; }

/* Pronunciation result on flashcard back */
.flashcard__hint--recording {
  background: var(--accent) !important;
  color: #fff !important;
  border-color: var(--accent) !important;
}

.flashcard__pron-result {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
  font-size: 0.85rem;
  line-height: 1.5;
}

.pron-score { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.4rem; }
.pron-feedback { color: var(--text); margin-bottom: 0.4rem; }
.pron-heard { font-size: 0.78rem; color: var(--text-muted); font-style: italic; }

/* ─── Settings panel ─────────────────────────────────────────────────── */
.settings-panel {
  position: absolute;
  top: 3rem;
  right: 0.5rem;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  width: 260px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.settings-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.setting-row label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.setting-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  outline: none;
  cursor: pointer;
}

.setting-select:focus { border-color: var(--accent); }

/* ─── Tab bar (top on desktop, bottom on mobile for thumb reach) ────── */
.tab-bar {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

@media (max-width: 600px) {
  .app-shell { flex-direction: column; }
  .tab-bar {
    order: 99;
    border-bottom: none;
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tab-btn { padding: 0.65rem 0.25rem 0.5rem; }
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.55rem 0.25rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 500;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover:not(:disabled) { color: var(--text); }
.tab-btn--active { color: var(--accent) !important; border-bottom-color: var(--accent); }
.tab-btn--soon:disabled { opacity: 0.35; cursor: not-allowed; }

.tab-icon { font-size: 1.1rem; line-height: 1; }
.tab-label { line-height: 1; }

/* ─── Tab content ────────────────────────────────────────────────────── */
.tab-content { flex: 1; overflow: hidden; position: relative; }

.tab-panel { height: 100%; display: flex; flex-direction: column; }
.tab-panel.hidden { display: none; }

.coming-soon {
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 1rem;
}

/* ─── Chat tab ───────────────────────────────────────────────────────── */
#tab-chat { height: 100%; }

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.75rem;
  scroll-behavior: smooth;
  /* custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.chat-scroll::-webkit-scrollbar { width: 4px; }
.chat-scroll::-webkit-scrollbar-track { background: transparent; }
.chat-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-width: 720px;
  margin: 0 auto;
}

/* ─── Messages ───────────────────────────────────────────────────────── */
.message {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-width: 82%;
  animation: fadeUp 0.2s ease;
}

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

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

.message__text {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.97rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

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

.message--user .message__text {
  background: var(--bubble-user);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  border-bottom-right-radius: 4px;
  color: var(--text);
}

/* Streaming pulse */
.message--streaming .message__text::after {
  content: '▋';
  animation: blink 0.8s step-end infinite;
  color: var(--accent);
  margin-left: 2px;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Typing indicator (three dots) shown while waiting for first token */
.typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.message--streaming .message__text:has(.typing-dots)::after { content: none; } /* hide cursor while dots show */

/* Inline toggle buttons */
.message__toggle {
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.72rem;
  padding: 0.15rem 0.4rem;
  transition: background 0.15s, color 0.15s;
  margin-left: 0.25rem;
}

.message--user .message__toggle { align-self: flex-end; margin-left: 0; margin-right: 0.25rem; }

.message__toggle:hover,
.message__toggle.active { background: var(--border); color: var(--text); }

/* Corrections block */
.message__corrections {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--border));
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.5;
  padding: 0.6rem 0.85rem;
  white-space: pre-wrap;
}

/* Welcome message */
.welcome-message { max-width: 100%; }
.welcome-message .message__text {
  background: linear-gradient(135deg, var(--bubble-ai), color-mix(in srgb, var(--accent) 6%, var(--bubble-ai)));
}

/* ─── Chat footer ────────────────────────────────────────────────────── */
.chat-footer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* On mobile, tab bar is at the bottom — chat footer doesn't need safe-area */
@media (min-width: 601px) {
  .chat-footer { padding-bottom: max(0.65rem, env(safe-area-inset-bottom)); }
}

.chat-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.97rem;
  line-height: 1.45;
  max-height: 120px;
  min-height: 42px;
  outline: none;
  padding: 0.55rem 0.9rem;
  resize: none;
  transition: border-color 0.15s;
}

.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-muted); }
.chat-input:disabled { opacity: 0.5; }

.chat-send {
  padding: 0.55rem 1rem;
  font-size: 1.1rem;
  border-radius: var(--radius);
  flex-shrink: 0;
  min-width: 44px;
}

.chat-mic {
  font-size: 1.25rem;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  position: relative;
}

.chat-mic:hover { background: var(--border); }
.chat-mic:active { transform: scale(0.95); }

/* Recording state — pulsing red */
.chat-mic[data-state="recording"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  animation: micPulse 1.4s ease-in-out infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); }
  50%      { box-shadow: 0 0 0 10px color-mix(in srgb, var(--accent) 0%,  transparent); }
}

/* Requesting / processing — spinning hourglass */
.chat-mic[data-state="requesting"],
.chat-mic[data-state="processing"] {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--text);
  cursor: wait;
}

/* Settings: checkbox + range */
.setting-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}

.setting-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.setting-range {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Floating "Stop Lupita" button — appears while she's speaking */
.tts-stop {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  animation: ttsStopAppear 0.2s ease;
  transition: background 0.15s, transform 0.15s;
}

.tts-stop:hover { background: var(--accent); color: #fff; transform: translateX(-50%) translateY(-2px); }
.tts-stop:active { transform: translateX(-50%) scale(0.96); }

@keyframes ttsStopAppear {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── Conversation Mode ──────────────────────────────────────────── */
.conv-start {
  position: absolute;
  bottom: 80px;
  right: 1rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: transform 0.15s, box-shadow 0.15s;
}

.conv-start:hover { transform: translateY(-2px); box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 50%, transparent); }
.conv-start:active { transform: translateY(0); }

.conv-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: convFadeIn 0.25s ease;
}

@keyframes convFadeIn { from { opacity: 0 } to { opacity: 1 } }

.conv-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  padding-bottom: max(2.5rem, calc(1.5rem + env(safe-area-inset-bottom)));
  text-align: center;
  box-shadow: var(--shadow);
}

.conv-pulse {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 1.5rem;
}

.conv-pulse__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.25;
  animation: convPulse 2s ease-out infinite;
}
.conv-pulse__ring--delayed { animation-delay: 1s; }

@keyframes convPulse {
  0%   { transform: scale(0.8); opacity: 0.5; }
  100% { transform: scale(1.6); opacity: 0; }
}

.conv-pulse__core {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: #fff;
  z-index: 2;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 40%, transparent);
}

.conv-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.conv-status {
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 0.75rem;
  min-height: 1.5em;
  font-weight: 500;
}

.conv-status[data-kind="thinking"] { color: var(--text-muted); }
.conv-status[data-kind="speaking"] { color: var(--accent); }

.conv-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

.conv-card .btn--ghost { width: 100%; }

@media (max-width: 480px) {
  .conv-card { padding: 2rem 1.25rem; }
  .conv-pulse { width: 100px; height: 100px; }
  .conv-pulse__core { width: 64px; height: 64px; font-size: 1.6rem; }
}

/* ─── Scenarios picker ───────────────────────────────────────────────── */
.scenarios-panel {
  height: 100%;
  overflow-y: auto;
  padding: 1.25rem 1rem 2rem;
}

.scenarios-header {
  max-width: 720px;
  margin: 0 auto 1.5rem;
  padding: 0 0.5rem;
}
.scenarios-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}
.scenarios-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.scenarios-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.85rem;
  max-width: 720px;
  margin: 0 auto;
}

.scenario-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1rem;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s;
  position: relative;
}

.scenario-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
}
.scenario-card:active { transform: translateY(0); }

.scenario-card__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.scenario-card__emoji { font-size: 1.8rem; line-height: 1; }

.scenario-card__level {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  color: #fff;
}

.scenario-card__title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
}

.scenario-card__sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.scenario-card__meta {
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  gap: 0.75rem;
}

/* ─── Active scenario banner (above chat) ───────────────────────────── */
.scenario-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.5rem;
}

.scenario-banner__main {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.scenario-banner__emoji { font-size: 1.6rem; flex-shrink: 0; }

.scenario-banner__title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.15rem;
}

.scenario-banner__goal {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.scenario-banner__exit {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.scenario-banner__exit:hover { background: var(--border); color: var(--text); }

/* ─── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .login-card, .placement-card { padding: 2rem 1.25rem; }
  .message { max-width: 90%; }
  .settings-panel { width: calc(100vw - 1rem); right: 0; }
}

@media (prefers-color-scheme: light) {
  /* Light mode overrides — user can force dark in settings (Phase 10) */
  :root {
    --bg:         #f5f5f8;
    --surface:    #ffffff;
    --surface-2:  #e8e8f0;
    --text:       #1a1a2e;
    --text-muted: #666688;
    --border:     #dddde8;
    --bubble-ai:  #eeeef8;
    --bubble-user:#fce4ec;
  }
}
