:root {
  --bg: #f5f3ff;
  --surface: #ffffff;
  --surface-2: #ede9fe;
  --text: #1e1b4b;
  --muted: #6b7280;
  --primary: #6d28d9;
  --primary-2: #8b5cf6;
  --on-primary: #ffffff;
  --good: #16a34a;
  --good-bg: #dcfce7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --gold: #d97706;
  --gold-bg: #fef3c7;
  --border: #ddd6fe;
  --shadow: 0 4px 14px rgb(76 29 149 / 0.12);
  --radius: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #13111c;
    --surface: #1e1b2e;
    --surface-2: #2a2540;
    --text: #ede9fe;
    --muted: #a1a1aa;
    --primary: #8b5cf6;
    --primary-2: #a78bfa;
    --good: #4ade80;
    --good-bg: #14532d;
    --bad: #f87171;
    --bad-bg: #7f1d1d;
    --gold: #fbbf24;
    --gold-bg: #78350f;
    --border: #3b3360;
    --shadow: 0 4px 14px rgb(0 0 0 / 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; margin-top: 8px; }
a { color: inherit; }

.screen { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }
.center { align-items: center; text-align: center; justify-content: center; min-height: 70dvh; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.title { font-size: 2.2rem; }
.big-emoji { font-size: 4rem; line-height: 1; }
.link { color: var(--primary); text-decoration: none; }

/* ----- przyciski ----- */
.btn {
  appearance: none; border: 2px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 14px; padding: 12px 18px; font: inherit; font-weight: 600; cursor: pointer;
  transition: transform .08s ease, background .15s ease; min-height: 48px;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .6; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.good { background: var(--good-bg); border-color: var(--good); color: var(--good); flex: 1; }
.btn.bad { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.row > .btn.bad { flex: 1; }
.row > .btn.bad.small { flex: 0; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 0.9rem; }
.btn.wide { width: 100%; }
.btn.icon { padding: 6px 10px; min-height: 44px; font-size: 1.3rem; }
.btn.listen { font-size: 1.4rem; padding: 18px 28px; }
.btn:focus-visible, .input:focus-visible, a:focus-visible { outline: 3px solid var(--primary-2); outline-offset: 2px; }

/* iOS Safari przybliża ekran przy polach < 16 px — wszystkie pola mają min. 16 px. */
.input {
  width: 100%; font: inherit; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--border);
  background: var(--surface); color: var(--text); min-height: 48px;
}
.input.right { border-color: var(--good); background: var(--good-bg); }
.input.wrong { border-color: var(--bad); background: var(--bad-bg); }
.input.mono { font-family: ui-monospace, Menlo, monospace; font-size: 16px; }
.input.cell { min-height: 38px; padding: 6px 8px; font-size: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; text-align: left; }
.field-label { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.check { display: inline-flex; align-items: center; gap: 4px; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
fieldset { border: 2px solid var(--border); border-radius: 14px; padding: 12px; margin: 0; }
legend { font-weight: 700; padding: 0 6px; }

.panel { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); width: 100%; }
.notice { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; }

/* ----- pasek postępu ----- */
.bar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: 99px; transition: width .4s ease; }
.bar.xp { height: 12px; background: rgb(255 255 255 / 0.25); }
.bar.xp .bar-fill { background: linear-gradient(90deg, #fde047, #fbbf24); }

/* ----- ekran główny ----- */
.hero {
  background: linear-gradient(135deg, #6d28d9, #a855f7);
  color: #fff; padding: calc(20px + env(safe-area-inset-top)) 16px 20px;
  border-radius: 0 0 28px 28px; box-shadow: var(--shadow);
}
.hero > * { max-width: 640px; margin-left: auto; margin-right: auto; }
.hero-row { display: flex; gap: 14px; align-items: center; }
.avatar { font-size: 3rem; background: rgb(255 255 255 / 0.2); border-radius: 50%; width: 72px; height: 72px; display: grid; place-items: center; flex: none; }
.hello { font-size: 1.4rem; font-weight: 800; }
.level { font-weight: 700; opacity: .9; margin-bottom: 4px; }
.xp-text { font-size: 0.8rem; opacity: .85; margin-top: 2px; }
.chips { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.chip { background: rgb(255 255 255 / 0.18); border-radius: 99px; padding: 6px 12px; font-size: 0.9rem; display: flex; gap: 4px; align-items: center; }
.chip.gold { background: #fbbf24; color: #78350f; }
.chip-icon { font-size: 1.1rem; }

.subject { display: flex; flex-direction: column; gap: 10px; }
.subject-title { font-size: 1.3rem; }
.chapter-card {
  display: flex; flex-direction: column; gap: 8px; text-decoration: none; background: var(--surface);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 2px solid transparent;
}
.chapter-card:active { border-color: var(--primary-2); }
.chapter-name { font-weight: 700; font-size: 1.1rem; }
.chapter-meta { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--muted); }
.chapter-meta .due { color: var(--gold); font-weight: 700; }
.chapter-meta .ok { color: var(--good); }

.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.badge { background: var(--surface); border-radius: 14px; padding: 10px 6px; text-align: center; opacity: .45; filter: grayscale(1); }
.badge.owned { opacity: 1; filter: none; box-shadow: var(--shadow); }
.badge-icon { font-size: 2rem; }
.badge-name { font-weight: 700; font-size: 0.8rem; }
.badge-desc { font-size: 0.7rem; color: var(--muted); }
.footer { text-align: center; padding-top: 12px; }

/* ----- wybór trybu ----- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg);
}
.topbar.parent { background: var(--surface); box-shadow: var(--shadow); }
.topbar-title { font-weight: 800; font-size: 1.1rem; flex: 1; }
.back { border: none; background: var(--surface-2); color: var(--text); width: 44px; height: 44px; border-radius: 50%; font-size: 1.2rem; display: grid; place-items: center; text-decoration: none; cursor: pointer; flex: none; }
.counter { font-weight: 700; color: var(--muted); min-width: 48px; text-align: right; }
.reward { display: flex; gap: 14px; align-items: center; background: var(--gold-bg); color: var(--text); border-radius: var(--radius); padding: 14px 16px; }
.reward-coins { font-size: 1.8rem; font-weight: 800; color: var(--gold); }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.mode-card { background: var(--surface); border-radius: var(--radius); padding: 18px 12px; text-align: center; text-decoration: none; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.mode-icon { font-size: 2.4rem; }
.mode-name { font-weight: 800; }
.mode-desc { font-size: 0.8rem; color: var(--muted); }

/* ----- nauka ----- */
.learn { padding-top: 4px; }
.mode-tag { align-self: center; background: var(--surface-2); padding: 4px 12px; border-radius: 99px; font-size: 0.8rem; font-weight: 700; color: var(--primary); }
.card-face { background: var(--surface); border-radius: 24px; padding: 20px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 18px; }
.prompt { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.prompt-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.prompt-row { display: flex; align-items: center; gap: 10px; justify-content: center; }
.prompt-text { font-size: 2.2rem; font-weight: 800; word-break: break-word; }
.hint { color: var(--muted); font-size: 1rem; }
/* nagłówek karty (wszystkie tryby): [🔊] pytanie | odpowiedź [🔊] — ADR-015 */
.card-head { display: flex; flex-direction: column; gap: 8px; }
.forms-row { display: flex; align-items: flex-end; gap: 8px; }
.forms { flex: 1; min-width: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px 10px; }
.form-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px; min-width: 0; }
.form-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; text-align: center; }
/* rozmiar zmniejsza wspólnie fitForms(), gdy słowa się nie mieszczą */
.form-value { font-size: 2.2rem; font-weight: 800; line-height: 1.15; white-space: nowrap; text-align: center; }
.btn.speak {
  flex: none; width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 50%;
  font-size: 1.2rem; display: grid; place-items: center; margin-bottom: 2px;
}
.btn.speak:disabled { opacity: .3; cursor: default; }
.speak-spacer { flex: none; width: 44px; }
.form-value.hidden-answer { color: var(--muted); opacity: .5; }
.form-value.revealed { color: var(--good); animation: pop .25s ease; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.form-value.tappable { cursor: pointer; }
.install-hint { border: 2px solid var(--primary-2); text-align: left; }
.steps { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.voice-box { border-top: 1px solid var(--border); padding-top: 10px; }
details summary { cursor: pointer; }
.center-text { text-align: center; }
.self-check { margin: 0; text-align: center; font-weight: 700; color: var(--muted); }
.answers { display: flex; flex-direction: column; gap: 8px; }
.answer { display: flex; justify-content: space-between; gap: 12px; background: var(--surface-2); border-radius: 12px; padding: 10px 14px; font-size: 1.2rem; }
.answer-label { color: var(--muted); font-size: 0.9rem; align-self: center; }
.verdict { font-weight: 800; font-size: 1.1rem; text-align: center; }
.verdict.good { color: var(--good); }
.verdict.bad { color: var(--bad); }
.options { display: grid; gap: 10px; }
.btn.option { text-align: left; font-size: 1.1rem; padding: 14px 16px; }
.btn.option.right { background: var(--good-bg); border-color: var(--good); }
.btn.option.wrong { background: var(--bad-bg); border-color: var(--bad); }

/* ----- podsumowanie ----- */
.summary h1 { font-size: 2rem; }
.score { font-size: 3rem; font-weight: 900; color: var(--primary); }
.xp-won { font-size: 1.3rem; font-weight: 800; color: var(--gold); }
.coins-won { font-size: 2.4rem; font-weight: 900; color: var(--gold); background: var(--gold-bg); border-radius: var(--radius); padding: 12px 24px; }
.coins-won .muted { font-size: 0.9rem; font-weight: 500; }
.new-badge { display: flex; gap: 10px; align-items: center; background: var(--surface); padding: 10px 16px; border-radius: 14px; box-shadow: var(--shadow); }

/* ----- panel rodzica ----- */
.tabs { display: flex; gap: 6px; padding: 10px 16px 0; max-width: 640px; margin: 0 auto; overflow-x: auto; }
.tab { padding: 8px 14px; border-radius: 99px; text-decoration: none; font-weight: 600; background: var(--surface); white-space: nowrap; }
.tab.active { background: var(--primary); color: var(--on-primary); }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; }
.stat-value { font-size: 1.3rem; font-weight: 800; }
.stat-label { font-size: 0.75rem; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.list-row { display: flex; gap: 8px; align-items: center; padding: 8px 10px; background: var(--surface-2); border-radius: 12px; }
.pill { font-size: 0.8rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--surface); }
.pill.good { color: var(--good); }
.pill.bad { color: var(--bad); }
.pill.gold { color: var(--gold); }
.badge-line { display: flex; flex-wrap: wrap; gap: 6px; font-size: 1.5rem; }
.mini-badge { opacity: .3; filter: grayscale(1); }
.mini-badge.owned { opacity: 1; filter: none; }
.table-wrap { overflow-x: auto; }
.table { border-collapse: collapse; width: 100%; }
.table th { text-align: left; font-size: 0.8rem; color: var(--muted); padding: 4px; }
.table td { padding: 3px; }
.modal { border: none; border-radius: var(--radius); padding: 18px; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
/* ----- podgląd rodzica ----- */
.preview-banner {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: repeating-linear-gradient(-45deg, #f59e0b, #f59e0b 12px, #fbbf24 12px, #fbbf24 24px);
  color: #451a03; font-weight: 700; font-size: 0.9rem;
}
.preview-banner .btn { background: #fff; color: #451a03; border-color: #451a03; text-decoration: none; }
.previewing .topbar { top: 52px; }
.preview-panel { border: 2px dashed var(--gold); }
.input.auto { width: auto; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.previewing .hero { padding-top: 20px; border-radius: 0 0 28px 28px; }

.form-error { background: var(--bad-bg); color: var(--bad); border: 2px solid var(--bad); border-radius: 12px; padding: 10px 14px; font-weight: 600; }
.form-error[hidden] { display: none; }
.modal.confirm { width: min(380px, calc(100vw - 32px)); padding: 0; }
.confirm-body { padding: 22px 20px 18px; text-align: center; align-items: center; }
.confirm-body p { margin: 0; }
.confirm-icon { font-size: 3rem; line-height: 1; }
.confirm-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: 6px; }
.confirm-actions .btn { width: 100%; }
.modal::backdrop { background: rgb(0 0 0 / 0.45); }

/* ----- toast, spinner, konfetti ----- */
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; z-index: 100; transition: opacity .3s; max-width: calc(100vw - 32px); }
.toast.error { background: var(--bad); color: #fff; }
.toast.ok { background: var(--good); color: #fff; }
.toast.out { opacity: 0; }
.spinner { width: 44px; height: 44px; border: 4px solid var(--surface-2); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetti i { position: absolute; top: -12px; width: 10px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
.confetti .c1 { background: #f43f5e; } .confetti .c2 { background: #fbbf24; } .confetti .c3 { background: #22c55e; }
.confetti .c4 { background: #3b82f6; } .confetti .c5 { background: #a855f7; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); } }
@media (prefers-reduced-motion: reduce) { .confetti { display: none; } * { transition: none !important; } }
