:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #2e3856;
  --muted: #586380;
  --border: #d9dde8;
  --accent: #4255ff;
  --accent-hover: #423ed8;
  --accent-soft: #edefff;
  --good: #18ae79;
  --good-soft: #e6f7f0;
  --bad: #e8542f;
  --bad-soft: #fdece7;
  --shadow: 0 4px 16px rgba(46, 56, 86, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a092d;
    --card: #2e3856;
    --text: #f6f7fb;
    --muted: #b8bed4;
    --border: #4a5578;
    --accent: #6f7dff;
    --accent-hover: #8a95ff;
    --accent-soft: #3a4470;
    --good: #3ccf98;
    --good-soft: #1d4a42;
    --bad: #ff7a59;
    --bad-soft: #5a2f33;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 1.1rem; display: flex; align-items: center; gap: 10px; }
.logo {
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
}

.progress { height: 4px; background: var(--border); }
#progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s ease; }

main {
  flex: 1;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 16px;
}

.card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.hero { text-align: center; }
.hero h1 { margin: 0 0 12px; font-size: 1.9rem; }
.hero p { max-width: 520px; margin: 0 auto 12px; line-height: 1.5; }

.length-picker { display: flex; gap: 8px; justify-content: center; margin: 24px 0; flex-wrap: wrap; }
.chip {
  font: inherit;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.btn {
  font: inherit;
  font-weight: 700;
  border-radius: 8px;
  padding: 12px 24px;
  border: 0;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; color: var(--accent); border: 2px solid var(--border); }
.btn.ghost:hover { border-color: var(--accent); }
.btn.big { padding: 14px 48px; font-size: 1.05rem; margin-bottom: 12px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.term-label { font-weight: 600; margin-bottom: 12px; }

.image-wrap {
  border-radius: 12px;
  overflow: hidden;
  background: var(--accent-soft);
  aspect-ratio: 16 / 9;
  margin-bottom: 20px;
}
.image-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-wrap.empty { display: none; }

.question h2 { font-size: 1.5rem; line-height: 1.35; margin: 0; font-weight: 600; }

.divider { height: 1px; background: var(--border); margin: 24px 0; }

.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.answer {
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  text-align: left;
  padding: 18px 16px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color 0.15s, background 0.15s;
}
.answer:hover:not(:disabled) { border-color: var(--accent); }
.answer:disabled { cursor: default; }
.answer kbd {
  font: inherit;
  font-size: 0.8rem;
  width: 26px;
  height: 26px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--muted);
  flex: none;
}
.answer.correct { border-color: var(--good); background: var(--good-soft); }
.answer.wrong { border-color: var(--bad); background: var(--bad-soft); }
.answer.dim { opacity: 0.55; }

.feedback {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-weight: 600;
}
.feedback.good { background: var(--good-soft); color: var(--good); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.feedback a { font-weight: 600; white-space: nowrap; }
.feedback .orig { display: block; font-weight: 400; color: var(--muted); font-size: 0.875rem; margin-top: 4px; }

.quiz-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  min-height: 48px;
  gap: 12px;
}

.score-ring {
  width: 140px;
  height: 140px;
  margin: 24px auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 2rem;
  font-weight: 800;
  background: conic-gradient(var(--good) calc(var(--pct, 0) * 1%), var(--border) 0);
  position: relative;
}
.score-ring::before {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  background: var(--card);
}
.score-ring span { position: relative; }

.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.review-heading { margin: 32px 0 12px; }
.review { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.review li {
  background: var(--card);
  border-radius: 12px;
  padding: 14px 16px;
  border-left: 5px solid var(--good);
  box-shadow: var(--shadow);
  display: flex;
  gap: 14px;
  align-items: center;
}
.review li.missed { border-left-color: var(--bad); }
.review img { width: 72px; height: 48px; object-fit: cover; border-radius: 6px; flex: none; }
.review .r-title { font-weight: 600; }
.review .r-meta { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }

.site-footer { text-align: center; padding: 20px 16px 28px; line-height: 1.6; }

@media (max-width: 560px) {
  .topbar { padding: 12px 16px; }
  .card { padding: 20px; }
  .hero h1 { font-size: 1.5rem; }
  .question h2 { font-size: 1.2rem; }
  .answers { grid-template-columns: 1fr; }
  .quiz-footer .small { display: none; }
  .quiz-footer { justify-content: flex-end; }
}
