/* ====== Matmator — styl ====== */

:root {
  --bg-top: #e8f4ff;
  --bg-bottom: #fff3e6;
  --ink: #2e3a4e;
  --ink-soft: #6b7a92;
  --card: #ffffff;
  --coral: #ff8a5c;
  --sun: #ffd449;
  --sky: #5bb8f5;
  --lilac: #b893f0;
  --mint: #4fd1a5;
  --rose: #f56b8d;
  --shadow: 0 6px 0 rgba(46, 58, 78, 0.15);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  font-family: "Baloo 2", "Comic Sans MS", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* ---- górny pasek ---- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 18px; }
.logo { font-weight: 800; font-size: 1.35rem; flex: 1; }
.stars, .streak { font-weight: 700; background: var(--card); padding: 6px 14px; border-radius: 999px; box-shadow: var(--shadow); }
.home-btn {
  font-size: 1.4rem;
  background: var(--card);
  border: none;
  border-radius: 50%;
  width: 46px; height: 46px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.home-btn:hover { transform: scale(1.1); }

/* ---- ekrany ---- */
.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 14px 18px 40px;
  text-align: center;
  max-width: 760px;
  margin: 0 auto;
}
.hidden { display: none !important; }
.welcome { font-size: clamp(1.6rem, 5vw, 2.2rem); margin: 8px 0 0; }

/* ---- poziomy ---- */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 18px;
  width: 100%;
}
.level-card {
  font-family: inherit;
  color: #fff;
  border: none;
  border-radius: 26px;
  padding: 24px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  box-shadow: 0 8px 0 rgba(46, 58, 78, 0.22);
  transition: transform 0.12s, box-shadow 0.12s;
}
.level-card:hover { transform: translateY(-3px); }
.level-card:active { transform: translateY(4px); box-shadow: 0 3px 0 rgba(46,58,78,0.22); }
.lv1 { background: var(--mint); }
.lv2 { background: var(--sky); }
.lv3 { background: var(--lilac); }
.lv-badge {
  background: rgba(255,255,255,0.3);
  border-radius: 50%;
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; font-weight: 800;
}
.lv-title { font-weight: 800; font-size: 1.5rem; }
.lv-desc { font-size: 0.98rem; opacity: 0.95; }
.lv-sample {
  font-family: "Andika", sans-serif;
  background: rgba(255,255,255,0.25);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 1rem;
  margin-top: 4px;
}

/* ---- gra ---- */
.game-head { display: flex; gap: 20px; align-items: baseline; }
.progress, .score-line { margin: 0; font-weight: 700; color: var(--ink-soft); }

.task-box {
  font-family: "Andika", sans-serif;
  font-weight: 700;
  font-size: clamp(2.4rem, 9vw, 4rem);
  background: var(--card);
  border-radius: 26px;
  padding: 26px 44px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 120px;
}

/* ułamki zwykłe */
.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.62em;
  line-height: 1.15;
  vertical-align: middle;
}
.frac .num { border-bottom: 4px solid var(--ink); padding: 0 8px; }
.frac .den { padding: 0 8px; }

/* pierwiastki */
.root { display: inline-flex; align-items: baseline; }
.root sup { font-size: 0.45em; margin-right: -4px; }

/* ---- pole odpowiedzi ---- */
.answer-display {
  font-family: "Andika", sans-serif;
  font-weight: 700;
  font-size: clamp(1.8rem, 7vw, 2.8rem);
  background: var(--card);
  border: 4px dashed var(--sky);
  border-radius: 20px;
  min-width: 220px;
  min-height: 72px;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, background 0.15s;
}
.answer-display.good { border-style: solid; border-color: var(--mint); background: #dff7ec; }
.answer-display.bad  { border-style: solid; border-color: var(--rose); background: #ffe9e4; animation: shake 0.35s; }

.cursor {
  display: inline-block;
  width: 3px; height: 1.2em;
  background: var(--sky);
  margin-left: 3px;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.feedback { min-height: 1.5em; margin: 0; font-weight: 800; font-size: 1.3rem; }
.feedback.good { color: #1f9d6f; }
.feedback.bad { color: var(--rose); }

/* ---- klawiatura ---- */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 86px);
  gap: 12px;
  justify-content: center;
}
.keypad button {
  font-family: "Andika", sans-serif;
  font-weight: 700;
  font-size: 1.7rem;
  color: var(--ink);
  background: var(--card);
  border: none;
  border-radius: 18px;
  height: 64px;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(46,58,78,0.18);
  transition: transform 0.08s, box-shadow 0.08s;
  user-select: none;
}
.keypad button:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(46,58,78,0.18); }
.key-back { background: var(--sun) !important; }
.key-ok {
  grid-column: span 2;
  background: var(--mint) !important;
  color: #fff !important;
  box-shadow: 0 6px 0 #3aa981 !important;
}
.key-ok:active { box-shadow: 0 2px 0 #3aa981 !important; }
.keypad button.key-hidden { visibility: hidden; }

/* ---- podsumowanie ---- */
.summary-card {
  background: var(--card);
  border-radius: 28px;
  padding: 30px clamp(20px, 5vw, 44px);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
  width: 100%;
}
.summary-card h2 { margin: 0; font-size: 1.9rem; }
.sum-stats { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; }
.sum-stat {
  border-radius: 20px;
  padding: 14px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 110px;
}
.sum-stat span { font-family: "Andika", sans-serif; font-weight: 700; font-size: 2.2rem; }
.sum-stat small { font-weight: 700; font-size: 0.95rem; }
.sum-stat.good { background: #dff7ec; color: #1f9d6f; }
.sum-stat.bad  { background: #ffe9e4; color: var(--rose); }
.sum-stat.pct  { background: #fff6d6; color: #a37b00; }

.mistake-list { width: 100%; text-align: left; }
.mistake-list h3 { margin: 0 0 8px; font-size: 1.2rem; }
.mistake-item {
  font-family: "Andika", sans-serif;
  font-size: 1.1rem;
  background: #f6f8fc;
  border-radius: 12px;
  padding: 8px 14px;
  margin-bottom: 6px;
}
.mistake-item b { color: #1f9d6f; }

/* ---- przyciski ---- */
.row { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; }
.pill-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff;
  background: var(--sky);
  border: none;
  border-radius: 999px;
  padding: 12px 24px;
  cursor: pointer;
  box-shadow: 0 5px 0 #3d92cc;
}
.pill-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #3d92cc; }
.pill-btn.ghost { background: var(--card); color: var(--ink); box-shadow: 0 5px 0 rgba(46,58,78,0.18); }
.next-btn {
  font-family: inherit;
  font-weight: 800;
  font-size: 1.3rem;
  color: #fff;
  background: var(--coral);
  border: none;
  border-radius: 999px;
  padding: 14px 34px;
  cursor: pointer;
  box-shadow: 0 8px 0 #d96a3f;
}
.next-btn:active { transform: translateY(5px); box-shadow: 0 3px 0 #d96a3f; }

/* ---- dostępność ---- */
button:focus-visible { outline: 4px solid var(--ink); outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media (max-width: 420px) {
  .keypad { grid-template-columns: repeat(3, 30vw); gap: 8px; }
  .task-box { padding: 18px 20px; }
}
