:root {
  --bg: #f4f7ff;
  --card: #ffffff;
  --ink: #29304d;
  --accent: #5b6ee8;
  --accent-dark: #3f4fc7;
  --good: #33b26a;
  --bad: #e8555b;
  --muted: #9aa2c0;
  --radius: 20px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: var(--card);
  box-shadow: 0 2px 10px rgba(41, 48, 77, 0.06);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-size: 1.3rem;
  font-weight: 800;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: #eef0ff;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-btn:active { background: #dde1fb; }

.points {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-dark);
  background: #eef0ff;
  padding: 6px 14px;
  border-radius: 999px;
  white-space: nowrap;
}

@media (max-width: 400px) {
  .topbar { padding: 12px 14px; }
  .brand { font-size: 1.1rem; }
  .topbar-actions { gap: 6px; }
  .icon-btn { width: 34px; height: 34px; font-size: 1.05rem; border-radius: 10px; }
  .points { font-size: .95rem; padding: 5px 10px; }
}

/* --- nakładki: menu zadań, statystyki, powód pominięcia --- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(41, 48, 77, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.overlay.hidden { display: none; }

.overlay-panel {
  background: var(--card);
  width: 100%;
  max-width: 480px;
  max-height: 82vh;
  border-radius: 24px 24px 0 0;
  padding: 20px;
  overflow-y: auto;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, .15);
}

.overlay-panel.small { max-height: 60vh; }

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.overlay-header h2 { margin: 0; font-size: 1.25rem; }

.menu-progress { margin-bottom: 16px; }

.progress-line { font-weight: 700; margin-bottom: 6px; }

.progress-bar {
  height: 10px;
  background: #eef0ff;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  border: 2px solid #eef0ff;
  background: white;
  border-radius: 14px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 1rem;
}

.menu-item-icon { font-size: 1.4rem; }
.menu-item-text small { color: var(--muted); }

.menu-item-done { border-color: #bfe9d3; background: #f2fbf6; }
.menu-item-current { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(91, 110, 232, 0.15); }
.menu-item-skipped { border-color: #ffe08a; background: #fffbea; }

.stats-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stats-item {
  border-bottom: 1px solid #eef0ff;
  padding-bottom: 12px;
}

.stats-item-title { font-weight: 800; margin-bottom: 4px; }

.original-badge {
  font-size: .75rem;
  font-weight: 700;
  color: var(--accent-dark);
  background: #eef0ff;
  border-radius: 999px;
  padding: 2px 8px;
  vertical-align: middle;
}
.stats-item-row { font-size: .92rem; color: var(--ink); opacity: .85; }

.reason-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.reason-btn {
  padding: 14px 10px;
  border-radius: 14px;
  border: 2px solid #eef0ff;
  background: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.reason-btn:active { background: #eef0ff; }

.exchange-summary {
  text-align: center;
  padding: 18px 12px 22px;
}

.exchange-summary .exchange-points {
  font-size: 1rem;
  color: var(--muted);
  font-weight: 700;
}

.exchange-summary .exchange-minutes {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--accent-dark);
  margin: 6px 0 4px;
}

.exchange-summary .exchange-rate {
  font-size: .85rem;
  color: var(--muted);
}

.exchange-total {
  text-align: center;
  font-weight: 700;
  color: var(--ink);
  background: #f4f6ff;
  border-radius: 999px;
  padding: 8px 16px;
  margin-bottom: 18px;
  display: block;
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
}

.exchange-log {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.exchange-log h3 {
  font-size: 1rem;
  margin: 0 0 10px;
}

.exchange-log-item {
  display: flex;
  justify-content: space-between;
  font-size: .9rem;
  color: var(--ink);
  background: #f9fafc;
  border-radius: 10px;
  padding: 8px 12px;
}

.exchange-log-item span:last-child { color: var(--muted); }

.stats-summary-box {
  background: #f4f6ff;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
  font-weight: 700;
  text-align: center;
}

main#app {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 100px;
}

.review-banner {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-dark);
  background: #eef0ff;
  border: 2px solid #ccd2f7;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 14px;
}

.exercise-content.review-locked {
  pointer-events: none;
  opacity: 0.85;
}

.summary-banner {
  font-size: 0.95rem;
  font-weight: 700;
  color: #b5730a;
  background: #fff4e0;
  border: 2px solid #ffd8a0;
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 14px;
}

.exercise-title {
  font-size: 1.4rem;
  font-weight: 800;
  margin: 0 0 4px;
}

.exercise-instructions {
  font-size: 1.1rem;
  color: var(--ink);
  background: #fff8e1;
  border: 2px solid #ffe08a;
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 22px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(41, 48, 77, 0.08);
  padding: 20px;
}

/* --- shapes grid (color-shapes / color-by-code) --- */
.shapes-grid, .legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center;
}

.legend-row {
  margin-bottom: 20px;
  gap: 14px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f4f6ff;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
}

.legend-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-block;
  border: 2px solid rgba(0,0,0,.12);
}

.shape-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.shape-label {
  font-size: .95rem;
  font-weight: 700;
  color: var(--muted);
}

svg.shape {
  transition: transform .12s ease;
}

.shape-wrap.clickable svg.shape {
  cursor: pointer;
}

svg.shape:active { transform: scale(0.94); }

.palette {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 140px;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,.15);
  cursor: pointer;
}

.swatch.selected {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

/* --- find-match / odd-one-out / match-pairs (emoji tiles) --- */
.emoji-ref {
  text-align: center;
  margin-bottom: 20px;
}

.emoji-ref .emoji-tile {
  display: inline-flex;
}

.tile-row, .pairs-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
}

.pairs-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  max-width: 480px;
  margin: 0 auto;
}

.emoji-tile {
  width: 84px;
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  background: #f4f6ff;
  border: 3px solid transparent;
  border-radius: 16px;
  cursor: pointer;
  user-select: none;
  transition: transform .12s ease, border-color .12s ease;
}

.emoji-tile:active { transform: scale(0.94); }

.emoji-tile.selected {
  border-color: var(--accent);
}

.emoji-tile.correct {
  border-color: var(--good);
  background: #e8faf0;
}

.emoji-tile.wrong {
  border-color: var(--bad);
  background: #fdeceb;
}

.emoji-tile.matched {
  border-color: var(--good);
  background: #e8faf0;
  opacity: .55;
  cursor: default;
}

.select-all-row .emoji-tile { font-size: 2.8rem; }
.select-all-row .emoji-tile svg.shape { width: 44px; height: 44px; }

.cluster-tile {
  width: auto;
  height: auto;
  min-width: 84px;
  min-height: 84px;
  padding: 8px;
}

.tile-cluster {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  max-width: 100px;
  justify-content: center;
  align-items: center;
}

.tile-cluster span { font-size: 1.3rem; line-height: 1; }

/* --- find-differences (znajdź różnice) --- */
.diff-label {
  text-align: center;
  font-weight: 700;
  color: var(--muted);
  margin: 4px 0 10px;
}

.diff-row { margin-bottom: 20px; }
.diff-row .emoji-tile { font-size: 2.4rem; }

.static-tile {
  cursor: default;
  opacity: .85;
}
.static-tile:active { transform: none; }

/* --- find-match-set (znajdź tę samą kartę) --- */
.matchset-reference {
  text-align: center;
  padding: 16px;
  background: #fff8e1;
  border: 2px solid #ffe08a;
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.matchset-label {
  font-weight: 800;
  margin-bottom: 10px;
}

.matchset-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.matchset-grid svg.shape {
  width: 34px;
  height: 34px;
}

.matchset-options {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.matchset-card {
  border: 3px solid #eef0ff;
  border-radius: 16px;
  padding: 12px;
  background: white;
  cursor: pointer;
}

.matchset-card.selected { border-color: var(--accent); }

/* --- count-items (policz na obrazku) --- */
.count-scene {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 2rem;
  justify-content: center;
  padding: 18px;
  background: #f4f6ff;
  border-radius: var(--radius);
  margin-bottom: 22px;
}

.count-question { margin-bottom: 22px; }
.count-question-text { font-weight: 700; margin-bottom: 10px; }

.count-number-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.count-number-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #eef0ff;
  font-weight: 800;
  cursor: pointer;
}

.count-number-btn.selected {
  background: var(--accent);
  color: white;
}

/* --- pattern-complete (dokończ rytm) --- */
.pattern-seq {
  margin-bottom: 28px;
}

.pattern-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 16px;
}

.pattern-row .emoji-tile {
  width: 50px;
  height: 50px;
  font-size: 1.5rem;
  border-radius: 10px;
}

.pattern-given {
  opacity: .55;
  cursor: default !important;
}

.pattern-blank {
  border: 2px dashed var(--muted) !important;
  background: #f9fafc;
  color: var(--muted);
}

.pattern-blank.filled {
  border-style: solid !important;
  color: var(--ink);
  background: #f4f6ff;
}

.pattern-palette {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.pattern-choice {
  width: 56px;
  height: 56px;
  font-size: 1.8rem;
}

.odd-group {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 12px;
  border-radius: 16px;
  background: #f9fafc;
  margin-bottom: 14px;
}

.bottombar {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 14px 16px;
  background: var(--card);
  box-shadow: 0 -2px 10px rgba(41, 48, 77, 0.08);
}

.btn {
  font-size: 1.05rem;
  font-weight: 800;
  padding: 14px 28px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  min-width: 140px;
}

@media (max-width: 420px) {
  .bottombar { gap: 8px; padding: 10px; }
  .btn { min-width: 0; flex: 1; padding: 12px 10px; font-size: .95rem; }
}

.btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:not(:disabled):active { background: var(--accent-dark); }

.btn-secondary {
  background: #eef0ff;
  color: var(--accent-dark);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  box-shadow: inset 0 0 0 2px #e4e7f7;
}

.btn-ghost:not(:disabled):active { color: var(--ink); }

.feedback {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 800;
  margin-top: 18px;
  min-height: 1.4em;
}

.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

/* --- trace-path (rysowanie po śladzie) --- */
.trace-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.trace-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.trace-canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 420px;
  border-radius: 16px;
  overflow: hidden;
  background: #fff;
  box-shadow: inset 0 0 0 2px #e4e7f7;
}

.trace-guide, .trace-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.trace-guide { pointer-events: none; }

.guide-path {
  fill: none;
  stroke: #c7cbe8;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.start-dot { fill: var(--good); }

.mirror-axis {
  stroke: #c7cbe8;
  stroke-width: 2;
  stroke-dasharray: 6 6;
}

.mirror-static {
  fill: #eef0ff;
  stroke: var(--ink);
  stroke-width: 4;
}

.trace-canvas {
  touch-action: none;
  cursor: crosshair;
}

.trace-progress {
  display: block;
  width: fit-content;
  margin: 0 auto 16px;
  font-weight: 800;
  color: var(--accent-dark);
  background: #eef0ff;
  border-radius: 999px;
  padding: 8px 18px;
}

.trace-progress.all-done {
  color: var(--good);
  background: #e8faf0;
}

.trace-item.trace-done .trace-canvas-wrap {
  box-shadow: inset 0 0 0 3px var(--good);
}

@keyframes tracePulse {
  0%, 100% { box-shadow: inset 0 0 0 3px transparent; }
  50% { box-shadow: inset 0 0 0 4px var(--accent); }
}

.trace-item.trace-highlight .trace-canvas-wrap {
  animation: tracePulse 0.55s ease-in-out 2;
}

.trace-item.trace-done .trace-canvas-wrap::after {
  content: "✓";
  position: absolute;
  top: 8px;
  right: 10px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--good);
  color: white;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.btn-clear-trace {
  border: none;
  background: #eef0ff;
  color: var(--accent-dark);
  font-weight: 700;
  font-size: .9rem;
  padding: 6px 16px;
  border-radius: 999px;
  cursor: pointer;
}

.home-screen {
  text-align: center;
  padding: 50px 20px;
}

.home-emoji { font-size: 4rem; margin-bottom: 10px; }
.home-screen h2 { font-size: 1.6rem; margin: 0 0 18px; }

.home-progress-label { font-weight: 700; margin-bottom: 8px; }
.home-progress-bar { max-width: 280px; margin: 0 auto; }

.home-sub { color: var(--muted); margin: 18px 0 0; }

.home-btn {
  margin-top: 30px;
  min-width: 200px;
  font-size: 1.2rem;
  padding: 18px 32px;
}

.summary {
  text-align: center;
  padding: 40px 20px;
}

.summary h2 { font-size: 1.8rem; }
.summary .big-points { font-size: 3rem; margin: 10px 0; }

.skipped-box {
  margin-top: 28px;
  padding: 18px;
  background: #fff8e1;
  border: 2px solid #ffe08a;
  border-radius: var(--radius);
  text-align: left;
}

.skipped-box h3 {
  margin: 0 0 12px;
  text-align: center;
  font-size: 1.1rem;
}

.skipped-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.btn-skipped-item {
  text-align: left;
  background: white;
  border: 2px solid #eee0b0;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}

.btn-skipped-item:active { background: #fdf3d4; }

.parent-email-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.parent-email-row input {
  flex: 1;
  min-width: 160px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 2px solid #e4e7f7;
  font-size: 1rem;
}

.report-context {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 10px;
}

.report-textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 16px;
  border: 2px solid #e4e7f7;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  margin-bottom: 10px;
  box-sizing: border-box;
}

.report-status {
  font-size: 0.9rem;
  font-weight: 700;
  min-height: 1.3em;
  margin-bottom: 8px;
}

.report-status.ok { color: #1d9a5f; }
.report-status.error { color: #d1453b; }
