:root {
  --bg: #f3f5fb;
  --card: #ffffff;
  --ink: #1d2340;
  --muted: #5d6584;
  --line: #e1e5f0;
  --primary: #3b4cca;
  --primary-dark: #2c3aa3;
  --primary-soft: #eceefe;
  --good: #1f9d63;
  --good-soft: #e6f6ee;
  --bad: #d64545;
  --bad-soft: #fdecec;
  --warn: #b7791f;
  --warn-soft: #fff6e0;
  --accent: #e0457b;
  --radius: 16px;
  --shadow: 0 2px 4px rgba(29, 35, 64, .05), 0 10px 30px rgba(29, 35, 64, .07);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.55;
  font-size: 17px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; padding-top: 24px; padding-bottom: 40px; }

.wrap { width: 100%; max-width: 820px; margin: 0 auto; padding: 0 16px; }

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ===== Antraštė ===== */
.site-header { background: var(--card); border-bottom: 1px solid var(--line); }
.header-inner { display: flex; align-items: center; justify-content: space-between; padding-top: 14px; padding-bottom: 14px; }
.brand { font-weight: 800; font-size: 1.35rem; color: var(--ink); text-decoration: none; letter-spacing: -.02em; }
.brand span { color: var(--primary); }
.badge { background: var(--primary-soft); color: var(--primary-dark); font-weight: 700; font-size: .85rem; padding: 4px 12px; border-radius: 999px; }

.site-footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 20px 0 28px; }

/* ===== Kortelės ir tipografija ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
  margin-bottom: 20px;
}

h1 { font-size: 1.9rem; line-height: 1.2; margin: 0 0 10px; letter-spacing: -.02em; }
h2 { font-size: 1.1rem; margin: 26px 0 12px; }
.card > h2:first-child { margin-top: 0; }
.lead { font-size: 1.05rem; color: var(--muted); margin: 0 0 8px; }

/* ===== Mygtukai ===== */
.btn {
  font: inherit;
  font-weight: 700;
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 11px 20px;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .choice:focus-visible, .link-btn:focus-visible, select:focus-visible, input:focus-visible {
  outline: 3px solid rgba(59, 76, 202, .35);
  outline-offset: 2px;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: #fff; color: var(--primary-dark); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--primary); background: var(--primary-soft); }
.btn.big { padding: 15px 34px; font-size: 1.1rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.link-btn { background: none; border: 0; color: var(--muted); font: inherit; text-decoration: underline; cursor: pointer; padding: 8px 0; }
.link-btn:hover { color: var(--bad); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.actions.end { justify-content: flex-end; }
.actions.center { justify-content: center; margin-bottom: 20px; }

/* ===== Pradžios ekranas ===== */
.topic-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.topic { position: relative; }
.topic input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.topic span {
  display: block;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  font-weight: 600;
  background: #fff;
  transition: all .15s ease;
}
.topic span small { display: block; font-weight: 400; color: var(--muted); font-size: .82rem; }
.topic input:checked + span { border-color: var(--primary); background: var(--primary-soft); }
.topic input:focus-visible + span { outline: 3px solid rgba(59, 76, 202, .35); outline-offset: 2px; }

.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.settings label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .95rem; }
select {
  font: inherit;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}

.start-actions { margin-top: 22px; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.start-actions p { margin: 0; }
.rules { margin-top: 22px; color: var(--muted); font-size: .95rem; }
.rules summary { cursor: pointer; font-weight: 600; color: var(--ink); }
.rules ul { margin: 10px 0 0; padding-left: 20px; }

.error { color: var(--bad); font-weight: 600; min-height: 1.2em; margin: 8px 0 0; }

/* ===== Testo HUD ===== */
.hud { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px; }
.hud-item { background: var(--card); border-radius: 14px; padding: 10px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.hud-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.hud-item strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.timer.low { color: var(--bad); animation: pulse 1s ease-in-out infinite; }
.level { color: var(--primary); letter-spacing: 2px; font-size: 1.05rem !important; }
.level small { color: var(--muted); letter-spacing: 0; font-size: .8rem; font-weight: 600; margin-left: 4px; }

.progress { height: 8px; background: #dfe3f2; border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
#progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width .4s ease; }

@keyframes pulse { 50% { opacity: .55; } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.shake { animation: shake .35s; }

/* ===== Klausimas ===== */
.q-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { background: var(--primary-soft); color: var(--primary-dark); font-weight: 700; font-size: .85rem; padding: 4px 12px; border-radius: 999px; }
.streak-wrap { display: inline-flex; align-items: center; gap: 8px; }
.streak { display: inline-flex; gap: 5px; }
.streak i { width: 13px; height: 13px; border-radius: 50%; background: #dfe3f2; display: block; transition: background .2s; }
.streak i.on { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }

.q-text { font-size: 1.2rem; font-weight: 600; margin-bottom: 10px; }
.q-text .katex { font-size: 1.15em; }

.figure { margin: 14px 0; text-align: center; }
.figure svg.tri { width: 100%; max-width: 300px; height: auto; color: var(--ink); }
svg.tri polygon { fill: var(--primary-soft); stroke: var(--primary); stroke-width: 2.5; stroke-linejoin: round; }
svg.tri .ra { fill: none; stroke: var(--primary); stroke-width: 1.5; }
svg.tri text { font-size: 14px; font-weight: 600; fill: currentColor; }
.chart-box { position: relative; width: 100%; max-width: 420px; margin: 0 auto; }
.chart-box.wide { max-width: 100%; height: 260px; }
.fig-note { font-size: .82rem; color: var(--muted); margin: 6px 0 0; }

.q-answer { margin-top: 14px; }
.answer-row { display: flex; align-items: center; gap: 10px; }
#answer-input {
  font: inherit;
  font-size: 1.3rem;
  font-weight: 700;
  width: 100%;
  max-width: 260px;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
}
#answer-input:focus { border-color: var(--primary); }
#answer-input.ok { border-color: var(--good); background: var(--good-soft); }
#answer-input.no { border-color: var(--bad); background: var(--bad-soft); }
.unit { font-weight: 700; color: var(--muted); font-size: 1.1rem; }

.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.choice {
  font: inherit;
  font-weight: 600;
  text-align: center;
  padding: 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: all .15s ease;
}
.choice:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }
.choice:disabled { cursor: default; }
.choice.correct { border-color: var(--good); background: var(--good-soft); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }

.hint {
  margin-top: 14px;
  background: var(--warn-soft);
  border-left: 4px solid var(--warn);
  border-radius: 10px;
  padding: 12px 16px;
}

/* ===== Grįžtamasis ryšys ===== */
.feedback { margin-top: 20px; border-radius: 14px; padding: 18px 20px; border-left: 6px solid; }
.feedback.correct { background: var(--good-soft); border-color: var(--good); }
.feedback.wrong { background: var(--bad-soft); border-color: var(--bad); }
.feedback h3 { margin: 0 0 8px; font-size: 1.15rem; }
.feedback .fb-block { margin-top: 14px; }
.feedback .fb-title { font-weight: 800; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 4px; }
.feedback .mistake { background: #fff; border-radius: 10px; padding: 10px 14px; border: 1px dashed var(--bad); }
.feedback .formula-box { background: #fff; border-radius: 10px; padding: 8px 14px; text-align: center; overflow-x: auto; }
.feedback ol { margin: 6px 0 0; padding-left: 22px; }
.feedback ol li { margin-bottom: 6px; }
.feedback .level-note { margin-top: 14px; font-weight: 600; padding: 10px 14px; border-radius: 10px; background: #fff; }
.feedback details summary { cursor: pointer; font-weight: 700; color: var(--primary-dark); }

/* ===== Rezultatai ===== */
.result-card { text-align: center; }
.big-score { margin: 8px 0; }
.big-score span { font-size: 4.2rem; font-weight: 800; color: var(--primary); line-height: 1; letter-spacing: -.03em; }
.big-score small { display: block; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; font-size: .8rem; }
.best-note { font-weight: 700; color: var(--good); min-height: 1.4em; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-top: 18px; }
.stat { background: var(--bg); border-radius: 14px; padding: 14px 8px; }
.stat-num { display: block; font-size: 1.6rem; font-weight: 800; }
.stat-label { font-size: .8rem; color: var(--muted); font-weight: 600; }

.topic-bars { display: grid; gap: 14px; }
.bar-head { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 4px; gap: 10px; }
.bar { height: 12px; border-radius: 999px; background: #e8ebf5; overflow: hidden; }
.bar > div { height: 100%; border-radius: 999px; background: var(--good); }
.bar > div.mid { background: var(--warn); }
.bar > div.low { background: var(--bad); }

.review-list { display: grid; gap: 14px; }
.review-item { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.review-item .chip { margin-bottom: 8px; display: inline-block; }
.review-item .r-q { font-weight: 600; margin-bottom: 6px; }
.review-item .r-a { font-size: .95rem; color: var(--muted); }
.review-item .r-a strong { color: var(--ink); }
.review-empty { text-align: center; color: var(--good); font-weight: 700; padding: 10px; }

.katex-display { margin: .5em 0; overflow-x: auto; overflow-y: hidden; }

/* ===== Mobilūs ===== */
@media (max-width: 560px) {
  body { font-size: 16px; }
  .card { padding: 18px; }
  h1 { font-size: 1.5rem; }
  .hud { grid-template-columns: repeat(2, 1fr); }
  .q-text { font-size: 1.1rem; }
  .actions .btn { flex: 1 1 auto; }
  .big-score span { font-size: 3.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
