/* ═══════════════════════════════════════════════════════════════
   Variables i reset
═══════════════════════════════════════════════════════════════ */
:root {
  --c-primary:   #7C3AED;
  --c-primary-d: #5B21B6;
  --c-secondary: #EC4899;
  --c-success:   #10B981;
  --c-error:     #EF4444;
  --c-warning:   #F59E0B;
  --c-bg:        #EDE9FE;
  --c-card:      #FFFFFF;
  --c-text:      #1E1B4B;
  --c-muted:     #6B7280;
  --c-border:    #DDD6FE;
  --r: 1.25rem;
  --shadow:    0 4px 12px rgba(124,58,237,.12);
  --shadow-lg: 0 10px 30px rgba(124,58,237,.20);
  --ff-display: 'Fredoka One', 'Comic Sans MS', cursive;
  --ff-body:    'Nunito', system-ui, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--ff-body);
  background: var(--c-bg);
  color: var(--c-text);
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ═══════════════════════════════════════════════════════════════
   Pantalles
═══════════════════════════════════════════════════════════════ */
.screen { display: none; min-height: 100dvh; flex-direction: column; }
.screen.active { display: flex; animation: screenIn .22s ease; }
@keyframes screenIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.screen-inner {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ═══════════════════════════════════════════════════════════════
   Capçalera
═══════════════════════════════════════════════════════════════ */
.app-header {
  background: var(--c-primary);
  color: #fff;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  box-shadow: var(--shadow-lg);
}
.app-title {
  font-family: var(--ff-display);
  font-size: 2rem;
  line-height: 1;
  flex-shrink: 0;
}
.username-bar { flex: 1; display: flex; align-items: center; gap: .5rem; min-width: 180px; }
.username-label { font-size: .875rem; opacity: .85; white-space: nowrap; }
.username-input {
  flex: 1;
  border: 2px solid rgba(255,255,255,.4);
  border-radius: .5rem;
  padding: .4rem .75rem;
  background: rgba(255,255,255,.15);
  color: #fff;
  font-family: var(--ff-body);
  font-size: .95rem;
  font-weight: 700;
  outline: none;
  transition: border-color .2s;
}
.username-input::placeholder { color: rgba(255,255,255,.55); }
.username-input:focus { border-color: #fff; background: rgba(255,255,255,.25); }
.btn-icon {
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: .75rem;
  font-size: 1.5rem;
  width: 2.5rem;
  height: 2.5rem;
  cursor: pointer;
  transition: background .2s, transform .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { background: rgba(255,255,255,.30); transform: scale(1.1); }
.btn-icon-admin { text-decoration: none; font-size: 1.1rem; opacity: .7; }
.btn-icon-admin:hover { opacity: 1; }

/* ═══════════════════════════════════════════════════════════════
   Inici
═══════════════════════════════════════════════════════════════ */
.home-main {
  flex: 1;
  padding: 1.5rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
.home-subtitle { text-align: center; font-size: 1.15rem; font-weight: 700; color: var(--c-primary); }
.topics-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.topic-card {
  background: var(--c-card);
  border-radius: var(--r);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform .2s, border-color .2s, box-shadow .2s;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.topic-card:hover { transform: translateY(-4px); border-color: var(--c-primary); box-shadow: var(--shadow-lg); }
.topic-card-title { font-family: var(--ff-display); font-size: 1.2rem; color: var(--c-primary); }
.topic-card-desc  { font-size: .9rem; color: var(--c-muted); }
.topic-card-meta  { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .25rem; }
.badge {
  font-size: .75rem;
  font-weight: 700;
  padding: .2rem .5rem;
  border-radius: 999px;
  background: var(--c-border);
  color: var(--c-primary-d);
}
.badge-easy   { background: #D1FAE5; color: #065F46; }
.badge-medium { background: #FEF3C7; color: #92400E; }
.badge-hard   { background: #FEE2E2; color: #991B1B; }
.topic-skeleton {
  height: 130px;
  border-radius: var(--r);
  background: linear-gradient(90deg, #E9D5FF 25%, #DDD6FE 50%, #E9D5FF 75%);
  background-size: 200%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 0% { background-position: 200%; } 100% { background-position: -200%; } }
.app-footer { text-align: center; padding: .75rem; font-size: .8rem; }
.footer-link { color: var(--c-muted); text-decoration: none; }
.footer-link:hover { color: var(--c-primary); }

/* ═══════════════════════════════════════════════════════════════
   Intro
═══════════════════════════════════════════════════════════════ */
.btn-back {
  background: none;
  border: none;
  color: var(--c-primary);
  font-family: var(--ff-body);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  padding: .25rem 0;
  align-self: flex-start;
}
.btn-back:hover { text-decoration: underline; }
.btn-back-lb { color: #fff; }
.btn-back-lb:hover { opacity: .8; }
.intro-header {
  background: var(--c-primary);
  color: #fff;
  border-radius: var(--r);
  padding: 1.25rem 1.5rem;
}
.intro-header h2 { font-family: var(--ff-display); font-size: 1.6rem; }
.intro-header p  { margin-top: .5rem; opacity: .85; font-size: .95rem; }
.intro-body {
  background: var(--c-card);
  border-radius: var(--r);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  font-size: 1rem;
  line-height: 1.75;
  max-height: 38dvh;
  overflow-y: auto;
}
.markdown-content h3 { font-size: 1.05rem; margin: 1rem 0 .4rem; color: var(--c-primary-d); }
.markdown-content p  { margin: .4rem 0; }
.markdown-content ul { padding-left: 1.5rem; margin: .4rem 0; }
.markdown-content strong { color: var(--c-primary-d); }

/* ═══════════════════════════════════════════════════════════════
   Quiz
═══════════════════════════════════════════════════════════════ */
.quiz-topbar {
  background: var(--c-primary);
  padding: .75rem 1rem .5rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.quiz-progress-wrap { background: rgba(255,255,255,.25); border-radius: 999px; height: .5rem; overflow: hidden; }
.quiz-progress-bar  { height: 100%; background: #fff; border-radius: 999px; transition: width .4s ease; width: 0%; }
.quiz-meta { display: flex; justify-content: space-between; color: rgba(255,255,255,.9); font-size: .85rem; font-weight: 700; }
.quiz-body { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 1.5rem 1rem; }
.question-card {
  background: var(--c-card);
  border-radius: var(--r);
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  transition: opacity .25s ease, transform .25s ease;
}
.question-card.fade-out { opacity: 0; transform: translateX(-24px); }
.question-text { font-size: 1.05rem; font-weight: 700; line-height: 1.6; }
.options-list  { display: flex; flex-direction: column; gap: .65rem; }
.option-btn {
  background: var(--c-bg);
  border: 2px solid var(--c-border);
  border-radius: .9rem;
  padding: .85rem 1rem;
  font-family: var(--ff-body);
  font-size: 1rem;
  font-weight: 600;
  color: var(--c-text);
  text-align: left;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .15s;
  display: flex;
  align-items: center;
  gap: .75rem;
}
.option-btn:hover:not(:disabled) { background: #EDE9FE; border-color: var(--c-primary); transform: translateX(4px); }
.opt-letter {
  min-width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: .85rem;
  flex-shrink: 0;
}
.option-btn.correct { background: #D1FAE5; border-color: var(--c-success); animation: pop .3s ease; }
.option-btn.correct .opt-letter { background: var(--c-success); }
.option-btn.incorrect { background: #FEE2E2; border-color: var(--c-error); animation: shake .4s ease; }
.option-btn.incorrect .opt-letter { background: var(--c-error); }
.option-btn.reveal-correct { background: #D1FAE5; border-color: var(--c-success); opacity: .8; }
.option-btn:disabled { cursor: default; }
@keyframes pop   { 0% { transform: scale(1); } 40% { transform: scale(1.04); } 100% { transform: scale(1); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-6px); } 60% { transform: translateX(6px); } }

/* ═══════════════════════════════════════════════════════════════
   Resultats
═══════════════════════════════════════════════════════════════ */
.results-inner { align-items: center; text-align: center; }
.result-header  { width: 100%; }
.score-bubble {
  width: 9rem; height: 9rem;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  box-shadow: var(--shadow-lg);
  animation: pop-in .5s ease;
}
@keyframes pop-in { 0% { transform: scale(0); } 70% { transform: scale(1.1); } 100% { transform: scale(1); } }
.score-number { font-family: var(--ff-display); font-size: 2.8rem; line-height: 1; }
.score-label  { font-size: .8rem; opacity: .85; }
.stars          { font-size: 2.5rem; margin: .5rem 0; letter-spacing: .1em; }
.result-message { font-size: 1.25rem; font-weight: 800; color: var(--c-primary); }
.result-stats   { display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; width: 100%; }
.stat-box { background: var(--c-card); border-radius: var(--r); padding: .9rem 1.25rem; box-shadow: var(--shadow); min-width: 110px; }
.stat-value { font-family: var(--ff-display); font-size: 1.6rem; color: var(--c-primary); }
.stat-label { font-size: .8rem; color: var(--c-muted); }
.result-rank {
  background: linear-gradient(135deg, var(--c-primary), var(--c-secondary));
  color: #fff;
  border-radius: var(--r);
  padding: .9rem 1.5rem;
  font-size: 1.1rem;
  font-weight: 800;
  width: 100%;
}
.result-review { width: 100%; display: flex; flex-direction: column; gap: .5rem; text-align: left; }
.review-title { font-weight: 800; font-size: 1rem; color: var(--c-primary-d); border-bottom: 2px solid var(--c-border); padding-bottom: .4rem; }
.review-item { background: var(--c-card); border-radius: .75rem; padding: .75rem 1rem; box-shadow: var(--shadow); border-left: 4px solid var(--c-border); font-size: .9rem; }
.review-item.ok { border-color: var(--c-success); }
.review-item.ko { border-color: var(--c-error); }
.review-item-q  { font-weight: 700; line-height: 1.4; margin-bottom: .3rem; }
.review-item-a  { color: var(--c-muted); font-size: .85rem; }
.review-item-a strong { color: var(--c-text); }
.result-actions { display: flex; gap: .75rem; flex-wrap: wrap; justify-content: center; width: 100%; }

/* ═══════════════════════════════════════════════════════════════
   Botons generals
═══════════════════════════════════════════════════════════════ */
.btn-primary, .btn-secondary {
  font-family: var(--ff-body);
  font-weight: 800;
  font-size: 1rem;
  border: none;
  border-radius: var(--r);
  padding: .8rem 1.5rem;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}
.btn-primary { background: var(--c-primary); color: #fff; box-shadow: 0 4px 0 var(--c-primary-d); }
.btn-primary:hover  { transform: translateY(-2px); box-shadow: 0 6px 0 var(--c-primary-d); }
.btn-primary:active { transform: translateY(1px);  box-shadow: 0 2px 0 var(--c-primary-d); }
.btn-secondary { background: var(--c-card); color: var(--c-primary); border: 2px solid var(--c-border); }
.btn-secondary:hover { background: var(--c-bg); }
.btn-big { width: 100%; font-size: 1.15rem; padding: 1rem; }

/* ═══════════════════════════════════════════════════════════════
   Rànquing
═══════════════════════════════════════════════════════════════ */
.lb-header {
  background: var(--c-primary);
  color: #fff;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.lb-title { font-family: var(--ff-display); font-size: 1.5rem; flex: 1; }
.lb-filter {
  border: 2px solid rgba(255,255,255,.4);
  border-radius: .5rem;
  padding: .4rem .75rem;
  background: rgba(255,255,255,.15);
  color: #fff;
  font-family: var(--ff-body);
  font-size: .9rem;
  cursor: pointer;
}
.lb-filter option { background: var(--c-primary-d); color: #fff; }
.lb-table-wrap { padding: 1rem; flex: 1; }
.lb-table { width: 100%; border-collapse: collapse; background: var(--c-card); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); }
.lb-table th { background: var(--c-primary); color: #fff; padding: .75rem 1rem; text-align: left; font-size: .85rem; font-weight: 800; }
.lb-table td { padding: .7rem 1rem; border-bottom: 1px solid var(--c-border); font-size: .9rem; }
.lb-table tr:last-child td { border-bottom: none; }
.lb-table tr:hover td { background: var(--c-bg); }
.lb-rank   { font-family: var(--ff-display); font-size: 1.2rem; color: var(--c-primary); }
.lb-rank-1 { color: #F59E0B; }
.lb-rank-2 { color: #9CA3AF; }
.lb-rank-3 { color: #B45309; }
.lb-score  { font-weight: 800; color: var(--c-primary); }
.lb-empty  { text-align: center; padding: 3rem; color: var(--c-muted); }

/* ═══════════════════════════════════════════════════════════════
   Confeti
═══════════════════════════════════════════════════════════════ */
.confetti-piece {
  position: fixed;
  top: -10px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  opacity: .9;
  animation: confetti-fall linear forwards;
  pointer-events: none;
  z-index: 9999;
}
@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110dvh) rotate(720deg); opacity: 0; }
}

/* ═══════════════════════════════════════════════════════════════
   Responsive
═══════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .app-title { font-size: 1.5rem; }
  .topics-grid { grid-template-columns: 1fr; }
  .score-bubble { width: 7rem; height: 7rem; }
  .score-number { font-size: 2.2rem; }
  .result-stats { gap: .5rem; }
  .stat-box { padding: .65rem .9rem; }
}
