:root {
  --bg1: #6d5efc;
  --bg2: #a855f7;
  --card: #ffffff;
  --ink: #1f2140;
  --muted: #8a8db5;
  --ok: #22c55e;
  --bad: #ef4444;
  --listen: #3b82f6;
  --record: #f43f5e;
  --record-active: #dc2626;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  display: flex;
  justify-content: center;
  min-height: 100dvh;
}

.app {
  width: 100%;
  max-width: 480px;
  padding: env(safe-area-inset-top, 12px) 16px 24px;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px;
  color: #fff;
}

.brand { font-size: 1.5rem; font-weight: 800; letter-spacing: .5px; }

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

.tr-toggle {
  border: none;
  cursor: pointer;
  background: rgba(255,255,255,.2);
  color: #fff;
  font-size: 1.05rem;
  line-height: 1;
  padding: 9px 12px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
  opacity: .6;
  transition: opacity .15s, background .15s;
}
.tr-toggle[aria-pressed="true"] { opacity: 1; background: rgba(255,255,255,.4); box-shadow: 0 0 0 2px rgba(255,255,255,.5) inset; }

/* ---- Pasek profili dzieci ---- */
.profiles { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 4px 2px; }
.chip {
  border: none; cursor: pointer; background: rgba(255,255,255,.22); color: #fff;
  font-weight: 700; font-size: .95rem; padding: 8px 14px; border-radius: 999px;
  backdrop-filter: blur(6px); transition: background .15s, transform .1s;
}
.chip:active { transform: scale(.95); }
.chip.selected { background: #fff; color: var(--ink); box-shadow: 0 6px 16px rgba(0,0,0,.2); }
.chip.add { font-size: 1.1rem; padding: 8px 13px; opacity: .8; }
.chip-score { font-weight: 800; margin-left: 4px; }

/* ---- Odznaka postępu na kafelku ---- */
.cat-done { font-size: .82rem; color: #f59e0b; font-weight: 800; }

/* ---- Panel ustawień (modal) ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,20,40,.55);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--card); color: var(--ink); border-radius: 22px; width: 100%; max-width: 420px;
  padding: 18px; box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 1.3rem; }
.modal-close { border: none; background: #eef0fb; cursor: pointer; font-size: 1rem; border-radius: 999px; width: 34px; height: 34px; }
.modal-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 14px; }
.modal-list .muted { color: var(--muted); text-align: center; }
.prow { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #f6f7fd; border-radius: 14px; padding: 10px 12px; }
.prow-who { font-weight: 800; }
.prow-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.mini { border: none; cursor: pointer; background: #e6e8f5; color: var(--ink); font-weight: 700; font-size: .82rem; padding: 7px 10px; border-radius: 10px; }
.mini.del { background: #fde2e2; color: #b91c1c; }
.btn-add-profile { width: 100%; border: none; cursor: pointer; padding: 13px; border-radius: 14px; font-weight: 800; font-size: 1rem; background: linear-gradient(90deg, var(--bg1), var(--bg2)); color: #fff; }

.parent-prot { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  font-size: .85rem; font-weight: 700; padding: 10px 12px; border-radius: 12px; margin-bottom: 4px; }
.parent-prot.on { background: #e8f7ee; color: #15803d; }
.parent-prot.off { background: #fff4e5; color: #b45309; }
.parent-prot .mini { background: #ffffff; }

.level select {
  appearance: none;
  border: none;
  background: rgba(255,255,255,.2);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
}
.level select option { color: #1f2140; }

.card {
  background: var(--card);
  border-radius: 28px;
  padding: 24px 20px 20px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
}

.progress { width: 100%; text-align: center; }
.progress #progressText { font-size: .85rem; color: var(--muted); font-weight: 700; }
.bar { height: 8px; background: #eef0fb; border-radius: 999px; margin-top: 8px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--bg1), var(--bg2)); transition: width .3s ease; }

.emoji {
  font-size: 6rem;
  line-height: 1;
  margin-top: 12px;
  filter: drop-shadow(0 8px 12px rgba(0,0,0,.15));
  transition: transform .2s ease;
}
.emoji.pop { transform: scale(1.15); }

.word { font-size: 2.6rem; font-weight: 800; letter-spacing: 1px; }
.word .sense { font-size: 1rem; font-weight: 500; opacity: 0.55; letter-spacing: 0; }

.translation {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--muted);
  min-height: 1.4em;
  margin-top: -6px;
  opacity: 0;
  transition: opacity .15s ease;
}
.card:hover .translation,
.card.show-translation .translation { opacity: .85; }

/* ---- Widoki / scena ---- */
.stage { flex: 1; display: flex; flex-direction: column; margin-top: 8px; min-height: 0; }
.view { flex: 1; display: flex; flex-direction: column; }
.view[hidden] { display: none; }
.view-title { color: #fff; text-align: center; font-size: 1.05rem; font-weight: 800; margin: 4px 0 14px; }

/* ---- Siatka kategorii ---- */
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-bottom: 8px; }
.cat-tile {
  border: none; cursor: pointer; background: var(--card); border-radius: 20px;
  padding: 18px 12px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  box-shadow: 0 10px 24px rgba(0,0,0,.18); transition: transform .1s ease;
}
.cat-tile:active { transform: scale(.96); }
.cat-icon { font-size: 2.4rem; line-height: 1; }
.cat-name { font-weight: 800; color: var(--ink); text-align: center; }
.cat-count { font-size: .8rem; color: var(--muted); font-weight: 700; }

/* ---- Przycisk powrotu ---- */
.back-btn {
  align-self: flex-start; border: none; cursor: pointer;
  background: #eef0fb; color: var(--ink); font-weight: 700;
  padding: 8px 14px; border-radius: 999px; font-size: .9rem; margin-bottom: 4px;
}

/* ---- Podsumowanie sesji ---- */
.summary { justify-content: center; text-align: center; gap: 16px; }
.summary-emoji { font-size: 5rem; line-height: 1; }
.summary h2 { margin: 0; font-size: 1.6rem; }
.summary p { margin: 0; font-size: 1.15rem; color: var(--ink); }
.summary-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: 8px; }
.summary-actions button {
  border: none; cursor: pointer; padding: 14px; border-radius: 16px;
  font-size: 1.05rem; font-weight: 800;
}
#btnNextChunk { background: linear-gradient(90deg, var(--bg1), var(--bg2)); color: #fff; }
#btnNextChunk[hidden] { display: none; }
#btnToCats { background: #eef0fb; color: var(--ink); }

.result {
  min-height: 64px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 100%;
}
.result .recognized { color: var(--muted); font-size: .95rem; }
.result .verdict { font-size: 1.4rem; font-weight: 800; }
.result.ok .verdict { color: var(--ok); }
.result.bad .verdict { color: var(--bad); }

.actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
}

.btn {
  border: none;
  border-radius: 18px;
  padding: 20px;
  font-size: 1.3rem;
  font-weight: 800;
  color: #fff;
  cursor: pointer;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { filter: grayscale(.6) opacity(.6); cursor: default; }

.btn-listen { background: var(--listen); }
.btn-record { background: var(--record); }
.btn-record.recording {
  background: var(--record-active);
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,.5); }
  50% { box-shadow: 0 0 0 16px rgba(220,38,38,0); }
}

.nav { display: flex; gap: 12px; width: 100%; }
.nav-btn {
  flex: 1;
  border: 2px solid #e6e8f5;
  background: #fff;
  color: var(--ink);
  border-radius: 16px;
  padding: 16px;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
}
.nav-next { flex: 2; }
.nav-btn:active { background: #f4f5ff; }

.hint {
  color: rgba(255,255,255,.85);
  text-align: center;
  font-size: .85rem;
  margin-top: 14px;
  min-height: 1.2em;
}

/* ---------- Brama startowa: rodzic → dziecko ---------- */
body.gated { overflow: hidden; }

.gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
}

.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 22px;
  padding: 28px 22px 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
  text-align: center;
}

.gate-brand { font-size: 1.4rem; font-weight: 800; color: var(--bg1); margin-bottom: 10px; }
.gate-title { font-size: 1.35rem; margin: 6px 0 4px; }
.gate-sub { color: var(--muted); margin: 0 0 16px; font-size: .95rem; }

.gate-form { display: flex; flex-direction: column; gap: 12px; }
.gate-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.05rem;
  border: 2px solid #e6e6f2;
  border-radius: 14px;
  outline: none;
}
.gate-input:focus { border-color: var(--bg1); }
.gate-err { color: var(--bad); font-size: .9rem; }

.gate-btn {
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  background: var(--bg1);
  border: none;
  border-radius: 14px;
  cursor: pointer;
}
.gate-btn.ghost { background: #f1f0fb; color: var(--ink); margin-top: 14px; }

.gate-children { display: flex; flex-direction: column; gap: 10px; margin: 4px 0 4px; }
.gate-child {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  font-size: 1.1rem;
  background: #f7f6ff;
  border: 2px solid #ece9ff;
  border-radius: 16px;
  cursor: pointer;
  text-align: left;
}
.gate-child:active { transform: scale(.98); }
.gate-child-av { font-size: 1.6rem; }
.gate-child-name { font-weight: 600; }

.gate-logout {
  display: block;
  margin: 18px auto 0;
  background: none;
  border: none;
  color: var(--muted);
  font-size: .85rem;
  cursor: pointer;
  text-decoration: underline;
}

/* Nagłówek modala ustawień: wyloguj + zamknij */
.modal-head-actions { display: flex; align-items: center; gap: 8px; }
.modal-logout {
  background: #f1f0fb;
  border: none;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: .8rem;
  color: var(--ink);
  cursor: pointer;
}

/* Zarządzanie profilami na bramie */
.gate-manage-link {
  display: block;
  margin: 12px auto 0;
  background: none;
  border: none;
  color: var(--bg1);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
}
.gate-manage { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 4px; text-align: left; }
.gate-mrow {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: #f7f6ff;
  border: 2px solid #ece9ff;
  border-radius: 14px;
}
.gate-mrow-who { font-weight: 600; font-size: 1.05rem; }
.gate-mrow-actions { display: flex; flex-wrap: wrap; gap: 6px; }
