: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:
    radial-gradient(1100px 700px at 85% -10%, rgba(99,102,241,.14), transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(168,85,247,.08), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  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; }
:focus-visible { outline: 2px solid var(--primary-2); outline-offset: 2px; }

#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; }

/* --- Animacje wejścia ekranów --- */
@keyframes viewIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes slideIn { from { opacity: 0; transform: translateX(26px); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: translateY(8px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes bounceIn { 0% { opacity: 0; transform: scale(.4); } 60% { transform: scale(1.15); } 100% { opacity: 1; transform: scale(1); } }

#app.anim > :not(.home-grid):not(.exam-grid):not(.narrow):not(.lock):not(.auth-wrap),
#app.anim :is(.home-main, .home-side, .narrow, .lock, .auth-wrap) > * {
  animation: viewIn .32s cubic-bezier(.22,.68,.3,1) both;
}
#app.anim > :nth-child(2), #app.anim :is(.home-main,.home-side,.narrow,.lock,.auth-wrap) > :nth-child(2) { animation-delay: .05s; }
#app.anim > :nth-child(3), #app.anim :is(.home-main,.home-side,.narrow,.lock,.auth-wrap) > :nth-child(3) { animation-delay: .1s; }
#app.anim > :nth-child(4), #app.anim :is(.home-main,.home-side,.narrow,.lock,.auth-wrap) > :nth-child(4) { animation-delay: .14s; }
#app.anim > :nth-child(5), #app.anim :is(.home-main,.home-side,.narrow,.lock,.auth-wrap) > :nth-child(5) { animation-delay: .18s; }
#app.anim > :nth-child(n+6), #app.anim :is(.home-main,.home-side,.narrow,.lock,.auth-wrap) > :nth-child(n+6) { animation-delay: .22s; }

.slide-in { animation: slideIn .26s cubic-bezier(.22,.68,.3,1) both; }
.explain { animation: popIn .25s ease both; }
.result-emoji { font-size: 3.2rem; animation: bounceIn .55s cubic-bezier(.34,1.56,.64,1) both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* --- Skeleton loading --- */
.skel {
  border-radius: 12px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* --- 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;
  transition: border-color .2s, box-shadow .2s;
}
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 16px; border-radius: var(--radius);
  /* Ciemniejsze indygo niż --primary: biały tekst na #6366f1 daje 4,46:1
     i nie przechodzi progu WCAG AA (4,5:1). Tu jest 5,8–6,3:1. */
  background: linear-gradient(135deg, #4f46e5, #6d3ff0); color: #fff; font-size: 1rem; font-weight: 700;
  box-shadow: 0 2px 10px rgba(99,102,241,.25);
  transition: transform .12s ease, box-shadow .2s, filter .15s, opacity .2s, background .2s;
}
.btn:active { transform: scale(0.98); }
.btn.secondary { background: var(--surface-2); box-shadow: none; }
.btn.ghost { background: transparent; border: 1.5px solid var(--border); color: var(--text); box-shadow: none; }
.btn.accent { background: linear-gradient(135deg, var(--accent), #16a34a); box-shadow: 0 2px 10px rgba(34,197,94,.25); }
.btn:disabled { opacity: .5; }
.btn-lg { padding: 18px; font-size: 1.05rem; }
.btn.loading { pointer-events: none; opacity: .75; }
.btn.loading::after {
  content: ''; width: 16px; height: 16px; flex: 0 0 16px;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}

.hero-grad {
  background: linear-gradient(135deg, #6366f1, #a855f7, #6366f1);
  background-size: 220% 220%;
  animation: heroShift 9s ease infinite;
  border-radius: 20px; padding: 24px; margin-bottom: 16px; border: none;
  position: relative; overflow: hidden;
}
@keyframes heroShift { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
.hero-grad::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(400px 200px at 90% -20%, rgba(255,255,255,.25), transparent 70%);
}
.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: 1px solid var(--border); 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);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.2); }
.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: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: 3px; transition: width .35s cubic-bezier(.22,.68,.3,1); }
.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; cursor: pointer;
  transition: border-color .15s, background .15s, transform .12s, box-shadow .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;
  transition: background .15s, color .15s; }
.opt.selected { border-color: var(--primary); background: rgba(99,102,241,.12); }
.opt.selected .letter { background: var(--primary); color: #fff; }
.opt.correct { border-color: var(--accent); background: rgba(34,197,94,.14); animation: popIn .2s ease both; }
.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; }
.opt.correct, .opt.wrong { cursor: default; }

.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; animation: bounceIn .55s cubic-bezier(.34,1.56,.64,1) both; }
.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); animation: timerPulse 1s ease infinite; }
@keyframes timerPulse { 50% { opacity: .55; } }
.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;
  transition: background .15s, color .15s, border-color .15s, transform .12s; }
.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); position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 0 8px; font-size: .7rem; font-weight: 600;
  transition: color .15s;
}
.tab-ico { font-size: 1.3rem; transition: transform .2s cubic-bezier(.34,1.56,.64,1); }
.tab.active { color: var(--primary-2); }
.tab.active .tab-ico { transform: translateY(-2px) scale(1.12); }
.tab::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%) scaleX(0);
  width: 36px; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary-2);
  transition: transform .2s ease;
}
.tab.active::before { transform: translateX(-50%) scaleX(1); }

.toast {
  position: fixed; bottom: calc(90px + var(--safe-bottom)); left: 50%; transform: translateX(-50%) translateY(6px);
  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, transform .2s; pointer-events: none; max-width: 90%;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.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; line-height: 1;
  background: linear-gradient(135deg, #818cf8, #c084fc);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.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;
  transition: border-color .15s, background .15s, transform .12s; }
.secrow:active { transform: scale(0.99); }
.secn { background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 2px 10px; font-size: .85rem; transition: background .15s, color .15s; }
.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;
  transition: border-color .15s, transform .12s; }
.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;
  transition: background .15s; }

/* --- Hover (tylko urządzenia z kursorem) --- */
@media (hover: hover) and (pointer: fine) {
  .btn:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 6px 22px rgba(99,102,241,.35); }
  .btn.secondary:hover { box-shadow: 0 4px 14px rgba(0,0,0,.25); }
  .btn.ghost:hover { border-color: var(--primary-2); box-shadow: none; }
  .btn.accent:hover { box-shadow: 0 6px 22px rgba(34,197,94,.35); }
  .opt:not(.correct):not(.wrong):hover { border-color: var(--primary-2); background: rgba(99,102,241,.08); transform: translateY(-1px); }
  .secrow:hover { border-color: var(--primary-2); background: rgba(99,102,241,.08); transform: translateY(-1px); }
  .secrow:hover .secn { background: var(--primary); color: #fff; }
  .histrow:hover { border-color: var(--primary-2); transform: translateY(-1px); }
  .navgrid button:hover { border-color: var(--primary-2); color: var(--text); transform: translateY(-1px); }
  .navgrid button.answered:hover { color: #fff; }
  .tab:hover { color: var(--text); }
  .danger-ghost:hover { background: rgba(239,68,68,.1); }
  .card:hover { border-color: #475569; }
}

/* --- Desktop / szerokie okna --- */
.home-grid, .exam-grid { display: block; }

@media (min-width: 900px) {
  #app {
    max-width: 1120px;
    padding: 96px 32px 56px;
  }

  /* nawigacja przenosi się na górę */
  .tabbar {
    top: 0; bottom: auto; max-width: none;
    justify-content: center; gap: 6px;
    padding: 10px 16px;
    border-top: none; border-bottom: 1px solid var(--border);
    background: rgba(15,23,42,.82);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  }
  .tab {
    flex: 0 0 auto; flex-direction: row; gap: 8px;
    padding: 10px 20px; font-size: .95rem; border-radius: 999px;
    transition: color .15s, background .15s;
  }
  .tab-ico { font-size: 1.15rem; }
  .tab.active { background: rgba(99,102,241,.18); }
  .tab.active .tab-ico { transform: none; }
  .tab::before { display: none; }
  .tab:hover { background: rgba(148,163,184,.1); }

  .toast { bottom: 32px; }

  h1 { font-size: 2rem; }

  /* home: dwie kolumny */
  .home-grid { display: grid; grid-template-columns: 1.05fr .95fr; gap: 28px; align-items: start; }
  .hero-grad { padding: 32px; }

  /* egzamin: mapa pytań z boku */
  .exam-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; align-items: start; }
  .exam-side { position: sticky; top: 92px; }
  .exam-side .navgrid { margin-top: 0; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); }

  /* węższe ekrany treści dla czytelności */
  .narrow { max-width: 760px; margin: 0 auto; }
  .auth-wrap { max-width: 480px; margin: 32px auto 0; }
  .lock { max-width: 560px; margin: 0 auto; }

  /* przegląd egzaminu w dwóch kolumnach */
  .review-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .review-grid > .card { margin-bottom: 0; }
}

@media (min-width: 1280px) {
  #app { max-width: 1220px; }
}

/* ---------- wskaźnik trybu offline / synchronizacji ---------- */
.netbadge {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 8px);
  transform: translate(-50%, -160%);
  z-index: 60; padding: 7px 16px; border-radius: 999px;
  background: var(--surface-2); color: var(--text);
  font-size: .8rem; font-weight: 600; white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
  transition: transform .25s cubic-bezier(.34,1.3,.64,1);
}
.netbadge.show { transform: translate(-50%, 0); }

/* ---------- plan na dziś ---------- */
.plan-card .plan-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pill.streak { background: rgba(251,191,36,.18); color: #fbbf24; }

/* ---------- statystyki per dział ---------- */
.secstat { margin-bottom: 16px; }
.secstat-top {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 10px; margin-bottom: 6px; font-weight: 600;
}
.secstat-top b { font-variant-numeric: tabular-nums; }
.secstat-top b.good { color: var(--accent); }
.secstat-top b.mid  { color: #fbbf24; }
.secstat-top b.bad  { color: var(--danger); }
.secstat-top b.none { color: var(--muted); }

.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > i {
  display: block; height: 100%; border-radius: 999px; background: var(--primary);
  transition: width .5s cubic-bezier(.22,1,.36,1);
}
.bar > i.good { background: var(--accent); }
.bar > i.mid  { background: #fbbf24; }
.bar > i.bad  { background: var(--danger); }
.bar > i.none { background: var(--surface-2); }

/* ---------- przełączniki w ustawieniach ---------- */
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border);
  font-weight: 600; cursor: pointer;
}
.switch-row:last-of-type { border-bottom: none; }
.switch-row input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 46px; height: 27px; border-radius: 999px; flex: 0 0 auto;
  background: var(--surface-2); position: relative; cursor: pointer;
  transition: background .2s;
}
.switch-row input[type="checkbox"]::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 21px; height: 21px; border-radius: 50%; background: #fff;
  transition: transform .2s cubic-bezier(.34,1.4,.64,1);
}
.switch-row input[type="checkbox"]:checked { background: var(--primary); }
.switch-row input[type="checkbox"]:checked::after { transform: translateX(19px); }
.switch-row select {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; font: inherit; font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  .netbadge, .bar > i, .switch-row input[type="checkbox"]::after { transition: none; }
}
