:root {
  --bg: #f6f4ef;
  --paper: #ffffff;
  --ink: #1f2328;
  --muted: #6b6f76;
  --line: #e2ded5;
  --accent: #8a3b12;
  --accent-soft: #f4e6dc;
  --ok: #1f7a3a;
  --ok-soft: #e3f3e8;
  --bad: #b42318;
  --bad-soft: #fbe7e5;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.55 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
a { color: var(--accent); }
.top { background: var(--paper); border-bottom: 1px solid var(--line); padding: 12px 16px; }
.brand { font-weight: 700; text-decoration: none; color: var(--ink); }
main { max-width: 860px; margin: 0 auto; padding: 20px 16px 40px; }
.foot { max-width: 860px; margin: 0 auto; padding: 0 16px 24px; color: var(--muted); font-size: 13px; }
h1 { font-size: 26px; line-height: 1.25; margin: 4px 0 18px; }
h2 { font-size: 20px; margin: 28px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.crumbs { margin: 0 0 6px; font-size: 14px; color: var(--muted); }
.notice { background: var(--accent-soft); border-radius: var(--radius); padding: 10px 14px; margin: 0 0 16px; }

/* разделы */
.cards { display: grid; gap: 12px; }
.card {
  display: grid; grid-template-columns: 44px 1fr; grid-template-rows: auto auto; column-gap: 12px;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; text-decoration: none; color: var(--ink);
}
.card:hover { border-color: var(--accent); }
.card-num { grid-row: span 2; font-size: 28px; font-weight: 700; color: var(--accent); align-self: center; text-align: center; }
.card-title { font-weight: 600; font-size: 18px; }
.card-meta { color: var(--muted); font-size: 14px; }

/* настройка теста */
.setup fieldset { border: 0; padding: 0; margin: 0 0 20px; }
.setup legend { font-weight: 700; margin-bottom: 8px; }
.topic { display: flex; gap: 10px; align-items: flex-start; background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 6px; cursor: pointer; }
.topic input { margin-top: 5px; }
.topic:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row legend { width: 100%; }
.pill { cursor: pointer; }
.pill input { position: absolute; opacity: 0; }
.pill span { display: inline-block; min-width: 56px; text-align: center; padding: 8px 14px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--paper); }
.pill input:checked + span { border-color: var(--accent); background: var(--accent); color: #fff; }
.pill input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.name { display: block; margin: 0 0 20px; font-weight: 700; }
.name input { display: block; width: 100%; max-width: 420px; margin-top: 6px; font: inherit; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px; font-weight: 400; }

.btn { display: inline-block; font: inherit; padding: 10px 18px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--paper); color: var(--ink); cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .4; cursor: default; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font: inherit; font-size: 14px; padding: 0; }

/* тест */
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 6px 0 14px; }
.bar { height: 100%; background: var(--accent); }
.qhead { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.question, .context { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.context summary { cursor: pointer; font-weight: 700; color: var(--accent); }
.context .rich { margin-top: 10px; }
.hint { margin: 0 0 8px; font-weight: 600; color: var(--accent); }
.rich p { margin: 0 0 8px; }
.rich img { max-width: 100%; height: auto; display: block; margin: 8px 0; }
.rich table { border-collapse: collapse; margin: 6px 0; max-width: 100%; }
.rich td, .rich th { padding: 2px 6px; vertical-align: top; }
.rich { overflow-x: auto; }

.answer-input { font-weight: 700; }
.answer-input input { display: block; width: 100%; max-width: 420px; margin-top: 6px; font: inherit; font-size: 19px;
  padding: 8px 10px; border: 2px solid var(--line); border-radius: 8px; }
.answer-input input:focus { border-color: var(--accent); outline: none; }
.options { margin-top: 12px; display: grid; gap: 6px; }
.option { display: grid; grid-template-columns: auto auto 1fr; gap: 8px; align-items: start; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.option input { margin-top: 6px; }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.option-num { font-weight: 700; }
.option-body p { margin: 0; }
.matching { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; }
.matching label { display: flex; flex-direction: column; align-items: center; font-weight: 700; }
.matching select { font: inherit; font-size: 19px; padding: 6px 8px; min-width: 64px; margin-top: 4px; }
.nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; }
.dots { display: flex; flex-wrap: wrap; gap: 6px; }
.dot { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--paper); font: inherit;
  font-size: 13px; cursor: pointer; }
.dot.done { background: var(--accent-soft); border-color: var(--accent); }
.dot.cur { outline: 2px solid var(--accent); }
.finish-early { margin-top: 14px; }

/* итог */
.result { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; text-align: center; }
.who { font-size: 22px; font-weight: 700; margin: 0; }
.big { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 10px 0; flex-wrap: wrap; }
.mark { font-size: 84px; font-weight: 800; line-height: 1; width: 120px; height: 120px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; }
.mark-5 .mark, .mark-4 .mark { background: var(--ok-soft); color: var(--ok); }
.mark-3 .mark { background: var(--accent-soft); color: var(--accent); }
.mark-2 .mark { background: var(--bad-soft); color: var(--bad); }
.score { font-size: 24px; font-weight: 600; }
.review { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.review li { background: var(--paper); border: 1px solid var(--line); border-left-width: 5px; border-radius: 8px; padding: 8px 12px; }
.review li.ok { border-left-color: var(--ok); }
.review li.bad { border-left-color: var(--bad); }
.review summary { cursor: pointer; }
.review .rich { margin-top: 8px; font-size: 15px; }
.context-mini { color: var(--muted); max-height: 240px; overflow: auto; border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
.options-mini { font-size: 15px; }
.mark-icon { display: inline-block; width: 18px; font-weight: 700; }
.review li.ok .mark-icon { color: var(--ok); }
.review li.bad .mark-icon { color: var(--bad); }

/* аналитика */
.table-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.stats { border-collapse: collapse; width: 100%; font-size: 15px; }
.stats th, .stats td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.stats th { font-size: 13px; color: var(--muted); font-weight: 600; }
.stats .num { text-align: right; white-space: nowrap; }
.stats tr.small-topic td { background: var(--accent-soft); }
.stats tr.total td { font-weight: 700; border-bottom: 0; }

@media (max-width: 560px) {
  body { font-size: 16px; }
  h1 { font-size: 22px; }
  .mark { font-size: 64px; width: 96px; height: 96px; }
}

/* --- экран задания: заметная смена, подсказка к ответу, панель кнопок всегда на виду --- */
.qnum { font-size: 22px; margin: 0; }
.qnum .muted { font-weight: 400; font-size: 18px; }
.context summary { font-weight: 600; }
.answer-box { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line); }
.answer-input { display: flex; flex-direction: column; gap: 6px; margin-top: 0; }
.answer-hint { margin: 8px 0 0; font-size: 14px; color: var(--muted); }
.matching.seq { align-items: flex-end; }
.matching .arrow { align-self: flex-end; padding-bottom: 10px; color: var(--muted); font-size: 20px; }
.navbar {
  position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 14px -16px 0; padding: 10px 16px; background: rgba(246, 244, 239, .96); border-top: 1px solid var(--line);
  backdrop-filter: blur(4px);
}
.navbar .btn { min-width: 120px; }
.navbar-pos { color: var(--muted); font-size: 14px; }
.dots { margin-top: 6px; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: 0 0 0 0 transparent; } }
.question.flash { animation: flash .9s ease-out; }
@media (prefers-reduced-motion: reduce) { .question.flash { animation: none; } }
.error { color: var(--bad); margin: 10px 0 0; }
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .35); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: var(--paper); border-radius: var(--radius); padding: 20px; max-width: 440px; width: 100%; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.modal-box h2 { margin: 0 0 8px; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.btn:focus-visible, .dot:focus-visible, .link:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* --- итог --- */
.result-title { font-size: 18px; font-weight: 600; margin: 0; }
.score { text-align: left; line-height: 1.2; }
.percent { font-size: 18px; color: var(--muted); font-weight: 400; }
.when { font-size: 20px; margin: 6px 0 2px; }
.review summary { display: flex; gap: 6px; align-items: baseline; }

/* клетки для ответа из цифр — как в бланке */
.cells { border: 0; padding: 0; margin: 0; }
.cells legend { font-weight: 700; margin-bottom: 6px; }
.cells-row { display: flex; flex-wrap: wrap; gap: 8px; }
.cell { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.cell input { width: 48px; height: 52px; text-align: center; font: inherit; font-size: 24px; font-weight: 700; color: var(--ink);
  border: 2px solid var(--line); border-radius: 8px; background: var(--paper); }
.cell input:focus { border-color: var(--accent); outline: none; }
