/* ── Variables ─────────────────────────────────────────── */
:root {
  --navy:      #0f2850;
  --navy-2:    #1a3a6c;
  --teal:      #0891b2;
  --teal-bg:   #e0f7fa;
  --amber:     #d97706;
  --green:     #059669;
  --red:       #dc2626;
  --bg:        #f0f4f8;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --text:      #1a202c;
  --muted:     #64748b;
  --light:     #94a3b8;
  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.10);

  /* Nivell colors */
  --nB1: #0891b2; --nB1-bg: #e0f7fa;
  --nB2: #4f46e5; --nB2-bg: #eef2ff;
  --nC1: #d97706; --nC1-bg: #fef3c7;
  --nC2: #dc2626; --nC2-bg: #fee2e2;
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; border: none; outline: none; }
input, select { font-family: inherit; }

/* ── Navbar ─────────────────────────────────────────────── */
.navbar {
  background: var(--navy);
  color: #fff;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.navbar .brand {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  white-space: nowrap;
}
.navbar .brand span { color: var(--teal); }
.nav-links {
  display: flex;
  gap: 0.2rem;
  list-style: none;
  flex-wrap: wrap;
}
.nav-links a {
  display: block;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  color: rgba(255,255,255,.75);
  transition: all .15s;
  white-space: nowrap;
}
.nav-links a:hover       { color: #fff; background: rgba(255,255,255,.1); }
.nav-links a.active      { color: #fff; background: rgba(255,255,255,.15); }
.navbar .spacer { flex: 1; }
.btn-flashcards {
  background: var(--amber);
  color: #fff;
  padding: 0.4rem 1rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  transition: filter .15s;
}
.btn-flashcards:hover { filter: brightness(1.1); }

/* ── Layout ─────────────────────────────────────────────── */
.page { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}
.card-sm { padding: 1rem; }

/* ── Stats row ──────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.stat-card .label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-card .value { font-size: 2rem; font-weight: 800; color: var(--navy); line-height: 1.1; }
.stat-card .sublabel { font-size: 0.8rem; color: var(--muted); }
.stat-card.accent-green .value { color: var(--green); }
.stat-card.accent-teal  .value { color: var(--teal); }
.stat-card.accent-amber .value { color: var(--amber); }

/* ── Category grid (dashboard) ──────────────────────────── */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 0.85rem;
  margin-bottom: 2rem;
}
.cat-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  border-left: 4px solid var(--cat-color, var(--teal));
  transition: box-shadow .15s;
}
.cat-card:hover { box-shadow: var(--shadow-md); }
.cat-header { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.cat-name { font-weight: 600; font-size: 0.85rem; line-height: 1.3; }
.cat-pct  { font-size: 1.1rem; font-weight: 800; color: var(--cat-color, var(--teal)); white-space: nowrap; }

.progress-bar-wrap {
  background: var(--border);
  border-radius: 6px;
  height: 8px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 6px;
  background: var(--cat-color, var(--teal));
  transition: width .4s ease;
}
.cat-card footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.cat-stats { font-size: 0.75rem; color: var(--muted); }

/* ── Exàmens (convocatòries completes) ── */
.exam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
}
.exam-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem;
  cursor: pointer;
  transition: box-shadow .15s, transform .1s;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.exam-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.exam-card-top { display: flex; gap: 0.4rem; align-items: center; }
.exam-card-title { font-size: 1.15rem; font-weight: 700; color: var(--navy); }
.exam-card-sub { font-size: 0.82rem; color: var(--muted); }
.exam-card-done { font-size: 0.78rem; color: var(--green); font-weight: 600; }
.exam-card-pending { font-size: 0.78rem; color: var(--muted); }
.btn-practice {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  color: #fff;
  background: var(--cat-color, var(--teal));
  transition: filter .15s;
}
.btn-practice:hover { filter: brightness(1.1); }

/* ── Sessions list ──────────────────────────────────────── */
.sessions-list { display: flex; flex-direction: column; gap: 0.5rem; }
.session-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}
.session-score {
  font-weight: 700;
  font-size: 1rem;
  min-width: 60px;
}
.session-score.good  { color: var(--green); }
.session-score.ok    { color: var(--amber); }
.session-score.bad   { color: var(--red);   }
.session-meta { color: var(--muted); font-size: 0.8rem; flex: 1; }
.session-pct  { font-weight: 600; font-size: 0.85rem; color: var(--navy); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.4rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  transition: all .15s;
}
.btn-primary   { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-teal      { background: var(--teal); color: #fff; }
.btn-teal:hover { filter: brightness(1.1); }
.btn-outline   { background: transparent; border: 2px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--navy); }
.btn-lg { padding: 0.85rem 2rem; font-size: 1rem; border-radius: 10px; }
.btn-full { width: 100%; justify-content: center; }

/* ── Test page ──────────────────────────────────────────── */
.test-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Progress donut (pantalla config de Test) */
.progress-chart-wrap {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
.progress-donut {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--border);
  transition: background .4s ease;
}
.progress-donut-center {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.progress-donut-center span:first-child { font-size: 1.15rem; font-weight: 800; color: var(--navy); line-height: 1.1; }
.donut-center-label { font-size: 0.62rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

.progress-legend { display: flex; flex-direction: column; gap: 0.5rem; flex: 1; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--navy);
}
.legend-item strong { margin-left: auto; font-size: 0.95rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* Config screen */
.config-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2rem;
}
.config-card h2 { font-size: 1.4rem; color: var(--navy); margin-bottom: 0.25rem; }
.config-card .subtitle { color: var(--muted); margin-bottom: 1.5rem; font-size: 0.95rem; }
.config-section { margin-bottom: 1.5rem; }
.config-label { font-size: 0.85rem; font-weight: 700; color: var(--navy); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 0.6rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.config-label .mini-actions { display: flex; gap: .4rem; text-transform: none; letter-spacing: 0; }
.mini-btn {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}
.mini-btn:hover { border-color: var(--navy); color: var(--navy); }

.nivell-checks {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.nivell-check-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border: 2px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: all .15s;
  user-select: none;
  font-weight: 700;
  font-size: 0.85rem;
}
.nivell-check-item input { display: none; }
.nivell-check-item[data-nivell="B1"].checked { border-color: var(--nB1); background: var(--nB1-bg); color: var(--nB1); }
.nivell-check-item[data-nivell="B2"].checked { border-color: var(--nB2); background: var(--nB2-bg); color: var(--nB2); }
.nivell-check-item[data-nivell="C1"].checked { border-color: var(--nC1); background: var(--nC1-bg); color: var(--nC1); }
.nivell-check-item[data-nivell="C2"].checked { border-color: var(--nC2); background: var(--nC2-bg); color: var(--nC2); }

.cat-checks {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}
.cat-check-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .15s;
  user-select: none;
}
.cat-check-item:hover { border-color: var(--teal); }
.cat-check-item.checked { border-color: var(--cat-color, var(--teal)); background: color-mix(in srgb, var(--cat-color, var(--teal)) 12%, white); }
.cat-check-item input { display: none; }
.cat-check-item .check-name { font-size: 0.82rem; font-weight: 500; }

.count-btns { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.count-btn {
  padding: 0.4rem 1rem;
  border: 2px solid var(--border);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--text);
  transition: all .15s;
}
.count-btn.active, .count-btn:hover { border-color: var(--navy); background: var(--navy); color: #fff; }

.mode-btns { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.mode-btn {
  padding: 0.4rem 1rem;
  border: 2px solid var(--border);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--text);
  transition: all .15s;
}
.mode-btn.active, .mode-btn:hover { border-color: var(--teal); background: var(--teal); color: #fff; }

/* Question card */
.question-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.question-header {
  background: var(--navy);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
}
.question-header .q-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.7rem;
  border-radius: 20px;
  color: #fff;
}
.question-header .q-num {
  font-size: 0.85rem;
  color: rgba(255,255,255,.7);
}
.question-body { padding: 1.5rem; }
.question-text {
  font-size: 1.1rem;
  font-weight: 500;
  line-height: 1.5;
  margin-bottom: 1.5rem;
  color: var(--navy);
}
.blank-current {
  background: var(--teal-bg);
  color: var(--teal);
  font-weight: 800;
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
  border: 1.5px solid var(--teal);
  white-space: nowrap;
}
.blank-other {
  color: var(--muted);
  font-weight: 400;
}
.options-grid {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.option-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: left;
  font-size: 0.95rem;
  transition: all .15s;
  width: 100%;
}
.option-btn:hover:not(:disabled) { border-color: var(--teal); background: var(--teal-bg); }
.option-btn .opt-letter {
  min-width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--navy);
  flex-shrink: 0;
}
.option-btn .opt-text { flex: 1; line-height: 1.4; }

.option-btn.correct {
  border-color: var(--green);
  background: #d1fae5;
}
.option-btn.correct .opt-letter { background: var(--green); color: #fff; }
.option-btn.wrong {
  border-color: var(--red);
  background: #fee2e2;
}
.option-btn.wrong .opt-letter { background: var(--red); color: #fff; }
.option-btn.anulada {
  border-color: var(--teal);
  background: var(--teal-bg);
}
.option-btn.anulada .opt-letter { background: var(--teal); color: #fff; }
.option-btn:disabled { cursor: not-allowed; }

.question-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
}
.feedback-msg {
  font-weight: 700;
  font-size: 0.95rem;
}
.feedback-msg.correct { color: var(--green); }
.feedback-msg.wrong   { color: var(--red); }
.feedback-msg.anulada { color: var(--teal); }
.feedback-ia-note {
  display: block;
  font-weight: 500;
  font-size: 0.78rem;
  color: var(--amber);
  margin-top: .25rem;
  cursor: help;
}

/* Progress */
.test-progress {
  margin-bottom: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--muted);
}
.test-progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 6px;
  margin-bottom: 1.25rem;
  overflow: hidden;
}
.test-progress-fill {
  height: 100%;
  background: var(--teal);
  border-radius: 6px;
  transition: width .3s ease;
}

/* Results */
.results-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2rem;
  text-align: center;
}
.results-card h2 { font-size: 1.5rem; color: var(--navy); margin-bottom: 0.5rem; }
.score-circle {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 1.5rem auto;
  border: 8px solid;
}
.score-circle.pass  { border-color: var(--green); }
.score-circle.fail  { border-color: var(--red); }
.score-circle .score-num { font-size: 2.2rem; font-weight: 800; line-height: 1; }
.score-circle.pass .score-num { color: var(--green); }
.score-circle.fail .score-num { color: var(--red); }
.score-circle .score-total   { font-size: 0.85rem; color: var(--muted); }
.score-verdict {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
}
.score-verdict.pass { color: var(--green); }
.score-verdict.fail { color: var(--red); }

.results-by-topic {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.6rem;
  margin: 1.5rem 0;
  text-align: left;
}
.result-topic-item {
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.result-topic-item .rt-name { font-weight: 600; }
.result-topic-item .rt-score { font-weight: 700; }

.wrong-answers { text-align: left; margin-top: 1rem; }
.wrong-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}
.wrong-item .wi-q { font-weight: 500; color: var(--navy); margin-bottom: 0.25rem; }
.wrong-item .wi-tu  { color: var(--red); }
.wrong-item .wi-ok  { color: var(--green); }

/* Results actions */
.results-actions { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; margin-top: 1.5rem; }

/* ── Banc ──────────────────────────────────────────────── */
.filters-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
  align-items: center;
}
.filter-select, .filter-input {
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}
.filter-select:focus, .filter-input:focus { outline: none; border-color: var(--teal); }
.filter-input { min-width: 200px; }

.questions-table-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  overflow-x: auto;
}
.questions-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.questions-table th {
  background: var(--navy);
  color: #fff;
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.questions-table td { padding: 0.7rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.questions-table tr:last-child td { border-bottom: none; }
.questions-table tr:hover td { background: var(--bg); }
.q-text-cell { max-width: 380px; }
.q-text-cell span {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 1.4;
}
.badge-prio {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
}
.badge-prio.Alta    { background: #fee2e2; color: #b91c1c; }
.badge-prio.Mitjana { background: #fef3c7; color: #92400e; }
.badge-prio.Baixa   { background: #f0fdf4; color: #166534; }
.badge-estat {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-weight: 600;
}
.badge-estat.nova     { background: var(--bg);     color: var(--muted); }
.badge-estat.aprenent { background: #fef3c7;        color: #92400e; }
.badge-estat.dominada { background: #d1fae5;        color: #065f46; }

.btn-ver {
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  transition: all .15s;
}
.btn-ver:hover { background: var(--navy); color: #fff; border-color: var(--navy); }

.pagination-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp .15s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity:0; } to { transform: translateY(0); opacity:1; } }
.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.modal-header h3 { font-size: 1rem; color: var(--navy); line-height: 1.4; }
.modal-close {
  background: none;
  font-size: 1.4rem;
  color: var(--muted);
  line-height: 1;
  padding: 0 0.25rem;
  flex-shrink: 0;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1.25rem 1.5rem; }
.modal-option {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background .15s;
}
.modal-option:hover { background: var(--bg); }
.modal-option.correct { background: #d1fae5; cursor: default; }
.modal-option.wrong   { background: #fee2e2; cursor: default; }
.modal-option.anulada { background: var(--teal-bg); cursor: default; }
.modal-option .opt-letter { min-width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.75rem; background: var(--bg); color: var(--navy); flex-shrink: 0; }
.modal-option.correct .opt-letter { background: var(--green); color: #fff; }
.modal-option.wrong   .opt-letter { background: #ef4444; color: #fff; }
.modal-option.anulada .opt-letter { background: var(--teal); color: #fff; }
#modal-options.answered .modal-option { cursor: default; }
#modal-options.answered .modal-option:not(.correct):not(.wrong):hover { background: transparent; }
.modal-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; font-size: 0.8rem; }
.meta-chip { background: var(--bg); border-radius: 6px; padding: 0.25rem 0.6rem; color: var(--muted); }
.modal-anulada-note {
  background: var(--teal-bg);
  border: 1.5px solid var(--teal);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  font-size: 0.83rem;
  color: #075966;
  margin-bottom: 1rem;
}
.modal-ia-note {
  background: #fffbeb;
  border: 1.5px solid var(--amber);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  font-size: 0.83rem;
  color: #92400e;
  margin-bottom: 1rem;
}

/* ── Stats page ─────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}
.chart-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}
.chart-card h3 { font-size: 0.9rem; font-weight: 700; color: var(--navy); margin-bottom: 1rem; }

.stat-bars { display: flex; flex-direction: column; gap: 0.65rem; }
.stat-bar-row { display: flex; align-items: center; gap: .75rem; font-size: .82rem; }
.stat-bar-label { min-width: 90px; font-weight: 700; color: var(--navy); }
.stat-bar-track { flex: 1; height: 10px; background: var(--border); border-radius: 6px; overflow: hidden; display: flex; }
.stat-bar-seg-dom { background: var(--green); height: 100%; }
.stat-bar-seg-apr { background: var(--amber); height: 100%; }
.stat-bar-nums { min-width: 90px; text-align: right; color: var(--muted); font-size: .78rem; }

/* ── Badges genéricos (nivell / font / categoria) ───────── */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  white-space: nowrap;
}
.nivell-badge.B1 { background: var(--nB1-bg); color: var(--nB1); }
.nivell-badge.B2 { background: var(--nB2-bg); color: var(--nB2); }
.nivell-badge.C1 { background: var(--nC1-bg); color: var(--nC1); }
.nivell-badge.C2 { background: var(--nC2-bg); color: var(--nC2); }
.font-badge { background: var(--bg); color: var(--muted); }
.ia-flag {
  font-size: 0.85rem;
  cursor: help;
}

/* ── Animations ─────────────────────────────────────────── */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25%      { transform: translateX(-6px); }
  75%      { transform: translateX(6px); }
}
.shake { animation: shake .3s ease; }

@keyframes bounce-in {
  0%   { transform: scale(.9); opacity: 0; }
  60%  { transform: scale(1.03); }
  100% { transform: scale(1); opacity: 1; }
}
.bounce-in { animation: bounce-in .25s ease forwards; }

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 0.5rem; }
.empty-state h3 { font-size: 1rem; color: var(--navy); margin-bottom: 0.25rem; }

/* ── Filtres / pills ─────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.75rem;
  align-items: center;
}
.filter-bar-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-right: 0.25rem;
}
.fpill {
  padding: 0.35rem 0.9rem;
  border: 2px solid var(--border);
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all .15s;
}
.fpill:hover          { border-color: var(--navy); }
.fpill.active         { border-color: var(--navy); background: var(--navy); color: #fff; }

/* ── Timer siempre visible ───────────────────────────────── */
.timer {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
  display: inline-block !important;
}
.timer.warning { color: var(--amber); }
.timer.danger  { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

/* ── Ranking ─────────────────────────────────────────────── */
.ranking-controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1.75rem;
}
.ranking-list   { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 2rem; }
.ranking-item {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 0.75rem;
  align-items: center;
  cursor: pointer;
  transition: box-shadow .15s;
}
.ranking-item:hover { box-shadow: var(--shadow-md); }
.ranking-item.expanded { box-shadow: var(--shadow-md); }

.rank-num {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--muted);
  text-align: center;
}
.rank-num.top3 { color: var(--amber); }

.rank-body {}
.rank-text {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--navy);
  line-height: 1.4;
  margin-bottom: 0.4rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.rank-text.full { -webkit-line-clamp: unset; }
.rank-badges    { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; margin-top: 0.3rem; }

.rank-freq {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
  min-width: 80px;
}
.freq-num {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--navy);
  white-space: nowrap;
}
.freq-label { font-size: 0.7rem; color: var(--muted); white-space: nowrap; }
.freq-bar-wrap {
  width: 80px;
  height: 6px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.freq-bar-fill {
  height: 100%;
  border-radius: 6px;
  background: var(--amber);
  transition: width .5s ease;
}
.freq-bar-fill.alta  { background: var(--red); }
.freq-bar-fill.mitjana { background: var(--amber); }
.freq-bar-fill.baixa  { background: var(--teal); }

/* Rank expanded detail */
.rank-detail {
  grid-column: 1 / -1;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  display: none;
}
.rank-detail.open { display: flex; }
.rank-opt {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  font-size: 0.87rem;
  line-height: 1.35;
}
.rank-opt { cursor: pointer; transition: background .15s; }
.rank-opt:hover { background: rgba(0,0,0,.04); }
.rank-opt.correct { background: #d1fae5; cursor: default; }
.rank-opt.wrong   { background: #fee2e2; cursor: default; }
.rank-opt.anulada { background: var(--teal-bg); cursor: default; }
.rank-opt.correct .opt-letter { background: var(--green); color: #fff; }
.rank-opt.wrong   .opt-letter { background: #ef4444; color: #fff; }
.rank-opt.anulada .opt-letter { background: var(--teal); color: #fff; }
.rank-opt .opt-letter {
  min-width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.75rem;
  background: var(--bg); color: var(--navy); flex-shrink: 0;
}
.rank-detail.answered .rank-opt { cursor: default; }
.rank-detail.answered .rank-opt:not(.correct):not(.wrong):hover { background: transparent; }

/* ── Pendents ──────────────────────────────────────────── */
.pend-cat-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.pend-cat-count {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--navy);
}
.pend-cat-count strong { font-size: 0.95rem; }

.rank-num.fail-num {
  font-size: 0.9rem;
  color: var(--red);
  white-space: nowrap;
}
.rank-num.age-num {
  font-size: 0.9rem;
  color: var(--teal);
  white-space: nowrap;
}

.fuente-hint {
  font-size: 0.83rem;
  color: var(--muted);
  margin: -0.5rem 0 1.25rem;
}
#pend-fuente-toggle .fpill strong {
  margin-left: 0.35rem;
  font-size: 0.78rem;
  opacity: 0.85;
}

.ranking-item.pend-resolved {
  opacity: 0;
  transform: translateX(24px);
  transition: opacity .45s ease, transform .45s ease;
}

/* by-category ranking grid */
.ranking-topics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}
.topic-ranking-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.topic-ranking-header {
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.9rem;
  color: #fff;
}
.topic-ranking-list { padding: 0.5rem 0; }
.topic-rank-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.83rem;
  cursor: pointer;
  transition: background .12s;
}
.topic-rank-item:last-child { border-bottom: none; }
.topic-rank-item:hover      { background: var(--bg); }
.trk-num   { font-weight: 800; color: var(--muted); min-width: 20px; }
.trk-text  { flex: 1; color: var(--navy); line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.trk-freq  { font-weight: 700; font-size: 0.85rem; white-space: nowrap; }

/* ── Dashboard top row ───────────────────────────────────── */
.dash-top-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  box-shadow: var(--shadow);
}
.dash-streak {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: default;
}
.streak-fire { font-size: 1.4rem; line-height: 1; }
.streak-num  { font-size: 1.5rem; font-weight: 800; color: var(--amber); line-height: 1; }
.streak-label{ font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.dash-streak:hover .streak-num { color: #f97316; }

.dash-nivell-wrap  { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-left: auto; }
.dash-nivell-label { font-size: 0.82rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.dash-nivell-btns  { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* ── Predictor de preparació ───────────────────────────────── */
.predictor-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.predictor-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.predictor-semaforo { font-size: 2.2rem; line-height: 1; }
.predictor-title    { font-size: 0.82rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.predictor-verdict  { font-size: 1.05rem; font-weight: 700; color: var(--navy); margin-top: 0.15rem; }
.predictor-stats {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.pred-stat  { display: flex; flex-direction: column; align-items: center; min-width: 80px; }
.pred-val   { font-size: 1.4rem; font-weight: 800; color: var(--navy); line-height: 1; }
.pred-lbl   { font-size: 0.73rem; color: var(--muted); text-align: center; margin-top: 0.15rem; }
.predictor-bar-wrap {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.predictor-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--teal);
  transition: width .6s ease, background .4s ease;
}
.predictor-bar-fill.verde  { background: var(--green); }
.predictor-bar-fill.ambar  { background: var(--amber); }
.predictor-bar-fill.rojo   { background: var(--red); }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 640px) {
  .navbar { gap: 1rem; padding: 0 1rem; height: auto; flex-wrap: wrap; padding-top: .5rem; padding-bottom: .5rem; position: static; }
  .nav-links a { padding: 0.35rem 0.6rem; font-size: 0.82rem; }
  .page { padding: 1.25rem 1rem; }
  .test-wrap { padding: 1rem; }
  .cat-checks { grid-template-columns: 1fr; }
  .question-text { font-size: 1rem; }
  .btn-flashcards { display: none; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}
