/* Mates! Estils: colorit, arrodonit i gran. Pensat per a mòbil i tauleta. */
:root {
  --bg: #fff8e7;
  --ink: #2b2d42;
  --muted: #6b6f86;
  --card: #ffffff;
  --line: #ece3cc;
  --yellow: #ffca3a;
  --orange: #ff924c;
  --red: #ff595e;
  --green: #8ac926;
  --blue: #1982c4;
  --purple: #6a4c93;
  --right: #2e9e4f;
  --right-bg: #e4f8e9;
  --wrong: #e0313a;
  --wrong-bg: #ffe7e8;
  --accent: #ff924c;
  --accent-dark: #e0702a;
  --radius: 22px;
  --shadow: 0 6px 0 rgba(43, 45, 66, .10);
  --font: 'Fredoka', 'Nunito', 'Varela Round', ui-rounded, 'SF Pro Rounded', 'Segoe UI', system-ui, sans-serif;
}

/* Colors per curs */
.course-1, .theme-1 { --c: #ff595e; --c-dark: #d93a40; --c-soft: #ffe3e4; }
.course-2, .theme-2 { --c: #ff924c; --c-dark: #e0702a; --c-soft: #ffeadb; }
.course-3, .theme-3 { --c: #f5b700; --c-dark: #c99500; --c-soft: #fff4cc; }
.course-4, .theme-4 { --c: #6bb81c; --c-dark: #4f8f0e; --c-soft: #eaf7d8; }
.course-5, .theme-5 { --c: #1982c4; --c-dark: #11649a; --c-soft: #dcefff; }
.course-6, .theme-6 { --c: #8a5cc4; --c-dark: #6a4c93; --c-soft: #efe5fb; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.4;
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(rgba(255, 146, 76, .13) 2px, transparent 2.5px);
  background-size: 28px 28px;
  display: flex;
  flex-direction: column;
}
button { font-family: inherit; color: inherit; }
[hidden] { display: none !important; }
h1, h2 { line-height: 1.15; margin: 0; }
h1:focus { outline: none; }

/* Símbols de fons */
.bg-shapes { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.bg-shapes span {
  position: absolute; font-weight: 700; font-size: 64px; opacity: .10;
}
.bg-shapes span:nth-child(1) { top: 8%; left: 4%; color: var(--red); transform: rotate(-12deg); }
.bg-shapes span:nth-child(2) { top: 22%; right: 6%; color: var(--blue); }
.bg-shapes span:nth-child(3) { top: 48%; left: 2%; color: var(--green); transform: rotate(10deg); }
.bg-shapes span:nth-child(4) { top: 62%; right: 3%; color: var(--purple); }
.bg-shapes span:nth-child(5) { bottom: 6%; left: 10%; color: var(--orange); }
.bg-shapes span:nth-child(6) { bottom: 14%; right: 14%; color: var(--red); transform: rotate(-8deg); }
.bg-shapes span:nth-child(7) { top: 36%; left: 46%; color: var(--yellow); opacity: .18; }
.bg-shapes span:nth-child(8) { top: 4%; right: 34%; color: var(--green); }

/* Capçalera */
.top {
  position: relative; z-index: 1;
  padding: 14px 16px 0;
  display: flex; justify-content: center;
}
.logo {
  display: inline-flex; align-items: center; gap: 10px;
  background: none; border: 0; cursor: pointer; padding: 6px 10px; border-radius: 16px;
}
.logo:focus-visible { outline: 3px solid var(--blue); }
.logo-badge {
  width: 44px; height: 44px; border-radius: 14px;
  background: var(--yellow); color: #fff; font-size: 34px; font-weight: 700;
  display: grid; place-items: center; line-height: 1;
  box-shadow: 0 4px 0 #e0a800;
  transform: rotate(-6deg);
}
.logo-text { font-size: 30px; font-weight: 700; letter-spacing: .5px; color: var(--ink); }

main {
  position: relative; z-index: 1;
  flex: 1;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 8px 16px 32px;
}
.screen { animation: pop .25s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.hero { text-align: center; margin: 12px 0 22px; }
.mascot { font-size: 64px; line-height: 1; margin-bottom: 6px; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-4deg); } }
.hero h1 { font-size: clamp(30px, 7vw, 44px); font-weight: 700; }
.lead { color: var(--muted); font-size: 20px; margin: 8px 0 0; }
.center { text-align: center; }

/* Botons de curs */
.course-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
@media (min-width: 640px) { .course-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; } }
.course-btn {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 2px;
  padding: 16px 10px 14px;
  min-height: 150px;
  background: var(--card);
  border: 4px solid var(--c);
  border-radius: var(--radius);
  box-shadow: 0 7px 0 var(--c-dark);
  cursor: pointer;
  transition: transform .08s, box-shadow .08s;
}
.course-btn:hover { background: var(--c-soft); }
.course-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--c-dark); }
.course-btn:focus-visible { outline: 4px solid var(--ink); outline-offset: 3px; }
.course-num {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--c); color: #fff;
  font-size: 30px; font-weight: 700;
  display: grid; place-items: center;
}
.course-name { font-size: 22px; font-weight: 600; margin-top: 6px; }
.course-desc { font-size: 15px; color: var(--muted); line-height: 1.25; }

/* Quantitat */
.chip {
  display: inline-block; margin-bottom: 12px;
  padding: 6px 16px; border-radius: 999px;
  background: var(--c-soft); color: var(--c-dark);
  font-weight: 600; font-size: 17px;
}
.count-grid { display: grid; gap: 14px; grid-template-columns: 1fr; max-width: 560px; margin: 0 auto; }
@media (min-width: 640px) { .count-grid { grid-template-columns: repeat(3, 1fr); } }
.count-btn {
  display: flex; flex-direction: column; align-items: center;
  padding: 16px; border-radius: var(--radius);
  border: 0; color: #fff; cursor: pointer;
  font-size: 20px; font-weight: 600;
  transition: transform .08s, box-shadow .08s;
}
.count-btn .big { font-size: 52px; font-weight: 700; line-height: 1; }
.count-btn .tiny { font-size: 15px; font-weight: 500; opacity: .95; }
.count-btn.c1 { background: var(--green); box-shadow: 0 7px 0 #5f9410; }
.count-btn.c2 { background: var(--blue); box-shadow: 0 7px 0 #0f5f92; }
.count-btn.c3 { background: var(--purple); box-shadow: 0 7px 0 #4b3570; }
.count-btn:active { transform: translateY(5px); box-shadow: none; }
.count-btn:focus-visible { outline: 4px solid var(--ink); outline-offset: 3px; }
@media (max-width: 639px) {
  .count-btn { flex-direction: row; justify-content: center; gap: 12px; }
  .count-btn .tiny { display: none; }
}

.link-btn {
  background: none; border: 0; cursor: pointer;
  color: var(--muted); font-size: 18px; font-weight: 500;
  padding: 14px 10px; text-decoration: underline; text-underline-offset: 4px;
}
.link-btn:hover { color: var(--ink); }

/* Barra d'exercicis */
.ex-bar {
  position: sticky; top: 0; z-index: 5;
  margin: 0 -16px 10px; padding: 10px 16px;
  background: rgba(255, 248, 231, .94);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border-bottom: 3px solid var(--c-soft);
}
.ex-title { font-size: 22px; font-weight: 700; color: var(--c-dark); }
.progress {
  height: 16px; border-radius: 999px; background: #fff; border: 3px solid var(--c-soft);
  margin: 8px 0 4px; overflow: hidden;
}
.progress-fill { height: 100%; width: 0; background: var(--c); border-radius: 999px; transition: width .25s; }
.progress-text { font-size: 16px; color: var(--muted); font-weight: 500; }
.hint { color: var(--muted); font-size: 16px; margin: 4px 0 14px; }

/* Targetes d'exercici */
.ex-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; }
@media (min-width: 760px) { .ex-list { grid-template-columns: 1fr 1fr; } }
.ex-card {
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  transition: border-color .15s;
}
.ex-card.answered { border-color: var(--c); }
.ex-card.flash { animation: flash 1s ease-in-out 2; }
@keyframes flash { 50% { border-color: var(--orange); box-shadow: 0 0 0 6px rgba(255, 146, 76, .35); } }
.ex-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.ex-num {
  flex: none;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--c-soft); color: var(--c-dark);
  display: grid; place-items: center; font-weight: 700; font-size: 18px;
}
.answered .ex-num { background: var(--c); color: #fff; }
.ex-prompt {
  flex: 1;
  font-size: clamp(26px, 7vw, 32px); font-weight: 600;
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  font-variant-numeric: tabular-nums;
}
.qmark { color: var(--c); font-weight: 700; }

/* Fraccions apilades */
.frac {
  display: inline-flex; flex-direction: column; align-items: center;
  vertical-align: middle; line-height: 1; font-size: .78em; margin: 0 2px;
}
.frac .num { padding: 0 4px 3px; border-bottom: 3px solid currentColor; }
.frac .den { padding: 3px 4px 0; }

/* Opcions */
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt { position: relative; display: block; cursor: pointer; }
.opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.opt-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 64px; padding: 8px;
  border-radius: 16px;
  background: #f7f4ee;
  border: 3px solid #e6dfd0;
  box-shadow: 0 4px 0 #e6dfd0;
  font-size: 26px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: transform .06s, background .1s, border-color .1s, box-shadow .06s;
  user-select: none; -webkit-user-select: none;
}
.opt:hover .opt-body { background: var(--c-soft); border-color: var(--c); }
.opt input:focus-visible + .opt-body { outline: 4px solid var(--ink); outline-offset: 2px; }
.opt input:active + .opt-body { transform: translateY(3px); box-shadow: 0 1px 0 #e6dfd0; }
.opt input:checked + .opt-body {
  background: var(--c); border-color: var(--c-dark); color: #fff;
  box-shadow: 0 4px 0 var(--c-dark);
}

/* Botons */
.actions { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 26px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; cursor: pointer;
  font-size: 20px; font-weight: 600;
  padding: 14px 28px; min-height: 56px;
  transition: transform .08s, box-shadow .08s, background .15s;
}
.btn:focus-visible { outline: 4px solid var(--ink); outline-offset: 3px; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 6px 0 var(--accent-dark); }
.btn-primary:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--accent-dark); }
.btn-secondary { background: #fff; color: var(--ink); border: 3px solid var(--line); box-shadow: 0 5px 0 var(--line); }
.btn-secondary:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--line); }
.btn-xl { font-size: 24px; padding: 16px 40px; min-height: 66px; width: 100%; max-width: 420px; }
#btn-check { background: #b9b2a3; box-shadow: 0 6px 0 #9a937f; }
#btn-check.ready { background: var(--right); box-shadow: 0 6px 0 #1f7438; animation: wiggle 1.6s ease-in-out infinite; }
@keyframes wiggle { 0%, 80%, 100% { transform: none; } 85% { transform: rotate(-2deg) scale(1.03); } 92% { transform: rotate(2deg) scale(1.03); } }

/* Resultat */
.score-card {
  text-align: center;
  background: var(--card);
  border: 4px solid var(--c);
  border-radius: 28px;
  box-shadow: 0 8px 0 var(--c-dark);
  padding: 22px 16px 18px;
  margin: 10px 0 30px;
}
.score-emoji { font-size: 64px; line-height: 1; }
.score-msg { font-size: clamp(26px, 6.5vw, 36px); font-weight: 700; margin: 8px 0 4px; }
.score { font-size: 72px; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.score-ok { color: var(--c-dark); }
.score-sep { color: var(--muted); margin: 0 6px; font-weight: 500; }
.score-total { color: var(--muted); }
.stars { font-size: 46px; letter-spacing: 6px; }
.star { color: #e6dfd0; }
.star.on { color: var(--yellow); text-shadow: 0 3px 0 #e0a800; }
.score-detail { color: var(--muted); font-size: 18px; margin: 4px 0 0; }
.perfect .score-emoji { animation: bob 1.2s ease-in-out infinite; }

.review-title { font-size: 26px; margin: 0 0 14px; text-align: center; }
.review .ex-card.is-right { border-color: var(--right); background: var(--right-bg); }
.review .ex-card.is-wrong { border-color: var(--wrong); background: var(--wrong-bg); }
.review .ex-num { background: #fff; }
.review .is-right .ex-num { color: var(--right); }
.review .is-wrong .ex-num { color: var(--wrong); }
.review .ex-head { margin-bottom: 6px; }
.verdict {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-size: 24px; font-weight: 700;
}
.is-right .verdict { background: var(--right); }
.is-wrong .verdict { background: var(--wrong); }
.review-body { display: grid; gap: 4px; padding-left: 50px; }
.ans { font-size: 19px; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.ans b { font-size: 24px; }
.ans-right b { color: var(--right); }
.ans-wrong b { color: var(--wrong); }
.ans .frac { font-size: .8em; }

/* Diàleg */
.dialog {
  border: 0; border-radius: 26px; padding: 22px 20px 18px;
  width: min(92vw, 420px);
  text-align: center; color: var(--ink); font-family: var(--font);
  box-shadow: 0 10px 0 rgba(0, 0, 0, .12), 0 20px 50px rgba(0, 0, 0, .25);
}
.dialog::backdrop { background: rgba(43, 45, 66, .45); }
.dialog p { font-size: 21px; font-weight: 500; margin: 6px 0 18px; }
.dialog-emoji { font-size: 48px; line-height: 1; }
.dialog-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.dialog-actions .btn { flex: 1 1 140px; padding: 12px 16px; font-size: 19px; }

/* Peu */
.foot { position: relative; z-index: 1; text-align: center; color: var(--muted); font-size: 14px; padding: 18px 16px 24px; }

/* Confeti */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.confetti i {
  position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 380px) {
  body { font-size: 17px; }
  .opt-body { font-size: 23px; min-height: 58px; }
  .course-btn { min-height: 136px; }
}

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