/* =============================================================================
 * styles.css — Design system for "Master English with AI"
 * -----------------------------------------------------------------------------
 * Sections:
 *   1. Theme tokens (:root variables)
 *   2. Base / reset / typography (RTL shell + LTR content)
 *   3. Layout (sidebar, topbar, content)
 *   4. Components (buttons, cards, inputs, chips, progress)
 *   5. Pillar-specific UI (speaking, grammar, writing, vocab)
 *   6. Onboarding modal & toasts
 *   7. Animations (@keyframes)
 *   8. Responsive
 * ========================================================================== */

/* ============================ 1. THEME TOKENS ============================ */
:root {
  /* Brand / trust */
  --color-navy:         #1E1B4B;   /* sidebar */
  --color-navy-2:       #312E81;
  --color-primary:      #4338CA;   /* primary actions (indigo) */
  --color-primary-600:  #4f46e5;
  --color-primary-700:  #3730A3;

  /* Vibrant accent + states */
  --color-accent:       #FF6B6B;   /* coral — interactive highlights */
  --color-accent-soft:  #FFE7E3;
  --color-success:      #10B981;   /* emerald — correct / success */
  --color-success-soft: #D1FAE5;
  --color-warning:      #F59E0B;   /* soft amber — warnings (no harsh red) */
  --color-warning-soft: #FEF3C7;
  --color-mismatch:     #DA4B33;   /* muted coral-red — pronunciation mismatch */
  --color-mismatch-soft:#FBE3DD;

  /* Neutrals */
  --bg:        #F4F6FB;
  --surface:   #FFFFFF;
  --surface-2: #F8FAFC;
  --border:    #E5E8F0;
  --text:      #1F2937;
  --text-muted:#6B7280;
  --text-onnavy:#E5E7FF;

  /* Typography */
  --font-ar: 'Tajawal', 'Cairo', system-ui, sans-serif;
  --font-en: 'Inter', 'Segoe UI', Roboto, system-ui, sans-serif;

  /* Shape & motion */
  --radius:    14px;
  --radius-sm: 10px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 3px rgba(16,24,64,.06), 0 1px 2px rgba(16,24,64,.04);
  --shadow:    0 8px 24px rgba(16,24,64,.08);
  --shadow-lg: 0 18px 48px rgba(16,24,64,.14);
  --ease:      cubic-bezier(.4, 0, .2, 1);
  --t-fast:    .15s var(--ease);
  --t:         .25s var(--ease);
}

/* ====================== 2. BASE / RESET / TYPOGRAPHY ===================== */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ar);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* English content zones flow left-to-right with the English font. */
.ltr {
  direction: ltr;
  unicode-bidi: isolate;
  font-family: var(--font-en);
}

h1, h2, h3 { margin: 0 0 .3em; font-weight: 700; line-height: 1.25; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
p  { margin: 0 0 .6em; }

.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.brand-en { font-family: var(--font-en); color: var(--color-primary); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* Focus visibility for accessibility */
:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: 6px;
}

[hidden] { display: none !important; }

/* ============================= 3. LAYOUT ================================ */
.app { display: flex; min-height: 100vh; }

/* ---- Sidebar (sits on the RIGHT in RTL automatically) ---- */
.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--color-navy-2), var(--color-navy));
  color: var(--text-onnavy);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.logo { display: flex; align-items: center; gap: 12px; padding: 4px 8px 20px; }
.logo-mark { font-size: 1.8rem; }
.logo-text { display: flex; flex-direction: column; line-height: 1.2; }
.logo-text strong { font-size: 1rem; color: #fff; }
.logo-text small { font-size: .72rem; color: #B9BBF0; }

.nav { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border: 0; background: transparent;
  color: var(--text-onnavy);
  font-family: var(--font-ar); font-size: .98rem; font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer; text-align: start;
  transition: background var(--t-fast), transform var(--t-fast);
  position: relative;
}
.nav-item:hover { background: rgba(255,255,255,.08); transform: translateX(-3px); }
.nav-item.active { background: rgba(255,255,255,.14); box-shadow: inset 3px 0 0 var(--color-accent); }
.nav-icon { font-size: 1.15rem; width: 22px; text-align: center; }
.nav-label { flex: 1; }
.nav-badge {
  background: var(--color-accent); color: #fff; font-size: .72rem; font-weight: 700;
  min-width: 20px; height: 20px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center; padding: 0 6px;
}

.sidebar-foot { margin-top: auto; padding-top: 16px; }
.btn-ghost-sm {
  width: 100%; background: rgba(255,255,255,.06); color: #C7C9F2;
  border: 1px solid rgba(255,255,255,.12); border-radius: var(--radius-sm);
  padding: 9px; font-family: var(--font-ar); font-size: .85rem; cursor: pointer;
  transition: background var(--t-fast);
}
.btn-ghost-sm:hover { background: rgba(255,255,255,.14); }

/* ---- Main column ---- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  position: sticky; top: 0; z-index: 20;
}
.hamburger {
  display: none; background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--text);
}
.topbar-greeting { font-size: 1rem; }
.topbar-greeting .hello { color: var(--text-muted); }
.topbar-stats { display: flex; align-items: center; gap: 10px; margin-inline-start: auto; }

.stat-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 7px 14px; font-weight: 600;
}
.chip-icon { font-size: 1.05rem; }
.chip-value { color: var(--color-primary); font-variant-numeric: tabular-nums; }
.chip-label { color: var(--text-muted); font-size: .8rem; font-weight: 500; }
#xp-chip.pop { animation: pop .5s var(--ease); }

.select {
  font-family: var(--font-ar); font-size: .9rem; font-weight: 600;
  padding: 8px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer;
}

.content { padding: 28px 24px 60px; max-width: 1100px; width: 100%; margin-inline: auto; }

/* View switching with a soft entrance */
.view { display: none; }
.view.active { display: block; animation: viewIn .35s var(--ease); }
.view-head { margin-bottom: 22px; }
.section-title { margin: 30px 0 14px; }

/* ============================ 4. COMPONENTS ============================= */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

.btn {
  font-family: var(--font-ar); font-size: .95rem; font-weight: 600;
  padding: 11px 20px; border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  transition: transform var(--t-fast), box-shadow var(--t-fast), background var(--t-fast), opacity var(--t-fast);
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }

.btn-primary { background: var(--color-primary); color: #fff; box-shadow: 0 6px 16px rgba(67,56,202,.28); }
.btn-primary:hover { background: var(--color-primary-700); }

.btn-ghost { background: var(--surface-2); color: var(--color-primary); border-color: var(--border); }
.btn-ghost:hover { background: #EEF0FA; }

.btn-success { background: var(--color-success); color: #fff; box-shadow: 0 6px 16px rgba(16,185,129,.26); }
.btn-success:hover { filter: brightness(.96); }

.btn-warning { background: var(--color-warning); color: #fff; box-shadow: 0 6px 16px rgba(245,158,11,.26); }
.btn-warning:hover { filter: brightness(.96); }

/* Inputs */
.field-label { display: block; font-weight: 600; font-size: .9rem; margin: 14px 0 6px; }
.text-input, .textarea {
  width: 100%; font-size: 1rem; padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); transition: border-color var(--t-fast), box-shadow var(--t-fast);
  font-family: var(--font-ar);
}
.text-input.ltr, .textarea.ltr { font-family: var(--font-en); }
.text-input:focus, .textarea:focus {
  outline: none; border-color: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(67,56,202,.12);
}
.textarea { min-height: 220px; resize: vertical; line-height: 1.7; }

.row { display: flex; gap: 10px; align-items: center; }
.row.spread { justify-content: space-between; margin-top: 14px; }
.row .text-input { flex: 1; }

/* Progress bar */
.progress { background: var(--border); border-radius: 999px; height: 10px; overflow: hidden; }
.progress-bar {
  height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  transition: width .6s var(--ease);
}

.pill {
  display: inline-block; background: var(--color-primary); color: #fff;
  font-size: .76rem; font-weight: 700; padding: 4px 12px; border-radius: 999px;
}

/* Loading spinner (used for the "AI analyzing…" delay) */
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.45); border-top-color: #fff;
  display: inline-block; animation: spin .7s linear infinite;
}
.spinner.dark { border-color: rgba(67,56,202,.25); border-top-color: var(--color-primary); }

/* ---- Home dashboard ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 4px;
  transition: transform var(--t), box-shadow var(--t);
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.stat-card-icon { font-size: 1.6rem; }
.stat-card-num { font-size: 1.8rem; font-weight: 700; color: var(--color-primary); font-variant-numeric: tabular-nums; }
.stat-card-label { color: var(--text-muted); font-size: .9rem; }

.pillar-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.pillar-card {
  text-align: start; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow-sm); transition: transform var(--t), box-shadow var(--t), border-color var(--t);
  display: flex; flex-direction: column; gap: 8px; font-family: var(--font-ar);
}
.pillar-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: var(--color-primary); }
.pillar-icon { font-size: 1.9rem; }
.pillar-title { font-weight: 700; font-size: 1.05rem; }
.pillar-desc { color: var(--text-muted); font-size: .88rem; flex: 1; }
.pillar-progress { font-size: .8rem; color: var(--color-primary); font-weight: 600; }

/* ====================== 5. PILLAR-SPECIFIC UI ========================== */

/* ---- Speaking ---- */
.speak-card { max-width: 720px; margin-inline: auto; text-align: center; }
.speak-prompt { margin-bottom: 18px; }
.prompt-label { color: var(--text-muted); font-size: .9rem; }
.target-text { font-size: 1.8rem; font-weight: 600; color: var(--text); margin: 6px 0; }
.target-ar { color: var(--text-muted); margin-bottom: 10px; }

.mic-zone { display: flex; flex-direction: column; align-items: center; gap: 14px; margin: 10px 0 6px; }
.waveform {
  display: flex; align-items: center; justify-content: center; gap: 5px; height: 56px;
}
.waveform span {
  width: 5px; height: 12px; border-radius: 999px;
  background: var(--color-primary); opacity: .35;
  transition: height var(--t-fast);
}
.waveform.recording span { animation: wave 1s ease-in-out infinite; opacity: 1; }
.waveform.recording span:nth-child(odd)  { animation-duration: .8s; }
.waveform.recording span:nth-child(3n)   { animation-duration: 1.2s; background: var(--color-accent); }
.waveform.recording span:nth-child(1){animation-delay:0s}
.waveform.recording span:nth-child(2){animation-delay:.1s}
.waveform.recording span:nth-child(3){animation-delay:.2s}
.waveform.recording span:nth-child(4){animation-delay:.3s}
.waveform.recording span:nth-child(5){animation-delay:.15s}
.waveform.recording span:nth-child(6){animation-delay:.25s}
.waveform.recording span:nth-child(7){animation-delay:.05s}
.waveform.recording span:nth-child(8){animation-delay:.35s}
.waveform.recording span:nth-child(9){animation-delay:.2s}
.waveform.recording span:nth-child(10){animation-delay:.1s}

.mic-btn {
  width: 84px; height: 84px; border-radius: 50%; cursor: pointer;
  border: none; color: #fff; font-size: 2rem;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-700));
  box-shadow: 0 10px 26px rgba(67,56,202,.4);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.mic-btn:hover { transform: scale(1.06); }
.mic-btn.recording {
  background: linear-gradient(135deg, var(--color-accent), #E2553A);
  animation: pulse 1.4s ease-out infinite;
}
.mic-status { color: var(--text-muted); font-size: .92rem; min-height: 1.4em; }

.fallback { margin-top: 8px; text-align: start; }

.speak-result { margin-top: 22px; text-align: start; animation: viewIn .3s var(--ease); }
.accuracy-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; font-weight: 600; }
.accuracy-pct { font-size: 1.4rem; color: var(--color-primary); }
.result-words { font-size: 1.4rem; margin: 16px 0; line-height: 2.1; }
.result-words .w-ok  { color: var(--color-success); background: var(--color-success-soft); padding: 2px 8px; border-radius: 6px; margin: 0 2px; }
.result-words .w-bad { color: var(--color-mismatch); background: var(--color-mismatch-soft); padding: 2px 8px; border-radius: 6px; margin: 0 2px; text-decoration: underline wavy var(--color-mismatch); }
.result-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* ---- Grammar ---- */
.grammar-card { max-width: 720px; margin-inline: auto; }
.grammar-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.grammar-count { color: var(--text-muted); font-weight: 600; font-size: .9rem; }
.grammar-instruction { color: var(--text-muted); }
.grammar-sentence { font-size: 1.5rem; font-weight: 600; margin: 8px 0 20px; line-height: 1.6; }

.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  font-family: var(--font-en); font-size: 1.05rem; text-align: start;
  padding: 13px 16px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer; color: var(--text);
  transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
  direction: ltr;
}
.option:hover:not(:disabled) { border-color: var(--color-primary); transform: translateY(-2px); }
.option.correct { border-color: var(--color-success); background: var(--color-success-soft); color: #047857; font-weight: 700; }
.option.wrong   { border-color: var(--color-mismatch); background: var(--color-mismatch-soft); color: var(--color-mismatch); }
.option:disabled { cursor: default; }

.feedback {
  margin-top: 20px; padding: 18px; border-radius: var(--radius);
  border: 1px solid var(--border); animation: viewIn .3s var(--ease);
}
.feedback.ok   { background: var(--color-success-soft); border-color: #A7F3D0; }
.feedback.warn { background: var(--color-warning-soft); border-color: #FDE68A; }
.feedback-head { font-weight: 700; margin-bottom: 8px; font-size: 1.05rem; }
.feedback.ok   .feedback-head { color: #047857; }
.feedback.warn .feedback-head { color: #B45309; }
.feedback-answer { font-weight: 600; margin-bottom: 6px; }
.feedback-why { color: var(--text); margin-bottom: 14px; }

/* ---- Writing ---- */
.writing-layout { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; align-items: start; }
.prompt-en { font-family: var(--font-en); color: var(--text-muted); font-size: .92rem; margin: 6px 0 12px; }
.writing-panel h3 { margin-bottom: 14px; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.metric { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 6px; text-align: center; }
.metric-num { display: block; font-size: 1.5rem; font-weight: 700; color: var(--color-primary); }
.metric-cap { font-size: .78rem; color: var(--text-muted); }

.suggestions { display: flex; flex-direction: column; gap: 10px; }
.suggestion {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 13px;
  border-radius: var(--radius-sm); font-size: .9rem; border: 1px solid var(--border);
  animation: viewIn .3s var(--ease);
}
.suggestion.sug-warn { background: var(--color-warning-soft); border-color: #FDE68A; }
.suggestion.sug-ok   { background: var(--color-success-soft); border-color: #A7F3D0; }
.sug-icon { font-size: 1.05rem; line-height: 1.4; }
.sug-text code { font-family: var(--font-en); background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; }

/* ---- Vocabulary / Word Bank ---- */
.vocab-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab {
  font-family: var(--font-ar); font-weight: 600; font-size: .95rem;
  padding: 9px 18px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; transition: all var(--t-fast);
}
.tab:hover { border-color: var(--color-primary); }
.tab.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.tab-badge { background: var(--color-accent); color: #fff; font-size: .72rem; border-radius: 999px; padding: 1px 8px; }

.vocab-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.word-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm); position: relative;
  transition: transform var(--t), box-shadow var(--t);
}
.word-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.word-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.word-en { font-family: var(--font-en); font-size: 1.25rem; font-weight: 700; color: var(--color-primary); direction: ltr; }
.word-ar { color: var(--text-muted); font-size: .9rem; }
.word-def { font-family: var(--font-en); direction: ltr; font-size: .9rem; margin: 8px 0 4px; }
.word-ex  { font-family: var(--font-en); direction: ltr; font-size: .85rem; color: var(--text-muted); font-style: italic; }
.word-box { font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--color-primary-soft, #EEF0FA); color: var(--color-primary); white-space: nowrap; }
.word-box.mastered { background: var(--color-success-soft); color: #047857; }
.word-remove {
  position: absolute; inset-block-start: 10px; inset-inline-start: 10px;
  background: none; border: 0; color: var(--text-muted); cursor: pointer; font-size: 1rem;
  opacity: .5; transition: opacity var(--t-fast), color var(--t-fast);
}
.word-remove:hover { opacity: 1; color: var(--color-mismatch); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-emoji { font-size: 3rem; display: block; margin-bottom: 10px; }

/* Flashcards (3D flip) */
.review-stage { max-width: 460px; margin-inline: auto; text-align: center; }
.review-progress { color: var(--text-muted); font-weight: 600; margin-bottom: 14px; }
.flashcard { perspective: 1200px; height: 260px; cursor: pointer; margin-bottom: 18px; }
.flashcard-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d; transition: transform .6s var(--ease);
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  border-radius: var(--radius-lg); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; padding: 24px; box-shadow: var(--shadow);
}
.flashcard-front { background: linear-gradient(135deg, var(--color-primary), var(--color-primary-700)); color: #fff; }
.flashcard-back  { background: var(--surface); border: 1px solid var(--border); transform: rotateY(180deg); }
.fc-word { font-family: var(--font-en); font-size: 2rem; font-weight: 700; direction: ltr; }
.fc-hint { font-size: .8rem; opacity: .85; }
.fc-ar { color: var(--color-primary); font-weight: 700; font-size: 1.1rem; }
.fc-def { font-family: var(--font-en); direction: ltr; }
.fc-ex { font-family: var(--font-en); direction: ltr; color: var(--text-muted); font-style: italic; font-size: .9rem; }
.review-actions { display: flex; gap: 12px; justify-content: center; }

/* ===================== 6. ONBOARDING MODAL & TOASTS ==================== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(30,27,75,.55); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fadeIn .3s var(--ease);
}
.modal { width: 100%; max-width: 460px; text-align: center; animation: modalIn .4s var(--ease); }
.modal-brand { font-size: 3rem; margin-bottom: 6px; }
.modal h2 { font-size: 1.3rem; }

.level-choice { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 10px 0 20px; }
.level-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 14px 8px; border: 2px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; font-family: var(--font-ar);
  transition: all var(--t-fast);
}
.level-card:hover { border-color: var(--color-primary); transform: translateY(-2px); }
.level-card.selected { border-color: var(--color-primary); background: #EEF0FA; box-shadow: 0 0 0 3px rgba(67,56,202,.12); }
.level-emoji { font-size: 1.6rem; }
.level-name { font-weight: 700; }
.level-sub { font-size: .72rem; color: var(--text-muted); }

.toast-area {
  position: fixed; inset-block-end: 24px; inset-inline-start: 24px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: var(--color-navy); color: #fff; padding: 12px 18px; border-radius: var(--radius);
  box-shadow: var(--shadow-lg); font-weight: 600; display: flex; align-items: center; gap: 10px;
  animation: toastIn .3s var(--ease);
}
.toast.success { background: var(--color-success); }
.toast.warn { background: var(--color-warning); }
.toast.xp { background: linear-gradient(135deg, var(--color-primary), var(--color-accent)); }

/* ============================ 7. ANIMATIONS ============================ */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes modalIn { from { opacity: 0; transform: translateY(20px) scale(.97); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes wave { 0%,100% { height: 12px; } 50% { height: 42px; } }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255,107,107,.5); }
  70%  { box-shadow: 0 0 0 18px rgba(255,107,107,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,107,107,0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ============================ 8. RESPONSIVE =========================== */
@media (max-width: 860px) {
  .writing-layout { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-end: 0; z-index: 90;
    transform: translateX(100%); transition: transform var(--t);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: inline-block; }
  .topbar-greeting { display: none; }
  .content { padding: 20px 16px 50px; }
  .target-text { font-size: 1.4rem; }
  .grammar-sentence { font-size: 1.25rem; }
  .level-selector .select { max-width: 130px; }
}

@media (max-width: 480px) {
  .topbar-stats { gap: 6px; }
  .stat-chip { padding: 6px 10px; }
  .chip-label { display: none; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
}

/* ============================ 9. AUTH UI ============================== */
.auth-card { max-width: 460px; max-height: 92vh; overflow-y: auto; text-align: start; }
.auth-card .modal-brand, .auth-card h2, .auth-card > .muted { text-align: center; }

.auth-tabs {
  display: flex; gap: 6px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px; margin: 16px 0 18px;
}
.auth-tab {
  flex: 1; border: 0; background: transparent; cursor: pointer;
  font-family: var(--font-ar); font-weight: 600; font-size: .92rem; color: var(--text-muted);
  padding: 9px; border-radius: 999px; transition: background var(--t-fast), color var(--t-fast);
}
.auth-tab.active { background: var(--color-primary); color: #fff; box-shadow: 0 4px 12px rgba(67,56,202,.25); }

.auth-form { display: flex; flex-direction: column; }
.auth-form .field-label { margin-top: 12px; }
.auth-form .btn-block { margin-top: 18px; }
.auth-form .level-choice { margin: 8px 0 4px; }
.auth-error { color: var(--color-mismatch); font-size: .88rem; font-weight: 600; min-height: 1.2em; margin: 8px 0 0; }
.auth-foot { text-align: center; margin-top: 16px; }
.auth-foot a { color: var(--color-primary); font-weight: 600; }

/* signed-in account block in the sidebar */
.user-mini {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 10px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); border-radius: var(--radius-sm);
}
.user-avatar {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 50%;
  background: var(--color-accent); color: #fff; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; font-size: .9rem;
}
.user-email { font-size: .78rem; color: #C7C9F2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
