:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #16181d;
  --muted: #656b7a;
  --border: #e2e6ef;
  --brand: #4f46e5;
  --brand-soft: #eef0ff;
  --good: #16a34a;
  --good-soft: #e8f7ee;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16, 20, 40, .06), 0 8px 24px rgba(16, 20, 40, .06);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117;
    --card: #171a22;
    --text: #eef0f6;
    --muted: #9aa1b1;
    --border: #262b36;
    --brand: #8b87ff;
    --brand-soft: #21213a;
    --good: #4ade80;
    --good-soft: #16281d;
    --bad: #f87171;
    --bad-soft: #2c1a1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117;
  --card: #171a22;
  --text: #eef0f6;
  --muted: #9aa1b1;
  --border: #262b36;
  --brand: #8b87ff;
  --brand-soft: #21213a;
  --good: #4ade80;
  --good-soft: #16281d;
  --bad: #f87171;
  --bad-soft: #2c1a1a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; cursor: pointer; }

.wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px 40px; }

/* ---------- fejléc ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px calc(14px);
  padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 19px; margin: 0; flex: 1; letter-spacing: -.02em; }
.back {
  border: 0; background: var(--brand-soft); color: var(--brand);
  width: 40px; height: 40px; border-radius: 12px; font-size: 20px; line-height: 1;
}
.icon-btn { border: 0; background: transparent; font-size: 20px; padding: 8px; border-radius: 10px; }

.stats { display: flex; gap: 8px; }
.stat {
  background: var(--brand-soft); color: var(--brand); font-weight: 700;
  border-radius: 999px; padding: 4px 11px; font-size: 14px; white-space: nowrap;
}

/* ---------- kártyák ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.card h2 { margin: 0 0 4px; font-size: 17px; }
.card p { margin: 0; color: var(--muted); font-size: 14.5px; }

.hero {
  background: linear-gradient(135deg, var(--brand), #7c3aed);
  color: #fff; border: 0; padding: 18px;
}
.hero h2 { color: #fff; font-size: 19px; }
.hero p { color: rgba(255, 255, 255, .85); }
.hero .go {
  margin-top: 14px; background: #fff; color: var(--brand); border: 0; font-weight: 700;
  border-radius: 12px; padding: 12px 16px; width: 100%;
}
.hero.done { background: linear-gradient(135deg, #16a34a, #0d9488); }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.subject {
  text-align: left; border: 1px solid var(--border); background: var(--card);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px; transition: transform .1s;
}
.subject:active { transform: scale(.97); }
.subject .emoji { font-size: 28px; }
.subject .name { font-weight: 700; font-size: 16px; }
.subject .meta { color: var(--muted); font-size: 13px; }

.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.row:active { transform: scale(.99); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { color: var(--muted); font-size: 13.5px; }
.row .chev { color: var(--muted); font-size: 20px; }

.bar { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .3s; }
.bar.thin { height: 6px; }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; font-weight: 700; }

/* ---------- kvíz ---------- */
.progress { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
.progress > span { display: block; height: 100%; background: var(--brand); transition: width .25s; }

.qcount { color: var(--muted); font-size: 14px; margin-bottom: 6px; display: flex; justify-content: space-between; }
.question { font-size: 21px; font-weight: 650; line-height: 1.35; margin: 0 0 18px; letter-spacing: -.01em; }

.answers { display: grid; gap: 10px; }
.answer {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 2px solid var(--border); border-radius: 14px;
  padding: 15px 14px; font-size: 16.5px; transition: transform .08s, border-color .15s, background .15s;
}
.answer:active { transform: scale(.98); }
.answer .key {
  width: 28px; height: 28px; flex: none; border-radius: 8px; background: var(--brand-soft);
  color: var(--brand); font-weight: 700; font-size: 14px; display: grid; place-items: center;
}
.answer.correct { border-color: var(--good); background: var(--good-soft); }
.answer.correct .key { background: var(--good); color: #fff; }
.answer.wrong { border-color: var(--bad); background: var(--bad-soft); }
.answer.wrong .key { background: var(--bad); color: #fff; }
.answer.dim { opacity: .5; }
.answer[disabled] { cursor: default; }

.feedback {
  margin-top: 16px; border-radius: 14px; padding: 14px; border: 1px solid var(--border);
  background: var(--card); animation: pop .2s ease-out;
}
.feedback.ok { border-color: var(--good); background: var(--good-soft); }
.feedback.no { border-color: var(--bad); background: var(--bad-soft); }
.feedback .head { font-weight: 700; margin-bottom: 4px; }
.feedback .exp { font-size: 15px; color: var(--text); opacity: .85; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.primary {
  width: 100%; border: 0; background: var(--brand); color: #fff; font-weight: 700;
  border-radius: 14px; padding: 15px; font-size: 17px; margin-top: 14px;
}
.primary:active { filter: brightness(.92); }
.secondary {
  width: 100%; border: 1px solid var(--border); background: var(--card); color: var(--text);
  font-weight: 600; border-radius: 14px; padding: 14px; font-size: 16px; margin-top: 10px;
}
.danger { color: var(--bad); border-color: var(--bad); }

.sticky-actions { position: sticky; bottom: 0; padding-bottom: env(safe-area-inset-bottom); background: linear-gradient(to bottom, transparent, var(--bg) 30%); padding-top: 8px; }

/* ---------- eredmény ---------- */
.result { text-align: center; padding: 26px 16px; }
.result .big { font-size: 56px; line-height: 1; margin-bottom: 8px; animation: pop .3s; }
.result .score { font-size: 32px; font-weight: 800; letter-spacing: -.02em; }
.result .xp { color: var(--brand); font-weight: 700; margin-top: 4px; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.badge-list { display: flex; flex-wrap: wrap; gap: 8px; }
.badge { background: var(--brand-soft); color: var(--brand); border-radius: 999px; padding: 6px 12px; font-size: 13.5px; font-weight: 600; }
.badge.off { background: var(--border); color: var(--muted); }

.kpi { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: center; }
.kpi div { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 12px 6px; }
.kpi .n { font-size: 22px; font-weight: 800; }
.kpi .l { font-size: 12px; color: var(--muted); }

.input-answer {
  width: 100%; font-size: 20px; padding: 14px; border-radius: 14px;
  border: 2px solid var(--border); background: var(--card); color: var(--text); text-align: center;
}
.input-answer:focus { outline: none; border-color: var(--brand); }
.input-answer.ok { border-color: var(--good); background: var(--good-soft); }
.input-answer.no { border-color: var(--bad); background: var(--bad-soft); }

/* ---------- általános kiegészítők ---------- */
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.lead { color: var(--muted); font-size: 15px; margin: 0 0 14px; }
.fineprint { color: var(--muted); font-size: 13px; margin-top: 18px; text-align: center; }
.row-emoji { font-size: 24px; line-height: 1; }
.pill {
  background: var(--brand-soft); color: var(--brand); font-weight: 700;
  font-size: 12.5px; border-radius: 999px; padding: 3px 9px; white-space: nowrap;
}
.progress.danger > span { background: linear-gradient(90deg, var(--bad), #f59e0b); }

/* ---------- párosító játék ---------- */
.pair-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair-col { display: grid; gap: 10px; align-content: start; }
.pair-item {
  border: 2px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 13px 10px; font-size: 15px; text-align: center;
  min-height: 54px; transition: transform .08s, border-color .15s, background .15s, opacity .25s;
  word-break: break-word; line-height: 1.25;
}
.pair-item:active { transform: scale(.97); }
.pair-item.selected { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.pair-item.matched { border-color: var(--good); background: var(--good-soft); color: var(--good); opacity: .55; }
.pair-item[disabled] { cursor: default; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
.shake { animation: shake .3s; border-color: var(--bad) !important; background: var(--bad-soft) !important; }

/* ---------- sorbarendező játék ---------- */
.order-slots { display: grid; gap: 8px; margin-bottom: 18px; }
.order-pool { display: flex; flex-wrap: wrap; gap: 8px; }
.order-item {
  display: flex; align-items: center; gap: 10px;
  border: 2px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font-size: 15.5px; text-align: left;
  transition: transform .08s, border-color .15s, background .15s;
}
.order-pool .order-item { flex: 0 1 auto; }
.order-item:active { transform: scale(.97); }
.order-item .num { color: var(--muted); font-weight: 700; font-size: 13px; min-width: 22px; }
.order-item.placed { border-color: var(--brand); background: var(--brand-soft); }
.order-item.empty { border-style: dashed; color: var(--muted); background: transparent; }
.order-item.correct { border-color: var(--good); background: var(--good-soft); }
.order-item.wrong { border-color: var(--bad); background: var(--bad-soft); }

/* ---------- igaz–hamis villám ---------- */
.blitz-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 6px; }
.question.blitz { font-size: 23px; min-height: 92px; display: flex; align-items: center; }
.tf-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tf {
  border: 0; border-radius: 16px; padding: 26px 10px; font-size: 19px; font-weight: 800;
  color: #fff; letter-spacing: .01em; transition: transform .08s, filter .15s;
}
.tf:active { transform: scale(.97); }
.tf.true { background: linear-gradient(135deg, #16a34a, #0d9488); }
.tf.false { background: linear-gradient(135deg, #dc2626, #db2777); }
.tf[disabled] { filter: grayscale(.55) brightness(.85); }

/* ---------- konfetti ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 60; }
.confetti i {
  position: absolute; top: -14px; width: 9px; height: 14px; border-radius: 2px;
  animation: fall 2.4s linear forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(540deg); opacity: .1; }
}
@media (prefers-reduced-motion: reduce) {
  .confetti { display: none; }
  * { animation-duration: .01ms !important; }
}

/* ---------- évfolyamválasztó ---------- */
.grade-chip { border: 0; cursor: pointer; font-family: inherit; }
.grade-chip:active { filter: brightness(.92); }
.grade-card {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--card); border: 2px solid var(--border); border-radius: 16px;
  padding: 16px 14px; margin-bottom: 10px; box-shadow: var(--shadow);
  transition: transform .08s, border-color .15s, background .15s;
}
.grade-card:active { transform: scale(.99); }
.grade-card.active { border-color: var(--brand); background: var(--brand-soft); }
.grade-card .grade-num {
  width: 46px; height: 46px; flex: none; border-radius: 14px;
  background: var(--brand); color: #fff; font-weight: 800; font-size: 19px;
  display: grid; place-items: center;
}
.grade-card .title { font-weight: 700; font-size: 17px; }
.grade-card .sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.grade-card .chev { color: var(--brand); font-size: 20px; font-weight: 800; }
