:root {
  color-scheme: light dark;
  --ink: #1a2530;
  --muted: #5b6873;
  --line: #d9e0e6;
  --panel: #ffffff;
  --surface: #f2f5f7;
  --brand: #0f6b5f;
  --brand-strong: #0a4f44;
  --brand-soft: #e3f1ee;
  --on-brand: #ffffff;
  --ok: #157347;
  --ok-soft: #e7f5ee;
  --bad: #b42318;
  --bad-soft: #fdefec;
  --warn: #684b00;
  --warn-soft: #fff8e6;
  --warn-line: #ffe2a0;
  --ring: rgba(15, 107, 95, 0.35);
  --shadow: 0 10px 28px rgba(25, 38, 52, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e6ecf1;
    --muted: #97a5b2;
    --line: #2c3843;
    --panel: #1a2127;
    --surface: #10161b;
    --brand: #2ba18b;
    --brand-strong: #3cb7a0;
    --brand-soft: #143029;
    --on-brand: #06211c;
    --ok: #5bc98a;
    --ok-soft: #14301f;
    --bad: #ff8f7b;
    --bad-soft: #3a1b15;
    --warn: #e8c56a;
    --warn-soft: #2e2510;
    --warn-line: #4d3d14;
    --ring: rgba(60, 183, 160, 0.45);
    --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--surface);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--brand-strong);
}

input, select, button {
  accent-color: var(--brand);
  font: inherit;
}

:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px clamp(16px, 4vw, 40px);
  padding-left: max(clamp(16px, 4vw, 40px), env(safe-area-inset-left));
  padding-right: max(clamp(16px, 4vw, 40px), env(safe-area-inset-right));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 2;
}

.brand {
  color: var(--ink);
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

.nav, .lang-picker {
  display: flex;
  align-items: center;
  gap: 14px;
}

.lang-picker span {
  color: var(--muted);
  font-size: 0.9rem;
}

select, input[type="number"] {
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--panel);
  color: var(--ink);
}

.lang-picker select {
  width: auto;
  min-height: 36px;
  padding: 4px 8px;
}

button, .button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.06s ease, box-shadow 0.15s ease;
}

button:hover, .button:hover {
  background: var(--brand-strong);
}

button:active, .button:active {
  transform: translateY(1px);
}

button.secondary, a.secondary {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  background: var(--panel);
  color: var(--brand-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 14px;
  text-decoration: none;
  font-weight: 700;
  transition: border-color 0.15s ease, background 0.15s ease;
}

button.secondary:hover, a.secondary:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.page {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.intro {
  margin-bottom: 24px;
}

.intro h1, .results h1, .error-panel h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3.4vw, 2.4rem);
  line-height: 1.2;
}

.intro .subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  max-width: 56ch;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  align-items: stretch;
}

.mode-card, .question-card, .results, .error-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.mode-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.mode-card--featured {
  border-top: 4px solid var(--brand);
}

.mode-card h2 {
  margin: 0;
  font-size: 1.2rem;
}

.mode-card p {
  margin: 0;
  color: var(--muted);
}

.mode-card button[type="submit"] {
  margin-top: auto;
}

.mode-card label > span, legend {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.choice-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 12px 8px 0;
  min-height: 32px;
}

.choice-inline input[type="radio"] {
  width: 18px;
  height: 18px;
  margin: 0;
}

.custom-count input[type="number"] {
  width: 86px;
}

.question-shell {
  max-width: 860px;
  margin: 0 auto;
}

.question-meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.95rem;
}

.progress {
  height: 8px;
  margin: 10px 0 18px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--brand);
  transition: width 0.3s ease;
}

.chapter {
  margin: 0 0 8px;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.question-card h1 {
  margin: 0 0 18px;
  font-size: clamp(1.25rem, 2.6vw, 1.6rem);
  line-height: 1.3;
}

.prompt-image {
  display: block;
  max-width: min(100%, 420px);
  max-height: 300px;
  object-fit: contain;
  margin: 8px 0 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
}

.answers {
  display: grid;
  gap: 12px;
  margin: 18px 0;
}

.answer-option {
  position: relative;
  display: grid;
  grid-template-columns: auto 34px 1fr;
  gap: 12px;
  align-items: center;
  min-height: 58px;
  padding: 12px;
  padding-right: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.answers:not([disabled]) .answer-option:hover {
  border-color: var(--brand);
}

.answer-option input[type="radio"] {
  width: 20px;
  height: 20px;
  margin: 0;
}

.answer-option:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.answer-option:focus-within {
  outline: 3px solid var(--ring);
  outline-offset: 1px;
}

.answer-option input[type="radio"]:focus-visible {
  outline: none;
}

.answers[disabled] .answer-option {
  cursor: default;
}

.answer-option::after {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  font-weight: 800;
  font-size: 1.1rem;
}

.answer-option.is-chosen.is-right,
.answer-option.is-answer,
.answer-option.is-answer:has(input:checked) {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.answer-option.is-chosen.is-right::after,
.answer-option.is-answer::after {
  content: "✓";
  color: var(--ok);
}

.answer-option.is-chosen.is-wrong,
.answer-option.is-chosen.is-wrong:has(input:checked) {
  border-color: var(--bad);
  background: var(--bad-soft);
}

.answer-option.is-chosen.is-wrong::after {
  content: "✕";
  color: var(--bad);
}

.answer-option img {
  max-width: 140px;
  max-height: 110px;
  object-fit: contain;
  grid-column: 3;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px;
}

.option-key {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-weight: 800;
}

.feedback, .notice, .toast {
  border-radius: 10px;
  padding: 12px 14px;
  font-weight: 700;
}

.feedback.ok {
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid var(--ok);
}

.feedback.bad, .toast {
  background: var(--bad-soft);
  color: var(--bad);
  border: 1px solid var(--bad);
}

.toast {
  width: min(720px, calc(100% - 32px));
  margin: 16px auto 0;
  animation: toast-in 0.25s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

.notice {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid var(--warn-line);
  margin-bottom: 18px;
}

.notice p {
  margin: 0;
}

.notice p + p {
  margin-top: 6px;
}

.reveal {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.reveal-form {
  margin-top: 14px;
}

.correct-option {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 14px;
}

.correct-option p {
  margin: 0;
}

.correct-option img {
  max-width: 160px;
  max-height: 120px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px;
}

.reveal h2, .reveal h3 {
  margin: 16px 0 8px;
}

blockquote {
  margin: 0;
  padding-left: 14px;
  border-left: 4px solid var(--brand);
  color: var(--muted);
}

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}

.pager .results-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  grid-column: 1 / -1;
  justify-self: center;
  color: var(--muted);
  font-weight: 700;
  padding: 6px 12px;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 20px 0 24px;
}

.score-grid div, .section-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  background: var(--surface);
}

dt {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
}

dd {
  margin: 6px 0 0;
  font-size: 1.7rem;
  font-weight: 800;
}

.score-grid .score-final dd {
  color: var(--brand-strong);
}

.section-results h2 {
  margin-top: 0;
}

.section-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-style: normal;
  font-weight: 700;
  font-size: 0.9rem;
}

.badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid var(--ok);
}

.badge.bad {
  background: var(--bad-soft);
  color: var(--bad);
  border: 1px solid var(--bad);
}

.final-state {
  font-size: 1.1rem;
}

.final-state .badge {
  font-size: 1.05rem;
  padding: 8px 18px;
}

.error-panel {
  max-width: 560px;
  margin: 24px auto 0;
  text-align: center;
}

.error-panel .button {
  margin-top: 18px;
}

.status-code {
  margin: 0 0 4px;
  font-size: 2.4rem;
  font-weight: 800;
}

.muted, .status-code {
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 700px) {
  .page {
    width: calc(100% - 24px);
    padding-top: 20px;
  }

  .brand {
    font-size: 0.95rem;
  }

  .brand, .nav a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }

  .nav {
    gap: 10px;
  }

  .lang-picker select {
    min-height: 44px;
  }

  .choice-inline {
    min-height: 44px;
  }

  .lang-picker span {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .mode-card, .question-card, .results, .error-panel {
    padding: 16px;
  }

  .pager {
    position: sticky;
    bottom: 0;
    z-index: 1;
    margin: 16px -12px 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--line);
  }

  .section-row {
    grid-template-columns: 1fr auto;
  }

  .section-row .badge {
    grid-column: 2;
    grid-row: 1;
  }
}

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