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

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #ca8a04;
  --warning-light: #fef9c3;
  --info: #0891b2;
  --info-light: #e0f2fe;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-800: #1f2937;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --font: system-ui, -apple-system, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ── */
.navbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--primary);
  letter-spacing: -0.5px;
  text-decoration: none;
}

.nav-links {
  display: flex;
  list-style: none;
  gap: 0.25rem;
  flex: 1;
}

.nav-links a {
  padding: 0.4rem 0.9rem;
  border-radius: 8px;
  color: var(--gray-600);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}

.nav-links a:hover,
.nav-links a.active {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-email {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ── Container ── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ── Flash messages ── */
.flash-container { margin-bottom: 1.5rem; }

.flash {
  padding: 0.8rem 1.1rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.flash-success { background: var(--success-light); color: var(--success); }
.flash-danger  { background: var(--danger-light);  color: var(--danger); }
.flash-info    { background: var(--info-light);    color: var(--info); }
.flash-warning { background: var(--warning-light); color: var(--warning); }

/* ── Cards ── */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 0.25rem; }
.card-subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }
.card-actions { display: flex; gap: 0.75rem; margin-top: 1.25rem; flex-wrap: wrap; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1.2rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
}

.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

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

.btn-ghost { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-ghost:hover { background: var(--primary-light); color: var(--primary); }

.btn-full { width: 100%; }
.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.8rem; }

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

.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-group label { font-size: 0.875rem; font-weight: 600; color: var(--gray-800); }
.form-group .hint { font-weight: 400; color: var(--text-muted); }

.form-group input,
.form-group select,
.form-group textarea {
  padding: 0.6rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: var(--font);
  transition: border-color 0.15s;
  background: #fff;
  color: var(--text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.form-check {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.form-check input { width: auto; }
.form-check label { font-weight: 400; margin: 0; }

/* ── Auth ── */
.auth-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
  padding: 2rem 1rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 2.5rem;
}

.auth-footer {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ── Page header ── */
.page-header {
  margin-bottom: 2rem;
}

.page-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.page-header .subtitle {
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.back-link {
  display: inline-block;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.back-link:hover { color: var(--primary); }

/* ── Grid ── */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 700px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--primary-light);
  color: var(--primary);
  letter-spacing: 0.3px;
}

.badge-secondary {
  background: var(--gray-100);
  color: var(--gray-600);
}

.badge-success {
  background: var(--success-light);
  color: var(--success);
}

.badge-grammar {
  background: #fdf4ff;
  color: #7e22ce;
}

.badge-listening {
  background: #ecfdf5;
  color: #065f46;
}

/* ── Stats ── */
.stat-card { text-align: center; }
.stat-label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 2.5rem; font-weight: 800; color: var(--primary); margin: 0.25rem 0; }
.stat-sub { font-size: 0.8rem; color: var(--text-muted); }
.cefr-badge { font-size: 2rem; }
.stat-card.placeholder .stat-value { color: var(--gray-400); }

/* ── Section ── */
.section { margin-top: 2rem; }
.section h2 { font-size: 1.2rem; font-weight: 700; margin-bottom: 1rem; }

/* ── Plan ── */
.plan-list { list-style: none; display: flex; flex-direction: column; gap: 0.6rem; }
.plan-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.plan-module { font-weight: 600; flex: 1; }
.plan-count { font-size: 0.85rem; color: var(--text-muted); }

/* ── Action cards ── */
.action-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
  text-decoration: none;
  color: var(--text);
}
.action-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
}
.action-icon { font-size: 2rem; }
.action-title { font-weight: 700; font-size: 1rem; }
.action-desc { font-size: 0.85rem; color: var(--text-muted); }

/* ── Exercise list ── */
.section-actions { margin-bottom: 1.25rem; }
.exercise-list { display: flex; flex-direction: column; gap: 1rem; }

.exercise-card { display: flex; flex-direction: column; gap: 0.6rem; }
.exercise-card.completed { border-left: 3px solid var(--success); }
.exercise-meta { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.exercise-title { font-size: 1.1rem; font-weight: 700; }
.exercise-preview { color: var(--text-muted); font-size: 0.875rem; line-height: 1.5; }

/* ── Grammar specific ── */
.grammar-explanation {
  font-size: 0.95rem;
  line-height: 1.8;
  color: var(--gray-800);
}

.grammar-example {
  margin-top: 1.25rem;
  padding: 0.8rem 1rem;
  background: var(--primary-light);
  border-left: 3px solid var(--primary);
  border-radius: 0 8px 8px 0;
  font-size: 0.9rem;
}

.example-label {
  font-weight: 700;
  color: var(--primary);
  margin-right: 0.4rem;
}

.grammar-rule-reminder {
  margin-top: 1.25rem;
  padding: 0.8rem 1rem;
  background: #fdf4ff;
  border-left: 3px solid #7e22ce;
  border-radius: 0 8px 8px 0;
  font-size: 0.875rem;
  color: #581c87;
}

.reminder-label {
  font-weight: 700;
  margin-right: 0.4rem;
}

.question-type-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.question-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 0.5rem;
}

.fill-input {
  width: 100%;
  padding: 0.6rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: var(--font);
  transition: border-color 0.15s;
}

.fill-input:focus {
  outline: none;
  border-color: var(--primary);
}

.error-sentence {
  padding: 0.7rem 1rem;
  background: var(--danger-light);
  border-left: 3px solid var(--danger);
  border-radius: 0 8px 8px 0;
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  color: var(--gray-800);
}

.exercise-topic {
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}

.qr-details {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}

.qr-answers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: baseline;
}

.qr-student-ans { font-size: 0.8rem; color: var(--danger); }
.qr-correct-ans { font-size: 0.8rem; color: var(--success); }

/* ── Exercise layout ── */
.exercise-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 800px) {
  .exercise-layout { grid-template-columns: 1fr; }
}

.text-panel h2, .questions-card h2 { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; color: var(--text-muted); }
.reading-text { line-height: 1.8; font-size: 0.95rem; white-space: pre-wrap; }

.vocabulary-section { margin-top: 1.5rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.vocabulary-section h3 { font-size: 0.875rem; font-weight: 700; color: var(--text-muted); margin-bottom: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; }
.vocab-list { list-style: none; display: flex; flex-direction: column; gap: 0.4rem; }
.vocab-def { color: var(--text-muted); font-size: 0.875rem; }

/* ── Questions ── */
.questions-card { position: sticky; top: 76px; }
.question-block { margin-bottom: 1.5rem; padding-bottom: 1.25rem; border-bottom: 1px solid var(--border); }
.question-block:last-of-type { border-bottom: none; }
.question-text { font-size: 0.95rem; margin-bottom: 0.75rem; font-weight: 600; }

.options-list { display: flex; flex-direction: column; gap: 0.5rem; }
.option-label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.8rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.1s, border-color 0.1s;
}
.option-label:hover { background: var(--primary-light); border-color: var(--primary); }
.option-label input { accent-color: var(--primary); }

.short-answer {
  width: 100%;
  padding: 0.6rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: var(--font);
  resize: vertical;
  transition: border-color 0.15s;
}
.short-answer:focus { outline: none; border-color: var(--primary); }

/* ── Feedback ── */
.feedback-card { }
.feedback-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.feedback-header h2 { font-size: 1rem; font-weight: 700; }

.score-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 800;
}
.score-good { background: var(--success-light); color: var(--success); }
.score-ok   { background: var(--warning-light); color: var(--warning); }
.score-low  { background: var(--danger-light);  color: var(--danger); }

.feedback-general { font-size: 0.9rem; line-height: 1.6; color: var(--gray-600); margin-bottom: 1rem; }
.feedback-section { margin-top: 1rem; }
.feedback-section h3 { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 0.5rem; }
.feedback-section ul { list-style: none; display: flex; flex-direction: column; gap: 0.35rem; }
.strength-item { color: var(--success); font-size: 0.875rem; }
.improvement-item { color: var(--warning); font-size: 0.875rem; }

.question-result {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.5rem 0;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}
.question-result:last-child { border-bottom: none; }
.question-result.correct .qr-icon { color: var(--success); font-weight: 700; }
.question-result.incorrect .qr-icon { color: var(--danger); font-weight: 700; }
.qr-label { font-weight: 700; color: var(--text-muted); min-width: 24px; }
.qr-feedback { color: var(--gray-600); }

/* ── Progress ── */
.attempts-list { display: flex; flex-direction: column; gap: 0.75rem; }
.attempt-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.attempt-meta { display: flex; gap: 0.5rem; align-items: center; }
.attempt-title { flex: 1; font-weight: 600; font-size: 0.9rem; }
.attempt-score {
  font-weight: 800;
  font-size: 1.1rem;
  padding: 0.2rem 0.6rem;
  border-radius: 8px;
}
.attempt-date { font-size: 0.8rem; }

/* ── Status messages ── */
.status-msg {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  margin-top: 0.75rem;
}
.status-msg.info    { background: var(--info-light);    color: var(--info); }
.status-msg.success { background: var(--success-light); color: var(--success); }
.status-msg.error   { background: var(--danger-light);  color: var(--danger); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}
.empty-icon { font-size: 3rem; }

/* ── Listening ── */
.audio-player {
  background: var(--gray-50);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.audio-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.btn-audio {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: var(--primary);
  color: #fff;
  transition: background 0.15s;
}

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

.btn-audio-secondary {
  background: #fff;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

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

.audio-speed {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.audio-speed select {
  padding: 0.3rem 0.5rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  background: #fff;
}

.audio-progress-bar {
  height: 6px;
  background: var(--gray-200);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.audio-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.3s ease;
}

.audio-status {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.audio-tip {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.6rem 0.8rem;
  background: var(--info-light);
  border-radius: 8px;
  margin-bottom: 1rem;
}

.listening-tip-box {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: #ecfdf5;
  border-left: 3px solid #065f46;
  border-radius: 0 8px 8px 0;
  font-size: 0.875rem;
  color: #064e3b;
}

.transcript-reveal {
  margin-top: 1.5rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.transcript-reveal h3 {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.75rem;
}

.questions-instruction {
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.strategy-item {
  font-size: 0.875rem;
  color: var(--info);
  margin-bottom: 0.3rem;
}

/* ── Misc ── */
.muted { color: var(--text-muted); }
canvas { width: 100%; display: block; }
