:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5b6676;
  --border: #d8dde4;
  --accent: #1d5fa8;
  --accent-text: #ffffff;
  --sub-bg: #eef1f5;
  --good: #1f7a45;
  --good-bg: #e7f5ec;
  --bad: #a3322b;
  --bad-bg: #fbeceb;
  --focus: #f2a900;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b2129;
    --text: #e6eaf0;
    --muted: #a0aab8;
    --border: #333c48;
    --accent: #5b9ee6;
    --accent-text: #0b1320;
    --sub-bg: #232b35;
    --good: #6fd59a;
    --good-bg: #16301f;
    --bad: #f08a82;
    --bad-bg: #3a1c1a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.top h1 { font-size: 1.1rem; margin: 0; }
nav { display: flex; gap: 4px; }

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

button, select, input { font: inherit; }
button:focus-visible, select:focus-visible, input:focus-visible, label.option:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.link {
  background: none;
  border: 0;
  padding: 6px 10px;
  color: var(--accent);
  cursor: pointer;
  border-radius: 6px;
}
.link[aria-current="page"] { background: var(--sub-bg); color: var(--text); font-weight: 600; }

.primary {
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}
.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.setup {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 12px;
}
.setup label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
.setup label.check { flex-direction: row; align-items: center; gap: 8px; min-height: 44px; }
.setup select {
  min-height: 44px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  max-width: 100%;
}

.status { color: var(--muted); min-height: 1.5em; margin: 0 0 8px; }
.status.error { color: var(--bad); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.tag { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; }
.timer.over { color: var(--bad); }

.intro { margin: 0 0 12px; }
.stem { font-weight: 700; margin: 16px 0 8px; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
caption { text-align: left; font-weight: 600; padding-bottom: 6px; }
th, td { border: 1px solid var(--border); padding: 6px 8px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; white-space: normal; min-width: 7em; }
thead th { background: var(--sub-bg); font-weight: 600; vertical-align: bottom; white-space: normal; }
tr.subtotal td { background: var(--sub-bg); font-weight: 600; }

fieldset { border: 0; margin: 0; padding: 0; }
.options { display: grid; gap: 8px; margin-bottom: 12px; }
label.option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
label.option input { width: 20px; height: 20px; margin: 0; }
label.option.correct { border-color: var(--good); background: var(--good-bg); }
label.option.wrong { border-color: var(--bad); background: var(--bad-bg); }

.feedback { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.feedback h2 { margin: 0 0 8px; font-size: 1.15rem; }
.feedback h2.good { color: var(--good); }
.feedback h2.bad { color: var(--bad); }
.feedback h3 { font-size: 1rem; margin: 12px 0 4px; }
.trap { background: var(--bad-bg); border-radius: 8px; padding: 10px 12px; margin: 0; }
.feedback ol { padding-left: 1.3em; margin: 0 0 16px; }
.feedback li { margin-bottom: 4px; }

.hint { color: var(--muted); font-size: 0.9rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 480px) {
  .setup { flex-direction: column; align-items: stretch; }
  .primary { width: 100%; }
  th, td { padding: 5px 6px; }
  table { font-size: 0.85rem; }
}
