:root {
  --bg: #f5f3ee;
  --card: #ffffff;
  --ink: #1d1c1a;
  --muted: #6d6a63;
  --line: #e4e0d7;
  --accent: #2f4bd8;
  --accent-ink: #ffffff;
  --accent-soft: #e6eafc;
  --ok: #1d8a4e;
  --ok-soft: #e1f4e8;
  --bad: #c8372d;
  --bad-soft: #fbe5e2;
  --warn-soft: #fff1d6;
  --warn: #8a5a00;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171b;
    --card: #212329;
    --ink: #eceae5;
    --muted: #9b9890;
    --line: #34363d;
    --accent: #7d92ff;
    --accent-ink: #10121a;
    --accent-soft: #262d4d;
    --ok: #4cc983;
    --ok-soft: #1c3527;
    --bad: #ff7a6e;
    --bad-soft: #3d2220;
    --warn-soft: #3a2f17;
    --warn: #f0c060;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100dvh;
}
#app, .login { max-width: 560px; margin: 0 auto; padding: 0 16px calc(28px + env(safe-area-inset-bottom)); }
h1 { font-size: 24px; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 0 10px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.loading { padding: 40vh 0; text-align: center; color: var(--muted); }

/* przyciski */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 600; border-radius: 12px; padding: 12px 16px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.big { width: 100%; padding: 16px; font-size: 18px; border-radius: 14px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn[disabled] { opacity: .5; }
.icon-btn {
  appearance: none; border: 0; background: transparent; color: var(--ink); width: 44px; height: 44px;
  border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn:active { background: var(--line); }
.icon-btn svg { width: 24px; height: 24px; }

/* górny pasek */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(12px + env(safe-area-inset-top)) 0 12px; }
.top .title { flex: 1; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 16px; }
.stack > * + * { margin-top: 10px; }

/* ekran startowy */
.hero { padding: 22px 18px; }
.hero p { margin: 4px 0 18px; }
.hero .btn + .btn { margin-top: 10px; }
.topic-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.topic-row:first-child { border-top: 0; padding-top: 0; }
.topic-row:last-child { padding-bottom: 0; }
.topic-row .name { flex: 1; min-width: 0; }
.topic-row .name b { display: block; font-weight: 600; font-size: 15px; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.ok > i { background: var(--ok); }
.prio { font-size: 12px; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 3px 8px; white-space: nowrap; }
.badge { font-size: 12px; font-weight: 600; border-radius: 999px; padding: 3px 8px; white-space: nowrap; }
.badge.wait { background: var(--warn-soft); color: var(--warn); }
.badge.off { background: var(--line); color: var(--muted); }
.result-row { display: flex; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.result-row:first-child { border-top: 0; padding-top: 0; }
.result-row:last-child { padding-bottom: 0; }

/* test */
.quiz-top { position: sticky; top: 0; background: var(--bg); z-index: 5; padding-bottom: 6px; }
.quiz-top .top { padding-bottom: 6px; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .25s; }
.qtopic { font-size: 13px; color: var(--muted); margin: 18px 0 6px; font-weight: 600; }
.qtext { font-size: 21px; line-height: 1.35; font-weight: 650; margin: 0 0 14px; letter-spacing: -.005em; }
.qimg { display: block; width: 100%; max-height: 300px; object-fit: contain; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 14px; padding: 8px; }
.answers { display: grid; gap: 10px; }
.answers.img { grid-template-columns: 1fr 1fr; }
.ans {
  appearance: none; font: inherit; text-align: left; color: var(--ink); width: 100%;
  background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 14px 14px;
  display: flex; align-items: center; gap: 12px; cursor: pointer; min-height: 56px; font-size: 17px;
}
.ans .key {
  flex: none; width: 28px; height: 28px; border-radius: 8px; background: var(--bg); color: var(--muted);
  font-size: 14px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.ans.sel { border-color: var(--accent); background: var(--accent-soft); }
.ans.sel .key { background: var(--accent); color: var(--accent-ink); }
.answers.img .ans { flex-direction: column; padding: 10px; gap: 8px; }
.answers.img .ans img { width: 100%; aspect-ratio: 1; object-fit: contain; }
.answers.img .ans .key { position: static; }

/* podsumowanie */
.score { text-align: center; padding: 22px 16px; }
.score .big-num { font-size: 52px; font-weight: 800; line-height: 1; letter-spacing: -.03em; }
.score .of { font-size: 20px; color: var(--muted); font-weight: 600; }
.score p { margin: 8px 0 0; }
.tstat { padding: 10px 0; border-top: 1px solid var(--line); }
.tstat:first-child { border-top: 0; padding-top: 0; }
.tstat:last-child { padding-bottom: 0; }
.tstat .row { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; }
.tstat .row b { font-weight: 600; }
.pct { font-weight: 700; white-space: nowrap; }
.pct.good { color: var(--ok); }
.pct.mid { color: var(--warn); }
.pct.low { color: var(--bad); }
.sticky-next {
  position: sticky; top: 0; z-index: 6; background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) 0 10px; margin-top: 14px;
}
.rev { padding: 14px; }
.rev + .rev { margin-top: 10px; }
.rev .meta { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.rev .qt { font-weight: 650; margin: 0 0 10px; font-size: 16px; }
.rev .qimg { max-height: 200px; }
.rev .ra { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); font-size: 15px; }
.rev .ra + .ra { margin-top: 6px; }
.rev .ra img { width: 64px; height: 64px; object-fit: contain; flex: none; }
.rev .ra .mark { margin-left: auto; font-weight: 800; flex: none; }
.rev .ra.correct { background: var(--ok-soft); border-color: var(--ok); }
.rev .ra.correct .mark { color: var(--ok); }
.rev .ra.wrong { background: var(--bad-soft); border-color: var(--bad); }
.rev .ra.wrong .mark { color: var(--bad); }
.rev .expl { margin: 10px 0 0; font-size: 14px; color: var(--muted); }
.tag { font-size: 12px; font-weight: 700; border-radius: 999px; padding: 2px 8px; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.empty { text-align: center; padding: 18px; color: var(--muted); }

/* ustawienia */
.field { display: flex; gap: 8px; }
input[type=text], input[type=password], input[type=search], select {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
select { width: auto; padding-right: 10px; }
.sugg { margin-top: 8px; }
.sugg .item { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px dashed var(--accent); border-radius: 12px; background: var(--accent-soft); }
.sugg .item + .item { margin-top: 6px; }
.sugg .item .name { flex: 1; min-width: 0; font-size: 15px; }
.set-topic { padding: 14px 0; border-top: 1px solid var(--line); }
.set-topic:first-child { border-top: 0; padding-top: 0; }
.set-topic:last-child { padding-bottom: 0; }
.set-topic .head { display: flex; gap: 8px; align-items: flex-start; }
.set-topic .head b { flex: 1; font-weight: 600; }
.set-topic .src { font-size: 13px; color: var(--muted); word-break: break-all; margin-top: 2px; }
.set-topic .ctrl { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.set-topic.off b { color: var(--muted); }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.note { font-size: 14px; color: var(--muted); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-size: 15px;
  max-width: calc(100% - 32px); z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.2);
}

/* logowanie */
.login { min-height: 100dvh; display: flex; align-items: center; }
.login-card { width: 100%; text-align: center; }
.login-card h1 { margin-top: 12px; }
.login-card input { margin: 18px 0 12px; text-align: center; }
.err { color: var(--bad); margin: 0 0 12px; }
.set-topic .ctrl { flex-wrap: nowrap; }
.set-topic .ctrl label, .set-topic .ctrl span { white-space: nowrap; }
.set-topic .ctrl select { min-width: 72px; }
.rev .meta { align-items: flex-start; }
.rev .meta .tag { flex: none; }
.sticky-next { box-shadow: 0 8px 12px -10px rgba(0,0,0,.25); }
