:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --text: #14181f;
  --muted: #5b6473;
  --primary: #1f6feb;
  --primary-text: #ffffff;
  --correct: #1f8a3f;
  --correct-bg: #e3f5e8;
  --wrong: #c8341d;
  --wrong-bg: #fbe6e2;
  --border: #d8dde6;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(20, 24, 31, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --text: #e6edf3;
    --muted: #8b949e;
    --primary: #4e8eff;
    --primary-text: #0d1117;
    --correct: #4cd97a;
    --correct-bg: #1d3024;
    --wrong: #ff6a55;
    --wrong-bg: #3a1c19;
    --border: #30363d;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}

.title { font-weight: 700; font-size: 17px; }
.counter { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }

.progress {
  height: 4px; background: var(--border);
  position: sticky; top: 51px; z-index: 9;
}
.progress-fill {
  height: 100%; width: 0%;
  background: var(--primary);
  transition: width 0.3s ease;
}

#main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.controls {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.control {
  flex: 1 1 140px;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted);
}
.control select {
  font: inherit; font-size: 14px; color: var(--text);
  padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
}
.reset-btn {
  align-self: flex-end;
  padding: 8px 14px; font: inherit; font-size: 13px;
  border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
}
.reset-btn:hover { color: var(--wrong); border-color: var(--wrong); }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 16px;
}

.card-meta {
  display: flex; gap: 10px;
  font-size: 12px; color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase; letter-spacing: 0.04em;
}

.qtext {
  font-size: 20px;
  line-height: 1.4;
  margin: 0 0 16px;
  font-weight: 600;
}

#qfigure {
  margin: 0 0 16px;
  text-align: center;
}
#qimg {
  max-width: 100%; max-height: 280px;
  border-radius: 8px;
  background: white;
}

.options {
  list-style: none;
  padding: 0;
  margin: 0 0 18px;
  display: flex; flex-direction: column; gap: 10px;
  counter-reset: opt;
}
.options li { display: contents; }
.options button {
  width: 100%;
  text-align: left;
  font: inherit; font-size: 15px;
  padding: 14px 16px 14px 44px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text);
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s, background 0.15s;
  min-height: 56px;
}
.options button:hover:not(:disabled) {
  border-color: var(--primary);
}
.options button:before {
  counter-increment: opt;
  content: counter(opt, upper-alpha);
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--border); color: var(--text);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
}
.options button.correct {
  border-color: var(--correct); background: var(--correct-bg);
}
.options button.correct:before { background: var(--correct); color: white; }
.options button.wrong {
  border-color: var(--wrong); background: var(--wrong-bg);
}
.options button.wrong:before { background: var(--wrong); color: white; }
.options button:disabled { cursor: default; }

.actions {
  display: flex; justify-content: flex-end;
}
#next-btn {
  font: inherit; font-size: 15px; font-weight: 600;
  padding: 12px 22px;
  background: var(--primary); color: var(--primary-text);
  border: 0; border-radius: 10px;
  cursor: pointer;
  min-height: 48px; min-width: 120px;
}
#next-btn:disabled {
  opacity: 0.4; cursor: not-allowed;
}

.feedback {
  margin-top: 14px; padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
  background: var(--correct-bg); color: var(--correct);
}
.feedback.wrong { background: var(--wrong-bg); color: var(--wrong); }

.footer {
  text-align: center;
  font-size: 12px; color: var(--muted);
  padding: 16px 0 32px;
}
.footer a { color: var(--muted); }

.empty-state {
  text-align: center; padding: 40px 20px;
  color: var(--muted);
}

@media (max-width: 480px) {
  .qtext { font-size: 18px; }
  .options button { font-size: 14px; }
}
