/* Wspólne style całej platformy — jedno miejsce dla wszystkich stron.
 *
 * Przepisane 2026-09-23. Poprzednia wersja była różowo-cukierkowa: tekst pisany
 * jasnym różem na różowym tle (słabo czytelny), emoji po 100 px, skaczący maskotek,
 * latające gwiazdki w tle. Dla dziecka z 1. klasy może i zabawne, ale platforma jest
 * dla klas 1-8 — starsze dzieci i nauczyciele mają to czytać bez zmrużonych oczu.
 *
 * Zasady:
 *   • jeden zestaw zmiennych (kolory, promienie, cienie) — strony ich używają, nie
 *     wpisują własnych hexów;
 *   • tekst zawsze ciemny na jasnym tle (kontrast ≥ 4.5:1), kolor służy do akcentów,
 *     nie do pisania nim zdań;
 *   • ruch tylko wtedy, gdy coś znaczy (odsłonięcie odpowiedzi, konfetti za wynik);
 *   • emoji są ilustracją, nie bohaterem ekranu.
 */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap');

:root {
  /* tło i powierzchnie */
  --bg:          #F4F5FA;
  --bg-akcent:   #ECEDFA;      /* delikatna poświata za kartami */
  --karta:       #FFFFFF;
  --pole:        #F3F4FB;      /* wypełnienie pól, wierszy, chipów */
  --linia:       #E2E4F0;

  /* tekst */
  --tekst:       #1D1E2C;
  --tekst-mniej: #55596E;
  --tekst-slaby: #646880;    /* najjaśniejszy dopuszczalny tekst: 5.0:1 na polu, 5.5:1 na bieli */

  /* akcent główny */
  --akcent:      #5457D6;
  --akcent-ciem: #3F41AB;
  --akcent-jasn: #E9EAFC;

  /* stany */
  --ok:          #146B35;
  --ok-tlo:      #E6F5EC;
  --blad:        #C62B2B;
  --blad-tlo:    #FCEBEB;
  --uwaga:       #9A5B00;
  --uwaga-tlo:   #FDF1DF;
  --zloto:       #B45309;

  /* przedmioty — akcent kafla i nagłówka */
  --matematyka:  #5457D6;
  --angielski:   #0B6A69;

  --r-l: 20px;
  --r-m: 14px;
  --r-s: 10px;
  --cien:    0 2px 8px rgba(29, 30, 44, .06);
  --cien-l:  0 10px 30px rgba(29, 30, 44, .10);
  --focus:   0 0 0 3px rgba(84, 87, 214, .35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Nunito', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--tekst);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Jedna miękka poświata zamiast dwóch kolorowych kul i gwiazdek. */
body::before {
  content: '';
  position: fixed;
  inset: -20% 0 auto 0;
  height: 420px;
  background: radial-gradient(60% 100% at 50% 0%, var(--bg-akcent) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

:where(button, a, input, select, textarea):focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

#app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 640px;
  padding: 28px 20px 48px;
}

.screen { display: none; }
.screen.active { display: block; }

.card {
  background: var(--karta);
  border: 1px solid var(--linia);
  border-radius: var(--r-l);
  padding: 32px 30px 28px;
  box-shadow: var(--cien);
}

/* ══ EKRAN STARTOWY ══ */
#start { text-align: center; }

.mascot { font-size: 52px; display: block; margin-bottom: 10px; line-height: 1; }

.title {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -.01em;
  color: var(--tekst);
  margin-bottom: 6px;
}
.subtitle {
  font-size: 1rem;
  color: var(--tekst-mniej);
  font-weight: 600;
  margin-bottom: 18px;
}

.start-greeting {
  font-size: 1rem;
  font-weight: 700;
  color: var(--akcent);
  margin-bottom: 16px;
}

.info-chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 24px; }
.chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--pole); color: var(--tekst-mniej);
  font-weight: 700; font-size: .85rem; padding: 6px 12px; border-radius: 50px;
}

.start-actions { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }

/* ══ WYBÓR KATEGORII ══ */
#categories { text-align: center; }

.cat-header { margin-bottom: 20px; }
.cat-title { font-size: 1.45rem; font-weight: 800; color: var(--tekst); margin-bottom: 4px; }
.cat-subtitle { font-size: .95rem; font-weight: 600; color: var(--tekst-mniej); }
.cat-player-greeting { font-size: .9rem; font-weight: 700; color: var(--akcent); margin-bottom: 4px; }

.cat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.cat-card {
  --kolor: var(--akcent);        /* nadpisywane przez przedmiot: kolor kategorii */
  background: var(--karta);
  border: 1px solid var(--linia);
  border-radius: var(--r-m);
  padding: 16px 10px 14px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.cat-card:hover { border-color: var(--kolor); transform: translateY(-2px); box-shadow: var(--cien); }
.cat-card:active { transform: none; }
.cat-icon {
  font-size: 24px; line-height: 1;
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: color-mix(in srgb, var(--kolor) 14%, white);
}
.cat-name { font-weight: 800; font-size: .95rem; color: var(--tekst); }
.cat-count { font-size: .78rem; font-weight: 600; color: var(--tekst-slaby); }

.cat-footer { margin-top: 18px; text-align: center; }

/* ══ PYTANIE ══ */
.quiz-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; }
.progress-wrap { flex: 1; }
.progress-label { font-size: .85rem; font-weight: 700; color: var(--tekst-mniej); margin-bottom: 6px; }
.progress-bar-bg { height: 8px; background: var(--pole); border-radius: 50px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--akcent); border-radius: 50px; transition: width .3s ease; }

.quiz-meta { display: flex; align-items: center; gap: 8px; }
.cat-pill {
  --kolor: var(--akcent);
  font-size: .8rem; font-weight: 700; padding: 5px 11px; border-radius: 50px;
  background: color-mix(in srgb, var(--kolor) 12%, white); color: var(--kolor);
}
.timer-badge {
  display: flex; align-items: center; gap: 5px;
  font-size: .85rem; font-weight: 800; font-variant-numeric: tabular-nums;
  background: var(--pole); color: var(--tekst-mniej); padding: 5px 11px; border-radius: 50px;
}
.timer-badge.pulse { color: var(--akcent); }

.exit-btn {
  font-family: inherit; font-size: .8rem; font-weight: 700; padding: 6px 12px; border-radius: 50px;
  border: 1px solid var(--linia); cursor: pointer; background: var(--karta); color: var(--tekst-mniej);
  transition: all .15s ease; white-space: nowrap;
}
.exit-btn:hover { border-color: var(--blad); color: var(--blad); background: var(--blad-tlo); }

/* Licznik nad pytaniem powtarzał to, co pasek postępu — zostaje dla czytników ekranu. */
.question-counter {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.question-box {
  background: var(--akcent);
  border-radius: var(--r-m);
  padding: 30px 20px;
  text-align: center;
  margin-bottom: 20px;
}
.question-text { font-size: 2.4rem; font-weight: 800; color: #fff; letter-spacing: .02em; }

.image-box {
  --kolor: var(--akcent);
  background: color-mix(in srgb, var(--kolor) 8%, white);
  border: 1px solid color-mix(in srgb, var(--kolor) 30%, white);
  border-radius: var(--r-m);
  padding: 22px 20px 16px;
  text-align: center;
  margin-bottom: 20px;
}
.question-emoji { font-size: 84px; display: block; line-height: 1.1; }
.question-prompt { font-size: .95rem; font-weight: 700; color: var(--tekst-mniej); margin-top: 6px; }

.answers-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.answer-btn {
  font-family: inherit; font-size: 1.15rem; font-weight: 700;
  padding: 16px 12px; border-radius: var(--r-m);
  border: 2px solid var(--linia); background: var(--karta); color: var(--tekst);
  cursor: pointer; transition: border-color .12s ease, background .12s ease, color .12s ease;
}
.answer-btn:hover:not(:disabled) { border-color: var(--akcent); background: var(--akcent-jasn); }
.answer-btn:disabled { cursor: default; }
.answer-btn.correct, .answer-btn.reveal-correct {
  border-color: var(--ok); background: var(--ok-tlo); color: var(--ok);
}
.answer-btn.wrong { border-color: var(--blad); background: var(--blad-tlo); color: var(--blad); }

.feedback-overlay {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.feedback-emoji { font-size: 92px; animation: feedbackPop .4s ease both; }
@keyframes feedbackPop {
  0% { transform: scale(.5); opacity: 0; }
  60% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ══ WYNIK ══ */
#result { text-align: center; }

.unicorn-banner {
  display: none;
  background: var(--akcent-jasn);
  border: 1px solid var(--akcent);
  border-radius: var(--r-m);
  padding: 14px 16px;
  margin-bottom: 18px;
}
.unicorn-banner.visible { display: block; }
.unicorn-stars { display: none; }
.unicorn-emoji { font-size: 34px; display: block; line-height: 1; margin-bottom: 4px; }
.unicorn-title { font-size: 1rem; font-weight: 800; color: var(--akcent-ciem); }
.unicorn-sub { font-size: .85rem; font-weight: 600; color: var(--tekst-mniej); }

.result-mascot { font-size: 52px; display: block; line-height: 1; margin-bottom: 8px; }
.result-player-name { font-size: .9rem; font-weight: 700; color: var(--tekst-slaby); }
.result-cat-badge:empty { display: none; }
.result-cat-badge {
  display: inline-block; font-size: .8rem; font-weight: 700; color: var(--tekst-mniej);
  background: var(--pole); padding: 4px 12px; border-radius: 50px; margin-top: 6px;
}
.result-title { font-size: 1.6rem; font-weight: 800; color: var(--tekst); margin: 10px 0 4px; }
.result-subtitle { font-size: .98rem; font-weight: 600; color: var(--tekst-mniej); margin-bottom: 20px; }

.save-error {
  display: none; background: var(--blad-tlo); color: var(--blad); font-weight: 700; font-size: .9rem;
  padding: 10px 14px; border-radius: var(--r-m); margin-bottom: 16px;
}
.save-error.visible { display: block; }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 20px; }
.stat-card {
  background: var(--pole); border-radius: var(--r-m); padding: 14px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.stat-icon { font-size: 20px; line-height: 1; }
.stat-value { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { font-size: .75rem; font-weight: 700; color: var(--tekst-slaby); }
.correct-card { background: var(--ok-tlo); } .correct-card .stat-value { color: var(--ok); }
.wrong-card   { background: var(--blad-tlo); } .wrong-card .stat-value { color: var(--blad); }
.time-card    { background: var(--akcent-jasn); } .time-card .stat-value { color: var(--akcent-ciem); }

.score-bar-wrap { margin-bottom: 22px; }
.score-bar-label {
  display: flex; justify-content: space-between; font-size: .85rem; font-weight: 700;
  color: var(--tekst-mniej); margin-bottom: 6px;
}
.score-bar-bg { height: 10px; background: var(--pole); border-radius: 50px; overflow: hidden; }
.score-bar-fill { height: 100%; background: var(--akcent); border-radius: 50px; transition: width .8s ease; }

.summary-section { text-align: left; margin-bottom: 22px; }
.summary-title { font-size: 1rem; font-weight: 800; color: var(--tekst); margin-bottom: 10px; }
.summary-list { display: flex; flex-direction: column; gap: 6px; }
.summary-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border-radius: var(--r-s);
  background: var(--pole); font-weight: 700; font-size: .95rem;
}
.summary-row.ok  { background: var(--ok-tlo); }
.summary-row.err { background: var(--blad-tlo); }
.summary-num  { font-size: .8rem; color: var(--tekst-slaby); min-width: 20px; }
.summary-icon { font-size: .95rem; }
.summary-equation { flex: 1; color: var(--tekst); }
.eq-answer { color: var(--ok); font-weight: 800; }
.summary-wrong-ans { font-size: .8rem; font-weight: 700; color: var(--blad); }

.result-actions { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }

/* ══ RANKING ══ */
#leaderboard { text-align: center; }
.lb-header { margin-bottom: 18px; }
.lb-title { font-size: 1.45rem; font-weight: 800; color: var(--tekst); }
.lb-subtitle { font-size: .88rem; font-weight: 600; color: var(--tekst-slaby); }

.lb-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 20px; }
.lb-row {
  display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 10px 14px; border-radius: var(--r-m); background: var(--pole);
}
.lb-row.rank-1 { background: #FDF6E3; }
.lb-row.rank-2, .lb-row.rank-3 { background: var(--pole); }
.lb-row.lb-me { outline: 2px solid var(--akcent); }
.lb-rank { font-size: 1.2rem; min-width: 26px; text-align: center; }
.lb-rank-num {
  min-width: 26px; text-align: center; font-weight: 800; font-size: .95rem; color: var(--tekst-slaby);
}
.lb-info { flex: 1; min-width: 0; }
.lb-name { display: flex; align-items: center; gap: 6px; font-weight: 800; color: var(--tekst); }
.lb-you-tag {
  font-size: .68rem; font-weight: 800; background: var(--akcent); color: #fff;
  padding: 2px 8px; border-radius: 50px;
}
.lb-cat-tag { font-size: .68rem; font-weight: 700; padding: 2px 8px; border-radius: 50px; }
.lb-date { font-size: .75rem; font-weight: 600; color: var(--tekst-slaby); }
.lb-score-col { text-align: right; flex-shrink: 0; }
.lb-score-val { font-size: 1rem; font-weight: 800; color: var(--tekst); font-variant-numeric: tabular-nums; }
.lb-score-time { font-size: .75rem; font-weight: 600; color: var(--tekst-slaby); font-variant-numeric: tabular-nums; }
.lb-empty { padding: 32px 20px; color: var(--tekst-slaby); font-size: .95rem; font-weight: 700; }

/* ══ PRZYCISKI ══ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 24px; border-radius: var(--r-m); border: 1px solid transparent;
  font-family: inherit; font-size: 1rem; font-weight: 700;
  cursor: pointer; text-decoration: none; transition: all .15s ease;
}
.btn-primary { background: var(--akcent); color: #fff; }
.btn-primary:hover { background: var(--akcent-ciem); }
.btn-secondary { background: var(--akcent-jasn); color: var(--akcent-ciem); }
.btn-secondary:hover { background: #DCDEFA; }
.btn-home { background: var(--pole); color: var(--tekst-mniej); border-color: var(--linia); }
.btn-home:hover { background: #E8EAF4; }
.btn-danger { background: var(--blad-tlo); color: var(--blad); }
.btn-danger:hover { background: #F8DADA; }
.btn-sm { padding: 8px 16px; font-size: .88rem; }
/* wyłączony przycisk ma WYGLĄDAĆ na wyłączony — inaczej klika się w niego bez skutku */
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ══ POLA FORMULARZY ══ */
.name-label {
  display: block; font-size: .8rem; font-weight: 700; color: var(--tekst-mniej);
  margin-bottom: 6px;
}
.name-input {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--linia); border-radius: var(--r-m);
  font-family: inherit; font-size: 1rem; font-weight: 600; color: var(--tekst);
  background: var(--karta); outline: none; transition: border-color .15s, box-shadow .15s;
}
.name-input:focus { border-color: var(--akcent); box-shadow: var(--focus); }
.name-input::placeholder { color: var(--tekst-slaby); font-weight: 500; }
select.name-input { cursor: pointer; }

/* ══ WYJŚCIE Z QUIZU ══ */
.wyjscie-overlay {
  display: none; position: fixed; inset: 0; z-index: 60;
  background: rgba(29, 30, 44, .5);
  align-items: center; justify-content: center; padding: 16px;
}
.wyjscie-overlay.visible { display: flex; }
.wyjscie-okno {
  background: var(--karta); border-radius: var(--r-l); padding: 26px 24px 22px;
  max-width: 380px; width: 100%; text-align: center; box-shadow: var(--cien-l);
  animation: slideIn .2s ease both;
}
.wyjscie-emoji { font-size: 40px; line-height: 1; margin-bottom: 8px; }
.wyjscie-tytul { font-size: 1.2rem; font-weight: 800; color: var(--tekst); margin-bottom: 4px; }
.wyjscie-opis { font-size: .92rem; font-weight: 600; color: var(--tekst-mniej); margin-bottom: 18px; }
.wyjscie-przyciski { display: flex; flex-direction: column; gap: 8px; }

/* ══ DROBIAZGI ══ */
.slide-in { animation: slideIn .25s ease both; }
@keyframes slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; }

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

@media (max-width: 600px) {
  .cat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  body { font-size: 15px; }
  #app { padding: 20px 14px 36px; }
  .card { padding: 22px 18px 20px; }
  .title { font-size: 1.55rem; }
  .question-text { font-size: 2rem; }
  .question-emoji { font-size: 68px; }
  .answer-btn { font-size: 1.05rem; padding: 14px 8px; }
  .stats-grid { grid-template-columns: 1fr; }
  /* Na telefonie w jednym rzędzie nie mieszczą się: postęp, kategoria, czas i „Wyjdź" —
     postęp idzie na pełną szerokość, reszta pod nim. */
  .quiz-header { flex-wrap: wrap; }
  .progress-wrap { flex-basis: 100%; }
  .quiz-meta { width: 100%; justify-content: flex-end; }
  .quiz-meta .cat-pill { margin-right: auto; }
}
