:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --card: #1e293b;
  --primary: #6366f1;
  --primary-2: #818cf8;
  --accent: #22c55e;
  --danger: #ef4444;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: #334155;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}
button { font-family: inherit; cursor: pointer; border: none; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 16px) 16px calc(90px + var(--safe-bottom));
  min-height: 100vh;
}
.hidden { display: none !important; }

/* --- Typografia --- */
h1 { font-size: 1.7rem; font-weight: 800; margin: 0 0 6px; letter-spacing: -0.02em; }
h2 { font-size: 1.25rem; font-weight: 700; margin: 0 0 12px; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* --- Karty / przyciski --- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 16px; border-radius: var(--radius);
  background: var(--primary); color: #fff; font-size: 1rem; font-weight: 700;
  transition: transform .08s ease, opacity .2s;
}
.btn:active { transform: scale(0.98); }
.btn.secondary { background: var(--surface-2); }
.btn.ghost { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn.accent { background: var(--accent); }
.btn:disabled { opacity: .5; }
.btn-lg { padding: 18px; font-size: 1.05rem; }

.hero-grad {
  background: linear-gradient(135deg, #6366f1, #a855f7);
  border-radius: 20px; padding: 24px; margin-bottom: 16px; border: none;
}
.hero-grad h1 { color: #fff; }
.hero-grad p { color: rgba(255,255,255,.9); margin: 0; }

.pill { display: inline-block; padding: 4px 12px; border-radius: 999px;
  background: var(--surface-2); font-size: .8rem; font-weight: 600; color: var(--muted); }
.pill.premium { background: #fbbf24; color: #422006; }

.stat-row { display: flex; gap: 10px; }
.stat { flex: 1; background: var(--surface); border-radius: 12px; padding: 14px; text-align: center; }
.stat .num { font-size: 1.5rem; font-weight: 800; color: var(--primary-2); }
.stat .lab { font-size: .75rem; color: var(--muted); }

/* --- Inputy --- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 15px; font-size: 1rem; border-radius: 12px;
  background: var(--surface); border: 1.5px solid var(--border); color: var(--text);
}
.field input:focus { outline: none; border-color: var(--primary); }
.err { color: var(--danger); font-size: .85rem; margin: 8px 0; }

/* --- Pytanie --- */
.qhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-bottom: 16px; }
.progress > i { display: block; height: 100%; background: var(--primary); transition: width .3s; }
.qtext { font-size: 1.1rem; font-weight: 600; margin-bottom: 18px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 12px; padding: 14px; margin-bottom: 10px; transition: all .15s;
}
.opt:active { transform: scale(0.99); }
.opt .letter { flex: 0 0 28px; height: 28px; border-radius: 8px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .9rem; }
.opt.selected { border-color: var(--primary); background: rgba(99,102,241,.12); }
.opt.correct { border-color: var(--accent); background: rgba(34,197,94,.14); }
.opt.correct .letter { background: var(--accent); color: #fff; }
.opt.wrong { border-color: var(--danger); background: rgba(239,68,68,.12); }
.opt.wrong .letter { background: var(--danger); color: #fff; }

.explain {
  background: rgba(99,102,241,.08); border: 1px solid rgba(99,102,241,.3);
  border-radius: 12px; padding: 14px; margin-top: 6px;
}
.explain .basis { font-size: .8rem; color: var(--primary-2); font-weight: 700; margin-bottom: 6px; }

/* --- Paywall --- */
.lock { text-align: center; padding: 30px 16px; }
.lock .big { font-size: 3rem; margin-bottom: 8px; }
.price { font-size: 2.2rem; font-weight: 800; color: var(--primary-2); }
.checklist { text-align: left; margin: 16px 0; }
.checklist div { padding: 6px 0; }

/* --- Egzamin --- */
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.1rem; }
.timer.warn { color: #fbbf24; } .timer.danger { color: var(--danger); }
.navgrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 16px; }
.navgrid button { aspect-ratio: 1; border-radius: 8px; background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); font-weight: 700; font-size: .85rem; }
.navgrid button.answered { background: var(--primary); color: #fff; border-color: var(--primary); }
.navgrid button.current { outline: 2px solid var(--primary-2); }

/* --- Dolna nawigacja --- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  max-width: 640px; margin: 0 auto;
}
.tab {
  flex: 1; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 0 8px; font-size: .7rem; font-weight: 600;
}
.tab-ico { font-size: 1.3rem; }
.tab.active { color: var(--primary-2); }

.toast {
  position: fixed; bottom: calc(90px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: #0b1220; border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 12px; font-size: .9rem; z-index: 100;
  opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90%;
}
.toast.show { opacity: 1; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--surface-2); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 1s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* odliczanie */
.countdown { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.cd-num { font-size: 2.4rem; font-weight: 800; color: var(--primary-2); line-height: 1; }
.cd-date { text-align: right; font-size: .85rem; font-weight: 600; }

/* lista sekcji */
.seclist { display: flex; flex-direction: column; gap: 8px; }
.secrow { display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; color: var(--text); font-size: 1rem; font-weight: 600; text-align: left; }
.secrow:active { transform: scale(0.99); }
.secn { background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 2px 10px; font-size: .85rem; }
.secbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px;
  background: rgba(99,102,241,.12); border: 1px solid rgba(99,102,241,.3); border-radius: 10px; padding: 8px 12px; font-weight: 700; font-size: .9rem; }
.secbar button { background: none; color: var(--primary-2); font-weight: 700; font-size: .85rem; }

/* historia */
.histrow { display: flex; justify-content: space-between; align-items: center;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 8px; }
.pill.ok { background: rgba(34,197,94,.2); color: var(--accent); }
.pill.no { background: var(--surface-2); color: var(--muted); }

/* konto */
.linkmuted { display: block; text-align: center; color: var(--muted); font-size: .85rem; margin-bottom: 12px; text-decoration: none; }
.danger-ghost { width: 100%; padding: 14px; border-radius: var(--radius); background: transparent;
  border: 1.5px solid var(--danger); color: var(--danger); font-weight: 700; font-size: .95rem; }
